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 > 1 && !strcmp(argv[1], "schedule-input-exec"))
14 return sc_input_exec(argc, argv);
15 if (argc > 3 || sc_init(argc == 3 ? atoi(argv[2]) : 0))
16 return 2;
17 const struct {
18 const char* name;
19 int (*run)(void);
20 } families[] = {{"api-policy", sc_api}, {"placement", sc_placement},
21 {"wakeups", sc_wakeups}, {"lifecycle", sc_lifecycle},
22 {"permissions", sc_permissions}, {"input-pinning", sc_input}};
23 int selected = 0;
24 for (size_t i = 0; i < sizeof(families) / sizeof(families[0]); ++i) {
25 if (argc >= 2 && strcmp(argv[1], "all") && strcmp(argv[1], families[i].name))
26 continue;
27 ++selected;
28 printf("SCHEDULING-CONTRACT: BEGIN %s\n", families[i].name);
29 pid_t pid = fork();
30 if (!pid) {
31 alarm(55);
32 int result = families[i].run();
33 fflush(stderr);
34 _exit(result ? 1 : 0);
35 }
36 int status = pid < 0 ? -1 : sc_reap(pid, 60000);
37 cpu_set_t current;
38 if (sched_getaffinity(0, sizeof(current), &current) || !CPU_EQUAL(&current, &sc_allowed)) {
39 fputs("supervisor affinity changed\n", stderr);
40 status = 1;
41 }
42 printf("SCHEDULING-CONTRACT: %s %s status=%d\n", status ? "FAIL" : "PASS", families[i].name,
43 status);
44 if (status)
45 return 1;
46 }
47 if (!selected)
48 return 2;
49 puts("SCHEDULING-CONTRACT: END PASS");
50 return 0;
51}