-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
96 lines (83 loc) · 2.18 KB
/
test.sh
File metadata and controls
96 lines (83 loc) · 2.18 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
#!/bin/bash
# Test script for Linux/macOS
echo "==================================="
echo "Testing bin2obj"
echo "==================================="
echo
# Detect platform
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
PLATFORM="linux"
FORMAT="elf"
OBJDUMP="objdump"
# Detect architecture on Linux
MACHINE=$(uname -m)
if [[ "$MACHINE" == "x86_64" ]]; then
ARCH="x86_64"
elif [[ "$MACHINE" == "i386" ]] || [[ "$MACHINE" == "i686" ]]; then
ARCH="x86"
elif [[ "$MACHINE" == "aarch64" ]] || [[ "$MACHINE" == "arm64" ]]; then
ARCH="arm64"
else
echo "Unknown architecture: $MACHINE"
exit 1
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
PLATFORM="macos"
FORMAT="mach-o"
OBJDUMP="otool"
# Detect architecture on macOS
if [[ $(uname -m) == "arm64" ]]; then
ARCH="arm64"
else
ARCH="x86_64"
fi
else
echo "Unknown platform: $OSTYPE"
exit 1
fi
echo "Platform: $PLATFORM"
echo "Format: $FORMAT"
echo "Architecture: $ARCH"
echo
echo "Step 1: Creating test data..."
python3 -c "with open('test_data.bin', 'wb') as f: f.write(b'Hello, this is test binary data!')"
echo
echo "Step 2: Generating object file..."
python3 bin2obj.py -i test_data.bin -o test_data.o -f $FORMAT -s test --arch $ARCH
if [ $? -ne 0 ]; then
echo "ERROR: Failed to generate object file"
exit 1
fi
echo
echo "Step 3: Compiling example.c..."
if [ "$PLATFORM" == "macos" ]; then
clang example.c test_data.o -o test_program
else
gcc example.c test_data.o -o test_program
fi
if [ $? -ne 0 ]; then
echo "ERROR: Compilation failed"
exit 1
fi
echo
echo "Step 4: Running the program..."
./test_program
echo
echo "Step 5: Inspecting object file..."
if [ "$PLATFORM" == "linux" ]; then
echo "--- Symbol table (nm) ---"
nm test_data.o
echo
echo "--- ELF header (readelf) ---"
readelf -h test_data.o
elif [ "$PLATFORM" == "macos" ]; then
echo "--- Symbol table (nm) ---"
nm test_data.o
echo
echo "--- Mach-O header (otool) ---"
otool -h test_data.o
fi
echo
echo "==================================="
echo "Test completed successfully!"
echo "==================================="