aboutsummaryrefslogtreecommitdiff
path: root/src/tests/test.c
blob: 172e4116f8f5efea3f72ff75043ee9bad9035202 (plain)
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
104
105
106
107
108
109
110
111
112
113
114
#include <cpu.h>
//#include <drivers/uart.h>
#include <graphics/lfb.h>
#include <lib/kmem.h>
#include <sys/core.h>
#include <sys/schedule.h>
#include <util/mutex.h>
#include <util/lock.h>

extern void atest(void);
void btest(void);

static int x = 0;
static int y = 13;
void test_entry(void)
{
	x = 0;
	unsigned int z = 1;
	draw_string(0, y+4, "Starting tests");
	unsigned long long ti, tf, dt=0;
	for(int i = 0; i < 64; i++) {
		sys0_64(SYS_TIME, &ti);
		sys0_64(SYS_TIME, &tf);
		dt += tf - ti;
		if (z % 2) {
			DRAW64(0+17, y+((z+1)/2)+5, (tf-ti));
		} else {
			DRAW64(0, y+(z/2)+5, (tf-ti));
		}
		z++;
	}
	DRAW64(0, y+5, dt/64);
	DRAW64(17, y+5, dt%64);
	z = 1;

	// atest
	//add_thread(atest, 0, 0);
	for(int i = 0; i < 64; i++) {
		sys0_64(SYS_TIME, &ti);
		sys0(SYS_YIELD);
		sys0_64(SYS_TIME, &tf);
		dt += tf - ti;
		if (z % 2) {
			DRAW64(35+17, y+((z+1)/2)+5, (tf-ti));
		} else {
			DRAW64(35, y+(z/2)+5, (tf-ti));
		}
		z++;
	}
	DRAW64(35, y+5, dt/64);
	DRAW64(35+17, y+5, dt%64);
	add_thread(btest, 0, 4);
}

//static struct Mutex testm = {.addr = 0, .pid = 0};
static struct Lock testm = {.pid = 0};

void ctest1(void);
void ctest2(void);
void ctest3(void);
void ctest4(void);

void ctest1(void)
{
	draw_cletter(x++, y+2, 'S', 0xFF0000);
	//uart_string("1 Started\n");
	draw_cletter(x++, y+2, 'L', 0xFF0000);
	//uart_string("1 Locking\n");
	lock(&testm);
	add_thread(ctest3, 0, 2);
	draw_cletter(x++, y+2, 'U', 0xFF0000);
	//uart_string("1 Unlocking\n");
	unlock(&testm);
	draw_cletter(x++, y+2, 'F', 0xFF0000);
	//uart_string("1 Finished\n");
}

void ctest2(void)
{
	draw_cletter(x++, y+0, 'S', 0x0000FF);
	//uart_string("2 Started\n");
	add_thread(ctest4, 0, 3);
	draw_cletter(x++, y+0, 'L', 0x0000FF);
	//uart_string("2 Locking\n");
	lock(&testm);
	draw_cletter(x++, y+0, 'U', 0x0000FF);
	//uart_string("2 Unlocking\n");
	unlock(&testm);
	draw_cletter(x++, y+0, 'F', 0x0000FF);
	//uart_string("2 Finished\n");
}

void ctest3(void)
{
	draw_cletter(x++, y+1, 'S', 0x00FF00);
	//uart_string("3 Started\n");
	add_thread(ctest2, 0, 1);
	draw_cletter(x++, y+1, 'F', 0x00FF00);
	//uart_string("3 Finished\n");
}

void ctest4(void)
{
	draw_cletter(x++, y+2, 'S', 0xAFAF00);
	//uart_string("4 Started\n");
	draw_cletter(x++, y+2, 'F', 0xAFAF00);
	//uart_string("4 Finished\n");
}

void btest(void)
{
	x = 0;
	add_thread(ctest1, 0, 3);
}