-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·66 lines (52 loc) · 1.52 KB
/
run.sh
File metadata and controls
executable file
·66 lines (52 loc) · 1.52 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
#!/bin/bash
EXECUTABLE="bin/compiler"
TEST_DIR="tests/test_suite"
OUTPUT_DIR="outputs"
# Ensure test directory exists
if [ ! -d "$TEST_DIR" ]; then
echo "Error: Test directory '$TEST_DIR' does not exist."
exit 1
fi
# Ensure executable exists
if [ ! -f "$EXECUTABLE" ]; then
echo "Error: Executable '$EXECUTABLE' does not exist."
exit 1
fi
# Create the outputs directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"
# Run the executable over each test case
for test_case in "$TEST_DIR"/*.cold; do
test_name=$(basename "$test_case" .cold)
echo "Running test case: $test_name"
# Run the compiler
"$EXECUTABLE" "$test_case" "--output" "$OUTPUT_DIR/" "$@"
if [ $? -ne 0 ]; then
echo "Test $test_name failed during compilation."
echo
continue
fi
# Check if assembly file was generated
if [ ! -f "$OUTPUT_DIR/${test_name}.asm" ]; then
echo "Error: Assembly file '$OUTPUT_DIR/${test_name}.asm' not found after compilation."
echo "Test $test_name failed."
echo
continue
fi
# Assemble with nasm
nasm -f elf32 "$OUTPUT_DIR/${test_name}.asm" -o "$OUTPUT_DIR/${test_name}.o"
if [ $? -ne 0 ]; then
echo "Test $test_name failed during assembly."
echo
continue
fi
# Link with gcc
gcc -m32 -no-pie -z noexecstack "$OUTPUT_DIR/${test_name}.o" -o "$OUTPUT_DIR/exec_${test_name}" -lm
# "$OUTPUT_DIR/exec_${test_name}"
if [ $? -ne 0 ]; then
echo "Test $test_name failed during linking."
echo
continue
fi
echo "Test $test_name passed successfully."
echo
done