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>
"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)] = {};
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)