Skip to content

Commit

Permalink
Added Unit Tests
Browse files Browse the repository at this point in the history
Added unit tests to verify that when the `brk` syscall is called with illegal arguments (causing a stack-heap collision), the syscall returns a non-zero value, indicating that it was not executed successfully.
  • Loading branch information
federicovilla55 committed Aug 29, 2024
1 parent 17f7d76 commit 4deccba
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/riscv-tests-64/brk_syscall.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.text
.globl _start
_start: nop

#-------------------------------------------------------------
# Stack-Heap Collision brk syscall Test
#-------------------------------------------------------------

test_0: # Test Ecall Return Value
mv a0, sp # Assign the ecall parameter to the stack pointer value
lw a7, BRK # Load the brk syscall immediate value
ecall

# If the return value of the ecall is zero, then the ecall
# was executed successfully and therefore the test failed
beqz a0, fail

bne x0, gp, pass

pass:
li a0, 42
li a7, 93
ecall


fail:
li a0, 0
li a7, 93
ecall

.data
.align 4

# Syscall immediate value
BRK: .word 214
27 changes: 27 additions & 0 deletions test/riscv-tests/brk_syscall.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.text

#-------------------------------------------------------------
# Stack-Heap Collision brk syscall Test
#-------------------------------------------------------------

test_0: # Test Ecall Return Value
mv a0, sp # Assign the ecall parameter to the stack pointer value
li a7, 214 # Load the brk syscall immediate value
ecall

# If the return value of the ecall is zero, then the ecall
# was executed successfully and therefore the test failed
beqz a0, fail

bne x0, gp, pass

pass:
li a0, 42
li a7, 93
ecall


fail:
li a0, 0
li a7, 93
ecall

0 comments on commit 4deccba

Please sign in to comment.