xref: /kvm-unit-tests/arm/selftest.c (revision d3aacb4f57d05f74f2030dbe12e7dfd6aa1b273d)
1 /*
2  * Test the framework itself. These tests confirm that setup works.
3  *
4  * Copyright (C) 2014, 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 "asm/setup.h"
10 
11 #define TESTGRP "selftest"
12 
13 static char testname[64];
14 
15 static void testname_set(const char *subtest)
16 {
17 	strcpy(testname, TESTGRP);
18 	if (subtest) {
19 		strcat(testname, "::");
20 		strcat(testname, subtest);
21 	}
22 }
23 
24 static void assert_args(int num_args, int needed_args)
25 {
26 	if (num_args < needed_args) {
27 		printf("%s: not enough arguments\n", testname);
28 		abort();
29 	}
30 }
31 
32 static char *split_var(char *s, long *val)
33 {
34 	char *p;
35 
36 	p = strchr(s, '=');
37 	if (!p)
38 		return NULL;
39 
40 	*val = atol(p+1);
41 	*p = '\0';
42 
43 	return s;
44 }
45 
46 static void check_setup(int argc, char **argv)
47 {
48 	int nr_tests = 0, i;
49 	char *var;
50 	long val;
51 
52 	for (i = 0; i < argc; ++i) {
53 
54 		var = split_var(argv[i], &val);
55 		if (!var)
56 			continue;
57 
58 		if (strcmp(var, "mem") == 0) {
59 
60 			phys_addr_t memsize = PHYS_END - PHYS_OFFSET;
61 			phys_addr_t expected = ((phys_addr_t)val)*1024*1024;
62 
63 			report("%s[%s]", memsize == expected, testname, "mem");
64 			++nr_tests;
65 
66 		} else if (strcmp(var, "smp") == 0) {
67 
68 			report("%s[%s]", nr_cpus == (int)val, testname, "smp");
69 			++nr_tests;
70 		}
71 	}
72 
73 	assert_args(nr_tests, 2);
74 }
75 
76 int main(int argc, char **argv)
77 {
78 	testname_set(NULL);
79 	assert_args(argc, 1);
80 	testname_set(argv[0]);
81 
82 	if (strcmp(argv[0], "setup") == 0)
83 		check_setup(argc-1, &argv[1]);
84 
85 	return report_summary();
86 }
87