The following change imports google/capsicum-test@9333154 from GitHub, omitting the embedded version of googletest, as well as the incomplete libcasper. This test suite helps verify capsicum(3) support via functional tests written in the GoogleTest test framework. Kernel support for capsicum(4) is tested by side-effect of testing capsicum(3). NB: as discussed in a previous [closed] PR [1], the casper(3) tests are incomplete/buggy and will not pass on FreeBSD. Thus, I have no intention of integrating them into the build/test on FreeBSD as-is. The import command used was: ``` curl -L https://github.com/google/capsicum-test/tarball/9333154 | tar --strip-components=1 -xvzf - -C dist/ rm -Rf dist/*/ ``` 1. https://github.com/google/capsicum-test/pull/26 Reviewed by: emaste (mentor) Differential Revision: https://reviews.freebsd.org/D19261
46 lines
1.3 KiB
C++
46 lines
1.3 KiB
C++
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <time.h>
|
|
#include <unistd.h>
|
|
|
|
#include "capsicum.h"
|
|
#include "syscalls.h"
|
|
#include "capsicum-test.h"
|
|
|
|
#ifdef HAVE_SYSCALL
|
|
double RepeatSyscall(int count, int nr, long arg1, long arg2, long arg3) {
|
|
const clock_t t0 = clock(); // or gettimeofday or whatever
|
|
for (int ii = 0; ii < count; ii++) {
|
|
syscall(nr, arg1, arg2, arg3);
|
|
}
|
|
const clock_t t1 = clock();
|
|
return (t1 - t0) / (double)CLOCKS_PER_SEC;
|
|
}
|
|
|
|
typedef int (*EntryFn)(void);
|
|
|
|
double CompareSyscall(EntryFn entry_fn, int count, int nr,
|
|
long arg1, long arg2, long arg3) {
|
|
double bare = RepeatSyscall(count, nr, arg1, arg2, arg3);
|
|
EXPECT_OK(entry_fn());
|
|
double capmode = RepeatSyscall(count, nr, arg1, arg2, arg3);
|
|
if (verbose) fprintf(stderr, "%d iterations bare=%fs capmode=%fs ratio=%.2f%%\n",
|
|
count, bare, capmode, 100.0*capmode/bare);
|
|
if (bare==0.0) {
|
|
if (capmode==0.0) return 1.0;
|
|
return 999.0;
|
|
}
|
|
return capmode/bare;
|
|
}
|
|
|
|
FORK_TEST(Overhead, GetTid) {
|
|
EXPECT_GT(10, CompareSyscall(&cap_enter, 10000, __NR_gettid, 0, 0, 0));
|
|
}
|
|
FORK_TEST(Overhead, Seek) {
|
|
int fd = open("/etc/passwd", O_RDONLY);
|
|
EXPECT_GT(50, CompareSyscall(&cap_enter, 10000, __NR_lseek, fd, 0, SEEK_SET));
|
|
close(fd);
|
|
}
|
|
#endif
|