9 #include "capsicum-test.h"
12 double RepeatSyscall(int count, int nr, long arg1, long arg2, long arg3) {
13 const clock_t t0 = clock(); // or gettimeofday or whatever
14 for (int ii = 0; ii < count; ii++) {
15 syscall(nr, arg1, arg2, arg3);
17 const clock_t t1 = clock();
18 return (t1 - t0) / (double)CLOCKS_PER_SEC;
21 typedef int (*EntryFn)(void);
23 double CompareSyscall(EntryFn entry_fn, int count, int nr,
24 long arg1, long arg2, long arg3) {
25 double bare = RepeatSyscall(count, nr, arg1, arg2, arg3);
26 EXPECT_OK(entry_fn());
27 double capmode = RepeatSyscall(count, nr, arg1, arg2, arg3);
28 if (verbose) fprintf(stderr, "%d iterations bare=%fs capmode=%fs ratio=%.2f%%\n",
29 count, bare, capmode, 100.0*capmode/bare);
31 if (capmode==0.0) return 1.0;
37 FORK_TEST(Overhead, GetTid) {
38 EXPECT_GT(10, CompareSyscall(&cap_enter, 10000, __NR_gettid, 0, 0, 0));
40 FORK_TEST(Overhead, Seek) {
41 int fd = open("/etc/passwd", O_RDONLY);
42 EXPECT_GT(50, CompareSyscall(&cap_enter, 10000, __NR_lseek, fd, 0, SEEK_SET));