xref: /kvm-unit-tests/powerpc/selftest.c (revision c76b0d0a3842ba312a2d8512f7a3728f4598bf94)
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 #include <asm/smp.h>
12 
check_setup(int argc,char ** argv)13 static void check_setup(int argc, char **argv)
14 {
15 	int nr_tests = 0, len, i;
16 	long val;
17 
18 	for (i = 0; i < argc; ++i) {
19 
20 		len = parse_keyval(argv[i], &val);
21 		if (len == -1)
22 			continue;
23 
24 		argv[i][len] = '\0';
25 		report_prefix_push(argv[i]);
26 
27 		if (strcmp(argv[i], "mem") == 0) {
28 
29 			phys_addr_t memsize = PHYSICAL_END - PHYSICAL_START;
30 			phys_addr_t expected = ((phys_addr_t)val)*1024*1024;
31 
32 			report(memsize == expected, "size = %" PRIu64 " MB",
33 							memsize/1024/1024);
34 			++nr_tests;
35 
36 		} else if (strcmp(argv[i], "smp") == 0) {
37 
38 			report(nr_cpus_present == (int)val,
39 				"nr_cpus_present = %d", nr_cpus_present);
40 			++nr_tests;
41 		}
42 
43 		report_prefix_pop();
44 	}
45 
46 	if (nr_tests < 2)
47 		report_abort("missing input");
48 }
49 
main(int argc,char ** argv)50 int main(int argc, char **argv)
51 {
52 	report_prefix_push("selftest");
53 
54 	if (argc < 2)
55 		report_abort("no test specified");
56 
57 	report_prefix_push(argv[1]);
58 
59 	if (strcmp(argv[1], "setup") == 0) {
60 
61 		check_setup(argc-2, &argv[2]);
62 
63 	}
64 
65 	return report_summary();
66 }
67