Reworked unit tests for machine and renamed test_programs directory
This commit is contained in:
9
test/riscv_instructions/Makefile
Normal file
9
test/riscv_instructions/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
dumps:
|
||||
make dumps -C boolean_logic/
|
||||
make dumps -C jump_instructions/
|
||||
make dumps -C simple_arithmetics/
|
||||
|
||||
tests:
|
||||
make tests -C boolean_logic/
|
||||
make tests -C jump_instructions/
|
||||
make tests -C simple_arithmetics/
|
9
test/riscv_instructions/boolean_logic/Makefile
Normal file
9
test/riscv_instructions/boolean_logic/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/Makefile.tests
|
||||
|
||||
dumps: comparisons.dump if.dump switch.dump
|
||||
|
||||
tests: comparisons.guac if.guac switch.guac
|
||||
|
||||
# Dependances
|
||||
$(PROGRAMS): % : $(USERLIB)/sys.o $(USERLIB)/libnachos.o %.o
|
15
test/riscv_instructions/boolean_logic/comparisons.c
Normal file
15
test/riscv_instructions/boolean_logic/comparisons.c
Normal file
@ -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 0;
|
||||
}
|
||||
}
|
||||
}
|
10
test/riscv_instructions/boolean_logic/if.c
Normal file
10
test/riscv_instructions/boolean_logic/if.c
Normal file
@ -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;
|
||||
}
|
||||
}
|
17
test/riscv_instructions/boolean_logic/new_comparisons.c
Normal file
17
test/riscv_instructions/boolean_logic/new_comparisons.c
Normal file
@ -0,0 +1,17 @@
|
||||
int main() {
|
||||
int x = 0;
|
||||
int y = 1;
|
||||
while (x <= y) {
|
||||
if (x > y) {
|
||||
y += 1;
|
||||
}
|
||||
if (x == y) {
|
||||
x += y;
|
||||
}
|
||||
if (x < y) {
|
||||
x += 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
7
test/riscv_instructions/boolean_logic/switch.c
Normal file
7
test/riscv_instructions/boolean_logic/switch.c
Normal file
@ -0,0 +1,7 @@
|
||||
int main() {
|
||||
int x = 0;
|
||||
switch(x) {
|
||||
case 1: x = 1; break;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
6
test/riscv_instructions/jump_instructions/Makefile
Normal file
6
test/riscv_instructions/jump_instructions/Makefile
Normal file
@ -0,0 +1,6 @@
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/Makefile.tests
|
||||
|
||||
dumps: jump.dump ret.dump
|
||||
|
||||
tests: jump.guac ret.guac
|
8
test/riscv_instructions/jump_instructions/jump.c
Normal file
8
test/riscv_instructions/jump_instructions/jump.c
Normal file
@ -0,0 +1,8 @@
|
||||
int test() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int x = test();
|
||||
return x;
|
||||
}
|
3
test/riscv_instructions/jump_instructions/ret.c
Normal file
3
test/riscv_instructions/jump_instructions/ret.c
Normal file
@ -0,0 +1,3 @@
|
||||
int main() {
|
||||
return 1;
|
||||
}
|
6
test/riscv_instructions/simple_arithmetics/Makefile
Normal file
6
test/riscv_instructions/simple_arithmetics/Makefile
Normal file
@ -0,0 +1,6 @@
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/Makefile.tests
|
||||
|
||||
dumps: unsigned_addition.dump unsigned_division.dump unsigned_multiplication.dump unsigned_substraction.dump
|
||||
|
||||
tests: unsigned_addition.guac unsigned_division.guac unsigned_multiplication.guac unsigned_substraction.guac
|
15
test/riscv_instructions/simple_arithmetics/README.md
Normal file
15
test/riscv_instructions/simple_arithmetics/README.md
Normal file
@ -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
|
@ -0,0 +1,9 @@
|
||||
#include "userlib/syscall.h"
|
||||
#include "userlib/libnachos.h"
|
||||
|
||||
// EXPECTS TWO VARIABLES WITH A VALUE OF UNSIGNED 1
|
||||
int main() {
|
||||
unsigned int x = 0;
|
||||
unsigned int y = 1;
|
||||
x = x + y;
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
// Expecting two variables with a value of two
|
||||
int main() {
|
||||
unsigned int x = 4;
|
||||
unsigned int y = 2;
|
||||
x = x / y;
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
// EXPECTS TWO VARIABLES WITH A VALUE OF UNSIGNED 2
|
||||
int main() {
|
||||
unsigned int x = 1;
|
||||
unsigned int y = 2;
|
||||
x = x * y;
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
// EXPECTS TWO VARIABLES WITH A VALUE OF UNSIGNED 1
|
||||
int main() {
|
||||
unsigned int x = 1;
|
||||
unsigned int y = 1;
|
||||
x = x - y;
|
||||
}
|
Reference in New Issue
Block a user