aboutsummaryrefslogtreecommitdiff
path: root/test/test_initrd.c
blob: 7c23acc2373c77ed6cc3fd47ac7e50187cfb1110 (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
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#include <fbos/init.h>
#include <fbos/sched.h>
#include <fbos/mm.h>

unsigned long stack[4][THREAD_SIZE / sizeof(unsigned long)];

struct task_struct tasks[4] = {
	[TASK_INIT] = { .stack = stack[0], .entry_addr = NULL, },
	[TASK_FIZZ] = { .stack = stack[1], .entry_addr = NULL, },
	[TASK_BUZZ] = { .stack = stack[2], .entry_addr = NULL, },
	[TASK_FIZZBUZZ] = { .stack = stack[3], .entry_addr = NULL, },
};

int main(void)
{
	FILE *fh = fopen("./usr/initramfs.cpio", "rb");
	assert(fh);

	fseek(fh, 0, SEEK_END);
	long fsize = ftell(fh);
	rewind(fh);

	unsigned char *contents = malloc((unsigned long)fsize + 1);
	fread(contents, (unsigned long)fsize, 1, fh);
	fclose(fh);

	contents[fsize] = 0;

	extract_initrd(contents, (uint64_t)fsize, tasks);
	free(contents);

	assert(((uintptr_t)tasks[0].entry_addr & 0xff) == 0xe8);
	assert(((uintptr_t)tasks[1].entry_addr & 0xff) == 0xbc);
	assert(((uintptr_t)tasks[2].entry_addr & 0xff) == 0xb4);
	assert(((uintptr_t)tasks[3].entry_addr & 0xff) == 0x80);

	exit(0);
}