summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTyler Hicks <tyhicks@canonical.com>2017-10-10 05:01:57 +0000
committerPaul Moore <paul@paul-moore.com>2017-10-19 14:23:52 -0400
commit4f16fe2082863cf317512b24e9a88da373b1894b (patch)
treee0c9afdce453d6689e61e86a42194a6497d74a29 /tests
parentf9d757de253dbbb7d32fe16774a12b0ccfb7f499 (diff)
downloadlibseccomp-4f16fe2082863cf317512b24e9a88da373b1894b.tar.gz
python: Expose API level functionality
Allow Python applications to get and set the API level using global functions. Signed-off-by: Tyler Hicks <tyhicks@canonical.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
Diffstat (limited to 'tests')
-rwxr-xr-xtests/39-basic-api_level.py34
1 files changed, 31 insertions, 3 deletions
diff --git a/tests/39-basic-api_level.py b/tests/39-basic-api_level.py
index e958bf1..49d23f2 100755
--- a/tests/39-basic-api_level.py
+++ b/tests/39-basic-api_level.py
@@ -4,7 +4,9 @@
# Seccomp Library test program
#
# Copyright (c) 2016 Red Hat <pmoore@redhat.com>
-# Author: Paul Moore <paul@paul-moore.com>
+# Copyright (c) 2017 Canonical Ltd.
+# Authors: Paul Moore <paul@paul-moore.com>
+# Tyler Hicks <tyhicks@canonical.com>
#
#
@@ -28,8 +30,34 @@ import util
from seccomp import *
-# NOTE: this is a NULL test since we don't support the seccomp_version() API
-# via the libseccomp python bindings
+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")
+
+ # 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 != 2:
+ 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;