Skip to content

Commit c08be00

Browse files
committed
Improved test scripts
1 parent bcfb846 commit c08be00

File tree

7 files changed

+109
-102
lines changed

7 files changed

+109
-102
lines changed

unittest/clean.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/sh
2+
echo "Clean test files..."
23
if [ -f unittest.c ]
34
then
45
rm -f _*.txt gmon.out

unittest/run_all.sh

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#!/bin/sh
2-
echo "Run all tests..."
3-
date
4-
echo ""
5-
./run_normal.sh
6-
./run_sanitizer.sh
7-
./run_gprof.sh
8-
./run_valgrind.sh
9-
./run_compare.sh
10-
echo ""
11-
echo "Done"
2+
OUT=_report.txt
3+
echo "Run all tests..." | tee $OUT
4+
date | tee -a $OUT
5+
echo "" | tee -a $OUT
6+
./run_normal.sh | tee -a $OUT
7+
./run_sanitizer.sh | tee -a $OUT
8+
./run_gprof.sh | tee -a $OUT
9+
./run_valgrind.sh | tee -a $OUT
10+
./run_compare.sh | tee -a $OUT
11+
echo "" | tee -a $OUT
12+
echo "Done" | tee -a $OUT

unittest/run_compare.sh

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/bin/sh
2-
REPORT=_report_compare.txt
32
OPTS="-Wall -Werror -Wno-pointer-to-int-cast"
43

54
NEW=../utility/mapcode
6-
OLD=$HOME/bin/mapcode-2.3.1
5+
OLD=$HOME/bin/mapcode-2.3.0
6+
NEWFILE=_new.txt
7+
OLDFILE=_old.txt
78

89
OPTS1="--grid 1000000 8"
910
OPTS2="--random 1000000 8 1234"
@@ -16,13 +17,13 @@ then
1617
exit 1
1718
fi
1819

19-
echo "!! -------------------------------------------------------------" | tee -a $REPORT
20-
echo "Run compare with previous output..." | tee $REPORT
21-
date | tee -a $REPORT
22-
echo "!! -------------------------------------------------------------" | tee -a $REPORT
20+
echo "!! -------------------------------------------------------------"
21+
echo "Run compare with previous output..."
22+
date
23+
echo "!! -------------------------------------------------------------"
2324

24-
echo "" | tee -a $REPORT
25-
echo "Run with: -O3" | tee -a $REPORT
25+
echo ""
26+
echo "Run with: -O3"
2627
cd ../mapcodelib
2728
gcc $OPTS -O3 -c mapcoder.c
2829
cd ../utility
@@ -37,51 +38,59 @@ then
3738
fi
3839

3940
echo ""
40-
echo "Execute: $NEW $OPTS1" | tee -a $REPORT
41-
$NEW | grep version | tee -a $REPORT
42-
$NEW $OPTS1 > _new_1.txt | tee -a $REPORT
41+
echo "Execute: $NEW $OPTS1"
42+
$NEW | grep version
43+
$NEW $OPTS1 > $NEWFILE
4344

4445
echo ""
45-
echo "Execute: $OLD $OPTS1" | tee -a $REPORT
46-
$OLD | grep version | tee -a $REPORT
47-
$OLD $OPTS1 > _old_1.txt | tee -a $REPORT
48-
diff _new_1.txt _old_1.txt | tee -a $REPORT
46+
echo "Execute: $OLD $OPTS1"
47+
$OLD | grep version
48+
$OLD $OPTS1 > $OLDFILE
49+
diff $NEWFILE $OLDFILE
4950
if [ $? -ne 0 ]
5051
then
51-
echo "ERROR: Diffs found with: " $OPTS1 | tee -a $REPORT
52+
echo "ERROR: Diffs found with:" $OPTS1
53+
exit 1
54+
else
55+
rm -f $NEWFILE $OLDFILE
5256
fi
5357

5458
echo ""
55-
echo "Execute: $NEW $OPTS2" | tee -a $REPORT
56-
$NEW | grep version | tee -a $REPORT
57-
$NEW $OPTS2 > _new_2.txt | tee -a $REPORT
59+
echo "Execute: $NEW $OPTS2"
60+
$NEW | grep version
61+
$NEW $OPTS2 > $NEWFILE
5862

5963
echo ""
60-
echo "Execute: $OLD $OPTS2" | tee -a $REPORT
61-
$OLD | grep version | tee -a $REPORT
62-
$OLD $OPTS2 > _old_2.txt | tee -a $REPORT
63-
diff _new_2.txt _old_2.txt | tee -a $REPORT
64+
echo "Execute: $OLD $OPTS2"
65+
$OLD | grep version
66+
$OLD $OPTS2 > $OLDFILE
67+
diff $NEWFILE $OLDFILE
6468
if [ $? -ne 0 ]
6569
then
66-
echo "ERROR: Diffs found with: " $OPTS2 | tee -a $REPORT
70+
echo "ERROR: Diffs found with:" $OPTS2
71+
exit 1
72+
else
73+
rm -f $NEWFILE $OLDFILE
6774
fi
6875

6976
echo ""
70-
echo "Execute: $NEW $OPTS3" | tee -a $REPORT
71-
$NEW | grep version | tee -a $REPORT
72-
$NEW $OPTS3 > _new_3.txt | tee -a $REPORT
77+
echo "Execute: $NEW $OPTS3"
78+
$NEW | grep version
79+
$NEW $OPTS3 > $NEWFILE
7380

7481
echo ""
75-
echo "Execute: $OLD $OPTS3" | tee -a $REPORT
76-
$OLD | grep version | tee -a $REPORT
77-
$OLD $OPTS3 > _old_3.txt | tee -a $REPORT
78-
diff _new_3.txt _old_3.txt | tee -a $REPORT
82+
echo "Execute: $OLD $OPTS3"
83+
$OLD | grep version
84+
$OLD $OPTS3 > $OLDFILE
85+
diff $NEWFILE $OLDFILE
7986
if [ $? -ne 0 ]
8087
then
81-
echo "ERROR: Diffs found with: " $OPTS3 | tee -a $REPORT
88+
echo "ERROR: Diffs found with:" $OPTS3
89+
exit 1
90+
else
91+
rm -f $NEWFILE $OLDFILE
8292
fi
93+
echo "!! -------------------------------------------------------------"
8394

84-
echo "!! -------------------------------------------------------------" | tee -a $REPORT
85-
86-
echo "" | tee -a $REPORT
95+
echo ""
8796
echo "Report in: $REPORT"

unittest/run_gprof.sh

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/sh
2-
REPORT=_report_gprof.txt
32
OPTS="-Wall -Werror -Wno-pointer-to-int-cast"
43
LIB="../mapcodelib/mapcoder.o"
54

@@ -10,30 +9,30 @@ then
109
exit 1
1110
fi
1211

13-
echo "!! -------------------------------------------------------------" | tee -a $REPORT
14-
echo "Run gprof profiler..." | tee $REPORT
15-
date | tee -a $REPORT
16-
echo "!! -------------------------------------------------------------" | tee -a $REPORT
12+
echo "!! -------------------------------------------------------------"
13+
echo "Run gprof profiler..."
14+
date
15+
echo "!! -------------------------------------------------------------"
1716

18-
echo "" | tee -a $REPORT
19-
echo "Run with: -O0" | tee -a $REPORT
17+
echo ""
18+
echo "Run with: -O0"
2019
cd ../mapcodelib
2120
gcc $OPTS -g -O0 -c mapcoder.c -pg
2221
cd ../unittest
2322
gcc $OPTS -g -O0 unittest.c -lm -lpthread -o unittest $LIB -pg
24-
./unittest | tee -a $REPORT
25-
gprof ./unittest | tee -a $REPORT
26-
echo "!! -------------------------------------------------------------" | tee -a $REPORT
23+
./unittest
24+
gprof ./unittest
25+
echo "!! -------------------------------------------------------------"
2726

28-
echo "" | tee -a $REPORT
29-
echo "Run with: -O3" | tee -a $REPORT
27+
echo ""
28+
echo "Run with: -O3"
3029
cd ../mapcodelib
3130
gcc $OPTS -g -O3 -c mapcoder.c -pg
3231
cd ../unittest
3332
gcc $OPTS -g -O3 unittest.c -lm -lpthread -o unittest $LIB -pg
34-
./unittest | tee -a $REPORT
35-
gprof ./unittest | tee -a $REPORT
36-
echo "!! -------------------------------------------------------------" | tee -a $REPORT
33+
./unittest
34+
gprof ./unittest
35+
echo "!! -------------------------------------------------------------"
3736

38-
echo "" | tee -a $REPORT
37+
echo ""
3938
echo "Report in: $REPORT"

unittest/run_normal.sh

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
#!/bin/sh
2-
REPORT=_report_normal.txt
32
OPTS="-Wall -Werror -Wno-pointer-to-int-cast"
43

5-
echo "!! -------------------------------------------------------------" | tee -a $REPORT
6-
echo "Run normal..." | tee $REPORT
7-
date | tee -a $REPORT
8-
echo "!! -------------------------------------------------------------" | tee -a $REPORT
4+
echo "!! -------------------------------------------------------------"
5+
echo "Run normal..."
6+
date
7+
echo "!! -------------------------------------------------------------"
98

10-
echo "" | tee -a $REPORT
11-
echo "Run with: -O0" | tee -a $REPORT
9+
echo ""
10+
echo "Run with: -O0"
1211
cd ../mapcodelib
1312
gcc $OPTS -O0 -DDEBUG -c mapcoder.c
1413
cd ../unittest
1514
gcc $OPTS -O0 -DDEBUG unittest.c -lm -lpthread -o unittest ../mapcodelib/mapcoder.o
16-
./unittest | tee -a $REPORT
17-
echo "!! -------------------------------------------------------------" | tee -a $REPORT
15+
./unittest
16+
echo "!! -------------------------------------------------------------"
1817

19-
echo "" | tee -a $REPORT
20-
echo "Run with: -O3" | tee -a $REPORT
18+
echo ""
19+
echo "Run with: -O3"
2120
cd ../mapcodelib
2221
gcc $OPTS -O3 -c mapcoder.c
2322
cd ../unittest
2423
gcc $OPTS -O3 unittest.c -lm -lpthread -o unittest ../mapcodelib/mapcoder.o
25-
./unittest | tee -a $REPORT
26-
echo "!! -------------------------------------------------------------" | tee -a $REPORT
24+
./unittest
25+
echo "!! -------------------------------------------------------------"
2726

28-
echo "" | tee -a $REPORT
27+
echo ""
2928
echo "Report in: $REPORT"

unittest/run_sanitizer.sh

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/sh
2-
REPORT=_report_sanitizer.txt
32
OPTS="-Wall -Werror -Wno-pointer-to-int-cast"
43
LIB="../mapcodelib/mapcoder.o"
54

@@ -12,40 +11,40 @@ then
1211
exit 1
1312
fi
1413

15-
echo "!! -------------------------------------------------------------" | tee -a $REPORT
16-
echo "Run address sanitizer..." | tee $REPORT
17-
date | tee -a $REPORT
18-
echo "!! -------------------------------------------------------------" | tee -a $REPORT
14+
echo "!! -------------------------------------------------------------"
15+
echo "Run address sanitizer..."
16+
date
17+
echo "!! -------------------------------------------------------------"
1918

2019
# No optimize
21-
echo "" | tee -a $REPORT
22-
echo "Run with: -O0" | tee -a $REPORT
20+
echo ""
21+
echo "Run with: -O0"
2322
cd ../mapcodelib
2423
gcc $OPTS -O0 -DDEBUG -c mapcoder.c
2524
cd ../unittest
2625
gcc $OPTS -O0 -DDEBUG unittest.c -lm -lpthread -fsanitize=address -o unittest $LIB
27-
./unittest | tee -a $REPORT
28-
echo "!! -------------------------------------------------------------" | tee -a $REPORT
26+
./unittest
27+
echo "!! -------------------------------------------------------------"
2928

3029
# Optimize 2
31-
echo "" | tee -a $REPORT
32-
echo "Run with: -O2" | tee -a $REPORT
30+
echo ""
31+
echo "Run with: -O2"
3332
cd ../mapcodelib
3433
gcc $OPTS -O2 -c mapcoder.c
3534
cd ../unittest
3635
gcc $OPTS -O2 unittest.c -lm -lpthread -fsanitize=address -o unittest $LIB
37-
./unittest | tee -a $REPORT
38-
echo "!! -------------------------------------------------------------" | tee -a $REPORT
36+
./unittest
37+
echo "!! -------------------------------------------------------------"
3938

4039
# Optimize 3
41-
echo "" | tee -a $REPORT
42-
echo "Run with: -O3" | tee -a $REPORT
40+
echo ""
41+
echo "Run with: -O3"
4342
cd ../mapcodelib
4443
gcc $OPTS -O3 -c mapcoder.c
4544
cd ../unittest
4645
gcc $OPTS -O3 unittest.c -lm -lpthread -fsanitize=address -o unittest $LIB
47-
./unittest | tee -a $REPORT
48-
echo "!! -------------------------------------------------------------" | tee -a $REPORT
46+
./unittest
47+
echo "!! -------------------------------------------------------------"
4948

50-
echo "" | tee -a $REPORT
49+
echo ""
5150
echo "Report in: $REPORT"

unittest/run_valgrind.sh

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/sh
2-
REPORT=_report_valgrind.txt
32
OPTS="-Wall -Werror -Wno-pointer-to-int-cast"
43
LIB="../mapcodelib/mapcoder.o"
54

@@ -10,19 +9,19 @@ then
109
exit 1
1110
fi
1211

13-
echo "!! -------------------------------------------------------------" | tee -a $REPORT
14-
echo "Run valgrind" | tee $REPORT
15-
date | tee -a $REPORT
16-
echo "!! -------------------------------------------------------------" | tee -a $REPORT
12+
echo "!! -------------------------------------------------------------"
13+
echo "Run valgrind"
14+
date
15+
echo "!! -------------------------------------------------------------"
1716

18-
echo "" | tee -a $REPORT
19-
echo "Run with: -O0" | tee -a report_valgrind.txt
17+
echo ""
18+
echo "Run with: -O0"
2019
cd ../mapcodelib
2120
gcc $OPTS -g -O0 -c mapcoder.c
2221
cd ../unittest
2322
gcc $OPTS -g -O0 unittest.c -lm -lpthread -o unittest $LIB
24-
valgrind --leak-check=yes ./unittest | tee -a $REPORT
25-
echo "!! -------------------------------------------------------------" | tee -a $REPORT
23+
valgrind --leak-check=yes ./unittest
24+
echo "!! -------------------------------------------------------------"
2625

2726
echo "" tee -a $REPORT
2827
echo "Report in: $REPORT"

0 commit comments

Comments
 (0)