summaryrefslogtreecommitdiff
path: root/tests/39-basic-api_level.py
blob: 93f3d7b561f6e4c49f1e8bc99c0408e64868a59a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python

#
# Seccomp Library test program
#
# Copyright (c) 2016 Red Hat <pmoore@redhat.com>
# Copyright (c) 2017 Canonical Ltd.
# Authors: Paul Moore <paul@paul-moore.com>
#          Tyler Hicks <tyhicks@canonical.com>
#

#
# This library is free software; you can redistribute it and/or modify it
# under the terms of version 2.1 of the GNU Lesser General Public License as
# published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library; if not, see <http://www.gnu.org/licenses>.
#

import argparse
import sys

import util

from seccomp import *

def test():
    api = get_api()
    if (api < 1):
        raise RuntimeError("Failed getting initial API level")

    set_api(1)
    api = get_api()
    if api != 1:
        raise RuntimeError("Failed getting API level 1")

    set_api(2)
    api = get_api()
    if api != 2:
        raise RuntimeError("Failed getting API level 2")

    set_api(3)
    api = get_api()
    if api != 3:
        raise RuntimeError("Failed getting API level 3")

    set_api(4)
    api = get_api()
    if api != 4:
        raise RuntimeError("Failed getting API level 4")

    set_api(5)
    api = get_api()
    if api != 5:
        raise RuntimeError("Failed getting API level 5")

    set_api(6)
    api = get_api()
    if api != 6:
        raise RuntimeError("Failed getting API level 6")

    set_api(7)
    api = get_api()
    if api != 7:
        raise RuntimeError("Failed getting API level 7")

    # Attempt to set a high, invalid API level
    try:
        set_api(1024)
    except ValueError:
        pass
    else:
        raise RuntimeError("Missing failure when setting invalid API level")
    # Ensure that the previously set API level didn't change
    api = get_api()
    if api != 7:
        raise RuntimeError("Failed getting old API level after setting an invalid API level")

test()

# kate: syntax python;
# kate: indent-mode python; space-indent on; indent-width 4; mixedindent off;