-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathselftest.c
74 lines (62 loc) · 1.66 KB
/
selftest.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
#include <kshell/kshell.h>
#include <arch/kshell.h>
#include <fs/vfs.h>
#include <panic.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syscall.h>
void print_selftest_header(const char* name)
{
printf("\n\033[1;33m[%s]\033[0m\n", name);
}
int selftest()
{
print_selftest_header("kernel syscalls");
// This does not call the syscall with an interrupt anymore, it directly uses
// `k_test()` under the hood.
test("kshell");
print_selftest_header("kernel stacktrace");
arch_kernel_dump_stacktrace();
print_selftest_header("memory");
printf("simple test with malloc()/free(): ");
char* str = (void*)0x42;
printf("pointer before malloc() = %p\n", str);
int str_len = 9;
str = (char*)malloc(str_len * sizeof(char));
if (str == 0) {
printf("failed\n");
return 1;
} else {
printf("success! p=%p", str);
strncpy(str, "it works", str_len);
printf(" and value is: %s\n", str);
free(str);
}
printf("now allocating a large chunk of memory... ");
printf("Pointer before malloc() = %p\n", str);
str = (char*)malloc(1024 * 1024 * 5 * sizeof(char));
if (str == 0) {
printf("failed\n");
return 2;
} else {
printf("success!\n");
free(str);
}
print_selftest_header("filesystem");
inode_t debug = vfs_namei("/dev/debug");
if (debug == NULL) {
printf("/dev/debug not found\n");
return 3;
} else {
const char* message = "This message should be written to the console.\n";
vfs_write(debug, (void*)message, strlen(message), 0);
}
print_selftest_header(ARCH);
int retval = arch_selftest();
if (retval != 0) {
return retval;
}
printf("\ndone.\n");
return 0;
}