-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun_tests.go
144 lines (116 loc) · 3.91 KB
/
run_tests.go
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
// Package main provides a test launcher for all individual tests
// This script uses os/exec to run individual test files
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("Available tests:")
fmt.Println(" sipgo - Test sipgo API")
fmt.Println(" siprec - Test SIPREC implementation")
fmt.Println(" audio - Test audio processing (requires UDP port 15000)")
fmt.Println(" all - Run all tests")
fmt.Println("\nUsage: go run run_tests.go [test]")
return
}
testType := os.Args[1]
// Get current directory for test file paths
currentDir, err := os.Getwd()
if err != nil {
fmt.Printf("Failed to get current directory: %v\n", err)
os.Exit(1)
}
// Temporary directory to store modified test files
tmpDir := filepath.Join(currentDir, "tmp_tests")
os.MkdirAll(tmpDir, 0755)
defer os.RemoveAll(tmpDir) // Clean up when done
switch testType {
case "sipgo":
fmt.Println("Running sipgo API test...")
runSipgoTest(currentDir, tmpDir)
case "siprec":
fmt.Println("Running SIPREC implementation test...")
runSiprecTest(currentDir, tmpDir)
case "audio":
fmt.Println("Running audio processing test...")
runAudioTest(currentDir, tmpDir)
case "all":
fmt.Println("Running all tests...")
fmt.Println("\n=== SIPGO TEST ===")
runSipgoTest(currentDir, tmpDir)
fmt.Println("\n=== SIPREC TEST ===")
runSiprecTest(currentDir, tmpDir)
fmt.Println("\n=== AUDIO TEST ===")
runAudioTest(currentDir, tmpDir)
default:
fmt.Printf("Unknown test type: %s\n", testType)
fmt.Println("Available tests: sipgo, siprec, audio, all")
}
}
// runSipgoTest runs the sipgo API test
func runSipgoTest(baseDir, tmpDir string) {
// Create temporary test file
testFile := filepath.Join(tmpDir, "test_sipgo_main.go")
// Copy test_sipgo.go to temporary file with package main
cmd := exec.Command("bash", "-c", fmt.Sprintf("sed 's/package test_sipgo/package main/' %s/test_sipgo.go | sed 's/func TestSipGo/func main/' > %s",
baseDir, testFile))
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
fmt.Printf("Failed to prepare sipgo test: %v\n", err)
return
}
// Run the test
runCmd := exec.Command("go", "run", testFile)
runCmd.Stdout = os.Stdout
runCmd.Stderr = os.Stderr
if err := runCmd.Run(); err != nil {
fmt.Printf("Sipgo test failed: %v\n", err)
}
}
// runSiprecTest runs the SIPREC implementation test
func runSiprecTest(baseDir, tmpDir string) {
// Create temporary test file
testFile := filepath.Join(tmpDir, "test_siprec_main.go")
// Copy test_siprec.go to temporary file with package main
cmd := exec.Command("bash", "-c", fmt.Sprintf("sed 's/package test_siprec/package main/' %s/test_siprec.go | sed 's/func TestSiprec/func main/' > %s",
baseDir, testFile))
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
fmt.Printf("Failed to prepare siprec test: %v\n", err)
return
}
// Run the test
runCmd := exec.Command("go", "run", testFile)
runCmd.Stdout = os.Stdout
runCmd.Stderr = os.Stderr
if err := runCmd.Run(); err != nil {
fmt.Printf("SIPREC test failed: %v\n", err)
}
}
// runAudioTest runs the audio processing test
func runAudioTest(baseDir, tmpDir string) {
// Create temporary test file
testFile := filepath.Join(tmpDir, "test_audio_main.go")
// Copy test_audio.go to temporary file with package main
cmd := exec.Command("bash", "-c", fmt.Sprintf("sed 's/package test_audio/package main/' %s/test_audio.go | sed 's/func TestAudioProcessing/func main/' > %s",
baseDir, testFile))
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
fmt.Printf("Failed to prepare audio test: %v\n", err)
return
}
// Run the test
runCmd := exec.Command("go", "run", testFile)
runCmd.Stdout = os.Stdout
runCmd.Stderr = os.Stderr
if err := runCmd.Run(); err != nil {
fmt.Printf("Audio test failed: %v\n", err)
}
}