mirror of
https://github.com/QingdaoU/Judger.git
synced 2024-12-28 07:51:42 +00:00
add math test case and use -static flag by default
This commit is contained in:
parent
e9ee465516
commit
95c18f41a7
@ -10,7 +10,8 @@ int load_seccomp(void *dl_handler, struct config *_config) {
|
||||
SCMP_SYS(munmap), SCMP_SYS(open),
|
||||
SCMP_SYS(arch_prctl), SCMP_SYS(brk),
|
||||
SCMP_SYS(access), SCMP_SYS(exit_group),
|
||||
SCMP_SYS(close)};
|
||||
SCMP_SYS(close), SCMP_SYS(readlink),
|
||||
SCMP_SYS(uname)};
|
||||
int syscalls_whitelist_length = sizeof(syscalls_whitelist) / sizeof(int);
|
||||
scmp_filter_ctx ctx = NULL;
|
||||
// load seccomp rules
|
||||
|
@ -23,10 +23,13 @@ class BaseTestCase(TestCase):
|
||||
def rand_str(self):
|
||||
return ''.join(map(lambda xx:(hex(ord(xx))[2:]), os.urandom(16)))
|
||||
|
||||
def _compile_c(self, src_name):
|
||||
def _compile_c(self, src_name, extra_flags=None):
|
||||
path = os.path.dirname(os.path.abspath(__file__))
|
||||
exe_path = os.path.join(self.workspace, src_name.split("/")[-1].split(".")[0])
|
||||
cmd = "gcc {0} -g -O0 -o {1}".format(os.path.join(path, src_name), exe_path)
|
||||
flags = " "
|
||||
if extra_flags:
|
||||
flags += " ".join(extra_flags)
|
||||
cmd = ("gcc {0} -g -O0 -static -o {1}" + flags).format(os.path.join(path, src_name), exe_path)
|
||||
if os.system(cmd):
|
||||
raise AssertionError("compile error, cmd: {0}".format(cmd))
|
||||
return exe_path
|
||||
|
@ -26,8 +26,8 @@ class IntegrationTest(base.BaseTestCase):
|
||||
"gid": 0}
|
||||
self.workspace = self.init_workspace("integration")
|
||||
|
||||
def _compile_c(self, src_name):
|
||||
return super(IntegrationTest, self)._compile_c("integration/" + src_name)
|
||||
def _compile_c(self, src_name, extra_flags=None):
|
||||
return super(IntegrationTest, self)._compile_c("integration/" + src_name, extra_flags)
|
||||
|
||||
def _compile_cpp(self, src_name):
|
||||
return super(IntegrationTest, self)._compile_cpp("integration/" + src_name)
|
||||
|
9
tests/testcase/seccomp/math.c
Normal file
9
tests/testcase/seccomp/math.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
sin(1.0);
|
||||
printf("sin");
|
||||
return 0;
|
||||
}
|
@ -26,8 +26,8 @@ class SeccompTest(base.BaseTestCase):
|
||||
"gid": 0}
|
||||
self.workspace = self.init_workspace("seccomp")
|
||||
|
||||
def _compile_c(self, src_name):
|
||||
return super(SeccompTest, self)._compile_c("seccomp/" + src_name)
|
||||
def _compile_c(self, src_name, extra_flags=None):
|
||||
return super(SeccompTest, self)._compile_c("seccomp/" + src_name, extra_flags)
|
||||
|
||||
def test_mmap_write_file(self):
|
||||
config = self.config
|
||||
@ -36,3 +36,12 @@ class SeccompTest(base.BaseTestCase):
|
||||
result = _judger.run(**config)
|
||||
self.assertEqual(result["result"], _judger.RESULT_RUNTIME_ERROR)
|
||||
self.assertEqual(result["signal"], 31)
|
||||
|
||||
def test_math(self):
|
||||
config = self.config
|
||||
config["exe_path"] = self._compile_c("math.c", extra_flags=["-lm"])
|
||||
config["seccomp_rule_so_path"] = "/usr/lib/judger/librule_c_cpp.so"
|
||||
config["output_path"] = self.output_path()
|
||||
result = _judger.run(**config)
|
||||
self.assertEqual(result["result"], _judger.RESULT_SUCCESS)
|
||||
self.assertEqual("sin", self.output_content(config["output_path"]))
|
||||
|
Loading…
Reference in New Issue
Block a user