unit test
This commit is contained in:
parent
98d5a1a3bc
commit
54db58d362
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,5 +1,7 @@
|
||||
build
|
||||
cov
|
||||
*.out
|
||||
a.out
|
||||
*.c.out
|
||||
*.o
|
||||
*.s
|
||||
*.ans
|
10
README.md
10
README.md
@ -13,7 +13,7 @@
|
||||
|
||||
### 真机运行
|
||||
|
||||
编译运行程序,src 为本语言源代码。可以编译 demo 文件夹下的实例。
|
||||
编译运行程序,src 为本语言源代码。可以编译 demo 或 test 文件夹下的实例。
|
||||
|
||||
```sh
|
||||
$ sh run-native.sh <src>
|
||||
@ -33,7 +33,7 @@ $ sh boot-native.sh
|
||||
sudo apt install gcc-12-riscv64-linux-gnu qemu-user qemu-system-misc
|
||||
```
|
||||
|
||||
编译运行程序,src 为本语言源代码。可以编译 demo 文件夹下的实例。
|
||||
编译运行程序,src 为本语言源代码。可以编译 demo 或 test 文件夹下的实例。
|
||||
|
||||
```sh
|
||||
$ sh run.sh <src>
|
||||
@ -180,7 +180,11 @@ $ sh boot.sh
|
||||
|
||||
### 单元测试
|
||||
|
||||
TODO
|
||||
直接运行
|
||||
|
||||
```sh
|
||||
$ sh test.sh
|
||||
```
|
||||
|
||||
### 覆盖率
|
||||
|
||||
|
1
run.sh
1
run.sh
@ -3,3 +3,4 @@ gcc boot.c &&
|
||||
riscv64-linux-gnu-gcc-12 -static $1.s -o $1.out &&
|
||||
qemu-riscv64 $1.out
|
||||
echo $?
|
||||
rm $1.s $1.out
|
||||
|
20
test.sh
Normal file
20
test.sh
Normal file
@ -0,0 +1,20 @@
|
||||
cd test
|
||||
gcc ../boot.c
|
||||
all=0
|
||||
succ=0
|
||||
for i in *.c; do
|
||||
all=$((all+1))
|
||||
i=$(basename $i .c)
|
||||
./a.out < $i.c > $i.s &&
|
||||
riscv64-linux-gnu-gcc-12 -static $i.s -o $i.c.out &&
|
||||
qemu-riscv64 $i.c.out < $i.in > $i.ans
|
||||
echo $? >> $i.ans
|
||||
if cmp $i.out $i.ans; then
|
||||
succ=$((succ+1))
|
||||
echo "Test '$i' passed"
|
||||
else
|
||||
echo "Test '$i' failed"
|
||||
fi
|
||||
done
|
||||
echo "Passed $succ/$all tests"
|
||||
rm *.c.out *.s *.ans a.out
|
10
test/add.c
Normal file
10
test/add.c
Normal file
@ -0,0 +1,10 @@
|
||||
int printf(char* format, ...);
|
||||
int scanf(char* format, ...);
|
||||
|
||||
int main() {
|
||||
int a;
|
||||
int b;
|
||||
scanf("%d", &a);
|
||||
scanf("%d", &b);
|
||||
printf("%d\n", a + b);
|
||||
}
|
1
test/add.in
Normal file
1
test/add.in
Normal file
@ -0,0 +1 @@
|
||||
3 4
|
2
test/add.out
Normal file
2
test/add.out
Normal file
@ -0,0 +1,2 @@
|
||||
7
|
||||
0
|
0
test/hello.in
Normal file
0
test/hello.in
Normal file
2
test/hello.out
Normal file
2
test/hello.out
Normal file
@ -0,0 +1,2 @@
|
||||
hello world 42
|
||||
0
|
1
test/parse.in
Normal file
1
test/parse.in
Normal file
@ -0,0 +1 @@
|
||||
42
|
1
test/parse.out
Normal file
1
test/parse.out
Normal file
@ -0,0 +1 @@
|
||||
42
|
@ -16,9 +16,7 @@ void sort(int a[], int n) {
|
||||
int main() {
|
||||
int n;
|
||||
int a[100];
|
||||
printf("Enter the number of elements in the array: ");
|
||||
scanf("%d", &n);
|
||||
printf("Enter the elements of the array: ");
|
||||
for (int i = 0; i < n; i++) {
|
||||
scanf("%d", &a[i]);
|
||||
}
|
11
test/sort.in
Normal file
11
test/sort.in
Normal file
@ -0,0 +1,11 @@
|
||||
100
|
||||
13 49 15 58 24 74 80 81 69 23
|
||||
67 88 59 39 1 12 73 50 55 53
|
||||
71 63 9 90 87 89 51 75 40 84
|
||||
25 94 68 47 48 14 99 33 62 79
|
||||
66 85 56 31 38 29 86 46 70 6
|
||||
10 19 64 72 45 4 11 42 78 7
|
||||
95 27 93 57 21 35 5 22 76 54
|
||||
44 98 61 32 17 92 65 36 20 28
|
||||
83 2 18 60 16 41 30 37 100 97
|
||||
77 3 82 8 26 34 91 43 96 52
|
2
test/sort.out
Normal file
2
test/sort.out
Normal file
@ -0,0 +1,2 @@
|
||||
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
||||
0
|
Loading…
Reference in New Issue
Block a user