-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_build.sh
More file actions
executable file
·140 lines (121 loc) · 3.34 KB
/
test_build.sh
File metadata and controls
executable file
·140 lines (121 loc) · 3.34 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
#!/bin/bash
set -e
echo "=== Opus Extension Build and Test Script ==="
echo ""
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check for required tools
echo "Checking required tools..."
for tool in php php-config phpize gcc make; do
if ! command -v $tool &> /dev/null; then
echo -e "${RED}✗ $tool not found${NC}"
exit 1
fi
echo -e "${GREEN}✓ $tool found${NC}"
done
# Check for opus library
echo ""
echo "Checking for libopus..."
if pkg-config --exists opus; then
echo -e "${GREEN}✓ libopus found: $(pkg-config --modversion opus)${NC}"
else
echo -e "${RED}✗ libopus not found${NC}"
echo "Install with: sudo apt-get install libopus-dev"
exit 1
fi
# Clean previous build
echo ""
echo "Cleaning previous build..."
make clean 2>/dev/null || true
phpize --clean 2>/dev/null || true
rm -f modules/*.so
# Build extension
echo ""
echo "Building extension..."
phpize
./configure --enable-opus
make clean
make
if [ ! -f "modules/opus.so" ]; then
echo -e "${RED}✗ Build failed - opus.so not found${NC}"
exit 1
fi
echo -e "${GREEN}✓ Build successful${NC}"
# Check for memory analysis tools
echo ""
echo "Checking for memory analysis tools..."
HAS_VALGRIND=0
if command -v valgrind &> /dev/null; then
echo -e "${GREEN}✓ valgrind found${NC}"
HAS_VALGRIND=1
else
echo -e "${YELLOW}⚠ valgrind not found (optional)${NC}"
fi
# Run basic test
echo ""
echo "=== Running Basic Tests ==="
php -dextension=modules/opus.so test_opus_safety.php
# Check exit code
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ Basic tests passed${NC}"
else
echo -e "${RED}✗ Basic tests failed${NC}"
exit 1
fi
# Run valgrind if available
if [ $HAS_VALGRIND -eq 1 ]; then
echo ""
echo "=== Running Valgrind Memory Check ==="
echo "This may take a few minutes..."
valgrind \
--leak-check=full \
--show-leak-kinds=all \
--track-origins=yes \
--error-exitcode=1 \
--errors-for-leak-kinds=all \
--suppressions=/usr/share/php*/valgrind-suppressions 2>/dev/null \
php -dextension=modules/opus.so test_opus_safety.php 2>&1 | tee valgrind.log
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ No memory leaks detected${NC}"
else
echo -e "${RED}✗ Memory issues detected - see valgrind.log${NC}"
echo ""
echo "Summary of issues:"
grep -A 2 "LEAK SUMMARY" valgrind.log || true
exit 1
fi
fi
# Run stress test
echo ""
echo "=== Running Stress Test ==="
php -dextension=modules/opus.so -r '
for ($i = 0; $i < 1000; $i++) {
$opus = new opusChannel(48000, 1);
$pcm = str_repeat(pack("s", rand(-16000, 16000)), 4800);
$encoded = $opus->encode($pcm);
$decoded = $opus->decode($encoded);
unset($opus);
if ($i % 100 == 0) echo "Progress: $i/1000\n";
}
echo "Stress test completed!\n";
'
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ Stress test passed${NC}"
else
echo -e "${RED}✗ Stress test failed${NC}"
exit 1
fi
echo ""
echo "=== All Tests Passed ==="
echo -e "${GREEN}✓ Build successful${NC}"
echo -e "${GREEN}✓ Basic tests passed${NC}"
echo -e "${GREEN}✓ Stress test passed${NC}"
if [ $HAS_VALGRIND -eq 1 ]; then
echo -e "${GREEN}✓ No memory leaks${NC}"
fi
echo ""
echo "Extension ready to use!"
echo "Load with: php -dextension=$(pwd)/modules/opus.so"