Blame tests/39-basic-api_level.py

Packit 56e23f
#!/usr/bin/env python
Packit 56e23f
Packit 56e23f
#
Packit 56e23f
# Seccomp Library test program
Packit 56e23f
#
Packit 56e23f
# Copyright (c) 2016 Red Hat <pmoore@redhat.com>
Packit 56e23f
# Copyright (c) 2017 Canonical Ltd.
Packit 56e23f
# Authors: Paul Moore <paul@paul-moore.com>
Packit 56e23f
#          Tyler Hicks <tyhicks@canonical.com>
Packit 56e23f
#
Packit 56e23f
Packit 56e23f
#
Packit 56e23f
# This library is free software; you can redistribute it and/or modify it
Packit 56e23f
# under the terms of version 2.1 of the GNU Lesser General Public License as
Packit 56e23f
# published by the Free Software Foundation.
Packit 56e23f
#
Packit 56e23f
# This library is distributed in the hope that it will be useful, but WITHOUT
Packit 56e23f
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
Packit 56e23f
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
Packit 56e23f
# for more details.
Packit 56e23f
#
Packit 56e23f
# You should have received a copy of the GNU Lesser General Public License
Packit 56e23f
# along with this library; if not, see <http://www.gnu.org/licenses>.
Packit 56e23f
#
Packit 56e23f
Packit 56e23f
import argparse
Packit 56e23f
import sys
Packit 56e23f
Packit 56e23f
import util
Packit 56e23f
Packit 56e23f
from seccomp import *
Packit 56e23f
Packit 56e23f
def test():
Packit 56e23f
    api = get_api()
Packit 56e23f
    if (api < 1):
Packit 56e23f
        raise RuntimeError("Failed getting initial API level")
Packit 56e23f
Packit 56e23f
    set_api(1)
Packit 56e23f
    api = get_api()
Packit 56e23f
    if api != 1:
Packit 56e23f
        raise RuntimeError("Failed getting API level 1")
Packit 56e23f
Packit 56e23f
    set_api(2)
Packit 56e23f
    api = get_api()
Packit 56e23f
    if api != 2:
Packit 56e23f
        raise RuntimeError("Failed getting API level 2")
Packit 56e23f
Packit 56e23f
    set_api(3)
Packit 56e23f
    api = get_api()
Packit 56e23f
    if api != 3:
Packit 56e23f
        raise RuntimeError("Failed getting API level 3")
Packit 56e23f
Packit Service 10c312
    set_api(4)
Packit Service 10c312
    api = get_api()
Packit Service 10c312
    if api != 4:
Packit Service 10c312
        raise RuntimeError("Failed getting API level 4")
Packit Service 10c312
Packit Service 10c312
    set_api(5)
Packit Service 10c312
    api = get_api()
Packit Service 10c312
    if api != 5:
Packit Service 10c312
        raise RuntimeError("Failed getting API level 5")
Packit Service 10c312
Packit Service 10c312
    set_api(6)
Packit Service 10c312
    api = get_api()
Packit Service 10c312
    if api != 6:
Packit Service 10c312
        raise RuntimeError("Failed getting API level 6")
Packit Service 10c312
Packit 56e23f
    # Attempt to set a high, invalid API level
Packit 56e23f
    try:
Packit 56e23f
        set_api(1024)
Packit 56e23f
    except ValueError:
Packit 56e23f
        pass
Packit 56e23f
    else:
Packit 56e23f
        raise RuntimeError("Missing failure when setting invalid API level")
Packit 56e23f
    # Ensure that the previously set API level didn't change
Packit 56e23f
    api = get_api()
Packit Service 10c312
    if api != 6:
Packit 56e23f
        raise RuntimeError("Failed getting old API level after setting an invalid API level")
Packit 56e23f
Packit 56e23f
test()
Packit 56e23f
Packit 56e23f
# kate: syntax python;
Packit 56e23f
# kate: indent-mode python; space-indent on; indent-width 4; mixedindent off;