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

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

struct task_struct tasks[4] = {
	[TASK_INIT] = { .entry_addr = NULL, },
	[TASK_FIZZ] = { .entry_addr = NULL, },
	[TASK_BUZZ] = { .entry_addr = NULL, },
	[TASK_FIZZBUZZ] = { .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(tasks[0].entry_addr);
	assert(tasks[1].entry_addr);
	assert(tasks[2].entry_addr);
	assert(tasks[3].entry_addr);

	exit(0);
}