-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjiffies_test.c
82 lines (75 loc) · 1.43 KB
/
jiffies_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
/* SPDX-License-Identifier: GPL-2.0 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "kselftest.h"
struct test {
const char *const name;
};
static int test(const struct test *restrict t)
{
const char *const path = "/proc/driver/jiffies";
char buf[512];
FILE *fp;
int ret;
fp = fopen(path, "r");
if (!fp)
goto perr;
ret = fread(buf, sizeof(buf), 1, fp);
if (ret == 0 && ferror(fp))
goto perr;
if (fclose(fp) == -1)
goto perr;
buf[sizeof(buf)-1] = '\0';
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 = "read /proc/driver/jiffies file",
},
{.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 by %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();
}