From fe930e4a0dbb66c9ce6e3211173ec050dd0b7c39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Autin?= Date: Wed, 8 Feb 2023 15:01:41 +0000 Subject: [PATCH] ONGOING: Test programs --- test_programs/Makefile | 14 ++++++++++ test_programs/Makefile.config | 18 ++++++++++++ test_programs/Makefile.objdumps | 24 ++++++++++++++++ test_programs/README.md | 28 +++++++++++++++++++ test_programs/riscv_instructions/Makefile | 2 ++ .../boolean_logic/comparisons.c | 15 ++++++++++ .../riscv_instructions/boolean_logic/if.c | 10 +++++++ .../riscv_instructions/boolean_logic/switch.c | 7 +++++ .../jump_instructions/jump.c | 7 +++++ .../jump_instructions/ret.c | 3 ++ .../simple_arithmerics/README.md | 15 ++++++++++ .../simple_arithmerics/unsigned_addition.c | 6 ++++ .../simple_arithmerics/unsigned_division.c | 6 ++++ .../unsigned_multiplication.c | 6 ++++ .../unsigned_substraction.c | 6 ++++ 15 files changed, 167 insertions(+) create mode 100644 test_programs/Makefile create mode 100644 test_programs/Makefile.config create mode 100644 test_programs/Makefile.objdumps create mode 100644 test_programs/README.md create mode 100644 test_programs/riscv_instructions/Makefile create mode 100644 test_programs/riscv_instructions/boolean_logic/comparisons.c create mode 100644 test_programs/riscv_instructions/boolean_logic/if.c create mode 100644 test_programs/riscv_instructions/boolean_logic/switch.c create mode 100644 test_programs/riscv_instructions/jump_instructions/jump.c create mode 100644 test_programs/riscv_instructions/jump_instructions/ret.c create mode 100644 test_programs/riscv_instructions/simple_arithmerics/README.md create mode 100644 test_programs/riscv_instructions/simple_arithmerics/unsigned_addition.c create mode 100644 test_programs/riscv_instructions/simple_arithmerics/unsigned_division.c create mode 100644 test_programs/riscv_instructions/simple_arithmerics/unsigned_multiplication.c create mode 100644 test_programs/riscv_instructions/simple_arithmerics/unsigned_substraction.c diff --git a/test_programs/Makefile b/test_programs/Makefile new file mode 100644 index 0000000..e15867e --- /dev/null +++ b/test_programs/Makefile @@ -0,0 +1,14 @@ +TOPDIR=. +include $(TOPDIR)/Makefile.config + +# +# Main targets +# +objdumps: + $(MAKE) -C riscv_instructions + +programs: + $(MAKE) -C programs + +clean: + rm -rf $(TOPDIR)/target \ No newline at end of file diff --git a/test_programs/Makefile.config b/test_programs/Makefile.config new file mode 100644 index 0000000..fca5849 --- /dev/null +++ b/test_programs/Makefile.config @@ -0,0 +1,18 @@ +# This is part of a GNU -*- Makefile -*-, to specify system-dependent +# parts of the Makefile enviroment. +# +# This gets included as part of the GNU-Makefile used in each of +# the subdirectories. +# +# Depending on your platform, you need to select the correct definition. + +## RISCV target compilation toolchain +RISCV_PREFIX=/opt/riscv/bin/ +RISCV_AS = $(RISCV_PREFIX)riscv64-unknown-elf-gcc -x assembler-with-cpp -march=rv64imfd +RISCV_GCC = $(RISCV_PREFIX)riscv64-unknown-elf-gcc +RISCV_LD = $(RISCV_PREFIX)riscv64-unknown-elf-ld +RISCV_OBJDUMP = $(RISCV_PREFIX)riscv64-unknown-elf-objdump +RISCV_ASFLAGS = $(RISCV_CPPFLAGS) +RISCV_CPPFLAGS = #nil +RISCV_CFLAGS = -Wall $(RISCV_CPPFLAGS) -march=rv64imfd +RISCV_LDFLAGS = #nil diff --git a/test_programs/Makefile.objdumps b/test_programs/Makefile.objdumps new file mode 100644 index 0000000..78a4520 --- /dev/null +++ b/test_programs/Makefile.objdumps @@ -0,0 +1,24 @@ +include $(TOPDIR)/Makefile.config + +COVERAGE = $(TOPDIR)/riscv_instructions + +AS = $(RISCV_AS) -c +GCC = $(RISCV_GCC) +LD = $(RISCV_LD) + +INCPATH += -I$(TOPDIR) -I$(COVERAGE) +ASFLAGS = $(RISCV_ASFLAGS) $(INCPATH) +CFLAGS = $(RISCV_CFLAGS) $(INCPATH) + +# Rules +%.a: + $(AR) rcv $@ $^ + +%.o: %.c + $(GCC) $(CFLAGS) -c $< + +%.o: %.s + $(AS) $(ASFLAGS) -c $< + +$(PROGRAMS): + $(LD) $+ -o $@ \ No newline at end of file diff --git a/test_programs/README.md b/test_programs/README.md new file mode 100644 index 0000000..6e73dba --- /dev/null +++ b/test_programs/README.md @@ -0,0 +1,28 @@ +# BurritOS Test programs +This folder contains small C programs pertaining to the assessment of the correctness of BurritOS' behavior. + +## Folder Structure + - **riscv_instructions**: contains small programs for testing simulator instruction coverage. + +## How to build +### In the Makefile.config file +Set the variables to the correct paths for the [RISCV Newlib compilation toolchain](https://github.com/riscv-collab/riscv-gnu-toolchain). Simply changing the `RISCV_PREFIX` variable should do the trick. **Do not forget to add a trailing slash**. + +### Exporting objdumps + +``` +$ make objdumps +``` + +### Compiling programs +``` +$ make programs +``` + +### Cleaning +``` +$ make clean +``` + +### Output folder +Compilation results are located in the target/objdumps and target/programs directories. \ No newline at end of file diff --git a/test_programs/riscv_instructions/Makefile b/test_programs/riscv_instructions/Makefile new file mode 100644 index 0000000..29df4bd --- /dev/null +++ b/test_programs/riscv_instructions/Makefile @@ -0,0 +1,2 @@ +TOPDIR = ../ +include $(TOPDIR)/Makefile.objdumps diff --git a/test_programs/riscv_instructions/boolean_logic/comparisons.c b/test_programs/riscv_instructions/boolean_logic/comparisons.c new file mode 100644 index 0000000..f653fff --- /dev/null +++ b/test_programs/riscv_instructions/boolean_logic/comparisons.c @@ -0,0 +1,15 @@ +int main() { + int x = 0; + int y = 1; + while (x <= y) { + if (x > y) { + x += 1; + } else if (x == y) { + x += y; + } else if (x < y) { + y += 1; + } else { + return; + } + } +} \ No newline at end of file diff --git a/test_programs/riscv_instructions/boolean_logic/if.c b/test_programs/riscv_instructions/boolean_logic/if.c new file mode 100644 index 0000000..2a11b58 --- /dev/null +++ b/test_programs/riscv_instructions/boolean_logic/if.c @@ -0,0 +1,10 @@ +int main() { + int x = 1; + if (x == 1 && x > 0) { + x = 2; + } else if (x || x == 0 ) { + x = 3; + } else { + x = 0; + } +} \ No newline at end of file diff --git a/test_programs/riscv_instructions/boolean_logic/switch.c b/test_programs/riscv_instructions/boolean_logic/switch.c new file mode 100644 index 0000000..86a181c --- /dev/null +++ b/test_programs/riscv_instructions/boolean_logic/switch.c @@ -0,0 +1,7 @@ +int main() { + int x = 0; + switch(1) { + case 1: x = 1; break; + default: return; + } +} \ No newline at end of file diff --git a/test_programs/riscv_instructions/jump_instructions/jump.c b/test_programs/riscv_instructions/jump_instructions/jump.c new file mode 100644 index 0000000..c4fd641 --- /dev/null +++ b/test_programs/riscv_instructions/jump_instructions/jump.c @@ -0,0 +1,7 @@ +int test() { + return 1; +} + +int main() { + int x = test(); +} \ No newline at end of file diff --git a/test_programs/riscv_instructions/jump_instructions/ret.c b/test_programs/riscv_instructions/jump_instructions/ret.c new file mode 100644 index 0000000..84eb8ea --- /dev/null +++ b/test_programs/riscv_instructions/jump_instructions/ret.c @@ -0,0 +1,3 @@ +int main() { + return 1; +} \ No newline at end of file diff --git a/test_programs/riscv_instructions/simple_arithmerics/README.md b/test_programs/riscv_instructions/simple_arithmerics/README.md new file mode 100644 index 0000000..031c1be --- /dev/null +++ b/test_programs/riscv_instructions/simple_arithmerics/README.md @@ -0,0 +1,15 @@ +# Simple arithmetics program + +These allow to check whether the following instructions are correctly implemented. + +- addi +- sd +- sw +- li +- sw +- lw +- mv +- addw +- nop +- ld +- ret \ No newline at end of file diff --git a/test_programs/riscv_instructions/simple_arithmerics/unsigned_addition.c b/test_programs/riscv_instructions/simple_arithmerics/unsigned_addition.c new file mode 100644 index 0000000..2881ac7 --- /dev/null +++ b/test_programs/riscv_instructions/simple_arithmerics/unsigned_addition.c @@ -0,0 +1,6 @@ +// EXPECTS TWO VARIABLES WITH A VALUE OF UNSIGNED 1 +void main() { + unsigned int x = 0; + unsigned int y = 1; + x = x + y; +} \ No newline at end of file diff --git a/test_programs/riscv_instructions/simple_arithmerics/unsigned_division.c b/test_programs/riscv_instructions/simple_arithmerics/unsigned_division.c new file mode 100644 index 0000000..729f889 --- /dev/null +++ b/test_programs/riscv_instructions/simple_arithmerics/unsigned_division.c @@ -0,0 +1,6 @@ +// Expecting two variables with a value of two +void main() { + unsigned int x = 4; + unsigned int y = 2; + x = x / y; +} \ No newline at end of file diff --git a/test_programs/riscv_instructions/simple_arithmerics/unsigned_multiplication.c b/test_programs/riscv_instructions/simple_arithmerics/unsigned_multiplication.c new file mode 100644 index 0000000..c79294d --- /dev/null +++ b/test_programs/riscv_instructions/simple_arithmerics/unsigned_multiplication.c @@ -0,0 +1,6 @@ +// EXPECTS TWO VARIABLES WITH A VALUE OF UNSIGNED 2 +void main() { + unsigned int x = 1; + unsigned int y = 2; + x = x * y; +} \ No newline at end of file diff --git a/test_programs/riscv_instructions/simple_arithmerics/unsigned_substraction.c b/test_programs/riscv_instructions/simple_arithmerics/unsigned_substraction.c new file mode 100644 index 0000000..dd4e09b --- /dev/null +++ b/test_programs/riscv_instructions/simple_arithmerics/unsigned_substraction.c @@ -0,0 +1,6 @@ +// EXPECTS TWO VARIABLES WITH A VALUE OF UNSIGNED 1 +void main() { + unsigned int x = 1; + unsigned int y = 1; + x = x - y; +} \ No newline at end of file