forked from brahem01/corewar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·153 lines (135 loc) · 5.79 KB
/
test.sh
File metadata and controls
executable file
·153 lines (135 loc) · 5.79 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Directories
REF_DIR="playground/players_src"
YOURS_DIR="players/bin"
# Test files
TEST_FILES=(
"empty_player.cor"
"live.cor"
"pierino_add.cor"
"pierino_and_ind_ind.cor"
"pierino_and_ind_reg.cor"
"pierino_and_reg_ind.cor"
"pierino_and_reg_reg.cor"
"pierino_fork.cor"
"pierino_ldi_dir_dir.cor"
"pierino_ldi_dir_reg.cor"
"pierino_ldi_ind_dir.cor"
"pierino_ldi_ind_reg.cor"
"pierino_ldi_reg_dir.cor"
"pierino_ldi_reg_reg.cor"
"pierino_ld.cor"
"pierino_lld_dir_reg.cor"
"pierino_lldi_dir_dir_reg.cor"
"pierino_lldi_dir_reg_reg.cor"
"pierino_lldi_ind_dir_reg.cor"
"pierino_lldi_ind_reg_reg.cor"
"pierino_lld_ind_reg.cor"
"pierino_lldi_reg_dir_reg.cor"
"pierino_lldi_reg_reg_reg.cor"
"pierino_or_ind_ind.cor"
"pierino_or_ind_reg.cor"
"pierino_or_reg_ind.cor"
"pierino_or_reg_reg.cor"
"pierino_st_ind.cor"
"pierino_sti_reg_dir_dir.cor"
"pierino_sti_reg_dir_reg.cor"
"pierino_sti_reg_ind_dir.cor"
"pierino_sti_reg_ind_reg.cor"
"pierino_sti_reg_reg_dir.cor"
"pierino_sti_reg_reg_reg.cor"
"pierino_st_reg.cor"
"pierino_sub.cor"
"pierino_test.cor"
"pierino_xor_ind_ind.cor"
"pierino_xor_ind_reg.cor"
"pierino_xor_reg_ind.cor"
"pierino_xor_reg_reg.cor"
"zjmp.cor"
)
# Statistics
TOTAL=0
PASSED=0
FAILED=0
MISSING=0
echo -e "${BLUE}╔════════════════════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ COREWAR BYTECODE COMPARISON TEST SUITE ║${NC}"
echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}"
echo ""
# Test each file
for FILE in "${TEST_FILES[@]}"; do
TOTAL=$((TOTAL + 1))
REF="$REF_DIR/$FILE"
YOURS="$YOURS_DIR/$FILE"
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BLUE}Testing: $FILE${NC}"
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
# Check if reference file exists
if [ ! -f "$REF" ]; then
echo -e "${RED}✗ Reference file not found: $REF${NC}"
MISSING=$((MISSING + 1))
echo ""
continue
fi
# Check if your file exists
if [ ! -f "$YOURS" ]; then
echo -e "${RED}✗ Your file not found: $YOURS${NC}"
FAILED=$((FAILED + 1))
echo ""
continue
fi
# File sizes
echo -e "\n${BLUE}=== File sizes ===${NC}"
ls -lh "$REF" "$YOURS" | awk '{print $5 "\t" $9}'
# Byte-by-byte comparison
echo -e "\n${BLUE}=== Byte-by-byte comparison ===${NC}"
if cmp -s "$REF" "$YOURS"; then
echo -e "${GREEN}✓ Files are identical!${NC}"
PASSED=$((PASSED + 1))
else
echo -e "${RED}✗ Files differ${NC}"
FAILED=$((FAILED + 1))
# Show hex diff (first 40 lines)
echo -e "\n${BLUE}=== Hex diff (first 40 lines) ===${NC}"
diff -u <(xxd "$REF") <(xxd "$YOURS") | head -40
# Show byte difference count
echo -e "\n${BLUE}=== Difference summary ===${NC}"
DIFF_COUNT=$(cmp -l "$REF" "$YOURS" 2>/dev/null | wc -l)
echo -e "Number of differing bytes: ${RED}$DIFF_COUNT${NC}"
fi
echo ""
done
# Summary
echo -e "${BLUE}╔════════════════════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ TEST SUMMARY ║${NC}"
echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}"
echo ""
echo -e "Total tests: ${BLUE}$TOTAL${NC}"
echo -e "Passed: ${GREEN}$PASSED${NC}"
echo -e "Failed: ${RED}$FAILED${NC}"
echo -e "Missing files: ${YELLOW}$MISSING${NC}"
echo ""
# Calculate percentage
if [ $TOTAL -gt 0 ]; then
PERCENTAGE=$((PASSED * 100 / TOTAL))
echo -e "Success rate: ${GREEN}$PERCENTAGE%${NC}"
fi
echo ""
# Exit with appropriate code
if [ $FAILED -eq 0 ] && [ $MISSING -eq 0 ]; then
echo -e "${GREEN}╔════════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ ALL TESTS PASSED! 🎉 ║${NC}"
echo -e "${GREEN}╚════════════════════════════════════════════════════════════╝${NC}"
exit 0
else
echo -e "${RED}╔════════════════════════════════════════════════════════════╗${NC}"
echo -e "${RED}║ SOME TESTS FAILED ❌ ║${NC}"
echo -e "${RED}╚════════════════════════════════════════════════════════════╝${NC}"
exit 1
fi