forked from microsoft/ntosebpfext
-
Notifications
You must be signed in to change notification settings - Fork 0
422 lines (378 loc) · 18.4 KB
/
reusable-test.yml
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
# Copyright (c) Microsoft Corporation
# SPDX-License-Identifier: MIT
# This workflow executes a single test, optionally gathering code coverage and logs.
name: Reusable Test Workflow
on:
workflow_call:
inputs:
name:
required: true
type: string
# The test command to invoke.
test_command:
required: true
type: string
# The name of the build artifact to download.
build_artifact:
required: true
type: string
# The environment to run this test on.
environment:
description: 'Environment to run tests on'
type: string
required: true
# Set to true to gather code coverage when this test runs.
code_coverage:
required: false
type: boolean
# Set to true to gather and upload memory dumps if a test process crashes.
gather_dumps:
required: false
type: boolean
pre_test:
required: false
type: string
post_test:
required: false
type: string
capture_etw:
required: false
type: boolean
# Set to true to use Visual Studio Developer command shell.
vs_dev:
required: false
type: boolean
fault_injection:
required: false
type: boolean
leak_detection:
required: false
type: boolean
configurations:
required: false
type: string
default: '["Debug", "Release"]'
permissions:
checks: read # Required by fountainhead/action-wait-for-check to wait for another GitHub check to complete.
contents: read # Required by actions/checkout to fetch code.
issues: write # Required to create issues.
jobs:
run_test:
# Due to app-verifier, unit tests take a lot longer to execute. Increase the timeout to 90 minutes.
timeout-minutes: 90
strategy:
matrix:
configurations: ${{ fromJSON(inputs.configurations) }}
runs-on: ${{inputs.environment}}
env:
# Configuration type to build.
SOURCE_ROOT: ${{github.workspace}}
NAME: ${{inputs.name}}
BUILD_CONFIGURATION: ${{matrix.configurations}}
BUILD_PLATFORM: x64
TEST_COMMAND: ${{inputs.test_command}}
PRE_COMMAND: ${{inputs.pre_test}}
POST_COMMAND: ${{inputs.post_test}}
CXPLAT_MEMORY_LEAK_DETECTION: ${{inputs.leak_detection}}
DUMP_PATH: c:/dumps/x64/${{matrix.configurations}}
TEST_TIMEOUT: 3600 # 1 hour timeout for tests.
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit
- id: skip_check
uses: fkirc/skip-duplicate-actions@f75f66ce1886f00957d99748a42c724f4330bdcf # v5.3.1
with:
cancel_others: 'false'
paths_ignore: '["**.md", "**/docs/**"]'
# Checking out the branch is needed to gather correct code coverage data.
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
# Only check out source code if code coverage is being gathered.
if: (inputs.code_coverage == true) && (steps.skip_check.outputs.should_skip != 'true')
with:
submodules: 'recursive'
ref: ${{ github.event.workflow_run.head_branch }}
- name: Install ProcDump
id: install_procdump
if: (inputs.gather_dumps == true) && (steps.skip_check.outputs.should_skip != 'true')
run: |
choco install -y procdump
where procdump.exe
- name: Set up OpenCppCoverage and add to PATH
id: set_up_opencppcoverage
if: (inputs.code_coverage == true) && (inputs.environment != 'ebpf_cicd_tests_ws2019' && inputs.environment != 'ebpf_cicd_tests_ws2022' && inputs.environment != 'ebpf_cicd_perf_ws2022') && (steps.skip_check.outputs.should_skip != 'true')
run: |
choco install -y --requirechecksum=true --checksum=2295A733DA39412C61E4F478677519DD0BB1893D88313CE56B468C9E50517888 --checksum-type=sha256 OpenCppCoverage
echo "C:\Program Files\OpenCppCoverage" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
where OpenCppCoverage.exe
- name: Configure Windows Error Reporting to make a local copy of any crashes that occur.
id: configure_windows_error_reporting
if: (inputs.gather_dumps == true) && (steps.skip_check.outputs.should_skip != 'true')
run: |
mkdir ${{env.DUMP_PATH}}
New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -ErrorAction SilentlyContinue
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpType" -Value 2 -PropertyType DWord -ErrorAction SilentlyContinue
$dump_path = "${{env.DUMP_PATH}}".Replace("/", "\")
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpFolder" -Value "$dump_path" -PropertyType ExpandString -ErrorAction SilentlyContinue
- name: Remove existing artifacts
if: (inputs.environment == 'ebpf_cicd_tests_ws2019' || inputs.environment == 'ebpf_cicd_tests_ws2022' || inputs.environment == 'ebpf_cicd_perf_ws2022') && (steps.skip_check.outputs.should_skip != 'true')
run: |
Remove-Item -Path ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}} -Recurse -Force -ErrorAction SilentlyContinue
- name: Download build artifact
if: (steps.skip_check.outputs.should_skip != 'true') && success()
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
id: download_artifact
with:
name: ${{inputs.build_artifact}}-${{matrix.configurations}}
path: ${{github.workspace}}
- name: Extract build artifact
if: steps.skip_check.outputs.should_skip != 'true'
working-directory: ${{github.workspace}}
run: |
mkdir ${{env.BUILD_PLATFORM}}
Expand-Archive .\build-${{ matrix.configurations }}.zip -DestinationPath .\${{env.BUILD_PLATFORM}}
- name: Start ETW tracing
id: start_etw_tracing
if: (inputs.capture_etw == true) && (steps.skip_check.outputs.should_skip != 'true')
shell: cmd
run: |
mkdir ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\TestLogs
wpr.exe -start ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\ntosebpfext.wprp -filemode
- name: Set ASAN Environment Variable
if: steps.skip_check.outputs.should_skip != 'true'
id: set_asan_env_var
shell: cmd
run: |
powershell.exe "echo 'ASAN_WIN_CONTINUE_ON_INTERCEPTION_FAILURE=true' | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append"
- name: Configure eBPF store
if: steps.skip_check.outputs.should_skip != 'true'
id: configure_ebpf_store
working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}}
run: |
.\ntos_ebpf_ext_export_program_info.exe --clear
.\ntos_ebpf_ext_export_program_info.exe
.\netevent_ebpf_ext_export_program_info.exe --clear
.\netevent_ebpf_ext_export_program_info.exe
- name: Run pre test command
if: steps.skip_check.outputs.should_skip != 'true' && (inputs.environment != 'ebpf_cicd_tests_ws2019' && inputs.environment != 'ebpf_cicd_tests_ws2022' && inputs.environment != 'ebpf_cicd_perf_ws2022')
id: run_pre_test_command
working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}}
run: |
${{env.PRE_COMMAND}}
- name: Run test with Code Coverage and low resource simulation
if: (inputs.code_coverage == true) && (inputs.fault_injection == true) && (steps.skip_check.outputs.should_skip != 'true')
id: run_test_with_code_coverage_in_fault_injection
shell: cmd
run: |
set EBPF_ENABLE_WER_REPORT=yes
OpenCppCoverage.exe -q --cover_children --sources %CD% --excluded_sources %CD%\external\Catch2 --export_type cobertura:ebpf_for_windows.xml --working_dir ${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}} -- powershell.exe .\Test-FaultInjection.ps1 ${{env.DUMP_PATH}} ${{env.TEST_TIMEOUT}} ${{env.TEST_COMMAND}} 4
- name: Run test with low resource simulation
if: (inputs.code_coverage != true) && (inputs.fault_injection == true) && (steps.skip_check.outputs.should_skip != 'true')
id: run_test_with_fault_injection
shell: cmd
working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}}
run: |
set EBPF_ENABLE_WER_REPORT=yes
powershell.exe .\Test-FaultInjection.ps1 ${{env.DUMP_PATH}} ${{env.TEST_TIMEOUT}} ${{env.TEST_COMMAND}} 16
- name: Run test with Code Coverage
if: (inputs.code_coverage == true) && (inputs.vs_dev != true) && (inputs.fault_injection != true) && (steps.skip_check.outputs.should_skip != 'true')
id: run_test_with_code_coverage
shell: cmd
run: |
set EBPF_ENABLE_WER_REPORT=yes
OpenCppCoverage.exe -q --sources %CD% --excluded_sources %CD%\external\Catch2 --export_type cobertura:ebpf_for_windows.xml --working_dir ${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}} -- powershell .\Run-Test.ps1 ${{env.DUMP_PATH}} ${{env.TEST_TIMEOUT}} ${{env.TEST_COMMAND}}
- name: Run test without codecoverage
if: (inputs.code_coverage != true) && (inputs.vs_dev != true) && (inputs.fault_injection != true) && (steps.skip_check.outputs.should_skip != 'true')
working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}}
id: run_test_without_code_coverage
shell: cmd
run: |
set EBPF_ENABLE_WER_REPORT=yes
${{env.TEST_COMMAND}}
- name: Run post test command
# Run the post test command even if the workflow has failed.
if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && (inputs.environment != 'ebpf_cicd_tests_ws2019' && inputs.environment != 'ebpf_cicd_tests_ws2022' && inputs.environment != 'ebpf_cicd_perf_ws2022')
id: run_post_test_command
working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}}
run: |
${{env.POST_COMMAND}}
- name: Check for CodeCoverage
if: steps.skip_check.outputs.should_skip != 'true'
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6
id: check_coverage
with:
files: ebpf_for_windows.xml
- name: Upload Report to Codecov attempt 1
if: (steps.skip_check.outputs.should_skip != 'true') && (steps.check_coverage.outputs.files_exists == 'true')
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238
id: upload_code_coverage_report_1
continue-on-error: true
with:
files: ebpf_for_windows.xml
fail_ci_if_error: true
functionalities: fix
root_dir: ${{github.workspace}}
- name: Wait on failure 1
if: (steps.skip_check.outputs.should_skip != 'true') && (steps.upload_code_coverage_report_1.outcome == 'failure')
run: Start-Sleep -Seconds 30
- name: Upload Report to Codecov attempt 2
if: (steps.skip_check.outputs.should_skip != 'true') && (steps.upload_code_coverage_report_1.outcome == 'failure')
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238
id: upload_code_coverage_report_2
continue-on-error: true
with:
files: ebpf_for_windows.xml
fail_ci_if_error: true
functionalities: fix
root_dir: ${{github.workspace}}
- name: Wait on failure 2
if: (steps.skip_check.outputs.should_skip != 'true') && (steps.upload_code_coverage_report_2.outcome == 'failure')
run: Start-Sleep -Seconds 60
- name: Upload Report to Codecov attempt 3
if: (steps.skip_check.outputs.should_skip != 'true') && (steps.upload_code_coverage_report_2.outcome == 'failure')
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238
id: upload_code_coverage_report_3
continue-on-error: true
with:
files: ebpf_for_windows.xml
fail_ci_if_error: true
functionalities: fix
root_dir: ${{github.workspace}}
- name: Wait on failure 3
if: (steps.skip_check.outputs.should_skip != 'true') && (steps.upload_code_coverage_report_3.outcome == 'failure')
run: Start-Sleep -Seconds 120
- name: Upload Report to Codecov attempt 4
if: (steps.skip_check.outputs.should_skip != 'true') && (steps.upload_code_coverage_report_3.outcome == 'failure')
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238
id: upload_code_coverage_report_4
continue-on-error: true
with:
files: ebpf_for_windows.xml
fail_ci_if_error: true
functionalities: fix
root_dir: ${{github.workspace}}
- name: Fail if code coverage upload fails
if: (steps.skip_check.outputs.should_skip != 'true')
run: |
if ($${{ steps.test.upload_code_coverage_report_1!='failure' }}) { exit 0 }
if ($${{ steps.test.upload_code_coverage_report_2!='failure' }}) { exit 0 }
if ($${{ steps.test.upload_code_coverage_report_3!='failure' }}) { exit 0 }
if ($${{ steps.test.upload_code_coverage_report_4!='failure' }}) { exit 0 }
exit 1
- name: Stop ETW tracing
id: stop_etw_tracing
if: always() && (inputs.capture_etw == true) && (steps.skip_check.outputs.should_skip != 'true')
shell: cmd
run: |
wpr.exe -stop ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\TestLogs\ntosebpfext.etl
- name: Check for crash dumps
# Check for crash dumps even if the workflow failed.
if: always() && (steps.skip_check.outputs.should_skip != 'true')
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6
id: check_dumps
with:
files: ${{env.DUMP_PATH}}/*.dmp
- name: Upload any crash dumps
# Upload crash dumps even if the workflow failed.
if: always() && (steps.skip_check.outputs.should_skip != 'true') && (steps.check_dumps.outputs.files_exists == 'true') && (inputs.gather_dumps == true)
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
id: upload_crash_dumps
with:
name: Crash-Dumps-${{env.NAME}}-${{env.BUILD_PLATFORM}}-${{env.BUILD_CONFIGURATION}}
path: ${{env.DUMP_PATH}}
retention-days: 5
- name: Check for TestLogs
# Check for test logs even if the workflow failed.
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6
if: always() && (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true')
id: check_logs
with:
files: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}}/TestLogs/*
- name: Upload log files
# Upload test logs even if the workflow failed.
if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && (steps.check_logs.outputs.files_exists == 'true')
id: upload_logs
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
continue-on-error: true
with:
name: Test-Logs-${{env.NAME}}-${{env.BUILD_PLATFORM}}-${{env.BUILD_CONFIGURATION}}
path: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}}/TestLogs
retention-days: 5
- name: Upload generated artifacts
# Upload artifacts even if the workflow failed.
if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && (steps.check_artifacts.outputs.files_exists == 'true')
id: upload_artifacts
continue-on-error: true
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
with:
name: Artifacts-${{env.NAME}}-${{env.BUILD_PLATFORM}}-${{env.BUILD_CONFIGURATION}}
path: ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\Artifacts
retention-days: 5
- name: Mark run as failed if crash dumps are found
if: (steps.skip_check.outputs.should_skip != 'true') && (steps.check_dumps.outputs.files_exists == 'true')
run: exit 1
create_or_update_issue:
needs: run_test
if: ${{ failure() }}
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.github.com:443
- id: skip_check
uses: fkirc/skip-duplicate-actions@f75f66ce1886f00957d99748a42c724f4330bdcf # v5.3.1
with:
cancel_others: 'false'
paths_ignore: '["**.md", "**/docs/**"]'
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
if: (github.event_name == 'schedule') || (github.event_name == 'push') && (steps.skip_check.outputs.should_skip != 'true')
env:
TITLE: Workflow failed - ${{inputs.name}}
BODY: |
[Failed Run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
[Codebase](https://github.com/${{ github.repository }}/tree/${{ github.sha }})
Test name - `${{ inputs.name }}`
LABELS: bug,ci/cd
with:
script: |
const owner = process.env.GITHUB_REPOSITORY.split('/')[0]
const repo = process.env.GITHUB_REPOSITORY.split('/')[1]
const body = process.env.BODY;
const title = process.env.TITLE;
const labels = process.env.LABELS;
const label_array = labels ? labels.split(',') : [];
console.log(label_array);
// Get all issues that have these labels.
const opts = github.rest.issues.listForRepo.endpoint.merge({
...context.issue,
state: 'open',
labels: label_array,
});
const issues = await github.paginate(opts);
// Look for an existing issue with the same title.
for (const issue of issues) {
if (issue.title === title) {
console.log(`Updating issue ${title}`);
await github.rest.issues.createComment({
issue_number: issue.number,
owner,
repo,
body,
});
return;
}
}
// Existing issue not found, create a new one.
console.log(`Creating issue ${title}`);
await github.rest.issues.create({
owner: owner,
repo: repo,
title: title,
body: body,
labels: label_array,
});