-
Notifications
You must be signed in to change notification settings - Fork 0
/
jitqueue_test.c
111 lines (104 loc) · 1.96 KB
/
jitqueue_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* SPDX-License-Identifier: GPL-2.0 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "kselftest.h"
struct test {
const char *const name;
unsigned int delay_ms;
};
static int test(const struct test *restrict t)
{
const char *const path = "/proc/driver/jitqueue";
char buf[512];
FILE *fp;
int ret;
fp = fopen(path, "w");
if (!fp)
goto perr;
ret = snprintf(buf, sizeof(buf), "%d\n", t->delay_ms);
if (ret < 0)
goto perr;
ret = fwrite(buf, strlen(buf), 1, fp);
if (ret == -1)
goto perr;
if (fclose(fp) == -1)
goto perr;
fp = fopen(path, "r");
if (!fp)
goto perr;
ret = fread(buf, sizeof(buf), 1, fp);
if (ret == 0 && ferror(fp))
goto perr;
/* reset the wait ms */
fp = fopen(path, "w");
if (!fp)
goto perr;
ret = fputs("0\n", fp);
if (ret == -1)
goto perr;
if (fclose(fp) == -1)
goto perr;
fprintf(stdout, "%s:\n%s\n", t->name, buf);
exit(EXIT_SUCCESS);
perr:
perror(t->name);
exit(EXIT_FAILURE);
}
int main(void)
{
const struct test *t, tests[] = {
{
.name = "wait queue based 1ms delay",
.delay_ms = 1,
},
{
.name = "wait queue based 2ms delay",
.delay_ms = 2,
},
{
.name = "wait queue based 4ms delay",
.delay_ms = 4,
},
{
.name = "wait queue based 8ms delay",
.delay_ms = 8,
},
{.name = NULL},
};
for (t = tests; t->name; t++) {
int ret, status;
pid_t pid;
pid = fork();
if (pid == -1)
goto perr;
else if (pid == 0)
test(t);
ret = waitpid(pid, &status, 0);
if (ret == -1)
goto perr;
if (WIFSIGNALED(status)) {
fprintf(stderr, "%s: signaled with %s\n",
t->name, strsignal(WTERMSIG(status)));
goto err;
}
if (!WIFEXITED(status)) {
fprintf(stderr, "%s: does not exit\n",
t->name);
goto err;
}
if (WEXITSTATUS(status))
goto err;
ksft_inc_pass_cnt();
continue;
perr:
perror(t->name);
err:
ksft_inc_fail_cnt();
}
if (ksft_get_fail_cnt())
ksft_exit_fail();
ksft_exit_pass();
}