forked from microsoft/ebpf-for-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_driver_tests.psm1
241 lines (199 loc) · 8.89 KB
/
run_driver_tests.psm1
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# Copyright (c) Microsoft Corporation
# SPDX-License-Identifier: MIT
param ([Parameter(Mandatory=$True)] [string] $WorkingDirectory,
[Parameter(Mandatory=$True)] [string] $LogFileName)
Push-Location $WorkingDirectory
Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue
Import-Module .\install_ebpf.psm1 -Force -ArgumentList ($WorkingDirectory, $LogFileName) -WarningAction SilentlyContinue
$CodeCoverage = 'C:\Program Files\OpenCppCoverage\OpenCppCoverage.exe'
#
# Execute tests on VM.
#
function Invoke-NetshEbpfCommand
{
param([Parameter(Mandatory=$True)][string] $Arguments)
$ArgumentsList = @("ebpf") + $Arguments.Split(" ")
$AddProgram = $false
if ($ArgumentsList[1] -eq "add"){
$AddProgram = $true
}
$LASTEXITCODE = 0
$Output = &netsh.exe $ArgumentsList 2>&1
# Check for errors.
if ($LASTEXITCODE -ne 0) {
throw ("netsh command returned error.")
}
Out-String -InputObject $Output | Write-Log -ForegroundColor Green
# For add program command, the 4th element of the output string contains
# the program Id.
if ($AddProgram -eq $true) {
$ProgId = ($Output.Split(" "))[3]
return $ProgId
}
}
function Invoke-Test
{
param([Parameter(Mandatory=$True)][string] $TestName,
[Parameter(Mandatory=$True)][bool] $VerboseLogs,
[Parameter(Mandatory=$False)][bool] $Coverage)
Write-Log "Executing $Testname"
$LASTEXITCODE = 0
$OriginalTestName = $TestName
$ArgumentsList = @()
if ($Coverage) {
$ArgumentsList += @('-q', '--modules=C:\eBPF', '--export_type', ('binary:' + $TestName + '.cov'), '--', $TestName)
$TestName = $CodeCoverage
}
# Execute Test.
if ($VerboseLogs -eq $true) {
$ArgumentsList += '-s'
}
Write-Log "$TestName $ArgumentsList"
$Output = &$TestName $ArgumentsList
$TestName = $OriginalTestName
if ($LASTEXITCODE -ne 0) {
throw ("$TestName Failed with $LASTEXITCODE.")
}
# Parse output to check for errors.
if ($null -eq $Output) {
throw ("No output generated by $TestName.")
}
Out-String -InputObject $Output | Write-Log
$ParsedOutput = $Output.Split(" ")
if (-not (($null -ne $ParsedOutput) -and ($ParsedOutput.Length -ge 2))) {
throw ("Failed to parse output generated by $TestName.")
}
if ($ParsedOutput[$ParsedOutput.Length -2] -eq "failed") {
throw ("$TestName Test Failed.")
}
Write-Log "$TestName Passed" -ForegroundColor Green
}
function Invoke-CICDTests
{
param([parameter(Mandatory = $true)][bool] $VerboseLogs,
[parameter(Mandatory = $false)][bool] $Coverage = $false)
pushd $WorkingDirectory
$env:EBPF_ENABLE_WER_REPORT = "yes"
try {
$TestList = @(
"api_test.exe",
"bpftool_tests.exe",
"sample_ext_app.exe",
"socket_tests.exe")
foreach ($Test in $TestList) {
Invoke-Test -TestName $Test -VerboseLogs $VerboseLogs -Coverage $Coverage
}
if ($Coverage) {
# Combine code coverage reports
$ArgumentsList += @()
foreach ($Test in $TestList) {
$ArgumentsList += @('--input_coverage', ($Test + '.cov'))
}
$ArgumentsList += @('--export_type', 'cobertura:c:\eBPF\ebpf_for_windows.xml', '--')
$Output = &$CodeCoverage $ArgumentsList
Out-String -InputObject $Output | Write-Log
}
if ($Env:BUILD_CONFIGURATION -eq "Release") {
Invoke-Test -TestName "ebpf_performance.exe" -VerboseLogs $VerboseLogs
}
}
catch {
Write-Log "One or more tests failed."
throw
}
popd
}
function Invoke-XDPTest
{
param([parameter(Mandatory=$true)][string] $RemoteIPV4Address,
[parameter(Mandatory=$true)][string] $RemoteIPV6Address,
[parameter(Mandatory=$true)][string] $XDPTestName,
[parameter(Mandatory=$true)][string] $WorkingDirectory)
pushd $WorkingDirectory
Write-Log "Executing $XDPTestName with remote address: $RemoteIPV4Address."
$LASTEXITCODE = 0
$Output = .\xdp_tests.exe $XDPTestName --remote-ip $RemoteIPV4Address
Out-String -InputObject $Output | Write-Log
$ParsedOutput = $Output.Split(" ")
if (($LASTEXITCODE -ne 0) -or ($ParsedOutput[$ParsedOutput.Length -2] -eq "failed")) { throw ("$XDPTestName Test Failed.") }
Write-Log "Executing $XDPTestName with remote address: $RemoteIPV6Address."
$LASTEXITCODE = 0
$Output = .\xdp_tests.exe $XDPTestName --remote-ip $RemoteIPV6Address
Out-String -InputObject $Output | Write-Log
$ParsedOutput = $Output.Split(" ")
if (($LASTEXITCODE -ne 0) -or ($ParsedOutput[$ParsedOutput.Length -2] -eq "failed")) { throw ("$XDPTestName Test Failed.") }
Write-Log "$XDPTestName Test Passed" -ForegroundColor Green
popd
}
function Invoke-ConnectRedirectTest
{
param([parameter(Mandatory=$true)][string] $LocalIPv4Address,
[parameter(Mandatory=$true)][string] $LocalIPv6Address,
[parameter(Mandatory=$true)][string] $RemoteIPv4Address,
[parameter(Mandatory=$true)][string] $RemoteIPv6Address,
[parameter(Mandatory=$true)][string] $VirtualIPv4Address,
[parameter(Mandatory=$true)][string] $VirtualIPv6Address,
[parameter(Mandatory=$true)][int] $DestinationPort,
[parameter(Mandatory=$true)][int] $ProxyPort,
[parameter(Mandatory=$true)][string] $StandardUserName,
[parameter(Mandatory=$true)][string] $StandardUserPassword,
[parameter(Mandatory=$true)][string] $UserType,
[parameter(Mandatory=$true)][string] $WorkingDirectory)
pushd $WorkingDirectory
## First run the test with both v4 and v6 programs attached.
$Parameters = "--virtual-ip-v4 $VirtualIPv4Address --virtual-ip-v6 $VirtualIPv6Address --local-ip-v4 $LocalIPv4Address --local-ip-v6 $LocalIPv6Address --remote-ip-v4 $RemoteIPv4Address --remote-ip-v6 $RemoteIPv6Address --destination-port $DestinationPort --proxy-port $ProxyPort --user-type $UserType"
Write-Log "Executing connect redirect tests with parameters: $Parameters"
$LASTEXITCODE = 0
$Output = .\connect_redirect_tests.exe `
--virtual-ip-v4 $VirtualIPv4Address `
--virtual-ip-v6 $VirtualIPv6Address `
--local-ip-v4 $LocalIPv4Address `
--local-ip-v6 $LocalIPv6Address `
--remote-ip-v4 $RemoteIPv4Address `
--remote-ip-v6 $RemoteIPv6Address `
--destination-port $DestinationPort `
--proxy-port $ProxyPort `
--user-name $StandardUserName `
--password $StandardUserPassword `
--user-type $UserType
Out-String -InputObject $Output | Write-Log
$ParsedOutput = $Output.Split(" ")
if (($LASTEXITCODE -ne 0) -or ($ParsedOutput[$ParsedOutput.Length -2] -eq "failed")) { throw ("Connect-Redirect Test Failed.") }
## Run test with only v4 program attached.
$Parameters = "--virtual-ip-v4 $VirtualIPv4Address --local-ip-v4 $LocalIPv4Address --remote-ip-v4 $RemoteIPv4Address --destination-port $DestinationPort --proxy-port $ProxyPort --user-type $UserType"
Write-Log "Executing connect redirect tests with parameters: $Parameters"
$LASTEXITCODE = 0
$Output = .\connect_redirect_tests.exe `
--virtual-ip-v4 $VirtualIPv4Address `
--local-ip-v4 $LocalIPv4Address `
--remote-ip-v4 $RemoteIPv4Address `
--destination-port $DestinationPort `
--proxy-port $ProxyPort `
--user-name $StandardUserName `
--password $StandardUserPassword `
--user-type $UserType `
"[connect_authorize_redirect_tests_v4]"
Out-String -InputObject $Output | Write-Log
$ParsedOutput = $Output.Split(" ")
if (($LASTEXITCODE -ne 0) -or ($ParsedOutput[$ParsedOutput.Length -2] -eq "failed")) { throw ("Connect-Redirect Test Failed.") }
## Run tests with only v6 program attached.
$Parameters = "--virtual-ip-v6 $VirtualIPv6Address --local-ip-v6 $LocalIPv6Address --remote-ip-v6 $RemoteIPv6Address --destination-port $DestinationPort --proxy-port $ProxyPort --user-type $UserType"
Write-Log "Executing connect redirect tests with parameters: $Parameters"
$LASTEXITCODE = 0
$Output = .\connect_redirect_tests.exe `
--virtual-ip-v6 $VirtualIPv6Address `
--local-ip-v6 $LocalIPv6Address `
--remote-ip-v6 $RemoteIPv6Address `
--destination-port $DestinationPort `
--proxy-port $ProxyPort `
--user-name $StandardUserName `
--password $StandardUserPassword `
--user-type $UserType `
"[connect_authorize_redirect_tests_v6]"
Out-String -InputObject $Output | Write-Log
$ParsedOutput = $Output.Split(" ")
if (($LASTEXITCODE -ne 0) -or ($ParsedOutput[$ParsedOutput.Length -2] -eq "failed")) { throw ("Connect-Redirect Test Failed.") }
Write-Log "Connect-Redirect Test Passed" -ForegroundColor Green
popd
}
Pop-Location