summaryrefslogtreecommitdiff
path: root/src/kernel/core/test.c
blob: 867a4b56b00afc19cae626893a6e93ec4b6c10a0 (plain) (blame)
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
#include "test.h"
#include "monitor.h"
#include <mem/mem.h>
#include "sys.h"

static void test_run_kmalloc() {
	monitor_write("\tkmalloc:\n");
	int alloc_sizes[8] = { 10, 32, 16, 20, 64, 128, 32, 48 };
	int *ptrs[8] = { 0 };
	int t, i;
	for (t = 0; t < 2; t++) {
		for (i = 0; i < 8; i++) {
			monitor_writeDec(i); monitor_write(" alloc "); monitor_writeDec(alloc_sizes[i]);
			monitor_write(" : ");
			ptrs[i] = kmalloc(alloc_sizes[i]);
			ASSERT(ptrs[i] != 0);
			*ptrs[i] = i;
			monitor_writeHex((int)ptrs[i]); monitor_write("\n");
		}
		monitor_write("free : ");
		for (i = 0; i < 8; i++) {
			monitor_writeDec(i);
			ASSERT(*ptrs[i] == i);
			kfree(ptrs[i]);
			monitor_write(".");
		}
		monitor_write("\n");
	}
}

/*	This function is called when the kernel starts up.
	It runs some basic unit tests (for the moment, only tests kmalloc/kfree) */
void test_run() {
	monitor_write("Unit tests:\n");
	test_run_kmalloc();
	monitor_write(" >> Tests OK\n");
}