-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_nice.c
More file actions
65 lines (57 loc) · 1.42 KB
/
test_nice.c
File metadata and controls
65 lines (57 loc) · 1.42 KB
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
#include "types.h"
#include "stat.h"
#include "user.h"
void test_nice()
{
int pid, nice;
printf(1, "case 1. get nice value of init process: ");
if (getnice(1) == 5)
printf(1, "OK\n");
else
printf(1, "WRONG\n");
printf(1, "case 2. get nice value of non-existing process: ");
if (getnice(100) == -1)
printf(1, "OK\n");
else
printf(1, "WRONG\n");
printf(1, "case 3. set nice value of current process: ");
pid = getpid();
setnice(pid, 3);
if (getnice(pid) == 3)
printf(1, "OK\n");
else
printf(1, "WRONG\n");
printf(1, "case 4. set nice value of non-existing process: ");
if (setnice(188, 3) == -1)
printf(1, "OK\n");
else
printf(1, "WRONG\n");
printf(1, "case 5. set wrong nice value of current process: ");
if (setnice(pid, -1) == -1 && setnice(pid, 11) == -1)
printf(1, "OK\n");
else
printf(1, "WRONG\n");
printf(1, "case 6. get nice value of forked process: ");
nice = getnice(pid);
pid = fork();
if (pid == 0) { // child
if (getnice(getpid()) == nice) {
printf(1, "OK\n");
exit();
}
else {
printf(1, "WRONG\n");
exit();
}
}
else { // parent
wait();
}
}
int main(void)
{
printf(1, "=== TEST START ===\n");
test_nice();
printf(1, "=== TEST END ===\n");
exit();
}