The Pedigree Project 0.1
scheduling-contract-test/main.c
1#define _GNU_SOURCE
2#include <signal.h>
3#include <stdlib.h>
4#include <string.h>
5#include <unistd.h>
6
7#include "contract.h"
8
9int main(int argc, char** argv) {
10 setvbuf(stdout, NULL, _IONBF, 0);
11 if (argc > 1 && !strcmp(argv[1], "schedule-exec"))
12 return sc_exec(argc, argv);
13 if (argc > 3 || sc_init(argc == 3 ? atoi(argv[2]) : 0))
14 return 2;
15 const struct {
16 const char* name;
17 int (*run)(void);
18 } families[] = {{"api-policy", sc_api}, {"placement", sc_placement},
19 {"wakeups", sc_wakeups}, {"affinity-races", sc_affinity_races},
20 {"lifecycle", sc_lifecycle}, {"permissions", sc_permissions}};
21 int selected = 0;
22 for (size_t i = 0; i < sizeof(families) / sizeof(families[0]); ++i) {
23 if (argc >= 2 && strcmp(argv[1], "all") && strcmp(argv[1], families[i].name))
24 continue;
25 ++selected;
26 printf("SCHEDULING-CONTRACT: BEGIN %s\n", families[i].name);
27 pid_t pid = fork();
28 if (!pid) {
29 alarm(55);
30 int result = families[i].run();
31 fflush(stderr);
32 _exit(result ? 1 : 0);
33 }
34 int status = pid < 0 ? -1 : sc_reap(pid, 60000);
35 cpu_set_t current;
36 if (sched_getaffinity(0, sizeof(current), &current) || !CPU_EQUAL(&current, &sc_allowed)) {
37 fputs("supervisor affinity changed\n", stderr);
38 status = 1;
39 }
40 printf("SCHEDULING-CONTRACT: %s %s status=%d\n", status ? "FAIL" : "PASS", families[i].name,
41 status);
42 if (status)
43 return 1;
44 }
45 if (!selected)
46 return 2;
47 puts("SCHEDULING-CONTRACT: END PASS");
48 return 0;
49}