xref: /kvm-unit-tests/powerpc/selftest.c (revision a299895b7abb54e7ba6bb4108f202acbb484ac65)
1 /*
2  * Test the framework itself. These tests confirm that setup works.
3  *
4  * Copyright (C) 2016, Red Hat Inc, Andrew Jones <drjones@redhat.com>
5  *
6  * This work is licensed under the terms of the GNU LGPL, version 2.
7  */
8 #include <libcflat.h>
9 #include <util.h>
10 #include <asm/setup.h>
11 
12 static void check_setup(int argc, char **argv)
13 {
14 	int nr_tests = 0, len, i;
15 	long val;
16 
17 	for (i = 0; i < argc; ++i) {
18 
19 		len = parse_keyval(argv[i], &val);
20 		if (len == -1)
21 			continue;
22 
23 		argv[i][len] = '\0';
24 		report_prefix_push(argv[i]);
25 
26 		if (strcmp(argv[i], "mem") == 0) {
27 
28 			phys_addr_t memsize = PHYSICAL_END - PHYSICAL_START;
29 			phys_addr_t expected = ((phys_addr_t)val)*1024*1024;
30 
31 			report(memsize == expected, "size = %" PRIu64 " MB",
32 							memsize/1024/1024);
33 			++nr_tests;
34 
35 		} else if (strcmp(argv[i], "smp") == 0) {
36 
37 			report(nr_cpus == (int)val, "nr_cpus = %d", nr_cpus);
38 			++nr_tests;
39 		}
40 
41 		report_prefix_pop();
42 	}
43 
44 	if (nr_tests < 2)
45 		report_abort("missing input");
46 }
47 
48 int main(int argc, char **argv)
49 {
50 	report_prefix_push("selftest");
51 
52 	if (argc < 2)
53 		report_abort("no test specified");
54 
55 	report_prefix_push(argv[1]);
56 
57 	if (strcmp(argv[1], "setup") == 0) {
58 
59 		check_setup(argc-2, &argv[2]);
60 
61 	}
62 
63 	return report_summary();
64 }
65