-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmemtest2.c
More file actions
103 lines (87 loc) · 1.53 KB
/
memtest2.c
File metadata and controls
103 lines (87 loc) · 1.53 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
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
#include "param.h"
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fs.h"
#include "fcntl.h"
#include "syscall.h"
#include "traps.h"
#include "memlayout.h"
char buf[8192];
char name[3];
char *echoargv[] = { "echo", "ALL", "TESTS", "PASSED", 0 };
int stdout = 1;
#define TOTAL_MEMORY (1 << 20) + (1 << 18)
void
mem(void)
{
void *m1 = 0, *m2, *start;
uint cur = 0;
uint count = 0;
uint total_count;
int pid;
printf(1, "mem test\n");
m1 = malloc(4096);
if (m1 == 0)
goto failed;
start = m1;
while (cur < TOTAL_MEMORY) {
m2 = malloc(4096);
if (m2 == 0)
goto failed;
*(char**)m1 = m2;
((int*)m1)[2] = count++;
m1 = m2;
cur += 4096;
}
((int*)m1)[2] = count;
total_count = count;
printf(1, "\n\nWhile Loop Over\n");
count = 0;
m1 = start;
while (count != total_count) {
if (((int*)m1)[2] != count)
{
goto failed;
}
m1 = *(char**)m1;
count++;
}
printf(1, "\n\nSecond While Loop Over\n");
if (swap(start) != 0)
printf(1, "failed to swap %p\n", start);
printf(1, "\n\nforking\n");
pid = fork();
if (pid == 0){
count = 0;
m1 = start;
while (count != total_count) {
if (((int*)m1)[2] != count)
goto failed;
m1 = *(char**)m1;
count++;
printf(1, "count_in_3rd_loop: %d\n", count);
}
exit();
}
else if (pid < 0)
{
printf(1, "fork failed\n");
}
else if (pid > 0)
{
wait();
}
printf(1, "mem ok %d\n", bstat());
exit();
failed:
printf(1, "test failed!\n");
exit();
}
int
main(int argc, char *argv[])
{
printf(1, "memtest starting\n");
mem();
return 0;
}