bug 1169: elf support, minor coding style adjustment, clearer
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 1 Dec 2023 14:42:25 +0000 (14:42 +0000)
committerJacob Lifshay <programmerjake@gmail.com>
Fri, 1 Dec 2023 20:49:02 +0000 (12:49 -0800)
src/openpower/test/elf/simple_cases.py

index 9e59bc8217c09c9ac87b345aca326986aece1c2b..f70467cce97574d0557cec7d2ff46933763afb99 100644 (file)
@@ -12,6 +12,7 @@ from openpower.test.common import TestAccumulatorBase, skip_case
 from openpower.test.state import ExpectedState
 from openpower.test.elf import compile_elf
 from openpower.consts import MSR, DEFAULT_MSR
+from copy import deepcopy
 
 SYSCALL_DEF = r"""
 #include <sys/syscall.h>
@@ -33,28 +34,15 @@ asm(".globl syscall\n"
     "blr");
 """
 
-# we have to specify *all* sprs that our binary might possibly need to
-# read, because ISACaller is annoying like that...
-# https://bugs.libre-soc.org/show_bug.cgi?id=1226#c2
-_INITIAL_SPRS = ('LR', 'CTR', 'TAR', 'SVSTATE', 'SRR0', 'SRR1',
-                 'SVSHAPE0', 'SVSHAPE1', 'SVSHAPE2', 'SVSHAPE3')
-
-DEFAULT_USER_MSR = DEFAULT_MSR | (1 << MSR.PR)
-
-class SimpleCases(TestAccumulatorBase):
-    def case_hello_world(self):
-        prog = compile_elf(SYSCALL_DEF + r"""
+hello_world = r"""
 void _start() {
     static const char msg[] = "Hello World!\n";
     syscall(SYS_write, 1, (const void *)msg, sizeof(msg) - 1);
     syscall(SYS_exit_group, 0);
 }
-""")
-        self.add_case(prog, initial_sprs=dict.fromkeys(_INITIAL_SPRS, 0),
-                      initial_msr=DEFAULT_USER_MSR)
+"""
 
-    def case_hello_world_with_data_and_bss(self):
-        prog = compile_elf(SYSCALL_DEF + r"""
+hello_word_data_bss = r"""
 const char msg_in_ro_data[] = "World!\n";
 char msg_in_data[] = "Hello ";
 char msg_in_bss[sizeof(msg_in_data)] = {};
@@ -67,14 +55,33 @@ void _start() {
     syscall(SYS_exit_group, 0);
 }
 """)
-        self.add_case(prog, initial_sprs=dict.fromkeys(_INITIAL_SPRS, 0),
-                      initial_msr=DEFAULT_USER_MSR)
 
-    def case_just_exit(self):
-        prog = compile_elf(SYSCALL_DEF + r"""
+just_exit = r"""
 void _start() {
     syscall(SYS_exit_group, 0);
-}
-""")
-        self.add_case(prog, initial_sprs=dict.fromkeys(_INITIAL_SPRS, 0),
+"""
+
+# we have to specify *all* sprs that our binary might possibly need to
+# read, because ISACaller is annoying like that...
+# https://bugs.libre-soc.org/show_bug.cgi?id=1226#c2
+INITIAL_SPRS = ('LR', 'CTR', 'TAR', 'SVSTATE', 'SRR0', 'SRR1',
+                 'SVSHAPE0', 'SVSHAPE1', 'SVSHAPE2', 'SVSHAPE3')
+initial_sprs = dict.fromkeys(INITIAL_SPRS, 0)
+
+DEFAULT_USER_MSR = DEFAULT_MSR | (1 << MSR.PR) # needs problem state
+
+class SimpleCases(TestAccumulatorBase):
+    def case_hello_world(self):
+        prog = compile_elf(SYSCALL_DEF + hello_world)
+        self.add_case(prog, initial_sprs=deepcopy(initial_sprs),
+                      initial_msr=DEFAULT_USER_MSR)
+
+    def case_hello_world_with_data_and_bss(self):
+        prog = compile_elf(SYSCALL_DEF + hello_word_data_bss)
+        self.add_case(prog, initial_sprs=deepcopy(initial_sprs),
+                      initial_msr=DEFAULT_USER_MSR)
+
+    def case_just_exit(self):
+        prog = compile_elf(SYSCALL_DEF + just_exit)
+        self.add_case(prog, initial_sprs=deepcopy(initial_sprs),
                       initial_msr=DEFAULT_USER_MSR)