-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_test_script.sh
More file actions
116 lines (100 loc) · 3.54 KB
/
build_test_script.sh
File metadata and controls
116 lines (100 loc) · 3.54 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
#!/bin/bash
set -e
echo "=== Order Book Feed Processor Build & Test ==="
echo
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Create build directory
mkdir -p build
cd build
# Compile the main processor
echo -e "${BLUE}Compiling order book processor...${NC}"
g++ -std=c++17 -O3 -Wall -Wextra -o orderbook_processor ../orderbook_processor.cpp
echo -e "${GREEN}✓ Processor compiled${NC}"
echo
# Compile the test generator
echo -e "${BLUE}Compiling test stream generator...${NC}"
g++ -std=c++17 -O3 -Wall -Wextra -o stream_generator ../stream_generator.cpp
echo -e "${GREEN}✓ Generator compiled${NC}"
echo
# Generate small test file
echo -e "${BLUE}Generating small test file (input1.bin)...${NC}"
./stream_generator input1.bin
echo -e "${GREEN}✓ Test file generated${NC}"
echo
# Test with small file
echo -e "${BLUE}Running test with depth=5...${NC}"
echo "Expected output:"
cat ../output1.log
echo
echo "Actual output:"
cat input1.bin | ./orderbook_processor 5 > actual_output.log
cat actual_output.log
echo
# Compare outputs
if diff -w ../output1.log actual_output.log > /dev/null 2>&1; then
echo -e "${GREEN}✓ Small test PASSED - outputs match!${NC}"
else
echo -e "${RED}✗ Small test FAILED - outputs differ${NC}"
echo "Differences:"
diff -w ../output1.log actual_output.log || true
fi
echo
# Generate 1MB test file
echo -e "${BLUE}Generating 1MB test file...${NC}"
./stream_generator large_1mb.bin 1
FILE_SIZE=$(stat -f%z large_1mb.bin 2>/dev/null || stat -c%s large_1mb.bin)
echo -e "${GREEN}✓ Generated file size: $(($FILE_SIZE / 1024))KB${NC}"
echo
# Test with 1MB file
echo -e "${BLUE}Testing 1MB file processing (first 10 lines)...${NC}"
START_TIME=$(date +%s%N)
cat large_1mb.bin | ./orderbook_processor 5 | head -10
END_TIME=$(date +%s%N)
ELAPSED_MS=$(( ($END_TIME - $START_TIME) / 1000000 ))
echo -e "${GREEN}✓ 1MB file processed in ${ELAPSED_MS}ms${NC}"
echo
# Generate 2MB test file
echo -e "${BLUE}Generating 2MB test file...${NC}"
./stream_generator large_2mb.bin 2
FILE_SIZE=$(stat -f%z large_2mb.bin 2>/dev/null || stat -c%s large_2mb.bin)
echo -e "${GREEN}✓ Generated file size: $(($FILE_SIZE / 1024))KB${NC}"
echo
# Test with 2MB file
echo -e "${BLUE}Testing 2MB file processing (first 10 lines)...${NC}"
START_TIME=$(date +%s%N)
cat large_2mb.bin | ./orderbook_processor 10 | head -10
END_TIME=$(date +%s%N)
ELAPSED_MS=$(( ($END_TIME - $START_TIME) / 1000000 ))
echo -e "${GREEN}✓ 2MB file processed in ${ELAPSED_MS}ms${NC}"
echo
# Count messages in 2MB file
echo -e "${BLUE}Counting total output snapshots from 2MB file...${NC}"
SNAPSHOT_COUNT=$(cat large_2mb.bin | ./orderbook_processor 5 | wc -l)
echo -e "${GREEN}✓ Generated $SNAPSHOT_COUNT snapshots${NC}"
echo
# Memory test with multiple symbols
echo -e "${BLUE}Testing with different depth levels...${NC}"
for DEPTH in 3 5 10 20; do
echo " Testing depth=$DEPTH"
cat input1.bin | ./orderbook_processor $DEPTH > /dev/null
echo -e " ${GREEN}✓ Depth $DEPTH works${NC}"
done
echo
echo -e "${GREEN}=== All tests completed ===${NC}"
echo
echo "Files generated in build/:"
echo " - orderbook_processor (main executable)"
echo " - stream_generator (test data generator)"
echo " - input1.bin (small test file)"
echo " - large_1mb.bin (1MB test file)"
echo " - large_2mb.bin (2MB test file)"
echo
echo "Usage examples:"
echo " cat input1.bin | ./orderbook_processor 5"
echo " cat large_1mb.bin | ./orderbook_processor 10"
echo " ./stream_generator custom_test.bin"
echo " ./stream_generator huge_test.bin 10 # Generate 10MB file"