Skip to content

Commit 518493f

Browse files
committed
tests: add Python version of 32-bit comparison test program
Signed-off-by: James Henstridge <james.henstridge@canonical.com>
1 parent d472727 commit 518493f

4 files changed

Lines changed: 51 additions & 1 deletion

File tree

src/python/libseccomp.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ cdef extern from "seccomp.h":
7272
SCMP_CMP_GE
7373
SCMP_CMP_GT
7474
SCMP_CMP_MASKED_EQ
75+
SCMP_CMP_32BIT
7576

7677
cdef enum:
7778
SCMP_ACT_KILL_PROCESS

src/python/seccomp.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ EQ = libseccomp.SCMP_CMP_EQ
133133
GE = libseccomp.SCMP_CMP_GE
134134
GT = libseccomp.SCMP_CMP_GT
135135
MASKED_EQ = libseccomp.SCMP_CMP_MASKED_EQ
136+
CMP_32BIT = libseccomp.SCMP_CMP_32BIT
136137

137138
def system_arch():
138139
""" Return the system architecture value.

tests/60-sim-32b_args_on_64b.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python
2+
3+
#
4+
# Seccomp Library test program
5+
#
6+
# Copyright (c) 2022 Canonical Ltd.
7+
# Author: James Henstridge <james.henstridge@canonical.com>
8+
#
9+
10+
#
11+
# This library is free software; you can redistribute it and/or modify it
12+
# under the terms of version 2.1 of the GNU Lesser General Public License as
13+
# published by the Free Software Foundation.
14+
#
15+
# This library is distributed in the hope that it will be useful, but WITHOUT
16+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
18+
# for more details.
19+
#
20+
# You should have received a copy of the GNU Lesser General Public License
21+
# along with this library; if not, see <http://www.gnu.org/licenses>.
22+
#
23+
24+
import argparse
25+
import sys
26+
27+
import util
28+
29+
from seccomp import *
30+
31+
def test(args):
32+
f = SyscallFilter(KILL)
33+
f.add_rule_exactly(ALLOW, 1001, Arg(0, NE | CMP_32BIT, 0x10))
34+
f.add_rule_exactly(ALLOW, 1002, Arg(0, LT | CMP_32BIT, 0x10))
35+
f.add_rule_exactly(ALLOW, 1003, Arg(0, LE | CMP_32BIT, 0x10))
36+
f.add_rule_exactly(ALLOW, 1004, Arg(0, EQ | CMP_32BIT, 0x10))
37+
f.add_rule_exactly(ALLOW, 1005, Arg(0, GE | CMP_32BIT, 0x10))
38+
f.add_rule_exactly(ALLOW, 1006, Arg(0, GT | CMP_32BIT, 0x10))
39+
f.add_rule_exactly(ALLOW, 1007, Arg(0, MASKED_EQ | CMP_32BIT, 0xff, 0x10))
40+
return f
41+
42+
args = util.get_opt()
43+
ctx = test(args)
44+
util.filter_output(args, ctx)
45+
46+
# kate: syntax python;
47+
# kate: indent-mode python; space-indent on; indent-width 4; mixedindent off;

tests/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ EXTRA_DIST_TESTPYTHON = \
155155
56-basic-iterate_syscalls.py \
156156
57-basic-rawsysrc.py \
157157
58-live-tsync_notify.py \
158-
59-basic-empty_binary_tree.py
158+
59-basic-empty_binary_tree.py \
159+
60-sim-32b_args_on_64b.tests.py
159160

160161
EXTRA_DIST_TESTCFGS = \
161162
01-sim-allow.tests \

0 commit comments

Comments
 (0)