mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-30 05:24:25 +01:00
gdb: create some automated tests with pytest
gem5 baremetal: use m5exit m5op in exit() so as to not force users to apply a patch for almost all examples
This commit is contained in:
13
baremetal/add.c
Normal file
13
baremetal/add.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <common.h>
|
||||
|
||||
void main(void) {
|
||||
int i, j, k;
|
||||
i = 1;
|
||||
/* test-gdb-op1 */
|
||||
j = 2;
|
||||
/* test-gdb-op2 */
|
||||
k = i + j;
|
||||
/* test-gdb-result */
|
||||
if (k != 3)
|
||||
assert_fail();
|
||||
}
|
||||
9
baremetal/add.py
Normal file
9
baremetal/add.py
Normal file
@@ -0,0 +1,9 @@
|
||||
def test(self):
|
||||
self.sendline('tbreak main')
|
||||
self.sendline('continue')
|
||||
self.continue_to('op1')
|
||||
assert self.get_int('i') == 1
|
||||
self.continue_to('op2')
|
||||
assert self.get_int('j') == 2
|
||||
self.continue_to('result')
|
||||
assert self.get_int('k') == 3
|
||||
12
baremetal/arch/aarch64/add.S
Normal file
12
baremetal/arch/aarch64/add.S
Normal file
@@ -0,0 +1,12 @@
|
||||
.global main
|
||||
main:
|
||||
/* 1 + 2 == 3 */
|
||||
mov x0, #1
|
||||
/* test-gdb-op1 */
|
||||
add x1, x0, #2
|
||||
/* test-gdb-result */
|
||||
cmp x1, #3
|
||||
beq 1f
|
||||
bl assert_fail
|
||||
1:
|
||||
ret
|
||||
7
baremetal/arch/aarch64/add.py
Normal file
7
baremetal/arch/aarch64/add.py
Normal file
@@ -0,0 +1,7 @@
|
||||
def test(self):
|
||||
self.sendline('tbreak main')
|
||||
self.sendline('continue')
|
||||
self.continue_to('op1')
|
||||
assert self.get_int('$x0') == 1
|
||||
self.continue_to('result')
|
||||
assert self.get_int('$x1') == 3
|
||||
12
baremetal/arch/arm/add.S
Normal file
12
baremetal/arch/arm/add.S
Normal file
@@ -0,0 +1,12 @@
|
||||
.global main
|
||||
main:
|
||||
/* 1 + 2 == 3 */
|
||||
mov r0, #1
|
||||
/* test-gdb-op1 */
|
||||
add r1, r0, #2
|
||||
/* test-gdb-result */
|
||||
cmp r1, #3
|
||||
beq 1f
|
||||
bl assert_fail
|
||||
1:
|
||||
bx lr
|
||||
7
baremetal/arch/arm/add.py
Normal file
7
baremetal/arch/arm/add.py
Normal file
@@ -0,0 +1,7 @@
|
||||
def test(self):
|
||||
self.sendline('tbreak main')
|
||||
self.sendline('continue')
|
||||
self.continue_to('op1')
|
||||
assert self.get_int('$r0') == 1
|
||||
self.continue_to('result')
|
||||
assert self.get_int('$r1') == 3
|
||||
@@ -2,5 +2,4 @@
|
||||
|
||||
void main(void) {
|
||||
puts("hello");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -61,6 +61,13 @@ int _write(int file, char *ptr, int len) {
|
||||
|
||||
/* Only 0 is supported for now, arm semihosting cannot handle other values. */
|
||||
void _exit(int status) {
|
||||
#if defined(GEM5)
|
||||
#if defined(__arm__)
|
||||
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; .inst 0xEE000110 | (0x21 << 16);");
|
||||
#elif defined(__aarch64__)
|
||||
__asm__ __volatile__ ("mov x0, #0; .inst 0XFF000110 | (0x21 << 16);");
|
||||
#endif
|
||||
#else
|
||||
#if defined(__arm__)
|
||||
__asm__ __volatile__ ("mov r0, #0x18; ldr r1, =#0x20026; svc 0x00123456");
|
||||
#elif defined(__aarch64__)
|
||||
@@ -76,6 +83,7 @@ void _exit(int status) {
|
||||
"hlt 0xf000\n"
|
||||
);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void assert_fail() {
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
void main(void) {
|
||||
return;
|
||||
}
|
||||
void main(void) {}
|
||||
|
||||
Reference in New Issue
Block a user