elf/simple_cases: disable case_static_glibc for now, re-enable when we work on it...
[openpower-isa.git] / src / openpower / test / elf / simple_cases.py
1 # SPDX-License-Identifier: LGPLv3+
2 # Copyright (C) 2023 Jacob Lifshay <programmerjake@gmail.com>
3 # Funded by NLnet http://nlnet.nl
4 """ simple ELF test cases
5
6 related bugs:
7
8 * https://bugs.libre-soc.org/show_bug.cgi?id=1169
9 """
10
11 from openpower.test.common import TestAccumulatorBase, skip_case
12 from openpower.test.state import ExpectedState
13 from openpower.test.elf import compile_elf
14 from openpower.consts import MSR, DEFAULT_MSR
15
16 SYSCALL_DEF = r"""
17 #include <sys/syscall.h>
18
19 long syscall(long number, ...);
20
21 asm(".globl syscall\n"
22 ".p2align 4\n"
23 ".type syscall,@function\n"
24 "syscall:\n"
25 "mr 0,3\n"
26 "mr 3,4\n"
27 "mr 4,5\n"
28 "mr 5,6\n"
29 "mr 6,7\n"
30 "mr 7,8\n"
31 "mr 8,9\n"
32 "sc\n"
33 "blr");
34 """
35
36 hello_world = r"""
37 void _start() {
38 static const char msg[] = "Hello World!\n";
39 syscall(SYS_write, 1, (const void *)msg, sizeof(msg) - 1);
40 syscall(SYS_exit_group, 0);
41 }
42 """
43
44 hello_word_data_bss = r"""
45 const char msg_in_ro_data[] = "World!\n";
46 char msg_in_data[] = "Hello ";
47 char msg_in_bss[sizeof(msg_in_data)] = {};
48
49 void _start() {
50 for(int i = 0; i < sizeof(msg_in_data); i++)
51 msg_in_bss[i] = msg_in_data[i];
52 syscall(SYS_write, 1, (const void *)msg_in_bss, sizeof(msg_in_data) - 1);
53 syscall(SYS_write, 1, (const void *)msg_in_ro_data, sizeof(msg_in_ro_data) - 1);
54 syscall(SYS_exit_group, 0);
55 }
56 """
57
58 just_exit = r"""
59 void _start() {
60 syscall(SYS_exit_group, 0);
61 }
62 """
63
64 static_glibc = r"""
65 #include <stdio.h>
66
67 int main() {
68 printf("Hello World!\n");
69 return 0;
70 }
71 """
72
73 # we have to specify *all* sprs that our binary might possibly need to
74 # read, because ISACaller is annoying like that...
75 # https://bugs.libre-soc.org/show_bug.cgi?id=1226#c2
76 INITIAL_SPRS = ('LR', 'CTR', 'TAR', 'SVSTATE', 'SRR0', 'SRR1',
77 'SVSHAPE0', 'SVSHAPE1', 'SVSHAPE2', 'SVSHAPE3')
78 initial_sprs = dict.fromkeys(INITIAL_SPRS, 0)
79
80 DEFAULT_USER_MSR = DEFAULT_MSR | (1 << MSR.PR) # needs problem state
81
82 class SimpleCases(TestAccumulatorBase):
83 def case_hello_world(self):
84 prog = compile_elf(SYSCALL_DEF + hello_world)
85 self.add_case(prog, initial_sprs=initial_sprs.copy(),
86 initial_msr=DEFAULT_USER_MSR)
87
88 def case_hello_world_with_data_and_bss(self):
89 prog = compile_elf(SYSCALL_DEF + hello_word_data_bss)
90 self.add_case(prog, initial_sprs=initial_sprs.copy(),
91 initial_msr=DEFAULT_USER_MSR)
92
93 def case_just_exit(self):
94 prog = compile_elf(SYSCALL_DEF + just_exit)
95 self.add_case(prog, initial_sprs=initial_sprs.copy(),
96 initial_msr=DEFAULT_USER_MSR)
97
98 # FIXME: see https://bugs.libre-soc.org/show_bug.cgi?id=1228
99 @skip_case("Statically-linked glibc is known to not work")
100 def case_static_glibc(self):
101 # we enable debug info because it makes following along in gdb
102 # much easier.
103 compiler_args = '-Os', '-static', '-xc', '-g'
104 prog = compile_elf(static_glibc, compiler_args)
105 self.add_case(prog, initial_sprs=initial_sprs.copy(),
106 initial_msr=DEFAULT_USER_MSR)