-
Notifications
You must be signed in to change notification settings - Fork 3
/
memtest1.c
73 lines (63 loc) · 1.16 KB
/
memtest1.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
#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 (2 << 20) + (1 << 18) + (1 << 17)
void
mem(void)
{
void *m1 = 0, *m2, *start;
uint cur = 0;
uint count = 0;
uint total_count;
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++;
printf(1, "CurrCount: %d\n", ((int*)m1)[2]);
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)
{
printf(1, "CurrCount: %d\n", count);
goto failed;
}
m1 = *(char**)m1;
count++;
}
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;
}