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
8 * https://bugs.libre-soc.org/show_bug.cgi?id=1169
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 from copy
import deepcopy
18 #include <sys/syscall.h>
20 long syscall(long number, ...);
22 asm(".globl syscall\n"
24 ".type syscall,@function\n"
39 static const char msg[] = "Hello World!\n";
40 syscall(SYS_write, 1, (const void *)msg, sizeof(msg) - 1);
41 syscall(SYS_exit_group, 0);
45 hello_word_data_bss
= r
"""
46 const char msg_in_ro_data[] = "World!\n";
47 char msg_in_data[] = "Hello ";
48 char msg_in_bss[sizeof(msg_in_data)] = {};
51 for(int i = 0; i < sizeof(msg_in_data); i++)
52 msg_in_bss[i] = msg_in_data[i];
53 syscall(SYS_write, 1, (const void *)msg_in_bss, sizeof(msg_in_data) - 1);
54 syscall(SYS_write, 1, (const void *)msg_in_ro_data, sizeof(msg_in_ro_data) - 1);
55 syscall(SYS_exit_group, 0);
61 syscall(SYS_exit_group, 0);
64 # we have to specify *all* sprs that our binary might possibly need to
65 # read, because ISACaller is annoying like that...
66 # https://bugs.libre-soc.org/show_bug.cgi?id=1226#c2
67 INITIAL_SPRS
= ('LR', 'CTR', 'TAR', 'SVSTATE', 'SRR0', 'SRR1',
68 'SVSHAPE0', 'SVSHAPE1', 'SVSHAPE2', 'SVSHAPE3')
69 initial_sprs
= dict.fromkeys(INITIAL_SPRS
, 0)
71 DEFAULT_USER_MSR
= DEFAULT_MSR |
(1 << MSR
.PR
) # needs problem state
73 class SimpleCases(TestAccumulatorBase
):
74 def case_hello_world(self
):
75 prog
= compile_elf(SYSCALL_DEF
+ hello_world
)
76 self
.add_case(prog
, initial_sprs
=deepcopy(initial_sprs
),
77 initial_msr
=DEFAULT_USER_MSR
)
79 def case_hello_world_with_data_and_bss(self
):
80 prog
= compile_elf(SYSCALL_DEF
+ hello_word_data_bss
)
81 self
.add_case(prog
, initial_sprs
=deepcopy(initial_sprs
),
82 initial_msr
=DEFAULT_USER_MSR
)
84 def case_just_exit(self
):
85 prog
= compile_elf(SYSCALL_DEF
+ just_exit
)
86 self
.add_case(prog
, initial_sprs
=deepcopy(initial_sprs
),
87 initial_msr
=DEFAULT_USER_MSR
)