xref: /kvm-unit-tests/s390x/selftest.c (revision 4363f1d9a646a5c7ea673bee8fc33ca6f2cddbd8)
1 /*
2  * Copyright (c) 2017 Red Hat Inc
3  *
4  * Authors:
5  *  Thomas Huth <thuth@redhat.com>
6  *  David Hildenbrand <david@redhat.com>
7  *
8  * This code is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Library General Public License version 2.
10  */
11 #include <libcflat.h>
12 #include <util.h>
13 #include <asm/interrupt.h>
14 
15 static void test_fp(void)
16 {
17 	double a = 3.0;
18 	double b = 2.0;
19 	double c;
20 
21 	asm volatile(
22 		"	ddb %1, %2\n"
23 		"	std %1, %0\n"
24 		: "=m" (c) : "f" (a), "m" (b));
25 
26 	report("3.0/2.0 == 1.5", c == 1.5);
27 }
28 
29 static void test_pgm_int(void)
30 {
31 	expect_pgm_int();
32 	asm volatile("	.insn e,0x0000"); /* used for SW breakpoints in QEMU */
33 	check_pgm_int_code(PGM_INT_CODE_OPERATION);
34 
35 	expect_pgm_int();
36 	asm volatile("	stg %0,0(%0)\n" : : "r"(-1));
37 	check_pgm_int_code(PGM_INT_CODE_ADDRESSING);
38 }
39 
40 int main(int argc, char**argv)
41 {
42 	report_prefix_push("selftest");
43 
44 	report("true", true);
45 	report("argc == 3", argc == 3);
46 	report("argv[0] == PROGNAME", !strcmp(argv[0], "s390x/selftest.elf"));
47 	report("argv[1] == test", !strcmp(argv[1], "test"));
48 	report("argv[2] == 123", !strcmp(argv[2], "123"));
49 
50 	test_fp();
51 	test_pgm_int();
52 
53 	return report_summary();
54 }
55