The Pedigree Project 0.1
remap-file-pages-contract-test/main.c
1#define _GNU_SOURCE
2#include <signal.h>
3#include <string.h>
4#include <unistd.h>
5
6#include "contract.h"
7
8size_t rp_page;
9
10static int run(const char* name, int (*function)(void)) {
11 printf("REMAP-FILE-PAGES-CONTRACT: BEGIN %s\n", name);
12 fflush(stdout);
13 pid_t child = fork();
14 if (child < 0)
15 return -1;
16 if (!child) {
17 alarm(40);
18 int result = function();
19 fflush(stdout);
20 fflush(stderr);
21 _exit(result ? 1 : 0);
22 }
23 int result = rp_reap(child, 45000);
24 printf("REMAP-FILE-PAGES-CONTRACT: %s %s status=%d\n", result ? "FAIL" : "PASS", name, result);
25 fflush(stdout);
26 return result;
27}
28
29int main(int argc, char** argv) {
30 rp_page = (size_t)sysconf(_SC_PAGESIZE);
31 if (rp_page < 512 || rp_page > 65536 || (rp_page & (rp_page - 1)))
32 return 2;
33 signal(SIGPIPE, SIG_IGN);
34 static const struct {
35 const char* name;
36 int (*function)(void);
37 } suites[] = {{"offsets", rp_offsets},
38 {"admission", rp_admission},
39 {"lifetime", rp_lifetime},
40 {"locks", rp_locks},
41 {"resize", rp_resize}};
42 int selected = 0;
43 for (size_t n = 0; n < sizeof(suites) / sizeof(suites[0]); ++n) {
44 if (argc > 1 && strcmp(argv[1], suites[n].name))
45 continue;
46 selected = 1;
47 if (run(suites[n].name, suites[n].function))
48 return 1;
49 }
50 if (!selected)
51 return 2;
52 puts("REMAP-FILE-PAGES-CONTRACT: END PASS");
53 return 0;
54}