From 27bd6a4ff26eb90b832a2d9d7183efb7c51abe00 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" Date: Tue, 29 Oct 2024 15:43:08 -0700 Subject: [PATCH 001/190] test - wip --- .github/workflows/cicd.yml | 556 ---------------------------- .github/workflows/reusable-test.yml | 4 +- 2 files changed, 3 insertions(+), 557 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 3caca0d7dd..ce371e7dfb 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -91,110 +91,6 @@ jobs: build_nuget: true configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' - # Run the unit tests in GitHub. - unit_tests_appverif: - # Always run this job. - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: unit_tests - pre_test: appverif -enable Exceptions Handles Heaps Leak Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe - # Exclude [processes] test that CodeCoverage can't work with. - test_command: .\unit_tests.exe -d yes ~[processes] - build_artifact: Build-x64 - environment: windows-2022 - code_coverage: true - gather_dumps: true - capture_etw: true - leak_detection: true - - # Run the unit tests in GitHub. - unit_tests: - # Always run this job. - needs: regular - if: github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' - uses: ./.github/workflows/reusable-test.yml - with: - name: unit_tests - pre_test: appverif -enable Exceptions Handles Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe - # Exclude [processes] test that CodeCoverage can't work with. - test_command: .\unit_tests.exe -d yes ~[processes] - build_artifact: Build-x64 - environment: windows-2022 - code_coverage: true - gather_dumps: true - capture_etw: true - leak_detection: true - - # Run the unit tests for NativeOnly build in GitHub. - unit_tests_native_only: - # Always run this job. - needs: regular_native-only - uses: ./.github/workflows/reusable-test.yml - with: - name: unit_tests - pre_test: appverif -enable Exceptions Handles Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe - # Exclude [processes] test that CodeCoverage can't work with. - test_command: .\unit_tests.exe -d yes ~[processes] - build_artifact: Build-x64-native-only - environment: windows-2022 - code_coverage: true - gather_dumps: true - capture_etw: true - leak_detection: true - configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' - - # Run the netebpfext unit tests in GitHub. - netebpf_ext_unit_tests: - # Always run this job. - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: netebpf_ext_unit_tests - pre_test: appverif -enable Exceptions Handles Heaps Leak Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe - test_command: .\netebpfext_unit.exe -d yes - build_artifact: Build-x64 - environment: windows-2022 - code_coverage: true - gather_dumps: true - capture_etw: true - leak_detection: true - - # Run the bpf2c tests in GitHub. - bpf2c: - # Always run this job. - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - test_command: .\bpf2c_tests.exe -d yes - name: bpf2c - build_artifact: Build-x64 - environment: windows-2022 - vs_dev: true - code_coverage: true - gather_dumps: true - capture_etw: true - - # Run the bpf2c conformance tests in GitHub. - bpf2c_conformance: - # Always run this job. - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - pre_test: Invoke-WebRequest https://github.com/Alan-Jowett/bpf_conformance/releases/download/v0.0.6/bpf_conformance_runner.exe -OutFile bpf_conformance_runner.exe - test_command: .\bpf_conformance_runner.exe --test_file_directory %SOURCE_ROOT%\external\ebpf-verifier\external\bpf_conformance\tests --cpu_version v4 --exclude_regex local --plugin_path bpf2c_plugin.exe --debug true --plugin_options "--include %SOURCE_ROOT%\include" - name: bpf2c_conformance - build_artifact: Build-x64 - environment: windows-2022 - vs_dev: true - code_coverage: true - gather_dumps: true - capture_etw: true - # Run the driver tests on self-hosted runners. driver_ws2019: # Always run this job. @@ -213,455 +109,3 @@ jobs: gather_dumps: false # driver tests manually gather code coverage code_coverage: false - - # Run the driver tests on self-hosted runners. - driver_ws2022: - # Always run this job. - # Only run this on repos that have self-host runners. - needs: regular - if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') - uses: ./.github/workflows/reusable-test.yml - with: - pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" - test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" - post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - name: driver_ws2022 - build_artifact: Build-x64 - environment: ebpf_cicd_tests_ws2022 - # driver test copies dumps to testlog folder. - gather_dumps: false - # driver tests manually gather code coverage - code_coverage: false - - # Run the native-only driver tests on self-hosted runners. - driver_native_only_ws2019: - # Always run this job. - # Only run this on repos that have self-host runners. - needs: regular_native-only - if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') - uses: ./.github/workflows/reusable-test.yml - with: - pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" - test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" - post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - name: driver_native_only_ws2019 - build_artifact: Build-x64-native-only - environment: ebpf_cicd_tests_ws2019 - # driver test copies dumps to testlog folder. - gather_dumps: false - # driver tests manually gather code coverage - code_coverage: false - configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' - - driver_native_only_ws2022: - # Always run this job. - # Only run this on repos that have self-host runners. - needs: regular_native-only - if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') - uses: ./.github/workflows/reusable-test.yml - with: - pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" - test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" - post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - name: driver_native_only_ws2022 - build_artifact: Build-x64-native-only - environment: ebpf_cicd_tests_ws2022 - # driver test copies dumps to testlog folder. - gather_dumps: false - # driver tests manually gather code coverage - code_coverage: false - configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' - - # Run the regression driver tests on self-hosted runners (only for 2022). - regression_driver_ws2022: - # Always run this job. - # Only run this on repos that have self-host runners. - needs: regular - if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') - uses: ./.github/workflows/reusable-test.yml - with: - pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" -TestMode "Regression" -RegressionArtifactsVersion "0.17.0" - test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Regression" - post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - name: regression_driver_ws2022 - build_artifact: Build-x64 - environment: ebpf_cicd_tests_ws2022 - # driver test copies dumps to testlog folder. - gather_dumps: false - # driver tests manually gather code coverage - code_coverage: false - - ossar: - # Always run this job. - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/ossar-scan.yml - with: - build_artifact: Build-x64 - - # Additional jobs to run on pull and schedule only (skip push). - # --------------------------------------------------------------------------- - # Build with C++ static analyzer. - analyze: - # Only run on schedule and pull request. - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-build.yml - with: - ref: ${{ github.ref }} - repository: ${{ github.repository }} - build_artifact: Build-x64-Analyze - # Analysis on external projects is conditional, as on small CI/CD VMs the compiler can run OOM - build_options: /p:Analysis='True' /p:AnalysisOnExternal='False' - - # Build with C++ address sanitizer. - sanitize: - # Only run on schedule and pull request. - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-build.yml - with: - ref: ${{ github.ref }} - repository: ${{ github.repository }} - build_artifact: Build-x64-Sanitize - build_options: /p:AddressSanitizer='True' - - bpf2c_fuzzer: - needs: regular - if: github.event_name == 'pull_request' || github.event_name == 'merge_group' - uses: ./.github/workflows/reusable-test.yml - with: - name: bpf2c_fuzzer - test_command: .\bpf2c_fuzzer.exe bpf2c_fuzzer_corpus -use_value_profile=1 -max_total_time=300 -artifact_prefix=Artifacts\ - build_artifact: Build-x64 - environment: windows-2022 - code_coverage: false - gather_dumps: true - configurations: '["FuzzerDebug"]' - - bpf2c_fuzzer_scheduled: - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: bpf2c_fuzzer - test_command: .\bpf2c_fuzzer.exe bpf2c_fuzzer_corpus -use_value_profile=1 -max_total_time=900 -artifact_prefix=Artifacts\ - build_artifact: Build-x64 - environment: windows-2022 - code_coverage: false - gather_dumps: true - configurations: '["FuzzerDebug"]' - - execution_context_fuzzer: - needs: regular - # Always run this job. - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: execution_context_fuzzer - test_command: .\execution_context_fuzzer.exe execution_context_fuzzer_corpus -use_value_profile=1 -runs=3000 -artifact_prefix=Artifacts\ - build_artifact: Build-x64 - environment: windows-2022 - code_coverage: false - gather_dumps: true - configurations: '["FuzzerDebug"]' - - # Run the verifier fuzzer. - verifier_fuzzer: - needs: regular - # Always run this job. - if: github.event_name == 'pull_request' || github.event_name == 'merge_group' - uses: ./.github/workflows/reusable-test.yml - with: - name: verifier_fuzzer - test_command: .\verifier_fuzzer.exe verifier_corpus -use_value_profile=1 -max_total_time=300 -artifact_prefix=Artifacts\ - build_artifact: Build-x64 - environment: windows-2022 - code_coverage: false - gather_dumps: true - configurations: '["FuzzerDebug"]' - - verifier_fuzzer_scheduled: - needs: regular - # Always run this job. - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: verifier_fuzzer - test_command: .\verifier_fuzzer.exe verifier_corpus -use_value_profile=1 -max_total_time=900 -artifact_prefix=Artifacts\ - build_artifact: Build-x64 - environment: windows-2022 - code_coverage: false - gather_dumps: true - configurations: '["FuzzerDebug"]' - - core_helper_fuzzer: - needs: regular - # Always run this job. - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: core_helper_fuzzer - test_command: .\core_helper_fuzzer core_helper_corpus -max_len=139 -runs=1000 -use_value_profile=1 -artifact_prefix=Artifacts\ - build_artifact: Build-x64 - environment: windows-2022 - code_coverage: false - gather_dumps: true - configurations: '["FuzzerDebug"]' - - netebpfext_fuzzer: - needs: regular - # Always run this job. - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: netebpfext_fuzzer - test_command: .\netebpfext_fuzzer netebpfext_corpus -max_len=12 -runs=1000 -use_value_profile=1 -artifact_prefix=Artifacts\ - build_artifact: Build-x64 - environment: windows-2022 - code_coverage: false - gather_dumps: true - configurations: '["FuzzerDebug"]' - - # Run Cilium regression tests in GitHub. - cilium_tests: - needs: regular - # Only run on schedule and pull request. - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: cilium_tests - test_command: .\cilium_tests.exe -d yes - build_artifact: Build-x64 - environment: windows-2022 - code_coverage: false - gather_dumps: true - - # Run the quick stress tests in GitHub. - stress: - needs: regular - # Only run on schedule and pull request. - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: stress - # Until there is a dedicated stress test, re-use the perf test. - test_command: .\ebpf_performance.exe -d yes - build_artifact: Build-x64 - environment: windows-2022 - # No code coverage on stress. - code_coverage: false - gather_dumps: true - - # Run the unit tests in GitHub with address sanitizer. - sanitize_unit_tests: - needs: sanitize - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: unit_tests - # Exclude [processes] test that ASAN can't work with. - test_command: .\unit_tests.exe -d yes ~[processes] - build_artifact: Build-x64-Sanitize - environment: windows-2022 - code_coverage: false - gather_dumps: true - capture_etw: true - - # Run the fault injection simulator in GitHub. - fault_injection: - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: fault_injection - test_command: .\unit_tests.exe - build_artifact: Build-x64 - environment: windows-2022 - code_coverage: true - gather_dumps: true - fault_injection: true - leak_detection: true - - # Run the low memory simulator for netebpfext_unit tests. - fault_injection_netebpfext_unit: - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: netebpfext_fault_injection - test_command: .\netebpfext_unit.exe - build_artifact: Build-x64 - environment: windows-2022 - code_coverage: true - gather_dumps: true - fault_injection: true - leak_detection: true - - # Run a fast multi-threaded stress test pass against the usersim user-mode 'mock' framework. - # Added as a 'per-PR' test to catch usersim regressions and/or run-time usage issues. - quick_user_mode_multi_threaded_stress_test: - needs: regular - if: github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' - uses: ./.github/workflows/reusable-test.yml - with: - name: quick_user_mode_multi_threaded_stress - test_command: .\ebpf_stress_tests_um -tt=8 -td=2 - build_artifact: Build-x64 - environment: windows-2022 - code_coverage: false - leak_detection: false - gather_dumps: true - capture_etw: true - - # Additional jobs to run on a schedule only (skip push and pull request). - # --------------------------------------------------------------------------- - codeql: - # Only run during daily scheduled run - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-build.yml - with: - ref: ${{ github.ref }} - repository: ${{ github.repository }} - build_artifact: Build-x64-CodeQl - build_codeql: true - - - # Run the complete fault injection simulator in GitHub. - # Runs on a schedule as this takes a long time to run. - fault_injection_full: - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: fault_injection_full - test_command: .\unit_tests.exe - build_artifact: Build-x64 - environment: windows-2022 - code_coverage: false - gather_dumps: true - fault_injection: true - leak_detection: true - - # Run the complete fault injection simulator for netebpfext in GitHub. - # Runs on a schedule as this takes a long time to run. - netebpfext_fault_injection_full: - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: netebpfext_fault_injection_full - test_command: .\netebpfext_unit.exe - build_artifact: Build-x64 - environment: windows-2022 - code_coverage: false - gather_dumps: true - fault_injection: true - - # Run multi-threaded stress tests against the user mode 'mock' framework. - user_mode_multi_threaded_stress_test: - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: user_mode_multi_threaded_stress - test_command: .\ebpf_stress_tests_um -tt=8 -td=10 - build_artifact: Build-x64 - environment: windows-2022 - code_coverage: false - leak_detection: false - gather_dumps: true - capture_etw: true - - # Run multi-threaded stress tests with 'restart extension' disabled (default behavior) - # against the kernel mode eBPF sub-system. - km_mt_stress_tests: - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: km_mt_stress_tests - pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "memory" - test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Stress" - post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - build_artifact: Build-x64 - environment: ebpf_cicd_tests_ws2019 - code_coverage: false - # For this test, we only want kernel mode dumps and not user mode dumps. - gather_dumps: false - - # Run multi-threaded stress tests with 'restart extension' enabled - # against the kernel mode eBPF sub-system. - km_mt_stress_tests_restart_extension: - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: km_mt_stress_tests_restart_extension - pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "memory" - test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Stress" -Options @("RestartExtension") - post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - build_artifact: Build-x64 - environment: ebpf_cicd_tests_ws2019 - code_coverage: false - # For this test, we only want kernel mode dumps and not user mode dumps. - gather_dumps: false - - performance: - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: km_performance - pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" - test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Performance" - post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - build_artifact: Build-x64 - environment: ebpf_cicd_perf_ws2022 - configurations: '["Release"]' - - netperf: - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/netperf.yml - with: - sha: ${{ github.sha }} - ref: ${{ github.ref }} - pull_request: ${{ github.event.pull_request.number }} - secrets: - NET_PERF_TRIGGER: ${{ secrets.NET_PERF_TRIGGER }} - - upload_perf_results: - needs: performance - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/upload-perf-results.yml - with: - name: upload_perf_results - result_artifact: km_performance-x64-Release - secrets: - AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} - AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} - AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - - upload_netperf_results_azure_2022: - needs: netperf - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/upload-perf-results.yml - with: - name: upload_netperf_results_azure_2022 - result_artifact: netperf_azure_2022_x64 - platform: Azure Windows 2022 - secrets: - AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} - AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} - AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - - upload_netperf_results_lab_2022: - needs: netperf - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/upload-perf-results.yml - with: - name: upload_netperf_results_lab_2022 - result_artifact: netperf_lab_2022_x64 - platform: Lab Windows 2022 - secrets: - AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} - AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} - AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index e8e70080bd..aa17bbb72c 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -69,7 +69,9 @@ jobs: strategy: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: ${{inputs.environment}} + runs-on: + - self-hosted + - "1ES.Pool=ebpf-cicd-runner-pool-server-2019" env: # Configuration type to build. SOURCE_ROOT: ${{github.workspace}} From 1c3de49402019bb90a936fb3a3a4184316e2d1f1 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" Date: Tue, 29 Oct 2024 15:47:18 -0700 Subject: [PATCH 002/190] TEST --- .github/workflows/reusable-test.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index aa17bbb72c..5e938a224f 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -233,6 +233,16 @@ jobs: .\export_program_info_sample.exe --clear .\export_program_info_sample.exe + - name: 1ES TEST + 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: | + hostname + whoami + powershell.exe Get-VM + dir /s + - 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 From f364af06bc03fced4028cf98eb8fc2a4e0a7b75b Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" Date: Tue, 29 Oct 2024 15:52:29 -0700 Subject: [PATCH 003/190] update --- .github/workflows/reusable-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 5e938a224f..f2aed9a228 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -235,7 +235,7 @@ jobs: - name: 1ES TEST 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 + id: 1es_test working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | hostname From 4f025006807b960f44e9f5a774c4a3afae0e1dfb Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" Date: Tue, 29 Oct 2024 15:54:35 -0700 Subject: [PATCH 004/190] fix --- .github/workflows/reusable-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index f2aed9a228..be3cb164a9 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -235,7 +235,7 @@ jobs: - name: 1ES TEST 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: 1es_test + id: test_1es working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | hostname From 4f3dbee0d4650553d927ac9f8df1ac590ee3add1 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" Date: Wed, 30 Oct 2024 09:39:12 -0700 Subject: [PATCH 005/190] more removal for now --- .github/workflows/cicd.yml | 36 +----------------------------------- 1 file changed, 1 insertion(+), 35 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index ce371e7dfb..1926a3aa55 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -55,41 +55,7 @@ jobs: build_msi: true build_nuget: true build_options: /p:ReleaseJIT='True' - configurations: '["Debug", "FuzzerDebug", "Release"]' - - - onebranch: - strategy: - matrix: - Architecture: ['x64', 'ARM64'] - # Always run this job. - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-build.yml - with: - ref: ${{ github.ref }} - repository: ${{ github.repository }} - build_artifact: Build-${{ matrix.Architecture }}-onebranch - generate_release_package: true - build_msi: true - build_nuget: true - configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' - build_options: /p:BuildOneBranch='True' /t:tools\onebranch /t:installer\ebpf-for-windows - solution_file: "ebpf-for-windows.sln" - architecture: ${{ matrix.Architecture }} - download_demo_repository: false - - # Perform the native-only build. - regular_native-only: - # Always run this job. - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-build.yml - with: - ref: ${{ github.ref }} - repository: ${{ github.repository }} - build_artifact: Build-x64-native-only - build_msi: true - build_nuget: true - configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' + configurations: '["Release"]' # Run the driver tests on self-hosted runners. driver_ws2019: From ed51912b1033bc56a12800eaf90ef3773ef316ce Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" Date: Wed, 30 Oct 2024 12:38:57 -0700 Subject: [PATCH 006/190] WIP --- .github/workflows/cicd.yml | 30 +- .github/workflows/reusable-test.yml | 899 ++++++++++++++-------------- 2 files changed, 470 insertions(+), 459 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 1926a3aa55..1d172e2823 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -42,26 +42,26 @@ jobs: # Jobs to run on pull, push, and schedule. # --------------------------------------------------------------------------- - # Perform the regular build. - regular: - # Always run this job. - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-build.yml - with: - ref: ${{ github.ref }} - repository: ${{ github.repository }} - build_artifact: Build-x64 - generate_release_package: true - build_msi: true - build_nuget: true - build_options: /p:ReleaseJIT='True' - configurations: '["Release"]' + # # Perform the regular build. + # regular: + # # Always run this job. + # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-build.yml + # with: + # ref: ${{ github.ref }} + # repository: ${{ github.repository }} + # build_artifact: Build-x64 + # generate_release_package: true + # build_msi: true + # build_nuget: true + # build_options: /p:ReleaseJIT='True' + # configurations: '["Release"]' # Run the driver tests on self-hosted runners. driver_ws2019: # Always run this job. # Only run this on repos that have self-host runners. - needs: regular + # needs: regular if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') uses: ./.github/workflows/reusable-test.yml with: diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index be3cb164a9..0a66a428b5 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -91,448 +91,459 @@ jobs: with: egress-policy: audit - - name: Print CPU information - run: - Get-WmiObject -Class Win32_Processor | Select-Object -Property Name, NumberOfCores, NumberOfLogicalProcessors - - - 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@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 - # 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 }} - - # Perform shallow checkout for self-hosted runner. - - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 - 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') - with: - ref: ${{ github.event.workflow_run.head_branch }} - - # Check if .github/workflows/reusable-test.yml exists locally. - - name: Check for .github/workflows/reusable-test.yml - # Check for test logs even if the workflow failed. - uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 - if: (inputs.gather_dumps == true) && (steps.skip_check.outputs.should_skip != 'true') - id: check_reusable_test_locally - with: - files: .github/workflows/reusable-test.yml - - # Check out just this file if code hasn't been checked out yet. - - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 - if: (steps.check_reusable_test_locally.outputs.files_exists != 'true') && (steps.skip_check.outputs.should_skip != 'true') - with: - sparse-checkout: | - .github/workflows/reusable-test.yml - sparse-checkout-cone-mode: false - - - name: Set up choco cache folder - # Set the choco cache to a local folder so that it can be cached. - if: (inputs.gather_dumps == true) && (steps.skip_check.outputs.should_skip != 'true') - id: choco-cache - run: | - mkdir ${{github.workspace}}\choco_cache - choco config set --name cacheLocation --value ${{github.workspace}}\choco_cache - - - name: Cache choco packages - # Add cache entry for any choco packages that are installed. - # The cache key is based on the hash of this file so if any choco packages are added or removed, the cache will be invalidated. - if: (inputs.gather_dumps == true) && (steps.skip_check.outputs.should_skip != 'true') - uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 - env: - cache-name: cache-choco-packages - with: - path: ${{github.workspace}}\choco_cache - key: ${{ hashFiles('.github/workflows/reusable-test.yml') }} - - - 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: Create generated artifact folder - if: (steps.skip_check.outputs.should_skip != 'true') - run: | - mkdir ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\Artifacts - - - 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}}\ebpfforwindows.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" - powershell.exe "echo 'ASAN_OPTIONS=allocator_may_return_null=1' | 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: | - .\export_program_info.exe --clear - .\export_program_info.exe - - - name: Configure eBPF store (undocked) - if: (steps.skip_check.outputs.should_skip != 'true') && (matrix.configurations != 'FuzzerDebug') - id: configure_ebpf_store_undocked - working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} - run: | - .\export_program_info_sample.exe --clear - .\export_program_info_sample.exe - - - name: 1ES TEST - 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: test_1es - working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} - run: | - hostname - whoami - powershell.exe Get-VM - dir /s - - - 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 pre test command on self-hosted runner - 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_self_hosted - working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} - run: | - ${{env.PRE_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} -RegressionArtifactsConfiguration ${{env.BUILD_CONFIGURATION}} - - # TODO: Clean up the combination of options: https://github.com/microsoft/ebpf-for-windows/issues/1590 - - name: Run test with Code Coverage in VS Dev environment - if: (inputs.code_coverage == true) && (inputs.vs_dev == true) && (steps.skip_check.outputs.should_skip != 'true') - id: run_test_with_code_coverage_in_vs_dev - shell: cmd - run: | - call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" - 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}} -- ${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\${{env.TEST_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}} 8 - - - 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 on self-hosted runner - if: (inputs.code_coverage == false) && (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') && (inputs.fault_injection != true) - id: run_test_self_hosted - working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} + - name: maige_test + id: maige-test run: | - ${{env.TEST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} - - - name: Run test without Code Coverage - if: (inputs.code_coverage == false) && (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') && (inputs.fault_injection != true) - id: run_test_without_code_coverage - working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} - shell: cmd - run: | - cd /d ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}} - powershell.exe .\Run-Test.ps1 ${{env.DUMP_PATH}} ${{env.TEST_TIMEOUT}} ${{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: Run post test command on self-hosted runner - # 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_self_hosted - working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} - run: | - ${{env.POST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} - - - 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\ebpfforwindows.etl - - - name: Copy any bpf2c test logs to TestLogs - if: (inputs.name == 'bpf2c') && (inputs.capture_etw == true) && (steps.skip_check.outputs.should_skip != 'true') - shell: cmd - run: | - copy ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\*.log ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\TestLogs - - - 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: 10 - - - 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: 10 - - - name: Check for generated artifacts - # Check for artifacts even if the workflow failed. - if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') - uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 - id: check_artifacts - with: - files: ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\Artifacts\* - - - 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: 10 - - - 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, - }); + powershell.exe "Get-NetAdapter" + powershell.exe "Get-VMSwitch" + powershell.exe "cd C:\bin\CloudTestWorker\ProvisioningScript; dir; .\Setup.ps1" + powershell.exe "Get-NetAdapter" + powershell.exe "Get-VMSwitch" + powershell.exe "Get-VM" + + # - name: Print CPU information + # run: + # Get-WmiObject -Class Win32_Processor | Select-Object -Property Name, NumberOfCores, NumberOfLogicalProcessors + + # - 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@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 + # # 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 }} + + # # Perform shallow checkout for self-hosted runner. + # - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 + # 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') + # with: + # ref: ${{ github.event.workflow_run.head_branch }} + + # # Check if .github/workflows/reusable-test.yml exists locally. + # - name: Check for .github/workflows/reusable-test.yml + # # Check for test logs even if the workflow failed. + # uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 + # if: (inputs.gather_dumps == true) && (steps.skip_check.outputs.should_skip != 'true') + # id: check_reusable_test_locally + # with: + # files: .github/workflows/reusable-test.yml + + # # Check out just this file if code hasn't been checked out yet. + # - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 + # if: (steps.check_reusable_test_locally.outputs.files_exists != 'true') && (steps.skip_check.outputs.should_skip != 'true') + # with: + # sparse-checkout: | + # .github/workflows/reusable-test.yml + # sparse-checkout-cone-mode: false + + + # - name: Set up choco cache folder + # # Set the choco cache to a local folder so that it can be cached. + # if: (inputs.gather_dumps == true) && (steps.skip_check.outputs.should_skip != 'true') + # id: choco-cache + # run: | + # mkdir ${{github.workspace}}\choco_cache + # choco config set --name cacheLocation --value ${{github.workspace}}\choco_cache + + # - name: Cache choco packages + # # Add cache entry for any choco packages that are installed. + # # The cache key is based on the hash of this file so if any choco packages are added or removed, the cache will be invalidated. + # if: (inputs.gather_dumps == true) && (steps.skip_check.outputs.should_skip != 'true') + # uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 + # env: + # cache-name: cache-choco-packages + # with: + # path: ${{github.workspace}}\choco_cache + # key: ${{ hashFiles('.github/workflows/reusable-test.yml') }} + + # - 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: Create generated artifact folder + # if: (steps.skip_check.outputs.should_skip != 'true') + # run: | + # mkdir ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\Artifacts + + # - 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}}\ebpfforwindows.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" + # powershell.exe "echo 'ASAN_OPTIONS=allocator_may_return_null=1' | 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: | + # .\export_program_info.exe --clear + # .\export_program_info.exe + + # - name: Configure eBPF store (undocked) + # if: (steps.skip_check.outputs.should_skip != 'true') && (matrix.configurations != 'FuzzerDebug') + # id: configure_ebpf_store_undocked + # working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} + # run: | + # .\export_program_info_sample.exe --clear + # .\export_program_info_sample.exe + + # - name: 1ES TEST + # 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: test_1es + # working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} + # run: | + # hostname + # whoami + # powershell.exe Get-VM + # dir /s + + # - 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 pre test command on self-hosted runner + # 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_self_hosted + # working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} + # run: | + # ${{env.PRE_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} -RegressionArtifactsConfiguration ${{env.BUILD_CONFIGURATION}} + + # # TODO: Clean up the combination of options: https://github.com/microsoft/ebpf-for-windows/issues/1590 + # - name: Run test with Code Coverage in VS Dev environment + # if: (inputs.code_coverage == true) && (inputs.vs_dev == true) && (steps.skip_check.outputs.should_skip != 'true') + # id: run_test_with_code_coverage_in_vs_dev + # shell: cmd + # run: | + # call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" + # 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}} -- ${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\${{env.TEST_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}} 8 + + # - 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 on self-hosted runner + # if: (inputs.code_coverage == false) && (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') && (inputs.fault_injection != true) + # id: run_test_self_hosted + # working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} + # run: | + # ${{env.TEST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} + + # - name: Run test without Code Coverage + # if: (inputs.code_coverage == false) && (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') && (inputs.fault_injection != true) + # id: run_test_without_code_coverage + # working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} + # shell: cmd + # run: | + # cd /d ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}} + # powershell.exe .\Run-Test.ps1 ${{env.DUMP_PATH}} ${{env.TEST_TIMEOUT}} ${{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: Run post test command on self-hosted runner + # # 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_self_hosted + # working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} + # run: | + # ${{env.POST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} + + # - 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\ebpfforwindows.etl + + # - name: Copy any bpf2c test logs to TestLogs + # if: (inputs.name == 'bpf2c') && (inputs.capture_etw == true) && (steps.skip_check.outputs.should_skip != 'true') + # shell: cmd + # run: | + # copy ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\*.log ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\TestLogs + + # - 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: 10 + + # - 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: 10 + + # - name: Check for generated artifacts + # # Check for artifacts even if the workflow failed. + # if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') + # uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 + # id: check_artifacts + # with: + # files: ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\Artifacts\* + + # - 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: 10 + + # - 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, + # }); From 7de87ddb61df2693d6fb0dc4fabf3eb42e383c3a Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" Date: Wed, 30 Oct 2024 12:41:24 -0700 Subject: [PATCH 007/190] wip --- .github/workflows/cicd.yml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 1d172e2823..1926a3aa55 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -42,26 +42,26 @@ jobs: # Jobs to run on pull, push, and schedule. # --------------------------------------------------------------------------- - # # Perform the regular build. - # regular: - # # Always run this job. - # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-build.yml - # with: - # ref: ${{ github.ref }} - # repository: ${{ github.repository }} - # build_artifact: Build-x64 - # generate_release_package: true - # build_msi: true - # build_nuget: true - # build_options: /p:ReleaseJIT='True' - # configurations: '["Release"]' + # Perform the regular build. + regular: + # Always run this job. + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-build.yml + with: + ref: ${{ github.ref }} + repository: ${{ github.repository }} + build_artifact: Build-x64 + generate_release_package: true + build_msi: true + build_nuget: true + build_options: /p:ReleaseJIT='True' + configurations: '["Release"]' # Run the driver tests on self-hosted runners. driver_ws2019: # Always run this job. # Only run this on repos that have self-host runners. - # needs: regular + needs: regular if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') uses: ./.github/workflows/reusable-test.yml with: From 88d29014f98caf8f6df198d303a291457f143203 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" Date: Wed, 30 Oct 2024 12:51:13 -0700 Subject: [PATCH 008/190] wip --- .github/workflows/reusable-test.yml | 892 ++++++++++++++-------------- 1 file changed, 446 insertions(+), 446 deletions(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 0a66a428b5..d07bc36045 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -101,449 +101,449 @@ jobs: powershell.exe "Get-VMSwitch" powershell.exe "Get-VM" - # - name: Print CPU information - # run: - # Get-WmiObject -Class Win32_Processor | Select-Object -Property Name, NumberOfCores, NumberOfLogicalProcessors - - # - 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@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 - # # 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 }} - - # # Perform shallow checkout for self-hosted runner. - # - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 - # 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') - # with: - # ref: ${{ github.event.workflow_run.head_branch }} - - # # Check if .github/workflows/reusable-test.yml exists locally. - # - name: Check for .github/workflows/reusable-test.yml - # # Check for test logs even if the workflow failed. - # uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 - # if: (inputs.gather_dumps == true) && (steps.skip_check.outputs.should_skip != 'true') - # id: check_reusable_test_locally - # with: - # files: .github/workflows/reusable-test.yml - - # # Check out just this file if code hasn't been checked out yet. - # - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 - # if: (steps.check_reusable_test_locally.outputs.files_exists != 'true') && (steps.skip_check.outputs.should_skip != 'true') - # with: - # sparse-checkout: | - # .github/workflows/reusable-test.yml - # sparse-checkout-cone-mode: false - - - # - name: Set up choco cache folder - # # Set the choco cache to a local folder so that it can be cached. - # if: (inputs.gather_dumps == true) && (steps.skip_check.outputs.should_skip != 'true') - # id: choco-cache - # run: | - # mkdir ${{github.workspace}}\choco_cache - # choco config set --name cacheLocation --value ${{github.workspace}}\choco_cache - - # - name: Cache choco packages - # # Add cache entry for any choco packages that are installed. - # # The cache key is based on the hash of this file so if any choco packages are added or removed, the cache will be invalidated. - # if: (inputs.gather_dumps == true) && (steps.skip_check.outputs.should_skip != 'true') - # uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 - # env: - # cache-name: cache-choco-packages - # with: - # path: ${{github.workspace}}\choco_cache - # key: ${{ hashFiles('.github/workflows/reusable-test.yml') }} - - # - 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: Create generated artifact folder - # if: (steps.skip_check.outputs.should_skip != 'true') - # run: | - # mkdir ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\Artifacts - - # - 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}}\ebpfforwindows.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" - # powershell.exe "echo 'ASAN_OPTIONS=allocator_may_return_null=1' | 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: | - # .\export_program_info.exe --clear - # .\export_program_info.exe - - # - name: Configure eBPF store (undocked) - # if: (steps.skip_check.outputs.should_skip != 'true') && (matrix.configurations != 'FuzzerDebug') - # id: configure_ebpf_store_undocked - # working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} - # run: | - # .\export_program_info_sample.exe --clear - # .\export_program_info_sample.exe - - # - name: 1ES TEST - # 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: test_1es - # working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} - # run: | - # hostname - # whoami - # powershell.exe Get-VM - # dir /s - - # - 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 pre test command on self-hosted runner - # 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_self_hosted - # working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} - # run: | - # ${{env.PRE_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} -RegressionArtifactsConfiguration ${{env.BUILD_CONFIGURATION}} - - # # TODO: Clean up the combination of options: https://github.com/microsoft/ebpf-for-windows/issues/1590 - # - name: Run test with Code Coverage in VS Dev environment - # if: (inputs.code_coverage == true) && (inputs.vs_dev == true) && (steps.skip_check.outputs.should_skip != 'true') - # id: run_test_with_code_coverage_in_vs_dev - # shell: cmd - # run: | - # call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" - # 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}} -- ${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\${{env.TEST_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}} 8 - - # - 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 on self-hosted runner - # if: (inputs.code_coverage == false) && (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') && (inputs.fault_injection != true) - # id: run_test_self_hosted - # working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} - # run: | - # ${{env.TEST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} - - # - name: Run test without Code Coverage - # if: (inputs.code_coverage == false) && (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') && (inputs.fault_injection != true) - # id: run_test_without_code_coverage - # working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} - # shell: cmd - # run: | - # cd /d ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}} - # powershell.exe .\Run-Test.ps1 ${{env.DUMP_PATH}} ${{env.TEST_TIMEOUT}} ${{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: Run post test command on self-hosted runner - # # 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_self_hosted - # working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} - # run: | - # ${{env.POST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} - - # - 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\ebpfforwindows.etl - - # - name: Copy any bpf2c test logs to TestLogs - # if: (inputs.name == 'bpf2c') && (inputs.capture_etw == true) && (steps.skip_check.outputs.should_skip != 'true') - # shell: cmd - # run: | - # copy ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\*.log ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\TestLogs - - # - 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: 10 - - # - 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: 10 - - # - name: Check for generated artifacts - # # Check for artifacts even if the workflow failed. - # if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') - # uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 - # id: check_artifacts - # with: - # files: ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\Artifacts\* - - # - 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: 10 - - # - 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, - # }); + - name: Print CPU information + run: + Get-WmiObject -Class Win32_Processor | Select-Object -Property Name, NumberOfCores, NumberOfLogicalProcessors + + - 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@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 + # 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 }} + + # Perform shallow checkout for self-hosted runner. + - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 + 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') + with: + ref: ${{ github.event.workflow_run.head_branch }} + + # Check if .github/workflows/reusable-test.yml exists locally. + - name: Check for .github/workflows/reusable-test.yml + # Check for test logs even if the workflow failed. + uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 + if: (inputs.gather_dumps == true) && (steps.skip_check.outputs.should_skip != 'true') + id: check_reusable_test_locally + with: + files: .github/workflows/reusable-test.yml + + # Check out just this file if code hasn't been checked out yet. + - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 + if: (steps.check_reusable_test_locally.outputs.files_exists != 'true') && (steps.skip_check.outputs.should_skip != 'true') + with: + sparse-checkout: | + .github/workflows/reusable-test.yml + sparse-checkout-cone-mode: false + + + - name: Set up choco cache folder + # Set the choco cache to a local folder so that it can be cached. + if: (inputs.gather_dumps == true) && (steps.skip_check.outputs.should_skip != 'true') + id: choco-cache + run: | + mkdir ${{github.workspace}}\choco_cache + choco config set --name cacheLocation --value ${{github.workspace}}\choco_cache + + - name: Cache choco packages + # Add cache entry for any choco packages that are installed. + # The cache key is based on the hash of this file so if any choco packages are added or removed, the cache will be invalidated. + if: (inputs.gather_dumps == true) && (steps.skip_check.outputs.should_skip != 'true') + uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 + env: + cache-name: cache-choco-packages + with: + path: ${{github.workspace}}\choco_cache + key: ${{ hashFiles('.github/workflows/reusable-test.yml') }} + + - 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: Create generated artifact folder + if: (steps.skip_check.outputs.should_skip != 'true') + run: | + mkdir ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\Artifacts + + - 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}}\ebpfforwindows.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" + powershell.exe "echo 'ASAN_OPTIONS=allocator_may_return_null=1' | 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: | + .\export_program_info.exe --clear + .\export_program_info.exe + + - name: Configure eBPF store (undocked) + if: (steps.skip_check.outputs.should_skip != 'true') && (matrix.configurations != 'FuzzerDebug') + id: configure_ebpf_store_undocked + working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} + run: | + .\export_program_info_sample.exe --clear + .\export_program_info_sample.exe + + - name: 1ES TEST + 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: test_1es + working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} + run: | + hostname + whoami + powershell.exe Get-VM + dir /s + + - 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 pre test command on self-hosted runner + 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_self_hosted + working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} + run: | + ${{env.PRE_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} -RegressionArtifactsConfiguration ${{env.BUILD_CONFIGURATION}} + + # TODO: Clean up the combination of options: https://github.com/microsoft/ebpf-for-windows/issues/1590 + - name: Run test with Code Coverage in VS Dev environment + if: (inputs.code_coverage == true) && (inputs.vs_dev == true) && (steps.skip_check.outputs.should_skip != 'true') + id: run_test_with_code_coverage_in_vs_dev + shell: cmd + run: | + call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" + 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}} -- ${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\${{env.TEST_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}} 8 + + - 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 on self-hosted runner + if: (inputs.code_coverage == false) && (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') && (inputs.fault_injection != true) + id: run_test_self_hosted + working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} + run: | + ${{env.TEST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} + + - name: Run test without Code Coverage + if: (inputs.code_coverage == false) && (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') && (inputs.fault_injection != true) + id: run_test_without_code_coverage + working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} + shell: cmd + run: | + cd /d ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}} + powershell.exe .\Run-Test.ps1 ${{env.DUMP_PATH}} ${{env.TEST_TIMEOUT}} ${{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: Run post test command on self-hosted runner + # 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_self_hosted + working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} + run: | + ${{env.POST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} + + - 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\ebpfforwindows.etl + + - name: Copy any bpf2c test logs to TestLogs + if: (inputs.name == 'bpf2c') && (inputs.capture_etw == true) && (steps.skip_check.outputs.should_skip != 'true') + shell: cmd + run: | + copy ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\*.log ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\TestLogs + + - 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: 10 + + - 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: 10 + + - name: Check for generated artifacts + # Check for artifacts even if the workflow failed. + if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') + uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 + id: check_artifacts + with: + files: ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\Artifacts\* + + - 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: 10 + + - 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, + }); From 40a3ad37f5d64988ff47260f49dc1208ee09d151 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" Date: Wed, 30 Oct 2024 14:23:57 -0700 Subject: [PATCH 009/190] WIP --- .github/workflows/reusable-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index d07bc36045..2463ea1f72 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -96,7 +96,7 @@ jobs: run: | powershell.exe "Get-NetAdapter" powershell.exe "Get-VMSwitch" - powershell.exe "cd C:\bin\CloudTestWorker\ProvisioningScript; dir; .\Setup.ps1" + powershell.exe "cd C:\bin\CloudTestWorker\ProvisioningScript; dir; .\Setup_orig.ps1" powershell.exe "Get-NetAdapter" powershell.exe "Get-VMSwitch" powershell.exe "Get-VM" From 68eb7185622ba28a086083f047d77998bf097d2e Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" Date: Tue, 12 Nov 2024 14:30:54 -0800 Subject: [PATCH 010/190] WIP --- 1es/Setup.ps1 | 29 ++++ 1es/Setup_orig.ps1 | 82 +++++++++ 1es/artifacts.json | 41 +++++ 1es/configure_vm.ps1 | 108 ++++++++++++ 1es/prepare_host.ps1 | 12 ++ 1es/prepare_vm_helpers.psm1 | 321 ++++++++++++++++++++++++++++++++++++ 1es/unattend.xml | 52 ++++++ 7 files changed, 645 insertions(+) create mode 100644 1es/Setup.ps1 create mode 100644 1es/Setup_orig.ps1 create mode 100644 1es/artifacts.json create mode 100644 1es/configure_vm.ps1 create mode 100644 1es/prepare_host.ps1 create mode 100644 1es/prepare_vm_helpers.psm1 create mode 100644 1es/unattend.xml diff --git a/1es/Setup.ps1 b/1es/Setup.ps1 new file mode 100644 index 0000000000..9b3994cd04 --- /dev/null +++ b/1es/Setup.ps1 @@ -0,0 +1,29 @@ +# Copyright (c) eBPF for Windows contributors +# SPDX-License-Identifier: MIT +# param( +# [Parameter(Mandatory=$False)][string]$VmUsername='Administrator', +# [Parameter(Mandatory=$False)][string]$VmPassword='P@ssw0rd', + +# [Parameter(Mandatory=$False)][string]$BaseUnattendPath='.\unattend.xml', +# [Parameter(Mandatory=$False)][string]$BaseVhdDirPath='.\', +# [Parameter(Mandatory=$False)][string]$WorkingPath='.\working', +# [Parameter(Mandatory=$False)][string]$OutVhdDirPath='.\exported_vhds', +# [Parameter(Mandatory=$False)][string]$ExternalSwitchName='VMExternalSwitch', + +# [Parameter(Mandatory=$False)][string]$VMCpuCount=4, +# [Parameter(Mandatory=$False)][string]$VMMemoryStartupBytes=512MB +# ) + +# $ErrorActionPreference = "Stop" + +# # Import helper functions +# Import-Module .\prepare_vm_helpers.psm1 -Force + +$hyperV = (Get-WindowsFeature -Name 'Hyper-V').Installed +Log-Message -Message "Hyper-V is installed: $hyperV" + +$names = (Get-NetAdapter).Name +Log-Message -Message "Network adapters: $names" + +$switches = Get-VMSwitch +Log-Message -Message "VM switches: $switches" diff --git a/1es/Setup_orig.ps1 b/1es/Setup_orig.ps1 new file mode 100644 index 0000000000..9ef71a2100 --- /dev/null +++ b/1es/Setup_orig.ps1 @@ -0,0 +1,82 @@ +# Copyright (c) eBPF for Windows contributors +# SPDX-License-Identifier: MIT +param( + [Parameter(Mandatory=$False)][string]$VmUsername='Administrator', + [Parameter(Mandatory=$False)][string]$VmPassword='P@ssw0rd', + + [Parameter(Mandatory=$False)][string]$BaseUnattendPath='.\unattend.xml', + [Parameter(Mandatory=$False)][string]$BaseVhdDirPath='.\', + [Parameter(Mandatory=$False)][string]$WorkingPath='.\working', + [Parameter(Mandatory=$False)][string]$OutVhdDirPath='.\exported_vhds', + [Parameter(Mandatory=$False)][string]$ExternalSwitchName='VMExternalSwitch', + + [Parameter(Mandatory=$False)][string]$VMCpuCount=2, + [Parameter(Mandatory=$False)][string]$VMMemoryStartupBytes=512MB +) + +$ErrorActionPreference = "Stop" + +# Import helper functions +Import-Module .\prepare_vm_helpers.psm1 -Force + +Create-ExternalSwitchIfNeeded -ExternalSwitchName $ExternalSwitchName +$ExternalSwitches = Get-VMSwitch -SwitchType External +if (-not $ExternalSwitches) { + throw "No external switches found" +} +foreach ($switch in $ExternalSwitches) { + Log-Message "External switch: $switch" + Log-Message "External switch: $($switch.Name)" +} + +if (-not (Test-Path -Path $BaseUnattendPath)) { + throw "Unattend file not found at $BaseUnattendPath" +} + +if (-not (Test-Path -Path $BaseVhdDirPath)) { + throw "VHD directory not found at $BaseVhdDirPath" +} + +Create-DirectoryIfNotExists -Path $WorkingPath + +# Create-DirectoryIfNotExists -Path $OutVhdDirPath + +# Create credential object for executing commands on the VM +# TODO - maybe this can be read from the unattend file? Or passed as an azure parameter, which replaces in the unattend file. +# $vmCredential = Create-VMCredential -VmUsername $VmUsername -VmPassword $VmPassword + +# Read the input VHDs +$vhds = @((Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhd)) +$vhds += Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhdx +if ($vhds.Count -eq 0) { + throw "No VHDs found in $BaseVhdDirPath" +} + +for ($i = 0; $i -lt $vhds.Count; $i++) { + $vhd = $vhds[$i] + Log-Message -Message "Processing VHD: $($vhd.FullName)" + $vmName = "runner_vm" + if ($i -gt 0) { + $vmName += "_$i" + } + $outVMPath = Join-Path -Path $WorkingPath -ChildPath $VMName + + Create-VM ` + -VmName $vmName ` + -VhdPath $vhd.FullName ` + -VmStoragePath $outVMPath ` + -ExternalVMSwitchName $ExternalSwitchName ` + -MemoryStartupBytes $VMMemoryStartupBytes ` + -UnattendPath $BaseUnattendPath ` + -VmUsername $VmUsername ` + -VmPassword $VmPassword + + Configure-VM ` + -VmName $vmName ` + -CpuCount $VMCpuCount ` + -VmUsername $VmUsername ` + -VmPassword $VmPassword + + Export-VM -Name $vmName -Path $OutVhdDirPath + Log-Message -Message "Successfully exported VM: $VMName to $VMWorkingDirectory\$VMName.vhd" -ForegroundColor Green +} diff --git a/1es/artifacts.json b/1es/artifacts.json new file mode 100644 index 0000000000..2eb447c1eb --- /dev/null +++ b/1es/artifacts.json @@ -0,0 +1,41 @@ +{ + "license":["Copyright (c) eBPF for Windows contributors", "SPDX-License-Identifier: MIT"], + "artifacts": [ + { + "name": "windows-bcdedit-testsigning", + "parameters": { + "TestSigningOption": "On" + } + }, + { + "name": "windows-server-install-feature-hyperv" + }, + { + "name": "windows-HyperV-NewVMSwitch", + "parameters" : { + "VMSwitchName": "VMExternalSwitch" + } + }, + { + "name": "windows-gitinstall", + "parameters": { + "SetCredHelper": "false" + } + } + ] +} + + + { + "name": "windows-vcredist-x64" + } + +https://dev.azure.com/devdiv/XlabImageFactory/_git/XlabImageFactory?path=%2Fartifacts +/artifacts/windows-server-install-feature-hyperv/windows-server-install-feature-hyperv.ps1 +\ + +/artifacts/windows-HyperV-NewVMSwitch/windows-HyperV-NewVMSwitch.ps1 + + + +/artifacts/Windows-NestedVirtualization/Windows-NestedVirtualization.ps1 \ No newline at end of file diff --git a/1es/configure_vm.ps1 b/1es/configure_vm.ps1 new file mode 100644 index 0000000000..a9d4481444 --- /dev/null +++ b/1es/configure_vm.ps1 @@ -0,0 +1,108 @@ +# Copyright (c) eBPF for Windows contributors +# SPDX-License-Identifier: MIT + +########## Helper Functions ########## +# Download and extract PSExec to run tests as SYSTEM. +function Get-PSExec { + $url = "https://download.sysinternals.com/files/PSTools.zip" + $DownloadPath = "$pwd\psexec" + mkdir $DownloadPath + Write-Host "Downloading PSExec from $url to $DownloadPath" + $ProgressPreference = 'SilentlyContinue' + Invoke-WebRequest $url -OutFile "$DownloadPath\pstools.zip" + cd $DownloadPath + Expand-Archive -Path "$DownloadPath\pstools.zip" -Force + cd .. + Move-Item -Path "$DownloadPath\PSTools\PsExec64.exe" -Destination $pwd -Force + Remove-Item -Path $DownloadPath -Force -Recurse +} + +function Get-ZipFileFromUrl { + param( + [Parameter(Mandatory=$True)][string] $Url, + [Parameter(Mandatory=$True)][string] $DownloadFilePath, + [Parameter(Mandatory=$True)][string] $OutputDir + ) + + for ($i = 0; $i -lt 5; $i++) { + try { + Write-Host "Downloading $Url to $DownloadFilePath" + $ProgressPreference = 'SilentlyContinue' + Invoke-WebRequest -Uri $Url -OutFile $DownloadFilePath + + Write-Host "Extracting $DownloadFilePath to $OutputDir" + Expand-Archive -Path $DownloadFilePath -DestinationPath $OutputDir -Force + break + } catch { + Write-Host "Iteration $i failed to download $Url. Removing $DownloadFilePath" -ForegroundColor Red + Remove-Item -Path $DownloadFilePath -Force -ErrorAction Ignore + Start-Sleep -Seconds 5 + } + } +} + +# Copied from https://github.com/microsoft/msquic/blob/main/scripts/prepare-machine.ps1 +function Get-Duonic { + # Download and extract https://github.com/microsoft/corenet-ci. + $DownloadPath = "$pwd\corenet-ci" + mkdir $DownloadPath + Write-Host "Downloading CoreNet-CI to $DownloadPath" + Get-ZipFileFromUrl -Url "https://github.com/microsoft/corenet-ci/archive/refs/heads/main.zip" -DownloadFilePath "$DownloadPath\corenet-ci.zip" -OutputDir $DownloadPath + Move-Item -Path "$DownloadPath\corenet-ci-main\vm-setup\duonic\*" -Destination $pwd -Force + Move-Item -Path "$DownloadPath\corenet-ci-main\vm-setup\procdump64.exe" -Destination $pwd -Force + Move-Item -Path "$DownloadPath\corenet-ci-main\vm-setup\notmyfault64.exe" -Destination $pwd -Force + Remove-Item -Path $DownloadPath -Force -Recurse +} + +function Initialize-NetworkInterfacesOnVMs +{ + # param([parameter(Mandatory=$true)] $VMMap) + + # foreach ($VM in $VMMap) + # { + # $VMName = $VM.Name + + # Write-Log "Initializing network interfaces on $VMName" + # $TestCredential = New-Credential -Username $Admin -AdminPassword $AdminPassword + + # Invoke-Command -VMName $VMName -Credential $TestCredential -ScriptBlock { + # param([Parameter(Mandatory=$True)] [string] $WorkingDirectory) + + # Push-Location "$env:SystemDrive\$WorkingDirectory" + + Write-Host "Installing DuoNic driver" + .\duonic.ps1 -Install -NumNicPairs 2 + # Disable Duonic's fake checksum offload and force TCP/IP to calculate it. + Set-NetAdapterAdvancedProperty duo? -DisplayName Checksum -RegistryValue 0 + + # Pop-Location + # } -ArgumentList ("eBPF") -ErrorAction Stop + # } +} + +########## Main Execution ########## + +# Enable test signing. +bcdedit -set TESTSIGNING ON + +# Enable user-mode dumps. +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 +New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpFolder" -Value "c:\dumps" -PropertyType ExpandString -ErrorAction SilentlyContinue -Force + +# Enable kernel dumps. +New-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl" -ErrorAction SilentlyContinue +New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl" -Name "CrashDumpEnabled" -Value 2 -PropertyType DWord -ErrorAction SilentlyContinue + +# Enable driver verifier on the eBPF platform drivers. +verifier /standard /bootmode persistent /driver ebpfcore.sys netebpfext.sys sample_ebpf_ext.sys + +# Install duonic and configure it. +Get-Duonic +Initialize-NetworkInterfacesOnVMs + +# Get PSExec to run tests as SYSTEM. +Get-PSExec + +# Reboot the machine to apply the changes. +Restart-Computer -Force \ No newline at end of file diff --git a/1es/prepare_host.ps1 b/1es/prepare_host.ps1 new file mode 100644 index 0000000000..1ea39fe6e4 --- /dev/null +++ b/1es/prepare_host.ps1 @@ -0,0 +1,12 @@ +# Copyright (c) eBPF for Windows contributors +# SPDX-License-Identifier: MIT +param( + [Parameter(Mandatory=$False)][string]$ExternalSwitchName='VMExternalSwitch' +) + +Import-Module .\prepare_vm_helpers.psm1 -Force + +Install-HyperVIfNeeded +Create-ExternalSwitchIfNeeded -ExternalSwitchName $ExternalSwitchName + +# TODO - Fetch VHDs \ No newline at end of file diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 new file mode 100644 index 0000000000..3404f90d4d --- /dev/null +++ b/1es/prepare_vm_helpers.psm1 @@ -0,0 +1,321 @@ +# Copyright (c) eBPF for Windows contributors +# SPDX-License-Identifier: MIT +$ErrorActionPreference = "Stop" + +function Log-Message { + param( + [Parameter(Mandatory=$True)][string]$Message, + [Parameter(Mandatory=$False)][string]$ForegroundColor='White' + ) + + # Get timestamp + $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" + + Write-Host "[$timestamp] - $Message" -ForegroundColor $ForegroundColor +} + +function Create-DirectoryIfNotExists { + param ( + [Parameter(Mandatory=$True)][string]$Path + ) + + try { + if (-not (Test-Path -Path $Path -PathType Container)) { + New-Item -Path $Path -ItemType Directory -Force # -ErrorAction Ignore | Out-Null + } + + if (-not (Test-Path -PathType Container $Path)) { + throw "Failed to create directory: $Path" + } + } catch { + throw "Failed to create directory: $Path. $_" + } +} + +function Create-VMCredential { + param ( + [Parameter(Mandatory=$True)][string]$VmUsername, + [Parameter(Mandatory=$True)][string]$VmPassword + ) + + try { + $secureVmPassword = ConvertTo-SecureString $VmPassword -AsPlainText -Force + return New-Object System.Management.Automation.PSCredential($VmUsername, $secureVmPassword) + } catch { + throw "Failed to create VM credential: $_" + } +} + +function Replace-PlaceholderStrings { + param ( + [Parameter(Mandatory=$True)][string]$FilePath, + [Parameter(Mandatory=$True)][string]$SearchString, + [Parameter(Mandatory=$True)][string]$ReplaceString + ) + + try { + $content = Get-Content -Path $FilePath + $content = $content -replace $SearchString, $ReplaceString + Set-Content -Path $FilePath -Value $content + } catch { + throw "Failed to replace placeholder strings in file: $FilePath. Error: $_" + } +} + +function Execute-CommandOnVM { + param ( + [Parameter(Mandatory=$True)][string]$VMName, + [Parameter(Mandatory=$True)][System.Management.Automation.PSCredential]$VmCredential, + [Parameter(Mandatory=$True)][string]$Command + ) + + try { + $result = Invoke-Command -VMName $VMName -Credential $VmCredential -ScriptBlock { + param($Command) + Invoke-Expression $Command + } -ArgumentList $Command + + Log-Message -Message "Executed command on VM: $VMName. Command: $Command. Result: $result" + } catch { + throw "Failed to execute command on VM: $VMName. Error: $_" + } +} + +function Wait-ForVMReady { + param ( + [Parameter(Mandatory=$True)][string]$VMName, + [Parameter(Mandatory=$True)][System.Management.Automation.PSCredential]$VmCredential, + [Parameter(Mandatory=$False)][int]$TimeoutInMinutes=30 + ) + + # Attempt for a maximum of 30 minutes + $limit = (Get-Date).AddMinutes($TimeoutInMinutes) + while ((Get-Date) -le $limit) { + try { + # Ensure the VM is in running state + while ((Get-VM -Name $VMName).State -ne 'Running') { + Log-Message -Message "Waiting for $VMName to reach running state..." + Start-Sleep -Seconds 5 + } + + # Trivial command to ensure that we can connect to the VM. + try { + Execute-CommandOnVM -VMName $VMName -VmCredential $VmCredential -Command 'hostname' + } catch { + Log-Message -Message "Failed to connect to $VMName. Retrying..." + Start-Sleep -Seconds 5 + continue + } + + Log-Message -Message "Successfully connected to $VMName" + return + } catch { + # Do nothing. We will retry if we failed to connect to the VM. + } + + Log-Message -Message "Failed to connect to $VMName. Retrying..." + Start-Sleep -Seconds 5 + } + + # If we reached here, we failed to connect to the VM. + throw "Failed to connect to $VMName after timeout..." +} + +function Update-VM { + param ( + [Parameter(Mandatory=$True)][string]$VMName, + [Parameter(Mandatory=$True)][System.Management.Automation.PSCredential]$VmCredential + ) + +# TODO debugging output - remove later + Get-VMNetworkAdapter -All + try { Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "ipconfig /all" } catch { Log-Message -Message "Failed to query IP config: $_" -ForegroundColor Red } + + try { Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "Invoke-WebRequest bing.com" } catch { Log-Message -Message "Failed to connect to the internet: $_" -ForegroundColor Red } + + try { Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "Install-PackageProvider -Name NuGet -Force" } catch { Log-Message -Message "Failed to install NuGet provider: $_" -ForegroundColor Red } + try { Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "Install-Module -Name PSWindowsUpdate -Force" } catch { Log-Message -Message "Failed to install PSWindowsUpdate module: $_" -ForegroundColor Red } + try { Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "Get-WindowsUpdate -Install -AcceptAll -AutoReboot" } catch { Log-Message -Message "Failed to install updates: $_" -ForegroundColor Red } + + Sleep -Seconds 300 # Sleep for 5 minutes to let the VM start fetching updates, etc... + Wait-ForVMReady -VMName $VMName -VmCredential $VmCredential + Log-Message -Message "Successfully updated VM: $VMName" -ForegroundColor Green +} + +function Create-VM { + param( + [Parameter(Mandatory=$True)][string]$VmName, + [Parameter(Mandatory=$True)][string]$VmUsername, + [Parameter(Mandatory=$True)][string]$VmPassword, + [Parameter(Mandatory=$True)][string]$VhdPath, + [Parameter(Mandatory=$True)][string]$VmStoragePath, + [Parameter(Mandatory=$True)][string]$ExternalVMSwitchName, + [Parameter(Mandatory=$True)][Int64]$MemoryStartupBytes, + [Parameter(Mandatory=$True)][string]$UnattendPath + ) + + try { + ## Check for any pre-requisites + # Check that the External Switch exists + $externalSwitches = Get-VMSwitch -SwitchType External + if ($externalSwitches -eq $null) { + throw "No external switches found" + } + + # Check that the VHD exists + if (-not (Test-Path -Path $VhdPath)) { + throw "VHD not found at $VhdPath" + } + + ## Create the VM + # Create storage directory for the VM + Create-DirectoryIfNotExists -Path $VmStoragePath + + # Move the VHD to the path + Log-Message "Moving $VhdPath to $VmStoragePath" + Move-Item -Path $VhdPath -Destination $VmStoragePath -Force + $VmVhdPath = Join-Path -Path $VmStoragePath -ChildPath (Split-Path -Path $VhdPath -Leaf) + + # Move unattend to the path + Log-Message "Moving $UnattendPath file to $VmStoragePath" + Move-Item -Path $UnattendPath -Destination $VmStoragePath -Force + $VmUnattendPath = Join-Path -Path $VmStoragePath -ChildPath (Split-Path -Path $UnattendPath -Leaf) + Replace-PlaceholderStrings -FilePath $VmUnattendPath -SearchString 'PLACEHOLDER_USERNAME' -ReplaceString $VmUsername + Replace-PlaceholderStrings -FilePath $VmUnattendPath -SearchString 'PLACEHOLDER_PASSWORD' -ReplaceString $VmPassword + + # Configure the VHD with the unattend file. + Log-Message "Mounting VHD and applying unattend file" + $VmMountPath = Join-Path -Path $VmStoragePath -ChildPath 'mountedVhd' + if (-not (Test-Path -Path $VmMountPath)) { + New-Item -ItemType Directory -Path $VmMountPath + } + Mount-WindowsImage -ImagePath $VmVhdPath -Index 1 -Path $VmMountPath -ErrorAction Stop | Out-Null + Copy-Item -Path $VmUnattendPath -Destination $VmMountPath\Unattend.xml + Apply-WindowsUnattend -Path $VmMountPath -UnattendPath $VmMountPath\Unattend.xml -ErrorAction Stop | Out-Null + Dismount-WindowsImage -Path $VmMountPath -Save -ErrorAction Stop + + # Create the VM + Log-Message "Creating the VM" + New-VM -Name $VmName -MemoryStartupBytes $MemoryStartupBytes -VhdPath $VmVhdPath # -SwitchName $ExternalVMSwitchName + foreach ($switch in $externalSwitches) { + Log-Message "Adding network adapter to VM: $VmName with switch: $($switch.Name)" + Add-VMNetworkAdapter -VMName $VmName -SwitchName $switch.Name + } + + if ((Get-VM -VMName $vmName) -eq $null) { + throw "Failed to create VM: $VMName" + } + + Log-Message -Message "Successfully created VM: $VMName" -ForegroundColor Green + } catch { + throw "Failed to create VM: $VmName. Error: $_" + } +} + +function Configure-VM { + param( + [Parameter(Mandatory=$True)][string]$VmName, + [Parameter(Mandatory=$True)][string]$VmUsername, + [Parameter(Mandatory=$True)][string]$VmPassword, + [Parameter(Mandatory=$True)][int]$CpuCount, + [Parameter(Mandatory=$False)][string]$VMWorkingDirectory='C:\ebpf_cicd', + [Parameter(Mandatory=$False)][string]$VMSetupScript='.\configure_vm.ps1' + ) + + try { + Log-Message "Configuring VM: $VmName" + + # Post VM creation configuration steps. + Log-Message "Setting VM processor count to $CpuCount" + Set-VMProcessor -VMName $VmName -Count $CpuCount + Log-Message "Enabling Guest Service Interface" + Enable-VMIntegrationService -VMName $VMName -Name 'Guest Service Interface' + + # Get the VM credential + $VmCredential = Create-VMCredential -VmUsername $VmUsername -VmPassword $VmPassword + + # Start the VM + Log-Message "Starting VM: $VmName" + Start-VM -Name $VmName + Wait-ForVMReady -VMName $VmName -VmCredential $VmCredential + + Log-Message "Sleeping for 1 minute to let the VM get into a steady state" + Sleep -Seconds 60 # Sleep for 1 minute to let the VM get into a steady state. + + # Fetch all updates on the VM + Log-Message "Fetching Updates on the VM" + Update-VM -VMName $VmName -VmCredential $VmCredential + Log-Message -Message "Successfully updated VM: $VMName" -ForegroundColor Green + + # Copy setup script to the VM and execute it. + Log-Message "Executing VM configuration script ($VMSetupScript) on VM: $VmName" + Copy-VMFile -VMName $VmName -FileSource Host -SourcePath $VMSetupScript -DestinationPath "$VMWorkingDirectory\$VMSetupScript" -CreateFullPath + Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "cd $VMWorkingDirectory; .\$VMSetupScript" + Log-Message -Message "Successfully executed VM configuration script ($VMSetupScript) on VM: $VmName" -ForegroundColor Green + + Wait-ForVMReady -VMName $VmName -VmCredential $VmCredential + + # Checkpoint the VM. + Log-Message "Checkpointing VM: $VmName" + Checkpoint-VM -Name $VMName -SnapshotName 'baseline' + Log-Message -Message "Successfully added 'baseline' checkpoint for VM: $VMName" -ForegroundColor Green + + # Export the configured VHD. + # TODO - set the path... + # Export-VM -Name $VMName -Path "$VMWorkingDirectory\$VMName.vhd" + # Log-Message -Message "Successfully exported VM: $VMName to $VMWorkingDirectory\$VMName.vhd" -ForegroundColor Green + } catch { + throw "Failed to configure VM: $VmName. Error: $_" + } +} + +########## Helpers for the host machine ########## +function Install-HyperVIfNeeded { + try { + if ((Get-WindowsFeature -Name 'Hyper-V').Installed) { + Log-Message -Message 'Hyper-V is already installed on this host' + } else { + Log-Message -Message 'Hyper-V is not installed on this host. Installing now...' + + Import-Module ServerManager + Install-WindowsFeature -Name 'Hyper-V' -IncludeManagementTools + Restart-Computer -Force + exit 1 + } + } catch { + throw "Failed to install Hyper-V: $_" + } +} + +function Create-ExternalSwitchIfNeeded { + param ( + [Parameter(Mandatory=$False)][string]$ExternalSwitchName='VMExternalSwitch' + ) + try { + # Check to see if an external switch already exists + $ExternalSwitches = (Get-VMSwitch -SwitchType External) + if ($ExternalSwitches -ne $null) { + Log-Message -Message "External switch already exists: $($ExternalSwitches[0].Name)" + return + } + + # Try to create the external switch + $NetAdapterNames = (Get-NetAdapter -Name 'Ethernet*' | Where-Object { $_.Status -eq 'Up' }).Name + $index = 0 + foreach ($NetAdapterName in $NetAdapterNames) { + try { + if ([string]::IsNullOrEmpty($NetAdapterName)) { + continue + } + $switchName = $ExternalSwitchName + '-' + $index + Log-Message "Attempting to creating external switch: $switchName with NetAdapter: $NetAdapterName" + New-VMSwitch -Name $switchName -NetAdapterName $NetAdapterName -AllowManagementOS $true + # break + } catch { + Log-Message "Failed to create external switch for NetAdapter: $NetAdapterName $_" + } + } + } catch { + throw "Failed to create external switch: $_" + } +} diff --git a/1es/unattend.xml b/1es/unattend.xml new file mode 100644 index 0000000000..27515d26ff --- /dev/null +++ b/1es/unattend.xml @@ -0,0 +1,52 @@ + + + + + + + + true + true + true + true + true + true + true + + + + PLACEHOLDER_PASSWORD + true</PlainText> + </AdministratorPassword> + <LocalAccounts> + <LocalAccount> + <Password> + <Value>PLACEHOLDER_PASSWORD</Value> + <PlainText>true</PlainText> + </Password> + <Description>Standard User Account</Description> + <DisplayName>VMStandardUser</DisplayName> + <Name>VMStandardUser</Name> + </LocalAccount> + </LocalAccounts> + </UserAccounts> + <AutoLogon> + <Password> + <Value>PLACEHOLDER_PASSWORD</Value> + <PlainText>true</PlainText> + </Password> + <Enabled>true</Enabled> + <LogonCount>9999</LogonCount> + <Username>PLACEHOLDER_USERNAME</Username> + </AutoLogon> + </component> + </settings> + <!-- <settings pass="specialize"> + <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <ComputerName>%ComputerNamePlaceholder%</ComputerName> + <DoNotCleanTaskBar>true</DoNotCleanTaskBar> + </component> + </settings> --> +</unattend> From 2883f2e11786b87c7ee4263dc522e727c92616cd Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 12 Nov 2024 14:33:56 -0800 Subject: [PATCH 011/190] Try without exteranl switch --- 1es/Setup.ps1 | 4 +++ 1es/Setup_orig.ps1 | 18 ++++++------- 1es/artifacts.json | 35 +------------------------- 1es/configure_vm.ps1 | 11 ++++---- 1es/prepare_host.ps1 | 12 --------- 1es/prepare_vm_helpers.psm1 | 50 ++++++++++++++++++------------------- 6 files changed, 45 insertions(+), 85 deletions(-) delete mode 100644 1es/prepare_host.ps1 diff --git a/1es/Setup.ps1 b/1es/Setup.ps1 index 9b3994cd04..70ef1753a1 100644 --- a/1es/Setup.ps1 +++ b/1es/Setup.ps1 @@ -27,3 +27,7 @@ Log-Message -Message "Network adapters: $names" $switches = Get-VMSwitch Log-Message -Message "VM switches: $switches" + + + +# TODO - eventually, setup_orig will become setup.ps1 \ No newline at end of file diff --git a/1es/Setup_orig.ps1 b/1es/Setup_orig.ps1 index 9ef71a2100..e83c9c7e88 100644 --- a/1es/Setup_orig.ps1 +++ b/1es/Setup_orig.ps1 @@ -19,15 +19,15 @@ $ErrorActionPreference = "Stop" # Import helper functions Import-Module .\prepare_vm_helpers.psm1 -Force -Create-ExternalSwitchIfNeeded -ExternalSwitchName $ExternalSwitchName -$ExternalSwitches = Get-VMSwitch -SwitchType External -if (-not $ExternalSwitches) { - throw "No external switches found" -} -foreach ($switch in $ExternalSwitches) { - Log-Message "External switch: $switch" - Log-Message "External switch: $($switch.Name)" -} +# Create-ExternalSwitchIfNeeded -ExternalSwitchName $ExternalSwitchName +# $ExternalSwitches = Get-VMSwitch -SwitchType External +# if (-not $ExternalSwitches) { +# throw "No external switches found" +# } +# foreach ($switch in $ExternalSwitches) { +# Log-Message "External switch: $switch" +# Log-Message "External switch: $($switch.Name)" +# } if (-not (Test-Path -Path $BaseUnattendPath)) { throw "Unattend file not found at $BaseUnattendPath" diff --git a/1es/artifacts.json b/1es/artifacts.json index 2eb447c1eb..0acb5a104b 100644 --- a/1es/artifacts.json +++ b/1es/artifacts.json @@ -1,41 +1,8 @@ { "license":["Copyright (c) eBPF for Windows contributors", "SPDX-License-Identifier: MIT"], "artifacts": [ - { - "name": "windows-bcdedit-testsigning", - "parameters": { - "TestSigningOption": "On" - } - }, { "name": "windows-server-install-feature-hyperv" - }, - { - "name": "windows-HyperV-NewVMSwitch", - "parameters" : { - "VMSwitchName": "VMExternalSwitch" - } - }, - { - "name": "windows-gitinstall", - "parameters": { - "SetCredHelper": "false" - } } ] -} - - - { - "name": "windows-vcredist-x64" - } - -https://dev.azure.com/devdiv/XlabImageFactory/_git/XlabImageFactory?path=%2Fartifacts -/artifacts/windows-server-install-feature-hyperv/windows-server-install-feature-hyperv.ps1 -\ - -/artifacts/windows-HyperV-NewVMSwitch/windows-HyperV-NewVMSwitch.ps1 - - - -/artifacts/Windows-NestedVirtualization/Windows-NestedVirtualization.ps1 \ No newline at end of file +} \ No newline at end of file diff --git a/1es/configure_vm.ps1 b/1es/configure_vm.ps1 index a9d4481444..81db964d46 100644 --- a/1es/configure_vm.ps1 +++ b/1es/configure_vm.ps1 @@ -97,12 +97,13 @@ New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl" -Na # Enable driver verifier on the eBPF platform drivers. verifier /standard /bootmode persistent /driver ebpfcore.sys netebpfext.sys sample_ebpf_ext.sys -# Install duonic and configure it. -Get-Duonic -Initialize-NetworkInterfacesOnVMs +# TODO - this will either need to be done post VM creation, or run on the host and copied into the VM +# # Install duonic and configure it. +# Get-Duonic +# Initialize-NetworkInterfacesOnVMs -# Get PSExec to run tests as SYSTEM. -Get-PSExec +# # Get PSExec to run tests as SYSTEM. +# Get-PSExec # Reboot the machine to apply the changes. Restart-Computer -Force \ No newline at end of file diff --git a/1es/prepare_host.ps1 b/1es/prepare_host.ps1 deleted file mode 100644 index 1ea39fe6e4..0000000000 --- a/1es/prepare_host.ps1 +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright (c) eBPF for Windows contributors -# SPDX-License-Identifier: MIT -param( - [Parameter(Mandatory=$False)][string]$ExternalSwitchName='VMExternalSwitch' -) - -Import-Module .\prepare_vm_helpers.psm1 -Force - -Install-HyperVIfNeeded -Create-ExternalSwitchIfNeeded -ExternalSwitchName $ExternalSwitchName - -# TODO - Fetch VHDs \ No newline at end of file diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index 3404f90d4d..26b97cc37d 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -121,26 +121,26 @@ function Wait-ForVMReady { throw "Failed to connect to $VMName after timeout..." } -function Update-VM { - param ( - [Parameter(Mandatory=$True)][string]$VMName, - [Parameter(Mandatory=$True)][System.Management.Automation.PSCredential]$VmCredential - ) +# function Update-VM { +# param ( +# [Parameter(Mandatory=$True)][string]$VMName, +# [Parameter(Mandatory=$True)][System.Management.Automation.PSCredential]$VmCredential +# ) -# TODO debugging output - remove later - Get-VMNetworkAdapter -All - try { Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "ipconfig /all" } catch { Log-Message -Message "Failed to query IP config: $_" -ForegroundColor Red } +# # TODO debugging output - remove later +# Get-VMNetworkAdapter -All +# try { Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "ipconfig /all" } catch { Log-Message -Message "Failed to query IP config: $_" -ForegroundColor Red } - try { Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "Invoke-WebRequest bing.com" } catch { Log-Message -Message "Failed to connect to the internet: $_" -ForegroundColor Red } +# try { Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "Invoke-WebRequest bing.com" } catch { Log-Message -Message "Failed to connect to the internet: $_" -ForegroundColor Red } - try { Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "Install-PackageProvider -Name NuGet -Force" } catch { Log-Message -Message "Failed to install NuGet provider: $_" -ForegroundColor Red } - try { Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "Install-Module -Name PSWindowsUpdate -Force" } catch { Log-Message -Message "Failed to install PSWindowsUpdate module: $_" -ForegroundColor Red } - try { Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "Get-WindowsUpdate -Install -AcceptAll -AutoReboot" } catch { Log-Message -Message "Failed to install updates: $_" -ForegroundColor Red } +# try { Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "Install-PackageProvider -Name NuGet -Force" } catch { Log-Message -Message "Failed to install NuGet provider: $_" -ForegroundColor Red } +# try { Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "Install-Module -Name PSWindowsUpdate -Force" } catch { Log-Message -Message "Failed to install PSWindowsUpdate module: $_" -ForegroundColor Red } +# try { Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "Get-WindowsUpdate -Install -AcceptAll -AutoReboot" } catch { Log-Message -Message "Failed to install updates: $_" -ForegroundColor Red } - Sleep -Seconds 300 # Sleep for 5 minutes to let the VM start fetching updates, etc... - Wait-ForVMReady -VMName $VMName -VmCredential $VmCredential - Log-Message -Message "Successfully updated VM: $VMName" -ForegroundColor Green -} +# Sleep -Seconds 300 # Sleep for 5 minutes to let the VM start fetching updates, etc... +# Wait-ForVMReady -VMName $VMName -VmCredential $VmCredential +# Log-Message -Message "Successfully updated VM: $VMName" -ForegroundColor Green +# } function Create-VM { param( @@ -157,10 +157,10 @@ function Create-VM { try { ## Check for any pre-requisites # Check that the External Switch exists - $externalSwitches = Get-VMSwitch -SwitchType External - if ($externalSwitches -eq $null) { - throw "No external switches found" - } + # $externalSwitches = Get-VMSwitch -SwitchType External + # if ($externalSwitches -eq $null) { + # throw "No external switches found" + # } # Check that the VHD exists if (-not (Test-Path -Path $VhdPath)) { @@ -197,10 +197,10 @@ function Create-VM { # Create the VM Log-Message "Creating the VM" New-VM -Name $VmName -MemoryStartupBytes $MemoryStartupBytes -VhdPath $VmVhdPath # -SwitchName $ExternalVMSwitchName - foreach ($switch in $externalSwitches) { - Log-Message "Adding network adapter to VM: $VmName with switch: $($switch.Name)" - Add-VMNetworkAdapter -VMName $VmName -SwitchName $switch.Name - } + # foreach ($switch in $externalSwitches) { + # Log-Message "Adding network adapter to VM: $VmName with switch: $($switch.Name)" + # Add-VMNetworkAdapter -VMName $VmName -SwitchName $switch.Name + # } if ((Get-VM -VMName $vmName) -eq $null) { throw "Failed to create VM: $VMName" @@ -244,7 +244,7 @@ function Configure-VM { # Fetch all updates on the VM Log-Message "Fetching Updates on the VM" - Update-VM -VMName $VmName -VmCredential $VmCredential + # Update-VM -VMName $VmName -VmCredential $VmCredential Log-Message -Message "Successfully updated VM: $VMName" -ForegroundColor Green # Copy setup script to the VM and execute it. From 8f90e6eb2e436e85bc4224c30a15e2463941a646 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 13 Nov 2024 08:30:57 -0800 Subject: [PATCH 012/190] WIP --- scripts/cleanup_ebpf_cicd_tests.ps1 | 9 ++- scripts/common.psm1 | 16 ++++- scripts/execute_ebpf_cicd_tests.ps1 | 10 ++- scripts/setup_ebpf_cicd_tests.ps1 | 19 +++--- scripts/test_execution.json | 100 +--------------------------- 5 files changed, 41 insertions(+), 113 deletions(-) diff --git a/scripts/cleanup_ebpf_cicd_tests.ps1 b/scripts/cleanup_ebpf_cicd_tests.ps1 index 148979cf1d..2dd2e42f6f 100644 --- a/scripts/cleanup_ebpf_cicd_tests.ps1 +++ b/scripts/cleanup_ebpf_cicd_tests.ps1 @@ -7,13 +7,16 @@ param ([parameter(Mandatory=$false)][string] $Target = "TEST_VM", [parameter(Mandatory=$false)][string] $WorkingDirectory = $pwd.ToString(), [parameter(Mandatory=$false)][string] $TestExecutionJsonFileName = "test_execution.json", [parameter(Mandatory=$false)][string] $SelfHostedRunnerName = [System.Net.Dns]::GetHostName(), - [Parameter(Mandatory = $false)][int] $TestJobTimeout = (30*60)) + [Parameter(Mandatory = $false)][int] $TestJobTimeout = (30*60), + [Parameter(Mandatory = $false)][string] $VMUserName="Administrator", + [Parameter(Mandatory = $false)][string] $VMPassword="P@ssw0rd" + ) Push-Location $WorkingDirectory Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue - -$TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop +$SelfHostedRunnerName = "runner_host" +$TestVMCredential = Create-VMCredential -VmUsername $VMUserName -VmPassword $VMPassword # Read the test execution json. $Config = Get-Content ("{0}\{1}" -f $PSScriptRoot, $TestExecutionJsonFileName) | ConvertFrom-Json diff --git a/scripts/common.psm1 b/scripts/common.psm1 index 44408f4780..eadb97b646 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -111,4 +111,18 @@ function Wait-TestJobToComplete $JobOutput | ForEach-Object { Write-Host $_ } return $JobTimedOut -} \ No newline at end of file +} + +function Create-VMCredential { + param ( + [Parameter(Mandatory=$True)][string]$VmUsername, + [Parameter(Mandatory=$True)][string]$VmPassword + ) + + try { + $secureVmPassword = ConvertTo-SecureString $VmPassword -AsPlainText -Force + return New-Object System.Management.Automation.PSCredential($VmUsername, $secureVmPassword) + } catch { + throw "Failed to create VM credential: $_" + } +} diff --git a/scripts/execute_ebpf_cicd_tests.ps1 b/scripts/execute_ebpf_cicd_tests.ps1 index 540cfd5fd0..fcca934c4a 100644 --- a/scripts/execute_ebpf_cicd_tests.ps1 +++ b/scripts/execute_ebpf_cicd_tests.ps1 @@ -11,15 +11,19 @@ param ([Parameter(Mandatory = $false)][string] $AdminTarget = "TEST_VM", [Parameter(Mandatory = $false)][string] $SelfHostedRunnerName = [System.Net.Dns]::GetHostName(), [Parameter(Mandatory = $false)][int] $TestHangTimeout = (10*60), [Parameter(Mandatory = $false)][string] $UserModeDumpFolder = "C:\Dumps", - [Parameter(Mandatory = $false)][int] $TestJobTimeout = (60*60) + [Parameter(Mandatory = $false)][int] $TestJobTimeout = (60*60), + [Parameter(Mandatory = $false)][string] $VMUserName="Administrator", + [Parameter(Mandatory = $false)][string] $VMPassword="P@ssw0rd" ) Push-Location $WorkingDirectory Import-Module $WorkingDirectory\common.psm1 -Force -ArgumentList ($LogFileName) -ErrorAction Stop -$AdminTestVMCredential = Get-StoredCredential -Target $AdminTarget -ErrorAction Stop -$StandardUserTestVMCredential = Get-StoredCredential -Target $StandardUserTarget -ErrorAction Stop +# TODO - figure out admin vs standard user +$SelfHostedRunnerName = "runner_host" +$AdminTestVMCredential = Create-VMCredential -VmUsername $VMUserName -VmPassword $VMPassword +$StandardUserTestVMCredential = Create-VMCredential -VmUsername 'VMStandardUser' -VmPassword $VMPassword # Read the test execution json. $Config = Get-Content ("{0}\{1}" -f $PSScriptRoot, $TestExecutionJsonFileName) | ConvertFrom-Json diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index f2d715fc5b..2c6dc7a3c4 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -10,15 +10,18 @@ param ([parameter(Mandatory=$false)][string] $Target = "TEST_VM", [parameter(Mandatory=$false)][string] $RegressionArtifactsVersion = "", [parameter(Mandatory=$false)][string] $RegressionArtifactsConfiguration = "", [parameter(Mandatory=$false)][string] $TestExecutionJsonFileName = "test_execution.json", - [parameter(Mandatory=$false)][string] $SelfHostedRunnerName = [System.Net.Dns]::GetHostName(), - [Parameter(Mandatory = $false)][int] $TestJobTimeout = (30*60)) + [parameter(Mandatory=$false)][string] $SelfHostedRunnerName = "runner_host" + [Parameter(Mandatory = $false)][int] $TestJobTimeout = (30*60), + [Parameter(Mandatory = $false)][string] $VMUserName="Administrator", + [Parameter(Mandatory = $false)][string] $VMPassword="P@ssw0rd" + ) Push-Location $WorkingDirectory -$TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop - # Load other utility modules. Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue +$SelfHostedRunnerName = "runner_host" +$TestVMCredential = Create-VMCredential -VmUsername $VMUserName -VmPassword $VMPassword Import-Module .\config_test_vm.psm1 -Force -ArgumentList ($TestVMCredential.UserName, $TestVMCredential.Password, $WorkingDirectory, $LogFileName) -WarningAction SilentlyContinue # Read the test execution json. @@ -27,10 +30,10 @@ $VMList = $Config.VMMap.$SelfHostedRunnerName # Delete old log files if any. Remove-Item "$env:TEMP\$LogFileName" -ErrorAction SilentlyContinue -foreach($VM in $VMList) { - $VMName = $VM.Name - Remove-Item $env:TEMP\$LogFileName -ErrorAction SilentlyContinue -} +# foreach($VM in $VMList) { +# $VMName = $VM.Name +# Remove-Item $env:TEMP\$LogFileName -ErrorAction SilentlyContinue +# } Remove-Item ".\TestLogs" -Recurse -Confirm:$false -ErrorAction SilentlyContinue if ($TestMode -eq "Regression") { diff --git a/scripts/test_execution.json b/scripts/test_execution.json index 779f47e643..ffa9f24949 100644 --- a/scripts/test_execution.json +++ b/scripts/test_execution.json @@ -3,106 +3,10 @@ "VMMap": { - "TK5-3WP08R0904_WS2019_1": + "runner_host" : [ { - "Name": "vm1_ws2019" - } - ], - "TK5-3WP08R0904_WS2019_2": - [ - { - "Name": "vm2_ws2019" - } - ], - "TK5-3WP08R0907_WS2019_1": - [ - { - "Name": "vm1_ws2019" - } - ], - "TK5-3WP08R0907_WS2019_2": - [ - { - "Name": "vm2_ws2019" - } - ], - "TK5-3WP07R0703_WS2019_1": - [ - { - "Name": "vm1_ws2019" - } - ], - "TK5-3WP07R0703_WS2019_2": - [ - { - "Name": "vm2_ws2019" - } - ], - "TK5-3WP07R0703_WS2019_3": - [ - { - "Name": "vm3_ws2019" - } - ], - "TK5-3WP07R0703_WS2019_4": - [ - { - "Name": "vm4_ws2019" - } - ], - "TK5-3WP07R0703_WS2022_1": - [ - { - "Name": "vm1_ws2022" - } - ], - "TK5-3WP07R0703_WS2022_2": - [ - { - "Name": "vm2_ws2022" - } - ], - "TK5-3WP07R0703_WS2022_3": - [ - { - "Name": "vm3_ws2022" - } - ], - "TK5-3WP07R0703_WS2022_4": - [ - { - "Name": "vm4_ws2022" - } - ], - "TK5-3WP07R0703_WS2022_5": - [ - { - "Name": "vm5_ws2022" - } - ], - "TK5-3WP07R0703_WS2022_6": - [ - { - "Name": "vm6_ws2022" - } - ], - "TK5-3WP07R0703_WS2022_7": - [ - { - "Name": "vm7_ws2022" - } - ], - "TK5-3WP07R0703_WS2022_8": - [ - { - "Name": "vm8_ws2022" - } - ], - "TK5-3WP07R0703_WS2022_PERF_1": - [ - { - "Name": "vm_perf_ws2022" + "Name": "runner_vm" } ] }, From 499579ad4da7b412aef7766c66126b1bf3918ecf Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 13 Nov 2024 09:12:10 -0800 Subject: [PATCH 013/190] WIP --- .github/workflows/cicd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index baac9ec77c..6f9afca8d7 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -55,7 +55,7 @@ jobs: build_msi: true build_nuget: true build_options: /p:ReleaseJIT='True' - configurations: '["Release"]' + configurations: '["Debug", "Release"]' # Run the driver tests on self-hosted runners. driver_ws2019: From 751a452094447a40ea385f0eb0d800a6627ee6d0 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 13 Nov 2024 09:51:50 -0800 Subject: [PATCH 014/190] fix --- scripts/setup_ebpf_cicd_tests.ps1 | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index 2c6dc7a3c4..58b9e9d0b9 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -10,11 +10,11 @@ param ([parameter(Mandatory=$false)][string] $Target = "TEST_VM", [parameter(Mandatory=$false)][string] $RegressionArtifactsVersion = "", [parameter(Mandatory=$false)][string] $RegressionArtifactsConfiguration = "", [parameter(Mandatory=$false)][string] $TestExecutionJsonFileName = "test_execution.json", - [parameter(Mandatory=$false)][string] $SelfHostedRunnerName = "runner_host" + [parameter(Mandatory=$false)][string] $SelfHostedRunnerName = [System.Net.Dns]::GetHostName(), [Parameter(Mandatory = $false)][int] $TestJobTimeout = (30*60), [Parameter(Mandatory = $false)][string] $VMUserName="Administrator", [Parameter(Mandatory = $false)][string] $VMPassword="P@ssw0rd" - ) + ) Push-Location $WorkingDirectory @@ -30,10 +30,6 @@ $VMList = $Config.VMMap.$SelfHostedRunnerName # Delete old log files if any. Remove-Item "$env:TEMP\$LogFileName" -ErrorAction SilentlyContinue -# foreach($VM in $VMList) { -# $VMName = $VM.Name -# Remove-Item $env:TEMP\$LogFileName -ErrorAction SilentlyContinue -# } Remove-Item ".\TestLogs" -Recurse -Confirm:$false -ErrorAction SilentlyContinue if ($TestMode -eq "Regression") { From 993f2d44ea46deb0bfb08cc1de6ad6e4af4d021a Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 13 Nov 2024 12:13:25 -0800 Subject: [PATCH 015/190] WIP --- 1es/Setup_orig.ps1 | 20 +---- 1es/prepare_vm_helpers.psm1 | 112 ++++++++++++++++++---------- scripts/cleanup_ebpf_cicd_tests.ps1 | 8 +- scripts/config_test_vm.psm1 | 2 + scripts/execute_ebpf_cicd_tests.ps1 | 9 +-- scripts/setup_ebpf_cicd_tests.ps1 | 10 +-- 6 files changed, 88 insertions(+), 73 deletions(-) diff --git a/1es/Setup_orig.ps1 b/1es/Setup_orig.ps1 index e83c9c7e88..7dd02de306 100644 --- a/1es/Setup_orig.ps1 +++ b/1es/Setup_orig.ps1 @@ -2,6 +2,7 @@ # SPDX-License-Identifier: MIT param( [Parameter(Mandatory=$False)][string]$VmUsername='Administrator', + [Parameter(Mandatory=$False)][string]$VmStandardUserName='VMStandardUser', [Parameter(Mandatory=$False)][string]$VmPassword='P@ssw0rd', [Parameter(Mandatory=$False)][string]$BaseUnattendPath='.\unattend.xml', @@ -19,16 +20,6 @@ $ErrorActionPreference = "Stop" # Import helper functions Import-Module .\prepare_vm_helpers.psm1 -Force -# Create-ExternalSwitchIfNeeded -ExternalSwitchName $ExternalSwitchName -# $ExternalSwitches = Get-VMSwitch -SwitchType External -# if (-not $ExternalSwitches) { -# throw "No external switches found" -# } -# foreach ($switch in $ExternalSwitches) { -# Log-Message "External switch: $switch" -# Log-Message "External switch: $($switch.Name)" -# } - if (-not (Test-Path -Path $BaseUnattendPath)) { throw "Unattend file not found at $BaseUnattendPath" } @@ -37,14 +28,11 @@ if (-not (Test-Path -Path $BaseVhdDirPath)) { throw "VHD directory not found at $BaseVhdDirPath" } +Create-VMSwitchIfNeeded -SwitchName 'VMInternalSwitch' -SwitchType Internal +Create-VMStoredCredential -CredentialName "TEST_VM" -Username $VmUsername -Password $VmPassword +Create-VMStoredCredential -CredentialName "TEST_VM_STANDARD" -Username $VmStandardUserName -Password $VmPassword Create-DirectoryIfNotExists -Path $WorkingPath -# Create-DirectoryIfNotExists -Path $OutVhdDirPath - -# Create credential object for executing commands on the VM -# TODO - maybe this can be read from the unattend file? Or passed as an azure parameter, which replaces in the unattend file. -# $vmCredential = Create-VMCredential -VmUsername $VmUsername -VmPassword $VmPassword - # Read the input VHDs $vhds = @((Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhd)) $vhds += Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhdx diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index 26b97cc37d..f01b550fb1 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -156,12 +156,6 @@ function Create-VM { try { ## Check for any pre-requisites - # Check that the External Switch exists - # $externalSwitches = Get-VMSwitch -SwitchType External - # if ($externalSwitches -eq $null) { - # throw "No external switches found" - # } - # Check that the VHD exists if (-not (Test-Path -Path $VhdPath)) { throw "VHD not found at $VhdPath" @@ -196,11 +190,12 @@ function Create-VM { # Create the VM Log-Message "Creating the VM" - New-VM -Name $VmName -MemoryStartupBytes $MemoryStartupBytes -VhdPath $VmVhdPath # -SwitchName $ExternalVMSwitchName - # foreach ($switch in $externalSwitches) { - # Log-Message "Adding network adapter to VM: $VmName with switch: $($switch.Name)" - # Add-VMNetworkAdapter -VMName $VmName -SwitchName $switch.Name - # } + New-VM -Name $VmName -MemoryStartupBytes $MemoryStartupBytes -VhdPath $VmVhdPath + $vmSwitches = Get-VMSwitch + foreach ($switch in $vmSwitches) { + Log-Message "Adding network adapter to VM: $VmName with switch: $($switch.Name)" + Add-VMNetworkAdapter -VMName $VmName -SwitchName $switch.Name + } if ((Get-VM -VMName $vmName) -eq $null) { throw "Failed to create VM: $VMName" @@ -255,15 +250,18 @@ function Configure-VM { Wait-ForVMReady -VMName $VmName -VmCredential $VmCredential - # Checkpoint the VM. - Log-Message "Checkpointing VM: $VmName" - Checkpoint-VM -Name $VMName -SnapshotName 'baseline' - Log-Message -Message "Successfully added 'baseline' checkpoint for VM: $VMName" -ForegroundColor Green - - # Export the configured VHD. - # TODO - set the path... - # Export-VM -Name $VMName -Path "$VMWorkingDirectory\$VMName.vhd" - # Log-Message -Message "Successfully exported VM: $VMName to $VMWorkingDirectory\$VMName.vhd" -ForegroundColor Green + # Checkpoint the VM. This can sometimes fail if other operations are in progress. + for ($i = 0; $i -lt 5; $i += 1) { + try { + Log-Message "Checkpointing VM: $VmName" + Checkpoint-VM -Name $VMName -SnapshotName 'baseline' + Log-Message -Message "Successfully added 'baseline' checkpoint for VM: $VMName" -ForegroundColor Green + } catch { + Log-Message "Failed to checkpoint VM: $VmName. Retrying..." + Start-Sleep -Seconds 5 + continue + } + } } catch { throw "Failed to configure VM: $VmName. Error: $_" } @@ -287,35 +285,67 @@ function Install-HyperVIfNeeded { } } -function Create-ExternalSwitchIfNeeded { +function Create-VMSwitchIfNeeded { param ( - [Parameter(Mandatory=$False)][string]$ExternalSwitchName='VMExternalSwitch' + [Parameter(Mandatory=$False)][string]$SwitchName='VMInternalSwitch', + [Parameter(Mandatory=$False)][string]$SwitchType='Internal' ) try { - # Check to see if an external switch already exists - $ExternalSwitches = (Get-VMSwitch -SwitchType External) - if ($ExternalSwitches -ne $null) { - Log-Message -Message "External switch already exists: $($ExternalSwitches[0].Name)" - return - } + if ($SwitchType -eq 'External') { + # Check to see if an external switch already exists + $ExternalSwitches = (Get-VMSwitch -SwitchType External) + if ($ExternalSwitches -ne $null) { + Log-Message -Message "External switch already exists: $($ExternalSwitches[0].Name)" + return + } - # Try to create the external switch - $NetAdapterNames = (Get-NetAdapter -Name 'Ethernet*' | Where-Object { $_.Status -eq 'Up' }).Name - $index = 0 - foreach ($NetAdapterName in $NetAdapterNames) { - try { - if ([string]::IsNullOrEmpty($NetAdapterName)) { - continue + # Try to create the external switch + $NetAdapterNames = (Get-NetAdapter -Name 'Ethernet*' | Where-Object { $_.Status -eq 'Up' }).Name + $index = 0 + foreach ($NetAdapterName in $NetAdapterNames) { + try { + if ([string]::IsNullOrEmpty($NetAdapterName)) { + continue + } + $switchName = $ExternalSwitchName + '-' + $index + Log-Message "Attempting to creating external switch: $switchName with NetAdapter: $NetAdapterName" + New-VMSwitch -Name $switchName -NetAdapterName $NetAdapterName -AllowManagementOS $true + # break + } catch { + Log-Message "Failed to create external switch for NetAdapter: $NetAdapterName $_" } - $switchName = $ExternalSwitchName + '-' + $index - Log-Message "Attempting to creating external switch: $switchName with NetAdapter: $NetAdapterName" - New-VMSwitch -Name $switchName -NetAdapterName $NetAdapterName -AllowManagementOS $true - # break - } catch { - Log-Message "Failed to create external switch for NetAdapter: $NetAdapterName $_" } + } elseif ($SwitchType -eq 'Internal') { + # Check to see if an internal switch already exists + $InternalSwitches = (Get-VMSwitch -SwitchType Internal) + if ($InternalSwitches -ne $null) { + Log-Message -Message "Internal switch already exists: $($InternalSwitches[0].Name)" + return + } + + # Try to create the internal switch + Log-Message "Creating internal switch" + New-VMSwitch -Name 'VMInternalSwitch' -SwitchType Internal + } else { + throw "Invalid switch type: $SwitchType" } } catch { throw "Failed to create external switch: $_" } } + +function Create-VMStoredCredential { + param ( + [Parameter(Mandatory=$True)][string]$CredentialName, + [Parameter(Mandatory=$True)][string]$Username, + [Parameter(Mandatory=$True)][string]$Password + ) + + try { + $secureVmPassword = ConvertTo-SecureString $Password -AsPlainText -Force + $vmCredential = New-Object System.Management.Automation.PSCredential($Username, $secureVmPassword) + $vmCredential | Export-StoredCredential -Target $CredentialName + } catch { + throw "Failed to create stored credential: $_" + } +} \ No newline at end of file diff --git a/scripts/cleanup_ebpf_cicd_tests.ps1 b/scripts/cleanup_ebpf_cicd_tests.ps1 index 2dd2e42f6f..fc5e25cf69 100644 --- a/scripts/cleanup_ebpf_cicd_tests.ps1 +++ b/scripts/cleanup_ebpf_cicd_tests.ps1 @@ -7,16 +7,14 @@ param ([parameter(Mandatory=$false)][string] $Target = "TEST_VM", [parameter(Mandatory=$false)][string] $WorkingDirectory = $pwd.ToString(), [parameter(Mandatory=$false)][string] $TestExecutionJsonFileName = "test_execution.json", [parameter(Mandatory=$false)][string] $SelfHostedRunnerName = [System.Net.Dns]::GetHostName(), - [Parameter(Mandatory = $false)][int] $TestJobTimeout = (30*60), - [Parameter(Mandatory = $false)][string] $VMUserName="Administrator", - [Parameter(Mandatory = $false)][string] $VMPassword="P@ssw0rd" - ) + [Parameter(Mandatory = $false)][int] $TestJobTimeout = (30*60)) Push-Location $WorkingDirectory Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue $SelfHostedRunnerName = "runner_host" -$TestVMCredential = Create-VMCredential -VmUsername $VMUserName -VmPassword $VMPassword +Write-Host "SelfHostedRunnerName: $SelfHostedRunnerName, Target: $Target" +$TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop # Read the test execution json. $Config = Get-Content ("{0}\{1}" -f $PSScriptRoot, $TestExecutionJsonFileName) | ConvertFrom-Json diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index 83da88cd30..f08b907b1c 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -540,6 +540,8 @@ function Initialize-NetworkInterfacesOnVMs # Disable Duonic's fake checksum offload and force TCP/IP to calculate it. Set-NetAdapterAdvancedProperty duo? -DisplayName Checksum -RegistryValue 0 + ipconfig /all + Pop-Location } -ArgumentList ("eBPF", $LogFileName) -ErrorAction Stop } diff --git a/scripts/execute_ebpf_cicd_tests.ps1 b/scripts/execute_ebpf_cicd_tests.ps1 index fcca934c4a..c4f163d3f7 100644 --- a/scripts/execute_ebpf_cicd_tests.ps1 +++ b/scripts/execute_ebpf_cicd_tests.ps1 @@ -11,9 +11,7 @@ param ([Parameter(Mandatory = $false)][string] $AdminTarget = "TEST_VM", [Parameter(Mandatory = $false)][string] $SelfHostedRunnerName = [System.Net.Dns]::GetHostName(), [Parameter(Mandatory = $false)][int] $TestHangTimeout = (10*60), [Parameter(Mandatory = $false)][string] $UserModeDumpFolder = "C:\Dumps", - [Parameter(Mandatory = $false)][int] $TestJobTimeout = (60*60), - [Parameter(Mandatory = $false)][string] $VMUserName="Administrator", - [Parameter(Mandatory = $false)][string] $VMPassword="P@ssw0rd" + [Parameter(Mandatory = $false)][int] $TestJobTimeout = (60*60) ) Push-Location $WorkingDirectory @@ -22,8 +20,9 @@ Import-Module $WorkingDirectory\common.psm1 -Force -ArgumentList ($LogFileName) # TODO - figure out admin vs standard user $SelfHostedRunnerName = "runner_host" -$AdminTestVMCredential = Create-VMCredential -VmUsername $VMUserName -VmPassword $VMPassword -$StandardUserTestVMCredential = Create-VMCredential -VmUsername 'VMStandardUser' -VmPassword $VMPassword +Write-Host "SelfHostedRunnerName: $SelfHostedRunnerName, AdminTarget: $AdminTarget, StandardUserTarget: $StandardUserTarget" +$AdminTestVMCredential = Get-StoredCredential -Target $AdminTarget -ErrorAction Stop +$StandardUserTestVMCredential = Get-StoredCredential -Target $StandardUserTarget -ErrorAction Stop # Read the test execution json. $Config = Get-Content ("{0}\{1}" -f $PSScriptRoot, $TestExecutionJsonFileName) | ConvertFrom-Json diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index 58b9e9d0b9..d8d2d6af26 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -11,17 +11,15 @@ param ([parameter(Mandatory=$false)][string] $Target = "TEST_VM", [parameter(Mandatory=$false)][string] $RegressionArtifactsConfiguration = "", [parameter(Mandatory=$false)][string] $TestExecutionJsonFileName = "test_execution.json", [parameter(Mandatory=$false)][string] $SelfHostedRunnerName = [System.Net.Dns]::GetHostName(), - [Parameter(Mandatory = $false)][int] $TestJobTimeout = (30*60), - [Parameter(Mandatory = $false)][string] $VMUserName="Administrator", - [Parameter(Mandatory = $false)][string] $VMPassword="P@ssw0rd" - ) + [Parameter(Mandatory = $false)][int] $TestJobTimeout = (30*60)) Push-Location $WorkingDirectory +$SelfHostedRunnerName = "runner_host" +$TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop + # Load other utility modules. Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue -$SelfHostedRunnerName = "runner_host" -$TestVMCredential = Create-VMCredential -VmUsername $VMUserName -VmPassword $VMPassword Import-Module .\config_test_vm.psm1 -Force -ArgumentList ($TestVMCredential.UserName, $TestVMCredential.Password, $WorkingDirectory, $LogFileName) -WarningAction SilentlyContinue # Read the test execution json. From ada843cda111bb2c47564d2e97d8c13a9397f922 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 13 Nov 2024 14:09:54 -0800 Subject: [PATCH 016/190] import cred manager --- 1es/prepare_vm_helpers.psm1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index f01b550fb1..abe2fb7b3c 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -340,11 +340,13 @@ function Create-VMStoredCredential { [Parameter(Mandatory=$True)][string]$Username, [Parameter(Mandatory=$True)][string]$Password ) - try { + Install-Module -Name CredentialManager -Scope AllUsers -Force + Import-Module CredentialManager -Force + $secureVmPassword = ConvertTo-SecureString $Password -AsPlainText -Force $vmCredential = New-Object System.Management.Automation.PSCredential($Username, $secureVmPassword) - $vmCredential | Export-StoredCredential -Target $CredentialName + New-StoredCredential -Target $CredentialName -Credential $vmCredential -Type Generic -Persist LocalMachine } catch { throw "Failed to create stored credential: $_" } From b63804aad2eb885aee815150d76a52b333173cb5 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 13 Nov 2024 14:56:56 -0800 Subject: [PATCH 017/190] fixes --- 1es/prepare_vm_helpers.psm1 | 4 +--- scripts/common.psm1 | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index abe2fb7b3c..dc261ffc04 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -344,9 +344,7 @@ function Create-VMStoredCredential { Install-Module -Name CredentialManager -Scope AllUsers -Force Import-Module CredentialManager -Force - $secureVmPassword = ConvertTo-SecureString $Password -AsPlainText -Force - $vmCredential = New-Object System.Management.Automation.PSCredential($Username, $secureVmPassword) - New-StoredCredential -Target $CredentialName -Credential $vmCredential -Type Generic -Persist LocalMachine + New-StoredCredential -Target $CredentialName -UserName $Username -Password $Password } catch { throw "Failed to create stored credential: $_" } diff --git a/scripts/common.psm1 b/scripts/common.psm1 index eadb97b646..9428f66993 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -3,6 +3,8 @@ param ([parameter(Mandatory=$True)] [string] $LogFileName) +Import-Module CredentialManager -Force + # # Common helper functions. # From 874f75bfef1b6d05e6209f9a56806c68d555bafd Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 13 Nov 2024 15:40:50 -0800 Subject: [PATCH 018/190] try with stored credential, but have workaround --- 1es/prepare_vm_helpers.psm1 | 5 +++-- scripts/cleanup_ebpf_cicd_tests.ps1 | 7 ++++++- scripts/execute_ebpf_cicd_tests.ps1 | 10 ++++++++-- scripts/setup_ebpf_cicd_tests.ps1 | 7 ++++++- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index dc261ffc04..1f393d0032 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -344,8 +344,9 @@ function Create-VMStoredCredential { Install-Module -Name CredentialManager -Scope AllUsers -Force Import-Module CredentialManager -Force - New-StoredCredential -Target $CredentialName -UserName $Username -Password $Password + New-StoredCredential -Target $CredentialName -UserName $Username -Password $Password -Type Generic -Persist LocalMachine } catch { - throw "Failed to create stored credential: $_" + Log-Message "Failed to create stored credential: $_" -ForegroundColor Red + # throw "Failed to create stored credential: $_" } } \ No newline at end of file diff --git a/scripts/cleanup_ebpf_cicd_tests.ps1 b/scripts/cleanup_ebpf_cicd_tests.ps1 index fc5e25cf69..1e74f08454 100644 --- a/scripts/cleanup_ebpf_cicd_tests.ps1 +++ b/scripts/cleanup_ebpf_cicd_tests.ps1 @@ -14,7 +14,12 @@ Push-Location $WorkingDirectory Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue $SelfHostedRunnerName = "runner_host" Write-Host "SelfHostedRunnerName: $SelfHostedRunnerName, Target: $Target" -$TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop +try { + $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop +} catch { + Write-Host "Failed to get credentials for $Target. Using default credentials." + $TestVMCredential = New-Credential -UserName 'Administrator' -AdminPassword 'P@ssw0rd' +} # Read the test execution json. $Config = Get-Content ("{0}\{1}" -f $PSScriptRoot, $TestExecutionJsonFileName) | ConvertFrom-Json diff --git a/scripts/execute_ebpf_cicd_tests.ps1 b/scripts/execute_ebpf_cicd_tests.ps1 index c4f163d3f7..09d0b3e0e4 100644 --- a/scripts/execute_ebpf_cicd_tests.ps1 +++ b/scripts/execute_ebpf_cicd_tests.ps1 @@ -21,8 +21,14 @@ Import-Module $WorkingDirectory\common.psm1 -Force -ArgumentList ($LogFileName) # TODO - figure out admin vs standard user $SelfHostedRunnerName = "runner_host" Write-Host "SelfHostedRunnerName: $SelfHostedRunnerName, AdminTarget: $AdminTarget, StandardUserTarget: $StandardUserTarget" -$AdminTestVMCredential = Get-StoredCredential -Target $AdminTarget -ErrorAction Stop -$StandardUserTestVMCredential = Get-StoredCredential -Target $StandardUserTarget -ErrorAction Stop +try { + $AdminTestVMCredential = Get-StoredCredential -Target $AdminTarget -ErrorAction Stop + $StandardUserTestVMCredential = Get-StoredCredential -Target $StandardUserTarget -ErrorAction Stop +} catch { + Write-Host "Failed to get credentials for $AdminTarget or $StandardUserTarget. Using default credentials." + $AdminTestVMCredential = New-Credential -UserName 'Administrator' -AdminPassword 'P@ssw0rd' + $StandardUserTestVMCredential = New-Credential -UserName 'VMStandardUser' -AdminPassword 'P@ssw0rd' +} # Read the test execution json. $Config = Get-Content ("{0}\{1}" -f $PSScriptRoot, $TestExecutionJsonFileName) | ConvertFrom-Json diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index d8d2d6af26..86d0cd45be 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -16,7 +16,12 @@ param ([parameter(Mandatory=$false)][string] $Target = "TEST_VM", Push-Location $WorkingDirectory $SelfHostedRunnerName = "runner_host" -$TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop +try { + $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop +} catch { + Write-Host "Failed to get credentials for $Target. Using default credentials." + $TestVMCredential = New-Credential -UserName 'Administrator' -AdminPassword 'P@ssw0rd' +} # Load other utility modules. Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue From 36accbfaf6c0db013ef234dc0b5771ad663d397a Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 13 Nov 2024 16:27:40 -0800 Subject: [PATCH 019/190] fix --- scripts/common.psm1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/common.psm1 b/scripts/common.psm1 index 9428f66993..f89d088b70 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -3,7 +3,11 @@ param ([parameter(Mandatory=$True)] [string] $LogFileName) -Import-Module CredentialManager -Force +try { + Import-Module CredentialManager -Force +} catch { + Write-Host "Failed to import CredentialManager module. Using default credentials." +} # # Common helper functions. From 4f3e04897166154a2bf16160dc7e00425f476afb Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 13 Nov 2024 17:10:43 -0800 Subject: [PATCH 020/190] fixes --- 1es/Setup_orig.ps1 | 3 --- 1es/prepare_vm_helpers.psm1 | 1 + scripts/execute_ebpf_cicd_tests.ps1 | 1 - scripts/setup_ebpf_cicd_tests.ps1 | 4 ++-- 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/1es/Setup_orig.ps1 b/1es/Setup_orig.ps1 index 7dd02de306..2abd5ea34a 100644 --- a/1es/Setup_orig.ps1 +++ b/1es/Setup_orig.ps1 @@ -64,7 +64,4 @@ for ($i = 0; $i -lt $vhds.Count; $i++) { -CpuCount $VMCpuCount ` -VmUsername $VmUsername ` -VmPassword $VmPassword - - Export-VM -Name $vmName -Path $OutVhdDirPath - Log-Message -Message "Successfully exported VM: $VMName to $VMWorkingDirectory\$VMName.vhd" -ForegroundColor Green } diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index 1f393d0032..aac41e96f5 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -256,6 +256,7 @@ function Configure-VM { Log-Message "Checkpointing VM: $VmName" Checkpoint-VM -Name $VMName -SnapshotName 'baseline' Log-Message -Message "Successfully added 'baseline' checkpoint for VM: $VMName" -ForegroundColor Green + break } catch { Log-Message "Failed to checkpoint VM: $VmName. Retrying..." Start-Sleep -Seconds 5 diff --git a/scripts/execute_ebpf_cicd_tests.ps1 b/scripts/execute_ebpf_cicd_tests.ps1 index 09d0b3e0e4..5af0a75830 100644 --- a/scripts/execute_ebpf_cicd_tests.ps1 +++ b/scripts/execute_ebpf_cicd_tests.ps1 @@ -18,7 +18,6 @@ Push-Location $WorkingDirectory Import-Module $WorkingDirectory\common.psm1 -Force -ArgumentList ($LogFileName) -ErrorAction Stop -# TODO - figure out admin vs standard user $SelfHostedRunnerName = "runner_host" Write-Host "SelfHostedRunnerName: $SelfHostedRunnerName, AdminTarget: $AdminTarget, StandardUserTarget: $StandardUserTarget" try { diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index 86d0cd45be..9f4bbbbb63 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -15,6 +15,8 @@ param ([parameter(Mandatory=$false)][string] $Target = "TEST_VM", Push-Location $WorkingDirectory +# Load other utility modules. +Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue $SelfHostedRunnerName = "runner_host" try { $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop @@ -23,8 +25,6 @@ try { $TestVMCredential = New-Credential -UserName 'Administrator' -AdminPassword 'P@ssw0rd' } -# Load other utility modules. -Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue Import-Module .\config_test_vm.psm1 -Force -ArgumentList ($TestVMCredential.UserName, $TestVMCredential.Password, $WorkingDirectory, $LogFileName) -WarningAction SilentlyContinue # Read the test execution json. From 8c5803c7773bd2b4bc616bb5714bab95eaf34a51 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 14 Nov 2024 08:12:39 -0800 Subject: [PATCH 021/190] fixes --- scripts/cleanup_ebpf_cicd_tests.ps1 | 3 ++- scripts/execute_ebpf_cicd_tests.ps1 | 5 +++-- scripts/setup_ebpf_cicd_tests.ps1 | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/cleanup_ebpf_cicd_tests.ps1 b/scripts/cleanup_ebpf_cicd_tests.ps1 index 1e74f08454..a379dfbbc9 100644 --- a/scripts/cleanup_ebpf_cicd_tests.ps1 +++ b/scripts/cleanup_ebpf_cicd_tests.ps1 @@ -18,7 +18,8 @@ try { $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop } catch { Write-Host "Failed to get credentials for $Target. Using default credentials." - $TestVMCredential = New-Credential -UserName 'Administrator' -AdminPassword 'P@ssw0rd' + $securePassword = ConvertTo-SecureString -String "P@ssw0rd" -AsPlainText -Force + $TestVMCredential = New-Credential -UserName 'Administrator' -AdminPassword $securePassword } # Read the test execution json. diff --git a/scripts/execute_ebpf_cicd_tests.ps1 b/scripts/execute_ebpf_cicd_tests.ps1 index 5af0a75830..82468d04b1 100644 --- a/scripts/execute_ebpf_cicd_tests.ps1 +++ b/scripts/execute_ebpf_cicd_tests.ps1 @@ -25,8 +25,9 @@ try { $StandardUserTestVMCredential = Get-StoredCredential -Target $StandardUserTarget -ErrorAction Stop } catch { Write-Host "Failed to get credentials for $AdminTarget or $StandardUserTarget. Using default credentials." - $AdminTestVMCredential = New-Credential -UserName 'Administrator' -AdminPassword 'P@ssw0rd' - $StandardUserTestVMCredential = New-Credential -UserName 'VMStandardUser' -AdminPassword 'P@ssw0rd' + $securePassword = ConvertTo-SecureString -String "P@ssw0rd" -AsPlainText -Force + $AdminTestVMCredential = New-Credential -UserName 'Administrator' -AdminPassword $securePassword + $StandardUserTestVMCredential = New-Credential -UserName 'VMStandardUser' -AdminPassword $securePassword } # Read the test execution json. diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index 9f4bbbbb63..f5f2fa6d9b 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -22,7 +22,8 @@ try { $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop } catch { Write-Host "Failed to get credentials for $Target. Using default credentials." - $TestVMCredential = New-Credential -UserName 'Administrator' -AdminPassword 'P@ssw0rd' + $securePassword = ConvertTo-SecureString -String "P@ssw0rd" -AsPlainText -Force + $TestVMCredential = New-Credential -UserName 'Administrator' -AdminPassword $securePassword } Import-Module .\config_test_vm.psm1 -Force -ArgumentList ($TestVMCredential.UserName, $TestVMCredential.Password, $WorkingDirectory, $LogFileName) -WarningAction SilentlyContinue From 91e5f704be7effeb2bbba9b31cbb8bdba2116dbf Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 14 Nov 2024 08:51:31 -0800 Subject: [PATCH 022/190] WIP --- scripts/common.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/common.psm1 b/scripts/common.psm1 index f89d088b70..ea215cff72 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -4,7 +4,7 @@ param ([parameter(Mandatory=$True)] [string] $LogFileName) try { - Import-Module CredentialManager -Force + Import-Module CredentialManager -Force -ErrorAction Ignore } catch { Write-Host "Failed to import CredentialManager module. Using default credentials." } From 7c2a20714c6e839fa89271f56def3fd978eba6fa Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 14 Nov 2024 14:06:41 -0800 Subject: [PATCH 023/190] fix --- 1es/configure_vm.ps1 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/1es/configure_vm.ps1 b/1es/configure_vm.ps1 index 81db964d46..871c21de5d 100644 --- a/1es/configure_vm.ps1 +++ b/1es/configure_vm.ps1 @@ -105,5 +105,21 @@ verifier /standard /bootmode persistent /driver ebpfcore.sys netebpfext.sys samp # # Get PSExec to run tests as SYSTEM. # Get-PSExec +# Loop through each adapter and enable IPv4 and IPv6 +$adapters = Get-NetAdapter +foreach ($adapter in $adapters) { + try { + # Enable IPv4 (usually enabled by default) + Enable-NetAdapterBinding -Name $adapter.Name -ComponentID ms_tcpip + + # Enable IPv6 + Enable-NetAdapterBinding -Name $adapter.Name -ComponentID ms_tcpip6 + + Write-Host "Enabled IPv4 and IPv6 on adapter: $($adapter.Name)" + } catch { + Write-Host "Failed to enable IPv4 and IPv6 on adapter: $($adapter.Name)" + } +} + # Reboot the machine to apply the changes. Restart-Computer -Force \ No newline at end of file From b21f8c6ab5ec461fd204624acaeb1bc79d6c9296 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 15 Nov 2024 07:36:28 -0800 Subject: [PATCH 024/190] fix --- 1es/configure_vm.ps1 | 4 ++++ scripts/config_test_vm.psm1 | 3 +++ 2 files changed, 7 insertions(+) diff --git a/1es/configure_vm.ps1 b/1es/configure_vm.ps1 index 871c21de5d..4254673e9b 100644 --- a/1es/configure_vm.ps1 +++ b/1es/configure_vm.ps1 @@ -121,5 +121,9 @@ foreach ($adapter in $adapters) { } } +ipconfig /all + +Get-NetIPInterface + # Reboot the machine to apply the changes. Restart-Computer -Force \ No newline at end of file diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index f08b907b1c..6d98d4c043 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -540,7 +540,10 @@ function Initialize-NetworkInterfacesOnVMs # Disable Duonic's fake checksum offload and force TCP/IP to calculate it. Set-NetAdapterAdvancedProperty duo? -DisplayName Checksum -RegistryValue 0 + # TODO - remove this debugging output ipconfig /all + Get-NetIPInterface + Get-NetAdapter Pop-Location } -ArgumentList ("eBPF", $LogFileName) -ErrorAction Stop From 94dd3876191d7dbfc93569ebf414a657864667eb Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 15 Nov 2024 09:18:53 -0800 Subject: [PATCH 025/190] fix --- 1es/Setup_orig.ps1 | 3 ++- scripts/config_test_vm.psm1 | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/1es/Setup_orig.ps1 b/1es/Setup_orig.ps1 index 2abd5ea34a..3a09dba395 100644 --- a/1es/Setup_orig.ps1 +++ b/1es/Setup_orig.ps1 @@ -28,7 +28,8 @@ if (-not (Test-Path -Path $BaseVhdDirPath)) { throw "VHD directory not found at $BaseVhdDirPath" } -Create-VMSwitchIfNeeded -SwitchName 'VMInternalSwitch' -SwitchType Internal +Create-VMSwitchIfNeeded -SwitchName 'VMInternalSwitch' -SwitchType 'Internal' +Create-VMSwitchIfNeeded -SwitchName 'VMExternalSwitch' -SwitchType 'External' Create-VMStoredCredential -CredentialName "TEST_VM" -Username $VmUsername -Password $VmPassword Create-VMStoredCredential -CredentialName "TEST_VM_STANDARD" -Username $VmStandardUserName -Password $VmPassword Create-DirectoryIfNotExists -Path $WorkingPath diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index 6d98d4c043..dde9c18f11 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -542,8 +542,8 @@ function Initialize-NetworkInterfacesOnVMs # TODO - remove this debugging output ipconfig /all - Get-NetIPInterface - Get-NetAdapter + Get-NetIPInterface | fl * + Get-NetAdapter | fl * Pop-Location } -ArgumentList ("eBPF", $LogFileName) -ErrorAction Stop From 59b867ea54890a6d946276c9ab342af685436557 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 10 Dec 2024 11:25:34 -0800 Subject: [PATCH 026/190] WIP --- 1es/configure_vm.ps1 | 2 ++ scripts/config_test_vm.psm1 | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/1es/configure_vm.ps1 b/1es/configure_vm.ps1 index 4254673e9b..32a1768c8d 100644 --- a/1es/configure_vm.ps1 +++ b/1es/configure_vm.ps1 @@ -121,6 +121,8 @@ foreach ($adapter in $adapters) { } } +Get-NetAdapterBinding -AllBindings + ipconfig /all Get-NetIPInterface diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index dde9c18f11..81f6fffcc0 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -544,6 +544,24 @@ function Initialize-NetworkInterfacesOnVMs ipconfig /all Get-NetIPInterface | fl * Get-NetAdapter | fl * + Get-NetAdapterBinding -AllBindings + + # Loop through each adapter and enable IPv4 and IPv6 + $adapters = Get-NetAdapter + foreach ($adapter in $adapters) { + try { + # Enable IPv4 (usually enabled by default) + Enable-NetAdapterBinding -Name $adapter.Name -ComponentID ms_tcpip + + # Enable IPv6 + Enable-NetAdapterBinding -Name $adapter.Name -ComponentID ms_tcpip6 + + Write-Host "Enabled IPv4 and IPv6 on adapter: $($adapter.Name)" + } catch { + Write-Host "Failed to enable IPv4 and IPv6 on adapter: $($adapter.Name)" + } + } + Get-NetAdapterBinding -AllBindings Pop-Location } -ArgumentList ("eBPF", $LogFileName) -ErrorAction Stop From 03e5e33324dafc0d0e5c82e1619c573d2486e25a Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 10 Dec 2024 14:11:10 -0800 Subject: [PATCH 027/190] WIP --- scripts/config_test_vm.psm1 | 8 ++++---- tests/libs/util/socket_helper.cpp | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index 81f6fffcc0..476c2a5680 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -542,9 +542,9 @@ function Initialize-NetworkInterfacesOnVMs # TODO - remove this debugging output ipconfig /all - Get-NetIPInterface | fl * - Get-NetAdapter | fl * - Get-NetAdapterBinding -AllBindings + Get-NetIPInterface | fl * | Out-String + Get-NetAdapter | fl * | Out-String + Get-NetAdapterBinding -AllBindings | fl * | Out-String # Loop through each adapter and enable IPv4 and IPv6 $adapters = Get-NetAdapter @@ -561,7 +561,7 @@ function Initialize-NetworkInterfacesOnVMs Write-Host "Failed to enable IPv4 and IPv6 on adapter: $($adapter.Name)" } } - Get-NetAdapterBinding -AllBindings + Get-NetAdapterBinding -AllBindings | fl * | Out-String Pop-Location } -ArgumentList ("eBPF", $LogFileName) -ErrorAction Stop diff --git a/tests/libs/util/socket_helper.cpp b/tests/libs/util/socket_helper.cpp index 23338fcf09..e2fd5f224a 100644 --- a/tests/libs/util/socket_helper.cpp +++ b/tests/libs/util/socket_helper.cpp @@ -86,6 +86,8 @@ _base_socket::_base_socket( socket, IPPROTO_IPV6, IPV6_V6ONLY, reinterpret_cast<const char*>(&ipv6_option), sizeof(unsigned long)); if (error != 0) { FAIL("Could not enable dual family endpoint: " << WSAGetLastError()); + } else { + printf("Dual family endpoint enabled\n"); } } From e96857dece75f5c121d1b14e5d5c1bfbfe0c5dae Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 10 Dec 2024 15:31:54 -0800 Subject: [PATCH 028/190] WIP --- 1es/Setup_orig.ps1 | 7 ++++--- 1es/prepare_vm_helpers.psm1 | 2 ++ scripts/cleanup_ebpf_cicd_tests.ps1 | 6 ++++++ scripts/config_test_vm.psm1 | 8 ++++---- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/1es/Setup_orig.ps1 b/1es/Setup_orig.ps1 index 3a09dba395..fe5d1fe858 100644 --- a/1es/Setup_orig.ps1 +++ b/1es/Setup_orig.ps1 @@ -28,10 +28,11 @@ if (-not (Test-Path -Path $BaseVhdDirPath)) { throw "VHD directory not found at $BaseVhdDirPath" } -Create-VMSwitchIfNeeded -SwitchName 'VMInternalSwitch' -SwitchType 'Internal' +# Create-VMSwitchIfNeeded -SwitchName 'VMInternalSwitch' -SwitchType 'Internal' Create-VMSwitchIfNeeded -SwitchName 'VMExternalSwitch' -SwitchType 'External' -Create-VMStoredCredential -CredentialName "TEST_VM" -Username $VmUsername -Password $VmPassword -Create-VMStoredCredential -CredentialName "TEST_VM_STANDARD" -Username $VmStandardUserName -Password $VmPassword +# Stored credentials doesn't seem to be working... +# Create-VMStoredCredential -CredentialName "TEST_VM" -Username $VmUsername -Password $VmPassword +# Create-VMStoredCredential -CredentialName "TEST_VM_STANDARD" -Username $VmStandardUserName -Password $VmPassword Create-DirectoryIfNotExists -Path $WorkingPath # Read the input VHDs diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index aac41e96f5..2fc87e7fd8 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -246,6 +246,8 @@ function Configure-VM { Log-Message "Executing VM configuration script ($VMSetupScript) on VM: $VmName" Copy-VMFile -VMName $VmName -FileSource Host -SourcePath $VMSetupScript -DestinationPath "$VMWorkingDirectory\$VMSetupScript" -CreateFullPath Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "cd $VMWorkingDirectory; .\$VMSetupScript" + Log-Message "Sleeping for 1 minute to let the VM get into a steady state" + Sleep -Seconds 60 # Sleep for 1 minute to let the VM get into a steady state. Log-Message -Message "Successfully executed VM configuration script ($VMSetupScript) on VM: $VmName" -ForegroundColor Green Wait-ForVMReady -VMName $VmName -VmCredential $VmCredential diff --git a/scripts/cleanup_ebpf_cicd_tests.ps1 b/scripts/cleanup_ebpf_cicd_tests.ps1 index a379dfbbc9..bc6e0698cb 100644 --- a/scripts/cleanup_ebpf_cicd_tests.ps1 +++ b/scripts/cleanup_ebpf_cicd_tests.ps1 @@ -55,6 +55,12 @@ $Job = Start-Job -ScriptBlock { -VMName $VMName ` -Credential $TestVMCredential ` -ScriptBlock { + # TODO - remove this debugging output + ipconfig /all + Get-NetIPInterface | Out-String + Get-NetAdapter | Out-String + Get-NetAdapterBinding -AllBindings | Out-String + Test-Path -Path "c:\windows\memory.dmp" -PathType leaf } diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index 476c2a5680..f265e3417d 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -542,9 +542,9 @@ function Initialize-NetworkInterfacesOnVMs # TODO - remove this debugging output ipconfig /all - Get-NetIPInterface | fl * | Out-String - Get-NetAdapter | fl * | Out-String - Get-NetAdapterBinding -AllBindings | fl * | Out-String + Get-NetIPInterface | Out-String + Get-NetAdapter | Out-String + Get-NetAdapterBinding -AllBindings | Out-String # Loop through each adapter and enable IPv4 and IPv6 $adapters = Get-NetAdapter @@ -561,7 +561,7 @@ function Initialize-NetworkInterfacesOnVMs Write-Host "Failed to enable IPv4 and IPv6 on adapter: $($adapter.Name)" } } - Get-NetAdapterBinding -AllBindings | fl * | Out-String + Get-NetAdapterBinding -AllBindings | Out-String Pop-Location } -ArgumentList ("eBPF", $LogFileName) -ErrorAction Stop From 3575a62d785745fedf770d037203e7fe83d712cc Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 11 Dec 2024 09:39:44 -0800 Subject: [PATCH 029/190] remove debug trace --- tests/libs/util/socket_helper.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/libs/util/socket_helper.cpp b/tests/libs/util/socket_helper.cpp index e2fd5f224a..23338fcf09 100644 --- a/tests/libs/util/socket_helper.cpp +++ b/tests/libs/util/socket_helper.cpp @@ -86,8 +86,6 @@ _base_socket::_base_socket( socket, IPPROTO_IPV6, IPV6_V6ONLY, reinterpret_cast<const char*>(&ipv6_option), sizeof(unsigned long)); if (error != 0) { FAIL("Could not enable dual family endpoint: " << WSAGetLastError()); - } else { - printf("Dual family endpoint enabled\n"); } } From e77ccfe513bc46151967ffbd4825c49952d7c253 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 11 Dec 2024 11:42:46 -0800 Subject: [PATCH 030/190] add extra debug logs --- scripts/common.psm1 | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/scripts/common.psm1 b/scripts/common.psm1 index ea215cff72..2842653d74 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -61,23 +61,42 @@ function Compress-File # Retry 3 times to ensure compression operation succeeds. # To mitigate error message: "The process cannot access the file <filename> because it is being used by another process." $retryCount = 1 - while ($retryCount -lt 4) { - $error.clear() - Compress-Archive ` - -Path $SourcePath ` - -DestinationPath $DestinationPath ` - -CompressionLevel Fastest ` - -Force - if ($error[0] -ne $null) { - $ErrorMessage = "*** ERROR *** Failed to compress kernel mode dump files: $error. Retrying $retryCount" + while ($retryCount -lt 6) { + try { + $error.clear() + Compress-Archive ` + -Path $SourcePath ` + -DestinationPath $DestinationPath ` + -CompressionLevel Fastest ` + -Force + if ($error[0] -ne $null) { + $ErrorMessage = "*** ERROR *** Failed to compress kernel mode dump files: $error. Retrying $retryCount" + Write-Output $ErrorMessage + Start-Sleep -seconds (5 * $retryCount) + $retryCount++ + } else { + # Compression succeeded. + if (Test-Path $DestinationPath) { + Write-Log "Successfully compressed $SourcePath -> $DestinationPath" + break; + } else { + $ErrorMessage = "*** ERROR *** Failed to compress kernel mode dump files: $error. Retrying $retryCount" + Write-Output $ErrorMessage + Start-Sleep -seconds (5 * $retryCount) + $retryCount++ + } + } + } catch { + $ErrorMessage = "*** ERROR *** Failed to compress kernel mode dump files: $_. Retrying $retryCount" Write-Output $ErrorMessage Start-Sleep -seconds (5 * $retryCount) $retryCount++ - } else { - # Compression succeeded. - break; } } + + if (!(Test-Path $DestinationPath)) { + Write-Log "Failed to compress kernel mode dump files after retries" + } } function Wait-TestJobToComplete From 112d69efb4471e2826a6cd5734a307b970725bdc Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 11 Dec 2024 16:13:41 -0800 Subject: [PATCH 031/190] WIP --- 1es/Setup_orig.ps1 | 6 +++--- 1es/prepare_vm_helpers.psm1 | 5 +++-- scripts/vm_run_tests.psm1 | 3 +++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/1es/Setup_orig.ps1 b/1es/Setup_orig.ps1 index fe5d1fe858..77e2cb5841 100644 --- a/1es/Setup_orig.ps1 +++ b/1es/Setup_orig.ps1 @@ -11,8 +11,8 @@ param( [Parameter(Mandatory=$False)][string]$OutVhdDirPath='.\exported_vhds', [Parameter(Mandatory=$False)][string]$ExternalSwitchName='VMExternalSwitch', - [Parameter(Mandatory=$False)][string]$VMCpuCount=2, - [Parameter(Mandatory=$False)][string]$VMMemoryStartupBytes=512MB + [Parameter(Mandatory=$False)][string]$VMCpuCount=4, + [Parameter(Mandatory=$False)][string]$VMMemory=4096MB ) $ErrorActionPreference = "Stop" @@ -56,7 +56,7 @@ for ($i = 0; $i -lt $vhds.Count; $i++) { -VhdPath $vhd.FullName ` -VmStoragePath $outVMPath ` -ExternalVMSwitchName $ExternalSwitchName ` - -MemoryStartupBytes $VMMemoryStartupBytes ` + -VMMemory $VMMemory ` -UnattendPath $BaseUnattendPath ` -VmUsername $VmUsername ` -VmPassword $VmPassword diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index 2fc87e7fd8..dc16039bdf 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -150,7 +150,7 @@ function Create-VM { [Parameter(Mandatory=$True)][string]$VhdPath, [Parameter(Mandatory=$True)][string]$VmStoragePath, [Parameter(Mandatory=$True)][string]$ExternalVMSwitchName, - [Parameter(Mandatory=$True)][Int64]$MemoryStartupBytes, + [Parameter(Mandatory=$True)][Int64]$VMMemory, [Parameter(Mandatory=$True)][string]$UnattendPath ) @@ -190,12 +190,13 @@ function Create-VM { # Create the VM Log-Message "Creating the VM" - New-VM -Name $VmName -MemoryStartupBytes $MemoryStartupBytes -VhdPath $VmVhdPath + New-VM -Name $VmName -VhdPath $VmVhdPath $vmSwitches = Get-VMSwitch foreach ($switch in $vmSwitches) { Log-Message "Adding network adapter to VM: $VmName with switch: $($switch.Name)" Add-VMNetworkAdapter -VMName $VmName -SwitchName $switch.Name } + Set-VMMemory -VMName $VmName -DynamicMemoryEnabled $false -MinimumBytes $VMMemory -StartupBytes $VMMemory -MaximumBytes $VMMemory if ((Get-VM -VMName $vmName) -eq $null) { throw "Failed to create VM: $VMName" diff --git a/scripts/vm_run_tests.psm1 b/scripts/vm_run_tests.psm1 index d6f92e7a44..28fa650df1 100644 --- a/scripts/vm_run_tests.psm1 +++ b/scripts/vm_run_tests.psm1 @@ -67,6 +67,7 @@ function Invoke-CICDTestsOnVM Import-Module $WorkingDirectory\common.psm1 -ArgumentList ($LogFileName) -Force -WarningAction SilentlyContinue Import-Module $WorkingDirectory\run_driver_tests.psm1 -ArgumentList ($WorkingDirectory, $LogFileName, $TestHangTimeout, $UserModeDumpFolder) -Force -WarningAction SilentlyContinue + GetDriveFreeSpaceGB $TestMode = $TestMode.ToLower() switch ($TestMode) { @@ -287,6 +288,7 @@ function Invoke-XDPTestOnVM Import-Module $WorkingDirectory\common.psm1 -ArgumentList ($LogFileName) -Force -WarningAction SilentlyContinue Import-Module $WorkingDirectory\run_driver_tests.psm1 -ArgumentList ($WorkingDirectory, $LogFileName, $TestHangTimeout, $UserModeDumpFolder) -Force -WarningAction SilentlyContinue + GetDriveFreeSpaceGB Write-Log "Invoking $XDPTestName on $VM" Invoke-XDPTest ` -RemoteIPV4Address $RemoteIPV4Address ` @@ -622,6 +624,7 @@ function Invoke-ConnectRedirectTestsOnVM Import-Module $WorkingDirectory\common.psm1 -ArgumentList ($LogFileName) -Force -WarningAction SilentlyContinue Import-Module $WorkingDirectory\run_driver_tests.psm1 -ArgumentList ($WorkingDirectory, $LogFileName, $TestHangTimeout, $UserModeDumpFolder) -Force -WarningAction SilentlyContinue + GetDriveFreeSpaceGB Write-Log "Invoking connect redirect tests [Mode=$UserType] on $VM" Invoke-ConnectRedirectTest ` -LocalIPv4Address $LocalIPv4Address ` From 0c443c4e38ef67da7859c45539f31c2c8bce9231 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 12 Dec 2024 09:23:53 -0800 Subject: [PATCH 032/190] WIP --- 1es/prepare_vm_helpers.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index dc16039bdf..d6b6f4554f 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -196,7 +196,7 @@ function Create-VM { Log-Message "Adding network adapter to VM: $VmName with switch: $($switch.Name)" Add-VMNetworkAdapter -VMName $VmName -SwitchName $switch.Name } - Set-VMMemory -VMName $VmName -DynamicMemoryEnabled $false -MinimumBytes $VMMemory -StartupBytes $VMMemory -MaximumBytes $VMMemory + Set-VMMemory -VMName $VmName -DynamicMemoryEnabled $false -StartupBytes $VMMemory if ((Get-VM -VMName $vmName) -eq $null) { throw "Failed to create VM: $VMName" From 9f73f64361b59f9e98b01378f13081dc731b6af5 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 12 Dec 2024 10:04:15 -0800 Subject: [PATCH 033/190] wip --- scripts/vm_run_tests.psm1 | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/vm_run_tests.psm1 b/scripts/vm_run_tests.psm1 index 28fa650df1..d6f92e7a44 100644 --- a/scripts/vm_run_tests.psm1 +++ b/scripts/vm_run_tests.psm1 @@ -67,7 +67,6 @@ function Invoke-CICDTestsOnVM Import-Module $WorkingDirectory\common.psm1 -ArgumentList ($LogFileName) -Force -WarningAction SilentlyContinue Import-Module $WorkingDirectory\run_driver_tests.psm1 -ArgumentList ($WorkingDirectory, $LogFileName, $TestHangTimeout, $UserModeDumpFolder) -Force -WarningAction SilentlyContinue - GetDriveFreeSpaceGB $TestMode = $TestMode.ToLower() switch ($TestMode) { @@ -288,7 +287,6 @@ function Invoke-XDPTestOnVM Import-Module $WorkingDirectory\common.psm1 -ArgumentList ($LogFileName) -Force -WarningAction SilentlyContinue Import-Module $WorkingDirectory\run_driver_tests.psm1 -ArgumentList ($WorkingDirectory, $LogFileName, $TestHangTimeout, $UserModeDumpFolder) -Force -WarningAction SilentlyContinue - GetDriveFreeSpaceGB Write-Log "Invoking $XDPTestName on $VM" Invoke-XDPTest ` -RemoteIPV4Address $RemoteIPV4Address ` @@ -624,7 +622,6 @@ function Invoke-ConnectRedirectTestsOnVM Import-Module $WorkingDirectory\common.psm1 -ArgumentList ($LogFileName) -Force -WarningAction SilentlyContinue Import-Module $WorkingDirectory\run_driver_tests.psm1 -ArgumentList ($WorkingDirectory, $LogFileName, $TestHangTimeout, $UserModeDumpFolder) -Force -WarningAction SilentlyContinue - GetDriveFreeSpaceGB Write-Log "Invoking connect redirect tests [Mode=$UserType] on $VM" Invoke-ConnectRedirectTest ` -LocalIPv4Address $LocalIPv4Address ` From 25810d170563baa25219ef06f68befc12f78020d Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 12 Dec 2024 13:39:06 -0800 Subject: [PATCH 034/190] WIP --- scripts/run_driver_tests.psm1 | 208 ++++++++++++++++++---------------- 1 file changed, 111 insertions(+), 97 deletions(-) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 01720f4ba5..5665315ed7 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -260,33 +260,38 @@ function Invoke-Test [Parameter(Mandatory = $True)][bool] $VerboseLogs, [Parameter(Mandatory = $True)][int] $TestHangTimeout) - # Initialize arguments. - if ($TestArgs -ne "") { - $ArgumentsList = @($TestArgs) - } + try { + # Initialize arguments. + if ($TestArgs -ne "") { + $ArgumentsList = @($TestArgs) + } - if ($VerboseLogs -eq $true) { - $ArgumentsList += '-s' - } + if ($VerboseLogs -eq $true) { + $ArgumentsList += '-s' + } - # Execute Test. - Write-Log "Executing $TestName $TestArgs" - $TestFilePath = "$pwd\$TestName" - $TempOutputFile = "$env:TEMP\app_output.log" # Log for standard output - $TempErrorFile = "$env:TEMP\app_error.log" # Log for standard error - if ($ArgumentsList) { - $TestProcess = Start-Process -FilePath $TestFilePath -ArgumentList $ArgumentsList -PassThru -NoNewWindow -RedirectStandardOutput $TempOutputFile -RedirectStandardError $TempErrorFile -ErrorAction Stop - } else { - $TestProcess = Start-Process -FilePath $TestFilePath -PassThru -NoNewWindow -RedirectStandardOutput $TempOutputFile -RedirectStandardError $TempErrorFile -ErrorAction Stop - } - if ($InnerTestName -ne "") { - Process-TestCompletion -TestProcess $TestProcess -TestCommand $InnerTestName -NestedProcess $True -TestHangTimeout $TestHangTimeout - } else { - Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestName -TestHangTimeout $TestHangTimeout - } + # Execute Test. + Write-Log "Executing $TestName $TestArgs" + $TestFilePath = "$pwd\$TestName" + $TempOutputFile = "$env:TEMP\app_output.log" # Log for standard output + $TempErrorFile = "$env:TEMP\app_error.log" # Log for standard error + if ($ArgumentsList) { + $TestProcess = Start-Process -FilePath $TestFilePath -ArgumentList $ArgumentsList -PassThru -NoNewWindow -RedirectStandardOutput $TempOutputFile -RedirectStandardError $TempErrorFile -ErrorAction Stop + } else { + $TestProcess = Start-Process -FilePath $TestFilePath -PassThru -NoNewWindow -RedirectStandardOutput $TempOutputFile -RedirectStandardError $TempErrorFile -ErrorAction Stop + } + if ($InnerTestName -ne "") { + Process-TestCompletion -TestProcess $TestProcess -TestCommand $InnerTestName -NestedProcess $True -TestHangTimeout $TestHangTimeout + } else { + Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestName -TestHangTimeout $TestHangTimeout + } - Write-Log "Test `"$TestName $TestArgs`" Passed" -ForegroundColor Green - Write-Log "`n==============================`n" + Write-Log "Test `"$TestName $TestArgs`" Passed" -ForegroundColor Green + Write-Log "`n==============================`n" + } catch { + $ErrorMessage = $_.Exception.Message + ThrowWithErrorMessage -ErrorMessage "Test `"$TestName $TestArgs`" Failed with $ErrorMessage" + } } # Function to create a tuple with default values for Arguments and Timeout @@ -358,22 +363,27 @@ function Invoke-XDPTest Push-Location $WorkingDirectory - Write-Log "Executing $XDPTestName with remote address: $RemoteIPV4Address" - $TestRunScript = ".\Run-Self-Hosted-Runner-Test.ps1" - $TestCommand = ".\xdp_tests.exe" - $TestArguments = "$XDPTestName --remote-ip $RemoteIPV4Address" - $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand - - Write-Log "Executing $XDPTestName with remote address: $RemoteIPV6Address" - $TestRunScript = ".\Run-Self-Hosted-Runner-Test.ps1" - $TestCommand = ".\xdp_tests.exe" - $TestArguments = "$XDPTestName --remote-ip $RemoteIPV6Address" - $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand - - Write-Log "$XDPTestName Test Passed" -ForegroundColor Green - Write-Log "`n`n" + try { + Write-Log "Executing $XDPTestName with remote address: $RemoteIPV4Address" + $TestRunScript = ".\Run-Self-Hosted-Runner-Test.ps1" + $TestCommand = ".\xdp_tests.exe" + $TestArguments = "$XDPTestName --remote-ip $RemoteIPV4Address" + $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow + Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand + + Write-Log "Executing $XDPTestName with remote address: $RemoteIPV6Address" + $TestRunScript = ".\Run-Self-Hosted-Runner-Test.ps1" + $TestCommand = ".\xdp_tests.exe" + $TestArguments = "$XDPTestName --remote-ip $RemoteIPV6Address" + $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow + Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand + + Write-Log "$XDPTestName Test Passed" -ForegroundColor Green + Write-Log "`n`n" + } catch { + $ErrorMessage = $_.Exception.Message + ThrowWithErrorMessage -ErrorMessage "XDP test Failed with $ErrorMessage" + } Pop-Location } @@ -395,63 +405,67 @@ function Invoke-ConnectRedirectTest Push-Location $WorkingDirectory - $TestRunScript = ".\Run-Self-Hosted-Runner-Test.ps1" - $TestCommand = ".\connect_redirect_tests.exe" - - ## First run the test with both v4 and v6 programs attached. - $TestArguments = - " --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" - - Write-Log "Executing connect redirect tests with v4 and v6 programs. Arguments: $TestArguments" - $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand - - - ## Run test with only v4 program attached. - $TestArguments = - " --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]" - - Write-Log "Executing connect redirect tests with v4 programs. Arguments: $TestArguments" - $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand - - - ## Run tests with only v6 program attached. - $TestArguments = - " --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]" - - Write-Log "Executing connect redirect tests with v6 programs. Arguments: $TestArguments" - $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand - - - Write-Log "Connect-Redirect Test Passed" -ForegroundColor Green + try { + $TestRunScript = ".\Run-Self-Hosted-Runner-Test.ps1" + $TestCommand = ".\connect_redirect_tests.exe" + + ## First run the test with both v4 and v6 programs attached. + $TestArguments = + " --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" + + Write-Log "Executing connect redirect tests with v4 and v6 programs. Arguments: $TestArguments" + $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow + Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand + + + ## Run test with only v4 program attached. + $TestArguments = + " --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]" + + Write-Log "Executing connect redirect tests with v4 programs. Arguments: $TestArguments" + $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow + Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand + + + ## Run tests with only v6 program attached. + $TestArguments = + " --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]" + + Write-Log "Executing connect redirect tests with v6 programs. Arguments: $TestArguments" + $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow + Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand + + Write-Log "Connect-Redirect Test Passed" -ForegroundColor Green + } catch { + $ErrorMessage = $_.Exception.Message + ThrowWithErrorMessage -ErrorMessage "Connect-Redirect Test Failed with $ErrorMessage" + } Pop-Location } From 949aeb2d1c037e658ce6e34b53517102f2ddf0cb Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 12 Dec 2024 14:15:23 -0800 Subject: [PATCH 035/190] WIP - try to separate out which jobs run on 1es vs which run on github: --- .github/workflows/cicd.yml | 20 ++++++++- .github/workflows/reusable-test.yml | 70 ++++++++++++++++++++--------- 2 files changed, 69 insertions(+), 21 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 6f9afca8d7..ecd359dbe7 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -57,6 +57,24 @@ jobs: build_options: /p:ReleaseJIT='True' configurations: '["Debug", "Release"]' + # Run the unit tests in GitHub. + unit_tests: + # Always run this job. + needs: regular + if: github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' + uses: ./.github/workflows/reusable-test.yml + with: + name: unit_tests + pre_test: appverif -enable Exceptions Handles Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe + # Exclude [processes] test that CodeCoverage can't work with. + test_command: .\unit_tests.exe -d yes ~[processes] + build_artifact: Build-x64 + environment: windows-2022 + code_coverage: true + gather_dumps: true + capture_etw: true + leak_detection: true + # Run the driver tests on self-hosted runners. driver_ws2019: # Always run this job. @@ -70,7 +88,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_ws2019 build_artifact: Build-x64 - environment: ebpf_cicd_tests_ws2019 + environment: 1es-server-2019 # ebpf_cicd_tests_ws2019 # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index d40f7fa76e..1c0ac05742 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -62,6 +62,47 @@ permissions: issues: write # Required to create issues. jobs: + set-job-environment: + # The following environments are supported: + # - 1es-<RUNNER_POOL_NAME> (which matches ebpf-cicd-runner-pool-<RUNNER_POOL_NAME> in the 1es pool) + # - Any of the github environments. + runs-on: ${{ inputs.environment }} + steps: + - name: Set runner type + id: set_runner + run: | + if [[ "${{ inputs.environment }}" == *"1es"* ]]; then + pool_name=$(echo "${{ inputs.environment }}" | sed 's/.*1es-//') + echo "::set-output name=runs_on::self-hosted" + echo "::set-output name=runs_on_pool::1ES.Pool=ebpf-cicd-runner-pool-$pool_name" + else + echo "::set-output name=runs_on::${{ inputs.environment }}" + fi +# Alternative solution: +# jobs: +# example-job: +# runs-on: ${{ inputs.environment }} +# steps: +# - name: Check condition +# id: condition +# run: echo "Condition check" +# # Set an output based on your condition +# # For example, set the output to 'true' if you want to use the self-hosted runner +# # You can replace this with your actual condition +# echo "::set-output name=use_self_hosted::true" + +# - name: Set runs-on +# if: steps.condition.outputs.use_self_hosted == 'true' +# run: | +# echo "::set-output name=runs_on::self-hosted" +# echo "::set-output name=runs_on_pool::1ES.Pool=ebpf-cicd-runner-pool-server-2019" + +# - name: Set runs-on +# if: steps.condition.outputs.use_self_hosted != 'true' +# run: echo "::set-output name=runs_on::${{ inputs.environment }}" + +# runs-on: ${{ steps.set_runs_on.outputs.runs_on }} +# runs-on: ${{ steps.set_runs_on.outputs.runs_on_pool }} run_test: # Due to app-verifier, unit tests take a lot longer to execute. Increase the timeout to 90 minutes. timeout-minutes: 90 @@ -69,9 +110,8 @@ jobs: strategy: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: - - self-hosted - - "1ES.Pool=ebpf-cicd-runner-pool-server-2019" + runs-on: ${{ steps.set_runner.outputs.runs_on }} + runs-on: ${{ steps.set_runner.outputs.runs_on_pool }} env: # Configuration type to build. SOURCE_ROOT: ${{github.workspace}} @@ -91,15 +131,15 @@ jobs: with: egress-policy: audit - - name: maige_test - id: maige-test + - name: Provision Mock (Move to setup script directly later) + id: provision-mock run: | - powershell.exe "Get-NetAdapter" - powershell.exe "Get-VMSwitch" powershell.exe "cd C:\bin\CloudTestWorker\ProvisioningScript; dir; .\Setup_orig.ps1" - powershell.exe "Get-NetAdapter" - powershell.exe "Get-VMSwitch" - powershell.exe "Get-VM" + # powershell.exe "Get-NetAdapter" + # powershell.exe "Get-VMSwitch" + # powershell.exe "Get-NetAdapter" + # powershell.exe "Get-VMSwitch" + # powershell.exe "Get-VM" - name: Print CPU information run: @@ -244,16 +284,6 @@ jobs: .\export_program_info_sample.exe --clear .\export_program_info_sample.exe - - name: 1ES TEST - 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: test_1es - working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} - run: | - hostname - whoami - powershell.exe Get-VM - dir /s - - 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 From cac10f2a2eeed415b2c0688334a71f48d0132d5a Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 12 Dec 2024 14:22:58 -0800 Subject: [PATCH 036/190] WIP --- .github/workflows/cicd.yml | 2 +- .github/workflows/reusable-test.yml | 29 ++--------------------------- 2 files changed, 3 insertions(+), 28 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index ecd359dbe7..d26fea180c 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -88,7 +88,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_ws2019 build_artifact: Build-x64 - environment: 1es-server-2019 # ebpf_cicd_tests_ws2019 + environment: 1es-server-2019 # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 1c0ac05742..23262daf49 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -64,9 +64,9 @@ permissions: jobs: set-job-environment: # The following environments are supported: - # - 1es-<RUNNER_POOL_NAME> (which matches ebpf-cicd-runner-pool-<RUNNER_POOL_NAME> in the 1es pool) # - Any of the github environments. - runs-on: ${{ inputs.environment }} + # - 1es-<RUNNER_POOL_NAME> (which matches ebpf-cicd-runner-pool-<RUNNER_POOL_NAME> in the 1es pool) + runs-on: ubuntu-latest steps: - name: Set runner type id: set_runner @@ -78,31 +78,6 @@ jobs: else echo "::set-output name=runs_on::${{ inputs.environment }}" fi -# Alternative solution: -# jobs: -# example-job: -# runs-on: ${{ inputs.environment }} -# steps: -# - name: Check condition -# id: condition -# run: echo "Condition check" -# # Set an output based on your condition -# # For example, set the output to 'true' if you want to use the self-hosted runner -# # You can replace this with your actual condition -# echo "::set-output name=use_self_hosted::true" - -# - name: Set runs-on -# if: steps.condition.outputs.use_self_hosted == 'true' -# run: | -# echo "::set-output name=runs_on::self-hosted" -# echo "::set-output name=runs_on_pool::1ES.Pool=ebpf-cicd-runner-pool-server-2019" - -# - name: Set runs-on -# if: steps.condition.outputs.use_self_hosted != 'true' -# run: echo "::set-output name=runs_on::${{ inputs.environment }}" - -# runs-on: ${{ steps.set_runs_on.outputs.runs_on }} -# runs-on: ${{ steps.set_runs_on.outputs.runs_on_pool }} run_test: # Due to app-verifier, unit tests take a lot longer to execute. Increase the timeout to 90 minutes. timeout-minutes: 90 From 30658da92ac40064b2aeb31347d7e7ee10a3d66a Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 12 Dec 2024 14:31:00 -0800 Subject: [PATCH 037/190] WIP --- .github/workflows/reusable-test.yml | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 23262daf49..2477fb6091 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -85,8 +85,9 @@ jobs: strategy: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: ${{ steps.set_runner.outputs.runs_on }} - runs-on: ${{ steps.set_runner.outputs.runs_on_pool }} + runs-on: + - ${{ steps.set_runner.outputs.runs_on }} + - ${{ steps.set_runner.outputs.runs_on_pool }} env: # Configuration type to build. SOURCE_ROOT: ${{github.workspace}} @@ -106,8 +107,9 @@ jobs: with: egress-policy: audit - - name: Provision Mock (Move to setup script directly later) - id: provision-mock + - name: Configure runner (Move to setup script directly later) + id: configure-runner + if: contains(inputs.environment, '1es') run: | powershell.exe "cd C:\bin\CloudTestWorker\ProvisioningScript; dir; .\Setup_orig.ps1" # powershell.exe "Get-NetAdapter" @@ -136,7 +138,7 @@ jobs: # Perform shallow checkout for self-hosted runner. - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - 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') + if: contains(inputs.environment, '1es') && (steps.skip_check.outputs.should_skip != 'true') with: ref: ${{ github.event.workflow_run.head_branch }} @@ -186,7 +188,7 @@ jobs: - 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') + if: (inputs.code_coverage == true) && !contains(inputs.environment, '1es') && (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 @@ -203,7 +205,7 @@ jobs: 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') + if: contains(inputs.environment, '1es') && (steps.skip_check.outputs.should_skip != 'true') run: | Remove-Item -Path ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}} -Recurse -Force -ErrorAction SilentlyContinue @@ -260,14 +262,14 @@ jobs: .\export_program_info_sample.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') + if: steps.skip_check.outputs.should_skip != 'true' && !contains(inputs.environment, '1es') id: run_pre_test_command working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | ${{env.PRE_COMMAND}} - name: Run pre test command on self-hosted runner - 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') + if: steps.skip_check.outputs.should_skip != 'true' && contains(inputs.environment, '1es') id: run_pre_test_command_self_hosted working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | @@ -309,14 +311,14 @@ jobs: 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 on self-hosted runner - if: (inputs.code_coverage == false) && (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') && (inputs.fault_injection != true) + if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && contains(inputs.environment, '1es') && (inputs.fault_injection != true) id: run_test_self_hosted working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | ${{env.TEST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} - name: Run test without Code Coverage - if: (inputs.code_coverage == false) && (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') && (inputs.fault_injection != true) + if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && contains(inputs.environment, '1es') && (inputs.fault_injection != true) id: run_test_without_code_coverage working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} shell: cmd @@ -326,7 +328,7 @@ jobs: - 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') + if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && contains(inputs.environment, '1es') id: run_post_test_command working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | @@ -334,7 +336,7 @@ jobs: - name: Run post test command on self-hosted runner # 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') + if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && contains(inputs.environment, '1es') id: run_post_test_command_self_hosted working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | From a79f74ebe581c1d68bc2895bd4f6c1933453993b Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 12 Dec 2024 14:35:03 -0800 Subject: [PATCH 038/190] WIP --- .github/workflows/reusable-test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 2477fb6091..21cd8660bc 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -86,8 +86,8 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} runs-on: - - ${{ steps.set_runner.outputs.runs_on }} - - ${{ steps.set_runner.outputs.runs_on_pool }} + - ${{ set-job-environment.steps.set_runner.outputs.runs_on }} + - ${{ set-job-environment.steps.set_runner.outputs.runs_on_pool }} env: # Configuration type to build. SOURCE_ROOT: ${{github.workspace}} From 9e2ca3de37a95296a802fb68a3b5e8e5f894b5ac Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 12 Dec 2024 14:38:01 -0800 Subject: [PATCH 039/190] WIP --- .github/workflows/reusable-test.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 21cd8660bc..087f3b0b26 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -79,6 +79,7 @@ jobs: echo "::set-output name=runs_on::${{ inputs.environment }}" fi run_test: + needs: set-job-environment # Due to app-verifier, unit tests take a lot longer to execute. Increase the timeout to 90 minutes. timeout-minutes: 90 @@ -86,8 +87,8 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} runs-on: - - ${{ set-job-environment.steps.set_runner.outputs.runs_on }} - - ${{ set-job-environment.steps.set_runner.outputs.runs_on_pool }} + - ${{ needs.set-job-environment.steps.outputs.runs_on }} + - ${{ needs.set-job-environment.steps.outputs.runs_on_pool }} env: # Configuration type to build. SOURCE_ROOT: ${{github.workspace}} From 53f62b27099b266b7044a9db9a613a4c1513420c Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 12 Dec 2024 15:06:06 -0800 Subject: [PATCH 040/190] WIP --- .github/workflows/reusable-test.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 087f3b0b26..d9d45ba61f 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -67,17 +67,19 @@ jobs: # - Any of the github environments. # - 1es-<RUNNER_POOL_NAME> (which matches ebpf-cicd-runner-pool-<RUNNER_POOL_NAME> in the 1es pool) runs-on: ubuntu-latest + outputs: + runs_on: ${{ steps.set_runner.outputs.runs_on }} + runs_on_pool: ${{ steps.set_runner.outputs.runs_on_pool }} steps: - name: Set runner type id: set_runner run: | if [[ "${{ inputs.environment }}" == *"1es"* ]]; then pool_name=$(echo "${{ inputs.environment }}" | sed 's/.*1es-//') - echo "::set-output name=runs_on::self-hosted" - echo "::set-output name=runs_on_pool::1ES.Pool=ebpf-cicd-runner-pool-$pool_name" + echo "runs_on=self-hosted" >> $GITHUB_OUTPUT + echo "runs_on_pool=1ES.Pool=ebpf-cicd-runner-pool-$pool_name" >> $GITHUB_OUTPUT else - echo "::set-output name=runs_on::${{ inputs.environment }}" - fi + echo "runs_on=${{ inputs.environment }}" >> $GITHUB_OUTPUT run_test: needs: set-job-environment # Due to app-verifier, unit tests take a lot longer to execute. Increase the timeout to 90 minutes. @@ -87,8 +89,8 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} runs-on: - - ${{ needs.set-job-environment.steps.outputs.runs_on }} - - ${{ needs.set-job-environment.steps.outputs.runs_on_pool }} + - ${{ needs.set-job-environment.outputs.runs_on }} + - ${{ needs.set-job-environment.outputs.runs_on_pool }} env: # Configuration type to build. SOURCE_ROOT: ${{github.workspace}} From fde019ba28933386637c95f2f3ccd01f32cc4ba1 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 12 Dec 2024 15:27:34 -0800 Subject: [PATCH 041/190] WIP --- .github/workflows/reusable-test.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index d9d45ba61f..c3db9edacd 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -76,10 +76,10 @@ jobs: run: | if [[ "${{ inputs.environment }}" == *"1es"* ]]; then pool_name=$(echo "${{ inputs.environment }}" | sed 's/.*1es-//') - echo "runs_on=self-hosted" >> $GITHUB_OUTPUT - echo "runs_on_pool=1ES.Pool=ebpf-cicd-runner-pool-$pool_name" >> $GITHUB_OUTPUT + echo "runs_on=self-hosted" >> $GITHUB_STATE + echo "runs_on_pool=1ES.Pool=ebpf-cicd-runner-pool-$pool_name" >> $GITHUB_STATE else - echo "runs_on=${{ inputs.environment }}" >> $GITHUB_OUTPUT + echo "runs_on=${{ inputs.environment }}" >> $GITHUB_STATE run_test: needs: set-job-environment # Due to app-verifier, unit tests take a lot longer to execute. Increase the timeout to 90 minutes. @@ -162,7 +162,6 @@ jobs: .github/workflows/reusable-test.yml sparse-checkout-cone-mode: false - - name: Set up choco cache folder # Set the choco cache to a local folder so that it can be cached. if: (inputs.gather_dumps == true) && (steps.skip_check.outputs.should_skip != 'true') From 0bae199d191f9a8f4ffa1f533197b938eec313f2 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 12 Dec 2024 16:46:51 -0800 Subject: [PATCH 042/190] WIP --- .github/workflows/reusable-test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index c3db9edacd..dd88c53c41 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -76,10 +76,10 @@ jobs: run: | if [[ "${{ inputs.environment }}" == *"1es"* ]]; then pool_name=$(echo "${{ inputs.environment }}" | sed 's/.*1es-//') - echo "runs_on=self-hosted" >> $GITHUB_STATE - echo "runs_on_pool=1ES.Pool=ebpf-cicd-runner-pool-$pool_name" >> $GITHUB_STATE + echo "runs_on=self-hosted" >> "$GITHUB_OUTPUT" + echo "runs_on_pool=1ES.Pool=ebpf-cicd-runner-pool-$pool_name" >> "$GITHUB_OUTPUT" else - echo "runs_on=${{ inputs.environment }}" >> $GITHUB_STATE + echo "runs_on=${{ inputs.environment }}" >> "$GITHUB_OUTPUT" run_test: needs: set-job-environment # Due to app-verifier, unit tests take a lot longer to execute. Increase the timeout to 90 minutes. From 874c6467c48f48761dbbcc016131a5f33849e314 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 12 Dec 2024 17:06:57 -0800 Subject: [PATCH 043/190] WIP --- .github/workflows/reusable-test.yml | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index dd88c53c41..60dc3cacad 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -68,18 +68,21 @@ jobs: # - 1es-<RUNNER_POOL_NAME> (which matches ebpf-cicd-runner-pool-<RUNNER_POOL_NAME> in the 1es pool) runs-on: ubuntu-latest outputs: - runs_on: ${{ steps.set_runner.outputs.runs_on }} - runs_on_pool: ${{ steps.set_runner.outputs.runs_on_pool }} + runs_on: ${{ steps.set_runner_1es.outputs.runs_on || steps.set_runner_github.outputs.runs_on }} + runs_on_pool: ${{ steps.set_runner_1es.outputs.runs_on_pool || '' }} steps: - - name: Set runner type - id: set_runner + - name: Set runner type (1es) + id: set_runner_1es + if: contains(inputs.environment, '1es') run: | - if [[ "${{ inputs.environment }}" == *"1es"* ]]; then - pool_name=$(echo "${{ inputs.environment }}" | sed 's/.*1es-//') - echo "runs_on=self-hosted" >> "$GITHUB_OUTPUT" - echo "runs_on_pool=1ES.Pool=ebpf-cicd-runner-pool-$pool_name" >> "$GITHUB_OUTPUT" - else - echo "runs_on=${{ inputs.environment }}" >> "$GITHUB_OUTPUT" + pool_name=$(echo "${{ inputs.environment }}" | sed 's/.*1es-//') + echo "runs_on=self-hosted" >> "$GITHUB_OUTPUT" + echo "runs_on_pool=1ES.Pool=ebpf-cicd-runner-pool-$pool_name" >> "$GITHUB_OUTPUT" + - name: Set runner type (github hosted) + id: set_runner_github + if: !contains(inputs.environment, '1es') + run: | + echo "runs_on=${{ inputs.environment }}" >> "$GITHUB_OUTPUT" run_test: needs: set-job-environment # Due to app-verifier, unit tests take a lot longer to execute. Increase the timeout to 90 minutes. From b45a65e8c041e9994bdc19a37ace600b893f2ad4 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 12 Dec 2024 17:11:19 -0800 Subject: [PATCH 044/190] WIP --- .github/workflows/reusable-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 60dc3cacad..eed3ed794a 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -78,6 +78,7 @@ jobs: pool_name=$(echo "${{ inputs.environment }}" | sed 's/.*1es-//') echo "runs_on=self-hosted" >> "$GITHUB_OUTPUT" echo "runs_on_pool=1ES.Pool=ebpf-cicd-runner-pool-$pool_name" >> "$GITHUB_OUTPUT" + - name: Set runner type (github hosted) id: set_runner_github if: !contains(inputs.environment, '1es') From 4e07b18ab33197a8e203fd2756e13b2a33c4e657 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 12 Dec 2024 17:15:52 -0800 Subject: [PATCH 045/190] WIP --- .github/workflows/reusable-test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index eed3ed794a..a5561de828 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -76,14 +76,14 @@ jobs: if: contains(inputs.environment, '1es') run: | pool_name=$(echo "${{ inputs.environment }}" | sed 's/.*1es-//') - echo "runs_on=self-hosted" >> "$GITHUB_OUTPUT" - echo "runs_on_pool=1ES.Pool=ebpf-cicd-runner-pool-$pool_name" >> "$GITHUB_OUTPUT" - + echo "pool_name=$pool_name" + echo "runs_on=self-hosted" >> $GITHUB_OUTPUT + echo "runs_on_pool=1ES.Pool=ebpf-cicd-runner-pool-$pool_name" >> $GITHUB_OUTPUT - name: Set runner type (github hosted) id: set_runner_github if: !contains(inputs.environment, '1es') run: | - echo "runs_on=${{ inputs.environment }}" >> "$GITHUB_OUTPUT" + echo "runs_on=${{ inputs.environment }}" >> $GITHUB_OUTPUT run_test: needs: set-job-environment # Due to app-verifier, unit tests take a lot longer to execute. Increase the timeout to 90 minutes. From 36900a9c1f7a9809fc1702749d21c4f7beddb363 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 09:52:08 -0800 Subject: [PATCH 046/190] WIP --- .github/workflows/cicd.yml | 6 ++- .github/workflows/reusable-test.yml | 71 ++++++++++++++++++----------- 2 files changed, 49 insertions(+), 28 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index d26fea180c..01719217f0 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -69,7 +69,7 @@ jobs: # Exclude [processes] test that CodeCoverage can't work with. test_command: .\unit_tests.exe -d yes ~[processes] build_artifact: Build-x64 - environment: windows-2022 + environment: [windows-2022] code_coverage: true gather_dumps: true capture_etw: true @@ -88,7 +88,9 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_ws2019 build_artifact: Build-x64 - environment: 1es-server-2019 + environment: [self-hosted, 1ES.Pool=ebpf-cicd-runner-pool-server-2019] + # - self-hosted + # - 1ES.Pool=ebpf-cicd-runner-pool-server-2019 # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index a5561de828..c63c91a156 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -22,7 +22,7 @@ on: # The environment to run this test on. environment: description: 'Environment to run tests on' - type: string + type: array required: true # Set to true to gather code coverage when this test runs. code_coverage: @@ -62,28 +62,41 @@ permissions: issues: write # Required to create issues. jobs: - set-job-environment: - # The following environments are supported: - # - Any of the github environments. - # - 1es-<RUNNER_POOL_NAME> (which matches ebpf-cicd-runner-pool-<RUNNER_POOL_NAME> in the 1es pool) - runs-on: ubuntu-latest - outputs: - runs_on: ${{ steps.set_runner_1es.outputs.runs_on || steps.set_runner_github.outputs.runs_on }} - runs_on_pool: ${{ steps.set_runner_1es.outputs.runs_on_pool || '' }} - steps: - - name: Set runner type (1es) - id: set_runner_1es - if: contains(inputs.environment, '1es') - run: | - pool_name=$(echo "${{ inputs.environment }}" | sed 's/.*1es-//') - echo "pool_name=$pool_name" - echo "runs_on=self-hosted" >> $GITHUB_OUTPUT - echo "runs_on_pool=1ES.Pool=ebpf-cicd-runner-pool-$pool_name" >> $GITHUB_OUTPUT - - name: Set runner type (github hosted) - id: set_runner_github - if: !contains(inputs.environment, '1es') - run: | - echo "runs_on=${{ inputs.environment }}" >> $GITHUB_OUTPUT + # set-job-environment: + # # The following environments are supported: + # # - Any of the github environments. + # # - 1es-<RUNNER_POOL_NAME> (which matches ebpf-cicd-runner-pool-<RUNNER_POOL_NAME> in the 1es pool) + # runs-on: ubuntu-latest + # outputs: + # runs_on: ${{ steps.set_runner_1es.outputs.runs_on || steps.set_runner_github.outputs.runs_on }} + # runs_on_pool: ${{ steps.set_runner_1es.outputs.runs_on_pool || '' }} + # steps: + # - name: Set 1es runner type + # id: set_runner_1es + # if: contains(inputs.environment, '1es') + # run: | + # pool_name=$(echo "${{ inputs.environment }}" | sed 's/.*1es-//') + # echo "pool_name=$pool_name" + # echo "runs_on=self-hosted" >> $GITHUB_OUTPUT + # echo "runs_on_pool=1ES.Pool=ebpf-cicd-runner-pool-$pool_name" >> $GITHUB_OUTPUT + # - name: Set github runner type + # id: set_runner_github + # if: !contains(inputs.environment, '1es') + # run: | + # echo "runs_on=${{ inputs.environment }}" >> $GITHUB_OUTPUT + +# jobs: +# build: +# runs-on: ${{ matrix.runner }} +# strategy: +# matrix: +# runner: [] +# include: +# - env: self-hosted +# runner: [self-hosted, 1ES.Pool=ebpf-cicd-runner-pool-server-2019] +# - env: windows +# runner: [windows-2022] + run_test: needs: set-job-environment # Due to app-verifier, unit tests take a lot longer to execute. Increase the timeout to 90 minutes. @@ -92,9 +105,15 @@ jobs: strategy: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: - - ${{ needs.set-job-environment.outputs.runs_on }} - - ${{ needs.set-job-environment.outputs.runs_on_pool }} + + runs-on: ${{ inputs.environment }} + # - ${{ needs.set-job-environment.outputs.runs_on }} + # - ${{ needs.set-job-environment.outputs.runs_on_pool }} + # runs-on: + # - self-hosted + # - 1ES.Pool=ebpf-cicd-runner-pool-server-2019 + # runs-on: + # - windows-2022 env: # Configuration type to build. SOURCE_ROOT: ${{github.workspace}} From 085aa1215870a46f64854cb58ceb05e5ad308e3f Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 10:10:25 -0800 Subject: [PATCH 047/190] WIP --- .github/workflows/cicd.yml | 7 +- .github/workflows/reusable-test.yml | 100 +++++++++++++++------------- 2 files changed, 58 insertions(+), 49 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 01719217f0..dcdbef10df 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -69,7 +69,7 @@ jobs: # Exclude [processes] test that CodeCoverage can't work with. test_command: .\unit_tests.exe -d yes ~[processes] build_artifact: Build-x64 - environment: [windows-2022] + environment: windows-2022 code_coverage: true gather_dumps: true capture_etw: true @@ -88,9 +88,8 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_ws2019 build_artifact: Build-x64 - environment: [self-hosted, 1ES.Pool=ebpf-cicd-runner-pool-server-2019] - # - self-hosted - # - 1ES.Pool=ebpf-cicd-runner-pool-server-2019 + environment: server-2019 + self-hosted-runner: true # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index c63c91a156..8487bcb799 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -22,8 +22,11 @@ on: # The environment to run this test on. environment: description: 'Environment to run tests on' - type: array + type: string required: true + self-hosted-runner: + type: boolean + required: false # Set to true to gather code coverage when this test runs. code_coverage: required: false @@ -62,43 +65,7 @@ permissions: issues: write # Required to create issues. jobs: - # set-job-environment: - # # The following environments are supported: - # # - Any of the github environments. - # # - 1es-<RUNNER_POOL_NAME> (which matches ebpf-cicd-runner-pool-<RUNNER_POOL_NAME> in the 1es pool) - # runs-on: ubuntu-latest - # outputs: - # runs_on: ${{ steps.set_runner_1es.outputs.runs_on || steps.set_runner_github.outputs.runs_on }} - # runs_on_pool: ${{ steps.set_runner_1es.outputs.runs_on_pool || '' }} - # steps: - # - name: Set 1es runner type - # id: set_runner_1es - # if: contains(inputs.environment, '1es') - # run: | - # pool_name=$(echo "${{ inputs.environment }}" | sed 's/.*1es-//') - # echo "pool_name=$pool_name" - # echo "runs_on=self-hosted" >> $GITHUB_OUTPUT - # echo "runs_on_pool=1ES.Pool=ebpf-cicd-runner-pool-$pool_name" >> $GITHUB_OUTPUT - # - name: Set github runner type - # id: set_runner_github - # if: !contains(inputs.environment, '1es') - # run: | - # echo "runs_on=${{ inputs.environment }}" >> $GITHUB_OUTPUT - -# jobs: -# build: -# runs-on: ${{ matrix.runner }} -# strategy: -# matrix: -# runner: [] -# include: -# - env: self-hosted -# runner: [self-hosted, 1ES.Pool=ebpf-cicd-runner-pool-server-2019] -# - env: windows -# runner: [windows-2022] - run_test: - needs: set-job-environment # Due to app-verifier, unit tests take a lot longer to execute. Increase the timeout to 90 minutes. timeout-minutes: 90 @@ -106,14 +73,7 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: ${{ inputs.environment }} - # - ${{ needs.set-job-environment.outputs.runs_on }} - # - ${{ needs.set-job-environment.outputs.runs_on_pool }} - # runs-on: - # - self-hosted - # - 1ES.Pool=ebpf-cicd-runner-pool-server-2019 - # runs-on: - # - windows-2022 + runs-on: ${{ (inputs.self-hosted-runner) && fromJSON('[ "self-hosted", " 1ES.Pool=ebpf-cicd-runner-pool-${{ inputs.environment }}"]') || ${{ inputs.environment }} }} env: # Configuration type to build. SOURCE_ROOT: ${{github.workspace}} @@ -579,3 +539,53 @@ jobs: body: body, labels: label_array, }); + + + + + + + # set-job-environment: + # # The following environments are supported: + # # - Any of the github environments. + # # - 1es-<RUNNER_POOL_NAME> (which matches ebpf-cicd-runner-pool-<RUNNER_POOL_NAME> in the 1es pool) + # runs-on: ubuntu-latest + # outputs: + # runs_on: ${{ steps.set_runner_1es.outputs.runs_on || steps.set_runner_github.outputs.runs_on }} + # runs_on_pool: ${{ steps.set_runner_1es.outputs.runs_on_pool || '' }} + # steps: + # - name: Set 1es runner type + # id: set_runner_1es + # if: contains(inputs.environment, '1es') + # run: | + # pool_name=$(echo "${{ inputs.environment }}" | sed 's/.*1es-//') + # echo "pool_name=$pool_name" + # echo "runs_on=self-hosted" >> $GITHUB_OUTPUT + # echo "runs_on_pool=1ES.Pool=ebpf-cicd-runner-pool-$pool_name" >> $GITHUB_OUTPUT + # - name: Set github runner type + # id: set_runner_github + # if: !contains(inputs.environment, '1es') + # run: | + # echo "runs_on=${{ inputs.environment }}" >> $GITHUB_OUTPUT + +# jobs: +# build: +# runs-on: ${{ matrix.runner }} +# strategy: +# matrix: +# runner: [] +# include: +# - env: self-hosted +# runner: [self-hosted, 1ES.Pool=ebpf-cicd-runner-pool-server-2019] +# - env: windows +# runner: [windows-2022] + + + # - ${{ needs.set-job-environment.outputs.runs_on }} + # - ${{ needs.set-job-environment.outputs.runs_on_pool }} + + # runs-on: + # - self-hosted + # - 1ES.Pool=ebpf-cicd-runner-pool-server-2019 + # runs-on: + # - windows-2022 \ No newline at end of file From 0e630a9f536d99ac8f712f5170aec7834f7ad305 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 10:17:24 -0800 Subject: [PATCH 048/190] WIP --- .github/workflows/reusable-test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 8487bcb799..f6213c44f5 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -73,7 +73,8 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: ${{ (inputs.self-hosted-runner) && fromJSON('[ "self-hosted", " 1ES.Pool=ebpf-cicd-runner-pool-${{ inputs.environment }}"]') || ${{ inputs.environment }} }} + runs-on: ${{ inputs.self-hosted-runner && fromJSON('["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-' + inputs.environment + '"]') || inputs.environment }} + env: # Configuration type to build. SOURCE_ROOT: ${{github.workspace}} From 3fbde1fac0485a8e580d484d2647229cbac9f06f Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 10:18:57 -0800 Subject: [PATCH 049/190] WIP --- .github/workflows/reusable-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index f6213c44f5..f468b2b2c2 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -73,7 +73,7 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: ${{ inputs.self-hosted-runner && fromJSON('["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-' + inputs.environment + '"]') || inputs.environment }} + runs-on: ${{ inputs.self-hosted-runner && fromJSON('["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-(inputs.environment)"]') || inputs.environment }} env: # Configuration type to build. From 666a268a6acc1091974ef744fd91dff751f044f7 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 10:49:19 -0800 Subject: [PATCH 050/190] WIP --- .github/workflows/reusable-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index f468b2b2c2..623e0aace2 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -73,7 +73,7 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: ${{ inputs.self-hosted-runner && fromJSON('["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-(inputs.environment)"]') || inputs.environment }} + runs-on: ${{ inputs.self-hosted-runner && fromJSON('["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool' + inputs.environment + '"]') || inputs.environment }} env: # Configuration type to build. From 128187848f84dd5f0742a25fdea185479f903553 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 10:58:08 -0800 Subject: [PATCH 051/190] WIP --- .github/workflows/reusable-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 623e0aace2..a755f804e9 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -73,7 +73,7 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: ${{ inputs.self-hosted-runner && fromJSON('["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool' + inputs.environment + '"]') || inputs.environment }} + runs-on: ${{ inputs.self-hosted-runner && fromJSON('["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool" + inputs.environment]') || inputs.environment }} env: # Configuration type to build. From 5901583d39cb9d9220187c74d58f2969e1fdb1da Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 11:23:02 -0800 Subject: [PATCH 052/190] WIP --- .github/workflows/reusable-test.yml | 72 +++++------------------------ 1 file changed, 11 insertions(+), 61 deletions(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index a755f804e9..5b97b46a0f 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -96,7 +96,7 @@ jobs: - name: Configure runner (Move to setup script directly later) id: configure-runner - if: contains(inputs.environment, '1es') + if: (inputs.self-hosted-runner) run: | powershell.exe "cd C:\bin\CloudTestWorker\ProvisioningScript; dir; .\Setup_orig.ps1" # powershell.exe "Get-NetAdapter" @@ -125,7 +125,7 @@ jobs: # Perform shallow checkout for self-hosted runner. - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - if: contains(inputs.environment, '1es') && (steps.skip_check.outputs.should_skip != 'true') + if: (inputs.self-hosted-runner) && (steps.skip_check.outputs.should_skip != 'true') with: ref: ${{ github.event.workflow_run.head_branch }} @@ -174,7 +174,7 @@ jobs: - name: Set up OpenCppCoverage and add to PATH id: set_up_opencppcoverage - if: (inputs.code_coverage == true) && !contains(inputs.environment, '1es') && (steps.skip_check.outputs.should_skip != 'true') + if: (inputs.code_coverage == true) && !(inputs.self-hosted-runner) && (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 @@ -191,7 +191,7 @@ jobs: 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: contains(inputs.environment, '1es') && (steps.skip_check.outputs.should_skip != 'true') + if: (inputs.self-hosted-runner) && (steps.skip_check.outputs.should_skip != 'true') run: | Remove-Item -Path ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}} -Recurse -Force -ErrorAction SilentlyContinue @@ -248,14 +248,14 @@ jobs: .\export_program_info_sample.exe - name: Run pre test command - if: steps.skip_check.outputs.should_skip != 'true' && !contains(inputs.environment, '1es') + if: steps.skip_check.outputs.should_skip != 'true' && !(inputs.self-hosted-runner) id: run_pre_test_command working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | ${{env.PRE_COMMAND}} - name: Run pre test command on self-hosted runner - if: steps.skip_check.outputs.should_skip != 'true' && contains(inputs.environment, '1es') + if: steps.skip_check.outputs.should_skip != 'true' && (inputs.self-hosted-runner) id: run_pre_test_command_self_hosted working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | @@ -297,14 +297,14 @@ jobs: 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 on self-hosted runner - if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && contains(inputs.environment, '1es') && (inputs.fault_injection != true) + if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && (inputs.self-hosted-runner) && (inputs.fault_injection != true) id: run_test_self_hosted working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | ${{env.TEST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} - name: Run test without Code Coverage - if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && contains(inputs.environment, '1es') && (inputs.fault_injection != true) + if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && (inputs.self-hosted-runner) && (inputs.fault_injection != true) id: run_test_without_code_coverage working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} shell: cmd @@ -314,7 +314,7 @@ jobs: - 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') && contains(inputs.environment, '1es') + if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && (inputs.self-hosted-runner) id: run_post_test_command working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | @@ -322,7 +322,7 @@ jobs: - name: Run post test command on self-hosted runner # Run the post test command even if the workflow has failed. - if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && contains(inputs.environment, '1es') + if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && (inputs.self-hosted-runner) id: run_post_test_command_self_hosted working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | @@ -539,54 +539,4 @@ jobs: title: title, body: body, labels: label_array, - }); - - - - - - - # set-job-environment: - # # The following environments are supported: - # # - Any of the github environments. - # # - 1es-<RUNNER_POOL_NAME> (which matches ebpf-cicd-runner-pool-<RUNNER_POOL_NAME> in the 1es pool) - # runs-on: ubuntu-latest - # outputs: - # runs_on: ${{ steps.set_runner_1es.outputs.runs_on || steps.set_runner_github.outputs.runs_on }} - # runs_on_pool: ${{ steps.set_runner_1es.outputs.runs_on_pool || '' }} - # steps: - # - name: Set 1es runner type - # id: set_runner_1es - # if: contains(inputs.environment, '1es') - # run: | - # pool_name=$(echo "${{ inputs.environment }}" | sed 's/.*1es-//') - # echo "pool_name=$pool_name" - # echo "runs_on=self-hosted" >> $GITHUB_OUTPUT - # echo "runs_on_pool=1ES.Pool=ebpf-cicd-runner-pool-$pool_name" >> $GITHUB_OUTPUT - # - name: Set github runner type - # id: set_runner_github - # if: !contains(inputs.environment, '1es') - # run: | - # echo "runs_on=${{ inputs.environment }}" >> $GITHUB_OUTPUT - -# jobs: -# build: -# runs-on: ${{ matrix.runner }} -# strategy: -# matrix: -# runner: [] -# include: -# - env: self-hosted -# runner: [self-hosted, 1ES.Pool=ebpf-cicd-runner-pool-server-2019] -# - env: windows -# runner: [windows-2022] - - - # - ${{ needs.set-job-environment.outputs.runs_on }} - # - ${{ needs.set-job-environment.outputs.runs_on_pool }} - - # runs-on: - # - self-hosted - # - 1ES.Pool=ebpf-cicd-runner-pool-server-2019 - # runs-on: - # - windows-2022 \ No newline at end of file + }); \ No newline at end of file From e4674876144d28ae306c30346ab7e0f0f807ef3d Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 13:27:12 -0800 Subject: [PATCH 053/190] WIP --- .github/workflows/reusable-test.yml | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 5b97b46a0f..399316a41f 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -89,6 +89,11 @@ jobs: TEST_TIMEOUT: 3600 # 1 hour timeout for tests. steps: + - name: Log runson + run: | + echo "Running on ${{input.environment}} + echo "" + - name: Harden Runner uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: @@ -96,7 +101,7 @@ jobs: - name: Configure runner (Move to setup script directly later) id: configure-runner - if: (inputs.self-hosted-runner) + if: (inputs.self-hosted-runner == true) run: | powershell.exe "cd C:\bin\CloudTestWorker\ProvisioningScript; dir; .\Setup_orig.ps1" # powershell.exe "Get-NetAdapter" @@ -125,7 +130,7 @@ jobs: # Perform shallow checkout for self-hosted runner. - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - if: (inputs.self-hosted-runner) && (steps.skip_check.outputs.should_skip != 'true') + if: (inputs.self-hosted-runner == true) && (steps.skip_check.outputs.should_skip != 'true') with: ref: ${{ github.event.workflow_run.head_branch }} @@ -174,7 +179,7 @@ jobs: - name: Set up OpenCppCoverage and add to PATH id: set_up_opencppcoverage - if: (inputs.code_coverage == true) && !(inputs.self-hosted-runner) && (steps.skip_check.outputs.should_skip != 'true') + if: (inputs.code_coverage == true) && (inputs.self-hosted-runner != true) && (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 @@ -191,7 +196,7 @@ jobs: 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.self-hosted-runner) && (steps.skip_check.outputs.should_skip != 'true') + if: (inputs.self-hosted-runner == true) && (steps.skip_check.outputs.should_skip != 'true') run: | Remove-Item -Path ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}} -Recurse -Force -ErrorAction SilentlyContinue @@ -248,14 +253,14 @@ jobs: .\export_program_info_sample.exe - name: Run pre test command - if: steps.skip_check.outputs.should_skip != 'true' && !(inputs.self-hosted-runner) + if: steps.skip_check.outputs.should_skip != 'true' && (inputs.self-hosted-runner != true) id: run_pre_test_command working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | ${{env.PRE_COMMAND}} - name: Run pre test command on self-hosted runner - if: steps.skip_check.outputs.should_skip != 'true' && (inputs.self-hosted-runner) + if: steps.skip_check.outputs.should_skip != 'true' && (inputs.self-hosted-runner == true) id: run_pre_test_command_self_hosted working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | @@ -297,14 +302,14 @@ jobs: 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 on self-hosted runner - if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && (inputs.self-hosted-runner) && (inputs.fault_injection != true) + if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && (inputs.self-hosted-runner == true) && (inputs.fault_injection != true) id: run_test_self_hosted working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | ${{env.TEST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} - name: Run test without Code Coverage - if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && (inputs.self-hosted-runner) && (inputs.fault_injection != true) + if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && (inputs.self-hosted-runner == true) && (inputs.fault_injection != true) id: run_test_without_code_coverage working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} shell: cmd @@ -314,7 +319,7 @@ jobs: - 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.self-hosted-runner) + if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && (inputs.self-hosted-runner == true) id: run_post_test_command working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | @@ -322,7 +327,7 @@ jobs: - name: Run post test command on self-hosted runner # Run the post test command even if the workflow has failed. - if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && (inputs.self-hosted-runner) + if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && (inputs.self-hosted-runner == true) id: run_post_test_command_self_hosted working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | From 051c178bfee9548806a6efa82c265c45d44235dc Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 13:28:45 -0800 Subject: [PATCH 054/190] WIP --- .github/workflows/reusable-test.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 399316a41f..cf61225711 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -89,11 +89,6 @@ jobs: TEST_TIMEOUT: 3600 # 1 hour timeout for tests. steps: - - name: Log runson - run: | - echo "Running on ${{input.environment}} - echo "" - - name: Harden Runner uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2 with: From 7501226bbbc54b882be3525e9e9cad84d783a537 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 13:29:40 -0800 Subject: [PATCH 055/190] WIP --- .github/workflows/reusable-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index cf61225711..725d7fbb67 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -73,7 +73,7 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: ${{ inputs.self-hosted-runner && fromJSON('["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool" + inputs.environment]') || inputs.environment }} + runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool" + inputs.environment]') || inputs.environment }} env: # Configuration type to build. From 6adcb6471cdb31cbab526381bc06af091b87caec Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 14:46:18 -0800 Subject: [PATCH 056/190] WIP --- .github/workflows/cicd.yml | 2 +- .github/workflows/reusable-test.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index dcdbef10df..647444ac92 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -88,7 +88,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_ws2019 build_artifact: Build-x64 - environment: server-2019 + environment: 1ES.Pool=ebpf-cicd-runner-pool-server-2019 self-hosted-runner: true # driver test copies dumps to testlog folder. gather_dumps: false diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 725d7fbb67..43cc86eb4d 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -73,7 +73,7 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool" + inputs.environment]') || inputs.environment }} + runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", inputs.environment]') || inputs.environment }} env: # Configuration type to build. From 7038eb801848ab5106471e27b181adce5aa46a01 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 15:21:42 -0800 Subject: [PATCH 057/190] WIP --- .github/workflows/cicd.yml | 30 ++++++++++++++--------------- .github/workflows/reusable-test.yml | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 647444ac92..7a727178e8 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -43,24 +43,24 @@ jobs: # --------------------------------------------------------------------------- # Perform the regular build. - regular: - # Always run this job. - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-build.yml - with: - ref: ${{ github.ref }} - repository: ${{ github.repository }} - build_artifact: Build-x64 - generate_release_package: true - build_msi: true - build_nuget: true - build_options: /p:ReleaseJIT='True' - configurations: '["Debug", "Release"]' + # regular: + # # Always run this job. + # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-build.yml + # with: + # ref: ${{ github.ref }} + # repository: ${{ github.repository }} + # build_artifact: Build-x64 + # generate_release_package: true + # build_msi: true + # build_nuget: true + # build_options: /p:ReleaseJIT='True' + # configurations: '["Debug", "Release"]' # Run the unit tests in GitHub. unit_tests: # Always run this job. - needs: regular + # needs: regular if: github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' uses: ./.github/workflows/reusable-test.yml with: @@ -79,7 +79,7 @@ jobs: driver_ws2019: # Always run this job. # Only run this on repos that have self-host runners. - needs: regular + # needs: regular if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') uses: ./.github/workflows/reusable-test.yml with: diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 43cc86eb4d..13f638699b 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -73,7 +73,7 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", inputs.environment]') || inputs.environment }} + runs-on: ${{ ((inputs.self-hosted-runner == true) && fromJSON('["self-hosted", inputs.environment]')) || inputs.environment }} env: # Configuration type to build. From dbaad888e64bfc51d13a2523e9f00e6e0f506e3f Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 15:25:41 -0800 Subject: [PATCH 058/190] WIP --- .github/workflows/reusable-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 13f638699b..2593db1ce3 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -73,7 +73,7 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: ${{ ((inputs.self-hosted-runner == true) && fromJSON('["self-hosted", inputs.environment]')) || inputs.environment }} + runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019"]') || inputs.environment }} env: # Configuration type to build. From af0066f6ef5a3d9b1c47286c124da1dc7a7453a0 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 15:26:57 -0800 Subject: [PATCH 059/190] WIP --- .github/workflows/reusable-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 2593db1ce3..15f3d6e387 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -73,7 +73,7 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019"]') || inputs.environment }} + runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", "inputs.environment"]') || inputs.environment }} env: # Configuration type to build. From 7c30abcfa46ce9026564ccbf52ed66135885ab71 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 15:28:23 -0800 Subject: [PATCH 060/190] WIP --- .github/workflows/reusable-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 15f3d6e387..43cc86eb4d 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -73,7 +73,7 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", "inputs.environment"]') || inputs.environment }} + runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", inputs.environment]') || inputs.environment }} env: # Configuration type to build. From e239ec8208a9b4657589e7f927c4113fce4c592d Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 15:29:29 -0800 Subject: [PATCH 061/190] WIP --- .github/workflows/cicd.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 7a727178e8..19f5641472 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -88,7 +88,8 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_ws2019 build_artifact: Build-x64 - environment: 1ES.Pool=ebpf-cicd-runner-pool-server-2019 + # environment: 1ES.Pool=ebpf-cicd-runner-pool-server-2019 + environment: '1ES.Pool=ebpf-cicd-runner-pool-server-2019' self-hosted-runner: true # driver test copies dumps to testlog folder. gather_dumps: false From f8146f13d373d068c99b56fa238baee3469f56b9 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 15:30:52 -0800 Subject: [PATCH 062/190] WIP --- .github/workflows/reusable-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 43cc86eb4d..9deb2d0c2f 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -73,7 +73,7 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", inputs.environment]') || inputs.environment }} + runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", ${{ inputs.environment }} ]') || inputs.environment }} env: # Configuration type to build. From 7a7cb83ca14fa1318d9cda2dc7f45e20b6227028 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 15:32:07 -0800 Subject: [PATCH 063/190] WIP --- .github/workflows/cicd.yml | 2 +- .github/workflows/reusable-test.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 19f5641472..3dbcaf8722 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -89,7 +89,7 @@ jobs: name: driver_ws2019 build_artifact: Build-x64 # environment: 1ES.Pool=ebpf-cicd-runner-pool-server-2019 - environment: '1ES.Pool=ebpf-cicd-runner-pool-server-2019' + environment: 1ES.Pool=ebpf-cicd-runner-pool-server-2019 self-hosted-runner: true # driver test copies dumps to testlog folder. gather_dumps: false diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 9deb2d0c2f..c09b639d6f 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -73,7 +73,7 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", ${{ inputs.environment }} ]') || inputs.environment }} + runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", "${{ inputs.environment }}" ]') || inputs.environment }} env: # Configuration type to build. From 4926ab73142a9e16e6188bde43c02d5d452a5461 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 15:33:42 -0800 Subject: [PATCH 064/190] WIP --- .github/workflows/reusable-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index c09b639d6f..7d4ef187ce 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -73,7 +73,7 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", "${{ inputs.environment }}" ]') || inputs.environment }} + runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", " 1ES.Pool=ebpf-cicd-runner-pool-" + ${{ inputs.environment }} ]') || inputs.environment }} env: # Configuration type to build. From 179fcfd88761629f22bc7f0c6c5c89b20b1753c6 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 15:34:40 -0800 Subject: [PATCH 065/190] WIP --- .github/workflows/reusable-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 7d4ef187ce..2c71368403 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -73,7 +73,7 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", " 1ES.Pool=ebpf-cicd-runner-pool-" + ${{ inputs.environment }} ]') || inputs.environment }} + runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", " 1ES.Pool=ebpf-cicd-runner-pool-" + ${ inputs.environment } ]') || inputs.environment }} env: # Configuration type to build. From 070f0c26c84c787abed1cc5ae66ce06142884063 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 15:35:25 -0800 Subject: [PATCH 066/190] WIP --- .github/workflows/reusable-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 2c71368403..345b153e41 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -73,7 +73,7 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", " 1ES.Pool=ebpf-cicd-runner-pool-" + ${ inputs.environment } ]') || inputs.environment }} + runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", " 1ES.Pool=ebpf-cicd-runner-pool-"${{ inputs.environment }} ]') || inputs.environment }} env: # Configuration type to build. From f498cdde797208feaccd229f62addfd10adec553 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 15:37:15 -0800 Subject: [PATCH 067/190] WIP --- .github/workflows/reusable-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 345b153e41..7f9ceb6977 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -73,7 +73,7 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", " 1ES.Pool=ebpf-cicd-runner-pool-"${{ inputs.environment }} ]') || inputs.environment }} + runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-"inputs.environment ]') || inputs.environment }} env: # Configuration type to build. From 29fd7eef4f2e222f568fcac1fe1bbc213065d85e Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 15:42:11 -0800 Subject: [PATCH 068/190] WIP --- .github/workflows/reusable-test.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 7f9ceb6977..62f4d85ecb 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -73,8 +73,6 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-"inputs.environment ]') || inputs.environment }} - env: # Configuration type to build. SOURCE_ROOT: ${{github.workspace}} @@ -87,6 +85,10 @@ jobs: CXPLAT_MEMORY_LEAK_DETECTION: ${{inputs.leak_detection}} DUMP_PATH: c:/dumps/x64/${{matrix.configurations}} TEST_TIMEOUT: 3600 # 1 hour timeout for tests. + 1ES_POOL: fromJSON('["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-" + ${{inputs.environment}} ]') + + # runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-"inputs.environment ]') || inputs.environment }} + runs-on: ${{ (inputs.self-hosted-runner == true) && env.1ES_POOL || inputs.environment }} steps: - name: Harden Runner From caaebc5004a98af8d264d2cebdc2309f845d8f6a Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 15:45:55 -0800 Subject: [PATCH 069/190] WIP --- .github/workflows/cicd.yml | 6 ++++++ .github/workflows/reusable-test.yml | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 3dbcaf8722..25834c9ac3 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -70,6 +70,8 @@ jobs: test_command: .\unit_tests.exe -d yes ~[processes] build_artifact: Build-x64 environment: windows-2022 + # environment2: windows-2022 + environment2: '["windows-2022"]' code_coverage: true gather_dumps: true capture_etw: true @@ -90,6 +92,10 @@ jobs: build_artifact: Build-x64 # environment: 1ES.Pool=ebpf-cicd-runner-pool-server-2019 environment: 1ES.Pool=ebpf-cicd-runner-pool-server-2019 + environment2: '["self-host", "1ES.Pool=ebpf-cicd-runner-pool-server-2019"]' + + # configurations: '["Debug", "Release"]' + self-hosted-runner: true # driver test copies dumps to testlog folder. gather_dumps: false diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 62f4d85ecb..009cbfcd99 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -24,6 +24,10 @@ on: description: 'Environment to run tests on' type: string required: true + environment2: + description: 'Environment to run tests on' + type: string + required: true self-hosted-runner: type: boolean required: false @@ -73,6 +77,8 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} + runs-on: ${{ fromJSON(inputs.environment2) }} + env: # Configuration type to build. SOURCE_ROOT: ${{github.workspace}} @@ -88,7 +94,7 @@ jobs: 1ES_POOL: fromJSON('["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-" + ${{inputs.environment}} ]') # runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-"inputs.environment ]') || inputs.environment }} - runs-on: ${{ (inputs.self-hosted-runner == true) && env.1ES_POOL || inputs.environment }} + # runs-on: ${{ (inputs.self-hosted-runner == true) && env.1ES_POOL || inputs.environment }} steps: - name: Harden Runner From 9eec83ed91b341f52a255bef46ea80f40c4344e9 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 15:47:24 -0800 Subject: [PATCH 070/190] WIP --- .github/workflows/cicd.yml | 41 ++++++++++++----------------- .github/workflows/reusable-test.yml | 6 +---- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 25834c9ac3..75c66743d8 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -43,24 +43,24 @@ jobs: # --------------------------------------------------------------------------- # Perform the regular build. - # regular: - # # Always run this job. - # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-build.yml - # with: - # ref: ${{ github.ref }} - # repository: ${{ github.repository }} - # build_artifact: Build-x64 - # generate_release_package: true - # build_msi: true - # build_nuget: true - # build_options: /p:ReleaseJIT='True' - # configurations: '["Debug", "Release"]' + regular: + # Always run this job. + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-build.yml + with: + ref: ${{ github.ref }} + repository: ${{ github.repository }} + build_artifact: Build-x64 + generate_release_package: true + build_msi: true + build_nuget: true + build_options: /p:ReleaseJIT='True' + configurations: '["Debug", "Release"]' # Run the unit tests in GitHub. unit_tests: # Always run this job. - # needs: regular + needs: regular if: github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' uses: ./.github/workflows/reusable-test.yml with: @@ -69,9 +69,7 @@ jobs: # Exclude [processes] test that CodeCoverage can't work with. test_command: .\unit_tests.exe -d yes ~[processes] build_artifact: Build-x64 - environment: windows-2022 - # environment2: windows-2022 - environment2: '["windows-2022"]' + environment: '["windows-2022"]' code_coverage: true gather_dumps: true capture_etw: true @@ -81,7 +79,7 @@ jobs: driver_ws2019: # Always run this job. # Only run this on repos that have self-host runners. - # needs: regular + needs: regular if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') uses: ./.github/workflows/reusable-test.yml with: @@ -90,12 +88,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_ws2019 build_artifact: Build-x64 - # environment: 1ES.Pool=ebpf-cicd-runner-pool-server-2019 - environment: 1ES.Pool=ebpf-cicd-runner-pool-server-2019 - environment2: '["self-host", "1ES.Pool=ebpf-cicd-runner-pool-server-2019"]' - - # configurations: '["Debug", "Release"]' - + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019"]' self-hosted-runner: true # driver test copies dumps to testlog folder. gather_dumps: false diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 009cbfcd99..b9b724022b 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -77,7 +77,7 @@ jobs: matrix: configurations: ${{ fromJSON(inputs.configurations) }} - runs-on: ${{ fromJSON(inputs.environment2) }} + runs-on: ${{ fromJSON(inputs.environment) }} env: # Configuration type to build. @@ -91,10 +91,6 @@ jobs: CXPLAT_MEMORY_LEAK_DETECTION: ${{inputs.leak_detection}} DUMP_PATH: c:/dumps/x64/${{matrix.configurations}} TEST_TIMEOUT: 3600 # 1 hour timeout for tests. - 1ES_POOL: fromJSON('["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-" + ${{inputs.environment}} ]') - - # runs-on: ${{ (inputs.self-hosted-runner == true) && fromJSON('["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-"inputs.environment ]') || inputs.environment }} - # runs-on: ${{ (inputs.self-hosted-runner == true) && env.1ES_POOL || inputs.environment }} steps: - name: Harden Runner From 061bcab563d5ffe1175400ed406b8c6f90abfa4e Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 15:50:06 -0800 Subject: [PATCH 071/190] WIP --- .github/workflows/reusable-test.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index b9b724022b..38a459d56e 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -24,10 +24,6 @@ on: description: 'Environment to run tests on' type: string required: true - environment2: - description: 'Environment to run tests on' - type: string - required: true self-hosted-runner: type: boolean required: false From 6f7db553e440b60e2c3529838f5fd8526dfa7a7b Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 16:43:41 -0800 Subject: [PATCH 072/190] add back in all tests to see what breaks --- .github/workflows/cicd.yml | 564 +++++++++++++++++++++++++++- .github/workflows/reusable-test.yml | 23 +- 2 files changed, 571 insertions(+), 16 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 75c66743d8..ec1c808786 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -55,7 +55,58 @@ jobs: build_msi: true build_nuget: true build_options: /p:ReleaseJIT='True' - configurations: '["Debug", "Release"]' + configurations: '["Debug", "FuzzerDebug", "Release"]' + + onebranch: + strategy: + matrix: + Architecture: ['x64', 'ARM64'] + # Always run this job. + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-build.yml + with: + ref: ${{ github.ref }} + repository: ${{ github.repository }} + build_artifact: Build-${{ matrix.Architecture }}-onebranch + generate_release_package: true + build_msi: true + build_nuget: true + configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' + build_options: /p:BuildOneBranch='True' /t:tools\onebranch /t:installer\ebpf-for-windows + solution_file: "ebpf-for-windows.sln" + architecture: ${{ matrix.Architecture }} + download_demo_repository: false + + # Perform the native-only build. + regular_native-only: + # Always run this job. + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-build.yml + with: + ref: ${{ github.ref }} + repository: ${{ github.repository }} + build_artifact: Build-x64-native-only + build_msi: true + build_nuget: true + configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' + + # Run the unit tests in GitHub. + unit_tests_appverif: + # Always run this job. + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: unit_tests + pre_test: appverif -enable Exceptions Handles Heaps Leak Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe + # Exclude [processes] test that CodeCoverage can't work with. + test_command: .\unit_tests.exe -d yes ~[processes] + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: true + gather_dumps: true + capture_etw: true + leak_detection: true # Run the unit tests in GitHub. unit_tests: @@ -75,6 +126,74 @@ jobs: capture_etw: true leak_detection: true + # Run the unit tests for NativeOnly build in GitHub. + unit_tests_native_only: + # Always run this job. + needs: regular_native-only + uses: ./.github/workflows/reusable-test.yml + with: + name: unit_tests + pre_test: appverif -enable Exceptions Handles Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe + # Exclude [processes] test that CodeCoverage can't work with. + test_command: .\unit_tests.exe -d yes ~[processes] + build_artifact: Build-x64-native-only + environment: '["windows-2022"]' + code_coverage: true + gather_dumps: true + capture_etw: true + leak_detection: true + configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' + + # Run the netebpfext unit tests in GitHub. + netebpf_ext_unit_tests: + # Always run this job. + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: netebpf_ext_unit_tests + pre_test: appverif -enable Exceptions Handles Heaps Leak Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe + test_command: .\netebpfext_unit.exe -d yes + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: true + gather_dumps: true + capture_etw: true + leak_detection: true + + # Run the bpf2c tests in GitHub. + bpf2c: + # Always run this job. + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + test_command: .\bpf2c_tests.exe -d yes + name: bpf2c + build_artifact: Build-x64 + environment: '["windows-2022"]' + vs_dev: true + code_coverage: true + gather_dumps: true + capture_etw: true + + # Run the bpf2c conformance tests in GitHub. + bpf2c_conformance: + # Always run this job. + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + pre_test: Invoke-WebRequest https://github.com/Alan-Jowett/bpf_conformance/releases/download/v0.0.6/bpf_conformance_runner.exe -OutFile bpf_conformance_runner.exe + test_command: .\bpf_conformance_runner.exe --test_file_directory %SOURCE_ROOT%\external\ebpf-verifier\external\bpf_conformance\tests --cpu_version v4 --plugin_path bpf2c_plugin.exe --debug true --plugin_options "--include %SOURCE_ROOT%\include" + name: bpf2c_conformance + build_artifact: Build-x64 + environment: '["windows-2022"]' + vs_dev: true + code_coverage: true + gather_dumps: true + capture_etw: true + # Run the driver tests on self-hosted runners. driver_ws2019: # Always run this job. @@ -89,8 +208,447 @@ jobs: name: driver_ws2019 build_artifact: Build-x64 environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019"]' - self-hosted-runner: true # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage - code_coverage: false \ No newline at end of file + code_coverage: false + + # Run the driver tests on self-hosted runners. + driver_ws2022: + # Always run this job. + # Only run this on repos that have self-host runners. + needs: regular + if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') + uses: ./.github/workflows/reusable-test.yml + with: + pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" + test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" + post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + name: driver_ws2022 + build_artifact: Build-x64 + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2022"]' + # driver test copies dumps to testlog folder. + gather_dumps: false + # driver tests manually gather code coverage + code_coverage: false + + # Run the native-only driver tests on self-hosted runners. + driver_native_only_ws2019: + # Always run this job. + # Only run this on repos that have self-host runners. + needs: regular_native-only + if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') + uses: ./.github/workflows/reusable-test.yml + with: + pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" + test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" + post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + name: driver_native_only_ws2019 + build_artifact: Build-x64-native-only + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019"]' + # driver test copies dumps to testlog folder. + gather_dumps: false + # driver tests manually gather code coverage + code_coverage: false + configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' + + driver_native_only_ws2022: + # Always run this job. + # Only run this on repos that have self-host runners. + needs: regular_native-only + if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') + uses: ./.github/workflows/reusable-test.yml + with: + pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" + test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" + post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + name: driver_native_only_ws2022 + build_artifact: Build-x64-native-only + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2022"]' + # driver test copies dumps to testlog folder. + gather_dumps: false + # driver tests manually gather code coverage + code_coverage: false + configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' + + # Run the regression driver tests on self-hosted runners (only for 2022). + regression_driver_ws2022: + # Always run this job. + # Only run this on repos that have self-host runners. + needs: regular + if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') + uses: ./.github/workflows/reusable-test.yml + with: + pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" -TestMode "Regression" -RegressionArtifactsVersion "0.17.0" + test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Regression" + post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + name: regression_driver_ws2022 + build_artifact: Build-x64 + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2022"]' + # driver test copies dumps to testlog folder. + gather_dumps: false + # driver tests manually gather code coverage + code_coverage: false + + ossar: + # Always run this job. + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/ossar-scan.yml + with: + build_artifact: Build-x64 + + # Additional jobs to run on pull and schedule only (skip push). + # --------------------------------------------------------------------------- + # Build with C++ static analyzer. + analyze: + # Only run on schedule and pull request. + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-build.yml + with: + ref: ${{ github.ref }} + repository: ${{ github.repository }} + build_artifact: Build-x64-Analyze + # Analysis on external projects is conditional, as on small CI/CD VMs the compiler can run OOM + build_options: /p:Analysis='True' /p:AnalysisOnExternal='False' + + # Build with C++ address sanitizer. + sanitize: + # Only run on schedule and pull request. + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-build.yml + with: + ref: ${{ github.ref }} + repository: ${{ github.repository }} + build_artifact: Build-x64-Sanitize + build_options: /p:AddressSanitizer='True' + + bpf2c_fuzzer: + needs: regular + if: github.event_name == 'pull_request' || github.event_name == 'merge_group' + uses: ./.github/workflows/reusable-test.yml + with: + name: bpf2c_fuzzer + test_command: .\bpf2c_fuzzer.exe bpf2c_fuzzer_corpus -use_value_profile=1 -max_total_time=300 -artifact_prefix=Artifacts\ + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + gather_dumps: true + configurations: '["FuzzerDebug"]' + + bpf2c_fuzzer_scheduled: + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: bpf2c_fuzzer + test_command: .\bpf2c_fuzzer.exe bpf2c_fuzzer_corpus -use_value_profile=1 -max_total_time=900 -artifact_prefix=Artifacts\ + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + gather_dumps: true + configurations: '["FuzzerDebug"]' + + execution_context_fuzzer: + needs: regular + # Always run this job. + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: execution_context_fuzzer + test_command: .\execution_context_fuzzer.exe execution_context_fuzzer_corpus -use_value_profile=1 -runs=3000 -artifact_prefix=Artifacts\ + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + gather_dumps: true + configurations: '["FuzzerDebug"]' + + # Run the verifier fuzzer. + verifier_fuzzer: + needs: regular + # Always run this job. + if: github.event_name == 'pull_request' || github.event_name == 'merge_group' + uses: ./.github/workflows/reusable-test.yml + with: + name: verifier_fuzzer + test_command: .\verifier_fuzzer.exe verifier_corpus -use_value_profile=1 -max_total_time=300 -artifact_prefix=Artifacts\ + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + gather_dumps: true + configurations: '["FuzzerDebug"]' + + verifier_fuzzer_scheduled: + needs: regular + # Always run this job. + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: verifier_fuzzer + test_command: .\verifier_fuzzer.exe verifier_corpus -use_value_profile=1 -max_total_time=900 -artifact_prefix=Artifacts\ + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + gather_dumps: true + configurations: '["FuzzerDebug"]' + + core_helper_fuzzer: + needs: regular + # Always run this job. + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: core_helper_fuzzer + test_command: .\core_helper_fuzzer core_helper_corpus -max_len=139 -runs=1000 -use_value_profile=1 -artifact_prefix=Artifacts\ + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + gather_dumps: true + configurations: '["FuzzerDebug"]' + + netebpfext_fuzzer: + needs: regular + # Always run this job. + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: netebpfext_fuzzer + test_command: .\netebpfext_fuzzer netebpfext_corpus -max_len=12 -runs=1000 -use_value_profile=1 -artifact_prefix=Artifacts\ + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + gather_dumps: true + configurations: '["FuzzerDebug"]' + + # Run Cilium regression tests in GitHub. + cilium_tests: + needs: regular + # Only run on schedule and pull request. + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: cilium_tests + test_command: .\cilium_tests.exe -d yes + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + gather_dumps: true + + # Run the quick stress tests in GitHub. + stress: + needs: regular + # Only run on schedule and pull request. + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: stress + # Until there is a dedicated stress test, re-use the perf test. + test_command: .\ebpf_performance.exe -d yes + build_artifact: Build-x64 + environment: '["windows-2022"]' + # No code coverage on stress. + code_coverage: false + gather_dumps: true + + # Run the unit tests in GitHub with address sanitizer. + sanitize_unit_tests: + needs: sanitize + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: unit_tests + # Exclude [processes] test that ASAN can't work with. + test_command: .\unit_tests.exe -d yes ~[processes] + build_artifact: Build-x64-Sanitize + environment: '["windows-2022"]' + code_coverage: false + gather_dumps: true + capture_etw: true + + # Run the fault injection simulator in GitHub. + fault_injection: + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: fault_injection + test_command: .\unit_tests.exe + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: true + gather_dumps: true + fault_injection: true + leak_detection: true + + # Run the low memory simulator for netebpfext_unit tests. + fault_injection_netebpfext_unit: + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: netebpfext_fault_injection + test_command: .\netebpfext_unit.exe + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: true + gather_dumps: true + fault_injection: true + leak_detection: true + + # Run a fast multi-threaded stress test pass against the usersim user-mode 'mock' framework. + # Added as a 'per-PR' test to catch usersim regressions and/or run-time usage issues. + quick_user_mode_multi_threaded_stress_test: + needs: regular + if: github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' + uses: ./.github/workflows/reusable-test.yml + with: + name: quick_user_mode_multi_threaded_stress + test_command: .\ebpf_stress_tests_um -tt=8 -td=2 + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + leak_detection: false + gather_dumps: true + capture_etw: true + + # Additional jobs to run on a schedule only (skip push and pull request). + # --------------------------------------------------------------------------- + codeql: + # Only run during daily scheduled run + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-build.yml + with: + ref: ${{ github.ref }} + repository: ${{ github.repository }} + build_artifact: Build-x64-CodeQl + build_codeql: true + + + # Run the complete fault injection simulator in GitHub. + # Runs on a schedule as this takes a long time to run. + fault_injection_full: + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: fault_injection_full + test_command: .\unit_tests.exe + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + gather_dumps: true + fault_injection: true + leak_detection: true + + # Run the complete fault injection simulator for netebpfext in GitHub. + # Runs on a schedule as this takes a long time to run. + netebpfext_fault_injection_full: + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: netebpfext_fault_injection_full + test_command: .\netebpfext_unit.exe + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + gather_dumps: true + fault_injection: true + + # Run multi-threaded stress tests against the user mode 'mock' framework. + user_mode_multi_threaded_stress_test: + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: user_mode_multi_threaded_stress + test_command: .\ebpf_stress_tests_um -tt=8 -td=10 + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + leak_detection: false + gather_dumps: true + capture_etw: true + + # Run multi-threaded stress tests with 'restart extension' disabled (default behavior) + # against the kernel mode eBPF sub-system. + km_mt_stress_tests: + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: km_mt_stress_tests + pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "memory" + test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Stress" + post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + build_artifact: Build-x64 + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019"]' + code_coverage: false + # For this test, we only want kernel mode dumps and not user mode dumps. + gather_dumps: false + + # Run multi-threaded stress tests with 'restart extension' enabled + # against the kernel mode eBPF sub-system. + km_mt_stress_tests_restart_extension: + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: km_mt_stress_tests_restart_extension + pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "memory" + test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Stress" -Options @("RestartExtension") + post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + build_artifact: Build-x64 + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019"]' + code_coverage: false + # For this test, we only want kernel mode dumps and not user mode dumps. + gather_dumps: false + + # Not sure what perf is - probably selfhosted runner, but do we need to support this now? + # performance: + # needs: regular + # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: km_performance + # pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" + # test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Performance" + # post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + # build_artifact: Build-x64 + # environment: ebpf_cicd_perf_ws2022 + # configurations: '["Release"]' + + netperf: + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/netperf.yml + with: + sha: ${{ github.sha }} + ref: ${{ github.ref }} + pull_request: ${{ github.event.pull_request.number }} + secrets: + NET_PERF_TRIGGER: ${{ secrets.NET_PERF_TRIGGER }} + + upload_perf_results: + needs: performance + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/upload-perf-results.yml + with: + name: upload_perf_results + result_artifact: km_performance-x64-Release + secrets: + AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} + AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} + AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + + upload_netperf_results_lab_2022: + needs: netperf + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/upload-perf-results.yml + with: + name: upload_netperf_results_lab_2022 + result_artifact: netperf_lab_2022_x64 + platform: Lab Windows 2022 + secrets: + AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} + AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} + AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 38a459d56e..3832623452 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -24,9 +24,6 @@ on: description: 'Environment to run tests on' type: string required: true - self-hosted-runner: - type: boolean - required: false # Set to true to gather code coverage when this test runs. code_coverage: required: false @@ -96,7 +93,7 @@ jobs: - name: Configure runner (Move to setup script directly later) id: configure-runner - if: (inputs.self-hosted-runner == true) + if: contains(inputs.environment, 'self-hosted') run: | powershell.exe "cd C:\bin\CloudTestWorker\ProvisioningScript; dir; .\Setup_orig.ps1" # powershell.exe "Get-NetAdapter" @@ -125,7 +122,7 @@ jobs: # Perform shallow checkout for self-hosted runner. - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - if: (inputs.self-hosted-runner == true) && (steps.skip_check.outputs.should_skip != 'true') + if: contains(inputs.environment, 'self-hosted') && (steps.skip_check.outputs.should_skip != 'true') with: ref: ${{ github.event.workflow_run.head_branch }} @@ -174,7 +171,7 @@ jobs: - name: Set up OpenCppCoverage and add to PATH id: set_up_opencppcoverage - if: (inputs.code_coverage == true) && (inputs.self-hosted-runner != true) && (steps.skip_check.outputs.should_skip != 'true') + if: (inputs.code_coverage == true) && !contains(inputs.environment, 'self-hosted') && (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 @@ -191,7 +188,7 @@ jobs: 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.self-hosted-runner == true) && (steps.skip_check.outputs.should_skip != 'true') + if: contains(inputs.environment, 'self-hosted') && (steps.skip_check.outputs.should_skip != 'true') run: | Remove-Item -Path ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}} -Recurse -Force -ErrorAction SilentlyContinue @@ -248,14 +245,14 @@ jobs: .\export_program_info_sample.exe - name: Run pre test command - if: steps.skip_check.outputs.should_skip != 'true' && (inputs.self-hosted-runner != true) + if: steps.skip_check.outputs.should_skip != 'true' && !contains(inputs.environment, 'self-hosted') id: run_pre_test_command working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | ${{env.PRE_COMMAND}} - name: Run pre test command on self-hosted runner - if: steps.skip_check.outputs.should_skip != 'true' && (inputs.self-hosted-runner == true) + if: steps.skip_check.outputs.should_skip != 'true' && contains(inputs.environment, 'self-hosted') id: run_pre_test_command_self_hosted working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | @@ -297,14 +294,14 @@ jobs: 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 on self-hosted runner - if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && (inputs.self-hosted-runner == true) && (inputs.fault_injection != true) + if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && contains(inputs.environment, 'self-hosted') && (inputs.fault_injection != true) id: run_test_self_hosted working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | ${{env.TEST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} - name: Run test without Code Coverage - if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && (inputs.self-hosted-runner == true) && (inputs.fault_injection != true) + if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && contains(inputs.environment, 'self-hosted') && (inputs.fault_injection != true) id: run_test_without_code_coverage working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} shell: cmd @@ -314,7 +311,7 @@ jobs: - 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.self-hosted-runner == true) + if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && contains(inputs.environment, 'self-hosted') id: run_post_test_command working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | @@ -322,7 +319,7 @@ jobs: - name: Run post test command on self-hosted runner # Run the post test command even if the workflow has failed. - if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && (inputs.self-hosted-runner == true) + if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && contains(inputs.environment, 'self-hosted') id: run_post_test_command_self_hosted working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | From 57c36eb7d015b61f44cb95de9f46c2af780c3fe7 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 16:46:41 -0800 Subject: [PATCH 073/190] WIP --- .github/workflows/cicd.yml | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index ec1c808786..76c28b53ac 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -271,6 +271,26 @@ jobs: code_coverage: false configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' + # TODO - this is only for initial testing - revert this later + # Run the regression driver tests on self-hosted runners (only for 2019). + regression_driver_ws2019: + # Always run this job. + # Only run this on repos that have self-host runners. + needs: regular + if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') + uses: ./.github/workflows/reusable-test.yml + with: + pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" -TestMode "Regression" -RegressionArtifactsVersion "0.17.0" + test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Regression" + post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + name: regression_driver_ws2019 + build_artifact: Build-x64 + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019"]' + # driver test copies dumps to testlog folder. + gather_dumps: false + # driver tests manually gather code coverage + code_coverage: false + # Run the regression driver tests on self-hosted runners (only for 2022). regression_driver_ws2022: # Always run this job. @@ -574,7 +594,9 @@ jobs: # against the kernel mode eBPF sub-system. km_mt_stress_tests: needs: regular - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + # TODO - revert this back + # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' uses: ./.github/workflows/reusable-test.yml with: name: km_mt_stress_tests @@ -591,7 +613,9 @@ jobs: # against the kernel mode eBPF sub-system. km_mt_stress_tests_restart_extension: needs: regular - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + # TODO - revert this back + # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' uses: ./.github/workflows/reusable-test.yml with: name: km_mt_stress_tests_restart_extension From 2f269a6dc2ed2366ed2d401699d7d1aa015ed348 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 13 Dec 2024 16:47:08 -0800 Subject: [PATCH 074/190] WIP --- .github/workflows/cicd.yml | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 76c28b53ac..e6ceb2134e 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -628,19 +628,20 @@ jobs: # For this test, we only want kernel mode dumps and not user mode dumps. gather_dumps: false + # TODO - figure this out... # Not sure what perf is - probably selfhosted runner, but do we need to support this now? - # performance: - # needs: regular - # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: km_performance - # pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" - # test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Performance" - # post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - # build_artifact: Build-x64 - # environment: ebpf_cicd_perf_ws2022 - # configurations: '["Release"]' + performance: + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: km_performance + pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" + test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Performance" + post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + build_artifact: Build-x64 + environment: ebpf_cicd_perf_ws2022 + configurations: '["Release"]' netperf: if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' From 0ae97f4dc008a356e6bbca15515cab42a68d81ae Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 16 Dec 2024 12:29:50 -0800 Subject: [PATCH 075/190] WIP --- .github/workflows/cicd.yml | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index e6ceb2134e..de54f7fc0b 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -207,7 +207,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_ws2019 build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2019"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage @@ -226,7 +226,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_ws2022 build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2022"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2022"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage @@ -245,7 +245,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_native_only_ws2019 build_artifact: Build-x64-native-only - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2019"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage @@ -264,33 +264,13 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_native_only_ws2022 build_artifact: Build-x64-native-only - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2022"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2019"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage code_coverage: false configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' - # TODO - this is only for initial testing - revert this later - # Run the regression driver tests on self-hosted runners (only for 2019). - regression_driver_ws2019: - # Always run this job. - # Only run this on repos that have self-host runners. - needs: regular - if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') - uses: ./.github/workflows/reusable-test.yml - with: - pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" -TestMode "Regression" -RegressionArtifactsVersion "0.17.0" - test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Regression" - post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - name: regression_driver_ws2019 - build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019"]' - # driver test copies dumps to testlog folder. - gather_dumps: false - # driver tests manually gather code coverage - code_coverage: false - # Run the regression driver tests on self-hosted runners (only for 2022). regression_driver_ws2022: # Always run this job. @@ -304,7 +284,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: regression_driver_ws2022 build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2022"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2022", "1ES.ImageOverride=ebpf-cicd-image-server-2019"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage @@ -604,7 +584,7 @@ jobs: test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Stress" post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2019"]' code_coverage: false # For this test, we only want kernel mode dumps and not user mode dumps. gather_dumps: false @@ -623,7 +603,7 @@ jobs: test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Stress" -Options @("RestartExtension") post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2019"]' code_coverage: false # For this test, we only want kernel mode dumps and not user mode dumps. gather_dumps: false From 91f3a84d4f42155b66580f7b1353cf836ac9fdbb Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 16 Dec 2024 16:03:02 -0800 Subject: [PATCH 076/190] WIP --- .github/workflows/cicd.yml | 4 +- .github/workflows/reusable-test.yml | 5 --- 1es/Setup_orig.ps1 | 68 +++++++++++++++++++---------- 1es/configure_vm.ps1 | 4 +- 1es/prepare_vm_helpers.psm1 | 19 ++++---- 5 files changed, 59 insertions(+), 41 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index de54f7fc0b..e0124388e5 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -264,7 +264,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_native_only_ws2022 build_artifact: Build-x64-native-only - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2019"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2022"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage @@ -284,7 +284,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: regression_driver_ws2022 build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2022", "1ES.ImageOverride=ebpf-cicd-image-server-2019"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2022"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 3832623452..b1259278f7 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -96,11 +96,6 @@ jobs: if: contains(inputs.environment, 'self-hosted') run: | powershell.exe "cd C:\bin\CloudTestWorker\ProvisioningScript; dir; .\Setup_orig.ps1" - # powershell.exe "Get-NetAdapter" - # powershell.exe "Get-VMSwitch" - # powershell.exe "Get-NetAdapter" - # powershell.exe "Get-VMSwitch" - # powershell.exe "Get-VM" - name: Print CPU information run: diff --git a/1es/Setup_orig.ps1 b/1es/Setup_orig.ps1 index 77e2cb5841..a7edab1932 100644 --- a/1es/Setup_orig.ps1 +++ b/1es/Setup_orig.ps1 @@ -9,7 +9,6 @@ param( [Parameter(Mandatory=$False)][string]$BaseVhdDirPath='.\', [Parameter(Mandatory=$False)][string]$WorkingPath='.\working', [Parameter(Mandatory=$False)][string]$OutVhdDirPath='.\exported_vhds', - [Parameter(Mandatory=$False)][string]$ExternalSwitchName='VMExternalSwitch', [Parameter(Mandatory=$False)][string]$VMCpuCount=4, [Parameter(Mandatory=$False)][string]$VMMemory=4096MB @@ -28,13 +27,29 @@ if (-not (Test-Path -Path $BaseVhdDirPath)) { throw "VHD directory not found at $BaseVhdDirPath" } -# Create-VMSwitchIfNeeded -SwitchName 'VMInternalSwitch' -SwitchType 'Internal' +Create-VMSwitchIfNeeded -SwitchName 'VMInternalSwitch' -SwitchType 'Internal' Create-VMSwitchIfNeeded -SwitchName 'VMExternalSwitch' -SwitchType 'External' # Stored credentials doesn't seem to be working... # Create-VMStoredCredential -CredentialName "TEST_VM" -Username $VmUsername -Password $VmPassword # Create-VMStoredCredential -CredentialName "TEST_VM_STANDARD" -Username $VmStandardUserName -Password $VmPassword Create-DirectoryIfNotExists -Path $WorkingPath +# Unzip any VHDs +$zipFiles = Get-ChildItem -Path $BaseVhdDirPath -Filter *.zip +foreach ($zipFile in $zipFiles) { + $outDir = Join-Path -Path $BaseVhdDirPath -ChildPath $zipFile.BaseName + if (-not (Test-Path -Path $outDir)) { + Expand-Archive -Path $zipFile.FullName -DestinationPath $outDir + + # Move the VHDs to the base directory + $vhdFiles = Get-ChildItem -Path $outDir -Filter *.vhd -ErrorAction Ignore + $vhdFiles += Get-ChildItem -Path $outDir -Filter *.vhdx -ErrorAction Ignore + foreach ($vhdFile in $vhdFiles) { + Move-Item -Path $vhdFile.FullName -Destination $BaseVhdDirPath + } + } +} + # Read the input VHDs $vhds = @((Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhd)) $vhds += Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhdx @@ -43,27 +58,34 @@ if ($vhds.Count -eq 0) { } for ($i = 0; $i -lt $vhds.Count; $i++) { - $vhd = $vhds[$i] - Log-Message -Message "Processing VHD: $($vhd.FullName)" - $vmName = "runner_vm" - if ($i -gt 0) { - $vmName += "_$i" - } - $outVMPath = Join-Path -Path $WorkingPath -ChildPath $VMName + try { + $vhd = $vhds[$i] + Log-Message -Message "Processing VHD: $($vhd.FullName)" + $vmName = "runner_vm" + if ($i -gt 0) { + $vmName += "_$i" + } + $outVMPath = Join-Path -Path $WorkingPath -ChildPath $VMName + + Create-VM ` + -VmName $vmName ` + -VhdPath $vhd.FullName ` + -VmStoragePath $outVMPath ` + -VMMemory $VMMemory ` + -UnattendPath $BaseUnattendPath ` + -VmUsername $VmUsername ` + -VmPassword $VmPassword - Create-VM ` - -VmName $vmName ` - -VhdPath $vhd.FullName ` - -VmStoragePath $outVMPath ` - -ExternalVMSwitchName $ExternalSwitchName ` - -VMMemory $VMMemory ` - -UnattendPath $BaseUnattendPath ` - -VmUsername $VmUsername ` - -VmPassword $VmPassword + Configure-VM ` + -VmName $vmName ` + -VmUsername $VmUsername ` + -VmPassword $VmPassword ` + -CpuCount $CpuCount - Configure-VM ` - -VmName $vmName ` - -CpuCount $VMCpuCount ` - -VmUsername $VmUsername ` - -VmPassword $VmPassword + Log-Message "VM $vmName created successfully" + } catch { + Log-Message "Failed to create VM $vmName: $_" + } } + +Log-Message "Setup.ps1 complete!" \ No newline at end of file diff --git a/1es/configure_vm.ps1 b/1es/configure_vm.ps1 index 32a1768c8d..43e5f3ce05 100644 --- a/1es/configure_vm.ps1 +++ b/1es/configure_vm.ps1 @@ -121,11 +121,11 @@ foreach ($adapter in $adapters) { } } -Get-NetAdapterBinding -AllBindings +Get-NetAdapterBinding -AllBindings | Out-String ipconfig /all -Get-NetIPInterface +Get-NetIPInterface | Out-String # Reboot the machine to apply the changes. Restart-Computer -Force \ No newline at end of file diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index d6b6f4554f..2404764252 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -149,7 +149,6 @@ function Create-VM { [Parameter(Mandatory=$True)][string]$VmPassword, [Parameter(Mandatory=$True)][string]$VhdPath, [Parameter(Mandatory=$True)][string]$VmStoragePath, - [Parameter(Mandatory=$True)][string]$ExternalVMSwitchName, [Parameter(Mandatory=$True)][Int64]$VMMemory, [Parameter(Mandatory=$True)][string]$UnattendPath ) @@ -191,7 +190,7 @@ function Create-VM { # Create the VM Log-Message "Creating the VM" New-VM -Name $VmName -VhdPath $VmVhdPath - $vmSwitches = Get-VMSwitch + $vmSwitches = Get-VMSwitch -ErrorAction Ignore foreach ($switch in $vmSwitches) { Log-Message "Adding network adapter to VM: $VmName with switch: $($switch.Name)" Add-VMNetworkAdapter -VMName $VmName -SwitchName $switch.Name @@ -238,10 +237,10 @@ function Configure-VM { Log-Message "Sleeping for 1 minute to let the VM get into a steady state" Sleep -Seconds 60 # Sleep for 1 minute to let the VM get into a steady state. - # Fetch all updates on the VM - Log-Message "Fetching Updates on the VM" - # Update-VM -VMName $VmName -VmCredential $VmCredential - Log-Message -Message "Successfully updated VM: $VMName" -ForegroundColor Green + # # Fetch all updates on the VM + # Log-Message "Fetching Updates on the VM" + # # Update-VM -VMName $VmName -VmCredential $VmCredential + # Log-Message -Message "Successfully updated VM: $VMName" -ForegroundColor Green # Copy setup script to the VM and execute it. Log-Message "Executing VM configuration script ($VMSetupScript) on VM: $VmName" @@ -266,6 +265,8 @@ function Configure-VM { continue } } + + Log-Message "Successfully configured VM: $VmName" -ForegroundColor Green } catch { throw "Failed to configure VM: $VmName. Error: $_" } @@ -297,7 +298,7 @@ function Create-VMSwitchIfNeeded { try { if ($SwitchType -eq 'External') { # Check to see if an external switch already exists - $ExternalSwitches = (Get-VMSwitch -SwitchType External) + $ExternalSwitches = (Get-VMSwitch -SwitchType External -ErrorAction Ignore) if ($ExternalSwitches -ne $null) { Log-Message -Message "External switch already exists: $($ExternalSwitches[0].Name)" return @@ -311,7 +312,7 @@ function Create-VMSwitchIfNeeded { if ([string]::IsNullOrEmpty($NetAdapterName)) { continue } - $switchName = $ExternalSwitchName + '-' + $index + $switchName = $SwitchName + '-' + $index Log-Message "Attempting to creating external switch: $switchName with NetAdapter: $NetAdapterName" New-VMSwitch -Name $switchName -NetAdapterName $NetAdapterName -AllowManagementOS $true # break @@ -321,7 +322,7 @@ function Create-VMSwitchIfNeeded { } } elseif ($SwitchType -eq 'Internal') { # Check to see if an internal switch already exists - $InternalSwitches = (Get-VMSwitch -SwitchType Internal) + $InternalSwitches = (Get-VMSwitch -SwitchType Internal -ErrorAction Ignore) if ($InternalSwitches -ne $null) { Log-Message -Message "Internal switch already exists: $($InternalSwitches[0].Name)" return From dfedb27b7ea270d0c477905d1c6770b24b83499b Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 16 Dec 2024 16:44:10 -0800 Subject: [PATCH 077/190] WIP --- 1es/Setup_orig.ps1 | 2 +- 1es/prepare_vm_helpers.psm1 | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/1es/Setup_orig.ps1 b/1es/Setup_orig.ps1 index a7edab1932..7c651a0ea4 100644 --- a/1es/Setup_orig.ps1 +++ b/1es/Setup_orig.ps1 @@ -84,7 +84,7 @@ for ($i = 0; $i -lt $vhds.Count; $i++) { Log-Message "VM $vmName created successfully" } catch { - Log-Message "Failed to create VM $vmName: $_" + Log-Message "Failed to create VM $vmName with error $_" } } diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index 2404764252..17c4c34ca3 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -28,7 +28,7 @@ function Create-DirectoryIfNotExists { throw "Failed to create directory: $Path" } } catch { - throw "Failed to create directory: $Path. $_" + throw "Failed to create directory: $Path with error $_" } } @@ -77,7 +77,7 @@ function Execute-CommandOnVM { Log-Message -Message "Executed command on VM: $VMName. Command: $Command. Result: $result" } catch { - throw "Failed to execute command on VM: $VMName. Error: $_" + throw "Failed to execute command on VM: $VMName with error: $_" } } @@ -203,7 +203,7 @@ function Create-VM { Log-Message -Message "Successfully created VM: $VMName" -ForegroundColor Green } catch { - throw "Failed to create VM: $VmName. Error: $_" + throw "Failed to create VM: $VmName with error: $_" } } @@ -268,7 +268,7 @@ function Configure-VM { Log-Message "Successfully configured VM: $VmName" -ForegroundColor Green } catch { - throw "Failed to configure VM: $VmName. Error: $_" + throw "Failed to configure VM: $VmName with error: $_" } } @@ -286,7 +286,7 @@ function Install-HyperVIfNeeded { exit 1 } } catch { - throw "Failed to install Hyper-V: $_" + throw "Failed to install Hyper-V with error: $_" } } @@ -317,7 +317,7 @@ function Create-VMSwitchIfNeeded { New-VMSwitch -Name $switchName -NetAdapterName $NetAdapterName -AllowManagementOS $true # break } catch { - Log-Message "Failed to create external switch for NetAdapter: $NetAdapterName $_" + Log-Message "Failed to create external switch for NetAdapter: $NetAdapterName with error: $_" } } } elseif ($SwitchType -eq 'Internal') { @@ -335,7 +335,7 @@ function Create-VMSwitchIfNeeded { throw "Invalid switch type: $SwitchType" } } catch { - throw "Failed to create external switch: $_" + throw "Failed to create external switch with error: $_" } } @@ -351,7 +351,6 @@ function Create-VMStoredCredential { New-StoredCredential -Target $CredentialName -UserName $Username -Password $Password -Type Generic -Persist LocalMachine } catch { - Log-Message "Failed to create stored credential: $_" -ForegroundColor Red - # throw "Failed to create stored credential: $_" + Log-Message "Failed to create stored credential with error $_" -ForegroundColor Red } } \ No newline at end of file From 5456831c6c5d0537f0cfe2a7e21766b609862cd5 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 16 Dec 2024 17:13:22 -0800 Subject: [PATCH 078/190] WIP --- 1es/prepare_vm_helpers.psm1 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index 17c4c34ca3..9e1d0a9426 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -312,9 +312,10 @@ function Create-VMSwitchIfNeeded { if ([string]::IsNullOrEmpty($NetAdapterName)) { continue } - $switchName = $SwitchName + '-' + $index - Log-Message "Attempting to creating external switch: $switchName with NetAdapter: $NetAdapterName" - New-VMSwitch -Name $switchName -NetAdapterName $NetAdapterName -AllowManagementOS $true + $currSwitchName = $SwitchName + '-' + $index + Log-Message "Attempting to creating external switch: $currSwitchName with NetAdapter: $NetAdapterName" + New-VMSwitch -Name $currSwitchName -NetAdapterName $NetAdapterName -AllowManagementOS $true + $index += 1 # break } catch { Log-Message "Failed to create external switch for NetAdapter: $NetAdapterName with error: $_" From 93255f3632ea7011401fb59ef4d59bc9bd772035 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 17 Dec 2024 09:28:03 -0800 Subject: [PATCH 079/190] WIP --- 1es/Setup_orig.ps1 | 19 +++++++--- 1es/prepare_vm_helpers.psm1 | 76 +++++++++++++++++++------------------ 2 files changed, 52 insertions(+), 43 deletions(-) diff --git a/1es/Setup_orig.ps1 b/1es/Setup_orig.ps1 index 7c651a0ea4..3d54330690 100644 --- a/1es/Setup_orig.ps1 +++ b/1es/Setup_orig.ps1 @@ -7,8 +7,9 @@ param( [Parameter(Mandatory=$False)][string]$BaseUnattendPath='.\unattend.xml', [Parameter(Mandatory=$False)][string]$BaseVhdDirPath='.\', - [Parameter(Mandatory=$False)][string]$WorkingPath='.\working', - [Parameter(Mandatory=$False)][string]$OutVhdDirPath='.\exported_vhds', + # [Parameter(Mandatory=$False)][string]$WorkingPath='.\working', + [Parameter(Mandatory=$False)][string]$WorkingPath='C:\vms', + # [Parameter(Mandatory=$False)][string]$OutVhdDirPath='.\exported_vhds', [Parameter(Mandatory=$False)][string]$VMCpuCount=4, [Parameter(Mandatory=$False)][string]$VMMemory=4096MB @@ -35,32 +36,38 @@ Create-VMSwitchIfNeeded -SwitchName 'VMExternalSwitch' -SwitchType 'External' Create-DirectoryIfNotExists -Path $WorkingPath # Unzip any VHDs +Log-Message "Processing VHDs in $BaseVhdDirPath" $zipFiles = Get-ChildItem -Path $BaseVhdDirPath -Filter *.zip foreach ($zipFile in $zipFiles) { + Log-Message "Extracting VHDs from $($zipFile.FullName)" $outDir = Join-Path -Path $BaseVhdDirPath -ChildPath $zipFile.BaseName if (-not (Test-Path -Path $outDir)) { Expand-Archive -Path $zipFile.FullName -DestinationPath $outDir # Move the VHDs to the base directory - $vhdFiles = Get-ChildItem -Path $outDir -Filter *.vhd -ErrorAction Ignore + $vhdFiles = @() + $vhdFiles += Get-ChildItem -Path $outDir -Filter *.vhd -ErrorAction Ignore $vhdFiles += Get-ChildItem -Path $outDir -Filter *.vhdx -ErrorAction Ignore foreach ($vhdFile in $vhdFiles) { Move-Item -Path $vhdFile.FullName -Destination $BaseVhdDirPath } } + Log-Message "Successfully processed $($zipFile.FullName)" } # Read the input VHDs -$vhds = @((Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhd)) -$vhds += Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhdx +$vhds = @() +$vhds += Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhd -ErrorAction Ignore +$vhds += Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhdx -ErrorAction Ignore if ($vhds.Count -eq 0) { throw "No VHDs found in $BaseVhdDirPath" } +Log-Message "Successfully processed VHDs" for ($i = 0; $i -lt $vhds.Count; $i++) { try { $vhd = $vhds[$i] - Log-Message -Message "Processing VHD: $($vhd.FullName)" + Log-Message -Message "Creating VM from VHD: $($vhd.FullName)" $vmName = "runner_vm" if ($i -gt 0) { $vmName += "_$i" diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index 9e1d0a9426..47fee26719 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -292,52 +292,54 @@ function Install-HyperVIfNeeded { function Create-VMSwitchIfNeeded { param ( - [Parameter(Mandatory=$False)][string]$SwitchName='VMInternalSwitch', - [Parameter(Mandatory=$False)][string]$SwitchType='Internal' + [Parameter(Mandatory=$true)][string]$SwitchName, + [Parameter(Mandatory=$true)][string]$SwitchType ) - try { - if ($SwitchType -eq 'External') { - # Check to see if an external switch already exists - $ExternalSwitches = (Get-VMSwitch -SwitchType External -ErrorAction Ignore) - if ($ExternalSwitches -ne $null) { - Log-Message -Message "External switch already exists: $($ExternalSwitches[0].Name)" - return - } + if ($SwitchType -eq 'External') { + # Check to see if an external switch already exists + $ExternalSwitches = (Get-VMSwitch -SwitchType External -ErrorAction Ignore) + if ($ExternalSwitches -ne $null) { + Log-Message -Message "External switch already exists: $($ExternalSwitches[0].Name)" + return + } - # Try to create the external switch - $NetAdapterNames = (Get-NetAdapter -Name 'Ethernet*' | Where-Object { $_.Status -eq 'Up' }).Name - $index = 0 - foreach ($NetAdapterName in $NetAdapterNames) { - try { - if ([string]::IsNullOrEmpty($NetAdapterName)) { - continue - } - $currSwitchName = $SwitchName + '-' + $index - Log-Message "Attempting to creating external switch: $currSwitchName with NetAdapter: $NetAdapterName" - New-VMSwitch -Name $currSwitchName -NetAdapterName $NetAdapterName -AllowManagementOS $true - $index += 1 - # break - } catch { - Log-Message "Failed to create external switch for NetAdapter: $NetAdapterName with error: $_" + # Try to create the external switch + $NetAdapterNames = (Get-NetAdapter -Name 'Ethernet*' | Where-Object { $_.Status -eq 'Up' }).Name + $index = 0 + foreach ($NetAdapterName in $NetAdapterNames) { + try { + if ([string]::IsNullOrEmpty($NetAdapterName)) { + continue } + $currSwitchName = $SwitchName + '-' + $index + Log-Message "Attempting to creating external switch: $currSwitchName with NetAdapter: $NetAdapterName" + New-VMSwitch -Name $currSwitchName -NetAdapterName $NetAdapterName -AllowManagementOS $true + $index += 1 + # break + } catch { + Log-Message "Failed to create external switch for NetAdapter: $NetAdapterName with error: $_" } - } elseif ($SwitchType -eq 'Internal') { - # Check to see if an internal switch already exists - $InternalSwitches = (Get-VMSwitch -SwitchType Internal -ErrorAction Ignore) - if ($InternalSwitches -ne $null) { - Log-Message -Message "Internal switch already exists: $($InternalSwitches[0].Name)" - return - } + } + } elseif ($SwitchType -eq 'Internal') { + # Check to see if an internal switch already exists + $InternalSwitches = (Get-VMSwitch -SwitchType Internal -ErrorAction Ignore) + if ($InternalSwitches -ne $null) { + Log-Message -Message "Internal switch already exists: $($InternalSwitches[0].Name)" + return + } - # Try to create the internal switch + # Try to create the internal switch + try { Log-Message "Creating internal switch" New-VMSwitch -Name 'VMInternalSwitch' -SwitchType Internal - } else { - throw "Invalid switch type: $SwitchType" + } catch { + throw "Failed to create internal switch with error: $_" } - } catch { - throw "Failed to create external switch with error: $_" + } else { + throw "Invalid switch type: $SwitchType" } + + Log-Message "Successfully created $SwitchType switch with name: $SwitchName" -ForegroundColor Green } function Create-VMStoredCredential { From 86237f29a333e7adb872e3b1612fffe2bbbcebc8 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 17 Dec 2024 10:15:46 -0800 Subject: [PATCH 080/190] WIP --- 1es/Setup_orig.ps1 | 2 +- 1es/prepare_vm_helpers.psm1 | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/1es/Setup_orig.ps1 b/1es/Setup_orig.ps1 index 3d54330690..b256d7a48d 100644 --- a/1es/Setup_orig.ps1 +++ b/1es/Setup_orig.ps1 @@ -87,7 +87,7 @@ for ($i = 0; $i -lt $vhds.Count; $i++) { -VmName $vmName ` -VmUsername $VmUsername ` -VmPassword $VmPassword ` - -CpuCount $CpuCount + -VMCpuCount $VMCpuCount Log-Message "VM $vmName created successfully" } catch { diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index 47fee26719..3bbf64d565 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -212,7 +212,7 @@ function Configure-VM { [Parameter(Mandatory=$True)][string]$VmName, [Parameter(Mandatory=$True)][string]$VmUsername, [Parameter(Mandatory=$True)][string]$VmPassword, - [Parameter(Mandatory=$True)][int]$CpuCount, + [Parameter(Mandatory=$True)][int]$VMCpuCount, [Parameter(Mandatory=$False)][string]$VMWorkingDirectory='C:\ebpf_cicd', [Parameter(Mandatory=$False)][string]$VMSetupScript='.\configure_vm.ps1' ) @@ -221,8 +221,8 @@ function Configure-VM { Log-Message "Configuring VM: $VmName" # Post VM creation configuration steps. - Log-Message "Setting VM processor count to $CpuCount" - Set-VMProcessor -VMName $VmName -Count $CpuCount + Log-Message "Setting VM processor count to $VMCpuCount" + Set-VMProcessor -VMName $VmName -Count $VMCpuCount Log-Message "Enabling Guest Service Interface" Enable-VMIntegrationService -VMName $VMName -Name 'Guest Service Interface' From 7143241740971e502ede4ca52ef9544ab3e90c03 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 17 Dec 2024 13:21:50 -0800 Subject: [PATCH 081/190] WIP --- .github/workflows/reusable-test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index b1259278f7..2133224b5b 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -296,7 +296,7 @@ jobs: ${{env.TEST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} - name: Run test without Code Coverage - if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && contains(inputs.environment, 'self-hosted') && (inputs.fault_injection != true) + if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && !contains(inputs.environment, 'self-hosted') && (inputs.fault_injection != true) id: run_test_without_code_coverage working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} shell: cmd @@ -306,7 +306,7 @@ jobs: - 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') && contains(inputs.environment, 'self-hosted') + if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && !contains(inputs.environment, 'self-hosted') id: run_post_test_command working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | From e3c4d808c4e053423c5fd2753e3ad7705dd7d0a0 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 17 Dec 2024 14:21:27 -0800 Subject: [PATCH 082/190] WIP --- .github/workflows/cicd.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index e0124388e5..677bb4f6af 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -226,7 +226,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_ws2022 build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2022"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride="ebpf-cicd-image-server-2022""]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage @@ -264,7 +264,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_native_only_ws2022 build_artifact: Build-x64-native-only - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2022"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=TestDoesnotExist"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage @@ -284,7 +284,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: regression_driver_ws2022 build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2022"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride='ebpf-cicd-image-server-2022'"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage From d891edee3c6983e8b0efd820ecc0d801363cfe78 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 17 Dec 2024 14:28:27 -0800 Subject: [PATCH 083/190] WIP --- .github/workflows/cicd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 677bb4f6af..ac16845bf4 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -284,7 +284,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: regression_driver_ws2022 build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride='ebpf-cicd-image-server-2022'"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=\"ebpf-cicd-image-server-2022\""]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage From 1ffaec3820d120c5e98d3101ccab98b5cb81cd32 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 17 Dec 2024 15:44:47 -0800 Subject: [PATCH 084/190] WIP --- .github/workflows/cicd.yml | 6 +++--- scripts/run_driver_tests.psm1 | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index ac16845bf4..e0124388e5 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -226,7 +226,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_ws2022 build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride="ebpf-cicd-image-server-2022""]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2022"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage @@ -264,7 +264,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_native_only_ws2022 build_artifact: Build-x64-native-only - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=TestDoesnotExist"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2022"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage @@ -284,7 +284,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: regression_driver_ws2022 build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=\"ebpf-cicd-image-server-2022\""]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2022"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 5665315ed7..aafab1a601 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -492,6 +492,14 @@ function Invoke-CICDStressTests } else { $TestArguments = "-tt=8 -td=5 -erd=1000 -er=1" } + + # TODO - remove debugging output + Write-Log "Items from .\" + Get-ChildItem '.\' + Write-Lost "Itesm from $WorkingDirectory" + Get-ChildItem $WorkingDirectory + Write-Log "Starting $TestCommand with arguments: $TestArguments" + $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand From e9ed4c170325aafa23c954c807c8b2f3934e9a61 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 17 Dec 2024 16:46:40 -0800 Subject: [PATCH 085/190] WIP --- .github/workflows/cicd.yml | 4 ++-- scripts/run_driver_tests.psm1 | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index e0124388e5..e92355996a 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -226,7 +226,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_ws2022 build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2022"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2022"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage @@ -264,7 +264,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_native_only_ws2022 build_artifact: Build-x64-native-only - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2022"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2022"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index aafab1a601..8a91105678 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -189,6 +189,10 @@ function Process-TestCompletion } else { # Ensure the process has completely exited. Wait-Process -InputObject $TestProcess + $currExitCode = $TestProcess.ExitCode + $temp = $TestProcess | Out-String + Write-Log "Maige - test output: $temp" + Write-Log "MAIGE - $TestCommand exited with code $currExitCode" # Read and display the output (if any) from the temporary output file. $TempOutputFile = "$env:TEMP\app_output.log" # Log for standard output @@ -485,7 +489,7 @@ function Invoke-CICDStressTests $LASTEXITCODE = 0 - $TestCommand = "ebpf_stress_tests_km" + $TestCommand = "ebpf_stress_tests_km.exe" $TestArguments = " " if ($RestartExtension -eq $false) { $TestArguments = "-tt=8 -td=5" @@ -496,11 +500,19 @@ function Invoke-CICDStressTests # TODO - remove debugging output Write-Log "Items from .\" Get-ChildItem '.\' - Write-Lost "Itesm from $WorkingDirectory" + Write-Log "Items from $WorkingDirectory" Get-ChildItem $WorkingDirectory Write-Log "Starting $TestCommand with arguments: $TestArguments" + # Valid that the test command exists. + if (-not (Test-Path $TestCommand)) { + ThrowWithErrorMessage -ErrorMessage "*** ERROR *** $TestCommand not found under $WorkingDirectory." + } + $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow + if ($TestProcess -eq $null) { + ThrowWithErrorMessage -ErrorMessage "*** ERROR *** Failed to start $TestCommand." + } Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand From 4910da3f25c342be8073da3fc13f8b990f97d8d2 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 18 Dec 2024 09:41:34 -0800 Subject: [PATCH 086/190] WIP --- scripts/run_driver_tests.psm1 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 8a91105678..98f1f3cc18 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -157,6 +157,11 @@ function Process-TestCompletion [Parameter(Mandatory = $false)] [int] $TestHangTimeout = (10*60), # 10 minutes default timeout. [Parameter(Mandatory = $false)] [bool] $NeedKernelDump = $true) + if ($TestProcess -eq $null) { + Write-Log "Process-TestCompletion: Failed to start $TestCommand" + throw "Failed to start $TestCommand" + } + # Use Wait-Process for the process to terminate or timeout. # See https://stackoverflow.com/a/23797762 Wait-Process -InputObject $TestProcess -Timeout $TestHangTimeout -ErrorAction SilentlyContinue @@ -206,6 +211,8 @@ function Process-TestCompletion } $TestExitCode = $TestProcess.ExitCode + Write-Log "Maige - Test exit code: $TestExitCode" + # if ($TestExitCode -ne $null -and $TestExitCode -ne 0) { if ($TestExitCode -ne 0) { $TempErrorFile = "$env:TEMP\app_error.log" # Log for standard error if ((Test-Path $TempErrorFile) -and (Get-Item $TempErrorFile).Length -gt 0) { @@ -373,6 +380,10 @@ function Invoke-XDPTest $TestCommand = ".\xdp_tests.exe" $TestArguments = "$XDPTestName --remote-ip $RemoteIPV4Address" $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow + if ($TestProcess -eq $null) { + Write-Log "Failed to start $TestCommand with arguments $TestArguments" + throw "Failed to start $TestCommand with arguments $TestArguments" + } Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand Write-Log "Executing $XDPTestName with remote address: $RemoteIPV6Address" @@ -380,6 +391,10 @@ function Invoke-XDPTest $TestCommand = ".\xdp_tests.exe" $TestArguments = "$XDPTestName --remote-ip $RemoteIPV6Address" $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow + if ($TestProcess -eq $null) { + Write-Log "Failed to start $TestCommand with arguments $TestArguments" + throw "Failed to start $TestCommand with arguments $TestArguments" + } Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand Write-Log "$XDPTestName Test Passed" -ForegroundColor Green From 5483105ee7e9963b722795ecded2651296575cce Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 18 Dec 2024 13:07:11 -0800 Subject: [PATCH 087/190] WIP --- scripts/run_driver_tests.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 98f1f3cc18..26e9a81d8b 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -212,8 +212,8 @@ function Process-TestCompletion $TestExitCode = $TestProcess.ExitCode Write-Log "Maige - Test exit code: $TestExitCode" - # if ($TestExitCode -ne $null -and $TestExitCode -ne 0) { - if ($TestExitCode -ne 0) { + if ($TestExitCode -ne $null -and $TestExitCode -ne 0) { + # if ($TestExitCode -ne 0) { $TempErrorFile = "$env:TEMP\app_error.log" # Log for standard error if ((Test-Path $TempErrorFile) -and (Get-Item $TempErrorFile).Length -gt 0) { Write-Log "$TestCommand Error Output:`n" -ForegroundColor Red From 5a1730bc152957f1f321d5ff76c078a53be3d7d6 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 18 Dec 2024 14:31:44 -0800 Subject: [PATCH 088/190] WIP --- .github/workflows/cicd.yml | 4 ++-- scripts/run_driver_tests.psm1 | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index e92355996a..e0124388e5 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -226,7 +226,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_ws2022 build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2022"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2022"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage @@ -264,7 +264,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_native_only_ws2022 build_artifact: Build-x64-native-only - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2022"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2022"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 26e9a81d8b..38a8f60641 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -162,6 +162,8 @@ function Process-TestCompletion throw "Failed to start $TestCommand" } + Write-Log "Process-TestCompletion invoked for $TestProcess and $TestCommand" + # Use Wait-Process for the process to terminate or timeout. # See https://stackoverflow.com/a/23797762 Wait-Process -InputObject $TestProcess -Timeout $TestHangTimeout -ErrorAction SilentlyContinue @@ -192,6 +194,7 @@ function Process-TestCompletion Write-Log "Throwing TestHungException for $TestCommand" -ForegroundColor Red throw [System.TimeoutException]::new("Test $TestCommand execution hang timeout ($TestHangTimeout seconds) expired.") } else { + Write-Log "Process-TestCompletion: command should have completed" # Ensure the process has completely exited. Wait-Process -InputObject $TestProcess $currExitCode = $TestProcess.ExitCode From 9aa514281df0cda30be00f0c21448a69a14e63db Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 18 Dec 2024 16:21:38 -0800 Subject: [PATCH 089/190] WIP --- scripts/run_driver_tests.psm1 | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 38a8f60641..ab691bbb35 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -195,12 +195,21 @@ function Process-TestCompletion throw [System.TimeoutException]::new("Test $TestCommand execution hang timeout ($TestHangTimeout seconds) expired.") } else { Write-Log "Process-TestCompletion: command should have completed" - # Ensure the process has completely exited. - Wait-Process -InputObject $TestProcess - $currExitCode = $TestProcess.ExitCode - $temp = $TestProcess | Out-String - Write-Log "Maige - test output: $temp" - Write-Log "MAIGE - $TestCommand exited with code $currExitCode" + try { + $currExitCode = $TestProcess.ExitCode + $temp = $TestProcess | Out-String + Write-Log "Maige - test output: $temp" + Write-Log "MAIGE - $TestCommand exited with code $currExitCode" + } catch { + Write-Log "maige - failed" + } + + # # Ensure the process has completely exited. + # Wait-Process -InputObject $TestProcess + # $currExitCode = $TestProcess.ExitCode + # $temp = $TestProcess | Out-String + # Write-Log "Maige - test output: $temp" + # Write-Log "MAIGE - $TestCommand exited with code $currExitCode" # Read and display the output (if any) from the temporary output file. $TempOutputFile = "$env:TEMP\app_output.log" # Log for standard output From ac1416b487eaa12ebc205a5f27afb42d1f6d357f Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 20 Dec 2024 12:22:09 -0500 Subject: [PATCH 090/190] WIP --- scripts/run_driver_tests.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index ab691bbb35..e070ef71f5 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -162,7 +162,7 @@ function Process-TestCompletion throw "Failed to start $TestCommand" } - Write-Log "Process-TestCompletion invoked for $TestProcess and $TestCommand" + Write-Log "Process-TestCompletion (maige) invoked for $TestProcess and $TestCommand" # Use Wait-Process for the process to terminate or timeout. # See https://stackoverflow.com/a/23797762 From 400c1dd9649de06a87cbb144166b6d0335a53d80 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 20 Dec 2024 15:26:31 -0500 Subject: [PATCH 091/190] WIP --- scripts/run_driver_tests.psm1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index e070ef71f5..f11538cab1 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -157,12 +157,13 @@ function Process-TestCompletion [Parameter(Mandatory = $false)] [int] $TestHangTimeout = (10*60), # 10 minutes default timeout. [Parameter(Mandatory = $false)] [bool] $NeedKernelDump = $true) + Write-Log "(maige) Process-TestCompletion (maige)" + Write-Log "Process-TestCompletion (maige) invoked for $TestCommand" if ($TestProcess -eq $null) { Write-Log "Process-TestCompletion: Failed to start $TestCommand" throw "Failed to start $TestCommand" } - Write-Log "Process-TestCompletion (maige) invoked for $TestProcess and $TestCommand" # Use Wait-Process for the process to terminate or timeout. # See https://stackoverflow.com/a/23797762 @@ -413,7 +414,7 @@ function Invoke-XDPTest Write-Log "`n`n" } catch { $ErrorMessage = $_.Exception.Message - ThrowWithErrorMessage -ErrorMessage "XDP test Failed with $ErrorMessage" + ThrowWithErrorMessage -ErrorMessage "(maige) XDP test Failed with $ErrorMessage" } Pop-Location From 193258ecb00bec96d4f1ea294e2d94bd3c33630e Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 30 Dec 2024 09:03:52 -0800 Subject: [PATCH 092/190] WIP --- scripts/run_driver_tests.psm1 | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index f11538cab1..7fa0d31a53 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -164,10 +164,17 @@ function Process-TestCompletion throw "Failed to start $TestCommand" } + try { + # Use Wait-Process for the process to terminate or timeout. + # See https://stackoverflow.com/a/23797762 + Wait-Process -InputObject $TestProcess -Timeout $TestHangTimeout -ErrorAction SilentlyContinue + } catch { + Write-Log "(CATCH) Process-TestCompletion: Failed to wait for $TestCommand" + throw "Failed to wait for $TestCommand" + } + + Write-Log "(maige) Process-TestCompletion: Process exit code: $($TestProcess.ExitCode)" - # Use Wait-Process for the process to terminate or timeout. - # See https://stackoverflow.com/a/23797762 - Wait-Process -InputObject $TestProcess -Timeout $TestHangTimeout -ErrorAction SilentlyContinue if (-not $TestProcess.HasExited) { Write-Log "`n*** ERROR *** Test $TestCommand execution hang timeout ($TestHangTimeout seconds) expired.`n" From ab8a023a66db963d2477521dcd4aaf8a864ea8e1 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 30 Dec 2024 10:07:39 -0800 Subject: [PATCH 093/190] WIP --- 1es/Setup.ps1 | 4 ++-- scripts/run_driver_tests.psm1 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/1es/Setup.ps1 b/1es/Setup.ps1 index 70ef1753a1..c5d7a87dcd 100644 --- a/1es/Setup.ps1 +++ b/1es/Setup.ps1 @@ -16,8 +16,8 @@ # $ErrorActionPreference = "Stop" -# # Import helper functions -# Import-Module .\prepare_vm_helpers.psm1 -Force +# Import helper functions +Import-Module .\prepare_vm_helpers.psm1 -Force $hyperV = (Get-WindowsFeature -Name 'Hyper-V').Installed Log-Message -Message "Hyper-V is installed: $hyperV" diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 7fa0d31a53..88517a942f 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -168,13 +168,13 @@ function Process-TestCompletion # Use Wait-Process for the process to terminate or timeout. # See https://stackoverflow.com/a/23797762 Wait-Process -InputObject $TestProcess -Timeout $TestHangTimeout -ErrorAction SilentlyContinue + Write-Log "(maige) Process-TestCompletion: Process exit code: $($TestProcess.ExitCode)" } catch { Write-Log "(CATCH) Process-TestCompletion: Failed to wait for $TestCommand" + Write-Log "(maige) Process-TestCompletion: Process exit code: $($TestProcess.ExitCode)" throw "Failed to wait for $TestCommand" } - Write-Log "(maige) Process-TestCompletion: Process exit code: $($TestProcess.ExitCode)" - if (-not $TestProcess.HasExited) { Write-Log "`n*** ERROR *** Test $TestCommand execution hang timeout ($TestHangTimeout seconds) expired.`n" From 22f08176d8c93aff23c2ff742be85211baeea029 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 30 Dec 2024 11:03:32 -0800 Subject: [PATCH 094/190] WIP --- .github/workflows/reusable-test.yml | 2 +- scripts/run_driver_tests.psm1 | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 2133224b5b..fef98a0250 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -95,7 +95,7 @@ jobs: id: configure-runner if: contains(inputs.environment, 'self-hosted') run: | - powershell.exe "cd C:\bin\CloudTestWorker\ProvisioningScript; dir; .\Setup_orig.ps1" + powershell.exe "Get-ChildItem 'C:\bin\CloudTestWorker' -Recurse; cd C:\bin\CloudTestWorker\ProvisioningScript; dir; .\Setup_orig.ps1" - name: Print CPU information run: diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 88517a942f..1650bcc4e6 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -172,6 +172,7 @@ function Process-TestCompletion } catch { Write-Log "(CATCH) Process-TestCompletion: Failed to wait for $TestCommand" Write-Log "(maige) Process-TestCompletion: Process exit code: $($TestProcess.ExitCode)" + Write-Log "(maige) Error: $_" throw "Failed to wait for $TestCommand" } @@ -396,7 +397,6 @@ function Invoke-XDPTest try { Write-Log "Executing $XDPTestName with remote address: $RemoteIPV4Address" - $TestRunScript = ".\Run-Self-Hosted-Runner-Test.ps1" $TestCommand = ".\xdp_tests.exe" $TestArguments = "$XDPTestName --remote-ip $RemoteIPV4Address" $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow @@ -404,10 +404,10 @@ function Invoke-XDPTest Write-Log "Failed to start $TestCommand with arguments $TestArguments" throw "Failed to start $TestCommand with arguments $TestArguments" } + Write-Log "maige1 - before Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand Write-Log "Executing $XDPTestName with remote address: $RemoteIPV6Address" - $TestRunScript = ".\Run-Self-Hosted-Runner-Test.ps1" $TestCommand = ".\xdp_tests.exe" $TestArguments = "$XDPTestName --remote-ip $RemoteIPV6Address" $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow @@ -415,6 +415,7 @@ function Invoke-XDPTest Write-Log "Failed to start $TestCommand with arguments $TestArguments" throw "Failed to start $TestCommand with arguments $TestArguments" } + Write-Log "maige2 - before Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand Write-Log "$XDPTestName Test Passed" -ForegroundColor Green From 72ded971b7a277df7163f1c4fcef61eaf59a2b68 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 30 Dec 2024 12:45:05 -0800 Subject: [PATCH 095/190] WIP --- 1es/prepare_vm_helpers.psm1 | 1 + 1 file changed, 1 insertion(+) diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index 3bbf64d565..045e4f9c05 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -342,6 +342,7 @@ function Create-VMSwitchIfNeeded { Log-Message "Successfully created $SwitchType switch with name: $SwitchName" -ForegroundColor Green } + function Create-VMStoredCredential { param ( [Parameter(Mandatory=$True)][string]$CredentialName, From 978b27a83db1d1107418f502fd4123f18d67f44c Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 31 Dec 2024 10:39:21 -0800 Subject: [PATCH 096/190] Previous version was entirely working. Move to 1es artifacts for testing --- .github/workflows/cicd.yml | 14 ++-- .github/workflows/reusable-test.yml | 4 +- 1es/Setup.ps1 | 103 +++++++++++++++++++++++----- 1es/Setup_orig.ps1 | 98 -------------------------- 1es/artifacts.json | 18 ++++- 5 files changed, 110 insertions(+), 127 deletions(-) delete mode 100644 1es/Setup_orig.ps1 diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index e0124388e5..3230f19f02 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -207,7 +207,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_ws2019 build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2019"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server-2019"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage @@ -226,7 +226,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_ws2022 build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2022"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server-2022"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage @@ -245,7 +245,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_native_only_ws2019 build_artifact: Build-x64-native-only - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2019"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server-2019"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage @@ -264,7 +264,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_native_only_ws2022 build_artifact: Build-x64-native-only - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2022"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server-2022"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage @@ -284,7 +284,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: regression_driver_ws2022 build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2022"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server-2022"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage @@ -584,7 +584,7 @@ jobs: test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Stress" post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2019"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server-2019"]' code_coverage: false # For this test, we only want kernel mode dumps and not user mode dumps. gather_dumps: false @@ -603,7 +603,7 @@ jobs: test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Stress" -Options @("RestartExtension") post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=ebpf-cicd-image-server-2019"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server-2019"]' code_coverage: false # For this test, we only want kernel mode dumps and not user mode dumps. gather_dumps: false diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index fef98a0250..35ff58f171 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -91,11 +91,11 @@ jobs: with: egress-policy: audit - - name: Configure runner (Move to setup script directly later) + - name: Check runner configuration (TODO possibly remove, if not needed) id: configure-runner if: contains(inputs.environment, 'self-hosted') run: | - powershell.exe "Get-ChildItem 'C:\bin\CloudTestWorker' -Recurse; cd C:\bin\CloudTestWorker\ProvisioningScript; dir; .\Setup_orig.ps1" + powershell.exe "Get-VM; Get-ChildItem 'C:\work' -Recurse;" - name: Print CPU information run: diff --git a/1es/Setup.ps1 b/1es/Setup.ps1 index c5d7a87dcd..b256d7a48d 100644 --- a/1es/Setup.ps1 +++ b/1es/Setup.ps1 @@ -1,33 +1,98 @@ # Copyright (c) eBPF for Windows contributors # SPDX-License-Identifier: MIT -# param( -# [Parameter(Mandatory=$False)][string]$VmUsername='Administrator', -# [Parameter(Mandatory=$False)][string]$VmPassword='P@ssw0rd', +param( + [Parameter(Mandatory=$False)][string]$VmUsername='Administrator', + [Parameter(Mandatory=$False)][string]$VmStandardUserName='VMStandardUser', + [Parameter(Mandatory=$False)][string]$VmPassword='P@ssw0rd', -# [Parameter(Mandatory=$False)][string]$BaseUnattendPath='.\unattend.xml', -# [Parameter(Mandatory=$False)][string]$BaseVhdDirPath='.\', -# [Parameter(Mandatory=$False)][string]$WorkingPath='.\working', -# [Parameter(Mandatory=$False)][string]$OutVhdDirPath='.\exported_vhds', -# [Parameter(Mandatory=$False)][string]$ExternalSwitchName='VMExternalSwitch', + [Parameter(Mandatory=$False)][string]$BaseUnattendPath='.\unattend.xml', + [Parameter(Mandatory=$False)][string]$BaseVhdDirPath='.\', + # [Parameter(Mandatory=$False)][string]$WorkingPath='.\working', + [Parameter(Mandatory=$False)][string]$WorkingPath='C:\vms', + # [Parameter(Mandatory=$False)][string]$OutVhdDirPath='.\exported_vhds', -# [Parameter(Mandatory=$False)][string]$VMCpuCount=4, -# [Parameter(Mandatory=$False)][string]$VMMemoryStartupBytes=512MB -# ) + [Parameter(Mandatory=$False)][string]$VMCpuCount=4, + [Parameter(Mandatory=$False)][string]$VMMemory=4096MB +) -# $ErrorActionPreference = "Stop" +$ErrorActionPreference = "Stop" # Import helper functions Import-Module .\prepare_vm_helpers.psm1 -Force -$hyperV = (Get-WindowsFeature -Name 'Hyper-V').Installed -Log-Message -Message "Hyper-V is installed: $hyperV" +if (-not (Test-Path -Path $BaseUnattendPath)) { + throw "Unattend file not found at $BaseUnattendPath" +} -$names = (Get-NetAdapter).Name -Log-Message -Message "Network adapters: $names" +if (-not (Test-Path -Path $BaseVhdDirPath)) { + throw "VHD directory not found at $BaseVhdDirPath" +} -$switches = Get-VMSwitch -Log-Message -Message "VM switches: $switches" +Create-VMSwitchIfNeeded -SwitchName 'VMInternalSwitch' -SwitchType 'Internal' +Create-VMSwitchIfNeeded -SwitchName 'VMExternalSwitch' -SwitchType 'External' +# Stored credentials doesn't seem to be working... +# Create-VMStoredCredential -CredentialName "TEST_VM" -Username $VmUsername -Password $VmPassword +# Create-VMStoredCredential -CredentialName "TEST_VM_STANDARD" -Username $VmStandardUserName -Password $VmPassword +Create-DirectoryIfNotExists -Path $WorkingPath +# Unzip any VHDs +Log-Message "Processing VHDs in $BaseVhdDirPath" +$zipFiles = Get-ChildItem -Path $BaseVhdDirPath -Filter *.zip +foreach ($zipFile in $zipFiles) { + Log-Message "Extracting VHDs from $($zipFile.FullName)" + $outDir = Join-Path -Path $BaseVhdDirPath -ChildPath $zipFile.BaseName + if (-not (Test-Path -Path $outDir)) { + Expand-Archive -Path $zipFile.FullName -DestinationPath $outDir + # Move the VHDs to the base directory + $vhdFiles = @() + $vhdFiles += Get-ChildItem -Path $outDir -Filter *.vhd -ErrorAction Ignore + $vhdFiles += Get-ChildItem -Path $outDir -Filter *.vhdx -ErrorAction Ignore + foreach ($vhdFile in $vhdFiles) { + Move-Item -Path $vhdFile.FullName -Destination $BaseVhdDirPath + } + } + Log-Message "Successfully processed $($zipFile.FullName)" +} -# TODO - eventually, setup_orig will become setup.ps1 \ No newline at end of file +# Read the input VHDs +$vhds = @() +$vhds += Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhd -ErrorAction Ignore +$vhds += Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhdx -ErrorAction Ignore +if ($vhds.Count -eq 0) { + throw "No VHDs found in $BaseVhdDirPath" +} +Log-Message "Successfully processed VHDs" + +for ($i = 0; $i -lt $vhds.Count; $i++) { + try { + $vhd = $vhds[$i] + Log-Message -Message "Creating VM from VHD: $($vhd.FullName)" + $vmName = "runner_vm" + if ($i -gt 0) { + $vmName += "_$i" + } + $outVMPath = Join-Path -Path $WorkingPath -ChildPath $VMName + + Create-VM ` + -VmName $vmName ` + -VhdPath $vhd.FullName ` + -VmStoragePath $outVMPath ` + -VMMemory $VMMemory ` + -UnattendPath $BaseUnattendPath ` + -VmUsername $VmUsername ` + -VmPassword $VmPassword + + Configure-VM ` + -VmName $vmName ` + -VmUsername $VmUsername ` + -VmPassword $VmPassword ` + -VMCpuCount $VMCpuCount + + Log-Message "VM $vmName created successfully" + } catch { + Log-Message "Failed to create VM $vmName with error $_" + } +} + +Log-Message "Setup.ps1 complete!" \ No newline at end of file diff --git a/1es/Setup_orig.ps1 b/1es/Setup_orig.ps1 deleted file mode 100644 index b256d7a48d..0000000000 --- a/1es/Setup_orig.ps1 +++ /dev/null @@ -1,98 +0,0 @@ -# Copyright (c) eBPF for Windows contributors -# SPDX-License-Identifier: MIT -param( - [Parameter(Mandatory=$False)][string]$VmUsername='Administrator', - [Parameter(Mandatory=$False)][string]$VmStandardUserName='VMStandardUser', - [Parameter(Mandatory=$False)][string]$VmPassword='P@ssw0rd', - - [Parameter(Mandatory=$False)][string]$BaseUnattendPath='.\unattend.xml', - [Parameter(Mandatory=$False)][string]$BaseVhdDirPath='.\', - # [Parameter(Mandatory=$False)][string]$WorkingPath='.\working', - [Parameter(Mandatory=$False)][string]$WorkingPath='C:\vms', - # [Parameter(Mandatory=$False)][string]$OutVhdDirPath='.\exported_vhds', - - [Parameter(Mandatory=$False)][string]$VMCpuCount=4, - [Parameter(Mandatory=$False)][string]$VMMemory=4096MB -) - -$ErrorActionPreference = "Stop" - -# Import helper functions -Import-Module .\prepare_vm_helpers.psm1 -Force - -if (-not (Test-Path -Path $BaseUnattendPath)) { - throw "Unattend file not found at $BaseUnattendPath" -} - -if (-not (Test-Path -Path $BaseVhdDirPath)) { - throw "VHD directory not found at $BaseVhdDirPath" -} - -Create-VMSwitchIfNeeded -SwitchName 'VMInternalSwitch' -SwitchType 'Internal' -Create-VMSwitchIfNeeded -SwitchName 'VMExternalSwitch' -SwitchType 'External' -# Stored credentials doesn't seem to be working... -# Create-VMStoredCredential -CredentialName "TEST_VM" -Username $VmUsername -Password $VmPassword -# Create-VMStoredCredential -CredentialName "TEST_VM_STANDARD" -Username $VmStandardUserName -Password $VmPassword -Create-DirectoryIfNotExists -Path $WorkingPath - -# Unzip any VHDs -Log-Message "Processing VHDs in $BaseVhdDirPath" -$zipFiles = Get-ChildItem -Path $BaseVhdDirPath -Filter *.zip -foreach ($zipFile in $zipFiles) { - Log-Message "Extracting VHDs from $($zipFile.FullName)" - $outDir = Join-Path -Path $BaseVhdDirPath -ChildPath $zipFile.BaseName - if (-not (Test-Path -Path $outDir)) { - Expand-Archive -Path $zipFile.FullName -DestinationPath $outDir - - # Move the VHDs to the base directory - $vhdFiles = @() - $vhdFiles += Get-ChildItem -Path $outDir -Filter *.vhd -ErrorAction Ignore - $vhdFiles += Get-ChildItem -Path $outDir -Filter *.vhdx -ErrorAction Ignore - foreach ($vhdFile in $vhdFiles) { - Move-Item -Path $vhdFile.FullName -Destination $BaseVhdDirPath - } - } - Log-Message "Successfully processed $($zipFile.FullName)" -} - -# Read the input VHDs -$vhds = @() -$vhds += Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhd -ErrorAction Ignore -$vhds += Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhdx -ErrorAction Ignore -if ($vhds.Count -eq 0) { - throw "No VHDs found in $BaseVhdDirPath" -} -Log-Message "Successfully processed VHDs" - -for ($i = 0; $i -lt $vhds.Count; $i++) { - try { - $vhd = $vhds[$i] - Log-Message -Message "Creating VM from VHD: $($vhd.FullName)" - $vmName = "runner_vm" - if ($i -gt 0) { - $vmName += "_$i" - } - $outVMPath = Join-Path -Path $WorkingPath -ChildPath $VMName - - Create-VM ` - -VmName $vmName ` - -VhdPath $vhd.FullName ` - -VmStoragePath $outVMPath ` - -VMMemory $VMMemory ` - -UnattendPath $BaseUnattendPath ` - -VmUsername $VmUsername ` - -VmPassword $VmPassword - - Configure-VM ` - -VmName $vmName ` - -VmUsername $VmUsername ` - -VmPassword $VmPassword ` - -VMCpuCount $VMCpuCount - - Log-Message "VM $vmName created successfully" - } catch { - Log-Message "Failed to create VM $vmName with error $_" - } -} - -Log-Message "Setup.ps1 complete!" \ No newline at end of file diff --git a/1es/artifacts.json b/1es/artifacts.json index 0acb5a104b..40651f9fcb 100644 --- a/1es/artifacts.json +++ b/1es/artifacts.json @@ -2,7 +2,23 @@ "license":["Copyright (c) eBPF for Windows contributors", "SPDX-License-Identifier: MIT"], "artifacts": [ { - "name": "windows-server-install-feature-hyperv" + "Name": "windows-server-install-feature-hyperv" + }, + { + "Name": "windows-azcopy-downloadfile-msi", + "Parameters": + { + "BlobUri": "https://ebpfcicdstorage.blob.core.windows.net/server-2019/*", + "Destination": "C:\\work", + "Identity": "/subscriptions/15cd5cd8-c222-405e-bb37-c5c6712a075f/resourceGroups/ebpf-cicd-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/ebpf-cicd-identity" + } + }, + { + "Name": "windows-powershell-invokecommand", + "Parameters": + { + "Script": "Get-ChildItem -Path 'C:\\work' -Recurse; cd 'C:\\work'; Invoke-Expression 'C:\\work\\Setup.ps1'" + } } ] } \ No newline at end of file From 1982e641d115e5fe2a601c4f44526767671c6701 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 31 Dec 2024 14:57:05 -0800 Subject: [PATCH 097/190] revert accidentally changed files --- libs/execution_context/ebpf_core.c | 9 ++++----- libs/execution_context/ebpf_maps.c | 2 +- libs/execution_context/ebpf_program.c | 3 ++- libs/runtime/ebpf_epoch.c | 5 +++-- libs/runtime/ebpf_platform.c | 4 +++- libs/service/api_service.cpp | 2 +- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/libs/execution_context/ebpf_core.c b/libs/execution_context/ebpf_core.c index f44a400366..d08b51c281 100644 --- a/libs/execution_context/ebpf_core.c +++ b/libs/execution_context/ebpf_core.c @@ -1203,9 +1203,8 @@ _ebpf_core_protocol_program_test_run_complete( { ebpf_operation_program_test_run_reply_t* reply = (ebpf_operation_program_test_run_reply_t*)completion_context; if (result == EBPF_SUCCESS) { - reply->header.length = (uint16_t)( - EBPF_OFFSET_OF(ebpf_operation_program_test_run_reply_t, data) + options->data_size_out + - options->context_size_out); + reply->header.length = (uint16_t)(EBPF_OFFSET_OF(ebpf_operation_program_test_run_reply_t, data) + + options->data_size_out + options->context_size_out); reply->return_value = options->return_value; reply->context_offset = (uint16_t)options->data_size_out; reply->duration = options->duration; @@ -1801,8 +1800,8 @@ _ebpf_core_protocol_serialize_map_info_reply( &required_serialization_length); if (result != EBPF_SUCCESS) { - map_info_reply->header.length = (uint16_t)( - required_serialization_length + EBPF_OFFSET_OF(ebpf_operation_get_pinned_map_info_reply_t, data)); + map_info_reply->header.length = (uint16_t)(required_serialization_length + + EBPF_OFFSET_OF(ebpf_operation_get_pinned_map_info_reply_t, data)); } else { map_info_reply->map_count = map_count; } diff --git a/libs/execution_context/ebpf_maps.c b/libs/execution_context/ebpf_maps.c index 66a15a8027..68cddb9a0d 100644 --- a/libs/execution_context/ebpf_maps.c +++ b/libs/execution_context/ebpf_maps.c @@ -144,7 +144,7 @@ typedef uint8_t* ebpf_lru_entry_t; ((uint8_t*)(((uint8_t*)entry) + EBPF_LRU_ENTRY_KEY_OFFSET(map->partition_count))) #define EBPF_LOG_MAP_OPERATION(flags, operation, map, key) \ - if (((flags)&EBPF_MAP_FLAG_HELPER) && (map)->ebpf_map_definition.key_size != 0) { \ + if (((flags) & EBPF_MAP_FLAG_HELPER) && (map)->ebpf_map_definition.key_size != 0) { \ EBPF_LOG_MESSAGE_UTF8_STRING( \ EBPF_TRACELOG_LEVEL_VERBOSE, EBPF_TRACELOG_KEYWORD_MAP, "Map "##operation, &(map)->name); \ EBPF_LOG_MESSAGE_BINARY( \ diff --git a/libs/execution_context/ebpf_program.c b/libs/execution_context/ebpf_program.c index 7f867e166c..24aed2a872 100644 --- a/libs/execution_context/ebpf_program.c +++ b/libs/execution_context/ebpf_program.c @@ -171,7 +171,8 @@ ebpf_program_initiate() void ebpf_program_terminate() -{} +{ +} _Requires_lock_not_held_(program->lock) static void _ebpf_program_detach_links(_Inout_ ebpf_program_t* program) { diff --git a/libs/runtime/ebpf_epoch.c b/libs/runtime/ebpf_epoch.c index 0face817b2..ef0e69c369 100644 --- a/libs/runtime/ebpf_epoch.c +++ b/libs/runtime/ebpf_epoch.c @@ -453,13 +453,14 @@ __drv_allocatesMem(Mem) _Must_inspect_result_ return header; } -_Must_inspect_result_ _Ret_writes_maybenull_(size) void* ebpf_epoch_allocate(size_t size) +_Must_inspect_result_ +_Ret_writes_maybenull_(size) void* ebpf_epoch_allocate(size_t size) { return ebpf_epoch_allocate_with_tag(size, EBPF_POOL_TAG_EPOCH); } _Must_inspect_result_ - _Ret_writes_maybenull_(size) void* ebpf_epoch_allocate_cache_aligned_with_tag(size_t size, uint32_t tag) +_Ret_writes_maybenull_(size) void* ebpf_epoch_allocate_cache_aligned_with_tag(size_t size, uint32_t tag) { ebpf_assert(size); ebpf_epoch_allocation_header_t* header; diff --git a/libs/runtime/ebpf_platform.c b/libs/runtime/ebpf_platform.c index 2c10cc92cc..78c43d89d7 100644 --- a/libs/runtime/ebpf_platform.c +++ b/libs/runtime/ebpf_platform.c @@ -39,7 +39,9 @@ ebpf_lock_destroy(_In_ _Post_invalid_ ebpf_lock_t* lock) } _Requires_lock_not_held_(*lock) _Acquires_lock_(*lock) _IRQL_requires_max_(DISPATCH_LEVEL) _IRQL_saves_ - _IRQL_raises_(DISPATCH_LEVEL) ebpf_lock_state_t ebpf_lock_lock(_Inout_ ebpf_lock_t* lock) + _IRQL_raises_(DISPATCH_LEVEL) +ebpf_lock_state_t +ebpf_lock_lock(_Inout_ ebpf_lock_t* lock) { KIRQL old_irql = KeGetCurrentIrql(); diff --git a/libs/service/api_service.cpp b/libs/service/api_service.cpp index c13a47a84d..5dbc056e0f 100644 --- a/libs/service/api_service.cpp +++ b/libs/service/api_service.cpp @@ -364,7 +364,7 @@ ebpf_verify_and_load_program( } ubpf_set_error_print( - vm, reinterpret_cast<int (*)(FILE * stream, const char* format, ...)>(log_function_address)); + vm, reinterpret_cast<int (*)(FILE* stream, const char* format, ...)>(log_function_address)); if (ubpf_load( vm, byte_code_data, static_cast<uint32_t>(byte_code_size), const_cast<char**>(error_message)) < 0) { From 8dc3082476bfbc4030c338c18f9536c6e4703570 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 31 Dec 2024 15:18:31 -0800 Subject: [PATCH 098/190] Remove some debugging logs, attempt to fix stress tests --- scripts/common.psm1 | 43 ++++-------- scripts/config_test_vm.psm1 | 39 +++++------ scripts/run_driver_tests.psm1 | 106 +++++++++++++++--------------- scripts/setup_ebpf_cicd_tests.ps1 | 6 ++ 4 files changed, 86 insertions(+), 108 deletions(-) diff --git a/scripts/common.psm1 b/scripts/common.psm1 index 2842653d74..ea215cff72 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -61,42 +61,23 @@ function Compress-File # Retry 3 times to ensure compression operation succeeds. # To mitigate error message: "The process cannot access the file <filename> because it is being used by another process." $retryCount = 1 - while ($retryCount -lt 6) { - try { - $error.clear() - Compress-Archive ` - -Path $SourcePath ` - -DestinationPath $DestinationPath ` - -CompressionLevel Fastest ` - -Force - if ($error[0] -ne $null) { - $ErrorMessage = "*** ERROR *** Failed to compress kernel mode dump files: $error. Retrying $retryCount" - Write-Output $ErrorMessage - Start-Sleep -seconds (5 * $retryCount) - $retryCount++ - } else { - # Compression succeeded. - if (Test-Path $DestinationPath) { - Write-Log "Successfully compressed $SourcePath -> $DestinationPath" - break; - } else { - $ErrorMessage = "*** ERROR *** Failed to compress kernel mode dump files: $error. Retrying $retryCount" - Write-Output $ErrorMessage - Start-Sleep -seconds (5 * $retryCount) - $retryCount++ - } - } - } catch { - $ErrorMessage = "*** ERROR *** Failed to compress kernel mode dump files: $_. Retrying $retryCount" + while ($retryCount -lt 4) { + $error.clear() + Compress-Archive ` + -Path $SourcePath ` + -DestinationPath $DestinationPath ` + -CompressionLevel Fastest ` + -Force + if ($error[0] -ne $null) { + $ErrorMessage = "*** ERROR *** Failed to compress kernel mode dump files: $error. Retrying $retryCount" Write-Output $ErrorMessage Start-Sleep -seconds (5 * $retryCount) $retryCount++ + } else { + # Compression succeeded. + break; } } - - if (!(Test-Path $DestinationPath)) { - Write-Log "Failed to compress kernel mode dump files after retries" - } } function Wait-TestJobToComplete diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index f265e3417d..c7028dcb6d 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -540,29 +540,6 @@ function Initialize-NetworkInterfacesOnVMs # Disable Duonic's fake checksum offload and force TCP/IP to calculate it. Set-NetAdapterAdvancedProperty duo? -DisplayName Checksum -RegistryValue 0 - # TODO - remove this debugging output - ipconfig /all - Get-NetIPInterface | Out-String - Get-NetAdapter | Out-String - Get-NetAdapterBinding -AllBindings | Out-String - - # Loop through each adapter and enable IPv4 and IPv6 - $adapters = Get-NetAdapter - foreach ($adapter in $adapters) { - try { - # Enable IPv4 (usually enabled by default) - Enable-NetAdapterBinding -Name $adapter.Name -ComponentID ms_tcpip - - # Enable IPv6 - Enable-NetAdapterBinding -Name $adapter.Name -ComponentID ms_tcpip6 - - Write-Host "Enabled IPv4 and IPv6 on adapter: $($adapter.Name)" - } catch { - Write-Host "Failed to enable IPv4 and IPv6 on adapter: $($adapter.Name)" - } - } - Get-NetAdapterBinding -AllBindings | Out-String - Pop-Location } -ArgumentList ("eBPF", $LogFileName) -ErrorAction Stop } @@ -715,4 +692,20 @@ function Get-PSExec { cd .. Move-Item -Path "$DownloadPath\PSTools\PsExec64.exe" -Destination $pwd -Force Remove-Item -Path $DownloadPath -Force -Recurse +} + +# +# Queries registry for OS build information and logs it. +# +function Log-OSBuildInformationOnVM +{ + param([parameter(Mandatory=$true)][string] $VMName) + + Write-Log "Logging OS build information on $VMName" + $TestCredential = New-Credential -Username $Admin -AdminPassword $AdminPassword + Invoke-Command -VMName $VMName -Credential $TestCredential -ScriptBlock { + $buildLabEx = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name 'BuildLabEx' + Write-Output "OS Build Information: $($buildLabEx.BuildLabEx)" + } + Write-Log "Finished logging OS build informatino on $VMName" -ForegroundColor Green } \ No newline at end of file diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 1650bcc4e6..9952c14977 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -157,24 +157,25 @@ function Process-TestCompletion [Parameter(Mandatory = $false)] [int] $TestHangTimeout = (10*60), # 10 minutes default timeout. [Parameter(Mandatory = $false)] [bool] $NeedKernelDump = $true) - Write-Log "(maige) Process-TestCompletion (maige)" - Write-Log "Process-TestCompletion (maige) invoked for $TestCommand" - if ($TestProcess -eq $null) { - Write-Log "Process-TestCompletion: Failed to start $TestCommand" - throw "Failed to start $TestCommand" - } - - try { - # Use Wait-Process for the process to terminate or timeout. - # See https://stackoverflow.com/a/23797762 - Wait-Process -InputObject $TestProcess -Timeout $TestHangTimeout -ErrorAction SilentlyContinue - Write-Log "(maige) Process-TestCompletion: Process exit code: $($TestProcess.ExitCode)" - } catch { - Write-Log "(CATCH) Process-TestCompletion: Failed to wait for $TestCommand" - Write-Log "(maige) Process-TestCompletion: Process exit code: $($TestProcess.ExitCode)" - Write-Log "(maige) Error: $_" - throw "Failed to wait for $TestCommand" - } + # Write-Log "(maige) Process-TestCompletion (maige)" + # Write-Log "Process-TestCompletion (maige) invoked for $TestCommand" + # if ($TestProcess -eq $null) { + # Write-Log "Process-TestCompletion: Failed to start $TestCommand" + # throw "Failed to start $TestCommand" + # } + + # try { + # # Use Wait-Process for the process to terminate or timeout. + # # See https://stackoverflow.com/a/23797762 + # Wait-Process -InputObject $TestProcess -Timeout $TestHangTimeout -ErrorAction SilentlyContinue + # Write-Log "(maige) Process-TestCompletion: Process exit code: $($TestProcess.ExitCode)" + # } catch { + # Write-Log "(CATCH) Process-TestCompletion: Failed to wait for $TestCommand" + # Write-Log "(maige) Process-TestCompletion: Process exit code: $($TestProcess.ExitCode)" + # Write-Log "(maige) Error: $_" + # throw "Failed to wait for $TestCommand" + # } + Wait-Process -InputObject $TestProcess -Timeout $TestHangTimeout -ErrorAction SilentlyContinue if (-not $TestProcess.HasExited) { Write-Log "`n*** ERROR *** Test $TestCommand execution hang timeout ($TestHangTimeout seconds) expired.`n" @@ -203,23 +204,24 @@ function Process-TestCompletion Write-Log "Throwing TestHungException for $TestCommand" -ForegroundColor Red throw [System.TimeoutException]::new("Test $TestCommand execution hang timeout ($TestHangTimeout seconds) expired.") } else { - Write-Log "Process-TestCompletion: command should have completed" - try { - $currExitCode = $TestProcess.ExitCode - $temp = $TestProcess | Out-String - Write-Log "Maige - test output: $temp" - Write-Log "MAIGE - $TestCommand exited with code $currExitCode" - } catch { - Write-Log "maige - failed" - } + Write-Log "(maige) Process-TestCompletion: command should have completed" + # try { + # $currExitCode = $TestProcess.ExitCode + # $temp = $TestProcess | Out-String + # Write-Log "Maige - test output: $temp" + # Write-Log "MAIGE - $TestCommand exited with code $currExitCode" + # } catch { + # Write-Log "maige - failed" + # } - # # Ensure the process has completely exited. - # Wait-Process -InputObject $TestProcess # $currExitCode = $TestProcess.ExitCode # $temp = $TestProcess | Out-String # Write-Log "Maige - test output: $temp" # Write-Log "MAIGE - $TestCommand exited with code $currExitCode" + # Ensure the process has completely exited. + Wait-Process -InputObject $TestProcess + # Read and display the output (if any) from the temporary output file. $TempOutputFile = "$env:TEMP\app_output.log" # Log for standard output # Process the log file line-by-line @@ -232,9 +234,9 @@ function Process-TestCompletion } $TestExitCode = $TestProcess.ExitCode - Write-Log "Maige - Test exit code: $TestExitCode" - if ($TestExitCode -ne $null -and $TestExitCode -ne 0) { - # if ($TestExitCode -ne 0) { + # Write-Log "Maige - Test exit code: $TestExitCode" + # if ($TestExitCode -ne $null -and $TestExitCode -ne 0) { + if ($TestExitCode -ne 0) { $TempErrorFile = "$env:TEMP\app_error.log" # Log for standard error if ((Test-Path $TempErrorFile) -and (Get-Item $TempErrorFile).Length -gt 0) { Write-Log "$TestCommand Error Output:`n" -ForegroundColor Red @@ -322,7 +324,7 @@ function Invoke-Test Write-Log "`n==============================`n" } catch { $ErrorMessage = $_.Exception.Message - ThrowWithErrorMessage -ErrorMessage "Test `"$TestName $TestArgs`" Failed with $ErrorMessage" + ThrowWithErrorMessage -ErrorMessage "(maige) Test `"$TestName $TestArgs`" Failed with $ErrorMessage" } } @@ -400,10 +402,10 @@ function Invoke-XDPTest $TestCommand = ".\xdp_tests.exe" $TestArguments = "$XDPTestName --remote-ip $RemoteIPV4Address" $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - if ($TestProcess -eq $null) { - Write-Log "Failed to start $TestCommand with arguments $TestArguments" - throw "Failed to start $TestCommand with arguments $TestArguments" - } + # if ($TestProcess -eq $null) { + # Write-Log "Failed to start $TestCommand with arguments $TestArguments" + # throw "Failed to start $TestCommand with arguments $TestArguments" + # } Write-Log "maige1 - before Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand @@ -411,10 +413,10 @@ function Invoke-XDPTest $TestCommand = ".\xdp_tests.exe" $TestArguments = "$XDPTestName --remote-ip $RemoteIPV6Address" $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - if ($TestProcess -eq $null) { - Write-Log "Failed to start $TestCommand with arguments $TestArguments" - throw "Failed to start $TestCommand with arguments $TestArguments" - } + # if ($TestProcess -eq $null) { + # Write-Log "Failed to start $TestCommand with arguments $TestArguments" + # throw "Failed to start $TestCommand with arguments $TestArguments" + # } Write-Log "maige2 - before Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand @@ -445,7 +447,6 @@ function Invoke-ConnectRedirectTest Push-Location $WorkingDirectory - try { $TestRunScript = ".\Run-Self-Hosted-Runner-Test.ps1" $TestCommand = ".\connect_redirect_tests.exe" @@ -501,11 +502,8 @@ function Invoke-ConnectRedirectTest $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand + Write-Log "Connect-Redirect Test Passed" -ForegroundColor Green - } catch { - $ErrorMessage = $_.Exception.Message - ThrowWithErrorMessage -ErrorMessage "Connect-Redirect Test Failed with $ErrorMessage" - } Pop-Location } @@ -525,7 +523,7 @@ function Invoke-CICDStressTests $LASTEXITCODE = 0 - $TestCommand = "ebpf_stress_tests_km.exe" + $TestCommand = ".\ebpf_stress_tests_km.exe" $TestArguments = " " if ($RestartExtension -eq $false) { $TestArguments = "-tt=8 -td=5" @@ -540,15 +538,15 @@ function Invoke-CICDStressTests Get-ChildItem $WorkingDirectory Write-Log "Starting $TestCommand with arguments: $TestArguments" - # Valid that the test command exists. - if (-not (Test-Path $TestCommand)) { - ThrowWithErrorMessage -ErrorMessage "*** ERROR *** $TestCommand not found under $WorkingDirectory." - } + # # Valid that the test command exists. + # if (-not (Test-Path $TestCommand)) { + # ThrowWithErrorMessage -ErrorMessage "*** ERROR *** $TestCommand not found under $WorkingDirectory." + # } $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - if ($TestProcess -eq $null) { - ThrowWithErrorMessage -ErrorMessage "*** ERROR *** Failed to start $TestCommand." - } + # if ($TestProcess -eq $null) { + # ThrowWithErrorMessage -ErrorMessage "*** ERROR *** Failed to start $TestCommand." + # } Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index f5f2fa6d9b..c1c558c399 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -84,6 +84,12 @@ $Job = Start-Job -ScriptBlock { Install-eBPFComponentsOnVM -VMName $VMname -TestMode $TestMode -KmTracing $KmTracing -KmTraceType $KmTraceType -ErrorAction Stop } + # Log OS build information on the test VM. + foreach($VM in $VMList) { + $VMName = $VM.Name + Log-OSBuildInformationOnVM -VMName $VMName -ErrorAction Stop + } + Pop-Location } -ArgumentList ( $TestVMCredential, From 74413ee4ab2263e45a824ffdb9931de43cfe5f68 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 31 Dec 2024 16:36:25 -0800 Subject: [PATCH 099/190] test out failing fix --- scripts/run_driver_tests.psm1 | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 9952c14977..cc1e41b699 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -205,22 +205,22 @@ function Process-TestCompletion throw [System.TimeoutException]::new("Test $TestCommand execution hang timeout ($TestHangTimeout seconds) expired.") } else { Write-Log "(maige) Process-TestCompletion: command should have completed" - # try { - # $currExitCode = $TestProcess.ExitCode - # $temp = $TestProcess | Out-String - # Write-Log "Maige - test output: $temp" - # Write-Log "MAIGE - $TestCommand exited with code $currExitCode" - # } catch { - # Write-Log "maige - failed" - # } + try { + $currExitCode = $TestProcess.ExitCode + $temp = $TestProcess | Out-String + Write-Log "Maige - test output: $temp" + Write-Log "MAIGE - $TestCommand exited with code $currExitCode" + } catch { + Write-Log "maige - failed" + } # $currExitCode = $TestProcess.ExitCode # $temp = $TestProcess | Out-String # Write-Log "Maige - test output: $temp" # Write-Log "MAIGE - $TestCommand exited with code $currExitCode" - # Ensure the process has completely exited. - Wait-Process -InputObject $TestProcess + # # Ensure the process has completely exited. + # Wait-Process -InputObject $TestProcess # Read and display the output (if any) from the temporary output file. $TempOutputFile = "$env:TEMP\app_output.log" # Log for standard output From 5af0e436ba0ad82b67b38e6a486bcc7410ab10ee Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 31 Dec 2024 17:26:10 -0800 Subject: [PATCH 100/190] two commits back seemed to be working, testing this --- scripts/run_driver_tests.psm1 | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index cc1e41b699..fc5515485d 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -205,22 +205,22 @@ function Process-TestCompletion throw [System.TimeoutException]::new("Test $TestCommand execution hang timeout ($TestHangTimeout seconds) expired.") } else { Write-Log "(maige) Process-TestCompletion: command should have completed" - try { - $currExitCode = $TestProcess.ExitCode - $temp = $TestProcess | Out-String - Write-Log "Maige - test output: $temp" - Write-Log "MAIGE - $TestCommand exited with code $currExitCode" - } catch { - Write-Log "maige - failed" - } + # try { + # $currExitCode = $TestProcess.ExitCode + # $temp = $TestProcess | Out-String + # Write-Log "Maige - test output: $temp" + # Write-Log "MAIGE - $TestCommand exited with code $currExitCode" + # } catch { + # Write-Log "maige - failed" + # } # $currExitCode = $TestProcess.ExitCode # $temp = $TestProcess | Out-String # Write-Log "Maige - test output: $temp" # Write-Log "MAIGE - $TestCommand exited with code $currExitCode" - # # Ensure the process has completely exited. - # Wait-Process -InputObject $TestProcess + # Ensure the process has completely exited. + Wait-Process -InputObject $TestProcess # Read and display the output (if any) from the temporary output file. $TempOutputFile = "$env:TEMP\app_output.log" # Log for standard output @@ -234,9 +234,9 @@ function Process-TestCompletion } $TestExitCode = $TestProcess.ExitCode - # Write-Log "Maige - Test exit code: $TestExitCode" - # if ($TestExitCode -ne $null -and $TestExitCode -ne 0) { - if ($TestExitCode -ne 0) { + Write-Log "Maige - Test exit code: $TestExitCode" + if ($TestExitCode -ne $null -and $TestExitCode -ne 0) { + # if ($TestExitCode -ne 0) { $TempErrorFile = "$env:TEMP\app_error.log" # Log for standard error if ((Test-Path $TempErrorFile) -and (Get-Item $TempErrorFile).Length -gt 0) { Write-Log "$TestCommand Error Output:`n" -ForegroundColor Red From 1bca22591bbbd8237f46329364da4c801ebc6494 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 2 Jan 2025 09:17:30 -0800 Subject: [PATCH 101/190] wip --- scripts/run_driver_tests.psm1 | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index fc5515485d..1b555291a4 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -205,22 +205,23 @@ function Process-TestCompletion throw [System.TimeoutException]::new("Test $TestCommand execution hang timeout ($TestHangTimeout seconds) expired.") } else { Write-Log "(maige) Process-TestCompletion: command should have completed" - # try { - # $currExitCode = $TestProcess.ExitCode - # $temp = $TestProcess | Out-String - # Write-Log "Maige - test output: $temp" - # Write-Log "MAIGE - $TestCommand exited with code $currExitCode" - # } catch { - # Write-Log "maige - failed" - # } + try { + $currExitCode = $TestProcess.ExitCode + $temp = $TestProcess | Out-String + Write-Log "Maige - test output: $temp" + Write-Log "MAIGE - $TestCommand exited with code $currExitCode" + Write-Log "maige3 - In Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" + } catch { + Write-Log "maige - failed" + } # $currExitCode = $TestProcess.ExitCode # $temp = $TestProcess | Out-String # Write-Log "Maige - test output: $temp" # Write-Log "MAIGE - $TestCommand exited with code $currExitCode" - # Ensure the process has completely exited. - Wait-Process -InputObject $TestProcess + # # Ensure the process has completely exited. + # Wait-Process -InputObject $TestProcess # Read and display the output (if any) from the temporary output file. $TempOutputFile = "$env:TEMP\app_output.log" # Log for standard output From 67ff5c6542506d76aae2b57f8f42948d47090a9a Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 2 Jan 2025 10:15:15 -0800 Subject: [PATCH 102/190] wip --- scripts/run_driver_tests.psm1 | 60 +++++++++++++++-------------------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 1b555291a4..cc1a107ae6 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -205,23 +205,15 @@ function Process-TestCompletion throw [System.TimeoutException]::new("Test $TestCommand execution hang timeout ($TestHangTimeout seconds) expired.") } else { Write-Log "(maige) Process-TestCompletion: command should have completed" - try { - $currExitCode = $TestProcess.ExitCode - $temp = $TestProcess | Out-String - Write-Log "Maige - test output: $temp" - Write-Log "MAIGE - $TestCommand exited with code $currExitCode" - Write-Log "maige3 - In Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" - } catch { - Write-Log "maige - failed" - } - - # $currExitCode = $TestProcess.ExitCode - # $temp = $TestProcess | Out-String - # Write-Log "Maige - test output: $temp" - # Write-Log "MAIGE - $TestCommand exited with code $currExitCode" - - # # Ensure the process has completely exited. - # Wait-Process -InputObject $TestProcess + # try { + # $currExitCode = $TestProcess.ExitCode + # $temp = $TestProcess | Out-String + # Write-Log "Maige - test output: $temp" + # Write-Log "MAIGE - $TestCommand exited with code $currExitCode" + # Write-Log "maige3 - In Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" + # } catch { + # Write-Log "maige - failed" + # } # Read and display the output (if any) from the temporary output file. $TempOutputFile = "$env:TEMP\app_output.log" # Log for standard output @@ -237,7 +229,6 @@ function Process-TestCompletion $TestExitCode = $TestProcess.ExitCode Write-Log "Maige - Test exit code: $TestExitCode" if ($TestExitCode -ne $null -and $TestExitCode -ne 0) { - # if ($TestExitCode -ne 0) { $TempErrorFile = "$env:TEMP\app_error.log" # Log for standard error if ((Test-Path $TempErrorFile) -and (Get-Item $TempErrorFile).Length -gt 0) { Write-Log "$TestCommand Error Output:`n" -ForegroundColor Red @@ -295,7 +286,7 @@ function Invoke-Test [Parameter(Mandatory = $True)][bool] $VerboseLogs, [Parameter(Mandatory = $True)][int] $TestHangTimeout) - try { + # try { # Initialize arguments. if ($TestArgs -ne "") { $ArgumentsList = @($TestArgs) @@ -323,10 +314,10 @@ function Invoke-Test Write-Log "Test `"$TestName $TestArgs`" Passed" -ForegroundColor Green Write-Log "`n==============================`n" - } catch { - $ErrorMessage = $_.Exception.Message - ThrowWithErrorMessage -ErrorMessage "(maige) Test `"$TestName $TestArgs`" Failed with $ErrorMessage" - } + # } catch { + # $ErrorMessage = $_.Exception.Message + # ThrowWithErrorMessage -ErrorMessage "(maige) Test `"$TestName $TestArgs`" Failed with $ErrorMessage" + # } } # Function to create a tuple with default values for Arguments and Timeout @@ -398,7 +389,7 @@ function Invoke-XDPTest Push-Location $WorkingDirectory - try { + # try { Write-Log "Executing $XDPTestName with remote address: $RemoteIPV4Address" $TestCommand = ".\xdp_tests.exe" $TestArguments = "$XDPTestName --remote-ip $RemoteIPV4Address" @@ -407,7 +398,7 @@ function Invoke-XDPTest # Write-Log "Failed to start $TestCommand with arguments $TestArguments" # throw "Failed to start $TestCommand with arguments $TestArguments" # } - Write-Log "maige1 - before Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" + # Write-Log "maige1 - before Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand Write-Log "Executing $XDPTestName with remote address: $RemoteIPV6Address" @@ -418,15 +409,15 @@ function Invoke-XDPTest # Write-Log "Failed to start $TestCommand with arguments $TestArguments" # throw "Failed to start $TestCommand with arguments $TestArguments" # } - Write-Log "maige2 - before Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" + # Write-Log "maige2 - before Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand Write-Log "$XDPTestName Test Passed" -ForegroundColor Green Write-Log "`n`n" - } catch { - $ErrorMessage = $_.Exception.Message - ThrowWithErrorMessage -ErrorMessage "(maige) XDP test Failed with $ErrorMessage" - } + # } catch { + # $ErrorMessage = $_.Exception.Message + # ThrowWithErrorMessage -ErrorMessage "(maige) XDP test Failed with $ErrorMessage" + # } Pop-Location } @@ -533,12 +524,11 @@ function Invoke-CICDStressTests } # TODO - remove debugging output - Write-Log "Items from .\" - Get-ChildItem '.\' - Write-Log "Items from $WorkingDirectory" - Get-ChildItem $WorkingDirectory + # Write-Log "Items from .\" + # Get-ChildItem '.\' + # Write-Log "Items from $WorkingDirectory" + # Get-ChildItem $WorkingDirectory Write-Log "Starting $TestCommand with arguments: $TestArguments" - # # Valid that the test command exists. # if (-not (Test-Path $TestCommand)) { # ThrowWithErrorMessage -ErrorMessage "*** ERROR *** $TestCommand not found under $WorkingDirectory." From b5cae860ec6b4777d2711f52aca93ecc8becfeaa Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 2 Jan 2025 11:51:37 -0800 Subject: [PATCH 103/190] Test with Azure Key vault instead of PS stored credential --- 1es/Setup.ps1 | 13 +++++--- 1es/prepare_vm_helpers.psm1 | 21 +++++++------ scripts/cleanup_ebpf_cicd_tests.ps1 | 8 +---- scripts/common.psm1 | 49 +++++++++++++++++------------ scripts/execute_ebpf_cicd_tests.ps1 | 11 ++----- scripts/run_driver_tests.psm1 | 5 +++ scripts/setup_ebpf_cicd_tests.ps1 | 8 +---- 7 files changed, 58 insertions(+), 57 deletions(-) diff --git a/1es/Setup.ps1 b/1es/Setup.ps1 index b256d7a48d..4c903e8f15 100644 --- a/1es/Setup.ps1 +++ b/1es/Setup.ps1 @@ -29,10 +29,14 @@ if (-not (Test-Path -Path $BaseVhdDirPath)) { } Create-VMSwitchIfNeeded -SwitchName 'VMInternalSwitch' -SwitchType 'Internal' -Create-VMSwitchIfNeeded -SwitchName 'VMExternalSwitch' -SwitchType 'External' +# Create-VMSwitchIfNeeded -SwitchName 'VMExternalSwitch' -SwitchType 'External' # Stored credentials doesn't seem to be working... -# Create-VMStoredCredential -CredentialName "TEST_VM" -Username $VmUsername -Password $VmPassword -# Create-VMStoredCredential -CredentialName "TEST_VM_STANDARD" -Username $VmStandardUserName -Password $VmPassword + +# TODO - switch to azure key vault, once we validate on CICD? +# $keyVaultValue = Get-AzKeyVaultSecret -VaultName "kobulloc-keyvaultAZPS" -Name "ExampleAZPSPassword" +# $keyVaultValue.SecretValue | ConvertFrom-SecureString -AsPlainText +Create-VMStoredCredential -CredentialName "TEST_VM" -Username $VmUsername -Password $VmPassword +Create-VMStoredCredential -CredentialName "TEST_VM_STANDARD" -Username $VmStandardUserName -Password $VmPassword Create-DirectoryIfNotExists -Path $WorkingPath # Unzip any VHDs @@ -81,7 +85,8 @@ for ($i = 0; $i -lt $vhds.Count; $i++) { -VMMemory $VMMemory ` -UnattendPath $BaseUnattendPath ` -VmUsername $VmUsername ` - -VmPassword $VmPassword + -VmPassword $VmPassword ` + -VMSwitchName 'VMInternalSwitch' Configure-VM ` -VmName $vmName ` diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index 045e4f9c05..5f6f57a3cc 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -150,7 +150,8 @@ function Create-VM { [Parameter(Mandatory=$True)][string]$VhdPath, [Parameter(Mandatory=$True)][string]$VmStoragePath, [Parameter(Mandatory=$True)][Int64]$VMMemory, - [Parameter(Mandatory=$True)][string]$UnattendPath + [Parameter(Mandatory=$True)][string]$UnattendPath, + [Parameter(Mandatory=$True)][string]$VmSwitchName ) try { @@ -189,12 +190,12 @@ function Create-VM { # Create the VM Log-Message "Creating the VM" - New-VM -Name $VmName -VhdPath $VmVhdPath - $vmSwitches = Get-VMSwitch -ErrorAction Ignore - foreach ($switch in $vmSwitches) { - Log-Message "Adding network adapter to VM: $VmName with switch: $($switch.Name)" - Add-VMNetworkAdapter -VMName $VmName -SwitchName $switch.Name - } + New-VM -Name $VmName -VhdPath $VmVhdPath -SwitchName $VmSwitchName + # $vmSwitches = Get-VMSwitch -ErrorAction Ignore + # foreach ($switch in $vmSwitches) { + # Log-Message "Adding network adapter to VM: $VmName with switch: $($switch.Name)" + # Add-VMNetworkAdapter -VMName $VmName -SwitchName $switch.Name + # } Set-VMMemory -VMName $VmName -DynamicMemoryEnabled $false -StartupBytes $VMMemory if ((Get-VM -VMName $vmName) -eq $null) { @@ -295,6 +296,7 @@ function Create-VMSwitchIfNeeded { [Parameter(Mandatory=$true)][string]$SwitchName, [Parameter(Mandatory=$true)][string]$SwitchType ) + if ($SwitchType -eq 'External') { # Check to see if an external switch already exists $ExternalSwitches = (Get-VMSwitch -SwitchType External -ErrorAction Ignore) @@ -322,7 +324,7 @@ function Create-VMSwitchIfNeeded { } } elseif ($SwitchType -eq 'Internal') { # Check to see if an internal switch already exists - $InternalSwitches = (Get-VMSwitch -SwitchType Internal -ErrorAction Ignore) + $InternalSwitches = (Get-VMSwitch -SwitchType Internal -Name $SwitchName -ErrorAction Ignore) if ($InternalSwitches -ne $null) { Log-Message -Message "Internal switch already exists: $($InternalSwitches[0].Name)" return @@ -331,7 +333,7 @@ function Create-VMSwitchIfNeeded { # Try to create the internal switch try { Log-Message "Creating internal switch" - New-VMSwitch -Name 'VMInternalSwitch' -SwitchType Internal + New-VMSwitch -Name $SwitchName -SwitchType Internal } catch { throw "Failed to create internal switch with error: $_" } @@ -342,7 +344,6 @@ function Create-VMSwitchIfNeeded { Log-Message "Successfully created $SwitchType switch with name: $SwitchName" -ForegroundColor Green } - function Create-VMStoredCredential { param ( [Parameter(Mandatory=$True)][string]$CredentialName, diff --git a/scripts/cleanup_ebpf_cicd_tests.ps1 b/scripts/cleanup_ebpf_cicd_tests.ps1 index bc6e0698cb..d51652001a 100644 --- a/scripts/cleanup_ebpf_cicd_tests.ps1 +++ b/scripts/cleanup_ebpf_cicd_tests.ps1 @@ -14,13 +14,7 @@ Push-Location $WorkingDirectory Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue $SelfHostedRunnerName = "runner_host" Write-Host "SelfHostedRunnerName: $SelfHostedRunnerName, Target: $Target" -try { - $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop -} catch { - Write-Host "Failed to get credentials for $Target. Using default credentials." - $securePassword = ConvertTo-SecureString -String "P@ssw0rd" -AsPlainText -Force - $TestVMCredential = New-Credential -UserName 'Administrator' -AdminPassword $securePassword -} +$TestVMCredential = Get-AzureKeyVaultCredential -SecretName'Administrator' # Read the test execution json. $Config = Get-Content ("{0}\{1}" -f $PSScriptRoot, $TestExecutionJsonFileName) | ConvertFrom-Json diff --git a/scripts/common.psm1 b/scripts/common.psm1 index ea215cff72..80de716d63 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -3,12 +3,6 @@ param ([parameter(Mandatory=$True)] [string] $LogFileName) -try { - Import-Module CredentialManager -Force -ErrorAction Ignore -} catch { - Write-Host "Failed to import CredentialManager module. Using default credentials." -} - # # Common helper functions. # @@ -49,6 +43,35 @@ function New-Credential return $Credential } +# +# Retrieves the secret from Azure Key Vault. +# Returns a PSCredential object, where the username is the secret name and the password is the retrieved secret. +# +function Get-AzureKeyVaultCredential +{ + param([Parameter(Mandatory=$False)][string] $KeyVaultName='ebpf-cicd-key-vault', + [Parameter(Mandatory=$True)][string] $SecretName) + + try { + # Check if the Az module is installed, if not, install it + if (-not (Get-Module -ListAvailable -Name Az)) { + Install-Module -Name Az -AllowClobber -Force + } + + # Authenticate using the managed identity + Connect-AzAccount -Identity + + # Retrieve the secret from Key Vault + $secret = Get-AzKeyVaultSecret -VaultName $KeyVaultName -Name $SecretName + + # The SecretName is the username and the secret value is the password + $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($SecretName, $secret) + return $credential + } catch { + throw "Failed to get Azure Key Vault Credential using KeyVaultName: $KeyVaultName, SecretName: $SecretName. Error: $_" + } +} + function Compress-File { @@ -118,17 +141,3 @@ function Wait-TestJobToComplete return $JobTimedOut } - -function Create-VMCredential { - param ( - [Parameter(Mandatory=$True)][string]$VmUsername, - [Parameter(Mandatory=$True)][string]$VmPassword - ) - - try { - $secureVmPassword = ConvertTo-SecureString $VmPassword -AsPlainText -Force - return New-Object System.Management.Automation.PSCredential($VmUsername, $secureVmPassword) - } catch { - throw "Failed to create VM credential: $_" - } -} diff --git a/scripts/execute_ebpf_cicd_tests.ps1 b/scripts/execute_ebpf_cicd_tests.ps1 index be1bafefdb..6ed00ab6de 100644 --- a/scripts/execute_ebpf_cicd_tests.ps1 +++ b/scripts/execute_ebpf_cicd_tests.ps1 @@ -20,15 +20,8 @@ Import-Module $WorkingDirectory\common.psm1 -Force -ArgumentList ($LogFileName) $SelfHostedRunnerName = "runner_host" Write-Host "SelfHostedRunnerName: $SelfHostedRunnerName, AdminTarget: $AdminTarget, StandardUserTarget: $StandardUserTarget" -try { - $AdminTestVMCredential = Get-StoredCredential -Target $AdminTarget -ErrorAction Stop - $StandardUserTestVMCredential = Get-StoredCredential -Target $StandardUserTarget -ErrorAction Stop -} catch { - Write-Host "Failed to get credentials for $AdminTarget or $StandardUserTarget. Using default credentials." - $securePassword = ConvertTo-SecureString -String "P@ssw0rd" -AsPlainText -Force - $AdminTestVMCredential = New-Credential -UserName 'Administrator' -AdminPassword $securePassword - $StandardUserTestVMCredential = New-Credential -UserName 'VMStandardUser' -AdminPassword $securePassword -} +$AdminTestVMCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' +$StandardUserTestVMCredential = Get-AzureKeyVaultCredential -SecretName 'VMStandardUser' # Read the test execution json. $Config = Get-Content ("{0}\{1}" -f $PSScriptRoot, $TestExecutionJsonFileName) | ConvertFrom-Json diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index cc1a107ae6..5ed190d41a 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -175,6 +175,11 @@ function Process-TestCompletion # Write-Log "(maige) Error: $_" # throw "Failed to wait for $TestCommand" # } + + # Sleep for a few seconds to ensure the process has had a chance to start. + Start-Sleep -Seconds 5 + + # Wait for the process to complete or for the timeout to complete. Wait-Process -InputObject $TestProcess -Timeout $TestHangTimeout -ErrorAction SilentlyContinue if (-not $TestProcess.HasExited) { diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index c1c558c399..097263465a 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -18,13 +18,7 @@ Push-Location $WorkingDirectory # Load other utility modules. Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue $SelfHostedRunnerName = "runner_host" -try { - $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop -} catch { - Write-Host "Failed to get credentials for $Target. Using default credentials." - $securePassword = ConvertTo-SecureString -String "P@ssw0rd" -AsPlainText -Force - $TestVMCredential = New-Credential -UserName 'Administrator' -AdminPassword $securePassword -} +$TestVMCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' Import-Module .\config_test_vm.psm1 -Force -ArgumentList ($TestVMCredential.UserName, $TestVMCredential.Password, $WorkingDirectory, $LogFileName) -WarningAction SilentlyContinue From e9e918e4ed7e409f13a6948000985c2fde75b6e1 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 2 Jan 2025 12:56:38 -0800 Subject: [PATCH 104/190] WIP --- 1es/Setup.ps1 | 23 +++++-------- 1es/prepare_vm_helpers.psm1 | 65 +++++++++++++++++-------------------- 1es/unattend.xml | 8 ++--- scripts/common.psm1 | 1 - 4 files changed, 42 insertions(+), 55 deletions(-) diff --git a/1es/Setup.ps1 b/1es/Setup.ps1 index 4c903e8f15..035caacf6d 100644 --- a/1es/Setup.ps1 +++ b/1es/Setup.ps1 @@ -1,9 +1,9 @@ # Copyright (c) eBPF for Windows contributors # SPDX-License-Identifier: MIT param( - [Parameter(Mandatory=$False)][string]$VmUsername='Administrator', - [Parameter(Mandatory=$False)][string]$VmStandardUserName='VMStandardUser', - [Parameter(Mandatory=$False)][string]$VmPassword='P@ssw0rd', + # [Parameter(Mandatory=$False)][string]$VmUsername='Administrator', + # [Parameter(Mandatory=$False)][string]$VmStandardUserName='VMStandardUser', + # [Parameter(Mandatory=$False)][string]$VmPassword='P@ssw0rd', [Parameter(Mandatory=$False)][string]$BaseUnattendPath='.\unattend.xml', [Parameter(Mandatory=$False)][string]$BaseVhdDirPath='.\', @@ -29,14 +29,6 @@ if (-not (Test-Path -Path $BaseVhdDirPath)) { } Create-VMSwitchIfNeeded -SwitchName 'VMInternalSwitch' -SwitchType 'Internal' -# Create-VMSwitchIfNeeded -SwitchName 'VMExternalSwitch' -SwitchType 'External' -# Stored credentials doesn't seem to be working... - -# TODO - switch to azure key vault, once we validate on CICD? -# $keyVaultValue = Get-AzKeyVaultSecret -VaultName "kobulloc-keyvaultAZPS" -Name "ExampleAZPSPassword" -# $keyVaultValue.SecretValue | ConvertFrom-SecureString -AsPlainText -Create-VMStoredCredential -CredentialName "TEST_VM" -Username $VmUsername -Password $VmPassword -Create-VMStoredCredential -CredentialName "TEST_VM_STANDARD" -Username $VmStandardUserName -Password $VmPassword Create-DirectoryIfNotExists -Path $WorkingPath # Unzip any VHDs @@ -68,6 +60,8 @@ if ($vhds.Count -eq 0) { } Log-Message "Successfully processed VHDs" +$AdminUserCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' +$StandardUserCredential = Get-AzureKeyVaultCredential -SecretName 'VMStandardUser' for ($i = 0; $i -lt $vhds.Count; $i++) { try { $vhd = $vhds[$i] @@ -80,18 +74,17 @@ for ($i = 0; $i -lt $vhds.Count; $i++) { Create-VM ` -VmName $vmName ` + -AdminUserCredential $AdminUserCredential ` + -StandardUserCredential $StandardUserCredential ` -VhdPath $vhd.FullName ` -VmStoragePath $outVMPath ` -VMMemory $VMMemory ` -UnattendPath $BaseUnattendPath ` - -VmUsername $VmUsername ` - -VmPassword $VmPassword ` -VMSwitchName 'VMInternalSwitch' Configure-VM ` -VmName $vmName ` - -VmUsername $VmUsername ` - -VmPassword $VmPassword ` + -VmCredential $AdminUserCredential ` -VMCpuCount $VMCpuCount Log-Message "VM $vmName created successfully" diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index 5f6f57a3cc..dedbb88e5d 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -32,20 +32,6 @@ function Create-DirectoryIfNotExists { } } -function Create-VMCredential { - param ( - [Parameter(Mandatory=$True)][string]$VmUsername, - [Parameter(Mandatory=$True)][string]$VmPassword - ) - - try { - $secureVmPassword = ConvertTo-SecureString $VmPassword -AsPlainText -Force - return New-Object System.Management.Automation.PSCredential($VmUsername, $secureVmPassword) - } catch { - throw "Failed to create VM credential: $_" - } -} - function Replace-PlaceholderStrings { param ( [Parameter(Mandatory=$True)][string]$FilePath, @@ -145,8 +131,8 @@ function Wait-ForVMReady { function Create-VM { param( [Parameter(Mandatory=$True)][string]$VmName, - [Parameter(Mandatory=$True)][string]$VmUsername, - [Parameter(Mandatory=$True)][string]$VmPassword, + [Parameter(Mandatory=$True)][PSCredential]$AdminUserCredential, + [Parameter(Mandatory=$True)][PSCredential]$StandardUserCredential, [Parameter(Mandatory=$True)][string]$VhdPath, [Parameter(Mandatory=$True)][string]$VmStoragePath, [Parameter(Mandatory=$True)][Int64]$VMMemory, @@ -170,12 +156,12 @@ function Create-VM { Move-Item -Path $VhdPath -Destination $VmStoragePath -Force $VmVhdPath = Join-Path -Path $VmStoragePath -ChildPath (Split-Path -Path $VhdPath -Leaf) - # Move unattend to the path + # Move unattend to the path and replace placeholder strings Log-Message "Moving $UnattendPath file to $VmStoragePath" Move-Item -Path $UnattendPath -Destination $VmStoragePath -Force $VmUnattendPath = Join-Path -Path $VmStoragePath -ChildPath (Split-Path -Path $UnattendPath -Leaf) - Replace-PlaceholderStrings -FilePath $VmUnattendPath -SearchString 'PLACEHOLDER_USERNAME' -ReplaceString $VmUsername - Replace-PlaceholderStrings -FilePath $VmUnattendPath -SearchString 'PLACEHOLDER_PASSWORD' -ReplaceString $VmPassword + Replace-PlaceholderStrings -FilePath $UnattendPath -SearchString 'PLACEHOLDER_ADMIN_PASSWORD' -ReplaceString $AdminUserCredential.GetNetworkCredential().Password + Replace-PlaceholderStrings -FilePath $UnattendPath -SearchString 'PLACEHOLDER_STANDARDUSER_PASSWORD' -ReplaceString $StandardUserCredential.GetNetworkCredential().Password # Configure the VHD with the unattend file. Log-Message "Mounting VHD and applying unattend file" @@ -211,8 +197,7 @@ function Create-VM { function Configure-VM { param( [Parameter(Mandatory=$True)][string]$VmName, - [Parameter(Mandatory=$True)][string]$VmUsername, - [Parameter(Mandatory=$True)][string]$VmPassword, + [Parameter(Mandatory=$True)][PSCredential]$VmCredential, [Parameter(Mandatory=$True)][int]$VMCpuCount, [Parameter(Mandatory=$False)][string]$VMWorkingDirectory='C:\ebpf_cicd', [Parameter(Mandatory=$False)][string]$VMSetupScript='.\configure_vm.ps1' @@ -227,9 +212,6 @@ function Configure-VM { Log-Message "Enabling Guest Service Interface" Enable-VMIntegrationService -VMName $VMName -Name 'Guest Service Interface' - # Get the VM credential - $VmCredential = Create-VMCredential -VmUsername $VmUsername -VmPassword $VmPassword - # Start the VM Log-Message "Starting VM: $VmName" Start-VM -Name $VmName @@ -344,18 +326,31 @@ function Create-VMSwitchIfNeeded { Log-Message "Successfully created $SwitchType switch with name: $SwitchName" -ForegroundColor Green } -function Create-VMStoredCredential { - param ( - [Parameter(Mandatory=$True)][string]$CredentialName, - [Parameter(Mandatory=$True)][string]$Username, - [Parameter(Mandatory=$True)][string]$Password - ) +# +# Retrieves the secret from Azure Key Vault. +# Returns a PSCredential object, where the username is the secret name and the password is the retrieved secret. +# +function Get-AzureKeyVaultCredential +{ + param([Parameter(Mandatory=$False)][string] $KeyVaultName='ebpf-cicd-key-vault', + [Parameter(Mandatory=$True)][string] $SecretName) + try { - Install-Module -Name CredentialManager -Scope AllUsers -Force - Import-Module CredentialManager -Force + # Check if the Az module is installed, if not, install it + if (-not (Get-Module -ListAvailable -Name Az)) { + Install-Module -Name Az -AllowClobber -Force + } + + # Authenticate using the managed identity + Connect-AzAccount -Identity - New-StoredCredential -Target $CredentialName -UserName $Username -Password $Password -Type Generic -Persist LocalMachine + # Retrieve the secret from Key Vault + $secret = Get-AzKeyVaultSecret -VaultName $KeyVaultName -Name $SecretName + + # The SecretName is the username and the secret value is the password + $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($SecretName, $secret) + return $credential } catch { - Log-Message "Failed to create stored credential with error $_" -ForegroundColor Red + throw "Failed to get Azure Key Vault Credential using KeyVaultName: $KeyVaultName, SecretName: $SecretName. Error: $_" } -} \ No newline at end of file +} diff --git a/1es/unattend.xml b/1es/unattend.xml index 27515d26ff..58e7c8a126 100644 --- a/1es/unattend.xml +++ b/1es/unattend.xml @@ -17,13 +17,13 @@ </OOBE> <UserAccounts> <AdministratorPassword> - <Value>PLACEHOLDER_PASSWORD</Value> + <Value>PLACEHOLDER_ADMIN_PASSWORD</Value> <PlainText>true</PlainText> </AdministratorPassword> <LocalAccounts> <LocalAccount> <Password> - <Value>PLACEHOLDER_PASSWORD</Value> + <Value>PLACEHOLDER_STANDARDUSER_PASSWORD</Value> <PlainText>true</PlainText> </Password> <Description>Standard User Account</Description> @@ -34,12 +34,12 @@ </UserAccounts> <AutoLogon> <Password> - <Value>PLACEHOLDER_PASSWORD</Value> + <Value>PLACEHOLDER_ADMIN_PASSWORD</Value> <PlainText>true</PlainText> </Password> <Enabled>true</Enabled> <LogonCount>9999</LogonCount> - <Username>PLACEHOLDER_USERNAME</Username> + <Username>Administrator</Username> </AutoLogon> </component> </settings> diff --git a/scripts/common.psm1 b/scripts/common.psm1 index 80de716d63..f7e24d839a 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -72,7 +72,6 @@ function Get-AzureKeyVaultCredential } } - function Compress-File { param ([Parameter(Mandatory = $True)] [string] $SourcePath, From 5fee54b8fb82e10cd49681b16eb29466cb3b5f3b Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 2 Jan 2025 13:04:39 -0800 Subject: [PATCH 105/190] test with HTTP query instead --- scripts/cleanup_ebpf_cicd_tests.ps1 | 2 +- scripts/common.psm1 | 42 +++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/scripts/cleanup_ebpf_cicd_tests.ps1 b/scripts/cleanup_ebpf_cicd_tests.ps1 index d51652001a..53a118a89e 100644 --- a/scripts/cleanup_ebpf_cicd_tests.ps1 +++ b/scripts/cleanup_ebpf_cicd_tests.ps1 @@ -14,7 +14,7 @@ Push-Location $WorkingDirectory Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue $SelfHostedRunnerName = "runner_host" Write-Host "SelfHostedRunnerName: $SelfHostedRunnerName, Target: $Target" -$TestVMCredential = Get-AzureKeyVaultCredential -SecretName'Administrator' +$TestVMCredential = Get-AzureKeyVaultCredential2 -SecretName'Administrator' # Read the test execution json. $Config = Get-Content ("{0}\{1}" -f $PSScriptRoot, $TestExecutionJsonFileName) | ConvertFrom-Json diff --git a/scripts/common.psm1 b/scripts/common.psm1 index f7e24d839a..a3681eb0ce 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -61,6 +61,8 @@ function Get-AzureKeyVaultCredential # Authenticate using the managed identity Connect-AzAccount -Identity + Set-AzContext -SubscriptionId '15cd5cd8-c222-405e-bb37-c5c6712a075f' + # Retrieve the secret from Key Vault $secret = Get-AzKeyVaultSecret -VaultName $KeyVaultName -Name $SecretName @@ -72,6 +74,46 @@ function Get-AzureKeyVaultCredential } } +# +# Retrieves the secret from Azure Key Vault. +# Returns a PSCredential object, where the username is the secret name and the password is the retrieved secret. +# +function Get-AzureKeyVaultCredential2 +{ + param([Parameter(Mandatory=$False)][string] $KeyVaultName='ebpf-cicd-key-vault', + [Parameter(Mandatory=$True)][string] $SecretName) + + try { + # # Check if the Az module is installed, if not, install it + # if (-not (Get-Module -ListAvailable -Name Az)) { + # Install-Module -Name Az -AllowClobber -Force + # } + + # # Authenticate using the managed identity + # Connect-AzAccount -Identity + + # Set-AzContext -SubscriptionId "your-subscription-id" + + # Get the managed identity token + $keyVaultUri = 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2019-08-01&resource=https://' + $KeyVaultName + '.vault.azure.net' + $token = (Invoke-RestMethod -Uri $keyVaultUri -Method GET -Headers @{Metadata="true"}).access_token + + # Set the token in the header + $headers = @{ + 'Authorization' = "Bearer $token" + } + + # Get the secret from the Key Vault + $keyVaultSecretUri = 'https://' + $KeyVaultName + '.vault.azure.net/secrets/' + $SecretName + '?api-version=7.0' + $secret = Invoke-RestMethod -Uri keyVaultSecretUri -Method GET -Headers $headers + $password = ConvertTo-SecureString $secret.value -AsPlainText -Force + + $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($SecretName, $password) + } catch { + throw "Failed to get Azure Key Vault Credential using KeyVaultName: $KeyVaultName, SecretName: $SecretName. Error: $_" + } +} + function Compress-File { param ([Parameter(Mandatory = $True)] [string] $SourcePath, From 38983c557a561fbeadba89f4252b6fec390fb831 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 2 Jan 2025 13:34:09 -0800 Subject: [PATCH 106/190] test again - fix typos --- scripts/cleanup_ebpf_cicd_tests.ps1 | 2 +- scripts/common.psm1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/cleanup_ebpf_cicd_tests.ps1 b/scripts/cleanup_ebpf_cicd_tests.ps1 index 53a118a89e..043b5370e4 100644 --- a/scripts/cleanup_ebpf_cicd_tests.ps1 +++ b/scripts/cleanup_ebpf_cicd_tests.ps1 @@ -14,7 +14,7 @@ Push-Location $WorkingDirectory Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue $SelfHostedRunnerName = "runner_host" Write-Host "SelfHostedRunnerName: $SelfHostedRunnerName, Target: $Target" -$TestVMCredential = Get-AzureKeyVaultCredential2 -SecretName'Administrator' +$TestVMCredential = Get-AzureKeyVaultCredential2 -SecretName 'Administrator' # Read the test execution json. $Config = Get-Content ("{0}\{1}" -f $PSScriptRoot, $TestExecutionJsonFileName) | ConvertFrom-Json diff --git a/scripts/common.psm1 b/scripts/common.psm1 index a3681eb0ce..94fb272977 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -61,7 +61,7 @@ function Get-AzureKeyVaultCredential # Authenticate using the managed identity Connect-AzAccount -Identity - Set-AzContext -SubscriptionId '15cd5cd8-c222-405e-bb37-c5c6712a075f' + # Set-AzContext -SubscriptionId '15cd5cd8-c222-405e-bb37-c5c6712a075f' # Retrieve the secret from Key Vault $secret = Get-AzKeyVaultSecret -VaultName $KeyVaultName -Name $SecretName From d2613683741e235002254304a0015dee3a9b6dad Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 2 Jan 2025 14:02:43 -0800 Subject: [PATCH 107/190] fix attempt --- scripts/common.psm1 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/common.psm1 b/scripts/common.psm1 index 94fb272977..e72f702413 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -61,13 +61,12 @@ function Get-AzureKeyVaultCredential # Authenticate using the managed identity Connect-AzAccount -Identity - # Set-AzContext -SubscriptionId '15cd5cd8-c222-405e-bb37-c5c6712a075f' - # Retrieve the secret from Key Vault $secret = Get-AzKeyVaultSecret -VaultName $KeyVaultName -Name $SecretName # The SecretName is the username and the secret value is the password - $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($SecretName, $secret) + Write-Host "Successfully retrieved secret from Azure Key Vault. $KeyVaultName: $KeyVaultName, SecretName: $SecretName" + $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($SecretName, $secret.SecretValue) return $credential } catch { throw "Failed to get Azure Key Vault Credential using KeyVaultName: $KeyVaultName, SecretName: $SecretName. Error: $_" @@ -96,6 +95,7 @@ function Get-AzureKeyVaultCredential2 # Get the managed identity token $keyVaultUri = 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2019-08-01&resource=https://' + $KeyVaultName + '.vault.azure.net' + Write-Host "Getting token from $keyVaultUri" $token = (Invoke-RestMethod -Uri $keyVaultUri -Method GET -Headers @{Metadata="true"}).access_token # Set the token in the header @@ -105,6 +105,7 @@ function Get-AzureKeyVaultCredential2 # Get the secret from the Key Vault $keyVaultSecretUri = 'https://' + $KeyVaultName + '.vault.azure.net/secrets/' + $SecretName + '?api-version=7.0' + Write-Host "Getting secret from $keyVaultSecretUri" $secret = Invoke-RestMethod -Uri keyVaultSecretUri -Method GET -Headers $headers $password = ConvertTo-SecureString $secret.value -AsPlainText -Force From e3920b6dea51dd24dd64bde62546e0ef9731b170 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 2 Jan 2025 14:25:46 -0800 Subject: [PATCH 108/190] fix --- scripts/common.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/common.psm1 b/scripts/common.psm1 index e72f702413..a739fd5ea3 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -65,7 +65,7 @@ function Get-AzureKeyVaultCredential $secret = Get-AzKeyVaultSecret -VaultName $KeyVaultName -Name $SecretName # The SecretName is the username and the secret value is the password - Write-Host "Successfully retrieved secret from Azure Key Vault. $KeyVaultName: $KeyVaultName, SecretName: $SecretName" + Write-Host "Successfully retrieved secret from Azure Key Vault. KeyVaultName: $KeyVaultName, SecretName: $SecretName" $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($SecretName, $secret.SecretValue) return $credential } catch { @@ -111,7 +111,7 @@ function Get-AzureKeyVaultCredential2 $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($SecretName, $password) } catch { - throw "Failed to get Azure Key Vault Credential using KeyVaultName: $KeyVaultName, SecretName: $SecretName. Error: $_" + throw "Failed to get Azure Key Vault Credential using KeyVaultName: $KeyVaultName SecretName: $SecretName Error: $_" } } From 430a4673740e3741e215dee5e2e20286f95da788 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 2 Jan 2025 14:26:22 -0800 Subject: [PATCH 109/190] fix --- scripts/common.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/common.psm1 b/scripts/common.psm1 index a739fd5ea3..1dde1a0c63 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -65,11 +65,11 @@ function Get-AzureKeyVaultCredential $secret = Get-AzKeyVaultSecret -VaultName $KeyVaultName -Name $SecretName # The SecretName is the username and the secret value is the password - Write-Host "Successfully retrieved secret from Azure Key Vault. KeyVaultName: $KeyVaultName, SecretName: $SecretName" + Write-Host "Successfully retrieved secret from Azure Key Vault. KeyVaultName: $KeyVaultName SecretName: $SecretName" $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($SecretName, $secret.SecretValue) return $credential } catch { - throw "Failed to get Azure Key Vault Credential using KeyVaultName: $KeyVaultName, SecretName: $SecretName. Error: $_" + throw "Failed to get Azure Key Vault Credential using KeyVaultName: $KeyVaultName SecretName: $SecretName Error: $_" } } From ab17d5d40267c016f9de60700fb2440e6488540c Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 2 Jan 2025 14:54:11 -0800 Subject: [PATCH 110/190] test --- scripts/cleanup_ebpf_cicd_tests.ps1 | 2 +- scripts/common.psm1 | 10 +++++----- scripts/setup_ebpf_cicd_tests.ps1 | 2 ++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/cleanup_ebpf_cicd_tests.ps1 b/scripts/cleanup_ebpf_cicd_tests.ps1 index 043b5370e4..34a9e5abe2 100644 --- a/scripts/cleanup_ebpf_cicd_tests.ps1 +++ b/scripts/cleanup_ebpf_cicd_tests.ps1 @@ -14,7 +14,7 @@ Push-Location $WorkingDirectory Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue $SelfHostedRunnerName = "runner_host" Write-Host "SelfHostedRunnerName: $SelfHostedRunnerName, Target: $Target" -$TestVMCredential = Get-AzureKeyVaultCredential2 -SecretName 'Administrator' +$TestVMCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' # Read the test execution json. $Config = Get-Content ("{0}\{1}" -f $PSScriptRoot, $TestExecutionJsonFileName) | ConvertFrom-Json diff --git a/scripts/common.psm1 b/scripts/common.psm1 index 1dde1a0c63..d95a4274b9 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -53,10 +53,10 @@ function Get-AzureKeyVaultCredential [Parameter(Mandatory=$True)][string] $SecretName) try { - # Check if the Az module is installed, if not, install it - if (-not (Get-Module -ListAvailable -Name Az)) { - Install-Module -Name Az -AllowClobber -Force - } + # # Check if the Az module is installed, if not, install it + # if (-not (Get-Module -ListAvailable -Name Az)) { + # Install-Module -Name Az -AllowClobber -Force + # } # Authenticate using the managed identity Connect-AzAccount -Identity @@ -65,7 +65,7 @@ function Get-AzureKeyVaultCredential $secret = Get-AzKeyVaultSecret -VaultName $KeyVaultName -Name $SecretName # The SecretName is the username and the secret value is the password - Write-Host "Successfully retrieved secret from Azure Key Vault. KeyVaultName: $KeyVaultName SecretName: $SecretName" + # Write-Host "Successfully retrieved secret from Azure Key Vault. KeyVaultName: $KeyVaultName SecretName: $SecretName" $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($SecretName, $secret.SecretValue) return $credential } catch { diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index 097263465a..58dc5fd0e9 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -19,6 +19,8 @@ Push-Location $WorkingDirectory Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue $SelfHostedRunnerName = "runner_host" $TestVMCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' +Write-Host "(maige) - cred $TestVMCredential" +Write-Host "(maige) credential UserName: $($TestVMCredential.UserName) and password: $($TestVMCredential.Password)" Import-Module .\config_test_vm.psm1 -Force -ArgumentList ($TestVMCredential.UserName, $TestVMCredential.Password, $WorkingDirectory, $LogFileName) -WarningAction SilentlyContinue From 3100bb3b05c3481ca1f4dd24723fabd70f279a86 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 2 Jan 2025 15:16:39 -0800 Subject: [PATCH 111/190] fix2 --- scripts/common.psm1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/common.psm1 b/scripts/common.psm1 index d95a4274b9..526c6369e8 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -53,10 +53,10 @@ function Get-AzureKeyVaultCredential [Parameter(Mandatory=$True)][string] $SecretName) try { - # # Check if the Az module is installed, if not, install it - # if (-not (Get-Module -ListAvailable -Name Az)) { - # Install-Module -Name Az -AllowClobber -Force - # } + # Check if the Az module is installed, if not, install it + if (-not (Get-Module -ListAvailable -Name Az)) { + Install-Module -Name Az -AllowClobber -Force + } # Authenticate using the managed identity Connect-AzAccount -Identity From 9c865087cba529d917ce9cf0c0d2926472beb590 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 2 Jan 2025 16:07:21 -0800 Subject: [PATCH 112/190] suppress output --- scripts/common.psm1 | 49 ++----------------------------- scripts/setup_ebpf_cicd_tests.ps1 | 2 +- 2 files changed, 4 insertions(+), 47 deletions(-) diff --git a/scripts/common.psm1 b/scripts/common.psm1 index 526c6369e8..8028dfcd5c 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -55,17 +55,16 @@ function Get-AzureKeyVaultCredential try { # Check if the Az module is installed, if not, install it if (-not (Get-Module -ListAvailable -Name Az)) { - Install-Module -Name Az -AllowClobber -Force + Install-Module -Name Az -AllowClobber -Force *> $null 2>&1 } # Authenticate using the managed identity - Connect-AzAccount -Identity + Connect-AzAccount -Identity *> $null 2>&1 # Retrieve the secret from Key Vault $secret = Get-AzKeyVaultSecret -VaultName $KeyVaultName -Name $SecretName - # The SecretName is the username and the secret value is the password - # Write-Host "Successfully retrieved secret from Azure Key Vault. KeyVaultName: $KeyVaultName SecretName: $SecretName" + # Return as a PSCredential object $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($SecretName, $secret.SecretValue) return $credential } catch { @@ -73,48 +72,6 @@ function Get-AzureKeyVaultCredential } } -# -# Retrieves the secret from Azure Key Vault. -# Returns a PSCredential object, where the username is the secret name and the password is the retrieved secret. -# -function Get-AzureKeyVaultCredential2 -{ - param([Parameter(Mandatory=$False)][string] $KeyVaultName='ebpf-cicd-key-vault', - [Parameter(Mandatory=$True)][string] $SecretName) - - try { - # # Check if the Az module is installed, if not, install it - # if (-not (Get-Module -ListAvailable -Name Az)) { - # Install-Module -Name Az -AllowClobber -Force - # } - - # # Authenticate using the managed identity - # Connect-AzAccount -Identity - - # Set-AzContext -SubscriptionId "your-subscription-id" - - # Get the managed identity token - $keyVaultUri = 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2019-08-01&resource=https://' + $KeyVaultName + '.vault.azure.net' - Write-Host "Getting token from $keyVaultUri" - $token = (Invoke-RestMethod -Uri $keyVaultUri -Method GET -Headers @{Metadata="true"}).access_token - - # Set the token in the header - $headers = @{ - 'Authorization' = "Bearer $token" - } - - # Get the secret from the Key Vault - $keyVaultSecretUri = 'https://' + $KeyVaultName + '.vault.azure.net/secrets/' + $SecretName + '?api-version=7.0' - Write-Host "Getting secret from $keyVaultSecretUri" - $secret = Invoke-RestMethod -Uri keyVaultSecretUri -Method GET -Headers $headers - $password = ConvertTo-SecureString $secret.value -AsPlainText -Force - - $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($SecretName, $password) - } catch { - throw "Failed to get Azure Key Vault Credential using KeyVaultName: $KeyVaultName SecretName: $SecretName Error: $_" - } -} - function Compress-File { param ([Parameter(Mandatory = $True)] [string] $SourcePath, diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index 58dc5fd0e9..24dbdd7fc8 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -19,7 +19,7 @@ Push-Location $WorkingDirectory Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue $SelfHostedRunnerName = "runner_host" $TestVMCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' -Write-Host "(maige) - cred $TestVMCredential" +Write-Host "(maige) - cred $TestVMCredential and type $($TestVMCredential.GetType())" Write-Host "(maige) credential UserName: $($TestVMCredential.UserName) and password: $($TestVMCredential.Password)" Import-Module .\config_test_vm.psm1 -Force -ArgumentList ($TestVMCredential.UserName, $TestVMCredential.Password, $WorkingDirectory, $LogFileName) -WarningAction SilentlyContinue From 9f095da2f35b328457bb2a032395df93e5546e25 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 2 Jan 2025 17:14:02 -0800 Subject: [PATCH 113/190] attempt fixes --- 1es/prepare_vm_helpers.psm1 | 14 +++++++------- scripts/run_driver_tests.psm1 | 18 +++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index dedbb88e5d..f7ae57c28f 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -160,8 +160,8 @@ function Create-VM { Log-Message "Moving $UnattendPath file to $VmStoragePath" Move-Item -Path $UnattendPath -Destination $VmStoragePath -Force $VmUnattendPath = Join-Path -Path $VmStoragePath -ChildPath (Split-Path -Path $UnattendPath -Leaf) - Replace-PlaceholderStrings -FilePath $UnattendPath -SearchString 'PLACEHOLDER_ADMIN_PASSWORD' -ReplaceString $AdminUserCredential.GetNetworkCredential().Password - Replace-PlaceholderStrings -FilePath $UnattendPath -SearchString 'PLACEHOLDER_STANDARDUSER_PASSWORD' -ReplaceString $StandardUserCredential.GetNetworkCredential().Password + Replace-PlaceholderStrings -FilePath $VmUnattendPath -SearchString 'PLACEHOLDER_ADMIN_PASSWORD' -ReplaceString $AdminUserCredential.GetNetworkCredential().Password + Replace-PlaceholderStrings -FilePath $VmUnattendPath -SearchString 'PLACEHOLDER_STANDARDUSER_PASSWORD' -ReplaceString $StandardUserCredential.GetNetworkCredential().Password # Configure the VHD with the unattend file. Log-Message "Mounting VHD and applying unattend file" @@ -338,19 +338,19 @@ function Get-AzureKeyVaultCredential try { # Check if the Az module is installed, if not, install it if (-not (Get-Module -ListAvailable -Name Az)) { - Install-Module -Name Az -AllowClobber -Force + Install-Module -Name Az -AllowClobber -Force *> $null 2>&1 } # Authenticate using the managed identity - Connect-AzAccount -Identity + Connect-AzAccount -Identity *> $null 2>&1 # Retrieve the secret from Key Vault $secret = Get-AzKeyVaultSecret -VaultName $KeyVaultName -Name $SecretName - # The SecretName is the username and the secret value is the password - $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($SecretName, $secret) + # Return as a PSCredential object + $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($SecretName, $secret.SecretValue) return $credential } catch { - throw "Failed to get Azure Key Vault Credential using KeyVaultName: $KeyVaultName, SecretName: $SecretName. Error: $_" + throw "Failed to get Azure Key Vault Credential using KeyVaultName: $KeyVaultName SecretName: $SecretName Error: $_" } } diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 5ed190d41a..5b68a47aae 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -210,15 +210,15 @@ function Process-TestCompletion throw [System.TimeoutException]::new("Test $TestCommand execution hang timeout ($TestHangTimeout seconds) expired.") } else { Write-Log "(maige) Process-TestCompletion: command should have completed" - # try { - # $currExitCode = $TestProcess.ExitCode - # $temp = $TestProcess | Out-String - # Write-Log "Maige - test output: $temp" - # Write-Log "MAIGE - $TestCommand exited with code $currExitCode" - # Write-Log "maige3 - In Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" - # } catch { - # Write-Log "maige - failed" - # } + try { + $currExitCode = $TestProcess.ExitCode + $temp = $TestProcess | Out-String + Write-Log "Maige - test output: $temp" + Write-Log "MAIGE - $TestCommand exited with code $currExitCode" + Write-Log "maige3 - In Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" + } catch { + Write-Log "maige - failed" + } # Read and display the output (if any) from the temporary output file. $TempOutputFile = "$env:TEMP\app_output.log" # Log for standard output From 9304e05acc58d6aa985075506f9ba5902e788b1b Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 3 Jan 2025 08:53:35 -0800 Subject: [PATCH 114/190] WIP --- scripts/run_driver_tests.psm1 | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 5b68a47aae..8a0f6dea8d 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -218,6 +218,7 @@ function Process-TestCompletion Write-Log "maige3 - In Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" } catch { Write-Log "maige - failed" + } # Read and display the output (if any) from the temporary output file. From 7e5c58729e800bf6711ab20aa708cb31ae1c27fd Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 3 Jan 2025 09:37:50 -0800 Subject: [PATCH 115/190] add more diagnostics --- scripts/run_driver_tests.psm1 | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 8a0f6dea8d..c77e00488f 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -177,7 +177,7 @@ function Process-TestCompletion # } # Sleep for a few seconds to ensure the process has had a chance to start. - Start-Sleep -Seconds 5 + # Start-Sleep -Seconds 5 # Wait for the process to complete or for the timeout to complete. Wait-Process -InputObject $TestProcess -Timeout $TestHangTimeout -ErrorAction SilentlyContinue @@ -400,22 +400,22 @@ function Invoke-XDPTest $TestCommand = ".\xdp_tests.exe" $TestArguments = "$XDPTestName --remote-ip $RemoteIPV4Address" $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - # if ($TestProcess -eq $null) { - # Write-Log "Failed to start $TestCommand with arguments $TestArguments" - # throw "Failed to start $TestCommand with arguments $TestArguments" - # } - # Write-Log "maige1 - before Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" + if ($TestProcess -eq $null) { + Write-Log "Failed to start $TestCommand with arguments $TestArguments" + ThrowWithErrorMessage -ErrorMessage "(maige) Failed to start $TestCommand with arguments $TestArguments" + } + Write-Log "maige1 - before Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand Write-Log "Executing $XDPTestName with remote address: $RemoteIPV6Address" $TestCommand = ".\xdp_tests.exe" $TestArguments = "$XDPTestName --remote-ip $RemoteIPV6Address" $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - # if ($TestProcess -eq $null) { - # Write-Log "Failed to start $TestCommand with arguments $TestArguments" - # throw "Failed to start $TestCommand with arguments $TestArguments" - # } - # Write-Log "maige2 - before Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" + if ($TestProcess -eq $null) { + Write-Log "Failed to start $TestCommand with arguments $TestArguments" + ThrowWithErrorMessage -ErrorMessage "(maige) Failed to start $TestCommand with arguments $TestArguments" + } + Write-Log "maige2 - before Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand Write-Log "$XDPTestName Test Passed" -ForegroundColor Green From d791881b9d81fc827c76314596a045973cb9d085 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 3 Jan 2025 10:34:37 -0800 Subject: [PATCH 116/190] cleanup of 1es scripts --- 1es/Setup.ps1 | 75 +++++----- 1es/configure_vm.ps1 | 100 ++----------- 1es/prepare_vm_helpers.psm1 | 277 ++++++++++++++++++++++++++++++------ 3 files changed, 276 insertions(+), 176 deletions(-) diff --git a/1es/Setup.ps1 b/1es/Setup.ps1 index 035caacf6d..3bcf0cdada 100644 --- a/1es/Setup.ps1 +++ b/1es/Setup.ps1 @@ -1,16 +1,35 @@ # Copyright (c) eBPF for Windows contributors # SPDX-License-Identifier: MIT -param( - # [Parameter(Mandatory=$False)][string]$VmUsername='Administrator', - # [Parameter(Mandatory=$False)][string]$VmStandardUserName='VMStandardUser', - # [Parameter(Mandatory=$False)][string]$VmPassword='P@ssw0rd', +<# +.SYNOPSIS + This script configures a host environment by creating and configuring VMs required for testing. + +.DESCRIPTION + This script will create and configure VMs based on the provided parameters. + It is expected that the current working directory contains the necessary files to execute this script. + +.PARAMETER BaseUnattendPath + The path to the base unattend.xml file used for VM creation. + +.PARAMETER BaseVhdDirPath + The path to the base VHD directory used for VM creation. +.PARAMETER WorkingPath + The working path where the VMs will be created. + +.PARAMETER VMCpuCount + The number of CPUs to assign to each VM. Default is 4. + +.PARAMETER VMMemory + The amount of memory to assign to each VM. Default is 4096MB. + +.EXAMPLE + .\Setup.ps1 -BaseUnattendPath 'C:\path\to\unattend.xml' -BaseVhdDirPath 'C:\path\to\vhd' -WorkingPath 'C:\vms' +#> +param( [Parameter(Mandatory=$False)][string]$BaseUnattendPath='.\unattend.xml', [Parameter(Mandatory=$False)][string]$BaseVhdDirPath='.\', - # [Parameter(Mandatory=$False)][string]$WorkingPath='.\working', [Parameter(Mandatory=$False)][string]$WorkingPath='C:\vms', - # [Parameter(Mandatory=$False)][string]$OutVhdDirPath='.\exported_vhds', - [Parameter(Mandatory=$False)][string]$VMCpuCount=4, [Parameter(Mandatory=$False)][string]$VMMemory=4096MB ) @@ -20,6 +39,7 @@ $ErrorActionPreference = "Stop" # Import helper functions Import-Module .\prepare_vm_helpers.psm1 -Force +# Input validation for input paths if (-not (Test-Path -Path $BaseUnattendPath)) { throw "Unattend file not found at $BaseUnattendPath" } @@ -28,40 +48,21 @@ if (-not (Test-Path -Path $BaseVhdDirPath)) { throw "VHD directory not found at $BaseVhdDirPath" } -Create-VMSwitchIfNeeded -SwitchName 'VMInternalSwitch' -SwitchType 'Internal' +# Create working directory used for VM creation. Create-DirectoryIfNotExists -Path $WorkingPath -# Unzip any VHDs -Log-Message "Processing VHDs in $BaseVhdDirPath" -$zipFiles = Get-ChildItem -Path $BaseVhdDirPath -Filter *.zip -foreach ($zipFile in $zipFiles) { - Log-Message "Extracting VHDs from $($zipFile.FullName)" - $outDir = Join-Path -Path $BaseVhdDirPath -ChildPath $zipFile.BaseName - if (-not (Test-Path -Path $outDir)) { - Expand-Archive -Path $zipFile.FullName -DestinationPath $outDir - - # Move the VHDs to the base directory - $vhdFiles = @() - $vhdFiles += Get-ChildItem -Path $outDir -Filter *.vhd -ErrorAction Ignore - $vhdFiles += Get-ChildItem -Path $outDir -Filter *.vhdx -ErrorAction Ignore - foreach ($vhdFile in $vhdFiles) { - Move-Item -Path $vhdFile.FullName -Destination $BaseVhdDirPath - } - } - Log-Message "Successfully processed $($zipFile.FullName)" -} - -# Read the input VHDs -$vhds = @() -$vhds += Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhd -ErrorAction Ignore -$vhds += Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhdx -ErrorAction Ignore -if ($vhds.Count -eq 0) { - throw "No VHDs found in $BaseVhdDirPath" -} -Log-Message "Successfully processed VHDs" +# Create internal switch for VM. +$VMSwitchName = 'VMInternalSwitch' +Create-VMSwitchIfNeeded -SwitchName $VMSwitchName -SwitchType 'Internal' +# Fetch the credentials for the VM using the Azure Key Vault. $AdminUserCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' $StandardUserCredential = Get-AzureKeyVaultCredential -SecretName 'VMStandardUser' + +# Unzip any VHD files, if needed, and get the list of VHDs to create VMs from. +$vhds = Prepare-VhdFiles -BaseVhdDirPath $BaseVhdDirPath + +# Process VM creation and setup. for ($i = 0; $i -lt $vhds.Count; $i++) { try { $vhd = $vhds[$i] @@ -80,7 +81,7 @@ for ($i = 0; $i -lt $vhds.Count; $i++) { -VmStoragePath $outVMPath ` -VMMemory $VMMemory ` -UnattendPath $BaseUnattendPath ` - -VMSwitchName 'VMInternalSwitch' + -VMSwitchName $VMSwitchName Configure-VM ` -VmName $vmName ` diff --git a/1es/configure_vm.ps1 b/1es/configure_vm.ps1 index 43e5f3ce05..e214b775b8 100644 --- a/1es/configure_vm.ps1 +++ b/1es/configure_vm.ps1 @@ -1,84 +1,14 @@ # Copyright (c) eBPF for Windows contributors # SPDX-License-Identifier: MIT -########## Helper Functions ########## -# Download and extract PSExec to run tests as SYSTEM. -function Get-PSExec { - $url = "https://download.sysinternals.com/files/PSTools.zip" - $DownloadPath = "$pwd\psexec" - mkdir $DownloadPath - Write-Host "Downloading PSExec from $url to $DownloadPath" - $ProgressPreference = 'SilentlyContinue' - Invoke-WebRequest $url -OutFile "$DownloadPath\pstools.zip" - cd $DownloadPath - Expand-Archive -Path "$DownloadPath\pstools.zip" -Force - cd .. - Move-Item -Path "$DownloadPath\PSTools\PsExec64.exe" -Destination $pwd -Force - Remove-Item -Path $DownloadPath -Force -Recurse -} - -function Get-ZipFileFromUrl { - param( - [Parameter(Mandatory=$True)][string] $Url, - [Parameter(Mandatory=$True)][string] $DownloadFilePath, - [Parameter(Mandatory=$True)][string] $OutputDir - ) - - for ($i = 0; $i -lt 5; $i++) { - try { - Write-Host "Downloading $Url to $DownloadFilePath" - $ProgressPreference = 'SilentlyContinue' - Invoke-WebRequest -Uri $Url -OutFile $DownloadFilePath - - Write-Host "Extracting $DownloadFilePath to $OutputDir" - Expand-Archive -Path $DownloadFilePath -DestinationPath $OutputDir -Force - break - } catch { - Write-Host "Iteration $i failed to download $Url. Removing $DownloadFilePath" -ForegroundColor Red - Remove-Item -Path $DownloadFilePath -Force -ErrorAction Ignore - Start-Sleep -Seconds 5 - } - } -} - -# Copied from https://github.com/microsoft/msquic/blob/main/scripts/prepare-machine.ps1 -function Get-Duonic { - # Download and extract https://github.com/microsoft/corenet-ci. - $DownloadPath = "$pwd\corenet-ci" - mkdir $DownloadPath - Write-Host "Downloading CoreNet-CI to $DownloadPath" - Get-ZipFileFromUrl -Url "https://github.com/microsoft/corenet-ci/archive/refs/heads/main.zip" -DownloadFilePath "$DownloadPath\corenet-ci.zip" -OutputDir $DownloadPath - Move-Item -Path "$DownloadPath\corenet-ci-main\vm-setup\duonic\*" -Destination $pwd -Force - Move-Item -Path "$DownloadPath\corenet-ci-main\vm-setup\procdump64.exe" -Destination $pwd -Force - Move-Item -Path "$DownloadPath\corenet-ci-main\vm-setup\notmyfault64.exe" -Destination $pwd -Force - Remove-Item -Path $DownloadPath -Force -Recurse -} - -function Initialize-NetworkInterfacesOnVMs -{ - # param([parameter(Mandatory=$true)] $VMMap) - - # foreach ($VM in $VMMap) - # { - # $VMName = $VM.Name +<# +.SYNOPSIS + This script executes on a VM to configure it for eBPF testing. - # Write-Log "Initializing network interfaces on $VMName" - # $TestCredential = New-Credential -Username $Admin -AdminPassword $AdminPassword - - # Invoke-Command -VMName $VMName -Credential $TestCredential -ScriptBlock { - # param([Parameter(Mandatory=$True)] [string] $WorkingDirectory) - - # Push-Location "$env:SystemDrive\$WorkingDirectory" - - Write-Host "Installing DuoNic driver" - .\duonic.ps1 -Install -NumNicPairs 2 - # Disable Duonic's fake checksum offload and force TCP/IP to calculate it. - Set-NetAdapterAdvancedProperty duo? -DisplayName Checksum -RegistryValue 0 - - # Pop-Location - # } -ArgumentList ("eBPF") -ErrorAction Stop - # } -} +.DESCRIPTION + This script configures a VM for eBPF testing by enabling test signing, user-mode dumps, kernel dumps, + and driver verifier on the eBPF platform drivers. It also enables IPv4 and IPv6 on all network adapters. +#> ########## Main Execution ########## @@ -97,19 +27,11 @@ New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl" -Na # Enable driver verifier on the eBPF platform drivers. verifier /standard /bootmode persistent /driver ebpfcore.sys netebpfext.sys sample_ebpf_ext.sys -# TODO - this will either need to be done post VM creation, or run on the host and copied into the VM -# # Install duonic and configure it. -# Get-Duonic -# Initialize-NetworkInterfacesOnVMs - -# # Get PSExec to run tests as SYSTEM. -# Get-PSExec - # Loop through each adapter and enable IPv4 and IPv6 $adapters = Get-NetAdapter foreach ($adapter in $adapters) { try { - # Enable IPv4 (usually enabled by default) + # Enable IPv4 Enable-NetAdapterBinding -Name $adapter.Name -ComponentID ms_tcpip # Enable IPv6 @@ -121,11 +43,5 @@ foreach ($adapter in $adapters) { } } -Get-NetAdapterBinding -AllBindings | Out-String - -ipconfig /all - -Get-NetIPInterface | Out-String - # Reboot the machine to apply the changes. Restart-Computer -Force \ No newline at end of file diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index f7ae57c28f..c9f402cee0 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -2,6 +2,24 @@ # SPDX-License-Identifier: MIT $ErrorActionPreference = "Stop" +<# +.SYNOPSIS + Helper function to format a log message with a timestamp and outputs the message to the console. + +.DESCRIPTION + This function formats a log message with a timestamp and outputs the message to the console. + +.PARAMETER Message + The message to log. + +.PARAMETER ForegroundColor + The color of the text to display in the console. Defaults to 'White'. + +.EXAMPLE + Log-Message -Message "This is a log message" + Log-Message -Message "This is a success log message" -ForegroundColor "Green" + Log-Message -Message "This is an error log message" -ForegroundColor "Red" +#> function Log-Message { param( [Parameter(Mandatory=$True)][string]$Message, @@ -14,6 +32,19 @@ function Log-Message { Write-Host "[$timestamp] - $Message" -ForegroundColor $ForegroundColor } +<# +.SYNOPSIS + Helper function to create a directory if it does not already exist. + +.DESCRIPTION + This function checks if a directory exists at the specified path. If it does not exist, it creates the directory. + +.PARAMETER Path + The path of the directory to create. + +.EXAMPLE + Create-DirectoryIfNotExists -Path "C:\MyDirectory" +#> function Create-DirectoryIfNotExists { param ( [Parameter(Mandatory=$True)][string]$Path @@ -32,6 +63,25 @@ function Create-DirectoryIfNotExists { } } +<# +.SYNOPSIS + Helper function to replace placeholder strings in a file. + +.DESCRIPTION + This function replaces all occurrences of a specified search string with a replacement string in a file. + +.PARAMETER FilePath + The path to the file in which to replace the placeholder strings. + +.PARAMETER SearchString + The string to search for in the file. + +.PARAMETER ReplaceString + The string to replace the search string with. + +.EXAMPLE + Replace-PlaceholderStrings -FilePath "C:\MyFile.txt" -SearchString "PLACEHOLDER" -ReplaceString "ActualValue" +#> function Replace-PlaceholderStrings { param ( [Parameter(Mandatory=$True)][string]$FilePath, @@ -48,6 +98,22 @@ function Replace-PlaceholderStrings { } } +<# +.SYNOPSIS + Helper function to execute a command on a VM. + +.DESCRIPTION + This function executes a command on a specified VM using the provided credentials. + +.PARAMETER VMName + The name of the VM to execute the command on. + +.PARAMETER VmCredential + The credentials to use for executing the command on the VM. + +.PARAMETER Command + The command to execute on the VM. +#> function Execute-CommandOnVM { param ( [Parameter(Mandatory=$True)][string]$VMName, @@ -56,17 +122,36 @@ function Execute-CommandOnVM { ) try { + Log-Message "Executing command on VM: $VMName. Command: $Command" $result = Invoke-Command -VMName $VMName -Credential $VmCredential -ScriptBlock { param($Command) Invoke-Expression $Command } -ArgumentList $Command - - Log-Message -Message "Executed command on VM: $VMName. Command: $Command. Result: $result" + Log-Message -Message "Successfully executed command on VM: $VMName. Command: $Command. Result: $result" } catch { throw "Failed to execute command on VM: $VMName with error: $_" } } +<# +.SYNOPSIS + Helper function to wait for a VM to be ready. + +.DESCRIPTION + This function waits for a VM to be in the 'Running' state and then connects to it using a simple command. + +.PARAMETER VMName + The name of the VM to wait for. + +.PARAMETER VmCredential + The credentials to use for connecting to the VM. + +.PARAMETER TimeoutInMinutes + The maximum time to wait for the VM to be ready, in minutes. Defaults to 30 minutes. + +.EXAMPLE + Wait-ForVMReady -VMName "MyVM" -VmCredential $myCredential -TimeoutInMinutes 20 +#> function Wait-ForVMReady { param ( [Parameter(Mandatory=$True)][string]$VMName, @@ -107,27 +192,40 @@ function Wait-ForVMReady { throw "Failed to connect to $VMName after timeout..." } -# function Update-VM { -# param ( -# [Parameter(Mandatory=$True)][string]$VMName, -# [Parameter(Mandatory=$True)][System.Management.Automation.PSCredential]$VmCredential -# ) +<# +.SYNOPSIS + Helper function to create a VM. -# # TODO debugging output - remove later -# Get-VMNetworkAdapter -All -# try { Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "ipconfig /all" } catch { Log-Message -Message "Failed to query IP config: $_" -ForegroundColor Red } +.DESCRIPTION + This function creates a new VM with the specified parameters. -# try { Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "Invoke-WebRequest bing.com" } catch { Log-Message -Message "Failed to connect to the internet: $_" -ForegroundColor Red } +.PARAMETER VmName + The name of the VM to create. -# try { Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "Install-PackageProvider -Name NuGet -Force" } catch { Log-Message -Message "Failed to install NuGet provider: $_" -ForegroundColor Red } -# try { Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "Install-Module -Name PSWindowsUpdate -Force" } catch { Log-Message -Message "Failed to install PSWindowsUpdate module: $_" -ForegroundColor Red } -# try { Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "Get-WindowsUpdate -Install -AcceptAll -AutoReboot" } catch { Log-Message -Message "Failed to install updates: $_" -ForegroundColor Red } +.PARAMETER AdminUserCredential + The credentials for the admin user to use for the VM. -# Sleep -Seconds 300 # Sleep for 5 minutes to let the VM start fetching updates, etc... -# Wait-ForVMReady -VMName $VMName -VmCredential $VmCredential -# Log-Message -Message "Successfully updated VM: $VMName" -ForegroundColor Green -# } +.PARAMETER StandardUserCredential + The credentials for the standard user to use for the VM. +.PARAMETER VhdPath + The path to the VHD file to use for the VM. + +.PARAMETER VmStoragePath + The storage path for the VM. + +.PARAMETER VMMemory + The amount of memory to allocate for the VM. + +.PARAMETER UnattendPath + The path to the unattend file to use for the VM. This will notably be used for configuring the user accounts and passwords. + +.PARAMETER VmSwitchName + The name of the switch to use for the VM. + +.EXAMPLE + Create-VM -VmName "MyVM" -AdminUserCredential $adminCredential -StandardUserCredential $userCredential -VhdPath "C:\MyVHD.vhd" -VmStoragePath "C:\VMStorage" -VMMemory 2GB -UnattendPath "C:\MyUnattend.xml" -VmSwitchName "VMInternalSwitch" +#> function Create-VM { param( [Parameter(Mandatory=$True)][string]$VmName, @@ -177,11 +275,6 @@ function Create-VM { # Create the VM Log-Message "Creating the VM" New-VM -Name $VmName -VhdPath $VmVhdPath -SwitchName $VmSwitchName - # $vmSwitches = Get-VMSwitch -ErrorAction Ignore - # foreach ($switch in $vmSwitches) { - # Log-Message "Adding network adapter to VM: $VmName with switch: $($switch.Name)" - # Add-VMNetworkAdapter -VMName $VmName -SwitchName $switch.Name - # } Set-VMMemory -VMName $VmName -DynamicMemoryEnabled $false -StartupBytes $VMMemory if ((Get-VM -VMName $vmName) -eq $null) { @@ -194,6 +287,31 @@ function Create-VM { } } +<# +.SYNOPSIS + Helper function to configure a VM after creation. + +.DESCRIPTION + This function configures a VM after it has been created, including setting the processor count, enabling the Guest Service Interface, and executing a setup script. + +.PARAMETER VmName + The name of the VM to configure. + +.PARAMETER VmCredential + The credentials to use for connecting to the VM. + +.PARAMETER VMCpuCount + The number of processors to allocate for the VM. + +.PARAMETER VMWorkingDirectory + The working directory on the VM to use for executing the setup script. Defaults to 'C:\ebpf_cicd'. + +.PARAMETER VMSetupScript + The path to the setup script to execute on the VM. Defaults to '.\configure_vm.ps1'. + +.EXAMPLE + Configure-VM -VmName "MyVM" -VmCredential $myCredential -VMCpuCount 4 +#> function Configure-VM { param( [Parameter(Mandatory=$True)][string]$VmName, @@ -218,12 +336,7 @@ function Configure-VM { Wait-ForVMReady -VMName $VmName -VmCredential $VmCredential Log-Message "Sleeping for 1 minute to let the VM get into a steady state" - Sleep -Seconds 60 # Sleep for 1 minute to let the VM get into a steady state. - - # # Fetch all updates on the VM - # Log-Message "Fetching Updates on the VM" - # # Update-VM -VMName $VmName -VmCredential $VmCredential - # Log-Message -Message "Successfully updated VM: $VMName" -ForegroundColor Green + Sleep -Seconds 60 # Copy setup script to the VM and execute it. Log-Message "Executing VM configuration script ($VMSetupScript) on VM: $VmName" @@ -256,23 +369,77 @@ function Configure-VM { } ########## Helpers for the host machine ########## -function Install-HyperVIfNeeded { - try { - if ((Get-WindowsFeature -Name 'Hyper-V').Installed) { - Log-Message -Message 'Hyper-V is already installed on this host' - } else { - Log-Message -Message 'Hyper-V is not installed on this host. Installing now...' - - Import-Module ServerManager - Install-WindowsFeature -Name 'Hyper-V' -IncludeManagementTools - Restart-Computer -Force - exit 1 +<# +.SYNOPSIS + Helper function to prepare VHD files for VM creation. + +.DESCRIPTION + Unzips any files in given directory and returns a list of VHD and VHDX files in the input directory. + +.PARAMETER BaseVhdDirPath + The base directory containing the VHD files or zip files containing the VHD files. + +.OUTPUTS + System.IO.FileInfo[] + This function returns a list of System.IO.FileInfo[] representing the VHD and VHDX files found in the input directory + after any processing is complete. + +.EXAMPLE + $vhds = Prepare-VhdFiles -BaseVhdDirPath "C:\path\to\vhd\directory" +#> +function Prepare-VhdFiles { + param( + [Parameter(Mandatory=$True)][string]$BaseVhdDirPath + ) + # Unzip any VHDs + Log-Message "Processing VHDs in $BaseVhdDirPath" + $zipFiles = Get-ChildItem -Path $BaseVhdDirPath -Filter *.zip + foreach ($zipFile in $zipFiles) { + Log-Message "Extracting VHDs from $($zipFile.FullName)" + $outDir = Join-Path -Path $BaseVhdDirPath -ChildPath $zipFile.BaseName + if (-not (Test-Path -Path $outDir)) { + Expand-Archive -Path $zipFile.FullName -DestinationPath $outDir + + # Move the VHDs to the base directory + $vhdFiles = @() + $vhdFiles += Get-ChildItem -Path $outDir -Filter *.vhd -ErrorAction Ignore + $vhdFiles += Get-ChildItem -Path $outDir -Filter *.vhdx -ErrorAction Ignore + foreach ($vhdFile in $vhdFiles) { + Move-Item -Path $vhdFile.FullName -Destination $BaseVhdDirPath + } } - } catch { - throw "Failed to install Hyper-V with error: $_" + Log-Message "Successfully processed $($zipFile.FullName)" + } + + # Read the input VHDs + $vhds = @() + $vhds += Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhd -ErrorAction Ignore + $vhds += Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhdx -ErrorAction Ignore + if ($vhds.Count -eq 0) { + throw "No VHDs found in $BaseVhdDirPath" } + Log-Message "Successfully processed VHDs" + + return $vhds } +<# +.SYNOPSIS + Helper function to create a VM switch if it does not already exist. + +.DESCRIPTION + Checks if a VM switch with the given name and type already exists. If not, it creates a new switch of the specified type. + +.PARAMETER SwitchName + The name of the switch to create. + +.PARAMETER SwitchType + The type of switch to create. Can be 'External' or 'Internal'. + +.EXAMPLE + Create-VMSwitchIfNeeded -SwitchName 'VMInternalSwitch' -SwitchType 'Internal' + Create-VMSwitchIfNeeded -SwitchName 'VMExternalSwitch' -SwitchType 'External' +#> function Create-VMSwitchIfNeeded { param ( [Parameter(Mandatory=$true)][string]$SwitchName, @@ -299,7 +466,6 @@ function Create-VMSwitchIfNeeded { Log-Message "Attempting to creating external switch: $currSwitchName with NetAdapter: $NetAdapterName" New-VMSwitch -Name $currSwitchName -NetAdapterName $NetAdapterName -AllowManagementOS $true $index += 1 - # break } catch { Log-Message "Failed to create external switch for NetAdapter: $NetAdapterName with error: $_" } @@ -326,10 +492,27 @@ function Create-VMSwitchIfNeeded { Log-Message "Successfully created $SwitchType switch with name: $SwitchName" -ForegroundColor Green } -# -# Retrieves the secret from Azure Key Vault. -# Returns a PSCredential object, where the username is the secret name and the password is the retrieved secret. -# +<# +.SYNOPSIS + Retrieves a secret from Azure Key Vault and returns it as a PSCredential object. + +.DESCRIPTION + This function retrieves a secret from Azure Key Vault and returns it as a PSCredential object. + +.PARAMETER KeyVaultName + The name of the Azure Key Vault to retrieve the secret from. Defaults to 'ebpf-cicd-key-vault'. + +.PARAMETER SecretName + The name of the secret to retrieve from the Key Vault. + +.OUTPUTS + System.Management.Automation.PSCredential + This function returns a PSCredential object containing the secret value from the Key Vault. + The username is the input 'SecretName' and the password is the secret value. + +.EXAMPLE + $credential = Get-AzureKeyVaultCredential -SecretName 'Administrator' +#> function Get-AzureKeyVaultCredential { param([Parameter(Mandatory=$False)][string] $KeyVaultName='ebpf-cicd-key-vault', From e8ad61528e25de7f564a5f00e61733a5ee328305 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 3 Jan 2025 10:34:46 -0800 Subject: [PATCH 117/190] test fix of tests --- scripts/run_driver_tests.psm1 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index c77e00488f..4aef93c8ca 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -69,6 +69,8 @@ function Generate-KernelDump # This will/should not return (test system will/should bluescreen and reboot). $NotMyFaultProc = Start-Process -NoNewWindow -Passthru -FilePath $NotMyFaultBinaryPath -ArgumentList "/crash" + # Cache the process handle to ensure subsequent access of the process is accurate + $handle = $NotMyFaultProc.Handle # wait for 30 minutes to generate the kernel dump. $NotMyFaultProc.WaitForExit(30*60*1000) @@ -121,6 +123,8 @@ function Generate-ProcessDump -FilePath $ProcDumpBinaryPath ` -ArgumentList $ProcDumpArguments ` -Wait -PassThru + # Cache the process handle to ensure subsequent access of the process is accurate + $handle = $ProcDumpProcess.Handle Write-Log "Waiting for user mode dump to complete..." $ProcDumpProcess.WaitForExit() @@ -309,8 +313,12 @@ function Invoke-Test $TempErrorFile = "$env:TEMP\app_error.log" # Log for standard error if ($ArgumentsList) { $TestProcess = Start-Process -FilePath $TestFilePath -ArgumentList $ArgumentsList -PassThru -NoNewWindow -RedirectStandardOutput $TempOutputFile -RedirectStandardError $TempErrorFile -ErrorAction Stop + # Cache the process handle to ensure subsequent access of the process is accurate + $handle = $TestProcess.Handle } else { $TestProcess = Start-Process -FilePath $TestFilePath -PassThru -NoNewWindow -RedirectStandardOutput $TempOutputFile -RedirectStandardError $TempErrorFile -ErrorAction Stop + # Cache the process handle to ensure subsequent access of the process is accurate + $handle = $TestProcess.Handle } if ($InnerTestName -ne "") { Process-TestCompletion -TestProcess $TestProcess -TestCommand $InnerTestName -NestedProcess $True -TestHangTimeout $TestHangTimeout @@ -400,6 +408,8 @@ function Invoke-XDPTest $TestCommand = ".\xdp_tests.exe" $TestArguments = "$XDPTestName --remote-ip $RemoteIPV4Address" $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow + # Cache the process handle to ensure subsequent access of the process is accurate + $handle = $TestProcess.Handle if ($TestProcess -eq $null) { Write-Log "Failed to start $TestCommand with arguments $TestArguments" ThrowWithErrorMessage -ErrorMessage "(maige) Failed to start $TestCommand with arguments $TestArguments" @@ -411,6 +421,8 @@ function Invoke-XDPTest $TestCommand = ".\xdp_tests.exe" $TestArguments = "$XDPTestName --remote-ip $RemoteIPV6Address" $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow + # Cache the process handle to ensure subsequent access of the process is accurate + $handle = $TestProcess.Handle if ($TestProcess -eq $null) { Write-Log "Failed to start $TestCommand with arguments $TestArguments" ThrowWithErrorMessage -ErrorMessage "(maige) Failed to start $TestCommand with arguments $TestArguments" @@ -464,6 +476,8 @@ function Invoke-ConnectRedirectTest Write-Log "Executing connect redirect tests with v4 and v6 programs. Arguments: $TestArguments" $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow + # Cache the process handle to ensure subsequent access of the process is accurate + $handle = $TestProcess.Handle Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand @@ -481,6 +495,8 @@ function Invoke-ConnectRedirectTest Write-Log "Executing connect redirect tests with v4 programs. Arguments: $TestArguments" $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow + # Cache the process handle to ensure subsequent access of the process is accurate + $handle = $TestProcess.Handle Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand @@ -498,6 +514,8 @@ function Invoke-ConnectRedirectTest Write-Log "Executing connect redirect tests with v6 programs. Arguments: $TestArguments" $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow + # Cache the process handle to ensure subsequent access of the process is accurate + $handle = $TestProcess.Handle Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand @@ -541,6 +559,8 @@ function Invoke-CICDStressTests # } $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow + # Cache the process handle to ensure subsequent access of the process is accurate + $handle = $TestProcess.Handle # if ($TestProcess -eq $null) { # ThrowWithErrorMessage -ErrorMessage "*** ERROR *** Failed to start $TestCommand." # } From 02569bbc5bcb47cf10872def2ff984a73a1e00f2 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 3 Jan 2025 11:28:15 -0800 Subject: [PATCH 118/190] previous commit seems to be working, trying out removing some debugging code --- scripts/run_driver_tests.psm1 | 45 +++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 4aef93c8ca..3e5d770d9e 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -214,16 +214,18 @@ function Process-TestCompletion throw [System.TimeoutException]::new("Test $TestCommand execution hang timeout ($TestHangTimeout seconds) expired.") } else { Write-Log "(maige) Process-TestCompletion: command should have completed" - try { - $currExitCode = $TestProcess.ExitCode - $temp = $TestProcess | Out-String - Write-Log "Maige - test output: $temp" - Write-Log "MAIGE - $TestCommand exited with code $currExitCode" - Write-Log "maige3 - In Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" - } catch { - Write-Log "maige - failed" - - } + # try { + # $currExitCode = $TestProcess.ExitCode + # $temp = $TestProcess | Out-String + # Write-Log "Maige - test output: $temp" + # Write-Log "MAIGE - $TestCommand exited with code $currExitCode" + # Write-Log "maige3 - In Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" + # } catch { + # Write-Log "maige - failed" + # } + + # Ensure the process has completely exited. + Wait-Process -InputObject $TestProcess # Read and display the output (if any) from the temporary output file. $TempOutputFile = "$env:TEMP\app_output.log" # Log for standard output @@ -238,7 +240,8 @@ function Process-TestCompletion $TestExitCode = $TestProcess.ExitCode Write-Log "Maige - Test exit code: $TestExitCode" - if ($TestExitCode -ne $null -and $TestExitCode -ne 0) { + # if ($TestExitCode -ne $null -and $TestExitCode -ne 0) { + if ($TestExitCode -ne 0) { $TempErrorFile = "$env:TEMP\app_error.log" # Log for standard error if ((Test-Path $TempErrorFile) -and (Get-Item $TempErrorFile).Length -gt 0) { Write-Log "$TestCommand Error Output:`n" -ForegroundColor Red @@ -410,11 +413,11 @@ function Invoke-XDPTest $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow # Cache the process handle to ensure subsequent access of the process is accurate $handle = $TestProcess.Handle - if ($TestProcess -eq $null) { - Write-Log "Failed to start $TestCommand with arguments $TestArguments" - ThrowWithErrorMessage -ErrorMessage "(maige) Failed to start $TestCommand with arguments $TestArguments" - } - Write-Log "maige1 - before Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" + # if ($TestProcess -eq $null) { + # Write-Log "Failed to start $TestCommand with arguments $TestArguments" + # ThrowWithErrorMessage -ErrorMessage "(maige) Failed to start $TestCommand with arguments $TestArguments" + # } + # Write-Log "maige1 - before Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand Write-Log "Executing $XDPTestName with remote address: $RemoteIPV6Address" @@ -423,11 +426,11 @@ function Invoke-XDPTest $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow # Cache the process handle to ensure subsequent access of the process is accurate $handle = $TestProcess.Handle - if ($TestProcess -eq $null) { - Write-Log "Failed to start $TestCommand with arguments $TestArguments" - ThrowWithErrorMessage -ErrorMessage "(maige) Failed to start $TestCommand with arguments $TestArguments" - } - Write-Log "maige2 - before Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" + # if ($TestProcess -eq $null) { + # Write-Log "Failed to start $TestCommand with arguments $TestArguments" + # ThrowWithErrorMessage -ErrorMessage "(maige) Failed to start $TestCommand with arguments $TestArguments" + # } + # Write-Log "maige2 - before Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand Write-Log "$XDPTestName Test Passed" -ForegroundColor Green From 3baa98a1482fd59c59ad1d75aabe4599eb3ecc94 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 3 Jan 2025 12:12:03 -0800 Subject: [PATCH 119/190] test removal of debugging pt 2 --- scripts/run_driver_tests.psm1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 3e5d770d9e..2aa82f0d1d 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -161,7 +161,7 @@ function Process-TestCompletion [Parameter(Mandatory = $false)] [int] $TestHangTimeout = (10*60), # 10 minutes default timeout. [Parameter(Mandatory = $false)] [bool] $NeedKernelDump = $true) - # Write-Log "(maige) Process-TestCompletion (maige)" + Write-Log "(maige) Process-TestCompletion (maige)" # Write-Log "Process-TestCompletion (maige) invoked for $TestCommand" # if ($TestProcess -eq $null) { # Write-Log "Process-TestCompletion: Failed to start $TestCommand" @@ -224,8 +224,8 @@ function Process-TestCompletion # Write-Log "maige - failed" # } - # Ensure the process has completely exited. - Wait-Process -InputObject $TestProcess + # # Ensure the process has completely exited. + # Wait-Process -InputObject $TestProcess # Read and display the output (if any) from the temporary output file. $TempOutputFile = "$env:TEMP\app_output.log" # Log for standard output From 63af262fbf86f5408254e2c95e9d911504a2afa0 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 3 Jan 2025 14:05:51 -0800 Subject: [PATCH 120/190] test --- scripts/run_driver_tests.psm1 | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 2aa82f0d1d..e0ea20767b 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -162,6 +162,7 @@ function Process-TestCompletion [Parameter(Mandatory = $false)] [bool] $NeedKernelDump = $true) Write-Log "(maige) Process-TestCompletion (maige)" + Write-Log "maige2 - In Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" # Write-Log "Process-TestCompletion (maige) invoked for $TestCommand" # if ($TestProcess -eq $null) { # Write-Log "Process-TestCompletion: Failed to start $TestCommand" From 711f0b4582bc770d23c90103a35d81e352d6715c Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 3 Jan 2025 15:07:26 -0800 Subject: [PATCH 121/190] debugging --- scripts/run_driver_tests.psm1 | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index e0ea20767b..d54bfc8ada 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -162,12 +162,12 @@ function Process-TestCompletion [Parameter(Mandatory = $false)] [bool] $NeedKernelDump = $true) Write-Log "(maige) Process-TestCompletion (maige)" + if ($TestProcess -eq $null) { + Write-Log "Process-TestCompletion: Failed to start $TestCommand" + throw "Failed to start $TestCommand" + } Write-Log "maige2 - In Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" # Write-Log "Process-TestCompletion (maige) invoked for $TestCommand" - # if ($TestProcess -eq $null) { - # Write-Log "Process-TestCompletion: Failed to start $TestCommand" - # throw "Failed to start $TestCommand" - # } # try { # # Use Wait-Process for the process to terminate or timeout. @@ -184,8 +184,17 @@ function Process-TestCompletion # Sleep for a few seconds to ensure the process has had a chance to start. # Start-Sleep -Seconds 5 - # Wait for the process to complete or for the timeout to complete. - Wait-Process -InputObject $TestProcess -Timeout $TestHangTimeout -ErrorAction SilentlyContinue + + for ($i = 0; $i -lt 5; $i++) { + try { + # Wait for the process to complete or for the timeout to complete. + Wait-Process -InputObject $TestProcess -Timeout $TestHangTimeout -ErrorAction SilentlyContinue + break + } catch { + Write-Lost "Process-TestCompletion: Wait-Process failed for $TestCommand . Retrying..." + Start-Sleep -Seconds 5 + } + } if (-not $TestProcess.HasExited) { Write-Log "`n*** ERROR *** Test $TestCommand execution hang timeout ($TestHangTimeout seconds) expired.`n" From 10a125db89339b693738d8d96faeecdcb14ad48f Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 3 Jan 2025 16:10:45 -0800 Subject: [PATCH 122/190] Test --- scripts/config_test_vm.psm1 | 2 -- scripts/run_driver_tests.psm1 | 8 ++++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index c7028dcb6d..297bb53b92 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -701,11 +701,9 @@ function Log-OSBuildInformationOnVM { param([parameter(Mandatory=$true)][string] $VMName) - Write-Log "Logging OS build information on $VMName" $TestCredential = New-Credential -Username $Admin -AdminPassword $AdminPassword Invoke-Command -VMName $VMName -Credential $TestCredential -ScriptBlock { $buildLabEx = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name 'BuildLabEx' Write-Output "OS Build Information: $($buildLabEx.BuildLabEx)" } - Write-Log "Finished logging OS build informatino on $VMName" -ForegroundColor Green } \ No newline at end of file diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index d54bfc8ada..1f22ffa0b5 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -191,8 +191,12 @@ function Process-TestCompletion Wait-Process -InputObject $TestProcess -Timeout $TestHangTimeout -ErrorAction SilentlyContinue break } catch { - Write-Lost "Process-TestCompletion: Wait-Process failed for $TestCommand . Retrying..." - Start-Sleep -Seconds 5 + if ($i -eq 4) { + ThrowWithErrorMessage -ErrorMessage "Process-TestCompletion: Wait-Process failed for $TestCommand after 5 retries." + } else { + Write-Log "Process-TestCompletion: Wait-Process failed for $TestCommand . Retrying..." + Start-Sleep -Seconds 5 + } } } From 24558dff37a0e3ff66866d7244a07b6338290629 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 3 Jan 2025 16:54:07 -0800 Subject: [PATCH 123/190] add debugging log --- scripts/run_driver_tests.psm1 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 1f22ffa0b5..afb07bd87e 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -194,7 +194,8 @@ function Process-TestCompletion if ($i -eq 4) { ThrowWithErrorMessage -ErrorMessage "Process-TestCompletion: Wait-Process failed for $TestCommand after 5 retries." } else { - Write-Log "Process-TestCompletion: Wait-Process failed for $TestCommand . Retrying..." + Write-Log "Wait-Process failed for $TestCommand with $_" + Write-Log "Process-TestCompletion Retrying Wait-Process..." Start-Sleep -Seconds 5 } } @@ -431,7 +432,7 @@ function Invoke-XDPTest # Write-Log "Failed to start $TestCommand with arguments $TestArguments" # ThrowWithErrorMessage -ErrorMessage "(maige) Failed to start $TestCommand with arguments $TestArguments" # } - # Write-Log "maige1 - before Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" + Write-Log "maige1 - before Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand Write-Log "Executing $XDPTestName with remote address: $RemoteIPV6Address" @@ -444,7 +445,7 @@ function Invoke-XDPTest # Write-Log "Failed to start $TestCommand with arguments $TestArguments" # ThrowWithErrorMessage -ErrorMessage "(maige) Failed to start $TestCommand with arguments $TestArguments" # } - # Write-Log "maige2 - before Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" + Write-Log "maige2 - before Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand Write-Log "$XDPTestName Test Passed" -ForegroundColor Green From b58287772c7b83d6ec13b61fff8a89a56e09b8dc Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 6 Jan 2025 08:29:29 -0800 Subject: [PATCH 124/190] WIP --- scripts/run_driver_tests.psm1 | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index afb07bd87e..3df219f220 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -162,11 +162,11 @@ function Process-TestCompletion [Parameter(Mandatory = $false)] [bool] $NeedKernelDump = $true) Write-Log "(maige) Process-TestCompletion (maige)" - if ($TestProcess -eq $null) { - Write-Log "Process-TestCompletion: Failed to start $TestCommand" - throw "Failed to start $TestCommand" - } - Write-Log "maige2 - In Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" + # if ($TestProcess -eq $null) { + # Write-Log "Process-TestCompletion: Failed to start $TestCommand" + # throw "Failed to start $TestCommand" + # } + # Write-Log "maige2 - In Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" # Write-Log "Process-TestCompletion (maige) invoked for $TestCommand" # try { @@ -239,8 +239,8 @@ function Process-TestCompletion # Write-Log "maige - failed" # } - # # Ensure the process has completely exited. - # Wait-Process -InputObject $TestProcess + # Ensure the process has completely exited. + Wait-Process -InputObject $TestProcess # Read and display the output (if any) from the temporary output file. $TempOutputFile = "$env:TEMP\app_output.log" # Log for standard output @@ -428,11 +428,7 @@ function Invoke-XDPTest $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow # Cache the process handle to ensure subsequent access of the process is accurate $handle = $TestProcess.Handle - # if ($TestProcess -eq $null) { - # Write-Log "Failed to start $TestCommand with arguments $TestArguments" - # ThrowWithErrorMessage -ErrorMessage "(maige) Failed to start $TestCommand with arguments $TestArguments" - # } - Write-Log "maige1 - before Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" + Write-Log "Started process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand Write-Log "Executing $XDPTestName with remote address: $RemoteIPV6Address" @@ -441,11 +437,7 @@ function Invoke-XDPTest $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow # Cache the process handle to ensure subsequent access of the process is accurate $handle = $TestProcess.Handle - # if ($TestProcess -eq $null) { - # Write-Log "Failed to start $TestCommand with arguments $TestArguments" - # ThrowWithErrorMessage -ErrorMessage "(maige) Failed to start $TestCommand with arguments $TestArguments" - # } - Write-Log "maige2 - before Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" + Write-Log "Started process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand Write-Log "$XDPTestName Test Passed" -ForegroundColor Green From 59171ed1db876f3d0d3d712e0d48921ed2e4084a Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 6 Jan 2025 09:29:56 -0800 Subject: [PATCH 125/190] wip --- scripts/run_driver_tests.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 3df219f220..7c5900d82c 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -239,8 +239,8 @@ function Process-TestCompletion # Write-Log "maige - failed" # } - # Ensure the process has completely exited. - Wait-Process -InputObject $TestProcess + # # Ensure the process has completely exited. + # Wait-Process -InputObject $TestProcess # Read and display the output (if any) from the temporary output file. $TempOutputFile = "$env:TEMP\app_output.log" # Log for standard output From 9701fa47022c185a4f7614679629deae0a518edf Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 6 Jan 2025 10:26:14 -0800 Subject: [PATCH 126/190] remove unneeded code in tests --- .github/workflows/reusable-test.yml | 6 - scripts/cleanup_ebpf_cicd_tests.ps1 | 10 +- scripts/execute_ebpf_cicd_tests.ps1 | 4 +- scripts/run_driver_tests.psm1 | 187 ++++++++++------------------ scripts/setup_ebpf_cicd_tests.ps1 | 5 +- 5 files changed, 66 insertions(+), 146 deletions(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 35ff58f171..8b28c3a09f 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -91,12 +91,6 @@ jobs: with: egress-policy: audit - - name: Check runner configuration (TODO possibly remove, if not needed) - id: configure-runner - if: contains(inputs.environment, 'self-hosted') - run: | - powershell.exe "Get-VM; Get-ChildItem 'C:\work' -Recurse;" - - name: Print CPU information run: Get-WmiObject -Class Win32_Processor | Select-Object -Property Name, NumberOfCores, NumberOfLogicalProcessors diff --git a/scripts/cleanup_ebpf_cicd_tests.ps1 b/scripts/cleanup_ebpf_cicd_tests.ps1 index 34a9e5abe2..f9ea065d05 100644 --- a/scripts/cleanup_ebpf_cicd_tests.ps1 +++ b/scripts/cleanup_ebpf_cicd_tests.ps1 @@ -6,14 +6,12 @@ param ([parameter(Mandatory=$false)][string] $Target = "TEST_VM", [parameter(Mandatory=$false)][string] $LogFileName = "TestLog.log", [parameter(Mandatory=$false)][string] $WorkingDirectory = $pwd.ToString(), [parameter(Mandatory=$false)][string] $TestExecutionJsonFileName = "test_execution.json", - [parameter(Mandatory=$false)][string] $SelfHostedRunnerName = [System.Net.Dns]::GetHostName(), + [parameter(Mandatory=$false)][string] $SelfHostedRunnerName = "runner_host", [Parameter(Mandatory = $false)][int] $TestJobTimeout = (30*60)) Push-Location $WorkingDirectory Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue -$SelfHostedRunnerName = "runner_host" -Write-Host "SelfHostedRunnerName: $SelfHostedRunnerName, Target: $Target" $TestVMCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' # Read the test execution json. @@ -49,12 +47,6 @@ $Job = Start-Job -ScriptBlock { -VMName $VMName ` -Credential $TestVMCredential ` -ScriptBlock { - # TODO - remove this debugging output - ipconfig /all - Get-NetIPInterface | Out-String - Get-NetAdapter | Out-String - Get-NetAdapterBinding -AllBindings | Out-String - Test-Path -Path "c:\windows\memory.dmp" -PathType leaf } diff --git a/scripts/execute_ebpf_cicd_tests.ps1 b/scripts/execute_ebpf_cicd_tests.ps1 index 6ed00ab6de..c645f44f48 100644 --- a/scripts/execute_ebpf_cicd_tests.ps1 +++ b/scripts/execute_ebpf_cicd_tests.ps1 @@ -8,7 +8,7 @@ param ([Parameter(Mandatory = $false)][string] $AdminTarget = "TEST_VM", [Parameter(Mandatory = $false)][string] $TestExecutionJsonFileName = "test_execution.json", [Parameter(Mandatory = $false)][string] $TestMode = "CI/CD", [Parameter(Mandatory = $false)][string[]] $Options = @("None"), - [Parameter(Mandatory = $false)][string] $SelfHostedRunnerName = [System.Net.Dns]::GetHostName(), + [Parameter(Mandatory = $false)][string] $SelfHostedRunnerName = "runner_host", [Parameter(Mandatory = $false)][int] $TestHangTimeout = (10*60), [Parameter(Mandatory = $false)][string] $UserModeDumpFolder = "C:\Dumps", [Parameter(Mandatory = $false)][int] $TestJobTimeout = (60*60) @@ -18,8 +18,6 @@ Push-Location $WorkingDirectory Import-Module $WorkingDirectory\common.psm1 -Force -ArgumentList ($LogFileName) -ErrorAction Stop -$SelfHostedRunnerName = "runner_host" -Write-Host "SelfHostedRunnerName: $SelfHostedRunnerName, AdminTarget: $AdminTarget, StandardUserTarget: $StandardUserTarget" $AdminTestVMCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' $StandardUserTestVMCredential = Get-AzureKeyVaultCredential -SecretName 'VMStandardUser' diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 7c5900d82c..79e4605fd2 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -160,46 +160,23 @@ function Process-TestCompletion [Parameter(Mandatory = $false)] [bool] $NestedProcess, [Parameter(Mandatory = $false)] [int] $TestHangTimeout = (10*60), # 10 minutes default timeout. [Parameter(Mandatory = $false)] [bool] $NeedKernelDump = $true) - - Write-Log "(maige) Process-TestCompletion (maige)" - # if ($TestProcess -eq $null) { - # Write-Log "Process-TestCompletion: Failed to start $TestCommand" - # throw "Failed to start $TestCommand" - # } - # Write-Log "maige2 - In Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" - # Write-Log "Process-TestCompletion (maige) invoked for $TestCommand" - - # try { - # # Use Wait-Process for the process to terminate or timeout. - # # See https://stackoverflow.com/a/23797762 - # Wait-Process -InputObject $TestProcess -Timeout $TestHangTimeout -ErrorAction SilentlyContinue - # Write-Log "(maige) Process-TestCompletion: Process exit code: $($TestProcess.ExitCode)" - # } catch { - # Write-Log "(CATCH) Process-TestCompletion: Failed to wait for $TestCommand" - # Write-Log "(maige) Process-TestCompletion: Process exit code: $($TestProcess.ExitCode)" - # Write-Log "(maige) Error: $_" - # throw "Failed to wait for $TestCommand" + # for ($i = 0; $i -lt 5; $i++) { + # try { + # # Wait for the process to complete or for the timeout to complete. + # Wait-Process -InputObject $TestProcess -Timeout $TestHangTimeout -ErrorAction SilentlyContinue + # break + # } catch { + # if ($i -eq 4) { + # ThrowWithErrorMessage -ErrorMessage "Process-TestCompletion: Wait-Process failed for $TestCommand after 5 retries." + # } else { + # Write-Log "Wait-Process failed for $TestCommand with $_" + # Write-Log "Process-TestCompletion Retrying Wait-Process..." + # Start-Sleep -Seconds 5 + # } + # } # } - - # Sleep for a few seconds to ensure the process has had a chance to start. - # Start-Sleep -Seconds 5 - - - for ($i = 0; $i -lt 5; $i++) { - try { - # Wait for the process to complete or for the timeout to complete. - Wait-Process -InputObject $TestProcess -Timeout $TestHangTimeout -ErrorAction SilentlyContinue - break - } catch { - if ($i -eq 4) { - ThrowWithErrorMessage -ErrorMessage "Process-TestCompletion: Wait-Process failed for $TestCommand after 5 retries." - } else { - Write-Log "Wait-Process failed for $TestCommand with $_" - Write-Log "Process-TestCompletion Retrying Wait-Process..." - Start-Sleep -Seconds 5 - } - } - } + # Wait for the process to complete or for the timeout to complete. + Wait-Process -InputObject $TestProcess -Timeout $TestHangTimeout -ErrorAction SilentlyContinue if (-not $TestProcess.HasExited) { Write-Log "`n*** ERROR *** Test $TestCommand execution hang timeout ($TestHangTimeout seconds) expired.`n" @@ -228,20 +205,6 @@ function Process-TestCompletion Write-Log "Throwing TestHungException for $TestCommand" -ForegroundColor Red throw [System.TimeoutException]::new("Test $TestCommand execution hang timeout ($TestHangTimeout seconds) expired.") } else { - Write-Log "(maige) Process-TestCompletion: command should have completed" - # try { - # $currExitCode = $TestProcess.ExitCode - # $temp = $TestProcess | Out-String - # Write-Log "Maige - test output: $temp" - # Write-Log "MAIGE - $TestCommand exited with code $currExitCode" - # Write-Log "maige3 - In Process-TestCompletion with process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" - # } catch { - # Write-Log "maige - failed" - # } - - # # Ensure the process has completely exited. - # Wait-Process -InputObject $TestProcess - # Read and display the output (if any) from the temporary output file. $TempOutputFile = "$env:TEMP\app_output.log" # Log for standard output # Process the log file line-by-line @@ -254,8 +217,7 @@ function Process-TestCompletion } $TestExitCode = $TestProcess.ExitCode - Write-Log "Maige - Test exit code: $TestExitCode" - # if ($TestExitCode -ne $null -and $TestExitCode -ne 0) { + Write-Log "Test exit code: $TestExitCode" if ($TestExitCode -ne 0) { $TempErrorFile = "$env:TEMP\app_error.log" # Log for standard error if ((Test-Path $TempErrorFile) -and (Get-Item $TempErrorFile).Length -gt 0) { @@ -314,42 +276,37 @@ function Invoke-Test [Parameter(Mandatory = $True)][bool] $VerboseLogs, [Parameter(Mandatory = $True)][int] $TestHangTimeout) - # try { - # Initialize arguments. - if ($TestArgs -ne "") { - $ArgumentsList = @($TestArgs) - } + # Initialize arguments. + if ($TestArgs -ne "") { + $ArgumentsList = @($TestArgs) + } - if ($VerboseLogs -eq $true) { - $ArgumentsList += '-s' - } + if ($VerboseLogs -eq $true) { + $ArgumentsList += '-s' + } - # Execute Test. - Write-Log "Executing $TestName $TestArgs" - $TestFilePath = "$pwd\$TestName" - $TempOutputFile = "$env:TEMP\app_output.log" # Log for standard output - $TempErrorFile = "$env:TEMP\app_error.log" # Log for standard error - if ($ArgumentsList) { - $TestProcess = Start-Process -FilePath $TestFilePath -ArgumentList $ArgumentsList -PassThru -NoNewWindow -RedirectStandardOutput $TempOutputFile -RedirectStandardError $TempErrorFile -ErrorAction Stop - # Cache the process handle to ensure subsequent access of the process is accurate - $handle = $TestProcess.Handle - } else { - $TestProcess = Start-Process -FilePath $TestFilePath -PassThru -NoNewWindow -RedirectStandardOutput $TempOutputFile -RedirectStandardError $TempErrorFile -ErrorAction Stop - # Cache the process handle to ensure subsequent access of the process is accurate - $handle = $TestProcess.Handle - } - if ($InnerTestName -ne "") { - Process-TestCompletion -TestProcess $TestProcess -TestCommand $InnerTestName -NestedProcess $True -TestHangTimeout $TestHangTimeout - } else { - Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestName -TestHangTimeout $TestHangTimeout - } + # Execute Test. + Write-Log "Executing $TestName $TestArgs" + $TestFilePath = "$pwd\$TestName" + $TempOutputFile = "$env:TEMP\app_output.log" # Log for standard output + $TempErrorFile = "$env:TEMP\app_error.log" # Log for standard error + if ($ArgumentsList) { + $TestProcess = Start-Process -FilePath $TestFilePath -ArgumentList $ArgumentsList -PassThru -NoNewWindow -RedirectStandardOutput $TempOutputFile -RedirectStandardError $TempErrorFile -ErrorAction Stop + # Cache the process handle to ensure subsequent access of the process is accurate + $handle = $TestProcess.Handle + } else { + $TestProcess = Start-Process -FilePath $TestFilePath -PassThru -NoNewWindow -RedirectStandardOutput $TempOutputFile -RedirectStandardError $TempErrorFile -ErrorAction Stop + # Cache the process handle to ensure subsequent access of the process is accurate + $handle = $TestProcess.Handle + } + if ($InnerTestName -ne "") { + Process-TestCompletion -TestProcess $TestProcess -TestCommand $InnerTestName -NestedProcess $True -TestHangTimeout $TestHangTimeout + } else { + Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestName -TestHangTimeout $TestHangTimeout + } - Write-Log "Test `"$TestName $TestArgs`" Passed" -ForegroundColor Green - Write-Log "`n==============================`n" - # } catch { - # $ErrorMessage = $_.Exception.Message - # ThrowWithErrorMessage -ErrorMessage "(maige) Test `"$TestName $TestArgs`" Failed with $ErrorMessage" - # } + Write-Log "Test `"$TestName $TestArgs`" Passed" -ForegroundColor Green + Write-Log "`n==============================`n" } # Function to create a tuple with default values for Arguments and Timeout @@ -421,31 +378,26 @@ function Invoke-XDPTest Push-Location $WorkingDirectory - # try { - Write-Log "Executing $XDPTestName with remote address: $RemoteIPV4Address" - $TestCommand = ".\xdp_tests.exe" - $TestArguments = "$XDPTestName --remote-ip $RemoteIPV4Address" - $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - # Cache the process handle to ensure subsequent access of the process is accurate - $handle = $TestProcess.Handle - Write-Log "Started process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" - Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand + Write-Log "Executing $XDPTestName with remote address: $RemoteIPV4Address" + $TestCommand = ".\xdp_tests.exe" + $TestArguments = "$XDPTestName --remote-ip $RemoteIPV4Address" + $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow + # Cache the process handle to ensure subsequent access of the process is accurate + $handle = $TestProcess.Handle + Write-Log "Started process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" + Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand - Write-Log "Executing $XDPTestName with remote address: $RemoteIPV6Address" - $TestCommand = ".\xdp_tests.exe" - $TestArguments = "$XDPTestName --remote-ip $RemoteIPV6Address" - $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - # Cache the process handle to ensure subsequent access of the process is accurate - $handle = $TestProcess.Handle - Write-Log "Started process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" - Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand + Write-Log "Executing $XDPTestName with remote address: $RemoteIPV6Address" + $TestCommand = ".\xdp_tests.exe" + $TestArguments = "$XDPTestName --remote-ip $RemoteIPV6Address" + $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow + # Cache the process handle to ensure subsequent access of the process is accurate + $handle = $TestProcess.Handle + Write-Log "Started process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" + Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand - Write-Log "$XDPTestName Test Passed" -ForegroundColor Green - Write-Log "`n`n" - # } catch { - # $ErrorMessage = $_.Exception.Message - # ThrowWithErrorMessage -ErrorMessage "(maige) XDP test Failed with $ErrorMessage" - # } + Write-Log "$XDPTestName Test Passed" -ForegroundColor Green + Write-Log "`n`n" Pop-Location } @@ -557,23 +509,10 @@ function Invoke-CICDStressTests $TestArguments = "-tt=8 -td=5 -erd=1000 -er=1" } - # TODO - remove debugging output - # Write-Log "Items from .\" - # Get-ChildItem '.\' - # Write-Log "Items from $WorkingDirectory" - # Get-ChildItem $WorkingDirectory Write-Log "Starting $TestCommand with arguments: $TestArguments" - # # Valid that the test command exists. - # if (-not (Test-Path $TestCommand)) { - # ThrowWithErrorMessage -ErrorMessage "*** ERROR *** $TestCommand not found under $WorkingDirectory." - # } - $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow # Cache the process handle to ensure subsequent access of the process is accurate $handle = $TestProcess.Handle - # if ($TestProcess -eq $null) { - # ThrowWithErrorMessage -ErrorMessage "*** ERROR *** Failed to start $TestCommand." - # } Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index 24dbdd7fc8..795b4f05ce 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -10,17 +10,14 @@ param ([parameter(Mandatory=$false)][string] $Target = "TEST_VM", [parameter(Mandatory=$false)][string] $RegressionArtifactsVersion = "", [parameter(Mandatory=$false)][string] $RegressionArtifactsConfiguration = "", [parameter(Mandatory=$false)][string] $TestExecutionJsonFileName = "test_execution.json", - [parameter(Mandatory=$false)][string] $SelfHostedRunnerName = [System.Net.Dns]::GetHostName(), + [parameter(Mandatory=$false)][string] $SelfHostedRunnerName = "runner_host", [Parameter(Mandatory = $false)][int] $TestJobTimeout = (30*60)) Push-Location $WorkingDirectory # Load other utility modules. Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue -$SelfHostedRunnerName = "runner_host" $TestVMCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' -Write-Host "(maige) - cred $TestVMCredential and type $($TestVMCredential.GetType())" -Write-Host "(maige) credential UserName: $($TestVMCredential.UserName) and password: $($TestVMCredential.Password)" Import-Module .\config_test_vm.psm1 -Force -ArgumentList ($TestVMCredential.UserName, $TestVMCredential.Password, $WorkingDirectory, $LogFileName) -WarningAction SilentlyContinue From 77eed1837549ddf3b6333b67f52a55ef30bfbbf8 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 6 Jan 2025 10:57:46 -0800 Subject: [PATCH 127/190] fixes --- .github/workflows/reusable-test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 8b28c3a09f..ab5da60a4e 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -245,7 +245,7 @@ jobs: id: run_pre_test_command_self_hosted working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | - ${{env.PRE_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} -RegressionArtifactsConfiguration ${{env.BUILD_CONFIGURATION}} + ${{env.PRE_COMMAND}} -RegressionArtifactsConfiguration ${{env.BUILD_CONFIGURATION}} # TODO: Clean up the combination of options: https://github.com/microsoft/ebpf-for-windows/issues/1590 - name: Run test with Code Coverage in VS Dev environment @@ -287,7 +287,7 @@ jobs: id: run_test_self_hosted working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | - ${{env.TEST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} + ${{env.TEST_COMMAND}} - name: Run test without Code Coverage if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && !contains(inputs.environment, 'self-hosted') && (inputs.fault_injection != true) @@ -312,7 +312,7 @@ jobs: id: run_post_test_command_self_hosted working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | - ${{env.POST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} + ${{env.POST_COMMAND}} - name: Check for CodeCoverage if: steps.skip_check.outputs.should_skip != 'true' From fbc6067644e590f78aa53c5b81eeda128b424a1f Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 6 Jan 2025 11:49:46 -0800 Subject: [PATCH 128/190] remove more unnecessry script changes --- scripts/run_driver_tests.psm1 | 40 +++-------------------------------- 1 file changed, 3 insertions(+), 37 deletions(-) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 79e4605fd2..f5d5702ddf 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -69,8 +69,6 @@ function Generate-KernelDump # This will/should not return (test system will/should bluescreen and reboot). $NotMyFaultProc = Start-Process -NoNewWindow -Passthru -FilePath $NotMyFaultBinaryPath -ArgumentList "/crash" - # Cache the process handle to ensure subsequent access of the process is accurate - $handle = $NotMyFaultProc.Handle # wait for 30 minutes to generate the kernel dump. $NotMyFaultProc.WaitForExit(30*60*1000) @@ -123,8 +121,6 @@ function Generate-ProcessDump -FilePath $ProcDumpBinaryPath ` -ArgumentList $ProcDumpArguments ` -Wait -PassThru - # Cache the process handle to ensure subsequent access of the process is accurate - $handle = $ProcDumpProcess.Handle Write-Log "Waiting for user mode dump to complete..." $ProcDumpProcess.WaitForExit() @@ -160,22 +156,9 @@ function Process-TestCompletion [Parameter(Mandatory = $false)] [bool] $NestedProcess, [Parameter(Mandatory = $false)] [int] $TestHangTimeout = (10*60), # 10 minutes default timeout. [Parameter(Mandatory = $false)] [bool] $NeedKernelDump = $true) - # for ($i = 0; $i -lt 5; $i++) { - # try { - # # Wait for the process to complete or for the timeout to complete. - # Wait-Process -InputObject $TestProcess -Timeout $TestHangTimeout -ErrorAction SilentlyContinue - # break - # } catch { - # if ($i -eq 4) { - # ThrowWithErrorMessage -ErrorMessage "Process-TestCompletion: Wait-Process failed for $TestCommand after 5 retries." - # } else { - # Write-Log "Wait-Process failed for $TestCommand with $_" - # Write-Log "Process-TestCompletion Retrying Wait-Process..." - # Start-Sleep -Seconds 5 - # } - # } - # } - # Wait for the process to complete or for the timeout to complete. + + # Use Wait-Process for the process to terminate or timeout. + # See https://stackoverflow.com/a/23797762 Wait-Process -InputObject $TestProcess -Timeout $TestHangTimeout -ErrorAction SilentlyContinue if (-not $TestProcess.HasExited) { @@ -292,12 +275,8 @@ function Invoke-Test $TempErrorFile = "$env:TEMP\app_error.log" # Log for standard error if ($ArgumentsList) { $TestProcess = Start-Process -FilePath $TestFilePath -ArgumentList $ArgumentsList -PassThru -NoNewWindow -RedirectStandardOutput $TempOutputFile -RedirectStandardError $TempErrorFile -ErrorAction Stop - # Cache the process handle to ensure subsequent access of the process is accurate - $handle = $TestProcess.Handle } else { $TestProcess = Start-Process -FilePath $TestFilePath -PassThru -NoNewWindow -RedirectStandardOutput $TempOutputFile -RedirectStandardError $TempErrorFile -ErrorAction Stop - # Cache the process handle to ensure subsequent access of the process is accurate - $handle = $TestProcess.Handle } if ($InnerTestName -ne "") { Process-TestCompletion -TestProcess $TestProcess -TestCommand $InnerTestName -NestedProcess $True -TestHangTimeout $TestHangTimeout @@ -382,8 +361,6 @@ function Invoke-XDPTest $TestCommand = ".\xdp_tests.exe" $TestArguments = "$XDPTestName --remote-ip $RemoteIPV4Address" $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - # Cache the process handle to ensure subsequent access of the process is accurate - $handle = $TestProcess.Handle Write-Log "Started process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand @@ -391,8 +368,6 @@ function Invoke-XDPTest $TestCommand = ".\xdp_tests.exe" $TestArguments = "$XDPTestName --remote-ip $RemoteIPV6Address" $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - # Cache the process handle to ensure subsequent access of the process is accurate - $handle = $TestProcess.Handle Write-Log "Started process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand @@ -438,8 +413,6 @@ function Invoke-ConnectRedirectTest Write-Log "Executing connect redirect tests with v4 and v6 programs. Arguments: $TestArguments" $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - # Cache the process handle to ensure subsequent access of the process is accurate - $handle = $TestProcess.Handle Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand @@ -457,8 +430,6 @@ function Invoke-ConnectRedirectTest Write-Log "Executing connect redirect tests with v4 programs. Arguments: $TestArguments" $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - # Cache the process handle to ensure subsequent access of the process is accurate - $handle = $TestProcess.Handle Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand @@ -476,8 +447,6 @@ function Invoke-ConnectRedirectTest Write-Log "Executing connect redirect tests with v6 programs. Arguments: $TestArguments" $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - # Cache the process handle to ensure subsequent access of the process is accurate - $handle = $TestProcess.Handle Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand @@ -509,10 +478,7 @@ function Invoke-CICDStressTests $TestArguments = "-tt=8 -td=5 -erd=1000 -er=1" } - Write-Log "Starting $TestCommand with arguments: $TestArguments" $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - # Cache the process handle to ensure subsequent access of the process is accurate - $handle = $TestProcess.Handle Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand From 8fce36985e3780f88a4b6a1dd3b77ff62c619d36 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 6 Jan 2025 13:04:23 -0800 Subject: [PATCH 129/190] add back in handle cache --- scripts/run_driver_tests.psm1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index f5d5702ddf..8ce63fc45f 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -69,6 +69,8 @@ function Generate-KernelDump # This will/should not return (test system will/should bluescreen and reboot). $NotMyFaultProc = Start-Process -NoNewWindow -Passthru -FilePath $NotMyFaultBinaryPath -ArgumentList "/crash" + # Cache the process handle to ensure subsequent access of the process is accurate + $handle = $NotMyFaultProc.Handle # wait for 30 minutes to generate the kernel dump. $NotMyFaultProc.WaitForExit(30*60*1000) @@ -121,6 +123,8 @@ function Generate-ProcessDump -FilePath $ProcDumpBinaryPath ` -ArgumentList $ProcDumpArguments ` -Wait -PassThru + # Cache the process handle to ensure subsequent access of the process is accurate + $handle = $ProcDumpProcess.Handle Write-Log "Waiting for user mode dump to complete..." $ProcDumpProcess.WaitForExit() @@ -156,6 +160,8 @@ function Process-TestCompletion [Parameter(Mandatory = $false)] [bool] $NestedProcess, [Parameter(Mandatory = $false)] [int] $TestHangTimeout = (10*60), # 10 minutes default timeout. [Parameter(Mandatory = $false)] [bool] $NeedKernelDump = $true) + # Cache the process handle to ensure subsequent access of the process is accurate + $handle = $TestProcess.Handle # Use Wait-Process for the process to terminate or timeout. # See https://stackoverflow.com/a/23797762 @@ -278,6 +284,7 @@ function Invoke-Test } else { $TestProcess = Start-Process -FilePath $TestFilePath -PassThru -NoNewWindow -RedirectStandardOutput $TempOutputFile -RedirectStandardError $TempErrorFile -ErrorAction Stop } + if ($InnerTestName -ne "") { Process-TestCompletion -TestProcess $TestProcess -TestCommand $InnerTestName -NestedProcess $True -TestHangTimeout $TestHangTimeout } else { From fa68ee4cff9e6de315853f4263c883213408a56f Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 6 Jan 2025 13:53:02 -0800 Subject: [PATCH 130/190] test xdp fix --- scripts/run_driver_tests.psm1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 8ce63fc45f..150be803ac 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -368,6 +368,9 @@ function Invoke-XDPTest $TestCommand = ".\xdp_tests.exe" $TestArguments = "$XDPTestName --remote-ip $RemoteIPV4Address" $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow + # Cache the process handle to ensure subsequent access of the process is accurate + $handle = $TestProcess.Handle + Write-Log "Started process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand @@ -375,6 +378,8 @@ function Invoke-XDPTest $TestCommand = ".\xdp_tests.exe" $TestArguments = "$XDPTestName --remote-ip $RemoteIPV6Address" $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow + # Cache the process handle to ensure subsequent access of the process is accurate + $handle = $TestProcess.Handle Write-Log "Started process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand From 48c14a2e567e8c85b4b5b2439fd787a8b71c3220 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 10 Jan 2025 15:40:07 -0800 Subject: [PATCH 131/190] updates with new base image --- .github/workflows/cicd.yml | 14 +++++++------- 1es/artifacts.json | 14 +++++++++++++- 1es/prepare_vm_helpers.psm1 | 5 ++++- scripts/common.psm1 | 6 +++++- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 3230f19f02..82877767a9 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -207,7 +207,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_ws2019 build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server-2019"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2019"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage @@ -226,7 +226,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_ws2022 build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server-2022"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2022"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage @@ -245,7 +245,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_native_only_ws2019 build_artifact: Build-x64-native-only - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server-2019"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2019"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage @@ -264,7 +264,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_native_only_ws2022 build_artifact: Build-x64-native-only - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server-2022"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2022"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage @@ -284,7 +284,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: regression_driver_ws2022 build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server-2022"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2022"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage @@ -584,7 +584,7 @@ jobs: test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Stress" post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server-2019"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2019"]' code_coverage: false # For this test, we only want kernel mode dumps and not user mode dumps. gather_dumps: false @@ -603,7 +603,7 @@ jobs: test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Stress" -Options @("RestartExtension") post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server-2019"]' + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2019"]' code_coverage: false # For this test, we only want kernel mode dumps and not user mode dumps. gather_dumps: false diff --git a/1es/artifacts.json b/1es/artifacts.json index 40651f9fcb..1f4f55c542 100644 --- a/1es/artifacts.json +++ b/1es/artifacts.json @@ -2,7 +2,19 @@ "license":["Copyright (c) eBPF for Windows contributors", "SPDX-License-Identifier: MIT"], "artifacts": [ { - "Name": "windows-server-install-feature-hyperv" + "name": "windows-enabledismfeature", + "parameters": { + "FeatureName": "Microsoft-Hyper-V" + } + }, + { + "name": "windows-enabledismfeature", + "parameters": { + "FeatureName": "Microsoft-Hyper-V-Management-PowerShell" + } + }, + { + "name": "windows-restart" }, { "Name": "windows-azcopy-downloadfile-msi", diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index c9f402cee0..2219febd89 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -519,9 +519,12 @@ function Get-AzureKeyVaultCredential [Parameter(Mandatory=$True)][string] $SecretName) try { + # NuGet is a dependency for the Az module. Ensure it is installed too. + Install-PackageProvider -Name NuGet -Force -ErrorAction Stop *> $null 2>&1 + Import-PackageProvider -Name NuGet -Force -ErrorAction Stop *> $null 2>&1 # Check if the Az module is installed, if not, install it if (-not (Get-Module -ListAvailable -Name Az)) { - Install-Module -Name Az -AllowClobber -Force *> $null 2>&1 + Install-Module -Name Az -AllowClobber -Force -ErrorAction Stop *> $null 2>&1 } # Authenticate using the managed identity diff --git a/scripts/common.psm1 b/scripts/common.psm1 index 8028dfcd5c..006da5fbc3 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -53,9 +53,13 @@ function Get-AzureKeyVaultCredential [Parameter(Mandatory=$True)][string] $SecretName) try { + # NuGet is a dependency for the Az module. Ensure it is installed too. + Install-PackageProvider -Name NuGet -Force -ErrorAction Stop *> $null 2>&1 + Import-PackageProvider -Name NuGet -Force -ErrorAction Stop *> $null 2>&1 + # Check if the Az module is installed, if not, install it if (-not (Get-Module -ListAvailable -Name Az)) { - Install-Module -Name Az -AllowClobber -Force *> $null 2>&1 + Install-Module -Name Az -AllowClobber -Force -ErrorAction Stop *> $null 2>&1 } # Authenticate using the managed identity From 3f482c03c0ef1b04835f7aa5b3134c8fdbb6c803 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 14 Jan 2025 14:15:18 -0800 Subject: [PATCH 132/190] add 2025 --- .github/workflows/cicd.yml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 82877767a9..f8ff5047e9 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -232,6 +232,25 @@ jobs: # driver tests manually gather code coverage code_coverage: false + # Run the driver tests on self-hosted runners. + driver_ws2025: + # Always run this job. + # Only run this on repos that have self-host runners. + needs: regular + if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') + uses: ./.github/workflows/reusable-test.yml + with: + pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" + test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" + post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + name: driver_ws2025 + build_artifact: Build-x64 + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2025"]' + # driver test copies dumps to testlog folder. + gather_dumps: false + # driver tests manually gather code coverage + code_coverage: false + # Run the native-only driver tests on self-hosted runners. driver_native_only_ws2019: # Always run this job. @@ -271,6 +290,25 @@ jobs: code_coverage: false configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' + driver_native_only_ws2025: + # Always run this job. + # Only run this on repos that have self-host runners. + needs: regular_native-only + if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') + uses: ./.github/workflows/reusable-test.yml + with: + pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" + test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" + post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + name: driver_native_only_ws2025 + build_artifact: Build-x64-native-only + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2025"]' + # driver test copies dumps to testlog folder. + gather_dumps: false + # driver tests manually gather code coverage + code_coverage: false + configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' + # Run the regression driver tests on self-hosted runners (only for 2022). regression_driver_ws2022: # Always run this job. From fdf30f8c0e35c3daeea0d6fd7525465e318b33a0 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 14 Jan 2025 14:26:52 -0800 Subject: [PATCH 133/190] wip --- scripts/common.psm1 | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/common.psm1 b/scripts/common.psm1 index 006da5fbc3..612fc182c8 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -51,7 +51,6 @@ function Get-AzureKeyVaultCredential { param([Parameter(Mandatory=$False)][string] $KeyVaultName='ebpf-cicd-key-vault', [Parameter(Mandatory=$True)][string] $SecretName) - try { # NuGet is a dependency for the Az module. Ensure it is installed too. Install-PackageProvider -Name NuGet -Force -ErrorAction Stop *> $null 2>&1 From 296631781f983bd3f0099ab67b445295e3e648cb Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 17 Jan 2025 15:31:04 -0800 Subject: [PATCH 134/190] use stored credentials, deployment script changes --- 1es/Setup.ps1 | 26 ++-- 1es/prepare_vm_helpers.psm1 | 191 ++++++++++++++++++++++------ scripts/cleanup_ebpf_cicd_tests.ps1 | 3 +- scripts/execute_ebpf_cicd_tests.ps1 | 6 +- scripts/setup_ebpf_cicd_tests.ps1 | 4 +- 5 files changed, 179 insertions(+), 51 deletions(-) diff --git a/1es/Setup.ps1 b/1es/Setup.ps1 index 3bcf0cdada..a16ab0aac6 100644 --- a/1es/Setup.ps1 +++ b/1es/Setup.ps1 @@ -55,18 +55,22 @@ Create-DirectoryIfNotExists -Path $WorkingPath $VMSwitchName = 'VMInternalSwitch' Create-VMSwitchIfNeeded -SwitchName $VMSwitchName -SwitchType 'Internal' -# Fetch the credentials for the VM using the Azure Key Vault. -$AdminUserCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' -$StandardUserCredential = Get-AzureKeyVaultCredential -SecretName 'VMStandardUser' +# # Fetch the credentials for the VM using the Azure Key Vault. +# $AdminUserCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' +# $StandardUserCredential = Get-AzureKeyVaultCredential -SecretName 'VMStandardUser' +$AdminUserCredential = Generate-StoredCredential -Target 'TEST_VM' -Username 'Administrator' +$StandardUserCredential = Generate-StoredCredential -Target 'TEST_VM_STANDARD' -Username 'VMStandardUser' # Unzip any VHD files, if needed, and get the list of VHDs to create VMs from. -$vhds = Prepare-VhdFiles -BaseVhdDirPath $BaseVhdDirPath +$vhds = Prepare-VhdFiles -InputDirectory $BaseVhdDirPath +Log-Message "Found $($vhds.Count) VHDs to create VMs from." +$vhdDebugString = $vhds | Out-String +Log-Message "VHDs: $vhdDebugString" # Process VM creation and setup. -for ($i = 0; $i -lt $vhds.Count; $i++) { +foreach ($vhd in $vhds) { try { - $vhd = $vhds[$i] - Log-Message -Message "Creating VM from VHD: $($vhd.FullName)" + Log-Message -Message "Creating VM from VHD: $vhd" $vmName = "runner_vm" if ($i -gt 0) { $vmName += "_$i" @@ -77,7 +81,7 @@ for ($i = 0; $i -lt $vhds.Count; $i++) { -VmName $vmName ` -AdminUserCredential $AdminUserCredential ` -StandardUserCredential $StandardUserCredential ` - -VhdPath $vhd.FullName ` + -VhdPath $vhd ` -VmStoragePath $outVMPath ` -VMMemory $VMMemory ` -UnattendPath $BaseUnattendPath ` @@ -94,4 +98,10 @@ for ($i = 0; $i -lt $vhds.Count; $i++) { } } +$vms = Get-VM +if ($vms.Count -eq 0) { + throw "No VMs were created. Check script execution logs for more details." + Exit 1 +} + Log-Message "Setup.ps1 complete!" \ No newline at end of file diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index 2219febd89..53985d15f5 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -369,58 +369,124 @@ function Configure-VM { } ########## Helpers for the host machine ########## +# <# +# .SYNOPSIS +# Helper function to prepare VHD files for VM creation. + +# .DESCRIPTION +# Unzips any files in given directory and returns a list of VHD and VHDX files in the input directory. + +# .PARAMETER BaseVhdDirPath +# The base directory containing the VHD files or zip files containing the VHD files. + +# .OUTPUTS +# System.IO.FileInfo[] +# This function returns a list of System.IO.FileInfo[] representing the VHD and VHDX files found in the input directory +# after any processing is complete. + +# .EXAMPLE +# $vhds = Prepare-VhdFiles -BaseVhdDirPath "C:\path\to\vhd\directory" +# #> +# function Prepare-VhdFiles { +# param( +# [Parameter(Mandatory=$True)][string]$BaseVhdDirPath +# ) +# # Unzip any VHDs +# Log-Message "Processing VHDs in $BaseVhdDirPath" +# $zipFiles = Get-ChildItem -Path $BaseVhdDirPath -Filter *.zip +# foreach ($zipFile in $zipFiles) { +# Log-Message "Extracting VHDs from $($zipFile.FullName)" +# $outDir = Join-Path -Path $BaseVhdDirPath -ChildPath $zipFile.BaseName +# if (-not (Test-Path -Path $outDir)) { +# $maxRetries = 3 +# $retryCount = 0 +# $success = $false + +# while (-not $success -and $retryCount -lt $maxRetries) { +# try { +# Expand-Archive -Path $zipFile.FullName -DestinationPath $outDir +# Log-Message "Successfully extracted $($zipFile.FullName) to $outDir" +# $success = $true +# } catch { +# $retryCount++ +# Log-Message "Failed to extract $($zipFile.FullName) on attempt $retryCount with error $_" +# Start-Sleep -Seconds 5 # Wait before retrying +# } +# } + +# if (-not $success) { +# throw "Failed to extract $($zipFile.FullName) after $maxRetries attempts" +# } +# } + +# # Check the extracted files +# Get-ChildItem -Path $outDir -Recurse + +# # Move the VHDs to the base directory +# $vhdFiles = @() +# $vhdFiles += Get-ChildItem -Path $outDir -Filter *.vhd -ErrorAction Ignore +# $vhdFiles += Get-ChildItem -Path $outDir -Filter *.vhdx -ErrorAction Ignore +# foreach ($vhdFile in $vhdFiles) { +# if (Test-Path -Path $vhdFile.FullName) { +# Move-Item -Path $vhdFile.FullName -Destination $BaseVhdDirPath +# } else { +# Log-Message "File not found: $($vhdFile.FullName)" +# throw "Failed to find extracted VHD file: $($vhdFile.FullName)" +# } +# } +# Log-Message "Successfully processed $($zipFile.FullName)" +# } + +# # Get the list of VHDs in the directory. +# $vhds = @() +# $vhds += Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhd -ErrorAction Ignore +# $vhds += Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhdx -ErrorAction Ignore +# if ($vhds.Count -eq 0) { +# throw "No VHDs found in $BaseVhdDirPath" +# } +# Log-Message "Successfully processed VHDs" + +# return $vhds +# } + <# .SYNOPSIS - Helper function to prepare VHD files for VM creation. + Extracts .zip files in the specified directory and returns paths to .vhd and .vhdx files. .DESCRIPTION - Unzips any files in given directory and returns a list of VHD and VHDX files in the input directory. - -.PARAMETER BaseVhdDirPath - The base directory containing the VHD files or zip files containing the VHD files. + This function takes an input directory as a parameter, looks inside the directory for any .zip files, extracts them, and returns a PowerShell string array of all full paths to .vhd and .vhdx files. It suppresses any output and throws errors if any exceptions are found. -.OUTPUTS - System.IO.FileInfo[] - This function returns a list of System.IO.FileInfo[] representing the VHD and VHDX files found in the input directory - after any processing is complete. +.PARAMETER InputDirectory + The directory to search for .zip files and extract them. .EXAMPLE - $vhds = Prepare-VhdFiles -BaseVhdDirPath "C:\path\to\vhd\directory" + $vhdFiles = Prepare-VhdFiles -InputDirectory "C:\MyDirectory" #> function Prepare-VhdFiles { - param( - [Parameter(Mandatory=$True)][string]$BaseVhdDirPath + param ( + [Parameter(Mandatory=$true)] + [string]$InputDirectory ) - # Unzip any VHDs - Log-Message "Processing VHDs in $BaseVhdDirPath" - $zipFiles = Get-ChildItem -Path $BaseVhdDirPath -Filter *.zip - foreach ($zipFile in $zipFiles) { - Log-Message "Extracting VHDs from $($zipFile.FullName)" - $outDir = Join-Path -Path $BaseVhdDirPath -ChildPath $zipFile.BaseName - if (-not (Test-Path -Path $outDir)) { - Expand-Archive -Path $zipFile.FullName -DestinationPath $outDir - - # Move the VHDs to the base directory - $vhdFiles = @() - $vhdFiles += Get-ChildItem -Path $outDir -Filter *.vhd -ErrorAction Ignore - $vhdFiles += Get-ChildItem -Path $outDir -Filter *.vhdx -ErrorAction Ignore - foreach ($vhdFile in $vhdFiles) { - Move-Item -Path $vhdFile.FullName -Destination $BaseVhdDirPath - } + + try { + $zipFiles = Get-ChildItem -Path $InputDirectory -Filter *.zip -Recurse + foreach ($zipFile in $zipFiles) { + Expand-Archive -Path $zipFile.FullName -DestinationPath $InputDirectory *> $null 2>&1 } - Log-Message "Successfully processed $($zipFile.FullName)" - } - # Read the input VHDs - $vhds = @() - $vhds += Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhd -ErrorAction Ignore - $vhds += Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhdx -ErrorAction Ignore - if ($vhds.Count -eq 0) { - throw "No VHDs found in $BaseVhdDirPath" - } - Log-Message "Successfully processed VHDs" + # Get all .vhd and .vhdx files + $vhdFiles = (Get-ChildItem -Path $InputDirectory -Recurse -Include *.vhd, *.vhdx) | Select-Object -ExpandProperty FullName - return $vhds + if ($vhdFiles.Count -eq 0) { + throw "No VHD files found in $InputDirectory" + } + + return [string[]]$vhdFiles + } + catch { + Get-ChildItem -Path $InputDirectory -Recurse + throw "Failed to prepare VHD files with error: $_" + } } <# @@ -540,3 +606,50 @@ function Get-AzureKeyVaultCredential throw "Failed to get Azure Key Vault Credential using KeyVaultName: $KeyVaultName SecretName: $SecretName Error: $_" } } + +<# +.SYNOPSIS + Creates and stores a new credential using the provided target and username and a randomly generated password. + +.DESCRIPTION + This function takes a username as a string, generates a random password, creates a stored credential using the CredentialManager module, and returns a PSCredential object. + It ensures that the CredentialManager module is installed and handles any errors that occur during the process. + +.PARAMETER Target + The target name for the stored credential. + +.PARAMETER Username + The username for the credential. + +.RETURNS + [System.Management.Automation.PSCredential] + The PSCredential object created from the provided username and generated password. + +.EXAMPLE + $credential = Generate-StoredCredential -Target "your_target" -Username "your_username" +#> +function Generate-StoredCredential { + param ( + [Parameter(Mandatory=$True)][string]$Target, + [Parameter(Mandatory=$True)][string]$Username + ) + + try { + # Import the CredentialManager module. Ensure any dependencies are installed. + Install-PackageProvider -Name NuGet -Force -ErrorAction Stop *> $null 2>&1 + Import-PackageProvider -Name NuGet -Force -ErrorAction Stop *> $null 2>&1 + if (-not (Get-Module -ListAvailable -Name CredentialManager)) { + Install-Module -Name CredentialManager -Force -ErrorAction Stop *> $null 2>&1 + } + Import-Module CredentialManager -ErrorAction Stop + + # Create the stored credential + $SecurePassword = ConvertTo-SecureString (Get-StrongPassword) -AsPlainText -Force + New-StoredCredential -Target $Target -UserName $Username -SecurePassword $SecurePassword -ErrorAction Stop *> $null 2>&1 + + # Create a new PSCredential object + New-Object System.Management.Automation.PSCredential ($Username, $SecurePassword) + } catch { + throw "Failed to create and store credential for username: $Username with error: $_" + } +} diff --git a/scripts/cleanup_ebpf_cicd_tests.ps1 b/scripts/cleanup_ebpf_cicd_tests.ps1 index f9ea065d05..6f0c6081c4 100644 --- a/scripts/cleanup_ebpf_cicd_tests.ps1 +++ b/scripts/cleanup_ebpf_cicd_tests.ps1 @@ -12,7 +12,8 @@ param ([parameter(Mandatory=$false)][string] $Target = "TEST_VM", Push-Location $WorkingDirectory Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue -$TestVMCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' +# $TestVMCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' +$TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop # Read the test execution json. $Config = Get-Content ("{0}\{1}" -f $PSScriptRoot, $TestExecutionJsonFileName) | ConvertFrom-Json diff --git a/scripts/execute_ebpf_cicd_tests.ps1 b/scripts/execute_ebpf_cicd_tests.ps1 index c645f44f48..7efcea7b96 100644 --- a/scripts/execute_ebpf_cicd_tests.ps1 +++ b/scripts/execute_ebpf_cicd_tests.ps1 @@ -18,8 +18,10 @@ Push-Location $WorkingDirectory Import-Module $WorkingDirectory\common.psm1 -Force -ArgumentList ($LogFileName) -ErrorAction Stop -$AdminTestVMCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' -$StandardUserTestVMCredential = Get-AzureKeyVaultCredential -SecretName 'VMStandardUser' +# $AdminTestVMCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' +# $StandardUserTestVMCredential = Get-AzureKeyVaultCredential -SecretName 'VMStandardUser' +$AdminTestVMCredential = Get-StoredCredential -Target $AdminTarget -ErrorAction Stop +$StandardUserTestVMCredential = Get-StoredCredential -Target $StandardUserTarget -ErrorAction Stop # Read the test execution json. $Config = Get-Content ("{0}\{1}" -f $PSScriptRoot, $TestExecutionJsonFileName) | ConvertFrom-Json diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index 795b4f05ce..65b1ee0359 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -15,9 +15,11 @@ param ([parameter(Mandatory=$false)][string] $Target = "TEST_VM", Push-Location $WorkingDirectory +$TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop + # Load other utility modules. Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue -$TestVMCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' +# $TestVMCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' Import-Module .\config_test_vm.psm1 -Force -ArgumentList ($TestVMCredential.UserName, $TestVMCredential.Password, $WorkingDirectory, $LogFileName) -WarningAction SilentlyContinue From 018a9fbbd14504a8211b8d6ab360012661f67755 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 17 Jan 2025 16:21:49 -0800 Subject: [PATCH 135/190] add import --- scripts/cleanup_ebpf_cicd_tests.ps1 | 1 + scripts/execute_ebpf_cicd_tests.ps1 | 2 +- scripts/setup_ebpf_cicd_tests.ps1 | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/cleanup_ebpf_cicd_tests.ps1 b/scripts/cleanup_ebpf_cicd_tests.ps1 index 6f0c6081c4..f9c2c4cc29 100644 --- a/scripts/cleanup_ebpf_cicd_tests.ps1 +++ b/scripts/cleanup_ebpf_cicd_tests.ps1 @@ -13,6 +13,7 @@ Push-Location $WorkingDirectory Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue # $TestVMCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' +Import-Module CredentialManager -ErrorAction Stop $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop # Read the test execution json. diff --git a/scripts/execute_ebpf_cicd_tests.ps1 b/scripts/execute_ebpf_cicd_tests.ps1 index 7efcea7b96..add852ccf1 100644 --- a/scripts/execute_ebpf_cicd_tests.ps1 +++ b/scripts/execute_ebpf_cicd_tests.ps1 @@ -17,7 +17,7 @@ param ([Parameter(Mandatory = $false)][string] $AdminTarget = "TEST_VM", Push-Location $WorkingDirectory Import-Module $WorkingDirectory\common.psm1 -Force -ArgumentList ($LogFileName) -ErrorAction Stop - +Import-Module CredentialManager -ErrorAction Stop # $AdminTestVMCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' # $StandardUserTestVMCredential = Get-AzureKeyVaultCredential -SecretName 'VMStandardUser' $AdminTestVMCredential = Get-StoredCredential -Target $AdminTarget -ErrorAction Stop diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index 65b1ee0359..3c82c51116 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -15,13 +15,14 @@ param ([parameter(Mandatory=$false)][string] $Target = "TEST_VM", Push-Location $WorkingDirectory -$TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop +Import-Module CredentialManager -ErrorAction Stop # Load other utility modules. Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue # $TestVMCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' Import-Module .\config_test_vm.psm1 -Force -ArgumentList ($TestVMCredential.UserName, $TestVMCredential.Password, $WorkingDirectory, $LogFileName) -WarningAction SilentlyContinue +$TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop # Read the test execution json. $Config = Get-Content ("{0}\{1}" -f $PSScriptRoot, $TestExecutionJsonFileName) | ConvertFrom-Json From d889d0b10ddf2035cf11930471eaebe28c7d01e3 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 21 Jan 2025 09:05:49 -0800 Subject: [PATCH 136/190] WIP --- scripts/execute_ebpf_cicd_tests.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/execute_ebpf_cicd_tests.ps1 b/scripts/execute_ebpf_cicd_tests.ps1 index add852ccf1..a8c93c03a7 100644 --- a/scripts/execute_ebpf_cicd_tests.ps1 +++ b/scripts/execute_ebpf_cicd_tests.ps1 @@ -18,8 +18,6 @@ Push-Location $WorkingDirectory Import-Module $WorkingDirectory\common.psm1 -Force -ArgumentList ($LogFileName) -ErrorAction Stop Import-Module CredentialManager -ErrorAction Stop -# $AdminTestVMCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' -# $StandardUserTestVMCredential = Get-AzureKeyVaultCredential -SecretName 'VMStandardUser' $AdminTestVMCredential = Get-StoredCredential -Target $AdminTarget -ErrorAction Stop $StandardUserTestVMCredential = Get-StoredCredential -Target $StandardUserTarget -ErrorAction Stop From ff8fd20131f3ecdb3b9dd75d17b84f7bbdee3320 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 21 Jan 2025 09:38:55 -0800 Subject: [PATCH 137/190] add retry logic and timeout for psexec --- scripts/config_test_vm.psm1 | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index 297bb53b92..8ad60dac8f 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -683,10 +683,28 @@ function Get-CoreNetTools { function Get-PSExec { $url = "https://download.sysinternals.com/files/PSTools.zip" $DownloadPath = "$pwd\psexec" + $maxRetries = 3 + $retryDelay = 10 # seconds + mkdir $DownloadPath Write-Log "Downloading PSExec from $url to $DownloadPath" $ProgressPreference = 'SilentlyContinue' - Invoke-WebRequest $url -OutFile "$DownloadPath\pstools.zip" + + for ($i = 1; $i -le $maxRetries; $i++) { + try { + Invoke-WebRequest $url -OutFile "$DownloadPath\pstools.zip" -TimeoutSec 300 + break + } catch { + Write-Log "Attempt $i failed: $_" + if ($i -eq $maxRetries) { + throw "Failed to download PSExec after $maxRetries attempts." + } else { + Write-Log "Retrying in $retryDelay seconds..." + Start-Sleep -Seconds $retryDelay + } + } + } + cd $DownloadPath Expand-Archive -Path "$DownloadPath\pstools.zip" -Force cd .. From cb163196d7dd384320307d94a9cf6cec5f7839be Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 21 Jan 2025 11:12:09 -0800 Subject: [PATCH 138/190] fixes --- scripts/config_test_vm.psm1 | 85 ++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 35 deletions(-) diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index 8ad60dac8f..57b15a63c6 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -551,20 +551,57 @@ function Get-ZipFileFromUrl { [Parameter(Mandatory=$True)][string] $DownloadFilePath, [Parameter(Mandatory=$True)][string] $OutputDir ) + $maxRetries = 5 + $retryDelay = 5 # seconds + $timeout = 300 # seconds - for ($i = 0; $i -lt 5; $i++) { + Write-Log "Downloading $Url to $DownloadFilePath" + + for ($i = 0; $i -lt $maxRetries; $i++) { try { - Write-Log "Downloading $Url to $DownloadFilePath" + Write-Log "Download attempt $($i + 1) started" $ProgressPreference = 'SilentlyContinue' - Invoke-WebRequest -Uri $Url -OutFile $DownloadFilePath - - Write-Log "Extracting $DownloadFilePath to $OutputDir" - Expand-Archive -Path $DownloadFilePath -DestinationPath $OutputDir -Force - break - } catch { - Write-Log "Iteration $i failed to download $Url. Removing $DownloadFilePath" -ForegroundColor Red - Remove-Item -Path $DownloadFilePath -Force -ErrorAction Ignore - Start-Sleep -Seconds 5 + + $job = Start-Job -ScriptBlock { + param ($Url, $DownloadFilePath) + Invoke-WebRequest -Uri $Url -OutFile $DownloadFilePath + } -ArgumentList $Url, $DownloadFilePath + + if (Wait-Job -Job $job -Timeout $timeout) { + Write-Log "Download completed" + Receive-Job -Job $job + + Write-Log "Extracting $DownloadFilePath to $OutputDir" + Expand-Archive -Path $DownloadFilePath -DestinationPath $OutputDir -Force + break + } else { + Stop-Job -Job $job + Remove-Job -Job $job + Write-Log "Download attempt $($i + 1) timed out after $timeout seconds." + if (Test-Path $DownloadFilePath) { + Remove-Item -Path $DownloadFilePath -Force + Write-Log "Removed partially downloaded file." + } + if ($i -eq ($maxRetries - 1)) { + throw "Failed to download $Url after $maxRetries attempts." + } else { + Write-Log "Retrying in $retryDelay seconds..." + Start-Sleep -Seconds $retryDelay + } + } + } + catch { + Write-Log "Iteration $($i + 1) failed to download $Url. Removing $DownloadFilePath" -ForegroundColor Red + if (Test-Path $DownloadFilePath) { + Remove-Item -Path $DownloadFilePath -Force -ErrorAction Ignore + Write-Log "Removed partially downloaded file." + } + if ($i -eq ($maxRetries - 1)) { + throw "Failed to download $Url after $maxRetries attempts." + } else { + Write-Log "Retrying in $retryDelay seconds..." + Start-Sleep -Seconds $retryDelay + } } } } @@ -683,32 +720,10 @@ function Get-CoreNetTools { function Get-PSExec { $url = "https://download.sysinternals.com/files/PSTools.zip" $DownloadPath = "$pwd\psexec" - $maxRetries = 3 - $retryDelay = 10 # seconds - - mkdir $DownloadPath - Write-Log "Downloading PSExec from $url to $DownloadPath" - $ProgressPreference = 'SilentlyContinue' - - for ($i = 1; $i -le $maxRetries; $i++) { - try { - Invoke-WebRequest $url -OutFile "$DownloadPath\pstools.zip" -TimeoutSec 300 - break - } catch { - Write-Log "Attempt $i failed: $_" - if ($i -eq $maxRetries) { - throw "Failed to download PSExec after $maxRetries attempts." - } else { - Write-Log "Retrying in $retryDelay seconds..." - Start-Sleep -Seconds $retryDelay - } - } - } - cd $DownloadPath - Expand-Archive -Path "$DownloadPath\pstools.zip" -Force + Get-ZipFileFromUrl -Url $url -DownloadFilePath "$pwd\pstools.zip" -OutputDir "$DownloadPath" cd .. - Move-Item -Path "$DownloadPath\PSTools\PsExec64.exe" -Destination $pwd -Force + Move-Item -Path "$DownloadPath\PsExec64.exe" -Destination $pwd -Force Remove-Item -Path $DownloadPath -Force -Recurse } From f97d9379f117e5d4b2a524703537227a9448ad4f Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 21 Jan 2025 11:52:34 -0800 Subject: [PATCH 139/190] fix --- scripts/config_test_vm.psm1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index 57b15a63c6..92b528c880 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -559,6 +559,11 @@ function Get-ZipFileFromUrl { for ($i = 0; $i -lt $maxRetries; $i++) { try { + $response = Invoke-WebRequest -Uri $Url -UseBasicParsing -Method Head -TimeoutSec $timeout + if ($response.StatusCode -ne 200) { + throw "Failed to reach $Url HTTP status code: $($response.StatusCode)" + } + Write-Log "Download attempt $($i + 1) started" $ProgressPreference = 'SilentlyContinue' @@ -589,8 +594,7 @@ function Get-ZipFileFromUrl { Start-Sleep -Seconds $retryDelay } } - } - catch { + } catch { Write-Log "Iteration $($i + 1) failed to download $Url. Removing $DownloadFilePath" -ForegroundColor Red if (Test-Path $DownloadFilePath) { Remove-Item -Path $DownloadFilePath -Force -ErrorAction Ignore From 568fd6689ff2b67911a0a2bfa4c6b3fb0d230467 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 21 Jan 2025 12:44:48 -0800 Subject: [PATCH 140/190] update zip expand logic --- scripts/config_test_vm.psm1 | 52 ++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index 92b528c880..9b9582f134 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -545,6 +545,50 @@ function Initialize-NetworkInterfacesOnVMs } } +function Expand-ZipFile { + param( + [Parameter(Mandatory=$True)][string] $DownloadFilePath, + [Parameter(Mandatory=$True)][string] $OutputDir, + [Parameter(Mandatory=$True)][int] $maxRetries, + [Parameter(Mandatory=$True)][int] $retryDelay, + [Parameter(Mandatory=$True)][int] $timeout + ) + + for ($i = 0; $i -lt $maxRetries; $i++) { + try { + Write-Log "Extract attempt $($i + 1) started" + $job = Start-Job -ScriptBlock { + param ($DownloadFilePath, $OutputDir) + Expand-Archive -Path $DownloadFilePath -DestinationPath $OutputDir -Force + } -ArgumentList $DownloadFilePath, $OutputDir + + if (Wait-Job -Job $job -Timeout $timeout) { + Write-Log "Extraction completed" + Receive-Job -Job $job + break + } else { + Stop-Job -Job $job + Remove-Job -Job $job + Write-Log "Extract attempt $($i + 1) timed out after $timeout seconds." + if ($i -eq ($maxRetries - 1)) { + throw "Failed to extract $DownloadFilePath after $maxRetries attempts." + } else { + Write-Log "Retrying in $retryDelay seconds..." + Start-Sleep -Seconds $retryDelay + } + } + } catch { + Write-Log "Iteration $($i + 1) failed to extract $DownloadFilePath" -ForegroundColor Red + if ($i -eq ($maxRetries - 1)) { + throw "Failed to extract $DownloadFilePath after $maxRetries attempts." + } else { + Write-Log "Retrying in $retryDelay seconds..." + Start-Sleep -Seconds $retryDelay + } + } + } +} + function Get-ZipFileFromUrl { param( [Parameter(Mandatory=$True)][string] $Url, @@ -568,16 +612,16 @@ function Get-ZipFileFromUrl { $ProgressPreference = 'SilentlyContinue' $job = Start-Job -ScriptBlock { - param ($Url, $DownloadFilePath) - Invoke-WebRequest -Uri $Url -OutFile $DownloadFilePath - } -ArgumentList $Url, $DownloadFilePath + param ($Url, $DownloadFilePath, $timeout) + Invoke-WebRequest -Uri $Url -OutFile $DownloadFilePath -TimeoutSec $timeout + } -ArgumentList $Url, $DownloadFilePath, $timeout if (Wait-Job -Job $job -Timeout $timeout) { Write-Log "Download completed" Receive-Job -Job $job Write-Log "Extracting $DownloadFilePath to $OutputDir" - Expand-Archive -Path $DownloadFilePath -DestinationPath $OutputDir -Force + Expand-ZipFile -DownloadFilePath $DownloadFilePath -OutputDir $OutputDir -maxRetries $maxRetries -retryDelay $retryDelay -timeout $timeout break } else { Stop-Job -Job $job From 52bae84b0d40044e56c5fafb9ab6477c6df38385 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 21 Jan 2025 13:19:13 -0800 Subject: [PATCH 141/190] WIP --- scripts/config_test_vm.psm1 | 4 +++- scripts/setup_ebpf_cicd_tests.ps1 | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index 9b9582f134..f3df454263 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -139,6 +139,8 @@ function Initialize-AllVMs { param ([Parameter(Mandatory=$True)] $VMList) + Write-Log "Initializing VMs..." + # Restore the VMs. Restore-AllVMs -VMList $VMList @@ -772,7 +774,7 @@ function Get-PSExec { Get-ZipFileFromUrl -Url $url -DownloadFilePath "$pwd\pstools.zip" -OutputDir "$DownloadPath" cd .. Move-Item -Path "$DownloadPath\PsExec64.exe" -Destination $pwd -Force - Remove-Item -Path $DownloadPath -Force -Recurse + Remove-Item -Path $DownloadPath -Force -Recurse -ErrorAction Ignore } # diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index 3c82c51116..ab2e4baab3 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -46,6 +46,7 @@ if ($TestMode -eq "CI/CD" -or $TestMode -eq "Regression") { Get-CoreNetTools Get-PSExec +Log-Message "Finished downloading the required tools. Installing tools on the test VM." $Job = Start-Job -ScriptBlock { param ([Parameter(Mandatory = $True)] [PSCredential] $TestVMCredential, From 2688238e5c4e75f7ac2ff437cd3484ed89e69a6e Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 21 Jan 2025 14:40:43 -0800 Subject: [PATCH 142/190] WIP --- scripts/setup_ebpf_cicd_tests.ps1 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index ab2e4baab3..bcfb5ea05d 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -46,7 +46,7 @@ if ($TestMode -eq "CI/CD" -or $TestMode -eq "Regression") { Get-CoreNetTools Get-PSExec -Log-Message "Finished downloading the required tools. Installing tools on the test VM." +Write-Log "Finished downloading the required tools. Installing tools on the test VM." $Job = Start-Job -ScriptBlock { param ([Parameter(Mandatory = $True)] [PSCredential] $TestVMCredential, @@ -67,23 +67,28 @@ $Job = Start-Job -ScriptBlock { $VMList = $Config.VMMap.$SelfHostedRunnerName # Get all VMs to ready state. + Write-Log "Initializing all VMs." Initialize-AllVMs -VMList $VMList -ErrorAction Stop # Export build artifacts to the test VMs. + Write-Log "Exporting build artifacts to VM" Export-BuildArtifactsToVMs -VMList $VMList -ErrorAction Stop # Configure network adapters on VMs. + Write-Log "Configuring network interfaces on VMs." Initialize-NetworkInterfacesOnVMs $VMList -ErrorAction Stop # Install eBPF Components on the test VM. foreach($VM in $VMList) { $VMName = $VM.Name + Write-Log "Installing eBPF components on VM: $VMName" Install-eBPFComponentsOnVM -VMName $VMname -TestMode $TestMode -KmTracing $KmTracing -KmTraceType $KmTraceType -ErrorAction Stop } # Log OS build information on the test VM. foreach($VM in $VMList) { $VMName = $VM.Name + Write-Log "Logging OS build information on VM: $VMName" Log-OSBuildInformationOnVM -VMName $VMName -ErrorAction Stop } From 436f47e8b6cc9e04fb342006f92ca3f04a9c8ba3 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 21 Jan 2025 15:18:38 -0800 Subject: [PATCH 143/190] debug logs --- scripts/setup_ebpf_cicd_tests.ps1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index bcfb5ea05d..81ddd13a19 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -11,7 +11,7 @@ param ([parameter(Mandatory=$false)][string] $Target = "TEST_VM", [parameter(Mandatory=$false)][string] $RegressionArtifactsConfiguration = "", [parameter(Mandatory=$false)][string] $TestExecutionJsonFileName = "test_execution.json", [parameter(Mandatory=$false)][string] $SelfHostedRunnerName = "runner_host", - [Parameter(Mandatory = $false)][int] $TestJobTimeout = (30*60)) + [Parameter(Mandatory = $false)][int] $TestJobTimeout = (5*60)) Push-Location $WorkingDirectory @@ -23,6 +23,8 @@ Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction S Import-Module .\config_test_vm.psm1 -Force -ArgumentList ($TestVMCredential.UserName, $TestVMCredential.Password, $WorkingDirectory, $LogFileName) -WarningAction SilentlyContinue $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop +$debugCred = $TestVMCredential.GetNetworkCredential() | Out-String +Write-Log "Cred: $debugCred" # Read the test execution json. $Config = Get-Content ("{0}\{1}" -f $PSScriptRoot, $TestExecutionJsonFileName) | ConvertFrom-Json @@ -58,8 +60,10 @@ $Job = Start-Job -ScriptBlock { [parameter(Mandatory = $true)] [bool] $KmTracing, [parameter(Mandatory = $true)] [string] $KmTraceType ) + Write-Log "Starting the setup job." Push-Location $WorkingDirectory + Write-Log "Importing modules." # Load other utility modules. Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue Import-Module .\config_test_vm.psm1 -Force -ArgumentList ($TestVMCredential.UserName, $TestVMCredential.Password, $WorkingDirectory, $LogFileName) -WarningAction SilentlyContinue From fe5781aca90e4129f8c3d53447f8677d763df31b Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 21 Jan 2025 16:09:17 -0800 Subject: [PATCH 144/190] WIP --- 1es/prepare_vm_helpers.psm1 | 9 +++++++-- scripts/common.psm1 | 2 ++ scripts/setup_ebpf_cicd_tests.ps1 | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index 53985d15f5..cd6a2fd359 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -647,8 +647,13 @@ function Generate-StoredCredential { $SecurePassword = ConvertTo-SecureString (Get-StrongPassword) -AsPlainText -Force New-StoredCredential -Target $Target -UserName $Username -SecurePassword $SecurePassword -ErrorAction Stop *> $null 2>&1 - # Create a new PSCredential object - New-Object System.Management.Automation.PSCredential ($Username, $SecurePassword) + # Validate that the credential was created + $cred = Get-StoredCredential -Target $Target -ErrorAction Stop + if ($cred -eq $null) { + throw "Failed to create and store credential for target: $Target and username: $Username" + } + + return $cred } catch { throw "Failed to create and store credential for username: $Username with error: $_" } diff --git a/scripts/common.psm1 b/scripts/common.psm1 index 612fc182c8..c76c195fe1 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -3,6 +3,8 @@ param ([parameter(Mandatory=$True)] [string] $LogFileName) +Import-Module CredentialManager -ErrorAction Stop + # # Common helper functions. # diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index 81ddd13a19..d07193455d 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -23,6 +23,9 @@ Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction S Import-Module .\config_test_vm.psm1 -Force -ArgumentList ($TestVMCredential.UserName, $TestVMCredential.Password, $WorkingDirectory, $LogFileName) -WarningAction SilentlyContinue $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop +if ($null -eq $TestVMCredential) { + ThrowWithErrorMessage "Failed to retrieve the test VM credential." +} $debugCred = $TestVMCredential.GetNetworkCredential() | Out-String Write-Log "Cred: $debugCred" From 5bfe30fbadc85c5303a76c22ebc436335b17dcc8 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 21 Jan 2025 16:40:27 -0800 Subject: [PATCH 145/190] WIP --- scripts/setup_ebpf_cicd_tests.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index d07193455d..92c98e7de5 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -22,6 +22,7 @@ Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction S # $TestVMCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' Import-Module .\config_test_vm.psm1 -Force -ArgumentList ($TestVMCredential.UserName, $TestVMCredential.Password, $WorkingDirectory, $LogFileName) -WarningAction SilentlyContinue +Write-Log "Fetching the test VM credential using target: $Target" $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop if ($null -eq $TestVMCredential) { ThrowWithErrorMessage "Failed to retrieve the test VM credential." From a066489790514f23661593559500c662497ef687 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 21 Jan 2025 18:08:49 -0800 Subject: [PATCH 146/190] use persist for storedcredential --- 1es/prepare_vm_helpers.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index cd6a2fd359..5fea26ccd5 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -645,7 +645,7 @@ function Generate-StoredCredential { # Create the stored credential $SecurePassword = ConvertTo-SecureString (Get-StrongPassword) -AsPlainText -Force - New-StoredCredential -Target $Target -UserName $Username -SecurePassword $SecurePassword -ErrorAction Stop *> $null 2>&1 + New-StoredCredential -Target $Target -UserName $Username -SecurePassword $SecurePassword -Persist LocalMachine -ErrorAction Stop *> $null 2>&1 # Validate that the credential was created $cred = Get-StoredCredential -Target $Target -ErrorAction Stop From 05b88ab59c5336a0bb0bba65ea40813501723533 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 22 Jan 2025 09:05:51 -0800 Subject: [PATCH 147/190] disable other parts of pipeline for development --- .github/workflows/cicd.yml | 1168 ++++++++++++++++++------------------ 1 file changed, 584 insertions(+), 584 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 37f1bd04e2..e097eb9321 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -57,25 +57,25 @@ jobs: build_options: /p:ReleaseJIT='True' configurations: '["Debug", "FuzzerDebug", "Release"]' - onebranch: - strategy: - matrix: - Architecture: ['x64', 'ARM64'] - # Always run this job. - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-build.yml - with: - ref: ${{ github.ref }} - repository: ${{ github.repository }} - build_artifact: Build-${{ matrix.Architecture }}-onebranch - generate_release_package: true - build_msi: true - build_nuget: true - configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' - build_options: /p:BuildOneBranch='True' /t:tools\onebranch /t:installer\ebpf-for-windows - solution_file: "ebpf-for-windows.sln" - architecture: ${{ matrix.Architecture }} - download_demo_repository: false + # onebranch: + # strategy: + # matrix: + # Architecture: ['x64', 'ARM64'] + # # Always run this job. + # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-build.yml + # with: + # ref: ${{ github.ref }} + # repository: ${{ github.repository }} + # build_artifact: Build-${{ matrix.Architecture }}-onebranch + # generate_release_package: true + # build_msi: true + # build_nuget: true + # configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' + # build_options: /p:BuildOneBranch='True' /t:tools\onebranch /t:installer\ebpf-for-windows + # solution_file: "ebpf-for-windows.sln" + # architecture: ${{ matrix.Architecture }} + # download_demo_repository: false # Perform the native-only build. regular_native-only: @@ -95,147 +95,147 @@ jobs: architecture: ${{ matrix.Architecture }} configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' - # Run the unit tests in GitHub. - unit_tests_appverif: - # Always run this job. - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: unit_tests - pre_test: appverif -enable Exceptions Handles Heaps Leak Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe - # Exclude [processes] test that CodeCoverage can't work with. - test_command: .\unit_tests.exe -d yes ~[processes] - build_artifact: Build-x64 - environment: '["windows-2022"]' - code_coverage: true - gather_dumps: true - capture_etw: true - leak_detection: true - - # Run the unit tests in GitHub. - unit_tests: - # Always run this job. - needs: regular - if: github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' - uses: ./.github/workflows/reusable-test.yml - with: - name: unit_tests - pre_test: appverif -enable Exceptions Handles Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe - # Exclude [processes] test that CodeCoverage can't work with. - test_command: .\unit_tests.exe -d yes ~[processes] - build_artifact: Build-x64 - environment: '["windows-2022"]' - code_coverage: true - gather_dumps: true - capture_etw: true - leak_detection: true - - # Run the unit tests for NativeOnly build in GitHub. - unit_tests_native_only: - # Always run this job. - needs: regular_native-only - uses: ./.github/workflows/reusable-test.yml - with: - name: unit_tests - pre_test: appverif -enable Exceptions Handles Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe - # Exclude [processes] test that CodeCoverage can't work with. - test_command: .\unit_tests.exe -d yes ~[processes] - build_artifact: Build-x64-native-only - environment: '["windows-2022"]' - code_coverage: true - gather_dumps: true - capture_etw: true - leak_detection: true - configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' - - # Run the netebpfext unit tests in GitHub. - netebpf_ext_unit_tests: - # Always run this job. - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: netebpf_ext_unit_tests - pre_test: appverif -enable Exceptions Handles Heaps Leak Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe - test_command: .\netebpfext_unit.exe -d yes - build_artifact: Build-x64 - environment: '["windows-2022"]' - code_coverage: true - gather_dumps: true - capture_etw: true - leak_detection: true - - # Run the bpf2c tests in GitHub. - bpf2c: - # Always run this job. - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - test_command: .\bpf2c_tests.exe -d yes - name: bpf2c - build_artifact: Build-x64 - environment: '["windows-2022"]' - vs_dev: true - code_coverage: true - gather_dumps: true - capture_etw: true - - # Run the bpf2c conformance tests in GitHub. - bpf2c_conformance: - # Always run this job. - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - pre_test: Invoke-WebRequest https://github.com/Alan-Jowett/bpf_conformance/releases/download/v0.0.6/bpf_conformance_runner.exe -OutFile bpf_conformance_runner.exe - test_command: .\bpf_conformance_runner.exe --test_file_directory %SOURCE_ROOT%\external\ebpf-verifier\external\bpf_conformance\tests --cpu_version v4 --plugin_path bpf2c_plugin.exe --debug true --plugin_options "--include %SOURCE_ROOT%\include" - name: bpf2c_conformance - build_artifact: Build-x64 - environment: '["windows-2022"]' - vs_dev: true - code_coverage: true - gather_dumps: true - capture_etw: true - - # Run the driver tests on self-hosted runners. - driver_ws2019: - # Always run this job. - # Only run this on repos that have self-host runners. - needs: regular - if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') - uses: ./.github/workflows/reusable-test.yml - with: - pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" - test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" - post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - name: driver_ws2019 - build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2019"]' - # driver test copies dumps to testlog folder. - gather_dumps: false - # driver tests manually gather code coverage - code_coverage: false - - # Run the driver tests on self-hosted runners. - driver_ws2022: - # Always run this job. - # Only run this on repos that have self-host runners. - needs: regular - if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') - uses: ./.github/workflows/reusable-test.yml - with: - pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" - test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" - post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - name: driver_ws2022 - build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2022"]' - # driver test copies dumps to testlog folder. - gather_dumps: false - # driver tests manually gather code coverage - code_coverage: false + # # Run the unit tests in GitHub. + # unit_tests_appverif: + # # Always run this job. + # needs: regular + # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: unit_tests + # pre_test: appverif -enable Exceptions Handles Heaps Leak Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe + # # Exclude [processes] test that CodeCoverage can't work with. + # test_command: .\unit_tests.exe -d yes ~[processes] + # build_artifact: Build-x64 + # environment: '["windows-2022"]' + # code_coverage: true + # gather_dumps: true + # capture_etw: true + # leak_detection: true + + # # Run the unit tests in GitHub. + # unit_tests: + # # Always run this job. + # needs: regular + # if: github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: unit_tests + # pre_test: appverif -enable Exceptions Handles Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe + # # Exclude [processes] test that CodeCoverage can't work with. + # test_command: .\unit_tests.exe -d yes ~[processes] + # build_artifact: Build-x64 + # environment: '["windows-2022"]' + # code_coverage: true + # gather_dumps: true + # capture_etw: true + # leak_detection: true + + # # Run the unit tests for NativeOnly build in GitHub. + # unit_tests_native_only: + # # Always run this job. + # needs: regular_native-only + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: unit_tests + # pre_test: appverif -enable Exceptions Handles Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe + # # Exclude [processes] test that CodeCoverage can't work with. + # test_command: .\unit_tests.exe -d yes ~[processes] + # build_artifact: Build-x64-native-only + # environment: '["windows-2022"]' + # code_coverage: true + # gather_dumps: true + # capture_etw: true + # leak_detection: true + # configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' + + # # Run the netebpfext unit tests in GitHub. + # netebpf_ext_unit_tests: + # # Always run this job. + # needs: regular + # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: netebpf_ext_unit_tests + # pre_test: appverif -enable Exceptions Handles Heaps Leak Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe + # test_command: .\netebpfext_unit.exe -d yes + # build_artifact: Build-x64 + # environment: '["windows-2022"]' + # code_coverage: true + # gather_dumps: true + # capture_etw: true + # leak_detection: true + + # # Run the bpf2c tests in GitHub. + # bpf2c: + # # Always run this job. + # needs: regular + # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-test.yml + # with: + # test_command: .\bpf2c_tests.exe -d yes + # name: bpf2c + # build_artifact: Build-x64 + # environment: '["windows-2022"]' + # vs_dev: true + # code_coverage: true + # gather_dumps: true + # capture_etw: true + + # # Run the bpf2c conformance tests in GitHub. + # bpf2c_conformance: + # # Always run this job. + # needs: regular + # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-test.yml + # with: + # pre_test: Invoke-WebRequest https://github.com/Alan-Jowett/bpf_conformance/releases/download/v0.0.6/bpf_conformance_runner.exe -OutFile bpf_conformance_runner.exe + # test_command: .\bpf_conformance_runner.exe --test_file_directory %SOURCE_ROOT%\external\ebpf-verifier\external\bpf_conformance\tests --cpu_version v4 --plugin_path bpf2c_plugin.exe --debug true --plugin_options "--include %SOURCE_ROOT%\include" + # name: bpf2c_conformance + # build_artifact: Build-x64 + # environment: '["windows-2022"]' + # vs_dev: true + # code_coverage: true + # gather_dumps: true + # capture_etw: true + + # # Run the driver tests on self-hosted runners. + # driver_ws2019: + # # Always run this job. + # # Only run this on repos that have self-host runners. + # needs: regular + # if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') + # uses: ./.github/workflows/reusable-test.yml + # with: + # pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" + # test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" + # post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + # name: driver_ws2019 + # build_artifact: Build-x64 + # environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2019"]' + # # driver test copies dumps to testlog folder. + # gather_dumps: false + # # driver tests manually gather code coverage + # code_coverage: false + + # # Run the driver tests on self-hosted runners. + # driver_ws2022: + # # Always run this job. + # # Only run this on repos that have self-host runners. + # needs: regular + # if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') + # uses: ./.github/workflows/reusable-test.yml + # with: + # pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" + # test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" + # post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + # name: driver_ws2022 + # build_artifact: Build-x64 + # environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2022"]' + # # driver test copies dumps to testlog folder. + # gather_dumps: false + # # driver tests manually gather code coverage + # code_coverage: false # Run the driver tests on self-hosted runners. driver_ws2025: @@ -256,44 +256,44 @@ jobs: # driver tests manually gather code coverage code_coverage: false - # Run the native-only driver tests on self-hosted runners. - driver_native_only_ws2019: - # Always run this job. - # Only run this on repos that have self-host runners. - needs: regular_native-only - if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') - uses: ./.github/workflows/reusable-test.yml - with: - pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" - test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" - post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - name: driver_native_only_ws2019 - build_artifact: Build-x64-native-only - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2019"]' - # driver test copies dumps to testlog folder. - gather_dumps: false - # driver tests manually gather code coverage - code_coverage: false - configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' - - driver_native_only_ws2022: - # Always run this job. - # Only run this on repos that have self-host runners. - needs: regular_native-only - if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') - uses: ./.github/workflows/reusable-test.yml - with: - pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" - test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" - post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - name: driver_native_only_ws2022 - build_artifact: Build-x64-native-only - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2022"]' - # driver test copies dumps to testlog folder. - gather_dumps: false - # driver tests manually gather code coverage - code_coverage: false - configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' + # # Run the native-only driver tests on self-hosted runners. + # driver_native_only_ws2019: + # # Always run this job. + # # Only run this on repos that have self-host runners. + # needs: regular_native-only + # if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') + # uses: ./.github/workflows/reusable-test.yml + # with: + # pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" + # test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" + # post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + # name: driver_native_only_ws2019 + # build_artifact: Build-x64-native-only + # environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2019"]' + # # driver test copies dumps to testlog folder. + # gather_dumps: false + # # driver tests manually gather code coverage + # code_coverage: false + # configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' + + # driver_native_only_ws2022: + # # Always run this job. + # # Only run this on repos that have self-host runners. + # needs: regular_native-only + # if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') + # uses: ./.github/workflows/reusable-test.yml + # with: + # pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" + # test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" + # post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + # name: driver_native_only_ws2022 + # build_artifact: Build-x64-native-only + # environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2022"]' + # # driver test copies dumps to testlog folder. + # gather_dumps: false + # # driver tests manually gather code coverage + # code_coverage: false + # configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' driver_native_only_ws2025: # Always run this job. @@ -314,389 +314,389 @@ jobs: code_coverage: false configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' - # Run the regression driver tests on self-hosted runners (only for 2022). - regression_driver_ws2022: - # Always run this job. - # Only run this on repos that have self-host runners. - needs: regular - if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') - uses: ./.github/workflows/reusable-test.yml - with: - pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" -TestMode "Regression" -RegressionArtifactsVersion "0.17.0" - test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Regression" - post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - name: regression_driver_ws2022 - build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2022"]' - # driver test copies dumps to testlog folder. - gather_dumps: false - # driver tests manually gather code coverage - code_coverage: false - - ossar: - # Always run this job. - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/ossar-scan.yml - with: - build_artifact: Build-x64 - - # Additional jobs to run on pull and schedule only (skip push). - # --------------------------------------------------------------------------- - # Build with C++ static analyzer. - analyze: - # Only run on schedule and pull request. - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-build.yml - with: - ref: ${{ github.ref }} - repository: ${{ github.repository }} - build_artifact: Build-x64-Analyze - # Analysis on external projects is conditional, as on small CI/CD VMs the compiler can run OOM - build_options: /p:Analysis='True' /p:AnalysisOnExternal='False' - - # Build with C++ address sanitizer. - sanitize: - # Only run on schedule and pull request. - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-build.yml - with: - ref: ${{ github.ref }} - repository: ${{ github.repository }} - build_artifact: Build-x64-Sanitize - build_options: /p:AddressSanitizer='True' - - bpf2c_fuzzer: - needs: regular - if: github.event_name == 'pull_request' || github.event_name == 'merge_group' - uses: ./.github/workflows/reusable-test.yml - with: - name: bpf2c_fuzzer - test_command: .\bpf2c_fuzzer.exe bpf2c_fuzzer_corpus -use_value_profile=1 -max_total_time=300 -artifact_prefix=Artifacts\ - build_artifact: Build-x64 - environment: '["windows-2022"]' - code_coverage: false - gather_dumps: true - configurations: '["FuzzerDebug"]' - - bpf2c_fuzzer_scheduled: - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: bpf2c_fuzzer - test_command: .\bpf2c_fuzzer.exe bpf2c_fuzzer_corpus -use_value_profile=1 -max_total_time=900 -artifact_prefix=Artifacts\ - build_artifact: Build-x64 - environment: '["windows-2022"]' - code_coverage: false - gather_dumps: true - configurations: '["FuzzerDebug"]' - - execution_context_fuzzer: - needs: regular - # Always run this job. - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: execution_context_fuzzer - test_command: .\execution_context_fuzzer.exe execution_context_fuzzer_corpus -use_value_profile=1 -runs=3000 -artifact_prefix=Artifacts\ - build_artifact: Build-x64 - environment: '["windows-2022"]' - code_coverage: false - gather_dumps: true - configurations: '["FuzzerDebug"]' - - # Run the verifier fuzzer. - verifier_fuzzer: - needs: regular - # Always run this job. - if: github.event_name == 'pull_request' || github.event_name == 'merge_group' - uses: ./.github/workflows/reusable-test.yml - with: - name: verifier_fuzzer - test_command: .\verifier_fuzzer.exe verifier_corpus -use_value_profile=1 -max_total_time=300 -artifact_prefix=Artifacts\ - build_artifact: Build-x64 - environment: '["windows-2022"]' - code_coverage: false - gather_dumps: true - configurations: '["FuzzerDebug"]' - - verifier_fuzzer_scheduled: - needs: regular - # Always run this job. - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: verifier_fuzzer - test_command: .\verifier_fuzzer.exe verifier_corpus -use_value_profile=1 -max_total_time=900 -artifact_prefix=Artifacts\ - build_artifact: Build-x64 - environment: '["windows-2022"]' - code_coverage: false - gather_dumps: true - configurations: '["FuzzerDebug"]' - - core_helper_fuzzer: - needs: regular - # Always run this job. - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: core_helper_fuzzer - test_command: .\core_helper_fuzzer core_helper_corpus -max_len=139 -runs=1000 -use_value_profile=1 -artifact_prefix=Artifacts\ - build_artifact: Build-x64 - environment: '["windows-2022"]' - code_coverage: false - gather_dumps: true - configurations: '["FuzzerDebug"]' - - netebpfext_fuzzer: - needs: regular - # Always run this job. - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: netebpfext_fuzzer - test_command: .\netebpfext_fuzzer netebpfext_corpus -max_len=12 -runs=1000 -use_value_profile=1 -artifact_prefix=Artifacts\ - build_artifact: Build-x64 - environment: '["windows-2022"]' - code_coverage: false - gather_dumps: true - configurations: '["FuzzerDebug"]' - - # Run Cilium regression tests in GitHub. - cilium_tests: - needs: regular - # Only run on schedule and pull request. - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: cilium_tests - test_command: .\cilium_tests.exe -d yes - build_artifact: Build-x64 - environment: '["windows-2022"]' - code_coverage: false - gather_dumps: true - - # Run the quick stress tests in GitHub. - stress: - needs: regular - # Only run on schedule and pull request. - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: stress - # Until there is a dedicated stress test, re-use the perf test. - test_command: .\ebpf_performance.exe -d yes - build_artifact: Build-x64 - environment: '["windows-2022"]' - # No code coverage on stress. - code_coverage: false - gather_dumps: true - - # Run the unit tests in GitHub with address sanitizer. - sanitize_unit_tests: - needs: sanitize - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: unit_tests - # Exclude [processes] test that ASAN can't work with. - test_command: .\unit_tests.exe -d yes ~[processes] - build_artifact: Build-x64-Sanitize - environment: '["windows-2022"]' - code_coverage: false - gather_dumps: true - capture_etw: true - - # Run the fault injection simulator in GitHub. - fault_injection: - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: fault_injection - test_command: .\unit_tests.exe - build_artifact: Build-x64 - environment: '["windows-2022"]' - code_coverage: true - gather_dumps: true - fault_injection: true - leak_detection: true - - # Run the low memory simulator for netebpfext_unit tests. - fault_injection_netebpfext_unit: - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: netebpfext_fault_injection - test_command: .\netebpfext_unit.exe - build_artifact: Build-x64 - environment: '["windows-2022"]' - code_coverage: true - gather_dumps: true - fault_injection: true - leak_detection: true - - # Run a fast multi-threaded stress test pass against the usersim user-mode 'mock' framework. - # Added as a 'per-PR' test to catch usersim regressions and/or run-time usage issues. - quick_user_mode_multi_threaded_stress_test: - needs: regular - if: github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' - uses: ./.github/workflows/reusable-test.yml - with: - name: quick_user_mode_multi_threaded_stress - test_command: .\ebpf_stress_tests_um -tt=8 -td=2 - build_artifact: Build-x64 - environment: '["windows-2022"]' - code_coverage: false - leak_detection: false - gather_dumps: true - capture_etw: true - - # Additional jobs to run on a schedule only (skip push and pull request). - # --------------------------------------------------------------------------- - codeql: - # Only run during daily scheduled run - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-build.yml - with: - ref: ${{ github.ref }} - repository: ${{ github.repository }} - build_artifact: Build-x64-CodeQl - build_codeql: true - - - # Run the complete fault injection simulator in GitHub. - # Runs on a schedule as this takes a long time to run. - fault_injection_full: - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: fault_injection_full - test_command: .\unit_tests.exe - build_artifact: Build-x64 - environment: '["windows-2022"]' - code_coverage: false - gather_dumps: true - fault_injection: true - leak_detection: true - - # Run the complete fault injection simulator for netebpfext in GitHub. - # Runs on a schedule as this takes a long time to run. - netebpfext_fault_injection_full: - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: netebpfext_fault_injection_full - test_command: .\netebpfext_unit.exe - build_artifact: Build-x64 - environment: '["windows-2022"]' - code_coverage: false - gather_dumps: true - fault_injection: true - - # Run multi-threaded stress tests against the user mode 'mock' framework. - user_mode_multi_threaded_stress_test: - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: user_mode_multi_threaded_stress - test_command: .\ebpf_stress_tests_um -tt=8 -td=10 - build_artifact: Build-x64 - environment: '["windows-2022"]' - code_coverage: false - leak_detection: false - gather_dumps: true - capture_etw: true - - # Run multi-threaded stress tests with 'restart extension' disabled (default behavior) - # against the kernel mode eBPF sub-system. - km_mt_stress_tests: - needs: regular - # TODO - revert this back - # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: km_mt_stress_tests - pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "memory" - test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Stress" - post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2019"]' - code_coverage: false - # For this test, we only want kernel mode dumps and not user mode dumps. - gather_dumps: false - - # Run multi-threaded stress tests with 'restart extension' enabled - # against the kernel mode eBPF sub-system. - km_mt_stress_tests_restart_extension: - needs: regular - # TODO - revert this back - # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: km_mt_stress_tests_restart_extension - pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "memory" - test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Stress" -Options @("RestartExtension") - post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2019"]' - code_coverage: false - # For this test, we only want kernel mode dumps and not user mode dumps. - gather_dumps: false - - # TODO - figure this out... - # Not sure what perf is - probably selfhosted runner, but do we need to support this now? - performance: - needs: regular - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/reusable-test.yml - with: - name: km_performance - pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" - test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Performance" - post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - build_artifact: Build-x64 - environment: ebpf_cicd_perf_ws2022 - configurations: '["Release"]' - - netperf: - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/netperf.yml - with: - sha: ${{ github.sha }} - ref: ${{ github.ref }} - pull_request: ${{ github.event.pull_request.number }} - secrets: - NET_PERF_TRIGGER: ${{ secrets.NET_PERF_TRIGGER }} - - upload_perf_results: - needs: performance - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/upload-perf-results.yml - with: - name: upload_perf_results - result_artifact: km_performance-x64-Release - secrets: - AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} - AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} - AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - - upload_netperf_results_lab_2022: - needs: netperf - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - uses: ./.github/workflows/upload-perf-results.yml - with: - name: upload_netperf_results_lab_2022 - result_artifact: netperf_lab_2022_x64 - platform: Lab Windows 2022 - secrets: - AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} - AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} - AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + # # Run the regression driver tests on self-hosted runners (only for 2022). + # regression_driver_ws2022: + # # Always run this job. + # # Only run this on repos that have self-host runners. + # needs: regular + # if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') + # uses: ./.github/workflows/reusable-test.yml + # with: + # pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" -TestMode "Regression" -RegressionArtifactsVersion "0.17.0" + # test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Regression" + # post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + # name: regression_driver_ws2022 + # build_artifact: Build-x64 + # environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2022"]' + # # driver test copies dumps to testlog folder. + # gather_dumps: false + # # driver tests manually gather code coverage + # code_coverage: false + + # ossar: + # # Always run this job. + # needs: regular + # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/ossar-scan.yml + # with: + # build_artifact: Build-x64 + + # # Additional jobs to run on pull and schedule only (skip push). + # # --------------------------------------------------------------------------- + # # Build with C++ static analyzer. + # analyze: + # # Only run on schedule and pull request. + # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-build.yml + # with: + # ref: ${{ github.ref }} + # repository: ${{ github.repository }} + # build_artifact: Build-x64-Analyze + # # Analysis on external projects is conditional, as on small CI/CD VMs the compiler can run OOM + # build_options: /p:Analysis='True' /p:AnalysisOnExternal='False' + + # # Build with C++ address sanitizer. + # sanitize: + # # Only run on schedule and pull request. + # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-build.yml + # with: + # ref: ${{ github.ref }} + # repository: ${{ github.repository }} + # build_artifact: Build-x64-Sanitize + # build_options: /p:AddressSanitizer='True' + + # bpf2c_fuzzer: + # needs: regular + # if: github.event_name == 'pull_request' || github.event_name == 'merge_group' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: bpf2c_fuzzer + # test_command: .\bpf2c_fuzzer.exe bpf2c_fuzzer_corpus -use_value_profile=1 -max_total_time=300 -artifact_prefix=Artifacts\ + # build_artifact: Build-x64 + # environment: '["windows-2022"]' + # code_coverage: false + # gather_dumps: true + # configurations: '["FuzzerDebug"]' + + # bpf2c_fuzzer_scheduled: + # needs: regular + # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: bpf2c_fuzzer + # test_command: .\bpf2c_fuzzer.exe bpf2c_fuzzer_corpus -use_value_profile=1 -max_total_time=900 -artifact_prefix=Artifacts\ + # build_artifact: Build-x64 + # environment: '["windows-2022"]' + # code_coverage: false + # gather_dumps: true + # configurations: '["FuzzerDebug"]' + + # execution_context_fuzzer: + # needs: regular + # # Always run this job. + # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: execution_context_fuzzer + # test_command: .\execution_context_fuzzer.exe execution_context_fuzzer_corpus -use_value_profile=1 -runs=3000 -artifact_prefix=Artifacts\ + # build_artifact: Build-x64 + # environment: '["windows-2022"]' + # code_coverage: false + # gather_dumps: true + # configurations: '["FuzzerDebug"]' + + # # Run the verifier fuzzer. + # verifier_fuzzer: + # needs: regular + # # Always run this job. + # if: github.event_name == 'pull_request' || github.event_name == 'merge_group' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: verifier_fuzzer + # test_command: .\verifier_fuzzer.exe verifier_corpus -use_value_profile=1 -max_total_time=300 -artifact_prefix=Artifacts\ + # build_artifact: Build-x64 + # environment: '["windows-2022"]' + # code_coverage: false + # gather_dumps: true + # configurations: '["FuzzerDebug"]' + + # verifier_fuzzer_scheduled: + # needs: regular + # # Always run this job. + # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: verifier_fuzzer + # test_command: .\verifier_fuzzer.exe verifier_corpus -use_value_profile=1 -max_total_time=900 -artifact_prefix=Artifacts\ + # build_artifact: Build-x64 + # environment: '["windows-2022"]' + # code_coverage: false + # gather_dumps: true + # configurations: '["FuzzerDebug"]' + + # core_helper_fuzzer: + # needs: regular + # # Always run this job. + # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: core_helper_fuzzer + # test_command: .\core_helper_fuzzer core_helper_corpus -max_len=139 -runs=1000 -use_value_profile=1 -artifact_prefix=Artifacts\ + # build_artifact: Build-x64 + # environment: '["windows-2022"]' + # code_coverage: false + # gather_dumps: true + # configurations: '["FuzzerDebug"]' + + # netebpfext_fuzzer: + # needs: regular + # # Always run this job. + # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: netebpfext_fuzzer + # test_command: .\netebpfext_fuzzer netebpfext_corpus -max_len=12 -runs=1000 -use_value_profile=1 -artifact_prefix=Artifacts\ + # build_artifact: Build-x64 + # environment: '["windows-2022"]' + # code_coverage: false + # gather_dumps: true + # configurations: '["FuzzerDebug"]' + + # # Run Cilium regression tests in GitHub. + # cilium_tests: + # needs: regular + # # Only run on schedule and pull request. + # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: cilium_tests + # test_command: .\cilium_tests.exe -d yes + # build_artifact: Build-x64 + # environment: '["windows-2022"]' + # code_coverage: false + # gather_dumps: true + + # # Run the quick stress tests in GitHub. + # stress: + # needs: regular + # # Only run on schedule and pull request. + # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: stress + # # Until there is a dedicated stress test, re-use the perf test. + # test_command: .\ebpf_performance.exe -d yes + # build_artifact: Build-x64 + # environment: '["windows-2022"]' + # # No code coverage on stress. + # code_coverage: false + # gather_dumps: true + + # # Run the unit tests in GitHub with address sanitizer. + # sanitize_unit_tests: + # needs: sanitize + # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: unit_tests + # # Exclude [processes] test that ASAN can't work with. + # test_command: .\unit_tests.exe -d yes ~[processes] + # build_artifact: Build-x64-Sanitize + # environment: '["windows-2022"]' + # code_coverage: false + # gather_dumps: true + # capture_etw: true + + # # Run the fault injection simulator in GitHub. + # fault_injection: + # needs: regular + # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: fault_injection + # test_command: .\unit_tests.exe + # build_artifact: Build-x64 + # environment: '["windows-2022"]' + # code_coverage: true + # gather_dumps: true + # fault_injection: true + # leak_detection: true + + # # Run the low memory simulator for netebpfext_unit tests. + # fault_injection_netebpfext_unit: + # needs: regular + # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: netebpfext_fault_injection + # test_command: .\netebpfext_unit.exe + # build_artifact: Build-x64 + # environment: '["windows-2022"]' + # code_coverage: true + # gather_dumps: true + # fault_injection: true + # leak_detection: true + + # # Run a fast multi-threaded stress test pass against the usersim user-mode 'mock' framework. + # # Added as a 'per-PR' test to catch usersim regressions and/or run-time usage issues. + # quick_user_mode_multi_threaded_stress_test: + # needs: regular + # if: github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: quick_user_mode_multi_threaded_stress + # test_command: .\ebpf_stress_tests_um -tt=8 -td=2 + # build_artifact: Build-x64 + # environment: '["windows-2022"]' + # code_coverage: false + # leak_detection: false + # gather_dumps: true + # capture_etw: true + + # # Additional jobs to run on a schedule only (skip push and pull request). + # # --------------------------------------------------------------------------- + # codeql: + # # Only run during daily scheduled run + # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-build.yml + # with: + # ref: ${{ github.ref }} + # repository: ${{ github.repository }} + # build_artifact: Build-x64-CodeQl + # build_codeql: true + + + # # Run the complete fault injection simulator in GitHub. + # # Runs on a schedule as this takes a long time to run. + # fault_injection_full: + # needs: regular + # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: fault_injection_full + # test_command: .\unit_tests.exe + # build_artifact: Build-x64 + # environment: '["windows-2022"]' + # code_coverage: false + # gather_dumps: true + # fault_injection: true + # leak_detection: true + + # # Run the complete fault injection simulator for netebpfext in GitHub. + # # Runs on a schedule as this takes a long time to run. + # netebpfext_fault_injection_full: + # needs: regular + # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: netebpfext_fault_injection_full + # test_command: .\netebpfext_unit.exe + # build_artifact: Build-x64 + # environment: '["windows-2022"]' + # code_coverage: false + # gather_dumps: true + # fault_injection: true + + # # Run multi-threaded stress tests against the user mode 'mock' framework. + # user_mode_multi_threaded_stress_test: + # needs: regular + # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: user_mode_multi_threaded_stress + # test_command: .\ebpf_stress_tests_um -tt=8 -td=10 + # build_artifact: Build-x64 + # environment: '["windows-2022"]' + # code_coverage: false + # leak_detection: false + # gather_dumps: true + # capture_etw: true + + # # Run multi-threaded stress tests with 'restart extension' disabled (default behavior) + # # against the kernel mode eBPF sub-system. + # km_mt_stress_tests: + # needs: regular + # # TODO - revert this back + # # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: km_mt_stress_tests + # pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "memory" + # test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Stress" + # post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + # build_artifact: Build-x64 + # environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2019"]' + # code_coverage: false + # # For this test, we only want kernel mode dumps and not user mode dumps. + # gather_dumps: false + + # # Run multi-threaded stress tests with 'restart extension' enabled + # # against the kernel mode eBPF sub-system. + # km_mt_stress_tests_restart_extension: + # needs: regular + # # TODO - revert this back + # # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: km_mt_stress_tests_restart_extension + # pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "memory" + # test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Stress" -Options @("RestartExtension") + # post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + # build_artifact: Build-x64 + # environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2019"]' + # code_coverage: false + # # For this test, we only want kernel mode dumps and not user mode dumps. + # gather_dumps: false + + # # TODO - figure this out... + # # Not sure what perf is - probably selfhosted runner, but do we need to support this now? + # performance: + # needs: regular + # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/reusable-test.yml + # with: + # name: km_performance + # pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" + # test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Performance" + # post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + # build_artifact: Build-x64 + # environment: ebpf_cicd_perf_ws2022 + # configurations: '["Release"]' + + # netperf: + # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/netperf.yml + # with: + # sha: ${{ github.sha }} + # ref: ${{ github.ref }} + # pull_request: ${{ github.event.pull_request.number }} + # secrets: + # NET_PERF_TRIGGER: ${{ secrets.NET_PERF_TRIGGER }} + + # upload_perf_results: + # needs: performance + # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/upload-perf-results.yml + # with: + # name: upload_perf_results + # result_artifact: km_performance-x64-Release + # secrets: + # AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} + # AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} + # AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + + # upload_netperf_results_lab_2022: + # needs: netperf + # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + # uses: ./.github/workflows/upload-perf-results.yml + # with: + # name: upload_netperf_results_lab_2022 + # result_artifact: netperf_lab_2022_x64 + # platform: Lab Windows 2022 + # secrets: + # AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} + # AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} + # AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} From 8b393a0f75868d8a85fff90ccfbdc3b7a2f191e2 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 22 Jan 2025 12:49:23 -0800 Subject: [PATCH 148/190] log user context --- 1es/Setup.ps1 | 33 +++++++++++++++++++++++++++++++ scripts/setup_ebpf_cicd_tests.ps1 | 20 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/1es/Setup.ps1 b/1es/Setup.ps1 index a16ab0aac6..6c5340c880 100644 --- a/1es/Setup.ps1 +++ b/1es/Setup.ps1 @@ -61,6 +61,38 @@ Create-VMSwitchIfNeeded -SwitchName $VMSwitchName -SwitchType 'Internal' $AdminUserCredential = Generate-StoredCredential -Target 'TEST_VM' -Username 'Administrator' $StandardUserCredential = Generate-StoredCredential -Target 'TEST_VM_STANDARD' -Username 'VMStandardUser' +$cred = Get-StoredCredential -Target 'TEST_VM' +if ($cred -eq $null) { + throw "Failed to retrieve the TEST_VM credential." +} else { + Log-Message "Sucessfully retrieved the TEST_VM credential." +} +$cred = Get-StoredCredential -Target 'TEST_VM_STANDARD' +if ($cred -eq $null) { + throw "Failed to retrieve the TEST_VM_STANDARD credential." +} else { + Log-Message "Sucessfully retrieved the TEST_VM_STANDARD credential." +} + +function Get-UserContext { + $whoami = whoami + $username = $env:USERNAME + $userdomain = $env:USERDOMAIN + $wmiUser = (Get-WmiObject -Class Win32_ComputerSystem).UserName + + [PSCustomObject]@{ + WhoAmI = $whoami + UserName = $username + UserDomain = $userdomain + WmiUserName = $wmiUser + } +} + +# Run the function +$user = Get-UserContext +$userString = $user | Out-String +Log-Message "User context: $userString" + # Unzip any VHD files, if needed, and get the list of VHDs to create VMs from. $vhds = Prepare-VhdFiles -InputDirectory $BaseVhdDirPath Log-Message "Found $($vhds.Count) VHDs to create VMs from." @@ -95,6 +127,7 @@ foreach ($vhd in $vhds) { Log-Message "VM $vmName created successfully" } catch { Log-Message "Failed to create VM $vmName with error $_" + throw "Failed to create VM $vmName with error $_" } } diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index 92c98e7de5..a2b78edbfa 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -22,6 +22,26 @@ Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction S # $TestVMCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' Import-Module .\config_test_vm.psm1 -Force -ArgumentList ($TestVMCredential.UserName, $TestVMCredential.Password, $WorkingDirectory, $LogFileName) -WarningAction SilentlyContinue + +function Get-UserContext { + $whoami = whoami + $username = $env:USERNAME + $userdomain = $env:USERDOMAIN + $wmiUser = (Get-WmiObject -Class Win32_ComputerSystem).UserName + + [PSCustomObject]@{ + WhoAmI = $whoami + UserName = $username + UserDomain = $userdomain + WmiUserName = $wmiUser + } +} + +# Run the function +$user = Get-UserContext +$userString = $user | Out-String +Log-Message "User context: $userString" + Write-Log "Fetching the test VM credential using target: $Target" $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop if ($null -eq $TestVMCredential) { From 1fcfd409a7271427873d07a687117d39a8e9936d Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 22 Jan 2025 14:23:42 -0800 Subject: [PATCH 149/190] fix --- scripts/setup_ebpf_cicd_tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index a2b78edbfa..b0fc562df3 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -40,7 +40,7 @@ function Get-UserContext { # Run the function $user = Get-UserContext $userString = $user | Out-String -Log-Message "User context: $userString" +Write-Log "User context: $userString" Write-Log "Fetching the test VM credential using target: $Target" $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop From c3e0041cd4fcf2a6d1615a93fd4018ea4f4059a3 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 23 Jan 2025 15:08:35 -0800 Subject: [PATCH 150/190] update to use encrypted local credential, as stored credential was not working --- .github/workflows/cicd.yml | 2 +- 1es/Setup.ps1 | 26 +++---- 1es/prepare_vm_helpers.psm1 | 112 ++++++++++------------------ scripts/cleanup_ebpf_cicd_tests.ps1 | 13 ++-- scripts/common.psm1 | 53 +++++++------ scripts/execute_ebpf_cicd_tests.ps1 | 12 ++- scripts/setup_ebpf_cicd_tests.ps1 | 48 +++++------- scripts/test_execution.json | 104 +++++++++++++++++++++++++- 8 files changed, 215 insertions(+), 155 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index e097eb9321..a6603426ac 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -245,7 +245,7 @@ jobs: if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') uses: ./.github/workflows/reusable-test.yml with: - pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" + pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" -SelfHostedRunnerName '1ESRunner' test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_ws2025 diff --git a/1es/Setup.ps1 b/1es/Setup.ps1 index 6c5340c880..04375ef1c9 100644 --- a/1es/Setup.ps1 +++ b/1es/Setup.ps1 @@ -55,25 +55,23 @@ Create-DirectoryIfNotExists -Path $WorkingPath $VMSwitchName = 'VMInternalSwitch' Create-VMSwitchIfNeeded -SwitchName $VMSwitchName -SwitchType 'Internal' -# # Fetch the credentials for the VM using the Azure Key Vault. -# $AdminUserCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' -# $StandardUserCredential = Get-AzureKeyVaultCredential -SecretName 'VMStandardUser' -$AdminUserCredential = Generate-StoredCredential -Target 'TEST_VM' -Username 'Administrator' -$StandardUserCredential = Generate-StoredCredential -Target 'TEST_VM_STANDARD' -Username 'VMStandardUser' - -$cred = Get-StoredCredential -Target 'TEST_VM' -if ($cred -eq $null) { - throw "Failed to retrieve the TEST_VM credential." +# Create new credentials for the VM. +$AdminUserCredential = Get-NewUserCredential -Username 'Administrator' +$StandardUserCredential = Get-NewUserCredential -Username 'VMStandardUser' + +if ($AdminUserCredential -eq $null) { + throw "Failed to retrieve the Administrator credential." } else { - Log-Message "Sucessfully retrieved the TEST_VM credential." + Log-Message "Sucessfully retrieved the Administrator credential." } -$cred = Get-StoredCredential -Target 'TEST_VM_STANDARD' -if ($cred -eq $null) { - throw "Failed to retrieve the TEST_VM_STANDARD credential." + +if ($StandardUserCredential -eq $null) { + throw "Failed to retrieve the VMStandardUser credential." } else { - Log-Message "Sucessfully retrieved the TEST_VM_STANDARD credential." + Log-Message "Sucessfully retrieved the VMStandardUser credential." } +# TODO - remove this debugging output. function Get-UserContext { $whoami = whoami $username = $env:USERNAME diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index 5fea26ccd5..6b856246fb 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -560,101 +560,69 @@ function Create-VMSwitchIfNeeded { <# .SYNOPSIS - Retrieves a secret from Azure Key Vault and returns it as a PSCredential object. + Reads a PSCredential object from an XML file. .DESCRIPTION - This function retrieves a secret from Azure Key Vault and returns it as a PSCredential object. + This function takes a username as input, reads the corresponding XML file, + and returns the PSCredential object stored in that file. -.PARAMETER KeyVaultName - The name of the Azure Key Vault to retrieve the secret from. Defaults to 'ebpf-cicd-key-vault'. - -.PARAMETER SecretName - The name of the secret to retrieve from the Key Vault. - -.OUTPUTS - System.Management.Automation.PSCredential - This function returns a PSCredential object containing the secret value from the Key Vault. - The username is the input 'SecretName' and the password is the secret value. +.PARAMETER FilePath + The FilePath for which the PSCredential object will be read. .EXAMPLE - $credential = Get-AzureKeyVaultCredential -SecretName 'Administrator' + $cred = Get-UserCredential -FilePath "C:\Administrator.xml" + This example reads the PSCredential object from the file "C:\Administrator.xml". #> -function Get-AzureKeyVaultCredential -{ - param([Parameter(Mandatory=$False)][string] $KeyVaultName='ebpf-cicd-key-vault', - [Parameter(Mandatory=$True)][string] $SecretName) - - try { - # NuGet is a dependency for the Az module. Ensure it is installed too. - Install-PackageProvider -Name NuGet -Force -ErrorAction Stop *> $null 2>&1 - Import-PackageProvider -Name NuGet -Force -ErrorAction Stop *> $null 2>&1 - # Check if the Az module is installed, if not, install it - if (-not (Get-Module -ListAvailable -Name Az)) { - Install-Module -Name Az -AllowClobber -Force -ErrorAction Stop *> $null 2>&1 - } - - # Authenticate using the managed identity - Connect-AzAccount -Identity *> $null 2>&1 +function Get-UserCredential { + param ( + [string]$FilePath + ) + # Check if the file exists + if (-Not (Test-Path -Path $FilePath)) { + throw "The file $FilePath does not exist." + } - # Retrieve the secret from Key Vault - $secret = Get-AzKeyVaultSecret -VaultName $KeyVaultName -Name $SecretName + # Import the credential from the XML file + $Credential = Import-Clixml -Path $FilePath - # Return as a PSCredential object - $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($SecretName, $secret.SecretValue) - return $credential - } catch { - throw "Failed to get Azure Key Vault Credential using KeyVaultName: $KeyVaultName SecretName: $SecretName Error: $_" - } + # Return the PSCredential object + return $Credential } <# .SYNOPSIS - Creates and stores a new credential using the provided target and username and a randomly generated password. + Creates a PSCredential object with a randomly generated password and exports it to an XML file. .DESCRIPTION - This function takes a username as a string, generates a random password, creates a stored credential using the CredentialManager module, and returns a PSCredential object. - It ensures that the CredentialManager module is installed and handles any errors that occur during the process. - -.PARAMETER Target - The target name for the stored credential. + This function takes a username as input, generates a random password, converts it to a secure string, + creates a PSCredential object, and exports the credential to an XML file named after the username. .PARAMETER Username - The username for the credential. - -.RETURNS - [System.Management.Automation.PSCredential] - The PSCredential object created from the provided username and generated password. + The username for which the PSCredential object will be created. .EXAMPLE - $credential = Generate-StoredCredential -Target "your_target" -Username "your_username" + $cred = Get-NewUserCredential -Username "exampleUser" + This example creates a PSCredential object for the user "exampleUser" and exports it to "exampleUser.xml". #> -function Generate-StoredCredential { +function Get-NewUserCredential { param ( - [Parameter(Mandatory=$True)][string]$Target, - [Parameter(Mandatory=$True)][string]$Username + [string]$Username ) - try { - # Import the CredentialManager module. Ensure any dependencies are installed. - Install-PackageProvider -Name NuGet -Force -ErrorAction Stop *> $null 2>&1 - Import-PackageProvider -Name NuGet -Force -ErrorAction Stop *> $null 2>&1 - if (-not (Get-Module -ListAvailable -Name CredentialManager)) { - Install-Module -Name CredentialManager -Force -ErrorAction Stop *> $null 2>&1 - } - Import-Module CredentialManager -ErrorAction Stop + # Generate a random password of 12 characters + $PasswordLength = 12 + $Password = -join ((65..90) + (97..122) + (48..57) | Get-Random -Count $PasswordLength | ForEach-Object {[char]$_}) - # Create the stored credential - $SecurePassword = ConvertTo-SecureString (Get-StrongPassword) -AsPlainText -Force - New-StoredCredential -Target $Target -UserName $Username -SecurePassword $SecurePassword -Persist LocalMachine -ErrorAction Stop *> $null 2>&1 + # Convert the password to a secure string + $SecurePassword = ConvertTo-SecureString $Password -AsPlainText -Force - # Validate that the credential was created - $cred = Get-StoredCredential -Target $Target -ErrorAction Stop - if ($cred -eq $null) { - throw "Failed to create and store credential for target: $Target and username: $Username" - } + # Create the PSCredential object with the username and secure password + $Credential = New-Object System.Management.Automation.PSCredential ($Username, $SecurePassword) - return $cred - } catch { - throw "Failed to create and store credential for username: $Username with error: $_" - } + # Export the credential to an XML file named after the username + $FilePath = ".\$Username.xml" + $Credential | Export-Clixml -Path $FilePath + + # Obtain the credential back to ensure it was exported correctly + return Get-UserCredential -FilePath $FilePath } diff --git a/scripts/cleanup_ebpf_cicd_tests.ps1 b/scripts/cleanup_ebpf_cicd_tests.ps1 index f9c2c4cc29..d27d371b5a 100644 --- a/scripts/cleanup_ebpf_cicd_tests.ps1 +++ b/scripts/cleanup_ebpf_cicd_tests.ps1 @@ -6,15 +6,17 @@ param ([parameter(Mandatory=$false)][string] $Target = "TEST_VM", [parameter(Mandatory=$false)][string] $LogFileName = "TestLog.log", [parameter(Mandatory=$false)][string] $WorkingDirectory = $pwd.ToString(), [parameter(Mandatory=$false)][string] $TestExecutionJsonFileName = "test_execution.json", - [parameter(Mandatory=$false)][string] $SelfHostedRunnerName = "runner_host", + [parameter(Mandatory=$false)][string] $SelfHostedRunnerName = [System.Net.Dns]::GetHostName(), [Parameter(Mandatory = $false)][int] $TestJobTimeout = (30*60)) Push-Location $WorkingDirectory Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue -# $TestVMCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' -Import-Module CredentialManager -ErrorAction Stop -$TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop +if ($SelfHostedRunnerName -eq "1ESRunner") { + $TestVMCredential = Get-UserCredential -FilePath 'C:\work\Administrator.xml' +} else { + $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop +} # Read the test execution json. $Config = Get-Content ("{0}\{1}" -f $PSScriptRoot, $TestExecutionJsonFileName) | ConvertFrom-Json @@ -89,4 +91,5 @@ Pop-Location if ($JobTimedOut) { exit 1 -} \ No newline at end of file +} + diff --git a/scripts/common.psm1 b/scripts/common.psm1 index c76c195fe1..f56e556a2c 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -3,8 +3,6 @@ param ([parameter(Mandatory=$True)] [string] $LogFileName) -Import-Module CredentialManager -ErrorAction Stop - # # Common helper functions. # @@ -45,36 +43,35 @@ function New-Credential return $Credential } -# -# Retrieves the secret from Azure Key Vault. -# Returns a PSCredential object, where the username is the secret name and the password is the retrieved secret. -# -function Get-AzureKeyVaultCredential -{ - param([Parameter(Mandatory=$False)][string] $KeyVaultName='ebpf-cicd-key-vault', - [Parameter(Mandatory=$True)][string] $SecretName) - try { - # NuGet is a dependency for the Az module. Ensure it is installed too. - Install-PackageProvider -Name NuGet -Force -ErrorAction Stop *> $null 2>&1 - Import-PackageProvider -Name NuGet -Force -ErrorAction Stop *> $null 2>&1 - - # Check if the Az module is installed, if not, install it - if (-not (Get-Module -ListAvailable -Name Az)) { - Install-Module -Name Az -AllowClobber -Force -ErrorAction Stop *> $null 2>&1 - } +<# +.SYNOPSIS + Reads a PSCredential object from an XML file. - # Authenticate using the managed identity - Connect-AzAccount -Identity *> $null 2>&1 +.DESCRIPTION + This function takes a username as input, reads the corresponding XML file, + and returns the PSCredential object stored in that file. - # Retrieve the secret from Key Vault - $secret = Get-AzKeyVaultSecret -VaultName $KeyVaultName -Name $SecretName +.PARAMETER FilePath + The FilePath for which the PSCredential object will be read. - # Return as a PSCredential object - $credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @($SecretName, $secret.SecretValue) - return $credential - } catch { - throw "Failed to get Azure Key Vault Credential using KeyVaultName: $KeyVaultName SecretName: $SecretName Error: $_" +.EXAMPLE + $cred = Get-UserCredential -FilePath "C:\Administrator.xml" + This example reads the PSCredential object from the file "C:\Administrator.xml". +#> +function Get-UserCredential { + param ( + [string]$FilePath + ) + # Check if the file exists + if (-Not (Test-Path -Path $FilePath)) { + throw "The file $FilePath does not exist." } + + # Import the credential from the XML file + $Credential = Import-Clixml -Path $FilePath + + # Return the PSCredential object + return $Credential } function Compress-File diff --git a/scripts/execute_ebpf_cicd_tests.ps1 b/scripts/execute_ebpf_cicd_tests.ps1 index a8c93c03a7..67a3279099 100644 --- a/scripts/execute_ebpf_cicd_tests.ps1 +++ b/scripts/execute_ebpf_cicd_tests.ps1 @@ -8,7 +8,7 @@ param ([Parameter(Mandatory = $false)][string] $AdminTarget = "TEST_VM", [Parameter(Mandatory = $false)][string] $TestExecutionJsonFileName = "test_execution.json", [Parameter(Mandatory = $false)][string] $TestMode = "CI/CD", [Parameter(Mandatory = $false)][string[]] $Options = @("None"), - [Parameter(Mandatory = $false)][string] $SelfHostedRunnerName = "runner_host", + [Parameter(Mandatory = $false)][string] $SelfHostedRunnerName = [System.Net.Dns]::GetHostName(), [Parameter(Mandatory = $false)][int] $TestHangTimeout = (10*60), [Parameter(Mandatory = $false)][string] $UserModeDumpFolder = "C:\Dumps", [Parameter(Mandatory = $false)][int] $TestJobTimeout = (60*60) @@ -17,9 +17,13 @@ param ([Parameter(Mandatory = $false)][string] $AdminTarget = "TEST_VM", Push-Location $WorkingDirectory Import-Module $WorkingDirectory\common.psm1 -Force -ArgumentList ($LogFileName) -ErrorAction Stop -Import-Module CredentialManager -ErrorAction Stop -$AdminTestVMCredential = Get-StoredCredential -Target $AdminTarget -ErrorAction Stop -$StandardUserTestVMCredential = Get-StoredCredential -Target $StandardUserTarget -ErrorAction Stop +if ($SelfHostedRunnerName -eq "1ESRunner") { + $AdminTestVMCredential = Get-UserCredential -FilePath 'C:\work\Administrator.xml' + $AdminTestVMCredential = Get-UserCredential -FilePath 'C:\work\VMStandardUser.xml' +} else { + $AdminTestVMCredential = Get-StoredCredential -Target $AdminTarget -ErrorAction Stop + $StandardUserTestVMCredential = Get-StoredCredential -Target $StandardUserTarget -ErrorAction Stop +} # Read the test execution json. $Config = Get-Content ("{0}\{1}" -f $PSScriptRoot, $TestExecutionJsonFileName) | ConvertFrom-Json diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index b0fc562df3..96082b1013 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -10,45 +10,29 @@ param ([parameter(Mandatory=$false)][string] $Target = "TEST_VM", [parameter(Mandatory=$false)][string] $RegressionArtifactsVersion = "", [parameter(Mandatory=$false)][string] $RegressionArtifactsConfiguration = "", [parameter(Mandatory=$false)][string] $TestExecutionJsonFileName = "test_execution.json", - [parameter(Mandatory=$false)][string] $SelfHostedRunnerName = "runner_host", - [Parameter(Mandatory = $false)][int] $TestJobTimeout = (5*60)) + [parameter(Mandatory=$false)][string] $SelfHostedRunnerName = [System.Net.Dns]::GetHostName(), + [Parameter(Mandatory = $false)][int] $TestJobTimeout = (30*60)) Push-Location $WorkingDirectory -Import-Module CredentialManager -ErrorAction Stop - # Load other utility modules. Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue -# $TestVMCredential = Get-AzureKeyVaultCredential -SecretName 'Administrator' - -Import-Module .\config_test_vm.psm1 -Force -ArgumentList ($TestVMCredential.UserName, $TestVMCredential.Password, $WorkingDirectory, $LogFileName) -WarningAction SilentlyContinue -function Get-UserContext { - $whoami = whoami - $username = $env:USERNAME - $userdomain = $env:USERDOMAIN - $wmiUser = (Get-WmiObject -Class Win32_ComputerSystem).UserName - - [PSCustomObject]@{ - WhoAmI = $whoami - UserName = $username - UserDomain = $userdomain - WmiUserName = $wmiUser +if ($SelfHostedRunnerName -eq "1ESRunner") { + Write-Log "Fetching the test VM credential using target: $Target" + $TestVMCredential = Get-UserCredential -FilePath 'C:\work\Administrator.xml' + # $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop + if ($null -eq $TestVMCredential) { + ThrowWithErrorMessage "Failed to retrieve the test VM credential." } -} + $debugCred = $TestVMCredential.GetNetworkCredential() | Out-String + Write-Log "Cred: $debugCred" -# Run the function -$user = Get-UserContext -$userString = $user | Out-String -Write-Log "User context: $userString" - -Write-Log "Fetching the test VM credential using target: $Target" -$TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop -if ($null -eq $TestVMCredential) { - ThrowWithErrorMessage "Failed to retrieve the test VM credential." +} else { + $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop } -$debugCred = $TestVMCredential.GetNetworkCredential() | Out-String -Write-Log "Cred: $debugCred" + +Import-Module .\config_test_vm.psm1 -Force -ArgumentList ($TestVMCredential.UserName, $TestVMCredential.Password, $WorkingDirectory, $LogFileName) -WarningAction SilentlyContinue # Read the test execution json. $Config = Get-Content ("{0}\{1}" -f $PSScriptRoot, $TestExecutionJsonFileName) | ConvertFrom-Json @@ -56,6 +40,10 @@ $VMList = $Config.VMMap.$SelfHostedRunnerName # Delete old log files if any. Remove-Item "$env:TEMP\$LogFileName" -ErrorAction SilentlyContinue +foreach($VM in $VMList) { + $VMName = $VM.Name + Remove-Item $env:TEMP\$LogFileName -ErrorAction SilentlyContinue +} Remove-Item ".\TestLogs" -Recurse -Confirm:$false -ErrorAction SilentlyContinue if ($TestMode -eq "Regression") { diff --git a/scripts/test_execution.json b/scripts/test_execution.json index ffa9f24949..48585ebcfc 100644 --- a/scripts/test_execution.json +++ b/scripts/test_execution.json @@ -3,7 +3,109 @@ "VMMap": { - "runner_host" : + "TK5-3WP08R0904_WS2019_1": + [ + { + "Name": "vm1_ws2019" + } + ], + "TK5-3WP08R0904_WS2019_2": + [ + { + "Name": "vm2_ws2019" + } + ], + "TK5-3WP08R0907_WS2019_1": + [ + { + "Name": "vm1_ws2019" + } + ], + "TK5-3WP08R0907_WS2019_2": + [ + { + "Name": "vm2_ws2019" + } + ], + "TK5-3WP07R0703_WS2019_1": + [ + { + "Name": "vm1_ws2019" + } + ], + "TK5-3WP07R0703_WS2019_2": + [ + { + "Name": "vm2_ws2019" + } + ], + "TK5-3WP07R0703_WS2019_3": + [ + { + "Name": "vm3_ws2019" + } + ], + "TK5-3WP07R0703_WS2019_4": + [ + { + "Name": "vm4_ws2019" + } + ], + "TK5-3WP07R0703_WS2022_1": + [ + { + "Name": "vm1_ws2022" + } + ], + "TK5-3WP07R0703_WS2022_2": + [ + { + "Name": "vm2_ws2022" + } + ], + "TK5-3WP07R0703_WS2022_3": + [ + { + "Name": "vm3_ws2022" + } + ], + "TK5-3WP07R0703_WS2022_4": + [ + { + "Name": "vm4_ws2022" + } + ], + "TK5-3WP07R0703_WS2022_5": + [ + { + "Name": "vm5_ws2022" + } + ], + "TK5-3WP07R0703_WS2022_6": + [ + { + "Name": "vm6_ws2022" + } + ], + "TK5-3WP07R0703_WS2022_7": + [ + { + "Name": "vm7_ws2022" + } + ], + "TK5-3WP07R0703_WS2022_8": + [ + { + "Name": "vm8_ws2022" + } + ], + "TK5-3WP07R0703_WS2022_PERF_1": + [ + { + "Name": "vm_perf_ws2022" + } + ], + "1ESRunner" : [ { "Name": "runner_vm" From eabb997463847cc70f8c3bda0e25c77ce8537142 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Thu, 23 Jan 2025 16:51:20 -0800 Subject: [PATCH 151/190] update and fixes to using xml file --- .github/workflows/cicd.yml | 4 ++-- 1es/Setup.ps1 | 4 +++- 1es/prepare_vm_helpers.psm1 | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index a6603426ac..62f9495b30 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -246,8 +246,8 @@ jobs: uses: ./.github/workflows/reusable-test.yml with: pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" -SelfHostedRunnerName '1ESRunner' - test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" - post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" -SelfHostedRunnerName '1ESRunner' + post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true -SelfHostedRunnerName '1ESRunner' name: driver_ws2025 build_artifact: Build-x64 environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2025"]' diff --git a/1es/Setup.ps1 b/1es/Setup.ps1 index 04375ef1c9..79db301a37 100644 --- a/1es/Setup.ps1 +++ b/1es/Setup.ps1 @@ -59,6 +59,7 @@ Create-VMSwitchIfNeeded -SwitchName $VMSwitchName -SwitchType 'Internal' $AdminUserCredential = Get-NewUserCredential -Username 'Administrator' $StandardUserCredential = Get-NewUserCredential -Username 'VMStandardUser' +# TODO - remove this debugging output. if ($AdminUserCredential -eq $null) { throw "Failed to retrieve the Administrator credential." } else { @@ -71,7 +72,8 @@ if ($StandardUserCredential -eq $null) { Log-Message "Sucessfully retrieved the VMStandardUser credential." } -# TODO - remove this debugging output. +Get-ChildItem -Path 'C:\work' -Recurse + function Get-UserContext { $whoami = whoami $username = $env:USERNAME diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index 6b856246fb..3ad1853dec 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -620,7 +620,7 @@ function Get-NewUserCredential { $Credential = New-Object System.Management.Automation.PSCredential ($Username, $SecurePassword) # Export the credential to an XML file named after the username - $FilePath = ".\$Username.xml" + $FilePath = ".\$($Username).xml" $Credential | Export-Clixml -Path $FilePath # Obtain the credential back to ensure it was exported correctly From d7fccb0e545d76f14569cb4ea6471c5cd281a279 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 24 Jan 2025 10:52:26 -0800 Subject: [PATCH 152/190] VM creation wiht psexec --- 1es/Setup.ps1 | 33 ++-- 1es/prepare_vm_helpers.psm1 | 169 +-------------------- scripts/common.psm1 | 243 ++++++++++++++++++++++++++---- scripts/config_test_vm.psm1 | 5 +- scripts/setup_ebpf_cicd_tests.ps1 | 4 +- 5 files changed, 242 insertions(+), 212 deletions(-) diff --git a/1es/Setup.ps1 b/1es/Setup.ps1 index 79db301a37..598879dcea 100644 --- a/1es/Setup.ps1 +++ b/1es/Setup.ps1 @@ -36,9 +36,6 @@ param( $ErrorActionPreference = "Stop" -# Import helper functions -Import-Module .\prepare_vm_helpers.psm1 -Force - # Input validation for input paths if (-not (Test-Path -Path $BaseUnattendPath)) { throw "Unattend file not found at $BaseUnattendPath" @@ -48,16 +45,25 @@ if (-not (Test-Path -Path $BaseVhdDirPath)) { throw "VHD directory not found at $BaseVhdDirPath" } -# Create working directory used for VM creation. -Create-DirectoryIfNotExists -Path $WorkingPath +# Import helper functions +$logFileName = 'Setup.log' +Import-Module .\common.psm1 -Force -ArgumentList ($logFileName) -WarningAction SilentlyContinue +$adminPassword = New-UniquePassword +$adminSecureString = ConvertTo-SecureString -String $adminPassword -AsPlainText -Force +$standardUserPassword = New-UniquePassword +Import-Module .\prepare_vm_helpers.psm1 -Force -WarningAction SilentlyContinue +Import-Module .\config_test_vm.psm1 -Force -ArgumentList('Administrator', $adminSecureString, 'C:\work', $logFileName) -WarningAction SilentlyContinue + +Get-PSExec +if (-not (Test-Path -Path "$pwd\PSExec64.exe")) { + throw "PSExec64.exe not found in the current directory." +} +$psExecPath = "$pwd\PSExec64.exe" -# Create internal switch for VM. -$VMSwitchName = 'VMInternalSwitch' -Create-VMSwitchIfNeeded -SwitchName $VMSwitchName -SwitchType 'Internal' # Create new credentials for the VM. -$AdminUserCredential = Get-NewUserCredential -Username 'Administrator' -$StandardUserCredential = Get-NewUserCredential -Username 'VMStandardUser' +$AdminUserCredential = Generate-NewCredential -Username 'Administrator' -Password $adminPassword -Target 'TEST_VM' -PsExecPath $psExecPath +$StandardUserCredential = Generate-NewCredential -Username 'VMStandardUser' -Password $standardUserPassword -Target 'TEST_VM_STANDARD' -PsExecPath $psExecPath # TODO - remove this debugging output. if ($AdminUserCredential -eq $null) { @@ -93,6 +99,13 @@ $user = Get-UserContext $userString = $user | Out-String Log-Message "User context: $userString" +# Create working directory used for VM creation. +Create-DirectoryIfNotExists -Path $WorkingPath + +# Create internal switch for VM. +$VMSwitchName = 'VMInternalSwitch' +Create-VMSwitchIfNeeded -SwitchName $VMSwitchName -SwitchType 'Internal' + # Unzip any VHD files, if needed, and get the list of VHDs to create VMs from. $vhds = Prepare-VhdFiles -InputDirectory $BaseVhdDirPath Log-Message "Found $($vhds.Count) VHDs to create VMs from." diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index 3ad1853dec..7d8009b20b 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -2,102 +2,6 @@ # SPDX-License-Identifier: MIT $ErrorActionPreference = "Stop" -<# -.SYNOPSIS - Helper function to format a log message with a timestamp and outputs the message to the console. - -.DESCRIPTION - This function formats a log message with a timestamp and outputs the message to the console. - -.PARAMETER Message - The message to log. - -.PARAMETER ForegroundColor - The color of the text to display in the console. Defaults to 'White'. - -.EXAMPLE - Log-Message -Message "This is a log message" - Log-Message -Message "This is a success log message" -ForegroundColor "Green" - Log-Message -Message "This is an error log message" -ForegroundColor "Red" -#> -function Log-Message { - param( - [Parameter(Mandatory=$True)][string]$Message, - [Parameter(Mandatory=$False)][string]$ForegroundColor='White' - ) - - # Get timestamp - $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" - - Write-Host "[$timestamp] - $Message" -ForegroundColor $ForegroundColor -} - -<# -.SYNOPSIS - Helper function to create a directory if it does not already exist. - -.DESCRIPTION - This function checks if a directory exists at the specified path. If it does not exist, it creates the directory. - -.PARAMETER Path - The path of the directory to create. - -.EXAMPLE - Create-DirectoryIfNotExists -Path "C:\MyDirectory" -#> -function Create-DirectoryIfNotExists { - param ( - [Parameter(Mandatory=$True)][string]$Path - ) - - try { - if (-not (Test-Path -Path $Path -PathType Container)) { - New-Item -Path $Path -ItemType Directory -Force # -ErrorAction Ignore | Out-Null - } - - if (-not (Test-Path -PathType Container $Path)) { - throw "Failed to create directory: $Path" - } - } catch { - throw "Failed to create directory: $Path with error $_" - } -} - -<# -.SYNOPSIS - Helper function to replace placeholder strings in a file. - -.DESCRIPTION - This function replaces all occurrences of a specified search string with a replacement string in a file. - -.PARAMETER FilePath - The path to the file in which to replace the placeholder strings. - -.PARAMETER SearchString - The string to search for in the file. - -.PARAMETER ReplaceString - The string to replace the search string with. - -.EXAMPLE - Replace-PlaceholderStrings -FilePath "C:\MyFile.txt" -SearchString "PLACEHOLDER" -ReplaceString "ActualValue" -#> -function Replace-PlaceholderStrings { - param ( - [Parameter(Mandatory=$True)][string]$FilePath, - [Parameter(Mandatory=$True)][string]$SearchString, - [Parameter(Mandatory=$True)][string]$ReplaceString - ) - - try { - $content = Get-Content -Path $FilePath - $content = $content -replace $SearchString, $ReplaceString - Set-Content -Path $FilePath -Value $content - } catch { - throw "Failed to replace placeholder strings in file: $FilePath. Error: $_" - } -} - <# .SYNOPSIS Helper function to execute a command on a VM. @@ -122,12 +26,12 @@ function Execute-CommandOnVM { ) try { - Log-Message "Executing command on VM: $VMName. Command: $Command" + Write-Log "Executing command on VM: $VMName. Command: $Command" $result = Invoke-Command -VMName $VMName -Credential $VmCredential -ScriptBlock { param($Command) Invoke-Expression $Command } -ArgumentList $Command - Log-Message -Message "Successfully executed command on VM: $VMName. Command: $Command. Result: $result" + Write-Log -Message "Successfully executed command on VM: $VMName. Command: $Command. Result: $result" } catch { throw "Failed to execute command on VM: $VMName with error: $_" } @@ -557,72 +461,3 @@ function Create-VMSwitchIfNeeded { Log-Message "Successfully created $SwitchType switch with name: $SwitchName" -ForegroundColor Green } - -<# -.SYNOPSIS - Reads a PSCredential object from an XML file. - -.DESCRIPTION - This function takes a username as input, reads the corresponding XML file, - and returns the PSCredential object stored in that file. - -.PARAMETER FilePath - The FilePath for which the PSCredential object will be read. - -.EXAMPLE - $cred = Get-UserCredential -FilePath "C:\Administrator.xml" - This example reads the PSCredential object from the file "C:\Administrator.xml". -#> -function Get-UserCredential { - param ( - [string]$FilePath - ) - # Check if the file exists - if (-Not (Test-Path -Path $FilePath)) { - throw "The file $FilePath does not exist." - } - - # Import the credential from the XML file - $Credential = Import-Clixml -Path $FilePath - - # Return the PSCredential object - return $Credential -} - -<# -.SYNOPSIS - Creates a PSCredential object with a randomly generated password and exports it to an XML file. - -.DESCRIPTION - This function takes a username as input, generates a random password, converts it to a secure string, - creates a PSCredential object, and exports the credential to an XML file named after the username. - -.PARAMETER Username - The username for which the PSCredential object will be created. - -.EXAMPLE - $cred = Get-NewUserCredential -Username "exampleUser" - This example creates a PSCredential object for the user "exampleUser" and exports it to "exampleUser.xml". -#> -function Get-NewUserCredential { - param ( - [string]$Username - ) - - # Generate a random password of 12 characters - $PasswordLength = 12 - $Password = -join ((65..90) + (97..122) + (48..57) | Get-Random -Count $PasswordLength | ForEach-Object {[char]$_}) - - # Convert the password to a secure string - $SecurePassword = ConvertTo-SecureString $Password -AsPlainText -Force - - # Create the PSCredential object with the username and secure password - $Credential = New-Object System.Management.Automation.PSCredential ($Username, $SecurePassword) - - # Export the credential to an XML file named after the username - $FilePath = ".\$($Username).xml" - $Credential | Export-Clixml -Path $FilePath - - # Obtain the credential back to ensure it was exported correctly - return Get-UserCredential -FilePath $FilePath -} diff --git a/scripts/common.psm1 b/scripts/common.psm1 index f56e556a2c..e0b109eefe 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -43,37 +43,6 @@ function New-Credential return $Credential } -<# -.SYNOPSIS - Reads a PSCredential object from an XML file. - -.DESCRIPTION - This function takes a username as input, reads the corresponding XML file, - and returns the PSCredential object stored in that file. - -.PARAMETER FilePath - The FilePath for which the PSCredential object will be read. - -.EXAMPLE - $cred = Get-UserCredential -FilePath "C:\Administrator.xml" - This example reads the PSCredential object from the file "C:\Administrator.xml". -#> -function Get-UserCredential { - param ( - [string]$FilePath - ) - # Check if the file exists - if (-Not (Test-Path -Path $FilePath)) { - throw "The file $FilePath does not exist." - } - - # Import the credential from the XML file - $Credential = Import-Clixml -Path $FilePath - - # Return the PSCredential object - return $Credential -} - function Compress-File { param ([Parameter(Mandatory = $True)] [string] $SourcePath, @@ -142,3 +111,215 @@ function Wait-TestJobToComplete return $JobTimedOut } + +<# +.SYNOPSIS + Helper function to create a directory if it does not already exist. + +.DESCRIPTION + This function checks if a directory exists at the specified path. If it does not exist, it creates the directory. + +.PARAMETER Path + The path of the directory to create. + +.EXAMPLE + Create-DirectoryIfNotExists -Path "C:\MyDirectory" +#> +function Create-DirectoryIfNotExists { + param ( + [Parameter(Mandatory=$True)][string]$Path + ) + + try { + if (-not (Test-Path -Path $Path -PathType Container)) { + New-Item -Path $Path -ItemType Directory -Force # -ErrorAction Ignore | Out-Null + } + + if (-not (Test-Path -PathType Container $Path)) { + throw "Failed to create directory: $Path" + } + } catch { + throw "Failed to create directory: $Path with error $_" + } +} + +<# +.SYNOPSIS + Helper function to replace placeholder strings in a file. + +.DESCRIPTION + This function replaces all occurrences of a specified search string with a replacement string in a file. + +.PARAMETER FilePath + The path to the file in which to replace the placeholder strings. + +.PARAMETER SearchString + The string to search for in the file. + +.PARAMETER ReplaceString + The string to replace the search string with. + +.EXAMPLE + Replace-PlaceholderStrings -FilePath "C:\MyFile.txt" -SearchString "PLACEHOLDER" -ReplaceString "ActualValue" +#> +function Replace-PlaceholderStrings { + param ( + [Parameter(Mandatory=$True)][string]$FilePath, + [Parameter(Mandatory=$True)][string]$SearchString, + [Parameter(Mandatory=$True)][string]$ReplaceString + ) + + try { + $content = Get-Content -Path $FilePath + $content = $content -replace $SearchString, $ReplaceString + Set-Content -Path $FilePath -Value $content + } catch { + throw "Failed to replace placeholder strings in file: $FilePath. Error: $_" + } +} + +<# +.SYNOPSIS + Imports the CredentialManager, and installs it if necessary. + +.DESCRIPTION + This function imports the CredentialManager module and installs it if it is not already installed. It also ensures that any dependencies are installed. +#> +function Get-CredentialManager { + # Import the CredentialManager module. Ensure any dependencies are installed. + Install-PackageProvider -Name NuGet -Force -ErrorAction Stop *> $null 2>&1 + Import-PackageProvider -Name NuGet -Force -ErrorAction Stop *> $null 2>&1 + if (-not (Get-Module -ListAvailable -Name CredentialManager)) { + Install-Module -Name CredentialManager -Force -ErrorAction Stop *> $null 2>&1 + } + Import-Module CredentialManager -ErrorAction Stop +} + +<# +.SYNOPSIS + Generates a strong password using the credential manager. + +.DESCRIPTION + This function generates a strong password using the CredentialManager module. + +.OUTPUTS + [String] + The generated strong password. +#> +function New-UniquePassword { + Get-CredentialManager + return Get-StrongPassword +} + +<# +.SYNOPSIS + Retrieves a credential from the Windows Credential Manager using PsExec. + +.PARAMETER PsExecPath + The path to the PsExec executable. + +.PARAMETER Target + The name of the stored credential. Default is "MyStoredCredential". + +.DESCRIPTION + This function uses PsExec to run a PowerShell script in the LocalSystem account context to retrieve a credential from the Windows Credential Manager. + +.EXAMPLE + $credential = Retrieve-StoredCredential -PsExecPath "C:\Path\To\PsExec.exe" -Target "MyStoredCredential" +#> +function Retrieve-StoredCredential { + param ( + [Parameter(Mandatory=$True)][string]$PsExecPath, + [Parameter(Mandatory=$True)][string]$Target + ) + $Script = @" + Import-Module CredentialManager -ErrorAction Stop; + `$Credential = Get-StoredCredential -Target '$Target'; + `$UserName = `$Credential.UserName; + `$Password = `$Credential.GetNetworkCredential().Password; + \"`$UserName`n`$Password\" +"@ + + $outputFile = [System.IO.Path]::GetTempFileName() + $errorFile = [System.IO.Path]::GetTempFileName() + + try { + $process = Start-Process -FilePath $PsExecPath -ArgumentList "-accepteula -nobanner -s powershell.exe -command `"$Script`"" -NoNewWindow -PassThru -Wait -RedirectStandardOutput $outputFile -RedirectStandardError $errorFile + $output = Get-Content $outputFile + $error = Get-Content $errorFile + + if ($process.ExitCode -ne 0) { + throw "PsExec failed with exit code $($process.ExitCode). Error: $error" + } + + $lines = $output -split "`n" + $Username = $lines[0].Trim() + $Password = ConvertTo-SecureString -String $lines[1].Trim() -AsPlainText -Force + return [System.Management.Automation.PSCredential]::new($Username, $Password) + } catch { + throw "An error occurred while retrieving the credential: $_" + } finally { + if (Test-Path $outputFile) { Remove-Item $outputFile } + if (Test-Path $errorFile) { Remove-Item $errorFile } + } +} + +<# +.SYNOPSIS + Stores a credential in the Windows Credential Manager using PsExec. + +.PARAMETER PsExecPath + The path to the PsExec executable. + +.PARAMETER Username + The username for the credential. + +.PARAMETER Password + The password for the credential as a secure string. + +.PARAMETER Target + The name of the stored credential. Default is "MyStoredCredential". + +.DESCRIPTION + This function uses PsExec to run a PowerShell script in the LocalSystem account context to store a credential in the Windows Credential Manager. + +.EXAMPLE + $securePassword = ConvertTo-SecureString "YourPassword" -AsPlainText -Force + $credential = Generate-NewCredential -Username "YourUsername" -Password $securePassword -Target "MyStoredCredential" -PsExecPath "C:\Path\To\PsExec.exe" +#> +function Generate-NewCredential { + param ( + [Parameter(Mandatory=$True)][string]$Username, + [Parameter(Mandatory=$True)][string]$Password, + [Parameter(Mandatory=$True)][string]$Target, + [Parameter(Mandatory=$True)][string]$PsExecPath + ) + Get-CredentialManager + + Write-Host "Password: $Password" + $Script = @" + Import-Module CredentialManager -ErrorAction Stop; + New-StoredCredential -Target '$Target' -UserName '$Username' -Password '$Password'; +"@ + + $outputFile = [System.IO.Path]::GetTempFileName() + $errorFile = [System.IO.Path]::GetTempFileName() + + try { + $process = Start-Process -FilePath $PsExecPath -ArgumentList "-accepteula -nobanner -s powershell.exe -command `"$Script`"" -NoNewWindow -PassThru -Wait -RedirectStandardOutput $outputFile -RedirectStandardError $errorFile + $output = Get-Content $outputFile + $error = Get-Content $errorFile + + if ($process.ExitCode -ne 0) { + throw "PsExec failed with exit code $($process.ExitCode). Error: $error" + } + + # Use the Retrieve-StoredCredential function to verify that the credential was stored correctly. + return (Retrieve-StoredCredential -PsExecPath $PsExecPath -Target $Target) + } catch { + throw "An error occurred while storing the credential: $_" + } finally { + if (Test-Path $outputFile) { Remove-Item $outputFile } + if (Test-Path $errorFile) { Remove-Item $errorFile } + } +} diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index f3df454263..34d43bf3e8 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -768,11 +768,14 @@ function Get-CoreNetTools { # Download and extract PSExec to run tests as SYSTEM. function Get-PSExec { + # Check to see if PSExec already exists + if (Test-Path -Path "$pwd\PsExec64.exe") { + return + } $url = "https://download.sysinternals.com/files/PSTools.zip" $DownloadPath = "$pwd\psexec" Get-ZipFileFromUrl -Url $url -DownloadFilePath "$pwd\pstools.zip" -OutputDir "$DownloadPath" - cd .. Move-Item -Path "$DownloadPath\PsExec64.exe" -Destination $pwd -Force Remove-Item -Path $DownloadPath -Force -Recurse -ErrorAction Ignore } diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index 96082b1013..7e71065b06 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -20,14 +20,12 @@ Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction S if ($SelfHostedRunnerName -eq "1ESRunner") { Write-Log "Fetching the test VM credential using target: $Target" - $TestVMCredential = Get-UserCredential -FilePath 'C:\work\Administrator.xml' - # $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop + $TestVMCredential = Retrieve-StoredCredential -Target $Target if ($null -eq $TestVMCredential) { ThrowWithErrorMessage "Failed to retrieve the test VM credential." } $debugCred = $TestVMCredential.GetNetworkCredential() | Out-String Write-Log "Cred: $debugCred" - } else { $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop } From c0dfc77629fae6983abe1f3d273427c763d9c2f3 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 24 Jan 2025 11:55:12 -0800 Subject: [PATCH 153/190] update test scripst to use psexec for creds --- 1es/Setup.ps1 | 37 +---- 1es/prepare_vm_helpers.psm1 | 136 ++++------------ scripts/cleanup_ebpf_cicd_tests.ps1 | 4 +- scripts/common.psm1 | 234 ++++++++++++++++++++++++++++ scripts/config_test_vm.psm1 | 233 --------------------------- scripts/execute_ebpf_cicd_tests.ps1 | 6 +- scripts/setup_ebpf_cicd_tests.ps1 | 4 +- 7 files changed, 280 insertions(+), 374 deletions(-) diff --git a/1es/Setup.ps1 b/1es/Setup.ps1 index 598879dcea..f639139f0b 100644 --- a/1es/Setup.ps1 +++ b/1es/Setup.ps1 @@ -69,36 +69,15 @@ $StandardUserCredential = Generate-NewCredential -Username 'VMStandardUser' -Pas if ($AdminUserCredential -eq $null) { throw "Failed to retrieve the Administrator credential." } else { - Log-Message "Sucessfully retrieved the Administrator credential." + Write-Log "Sucessfully retrieved the Administrator credential." } if ($StandardUserCredential -eq $null) { throw "Failed to retrieve the VMStandardUser credential." } else { - Log-Message "Sucessfully retrieved the VMStandardUser credential." + Write-Log "Sucessfully retrieved the VMStandardUser credential." } -Get-ChildItem -Path 'C:\work' -Recurse - -function Get-UserContext { - $whoami = whoami - $username = $env:USERNAME - $userdomain = $env:USERDOMAIN - $wmiUser = (Get-WmiObject -Class Win32_ComputerSystem).UserName - - [PSCustomObject]@{ - WhoAmI = $whoami - UserName = $username - UserDomain = $userdomain - WmiUserName = $wmiUser - } -} - -# Run the function -$user = Get-UserContext -$userString = $user | Out-String -Log-Message "User context: $userString" - # Create working directory used for VM creation. Create-DirectoryIfNotExists -Path $WorkingPath @@ -108,14 +87,14 @@ Create-VMSwitchIfNeeded -SwitchName $VMSwitchName -SwitchType 'Internal' # Unzip any VHD files, if needed, and get the list of VHDs to create VMs from. $vhds = Prepare-VhdFiles -InputDirectory $BaseVhdDirPath -Log-Message "Found $($vhds.Count) VHDs to create VMs from." +Write-Log "Found $($vhds.Count) VHDs to create VMs from." $vhdDebugString = $vhds | Out-String -Log-Message "VHDs: $vhdDebugString" +Write-Log "VHDs: $vhdDebugString" # Process VM creation and setup. foreach ($vhd in $vhds) { try { - Log-Message -Message "Creating VM from VHD: $vhd" + Write-Log "Creating VM from VHD: $vhd" $vmName = "runner_vm" if ($i -gt 0) { $vmName += "_$i" @@ -137,9 +116,9 @@ foreach ($vhd in $vhds) { -VmCredential $AdminUserCredential ` -VMCpuCount $VMCpuCount - Log-Message "VM $vmName created successfully" + Write-Log "VM $vmName created successfully" } catch { - Log-Message "Failed to create VM $vmName with error $_" + Write-Log "Failed to create VM $vmName with error $_" throw "Failed to create VM $vmName with error $_" } } @@ -150,4 +129,4 @@ if ($vms.Count -eq 0) { Exit 1 } -Log-Message "Setup.ps1 complete!" \ No newline at end of file +Write-Log "Setup.ps1 complete!" \ No newline at end of file diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 index 7d8009b20b..4686e48c9e 100644 --- a/1es/prepare_vm_helpers.psm1 +++ b/1es/prepare_vm_helpers.psm1 @@ -31,7 +31,7 @@ function Execute-CommandOnVM { param($Command) Invoke-Expression $Command } -ArgumentList $Command - Write-Log -Message "Successfully executed command on VM: $VMName. Command: $Command. Result: $result" + Write-Log "Successfully executed command on VM: $VMName. Command: $Command. Result: $result" } catch { throw "Failed to execute command on VM: $VMName with error: $_" } @@ -69,7 +69,7 @@ function Wait-ForVMReady { try { # Ensure the VM is in running state while ((Get-VM -Name $VMName).State -ne 'Running') { - Log-Message -Message "Waiting for $VMName to reach running state..." + Write-Log "Waiting for $VMName to reach running state..." Start-Sleep -Seconds 5 } @@ -77,18 +77,18 @@ function Wait-ForVMReady { try { Execute-CommandOnVM -VMName $VMName -VmCredential $VmCredential -Command 'hostname' } catch { - Log-Message -Message "Failed to connect to $VMName. Retrying..." + Write-Log "Failed to connect to $VMName. Retrying..." Start-Sleep -Seconds 5 continue } - Log-Message -Message "Successfully connected to $VMName" + Write-Log "Successfully connected to $VMName" return } catch { # Do nothing. We will retry if we failed to connect to the VM. } - Log-Message -Message "Failed to connect to $VMName. Retrying..." + Write-Log "Failed to connect to $VMName. Retrying..." Start-Sleep -Seconds 5 } @@ -154,19 +154,19 @@ function Create-VM { Create-DirectoryIfNotExists -Path $VmStoragePath # Move the VHD to the path - Log-Message "Moving $VhdPath to $VmStoragePath" + Write-Log "Moving $VhdPath to $VmStoragePath" Move-Item -Path $VhdPath -Destination $VmStoragePath -Force $VmVhdPath = Join-Path -Path $VmStoragePath -ChildPath (Split-Path -Path $VhdPath -Leaf) # Move unattend to the path and replace placeholder strings - Log-Message "Moving $UnattendPath file to $VmStoragePath" + Write-Log "Moving $UnattendPath file to $VmStoragePath" Move-Item -Path $UnattendPath -Destination $VmStoragePath -Force $VmUnattendPath = Join-Path -Path $VmStoragePath -ChildPath (Split-Path -Path $UnattendPath -Leaf) Replace-PlaceholderStrings -FilePath $VmUnattendPath -SearchString 'PLACEHOLDER_ADMIN_PASSWORD' -ReplaceString $AdminUserCredential.GetNetworkCredential().Password Replace-PlaceholderStrings -FilePath $VmUnattendPath -SearchString 'PLACEHOLDER_STANDARDUSER_PASSWORD' -ReplaceString $StandardUserCredential.GetNetworkCredential().Password # Configure the VHD with the unattend file. - Log-Message "Mounting VHD and applying unattend file" + Write-Log "Mounting VHD and applying unattend file" $VmMountPath = Join-Path -Path $VmStoragePath -ChildPath 'mountedVhd' if (-not (Test-Path -Path $VmMountPath)) { New-Item -ItemType Directory -Path $VmMountPath @@ -177,7 +177,7 @@ function Create-VM { Dismount-WindowsImage -Path $VmMountPath -Save -ErrorAction Stop # Create the VM - Log-Message "Creating the VM" + Write-Log "Creating the VM" New-VM -Name $VmName -VhdPath $VmVhdPath -SwitchName $VmSwitchName Set-VMMemory -VMName $VmName -DynamicMemoryEnabled $false -StartupBytes $VMMemory @@ -185,7 +185,7 @@ function Create-VM { throw "Failed to create VM: $VMName" } - Log-Message -Message "Successfully created VM: $VMName" -ForegroundColor Green + Write-Log "Successfully created VM: $VMName" -ForegroundColor Green } catch { throw "Failed to create VM: $VmName with error: $_" } @@ -226,133 +226,53 @@ function Configure-VM { ) try { - Log-Message "Configuring VM: $VmName" + Write-Log "Configuring VM: $VmName" # Post VM creation configuration steps. - Log-Message "Setting VM processor count to $VMCpuCount" + Write-Log "Setting VM processor count to $VMCpuCount" Set-VMProcessor -VMName $VmName -Count $VMCpuCount - Log-Message "Enabling Guest Service Interface" + Write-Log "Enabling Guest Service Interface" Enable-VMIntegrationService -VMName $VMName -Name 'Guest Service Interface' # Start the VM - Log-Message "Starting VM: $VmName" + Write-Log "Starting VM: $VmName" Start-VM -Name $VmName Wait-ForVMReady -VMName $VmName -VmCredential $VmCredential - Log-Message "Sleeping for 1 minute to let the VM get into a steady state" + Write-Log "Sleeping for 1 minute to let the VM get into a steady state" Sleep -Seconds 60 # Copy setup script to the VM and execute it. - Log-Message "Executing VM configuration script ($VMSetupScript) on VM: $VmName" + Write-Log "Executing VM configuration script ($VMSetupScript) on VM: $VmName" Copy-VMFile -VMName $VmName -FileSource Host -SourcePath $VMSetupScript -DestinationPath "$VMWorkingDirectory\$VMSetupScript" -CreateFullPath Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "cd $VMWorkingDirectory; .\$VMSetupScript" - Log-Message "Sleeping for 1 minute to let the VM get into a steady state" + Write-Log "Sleeping for 1 minute to let the VM get into a steady state" Sleep -Seconds 60 # Sleep for 1 minute to let the VM get into a steady state. - Log-Message -Message "Successfully executed VM configuration script ($VMSetupScript) on VM: $VmName" -ForegroundColor Green + Write-Log "Successfully executed VM configuration script ($VMSetupScript) on VM: $VmName" -ForegroundColor Green Wait-ForVMReady -VMName $VmName -VmCredential $VmCredential # Checkpoint the VM. This can sometimes fail if other operations are in progress. for ($i = 0; $i -lt 5; $i += 1) { try { - Log-Message "Checkpointing VM: $VmName" + Write-Log "Checkpointing VM: $VmName" Checkpoint-VM -Name $VMName -SnapshotName 'baseline' - Log-Message -Message "Successfully added 'baseline' checkpoint for VM: $VMName" -ForegroundColor Green + Write-Log "Successfully added 'baseline' checkpoint for VM: $VMName" -ForegroundColor Green break } catch { - Log-Message "Failed to checkpoint VM: $VmName. Retrying..." + Write-Log "Failed to checkpoint VM: $VmName. Retrying..." Start-Sleep -Seconds 5 continue } } - Log-Message "Successfully configured VM: $VmName" -ForegroundColor Green + Write-Log "Successfully configured VM: $VmName" -ForegroundColor Green } catch { throw "Failed to configure VM: $VmName with error: $_" } } ########## Helpers for the host machine ########## -# <# -# .SYNOPSIS -# Helper function to prepare VHD files for VM creation. - -# .DESCRIPTION -# Unzips any files in given directory and returns a list of VHD and VHDX files in the input directory. - -# .PARAMETER BaseVhdDirPath -# The base directory containing the VHD files or zip files containing the VHD files. - -# .OUTPUTS -# System.IO.FileInfo[] -# This function returns a list of System.IO.FileInfo[] representing the VHD and VHDX files found in the input directory -# after any processing is complete. - -# .EXAMPLE -# $vhds = Prepare-VhdFiles -BaseVhdDirPath "C:\path\to\vhd\directory" -# #> -# function Prepare-VhdFiles { -# param( -# [Parameter(Mandatory=$True)][string]$BaseVhdDirPath -# ) -# # Unzip any VHDs -# Log-Message "Processing VHDs in $BaseVhdDirPath" -# $zipFiles = Get-ChildItem -Path $BaseVhdDirPath -Filter *.zip -# foreach ($zipFile in $zipFiles) { -# Log-Message "Extracting VHDs from $($zipFile.FullName)" -# $outDir = Join-Path -Path $BaseVhdDirPath -ChildPath $zipFile.BaseName -# if (-not (Test-Path -Path $outDir)) { -# $maxRetries = 3 -# $retryCount = 0 -# $success = $false - -# while (-not $success -and $retryCount -lt $maxRetries) { -# try { -# Expand-Archive -Path $zipFile.FullName -DestinationPath $outDir -# Log-Message "Successfully extracted $($zipFile.FullName) to $outDir" -# $success = $true -# } catch { -# $retryCount++ -# Log-Message "Failed to extract $($zipFile.FullName) on attempt $retryCount with error $_" -# Start-Sleep -Seconds 5 # Wait before retrying -# } -# } - -# if (-not $success) { -# throw "Failed to extract $($zipFile.FullName) after $maxRetries attempts" -# } -# } - -# # Check the extracted files -# Get-ChildItem -Path $outDir -Recurse - -# # Move the VHDs to the base directory -# $vhdFiles = @() -# $vhdFiles += Get-ChildItem -Path $outDir -Filter *.vhd -ErrorAction Ignore -# $vhdFiles += Get-ChildItem -Path $outDir -Filter *.vhdx -ErrorAction Ignore -# foreach ($vhdFile in $vhdFiles) { -# if (Test-Path -Path $vhdFile.FullName) { -# Move-Item -Path $vhdFile.FullName -Destination $BaseVhdDirPath -# } else { -# Log-Message "File not found: $($vhdFile.FullName)" -# throw "Failed to find extracted VHD file: $($vhdFile.FullName)" -# } -# } -# Log-Message "Successfully processed $($zipFile.FullName)" -# } - -# # Get the list of VHDs in the directory. -# $vhds = @() -# $vhds += Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhd -ErrorAction Ignore -# $vhds += Get-ChildItem -Path $BaseVhdDirPath -Filter *.vhdx -ErrorAction Ignore -# if ($vhds.Count -eq 0) { -# throw "No VHDs found in $BaseVhdDirPath" -# } -# Log-Message "Successfully processed VHDs" - -# return $vhds -# } - <# .SYNOPSIS Extracts .zip files in the specified directory and returns paths to .vhd and .vhdx files. @@ -420,7 +340,7 @@ function Create-VMSwitchIfNeeded { # Check to see if an external switch already exists $ExternalSwitches = (Get-VMSwitch -SwitchType External -ErrorAction Ignore) if ($ExternalSwitches -ne $null) { - Log-Message -Message "External switch already exists: $($ExternalSwitches[0].Name)" + Write-Log "External switch already exists: $($ExternalSwitches[0].Name)" return } @@ -433,24 +353,24 @@ function Create-VMSwitchIfNeeded { continue } $currSwitchName = $SwitchName + '-' + $index - Log-Message "Attempting to creating external switch: $currSwitchName with NetAdapter: $NetAdapterName" + Write-Log "Attempting to creating external switch: $currSwitchName with NetAdapter: $NetAdapterName" New-VMSwitch -Name $currSwitchName -NetAdapterName $NetAdapterName -AllowManagementOS $true $index += 1 } catch { - Log-Message "Failed to create external switch for NetAdapter: $NetAdapterName with error: $_" + Write-Log "Failed to create external switch for NetAdapter: $NetAdapterName with error: $_" } } } elseif ($SwitchType -eq 'Internal') { # Check to see if an internal switch already exists $InternalSwitches = (Get-VMSwitch -SwitchType Internal -Name $SwitchName -ErrorAction Ignore) if ($InternalSwitches -ne $null) { - Log-Message -Message "Internal switch already exists: $($InternalSwitches[0].Name)" + Write-Log "Internal switch already exists: $($InternalSwitches[0].Name)" return } # Try to create the internal switch try { - Log-Message "Creating internal switch" + Write-Log "Creating internal switch" New-VMSwitch -Name $SwitchName -SwitchType Internal } catch { throw "Failed to create internal switch with error: $_" @@ -459,5 +379,5 @@ function Create-VMSwitchIfNeeded { throw "Invalid switch type: $SwitchType" } - Log-Message "Successfully created $SwitchType switch with name: $SwitchName" -ForegroundColor Green + Write-Log "Successfully created $SwitchType switch with name: $SwitchName" -ForegroundColor Green } diff --git a/scripts/cleanup_ebpf_cicd_tests.ps1 b/scripts/cleanup_ebpf_cicd_tests.ps1 index d27d371b5a..3c6236cb9b 100644 --- a/scripts/cleanup_ebpf_cicd_tests.ps1 +++ b/scripts/cleanup_ebpf_cicd_tests.ps1 @@ -13,7 +13,9 @@ Push-Location $WorkingDirectory Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue if ($SelfHostedRunnerName -eq "1ESRunner") { - $TestVMCredential = Get-UserCredential -FilePath 'C:\work\Administrator.xml' + Get-PSExec + $psExecPath = "$pwd\PSExec64.exe" + $TestVMCredential = Retrieve-StoredCredential -Target $Target -PsExecPath $psExecPath } else { $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop } diff --git a/scripts/common.psm1 b/scripts/common.psm1 index e0b109eefe..261564d761 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -323,3 +323,237 @@ function Generate-NewCredential { if (Test-Path $errorFile) { Remove-Item $errorFile } } } + + +function Expand-ZipFile { + param( + [Parameter(Mandatory=$True)][string] $DownloadFilePath, + [Parameter(Mandatory=$True)][string] $OutputDir, + [Parameter(Mandatory=$True)][int] $maxRetries, + [Parameter(Mandatory=$True)][int] $retryDelay, + [Parameter(Mandatory=$True)][int] $timeout + ) + + for ($i = 0; $i -lt $maxRetries; $i++) { + try { + Write-Log "Extract attempt $($i + 1) started" + $job = Start-Job -ScriptBlock { + param ($DownloadFilePath, $OutputDir) + Expand-Archive -Path $DownloadFilePath -DestinationPath $OutputDir -Force + } -ArgumentList $DownloadFilePath, $OutputDir + + if (Wait-Job -Job $job -Timeout $timeout) { + Write-Log "Extraction completed" + Receive-Job -Job $job + break + } else { + Stop-Job -Job $job + Remove-Job -Job $job + Write-Log "Extract attempt $($i + 1) timed out after $timeout seconds." + if ($i -eq ($maxRetries - 1)) { + throw "Failed to extract $DownloadFilePath after $maxRetries attempts." + } else { + Write-Log "Retrying in $retryDelay seconds..." + Start-Sleep -Seconds $retryDelay + } + } + } catch { + Write-Log "Iteration $($i + 1) failed to extract $DownloadFilePath" -ForegroundColor Red + if ($i -eq ($maxRetries - 1)) { + throw "Failed to extract $DownloadFilePath after $maxRetries attempts." + } else { + Write-Log "Retrying in $retryDelay seconds..." + Start-Sleep -Seconds $retryDelay + } + } + } +} + +function Get-ZipFileFromUrl { + param( + [Parameter(Mandatory=$True)][string] $Url, + [Parameter(Mandatory=$True)][string] $DownloadFilePath, + [Parameter(Mandatory=$True)][string] $OutputDir + ) + $maxRetries = 5 + $retryDelay = 5 # seconds + $timeout = 300 # seconds + + Write-Log "Downloading $Url to $DownloadFilePath" + + for ($i = 0; $i -lt $maxRetries; $i++) { + try { + $response = Invoke-WebRequest -Uri $Url -UseBasicParsing -Method Head -TimeoutSec $timeout + if ($response.StatusCode -ne 200) { + throw "Failed to reach $Url HTTP status code: $($response.StatusCode)" + } + + Write-Log "Download attempt $($i + 1) started" + $ProgressPreference = 'SilentlyContinue' + + $job = Start-Job -ScriptBlock { + param ($Url, $DownloadFilePath, $timeout) + Invoke-WebRequest -Uri $Url -OutFile $DownloadFilePath -TimeoutSec $timeout + } -ArgumentList $Url, $DownloadFilePath, $timeout + + if (Wait-Job -Job $job -Timeout $timeout) { + Write-Log "Download completed" + Receive-Job -Job $job + + Write-Log "Extracting $DownloadFilePath to $OutputDir" + Expand-ZipFile -DownloadFilePath $DownloadFilePath -OutputDir $OutputDir -maxRetries $maxRetries -retryDelay $retryDelay -timeout $timeout + break + } else { + Stop-Job -Job $job + Remove-Job -Job $job + Write-Log "Download attempt $($i + 1) timed out after $timeout seconds." + if (Test-Path $DownloadFilePath) { + Remove-Item -Path $DownloadFilePath -Force + Write-Log "Removed partially downloaded file." + } + if ($i -eq ($maxRetries - 1)) { + throw "Failed to download $Url after $maxRetries attempts." + } else { + Write-Log "Retrying in $retryDelay seconds..." + Start-Sleep -Seconds $retryDelay + } + } + } catch { + Write-Log "Iteration $($i + 1) failed to download $Url. Removing $DownloadFilePath" -ForegroundColor Red + if (Test-Path $DownloadFilePath) { + Remove-Item -Path $DownloadFilePath -Force -ErrorAction Ignore + Write-Log "Removed partially downloaded file." + } + if ($i -eq ($maxRetries - 1)) { + throw "Failed to download $Url after $maxRetries attempts." + } else { + Write-Log "Retrying in $retryDelay seconds..." + Start-Sleep -Seconds $retryDelay + } + } + } +} + +function Get-LegacyRegressionTestArtifacts +{ + $ArifactVersionList = @("0.11.0") + $RegressionTestArtifactsPath = "$pwd\regression" + if (Test-Path -Path $RegressionTestArtifactsPath) { + Remove-Item -Path $RegressionTestArtifactsPath -Recurse -Force + } + mkdir $RegressionTestArtifactsPath + + # verify Artifacts' folder presense + if (-not (Test-Path -Path $RegressionTestArtifactsPath)) { + $ErrorMessage = "*** ERROR *** Regression test artifacts folder not found: $RegressionTestArtifactsPath)" + Write-Log $ErrorMessage + throw $ErrorMessage + } + + # Download regression test artifacts for each version. + foreach ($ArtifactVersion in $ArifactVersionList) + { + Write-Log "Downloading legacy regression test artifacts for version $ArtifactVersion" + $DownloadPath = "$RegressionTestArtifactsPath\$ArtifactVersion" + mkdir $DownloadPath + $ArtifactName = "v$ArtifactVersion/Build-x64-native-only-Release.$ArtifactVersion.zip" + $ArtifactUrl = "https://github.com/microsoft/ebpf-for-windows/releases/download/" + $ArtifactName + + for ($i = 0; $i -lt 5; $i++) { + try { + # Download and extract the artifact. + Get-ZipFileFromUrl -Url $ArtifactUrl -DownloadFilePath "$DownloadPath\artifact.zip" -OutputDir $DownloadPath + + # Extract the inner zip file. + Expand-Archive -Path "$DownloadPath\build-NativeOnlyRelease.zip" -DestinationPath $DownloadPath -Force + break + } catch { + Write-Log -TraceMessage "Iteration $i failed to download $ArtifactUrl. Removing $DownloadPath" -ForegroundColor Red + Remove-Item -Path $DownloadPath -Force -ErrorAction Ignore + Start-Sleep -Seconds 5 + } + } + + Move-Item -Path "$DownloadPath\NativeOnlyRelease\cgroup_sock_addr2.sys" -Destination "$RegressionTestArtifactsPath\cgroup_sock_addr2_$ArtifactVersion.sys" -Force + Remove-Item -Path $DownloadPath -Force -Recurse + } +} + +function Get-RegressionTestArtifacts +{ + param([Parameter(Mandatory=$True)][string] $Configuration, + [Parameter(Mandatory=$True)][string] $ArtifactVersion) + + $RegressionTestArtifactsPath = "$pwd\regression" + $OriginalPath = $pwd + if (Test-Path -Path $RegressionTestArtifactsPath) { + Remove-Item -Path $RegressionTestArtifactsPath -Recurse -Force + } + mkdir $RegressionTestArtifactsPath + + # Verify artifacts' folder presence + if (-not (Test-Path -Path $RegressionTestArtifactsPath)) { + $ErrorMessage = "*** ERROR *** Regression test artifacts folder not found: $RegressionTestArtifactsPath)" + Write-Log $ErrorMessage + throw $ErrorMessage + } + + # Download regression test artifacts for each version. + $DownloadPath = "$RegressionTestArtifactsPath" + $ArtifactName = "Release-v$ArtifactVersion/Build-x64.$Configuration.zip" + $ArtifactUrl = "https://github.com/microsoft/ebpf-for-windows/releases/download/" + $ArtifactName + + if (Test-Path -Path $DownloadPath\Build-x64.$Configuration) { + Remove-Item -Path $DownloadPath\Build-x64.$Configuration -Recurse -Force + } + + Get-ZipFileFromUrl -Url $ArtifactUrl -DownloadFilePath "$DownloadPath\Build-x64.$Configuration.zip" -OutputDir $DownloadPath + $DownloadedArtifactPath = "$DownloadPath\Build-x64 $Configuration" + if (!(Test-Path -Path $DownloadedArtifactPath)) { + throw ("Path ""$DownloadedArtifactPath"" not found.") + } + + # Copy all the drivers, DLLs, exe and .o files to pwd. + Write-Log "Copy regression test artifacts to main folder" -ForegroundColor Green + Push-Location $DownloadedArtifactPath + Get-ChildItem -Path .\* -Include *.sys | Move-Item -Destination $OriginalPath -Force + Get-ChildItem -Path .\* -Include *.dll | Move-Item -Destination $OriginalPath -Force + Get-ChildItem -Path .\* -Include *.exe | Move-Item -Destination $OriginalPath -Force + Get-ChildItem -Path .\* -Include *.o | Move-Item -Destination $OriginalPath -Force + Pop-Location + + Remove-Item -Path $DownloadPath -Force -Recurse + + # Delete ebpfapi.dll from the artifacts. ebpfapi.dll from the MSI installation should be used instead. + Remove-Item -Path ".\ebpfapi.dll" -Force +} + +# Copied from https://github.com/microsoft/msquic/blob/main/scripts/prepare-machine.ps1 +function Get-CoreNetTools { + # Download and extract https://github.com/microsoft/corenet-ci. + $DownloadPath = "$pwd\corenet-ci" + mkdir $DownloadPath + Write-Log "Downloading CoreNet-CI to $DownloadPath" + Get-ZipFileFromUrl -Url "https://github.com/microsoft/corenet-ci/archive/refs/heads/main.zip" -DownloadFilePath "$DownloadPath\corenet-ci.zip" -OutputDir $DownloadPath + #DuoNic. + Move-Item -Path "$DownloadPath\corenet-ci-main\vm-setup\duonic\*" -Destination $pwd -Force + # Procdump. + Move-Item -Path "$DownloadPath\corenet-ci-main\vm-setup\procdump64.exe" -Destination $pwd -Force + # NotMyFault. + Move-Item -Path "$DownloadPath\corenet-ci-main\vm-setup\notmyfault64.exe" -Destination $pwd -Force + Remove-Item -Path $DownloadPath -Force -Recurse +} + +# Download and extract PSExec to run tests as SYSTEM. +function Get-PSExec { + # Check to see if PSExec already exists + if (Test-Path -Path "$pwd\PsExec64.exe") { + return + } + $url = "https://download.sysinternals.com/files/PSTools.zip" + $DownloadPath = "$pwd\psexec" + + Get-ZipFileFromUrl -Url $url -DownloadFilePath "$pwd\pstools.zip" -OutputDir "$DownloadPath" + Move-Item -Path "$DownloadPath\PsExec64.exe" -Destination $pwd -Force + Remove-Item -Path $DownloadPath -Force -Recurse -ErrorAction Ignore +} diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index 34d43bf3e8..a18a78a503 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -547,239 +547,6 @@ function Initialize-NetworkInterfacesOnVMs } } -function Expand-ZipFile { - param( - [Parameter(Mandatory=$True)][string] $DownloadFilePath, - [Parameter(Mandatory=$True)][string] $OutputDir, - [Parameter(Mandatory=$True)][int] $maxRetries, - [Parameter(Mandatory=$True)][int] $retryDelay, - [Parameter(Mandatory=$True)][int] $timeout - ) - - for ($i = 0; $i -lt $maxRetries; $i++) { - try { - Write-Log "Extract attempt $($i + 1) started" - $job = Start-Job -ScriptBlock { - param ($DownloadFilePath, $OutputDir) - Expand-Archive -Path $DownloadFilePath -DestinationPath $OutputDir -Force - } -ArgumentList $DownloadFilePath, $OutputDir - - if (Wait-Job -Job $job -Timeout $timeout) { - Write-Log "Extraction completed" - Receive-Job -Job $job - break - } else { - Stop-Job -Job $job - Remove-Job -Job $job - Write-Log "Extract attempt $($i + 1) timed out after $timeout seconds." - if ($i -eq ($maxRetries - 1)) { - throw "Failed to extract $DownloadFilePath after $maxRetries attempts." - } else { - Write-Log "Retrying in $retryDelay seconds..." - Start-Sleep -Seconds $retryDelay - } - } - } catch { - Write-Log "Iteration $($i + 1) failed to extract $DownloadFilePath" -ForegroundColor Red - if ($i -eq ($maxRetries - 1)) { - throw "Failed to extract $DownloadFilePath after $maxRetries attempts." - } else { - Write-Log "Retrying in $retryDelay seconds..." - Start-Sleep -Seconds $retryDelay - } - } - } -} - -function Get-ZipFileFromUrl { - param( - [Parameter(Mandatory=$True)][string] $Url, - [Parameter(Mandatory=$True)][string] $DownloadFilePath, - [Parameter(Mandatory=$True)][string] $OutputDir - ) - $maxRetries = 5 - $retryDelay = 5 # seconds - $timeout = 300 # seconds - - Write-Log "Downloading $Url to $DownloadFilePath" - - for ($i = 0; $i -lt $maxRetries; $i++) { - try { - $response = Invoke-WebRequest -Uri $Url -UseBasicParsing -Method Head -TimeoutSec $timeout - if ($response.StatusCode -ne 200) { - throw "Failed to reach $Url HTTP status code: $($response.StatusCode)" - } - - Write-Log "Download attempt $($i + 1) started" - $ProgressPreference = 'SilentlyContinue' - - $job = Start-Job -ScriptBlock { - param ($Url, $DownloadFilePath, $timeout) - Invoke-WebRequest -Uri $Url -OutFile $DownloadFilePath -TimeoutSec $timeout - } -ArgumentList $Url, $DownloadFilePath, $timeout - - if (Wait-Job -Job $job -Timeout $timeout) { - Write-Log "Download completed" - Receive-Job -Job $job - - Write-Log "Extracting $DownloadFilePath to $OutputDir" - Expand-ZipFile -DownloadFilePath $DownloadFilePath -OutputDir $OutputDir -maxRetries $maxRetries -retryDelay $retryDelay -timeout $timeout - break - } else { - Stop-Job -Job $job - Remove-Job -Job $job - Write-Log "Download attempt $($i + 1) timed out after $timeout seconds." - if (Test-Path $DownloadFilePath) { - Remove-Item -Path $DownloadFilePath -Force - Write-Log "Removed partially downloaded file." - } - if ($i -eq ($maxRetries - 1)) { - throw "Failed to download $Url after $maxRetries attempts." - } else { - Write-Log "Retrying in $retryDelay seconds..." - Start-Sleep -Seconds $retryDelay - } - } - } catch { - Write-Log "Iteration $($i + 1) failed to download $Url. Removing $DownloadFilePath" -ForegroundColor Red - if (Test-Path $DownloadFilePath) { - Remove-Item -Path $DownloadFilePath -Force -ErrorAction Ignore - Write-Log "Removed partially downloaded file." - } - if ($i -eq ($maxRetries - 1)) { - throw "Failed to download $Url after $maxRetries attempts." - } else { - Write-Log "Retrying in $retryDelay seconds..." - Start-Sleep -Seconds $retryDelay - } - } - } -} - -function Get-LegacyRegressionTestArtifacts -{ - $ArifactVersionList = @("0.11.0") - $RegressionTestArtifactsPath = "$pwd\regression" - if (Test-Path -Path $RegressionTestArtifactsPath) { - Remove-Item -Path $RegressionTestArtifactsPath -Recurse -Force - } - mkdir $RegressionTestArtifactsPath - - # verify Artifacts' folder presense - if (-not (Test-Path -Path $RegressionTestArtifactsPath)) { - $ErrorMessage = "*** ERROR *** Regression test artifacts folder not found: $RegressionTestArtifactsPath)" - Write-Log $ErrorMessage - throw $ErrorMessage - } - - # Download regression test artifacts for each version. - foreach ($ArtifactVersion in $ArifactVersionList) - { - Write-Log "Downloading legacy regression test artifacts for version $ArtifactVersion" - $DownloadPath = "$RegressionTestArtifactsPath\$ArtifactVersion" - mkdir $DownloadPath - $ArtifactName = "v$ArtifactVersion/Build-x64-native-only-Release.$ArtifactVersion.zip" - $ArtifactUrl = "https://github.com/microsoft/ebpf-for-windows/releases/download/" + $ArtifactName - - for ($i = 0; $i -lt 5; $i++) { - try { - # Download and extract the artifact. - Get-ZipFileFromUrl -Url $ArtifactUrl -DownloadFilePath "$DownloadPath\artifact.zip" -OutputDir $DownloadPath - - # Extract the inner zip file. - Expand-Archive -Path "$DownloadPath\build-NativeOnlyRelease.zip" -DestinationPath $DownloadPath -Force - break - } catch { - Write-Log -TraceMessage "Iteration $i failed to download $ArtifactUrl. Removing $DownloadPath" -ForegroundColor Red - Remove-Item -Path $DownloadPath -Force -ErrorAction Ignore - Start-Sleep -Seconds 5 - } - } - - Move-Item -Path "$DownloadPath\NativeOnlyRelease\cgroup_sock_addr2.sys" -Destination "$RegressionTestArtifactsPath\cgroup_sock_addr2_$ArtifactVersion.sys" -Force - Remove-Item -Path $DownloadPath -Force -Recurse - } -} - -function Get-RegressionTestArtifacts -{ - param([Parameter(Mandatory=$True)][string] $Configuration, - [Parameter(Mandatory=$True)][string] $ArtifactVersion) - - $RegressionTestArtifactsPath = "$pwd\regression" - $OriginalPath = $pwd - if (Test-Path -Path $RegressionTestArtifactsPath) { - Remove-Item -Path $RegressionTestArtifactsPath -Recurse -Force - } - mkdir $RegressionTestArtifactsPath - - # Verify artifacts' folder presence - if (-not (Test-Path -Path $RegressionTestArtifactsPath)) { - $ErrorMessage = "*** ERROR *** Regression test artifacts folder not found: $RegressionTestArtifactsPath)" - Write-Log $ErrorMessage - throw $ErrorMessage - } - - # Download regression test artifacts for each version. - $DownloadPath = "$RegressionTestArtifactsPath" - $ArtifactName = "Release-v$ArtifactVersion/Build-x64.$Configuration.zip" - $ArtifactUrl = "https://github.com/microsoft/ebpf-for-windows/releases/download/" + $ArtifactName - - if (Test-Path -Path $DownloadPath\Build-x64.$Configuration) { - Remove-Item -Path $DownloadPath\Build-x64.$Configuration -Recurse -Force - } - - Get-ZipFileFromUrl -Url $ArtifactUrl -DownloadFilePath "$DownloadPath\Build-x64.$Configuration.zip" -OutputDir $DownloadPath - $DownloadedArtifactPath = "$DownloadPath\Build-x64 $Configuration" - if (!(Test-Path -Path $DownloadedArtifactPath)) { - throw ("Path ""$DownloadedArtifactPath"" not found.") - } - - # Copy all the drivers, DLLs, exe and .o files to pwd. - Write-Log "Copy regression test artifacts to main folder" -ForegroundColor Green - Push-Location $DownloadedArtifactPath - Get-ChildItem -Path .\* -Include *.sys | Move-Item -Destination $OriginalPath -Force - Get-ChildItem -Path .\* -Include *.dll | Move-Item -Destination $OriginalPath -Force - Get-ChildItem -Path .\* -Include *.exe | Move-Item -Destination $OriginalPath -Force - Get-ChildItem -Path .\* -Include *.o | Move-Item -Destination $OriginalPath -Force - Pop-Location - - Remove-Item -Path $DownloadPath -Force -Recurse - - # Delete ebpfapi.dll from the artifacts. ebpfapi.dll from the MSI installation should be used instead. - Remove-Item -Path ".\ebpfapi.dll" -Force -} - -# Copied from https://github.com/microsoft/msquic/blob/main/scripts/prepare-machine.ps1 -function Get-CoreNetTools { - # Download and extract https://github.com/microsoft/corenet-ci. - $DownloadPath = "$pwd\corenet-ci" - mkdir $DownloadPath - Write-Log "Downloading CoreNet-CI to $DownloadPath" - Get-ZipFileFromUrl -Url "https://github.com/microsoft/corenet-ci/archive/refs/heads/main.zip" -DownloadFilePath "$DownloadPath\corenet-ci.zip" -OutputDir $DownloadPath - #DuoNic. - Move-Item -Path "$DownloadPath\corenet-ci-main\vm-setup\duonic\*" -Destination $pwd -Force - # Procdump. - Move-Item -Path "$DownloadPath\corenet-ci-main\vm-setup\procdump64.exe" -Destination $pwd -Force - # NotMyFault. - Move-Item -Path "$DownloadPath\corenet-ci-main\vm-setup\notmyfault64.exe" -Destination $pwd -Force - Remove-Item -Path $DownloadPath -Force -Recurse -} - -# Download and extract PSExec to run tests as SYSTEM. -function Get-PSExec { - # Check to see if PSExec already exists - if (Test-Path -Path "$pwd\PsExec64.exe") { - return - } - $url = "https://download.sysinternals.com/files/PSTools.zip" - $DownloadPath = "$pwd\psexec" - - Get-ZipFileFromUrl -Url $url -DownloadFilePath "$pwd\pstools.zip" -OutputDir "$DownloadPath" - Move-Item -Path "$DownloadPath\PsExec64.exe" -Destination $pwd -Force - Remove-Item -Path $DownloadPath -Force -Recurse -ErrorAction Ignore -} - # # Queries registry for OS build information and logs it. # diff --git a/scripts/execute_ebpf_cicd_tests.ps1 b/scripts/execute_ebpf_cicd_tests.ps1 index 67a3279099..619e85f7de 100644 --- a/scripts/execute_ebpf_cicd_tests.ps1 +++ b/scripts/execute_ebpf_cicd_tests.ps1 @@ -18,8 +18,10 @@ Push-Location $WorkingDirectory Import-Module $WorkingDirectory\common.psm1 -Force -ArgumentList ($LogFileName) -ErrorAction Stop if ($SelfHostedRunnerName -eq "1ESRunner") { - $AdminTestVMCredential = Get-UserCredential -FilePath 'C:\work\Administrator.xml' - $AdminTestVMCredential = Get-UserCredential -FilePath 'C:\work\VMStandardUser.xml' + Get-PSExec + $psExecPath = "$pwd\PSExec64.exe" + $TestVMCredential = Retrieve-StoredCredential -Target $Target -PsExecPath $psExecPath + $StandardUserTestVMCredential = Retrieve-StoredCredential -Target $StandardUserTarget -PsExecPath $psExecPath } else { $AdminTestVMCredential = Get-StoredCredential -Target $AdminTarget -ErrorAction Stop $StandardUserTestVMCredential = Get-StoredCredential -Target $StandardUserTarget -ErrorAction Stop diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index 7e71065b06..4585f7b205 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -20,7 +20,9 @@ Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction S if ($SelfHostedRunnerName -eq "1ESRunner") { Write-Log "Fetching the test VM credential using target: $Target" - $TestVMCredential = Retrieve-StoredCredential -Target $Target + Get-PSExec + $psExecPath = "$pwd\PSExec64.exe" + $TestVMCredential = Retrieve-StoredCredential -Target $Target -PsExecPath $psExecPath if ($null -eq $TestVMCredential) { ThrowWithErrorMessage "Failed to retrieve the test VM credential." } From 2cf8e905025de187494274db8702e0584d45f5c5 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 24 Jan 2025 12:19:09 -0800 Subject: [PATCH 154/190] WFIP --- scripts/common.psm1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/common.psm1 b/scripts/common.psm1 index 261564d761..6287ccf19f 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -252,9 +252,11 @@ function Retrieve-StoredCredential { throw "PsExec failed with exit code $($process.ExitCode). Error: $error" } + Write-Host "Output: $output" $lines = $output -split "`n" $Username = $lines[0].Trim() $Password = ConvertTo-SecureString -String $lines[1].Trim() -AsPlainText -Force + Write-Host "Username: $Username Password: $Password" return [System.Management.Automation.PSCredential]::new($Username, $Password) } catch { throw "An error occurred while retrieving the credential: $_" From f4cdaf85eaccabedbd8330e1530e26437034bbe6 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 24 Jan 2025 12:57:57 -0800 Subject: [PATCH 155/190] make cred persistent --- scripts/common.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/common.psm1 b/scripts/common.psm1 index 6287ccf19f..87db542aec 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -301,7 +301,7 @@ function Generate-NewCredential { Write-Host "Password: $Password" $Script = @" Import-Module CredentialManager -ErrorAction Stop; - New-StoredCredential -Target '$Target' -UserName '$Username' -Password '$Password'; + New-StoredCredential -Target '$Target' -UserName '$Username' -Password '$Password' -Persist LocalMachine; "@ $outputFile = [System.IO.Path]::GetTempFileName() From 5d389da0b70d28796dfc7894718600de7846667b Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 24 Jan 2025 13:56:13 -0800 Subject: [PATCH 156/190] fix --- scripts/setup_ebpf_cicd_tests.ps1 | 7 ------- 1 file changed, 7 deletions(-) diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index 4585f7b205..6c5d561e00 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -72,10 +72,8 @@ $Job = Start-Job -ScriptBlock { [parameter(Mandatory = $true)] [bool] $KmTracing, [parameter(Mandatory = $true)] [string] $KmTraceType ) - Write-Log "Starting the setup job." Push-Location $WorkingDirectory - Write-Log "Importing modules." # Load other utility modules. Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue Import-Module .\config_test_vm.psm1 -Force -ArgumentList ($TestVMCredential.UserName, $TestVMCredential.Password, $WorkingDirectory, $LogFileName) -WarningAction SilentlyContinue @@ -83,28 +81,23 @@ $Job = Start-Job -ScriptBlock { $VMList = $Config.VMMap.$SelfHostedRunnerName # Get all VMs to ready state. - Write-Log "Initializing all VMs." Initialize-AllVMs -VMList $VMList -ErrorAction Stop # Export build artifacts to the test VMs. - Write-Log "Exporting build artifacts to VM" Export-BuildArtifactsToVMs -VMList $VMList -ErrorAction Stop # Configure network adapters on VMs. - Write-Log "Configuring network interfaces on VMs." Initialize-NetworkInterfacesOnVMs $VMList -ErrorAction Stop # Install eBPF Components on the test VM. foreach($VM in $VMList) { $VMName = $VM.Name - Write-Log "Installing eBPF components on VM: $VMName" Install-eBPFComponentsOnVM -VMName $VMname -TestMode $TestMode -KmTracing $KmTracing -KmTraceType $KmTraceType -ErrorAction Stop } # Log OS build information on the test VM. foreach($VM in $VMList) { $VMName = $VM.Name - Write-Log "Logging OS build information on VM: $VMName" Log-OSBuildInformationOnVM -VMName $VMName -ErrorAction Stop } From 0077a2c61f1e23a1a19dfba60fb2531a8fd52963 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 24 Jan 2025 14:27:38 -0800 Subject: [PATCH 157/190] fix test execution --- scripts/execute_ebpf_cicd_tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/execute_ebpf_cicd_tests.ps1 b/scripts/execute_ebpf_cicd_tests.ps1 index 619e85f7de..dfb5cff1cd 100644 --- a/scripts/execute_ebpf_cicd_tests.ps1 +++ b/scripts/execute_ebpf_cicd_tests.ps1 @@ -20,7 +20,7 @@ Import-Module $WorkingDirectory\common.psm1 -Force -ArgumentList ($LogFileName) if ($SelfHostedRunnerName -eq "1ESRunner") { Get-PSExec $psExecPath = "$pwd\PSExec64.exe" - $TestVMCredential = Retrieve-StoredCredential -Target $Target -PsExecPath $psExecPath + $TestVMCredential = Retrieve-StoredCredential -Target $AdminTarget -PsExecPath $psExecPath $StandardUserTestVMCredential = Retrieve-StoredCredential -Target $StandardUserTarget -PsExecPath $psExecPath } else { $AdminTestVMCredential = Get-StoredCredential -Target $AdminTarget -ErrorAction Stop From f1dd866fbff7a091564b8f962e90c3b8b2aa42f6 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 24 Jan 2025 15:35:39 -0800 Subject: [PATCH 158/190] refactoring --- .github/workflows/reusable-build.yml | 10 + 1es/Setup.ps1 | 50 +--- 1es/artifacts.json | 2 +- 1es/prepare_vm_helpers.psm1 | 383 --------------------------- scripts/cleanup_ebpf_cicd_tests.ps1 | 4 +- scripts/common.psm1 | 27 +- scripts/config_test_vm.psm1 | 316 +++++++++++++++++++++- scripts/execute_ebpf_cicd_tests.ps1 | 13 +- scripts/setup_ebpf_cicd_tests.ps1 | 4 +- 9 files changed, 356 insertions(+), 453 deletions(-) delete mode 100644 1es/prepare_vm_helpers.psm1 diff --git a/.github/workflows/reusable-build.yml b/.github/workflows/reusable-build.yml index d34ec441e4..35c2668038 100644 --- a/.github/workflows/reusable-build.yml +++ b/.github/workflows/reusable-build.yml @@ -304,3 +304,13 @@ jobs: - name: Perform CodeQL Analysis if: inputs.build_codeql == true && steps.skip_check.outputs.should_skip != 'true' uses: github/codeql-action/analyze@b6a472f63d85b9c78a3ac5e89422239fc15e9b3c + + - name: Upload 1ES artifacts + if: steps.skip_check.outputs.should_skip != 'true' && (inputs.build_artifact == 'Build-x64' && matrix.configurations == 'Release') + uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 + with: + name: ebpf-for-windows - 1ES artifacts (${{inputs.build_artifact}}_${{env.BUILD_CONFIGURATION}}) + path: | + 1es/** + scripts/common.psm1 + scripts/config_test_vm.psm1 diff --git a/1es/Setup.ps1 b/1es/Setup.ps1 index f639139f0b..70831aad52 100644 --- a/1es/Setup.ps1 +++ b/1es/Setup.ps1 @@ -36,47 +36,16 @@ param( $ErrorActionPreference = "Stop" -# Input validation for input paths -if (-not (Test-Path -Path $BaseUnattendPath)) { - throw "Unattend file not found at $BaseUnattendPath" -} - -if (-not (Test-Path -Path $BaseVhdDirPath)) { - throw "VHD directory not found at $BaseVhdDirPath" -} - # Import helper functions $logFileName = 'Setup.log' Import-Module .\common.psm1 -Force -ArgumentList ($logFileName) -WarningAction SilentlyContinue -$adminPassword = New-UniquePassword -$adminSecureString = ConvertTo-SecureString -String $adminPassword -AsPlainText -Force -$standardUserPassword = New-UniquePassword -Import-Module .\prepare_vm_helpers.psm1 -Force -WarningAction SilentlyContinue -Import-Module .\config_test_vm.psm1 -Force -ArgumentList('Administrator', $adminSecureString, 'C:\work', $logFileName) -WarningAction SilentlyContinue - -Get-PSExec -if (-not (Test-Path -Path "$pwd\PSExec64.exe")) { - throw "PSExec64.exe not found in the current directory." -} -$psExecPath = "$pwd\PSExec64.exe" - +$password = New-UniquePassword +$passwordSecureString = ConvertTo-SecureString -String $adminPassword -AsPlainText -Force +Import-Module .\config_test_vm.psm1 -Force -ArgumentList('Administrator', $passwordSecureString, 'C:\work', $logFileName) -WarningAction SilentlyContinue # Create new credentials for the VM. -$AdminUserCredential = Generate-NewCredential -Username 'Administrator' -Password $adminPassword -Target 'TEST_VM' -PsExecPath $psExecPath -$StandardUserCredential = Generate-NewCredential -Username 'VMStandardUser' -Password $standardUserPassword -Target 'TEST_VM_STANDARD' -PsExecPath $psExecPath - -# TODO - remove this debugging output. -if ($AdminUserCredential -eq $null) { - throw "Failed to retrieve the Administrator credential." -} else { - Write-Log "Sucessfully retrieved the Administrator credential." -} - -if ($StandardUserCredential -eq $null) { - throw "Failed to retrieve the VMStandardUser credential." -} else { - Write-Log "Sucessfully retrieved the VMStandardUser credential." -} +$AdminUserCredential = Generate-NewCredential -Username 'Administrator' -Password $password -Target 'TEST_VM' +$StandardUserCredential = Generate-NewCredential -Username 'VMStandardUser' -Password $password -Target 'TEST_VM_STANDARD' # Create working directory used for VM creation. Create-DirectoryIfNotExists -Path $WorkingPath @@ -87,9 +56,7 @@ Create-VMSwitchIfNeeded -SwitchName $VMSwitchName -SwitchType 'Internal' # Unzip any VHD files, if needed, and get the list of VHDs to create VMs from. $vhds = Prepare-VhdFiles -InputDirectory $BaseVhdDirPath -Write-Log "Found $($vhds.Count) VHDs to create VMs from." $vhdDebugString = $vhds | Out-String -Write-Log "VHDs: $vhdDebugString" # Process VM creation and setup. foreach ($vhd in $vhds) { @@ -103,17 +70,16 @@ foreach ($vhd in $vhds) { Create-VM ` -VmName $vmName ` - -AdminUserCredential $AdminUserCredential ` - -StandardUserCredential $StandardUserCredential ` + -UserPassword $password ` -VhdPath $vhd ` -VmStoragePath $outVMPath ` -VMMemory $VMMemory ` -UnattendPath $BaseUnattendPath ` -VMSwitchName $VMSwitchName - Configure-VM ` + Initialize-VM ` -VmName $vmName ` - -VmCredential $AdminUserCredential ` + -UserPassword $password ` -VMCpuCount $VMCpuCount Write-Log "VM $vmName created successfully" diff --git a/1es/artifacts.json b/1es/artifacts.json index 1f4f55c542..b2639d688b 100644 --- a/1es/artifacts.json +++ b/1es/artifacts.json @@ -20,7 +20,7 @@ "Name": "windows-azcopy-downloadfile-msi", "Parameters": { - "BlobUri": "https://ebpfcicdstorage.blob.core.windows.net/server-2019/*", + "BlobUri": "https://ebpfcicdstorage.blob.core.windows.net/server-2025/*", "Destination": "C:\\work", "Identity": "/subscriptions/15cd5cd8-c222-405e-bb37-c5c6712a075f/resourceGroups/ebpf-cicd-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/ebpf-cicd-identity" } diff --git a/1es/prepare_vm_helpers.psm1 b/1es/prepare_vm_helpers.psm1 deleted file mode 100644 index 4686e48c9e..0000000000 --- a/1es/prepare_vm_helpers.psm1 +++ /dev/null @@ -1,383 +0,0 @@ -# Copyright (c) eBPF for Windows contributors -# SPDX-License-Identifier: MIT -$ErrorActionPreference = "Stop" - -<# -.SYNOPSIS - Helper function to execute a command on a VM. - -.DESCRIPTION - This function executes a command on a specified VM using the provided credentials. - -.PARAMETER VMName - The name of the VM to execute the command on. - -.PARAMETER VmCredential - The credentials to use for executing the command on the VM. - -.PARAMETER Command - The command to execute on the VM. -#> -function Execute-CommandOnVM { - param ( - [Parameter(Mandatory=$True)][string]$VMName, - [Parameter(Mandatory=$True)][System.Management.Automation.PSCredential]$VmCredential, - [Parameter(Mandatory=$True)][string]$Command - ) - - try { - Write-Log "Executing command on VM: $VMName. Command: $Command" - $result = Invoke-Command -VMName $VMName -Credential $VmCredential -ScriptBlock { - param($Command) - Invoke-Expression $Command - } -ArgumentList $Command - Write-Log "Successfully executed command on VM: $VMName. Command: $Command. Result: $result" - } catch { - throw "Failed to execute command on VM: $VMName with error: $_" - } -} - -<# -.SYNOPSIS - Helper function to wait for a VM to be ready. - -.DESCRIPTION - This function waits for a VM to be in the 'Running' state and then connects to it using a simple command. - -.PARAMETER VMName - The name of the VM to wait for. - -.PARAMETER VmCredential - The credentials to use for connecting to the VM. - -.PARAMETER TimeoutInMinutes - The maximum time to wait for the VM to be ready, in minutes. Defaults to 30 minutes. - -.EXAMPLE - Wait-ForVMReady -VMName "MyVM" -VmCredential $myCredential -TimeoutInMinutes 20 -#> -function Wait-ForVMReady { - param ( - [Parameter(Mandatory=$True)][string]$VMName, - [Parameter(Mandatory=$True)][System.Management.Automation.PSCredential]$VmCredential, - [Parameter(Mandatory=$False)][int]$TimeoutInMinutes=30 - ) - - # Attempt for a maximum of 30 minutes - $limit = (Get-Date).AddMinutes($TimeoutInMinutes) - while ((Get-Date) -le $limit) { - try { - # Ensure the VM is in running state - while ((Get-VM -Name $VMName).State -ne 'Running') { - Write-Log "Waiting for $VMName to reach running state..." - Start-Sleep -Seconds 5 - } - - # Trivial command to ensure that we can connect to the VM. - try { - Execute-CommandOnVM -VMName $VMName -VmCredential $VmCredential -Command 'hostname' - } catch { - Write-Log "Failed to connect to $VMName. Retrying..." - Start-Sleep -Seconds 5 - continue - } - - Write-Log "Successfully connected to $VMName" - return - } catch { - # Do nothing. We will retry if we failed to connect to the VM. - } - - Write-Log "Failed to connect to $VMName. Retrying..." - Start-Sleep -Seconds 5 - } - - # If we reached here, we failed to connect to the VM. - throw "Failed to connect to $VMName after timeout..." -} - -<# -.SYNOPSIS - Helper function to create a VM. - -.DESCRIPTION - This function creates a new VM with the specified parameters. - -.PARAMETER VmName - The name of the VM to create. - -.PARAMETER AdminUserCredential - The credentials for the admin user to use for the VM. - -.PARAMETER StandardUserCredential - The credentials for the standard user to use for the VM. - -.PARAMETER VhdPath - The path to the VHD file to use for the VM. - -.PARAMETER VmStoragePath - The storage path for the VM. - -.PARAMETER VMMemory - The amount of memory to allocate for the VM. - -.PARAMETER UnattendPath - The path to the unattend file to use for the VM. This will notably be used for configuring the user accounts and passwords. - -.PARAMETER VmSwitchName - The name of the switch to use for the VM. - -.EXAMPLE - Create-VM -VmName "MyVM" -AdminUserCredential $adminCredential -StandardUserCredential $userCredential -VhdPath "C:\MyVHD.vhd" -VmStoragePath "C:\VMStorage" -VMMemory 2GB -UnattendPath "C:\MyUnattend.xml" -VmSwitchName "VMInternalSwitch" -#> -function Create-VM { - param( - [Parameter(Mandatory=$True)][string]$VmName, - [Parameter(Mandatory=$True)][PSCredential]$AdminUserCredential, - [Parameter(Mandatory=$True)][PSCredential]$StandardUserCredential, - [Parameter(Mandatory=$True)][string]$VhdPath, - [Parameter(Mandatory=$True)][string]$VmStoragePath, - [Parameter(Mandatory=$True)][Int64]$VMMemory, - [Parameter(Mandatory=$True)][string]$UnattendPath, - [Parameter(Mandatory=$True)][string]$VmSwitchName - ) - - try { - ## Check for any pre-requisites - # Check that the VHD exists - if (-not (Test-Path -Path $VhdPath)) { - throw "VHD not found at $VhdPath" - } - - ## Create the VM - # Create storage directory for the VM - Create-DirectoryIfNotExists -Path $VmStoragePath - - # Move the VHD to the path - Write-Log "Moving $VhdPath to $VmStoragePath" - Move-Item -Path $VhdPath -Destination $VmStoragePath -Force - $VmVhdPath = Join-Path -Path $VmStoragePath -ChildPath (Split-Path -Path $VhdPath -Leaf) - - # Move unattend to the path and replace placeholder strings - Write-Log "Moving $UnattendPath file to $VmStoragePath" - Move-Item -Path $UnattendPath -Destination $VmStoragePath -Force - $VmUnattendPath = Join-Path -Path $VmStoragePath -ChildPath (Split-Path -Path $UnattendPath -Leaf) - Replace-PlaceholderStrings -FilePath $VmUnattendPath -SearchString 'PLACEHOLDER_ADMIN_PASSWORD' -ReplaceString $AdminUserCredential.GetNetworkCredential().Password - Replace-PlaceholderStrings -FilePath $VmUnattendPath -SearchString 'PLACEHOLDER_STANDARDUSER_PASSWORD' -ReplaceString $StandardUserCredential.GetNetworkCredential().Password - - # Configure the VHD with the unattend file. - Write-Log "Mounting VHD and applying unattend file" - $VmMountPath = Join-Path -Path $VmStoragePath -ChildPath 'mountedVhd' - if (-not (Test-Path -Path $VmMountPath)) { - New-Item -ItemType Directory -Path $VmMountPath - } - Mount-WindowsImage -ImagePath $VmVhdPath -Index 1 -Path $VmMountPath -ErrorAction Stop | Out-Null - Copy-Item -Path $VmUnattendPath -Destination $VmMountPath\Unattend.xml - Apply-WindowsUnattend -Path $VmMountPath -UnattendPath $VmMountPath\Unattend.xml -ErrorAction Stop | Out-Null - Dismount-WindowsImage -Path $VmMountPath -Save -ErrorAction Stop - - # Create the VM - Write-Log "Creating the VM" - New-VM -Name $VmName -VhdPath $VmVhdPath -SwitchName $VmSwitchName - Set-VMMemory -VMName $VmName -DynamicMemoryEnabled $false -StartupBytes $VMMemory - - if ((Get-VM -VMName $vmName) -eq $null) { - throw "Failed to create VM: $VMName" - } - - Write-Log "Successfully created VM: $VMName" -ForegroundColor Green - } catch { - throw "Failed to create VM: $VmName with error: $_" - } -} - -<# -.SYNOPSIS - Helper function to configure a VM after creation. - -.DESCRIPTION - This function configures a VM after it has been created, including setting the processor count, enabling the Guest Service Interface, and executing a setup script. - -.PARAMETER VmName - The name of the VM to configure. - -.PARAMETER VmCredential - The credentials to use for connecting to the VM. - -.PARAMETER VMCpuCount - The number of processors to allocate for the VM. - -.PARAMETER VMWorkingDirectory - The working directory on the VM to use for executing the setup script. Defaults to 'C:\ebpf_cicd'. - -.PARAMETER VMSetupScript - The path to the setup script to execute on the VM. Defaults to '.\configure_vm.ps1'. - -.EXAMPLE - Configure-VM -VmName "MyVM" -VmCredential $myCredential -VMCpuCount 4 -#> -function Configure-VM { - param( - [Parameter(Mandatory=$True)][string]$VmName, - [Parameter(Mandatory=$True)][PSCredential]$VmCredential, - [Parameter(Mandatory=$True)][int]$VMCpuCount, - [Parameter(Mandatory=$False)][string]$VMWorkingDirectory='C:\ebpf_cicd', - [Parameter(Mandatory=$False)][string]$VMSetupScript='.\configure_vm.ps1' - ) - - try { - Write-Log "Configuring VM: $VmName" - - # Post VM creation configuration steps. - Write-Log "Setting VM processor count to $VMCpuCount" - Set-VMProcessor -VMName $VmName -Count $VMCpuCount - Write-Log "Enabling Guest Service Interface" - Enable-VMIntegrationService -VMName $VMName -Name 'Guest Service Interface' - - # Start the VM - Write-Log "Starting VM: $VmName" - Start-VM -Name $VmName - Wait-ForVMReady -VMName $VmName -VmCredential $VmCredential - - Write-Log "Sleeping for 1 minute to let the VM get into a steady state" - Sleep -Seconds 60 - - # Copy setup script to the VM and execute it. - Write-Log "Executing VM configuration script ($VMSetupScript) on VM: $VmName" - Copy-VMFile -VMName $VmName -FileSource Host -SourcePath $VMSetupScript -DestinationPath "$VMWorkingDirectory\$VMSetupScript" -CreateFullPath - Execute-CommandOnVM -VMName $VmName -VmCredential $VmCredential -Command "cd $VMWorkingDirectory; .\$VMSetupScript" - Write-Log "Sleeping for 1 minute to let the VM get into a steady state" - Sleep -Seconds 60 # Sleep for 1 minute to let the VM get into a steady state. - Write-Log "Successfully executed VM configuration script ($VMSetupScript) on VM: $VmName" -ForegroundColor Green - - Wait-ForVMReady -VMName $VmName -VmCredential $VmCredential - - # Checkpoint the VM. This can sometimes fail if other operations are in progress. - for ($i = 0; $i -lt 5; $i += 1) { - try { - Write-Log "Checkpointing VM: $VmName" - Checkpoint-VM -Name $VMName -SnapshotName 'baseline' - Write-Log "Successfully added 'baseline' checkpoint for VM: $VMName" -ForegroundColor Green - break - } catch { - Write-Log "Failed to checkpoint VM: $VmName. Retrying..." - Start-Sleep -Seconds 5 - continue - } - } - - Write-Log "Successfully configured VM: $VmName" -ForegroundColor Green - } catch { - throw "Failed to configure VM: $VmName with error: $_" - } -} - -########## Helpers for the host machine ########## -<# -.SYNOPSIS - Extracts .zip files in the specified directory and returns paths to .vhd and .vhdx files. - -.DESCRIPTION - This function takes an input directory as a parameter, looks inside the directory for any .zip files, extracts them, and returns a PowerShell string array of all full paths to .vhd and .vhdx files. It suppresses any output and throws errors if any exceptions are found. - -.PARAMETER InputDirectory - The directory to search for .zip files and extract them. - -.EXAMPLE - $vhdFiles = Prepare-VhdFiles -InputDirectory "C:\MyDirectory" -#> -function Prepare-VhdFiles { - param ( - [Parameter(Mandatory=$true)] - [string]$InputDirectory - ) - - try { - $zipFiles = Get-ChildItem -Path $InputDirectory -Filter *.zip -Recurse - foreach ($zipFile in $zipFiles) { - Expand-Archive -Path $zipFile.FullName -DestinationPath $InputDirectory *> $null 2>&1 - } - - # Get all .vhd and .vhdx files - $vhdFiles = (Get-ChildItem -Path $InputDirectory -Recurse -Include *.vhd, *.vhdx) | Select-Object -ExpandProperty FullName - - if ($vhdFiles.Count -eq 0) { - throw "No VHD files found in $InputDirectory" - } - - return [string[]]$vhdFiles - } - catch { - Get-ChildItem -Path $InputDirectory -Recurse - throw "Failed to prepare VHD files with error: $_" - } -} - -<# -.SYNOPSIS - Helper function to create a VM switch if it does not already exist. - -.DESCRIPTION - Checks if a VM switch with the given name and type already exists. If not, it creates a new switch of the specified type. - -.PARAMETER SwitchName - The name of the switch to create. - -.PARAMETER SwitchType - The type of switch to create. Can be 'External' or 'Internal'. - -.EXAMPLE - Create-VMSwitchIfNeeded -SwitchName 'VMInternalSwitch' -SwitchType 'Internal' - Create-VMSwitchIfNeeded -SwitchName 'VMExternalSwitch' -SwitchType 'External' -#> -function Create-VMSwitchIfNeeded { - param ( - [Parameter(Mandatory=$true)][string]$SwitchName, - [Parameter(Mandatory=$true)][string]$SwitchType - ) - - if ($SwitchType -eq 'External') { - # Check to see if an external switch already exists - $ExternalSwitches = (Get-VMSwitch -SwitchType External -ErrorAction Ignore) - if ($ExternalSwitches -ne $null) { - Write-Log "External switch already exists: $($ExternalSwitches[0].Name)" - return - } - - # Try to create the external switch - $NetAdapterNames = (Get-NetAdapter -Name 'Ethernet*' | Where-Object { $_.Status -eq 'Up' }).Name - $index = 0 - foreach ($NetAdapterName in $NetAdapterNames) { - try { - if ([string]::IsNullOrEmpty($NetAdapterName)) { - continue - } - $currSwitchName = $SwitchName + '-' + $index - Write-Log "Attempting to creating external switch: $currSwitchName with NetAdapter: $NetAdapterName" - New-VMSwitch -Name $currSwitchName -NetAdapterName $NetAdapterName -AllowManagementOS $true - $index += 1 - } catch { - Write-Log "Failed to create external switch for NetAdapter: $NetAdapterName with error: $_" - } - } - } elseif ($SwitchType -eq 'Internal') { - # Check to see if an internal switch already exists - $InternalSwitches = (Get-VMSwitch -SwitchType Internal -Name $SwitchName -ErrorAction Ignore) - if ($InternalSwitches -ne $null) { - Write-Log "Internal switch already exists: $($InternalSwitches[0].Name)" - return - } - - # Try to create the internal switch - try { - Write-Log "Creating internal switch" - New-VMSwitch -Name $SwitchName -SwitchType Internal - } catch { - throw "Failed to create internal switch with error: $_" - } - } else { - throw "Invalid switch type: $SwitchType" - } - - Write-Log "Successfully created $SwitchType switch with name: $SwitchName" -ForegroundColor Green -} diff --git a/scripts/cleanup_ebpf_cicd_tests.ps1 b/scripts/cleanup_ebpf_cicd_tests.ps1 index 3c6236cb9b..520f154bab 100644 --- a/scripts/cleanup_ebpf_cicd_tests.ps1 +++ b/scripts/cleanup_ebpf_cicd_tests.ps1 @@ -13,9 +13,7 @@ Push-Location $WorkingDirectory Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue if ($SelfHostedRunnerName -eq "1ESRunner") { - Get-PSExec - $psExecPath = "$pwd\PSExec64.exe" - $TestVMCredential = Retrieve-StoredCredential -Target $Target -PsExecPath $psExecPath + $TestVMCredential = Retrieve-StoredCredential -Target $Target } else { $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop } diff --git a/scripts/common.psm1 b/scripts/common.psm1 index 87db542aec..75ba88f3f5 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -215,9 +215,6 @@ function New-UniquePassword { .SYNOPSIS Retrieves a credential from the Windows Credential Manager using PsExec. -.PARAMETER PsExecPath - The path to the PsExec executable. - .PARAMETER Target The name of the stored credential. Default is "MyStoredCredential". @@ -225,13 +222,15 @@ function New-UniquePassword { This function uses PsExec to run a PowerShell script in the LocalSystem account context to retrieve a credential from the Windows Credential Manager. .EXAMPLE - $credential = Retrieve-StoredCredential -PsExecPath "C:\Path\To\PsExec.exe" -Target "MyStoredCredential" + $credential = Retrieve-StoredCredential -Target "MyStoredCredential" #> function Retrieve-StoredCredential { param ( - [Parameter(Mandatory=$True)][string]$PsExecPath, [Parameter(Mandatory=$True)][string]$Target ) + + $PSExecPath = Get-PSExec + $Script = @" Import-Module CredentialManager -ErrorAction Stop; `$Credential = Get-StoredCredential -Target '$Target'; @@ -252,11 +251,9 @@ function Retrieve-StoredCredential { throw "PsExec failed with exit code $($process.ExitCode). Error: $error" } - Write-Host "Output: $output" $lines = $output -split "`n" $Username = $lines[0].Trim() $Password = ConvertTo-SecureString -String $lines[1].Trim() -AsPlainText -Force - Write-Host "Username: $Username Password: $Password" return [System.Management.Automation.PSCredential]::new($Username, $Password) } catch { throw "An error occurred while retrieving the credential: $_" @@ -270,9 +267,6 @@ function Retrieve-StoredCredential { .SYNOPSIS Stores a credential in the Windows Credential Manager using PsExec. -.PARAMETER PsExecPath - The path to the PsExec executable. - .PARAMETER Username The username for the credential. @@ -287,18 +281,17 @@ function Retrieve-StoredCredential { .EXAMPLE $securePassword = ConvertTo-SecureString "YourPassword" -AsPlainText -Force - $credential = Generate-NewCredential -Username "YourUsername" -Password $securePassword -Target "MyStoredCredential" -PsExecPath "C:\Path\To\PsExec.exe" + $credential = Generate-NewCredential -Username "YourUsername" -Password $securePassword -Target "MyStoredCredential" #> function Generate-NewCredential { param ( [Parameter(Mandatory=$True)][string]$Username, [Parameter(Mandatory=$True)][string]$Password, - [Parameter(Mandatory=$True)][string]$Target, - [Parameter(Mandatory=$True)][string]$PsExecPath + [Parameter(Mandatory=$True)][string]$Target ) Get-CredentialManager + $PSExecPath = Get-PSExec - Write-Host "Password: $Password" $Script = @" Import-Module CredentialManager -ErrorAction Stop; New-StoredCredential -Target '$Target' -UserName '$Username' -Password '$Password' -Persist LocalMachine; @@ -548,9 +541,10 @@ function Get-CoreNetTools { # Download and extract PSExec to run tests as SYSTEM. function Get-PSExec { + $psExecPath = "$pwd\PsExec64.exe" # Check to see if PSExec already exists - if (Test-Path -Path "$pwd\PsExec64.exe") { - return + if (Test-Path -Path $psExecPath) { + return $psExecPath } $url = "https://download.sysinternals.com/files/PSTools.zip" $DownloadPath = "$pwd\psexec" @@ -558,4 +552,5 @@ function Get-PSExec { Get-ZipFileFromUrl -Url $url -DownloadFilePath "$pwd\pstools.zip" -OutputDir "$DownloadPath" Move-Item -Path "$DownloadPath\PsExec64.exe" -Destination $pwd -Force Remove-Item -Path $DownloadPath -Force -Recurse -ErrorAction Ignore + return $psExecPath } diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index a18a78a503..1903607139 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -559,4 +559,318 @@ function Log-OSBuildInformationOnVM $buildLabEx = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name 'BuildLabEx' Write-Output "OS Build Information: $($buildLabEx.BuildLabEx)" } -} \ No newline at end of file +} + +<# +.SYNOPSIS + Helper function to execute a command on a VM. + +.DESCRIPTION + This function executes a command on a specified VM using the provided credentials. + +.PARAMETER VMName + The name of the VM to execute the command on. + +.PARAMETER Command + The command to execute on the VM. +#> +function Execute-CommandOnVM { + param ( + [Parameter(Mandatory=$True)][string]$VMName, + [Parameter(Mandatory=$True)][string]$Command + ) + + try { + $vmCredential = New-Credential -Username $Admin -AdminPassword $AdminPassword + Write-Log "Executing command on VM: $VMName. Command: $Command" + $result = Invoke-Command -VMName $VMName -Credential $VmCredential -ScriptBlock { + param($Command) + Invoke-Expression $Command + } -ArgumentList $Command + Write-Log "Successfully executed command on VM: $VMName. Command: $Command. Result: $result" + } catch { + throw "Failed to execute command on VM: $VMName with error: $_" + } +} + + +<# +.SYNOPSIS + Helper function to create a VM. + +.DESCRIPTION + This function creates a new VM with the specified parameters. + +.PARAMETER VmName + The name of the VM to create. + +.PARAMETER VhdPath + The path to the VHD file to use for the VM. + +.PARAMETER VmStoragePath + The storage path for the VM. + +.PARAMETER VMMemory + The amount of memory to allocate for the VM. + +.PARAMETER UnattendPath + The path to the unattend file to use for the VM. This will notably be used for configuring the user accounts and passwords. + +.PARAMETER VmSwitchName + The name of the switch to use for the VM. + +.EXAMPLE + Create-VM -VmName "MyVM" -UserPassword "Password -VhdPath "C:\MyVHD.vhd" -VmStoragePath "C:\VMStorage" -VMMemory 2GB -UnattendPath "C:\MyUnattend.xml" -VmSwitchName "VMInternalSwitch" +#> +function Create-VM { + param( + [Parameter(Mandatory=$True)][string]$VmName, + [Parameter(Mandatory=$True)][string]$UserPassword, + [Parameter(Mandatory=$True)][string]$VhdPath, + [Parameter(Mandatory=$True)][string]$VmStoragePath, + [Parameter(Mandatory=$True)][Int64]$VMMemory, + [Parameter(Mandatory=$True)][string]$UnattendPath, + [Parameter(Mandatory=$True)][string]$VmSwitchName + ) + + try { + ## Check for any pre-requisites + # Check that the VHD exists + if (-not (Test-Path -Path $VhdPath)) { + throw "VHD not found at $VhdPath" + } + + ## Create the VM + # Create storage directory for the VM + Create-DirectoryIfNotExists -Path $VmStoragePath + + # Move the VHD to the path + Write-Log "Moving $VhdPath to $VmStoragePath" + Move-Item -Path $VhdPath -Destination $VmStoragePath -Force + $VmVhdPath = Join-Path -Path $VmStoragePath -ChildPath (Split-Path -Path $VhdPath -Leaf) + + # Move unattend to the path and replace placeholder strings + Write-Log "Moving $UnattendPath file to $VmStoragePath" + Move-Item -Path $UnattendPath -Destination $VmStoragePath -Force + $VmUnattendPath = Join-Path -Path $VmStoragePath -ChildPath (Split-Path -Path $UnattendPath -Leaf) + Replace-PlaceholderStrings -FilePath $VmUnattendPath -SearchString 'PLACEHOLDER_ADMIN_PASSWORD' -ReplaceString $UserPassword + Replace-PlaceholderStrings -FilePath $VmUnattendPath -SearchString 'PLACEHOLDER_STANDARDUSER_PASSWORD' -ReplaceString $UserPassword + + # Configure the VHD with the unattend file. + Write-Log "Mounting VHD and applying unattend file" + $VmMountPath = Join-Path -Path $VmStoragePath -ChildPath 'mountedVhd' + if (-not (Test-Path -Path $VmMountPath)) { + New-Item -ItemType Directory -Path $VmMountPath + } + Mount-WindowsImage -ImagePath $VmVhdPath -Index 1 -Path $VmMountPath -ErrorAction Stop | Out-Null + Copy-Item -Path $VmUnattendPath -Destination $VmMountPath\Unattend.xml + Apply-WindowsUnattend -Path $VmMountPath -UnattendPath $VmMountPath\Unattend.xml -ErrorAction Stop | Out-Null + Dismount-WindowsImage -Path $VmMountPath -Save -ErrorAction Stop + + # Create the VM + Write-Log "Creating the VM" + New-VM -Name $VmName -VhdPath $VmVhdPath -SwitchName $VmSwitchName + Set-VMMemory -VMName $VmName -DynamicMemoryEnabled $false -StartupBytes $VMMemory + + if ((Get-VM -VMName $vmName) -eq $null) { + throw "Failed to create VM: $VMName" + } + + Write-Log "Successfully created VM: $VMName" -ForegroundColor Green + } catch { + throw "Failed to create VM: $VmName with error: $_" + } +} + +<# +.SYNOPSIS + Helper function to configure a VM after creation. + +.DESCRIPTION + This function configures a VM after it has been created, including setting the processor count, enabling the Guest Service Interface, and executing a setup script. + +.PARAMETER VmName + The name of the VM to configure. + +.PARAMETER VMCpuCount + The number of processors to allocate for the VM. + +.PARAMETER VMWorkingDirectory + The working directory on the VM to use for executing the setup script. Defaults to 'C:\ebpf_cicd'. + +.PARAMETER VMSetupScript + The path to the setup script to execute on the VM. Defaults to '.\configure_vm.ps1'. + +.EXAMPLE + Initialize-VM -VmName "MyVM" -VMCpuCount 4 +#> +function Initialize-VM { + param( + [Parameter(Mandatory=$True)][string]$VmName, + [Parameter(Mandatory=$True)][int]$VMCpuCount, + [Parameter(Mandatory=$False)][string]$VMWorkingDirectory='C:\ebpf_cicd', + [Parameter(Mandatory=$False)][string]$VMSetupScript='.\configure_vm.ps1' + ) + + try { + Write-Log "Configuring VM: $VmName" + $vmList = @( + @{ + Name = $VmName + } + ) + + # Post VM creation configuration steps. + Write-Log "Setting VM processor count to $VMCpuCount" + Set-VMProcessor -VMName $VmName -Count $VMCpuCount + Write-Log "Enabling Guest Service Interface" + Enable-VMIntegrationService -VMName $VMName -Name 'Guest Service Interface' + + # Start the VM + Write-Log "Starting VM: $VmName" + Start-VM -Name $VmName + Wait-AllVMsToInitialize -VMList $vmList -UserName $Admin -AdminPassword $AdminPassword + + Write-Log "Sleeping for 1 minute to let the VM get into a steady state" + Sleep -Seconds 60 + + # Copy setup script to the VM and execute it. + Write-Log "Executing VM configuration script ($VMSetupScript) on VM: $VmName" + Copy-VMFile -VMName $VmName -FileSource Host -SourcePath $VMSetupScript -DestinationPath "$VMWorkingDirectory\$VMSetupScript" -CreateFullPath + $vmCredential = New-Credential -Username $Admin -AdminPassword $AdminPassword + Execute-CommandOnVM -VMName $VmName -VmCredential $vmCredential -Command "cd $VMWorkingDirectory; .\$VMSetupScript" + Write-Log "Sleeping for 1 minute to let the VM get into a steady state" + Sleep -Seconds 60 # Sleep for 1 minute to let the VM get into a steady state. + Write-Log "Successfully executed VM configuration script ($VMSetupScript) on VM: $VmName" -ForegroundColor Green + + Wait-AllVMsToInitialize -VMList $vmList -UserName $Admin -AdminPassword $AdminPassword + + # Checkpoint the VM. This can sometimes fail if other operations are in progress, so retry a few times to ensure a successful checkpoint. + for ($i = 0; $i -lt 5; $i += 1) { + try { + Write-Log "Checkpointing VM: $VmName" + Checkpoint-VM -Name $VMName -SnapshotName 'baseline' + Write-Log "Successfully added 'baseline' checkpoint for VM: $VMName" -ForegroundColor Green + break + } catch { + Write-Log "Failed to checkpoint VM: $VmName. Retrying..." + Start-Sleep -Seconds 5 + continue + } + } + + Write-Log "Successfully configured VM: $VmName" -ForegroundColor Green + } catch { + throw "Failed to configure VM: $VmName with error: $_" + } +} + +########## Helpers for the host machine ########## +<# +.SYNOPSIS + Extracts .zip files in the specified directory and returns paths to .vhd and .vhdx files. + +.DESCRIPTION + This function takes an input directory as a parameter, looks inside the directory for any .zip files, extracts them, and returns a PowerShell string array of all full paths to .vhd and .vhdx files. It suppresses any output and throws errors if any exceptions are found. + +.PARAMETER InputDirectory + The directory to search for .zip files and extract them. + +.EXAMPLE + $vhdFiles = Prepare-VhdFiles -InputDirectory "C:\MyDirectory" +#> +function Prepare-VhdFiles { + param ( + [Parameter(Mandatory=$true)] + [string]$InputDirectory + ) + + try { + $zipFiles = Get-ChildItem -Path $InputDirectory -Filter *.zip -Recurse + foreach ($zipFile in $zipFiles) { + Expand-Archive -Path $zipFile.FullName -DestinationPath $InputDirectory *> $null 2>&1 + } + + # Get all .vhd and .vhdx files + $vhdFiles = (Get-ChildItem -Path $InputDirectory -Recurse -Include *.vhd, *.vhdx) | Select-Object -ExpandProperty FullName + + if ($vhdFiles.Count -eq 0) { + throw "No VHD files found in $InputDirectory" + } + + return [string[]]$vhdFiles + } + catch { + Get-ChildItem -Path $InputDirectory -Recurse + throw "Failed to prepare VHD files with error: $_" + } +} + +<# +.SYNOPSIS + Helper function to create a VM switch if it does not already exist. + +.DESCRIPTION + Checks if a VM switch with the given name and type already exists. If not, it creates a new switch of the specified type. + +.PARAMETER SwitchName + The name of the switch to create. + +.PARAMETER SwitchType + The type of switch to create. Can be 'External' or 'Internal'. + +.EXAMPLE + Create-VMSwitchIfNeeded -SwitchName 'VMInternalSwitch' -SwitchType 'Internal' + Create-VMSwitchIfNeeded -SwitchName 'VMExternalSwitch' -SwitchType 'External' +#> +function Create-VMSwitchIfNeeded { + param ( + [Parameter(Mandatory=$true)][string]$SwitchName, + [Parameter(Mandatory=$true)][string]$SwitchType + ) + + if ($SwitchType -eq 'External') { + # Check to see if an external switch already exists + $ExternalSwitches = (Get-VMSwitch -SwitchType External -ErrorAction Ignore) + if ($ExternalSwitches -ne $null) { + Write-Log "External switch already exists: $($ExternalSwitches[0].Name)" + return + } + + # Try to create the external switch + $NetAdapterNames = (Get-NetAdapter -Name 'Ethernet*' | Where-Object { $_.Status -eq 'Up' }).Name + $index = 0 + foreach ($NetAdapterName in $NetAdapterNames) { + try { + if ([string]::IsNullOrEmpty($NetAdapterName)) { + continue + } + $currSwitchName = $SwitchName + '-' + $index + Write-Log "Attempting to creating external switch: $currSwitchName with NetAdapter: $NetAdapterName" + New-VMSwitch -Name $currSwitchName -NetAdapterName $NetAdapterName -AllowManagementOS $true + $index += 1 + } catch { + Write-Log "Failed to create external switch for NetAdapter: $NetAdapterName with error: $_" + } + } + } elseif ($SwitchType -eq 'Internal') { + # Check to see if an internal switch already exists + $InternalSwitches = (Get-VMSwitch -SwitchType Internal -Name $SwitchName -ErrorAction Ignore) + if ($InternalSwitches -ne $null) { + Write-Log "Internal switch already exists: $($InternalSwitches[0].Name)" + return + } + + # Try to create the internal switch + try { + Write-Log "Creating internal switch" + New-VMSwitch -Name $SwitchName -SwitchType Internal + } catch { + throw "Failed to create internal switch with error: $_" + } + } else { + throw "Invalid switch type: $SwitchType" + } + + Write-Log "Successfully created $SwitchType switch with name: $SwitchName" -ForegroundColor Green +} diff --git a/scripts/execute_ebpf_cicd_tests.ps1 b/scripts/execute_ebpf_cicd_tests.ps1 index dfb5cff1cd..4457a149eb 100644 --- a/scripts/execute_ebpf_cicd_tests.ps1 +++ b/scripts/execute_ebpf_cicd_tests.ps1 @@ -18,10 +18,14 @@ Push-Location $WorkingDirectory Import-Module $WorkingDirectory\common.psm1 -Force -ArgumentList ($LogFileName) -ErrorAction Stop if ($SelfHostedRunnerName -eq "1ESRunner") { - Get-PSExec - $psExecPath = "$pwd\PSExec64.exe" - $TestVMCredential = Retrieve-StoredCredential -Target $AdminTarget -PsExecPath $psExecPath - $StandardUserTestVMCredential = Retrieve-StoredCredential -Target $StandardUserTarget -PsExecPath $psExecPath + $TestVMCredential = Retrieve-StoredCredential -Target $AdminTarget + if ($null -eq $TestVMCredential) { + ThrowWithErrorMessage "Failed to retrieve the test VM credential." + } + $StandardUserTestVMCredential = Retrieve-StoredCredential -Target $StandardUserTarget + if ($null -eq $StandardUserTestVMCredential) { + ThrowWithErrorMessage "Failed to retrieve the standard user test VM credential." + } } else { $AdminTestVMCredential = Get-StoredCredential -Target $AdminTarget -ErrorAction Stop $StandardUserTestVMCredential = Get-StoredCredential -Target $StandardUserTarget -ErrorAction Stop @@ -30,6 +34,7 @@ if ($SelfHostedRunnerName -eq "1ESRunner") { # Read the test execution json. $Config = Get-Content ("{0}\{1}" -f $PSScriptRoot, $TestExecutionJsonFileName) | ConvertFrom-Json +Write-Log "Starting eBPF CICD tests on $SelfHostedRunnerName" $Job = Start-Job -ScriptBlock { param ([Parameter(Mandatory = $True)] [PSCredential] $AdminTestVMCredential, [Parameter(Mandatory = $True)] [PSCredential] $StandardUserTestVMCredential, diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index 6c5d561e00..5978cc4df6 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -20,9 +20,7 @@ Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction S if ($SelfHostedRunnerName -eq "1ESRunner") { Write-Log "Fetching the test VM credential using target: $Target" - Get-PSExec - $psExecPath = "$pwd\PSExec64.exe" - $TestVMCredential = Retrieve-StoredCredential -Target $Target -PsExecPath $psExecPath + $TestVMCredential = Retrieve-StoredCredential -Target $Target if ($null -eq $TestVMCredential) { ThrowWithErrorMessage "Failed to retrieve the test VM credential." } From bd781de41030041621de5f7bb62617cc251c3661 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 24 Jan 2025 15:59:27 -0800 Subject: [PATCH 159/190] update build outputs --- .github/workflows/reusable-build.yml | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/.github/workflows/reusable-build.yml b/.github/workflows/reusable-build.yml index 35c2668038..2fc0812d25 100644 --- a/.github/workflows/reusable-build.yml +++ b/.github/workflows/reusable-build.yml @@ -224,6 +224,19 @@ jobs: cd ${{github.workspace}}/${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} Invoke-WebRequest https://github.com/microsoft/bpf_performance/releases/download/v0.11.0/build-Release-windows-2022.zip -OutFile bpf_performance.zip + - name: Prepare 1ES artifacts + if: steps.skip_check.outputs.should_skip != 'true' && (inputs.build_artifact == 'Build-x64' && matrix.configurations == 'Release') + run: | + cp scripts/common.psm1 1es/ + cp scripts/config_test_vm.psm1 1es/ + + - name: Upload 1ES artifacts + if: steps.skip_check.outputs.should_skip != 'true' && (inputs.build_artifact == 'Build-x64' && matrix.configurations == 'Release') + uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 + with: + name: 1ES artifacts + path: 1es/** + - name: Extract artifacts to build path if: steps.skip_check.outputs.should_skip != 'true' && inputs.download_demo_repository == true && matrix.configurations != 'FuzzerDebug' working-directory: ${{env.GITHUB_WORKSPACE}} @@ -304,13 +317,3 @@ jobs: - name: Perform CodeQL Analysis if: inputs.build_codeql == true && steps.skip_check.outputs.should_skip != 'true' uses: github/codeql-action/analyze@b6a472f63d85b9c78a3ac5e89422239fc15e9b3c - - - name: Upload 1ES artifacts - if: steps.skip_check.outputs.should_skip != 'true' && (inputs.build_artifact == 'Build-x64' && matrix.configurations == 'Release') - uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 - with: - name: ebpf-for-windows - 1ES artifacts (${{inputs.build_artifact}}_${{env.BUILD_CONFIGURATION}}) - path: | - 1es/** - scripts/common.psm1 - scripts/config_test_vm.psm1 From afd1204abd7aaae991c3088a6851c235a96ccf42 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 24 Jan 2025 16:06:49 -0800 Subject: [PATCH 160/190] fixes for 1es --- 1es/Setup.ps1 | 2 +- scripts/cleanup_ebpf_cicd_tests.ps1 | 3 +++ scripts/config_test_vm.psm1 | 3 +-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/1es/Setup.ps1 b/1es/Setup.ps1 index 70831aad52..7479f11250 100644 --- a/1es/Setup.ps1 +++ b/1es/Setup.ps1 @@ -40,7 +40,7 @@ $ErrorActionPreference = "Stop" $logFileName = 'Setup.log' Import-Module .\common.psm1 -Force -ArgumentList ($logFileName) -WarningAction SilentlyContinue $password = New-UniquePassword -$passwordSecureString = ConvertTo-SecureString -String $adminPassword -AsPlainText -Force +$passwordSecureString = ConvertTo-SecureString -String $password -AsPlainText -Force Import-Module .\config_test_vm.psm1 -Force -ArgumentList('Administrator', $passwordSecureString, 'C:\work', $logFileName) -WarningAction SilentlyContinue # Create new credentials for the VM. diff --git a/scripts/cleanup_ebpf_cicd_tests.ps1 b/scripts/cleanup_ebpf_cicd_tests.ps1 index 520f154bab..c7f0d9d2e5 100644 --- a/scripts/cleanup_ebpf_cicd_tests.ps1 +++ b/scripts/cleanup_ebpf_cicd_tests.ps1 @@ -14,6 +14,9 @@ Push-Location $WorkingDirectory Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue if ($SelfHostedRunnerName -eq "1ESRunner") { $TestVMCredential = Retrieve-StoredCredential -Target $Target + if ($null -eq $TestVMCredential) { + ThrowWithErrorMessage "Failed to retrieve the test VM credential." + } } else { $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop } diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index 1903607139..ec0706db2f 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -781,8 +781,7 @@ function Initialize-VM { #> function Prepare-VhdFiles { param ( - [Parameter(Mandatory=$true)] - [string]$InputDirectory + [Parameter(Mandatory=$true)][string]$InputDirectory ) try { From 7257fbefa593d217856996d39a02b17bc74488d5 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Fri, 24 Jan 2025 16:43:19 -0800 Subject: [PATCH 161/190] some debugging logs --- scripts/common.psm1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/common.psm1 b/scripts/common.psm1 index 75ba88f3f5..c0d9e65fe7 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -229,7 +229,11 @@ function Retrieve-StoredCredential { [Parameter(Mandatory=$True)][string]$Target ) + Get-CredentialManager $PSExecPath = Get-PSExec + if (-not (Test-Path $PSExecPath)) { + throw "PsExec not found at $PSExecPath" + } $Script = @" Import-Module CredentialManager -ErrorAction Stop; @@ -291,6 +295,9 @@ function Generate-NewCredential { ) Get-CredentialManager $PSExecPath = Get-PSExec + if (-not (Test-Path $PSExecPath)) { + throw "PsExec not found at $PSExecPath" + } $Script = @" Import-Module CredentialManager -ErrorAction Stop; From 47c78915fc2f2270e0daacb190240484e0478e1e Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Sat, 25 Jan 2025 07:05:28 -0800 Subject: [PATCH 162/190] fix psexec path --- scripts/common.psm1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/common.psm1 b/scripts/common.psm1 index c0d9e65fe7..30b2123ddf 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -231,8 +231,8 @@ function Retrieve-StoredCredential { Get-CredentialManager $PSExecPath = Get-PSExec - if (-not (Test-Path $PSExecPath)) { - throw "PsExec not found at $PSExecPath" + if (($null -eq $PSExecPath) -or (-not (Test-Path $PSExecPath))) { + throw "Failed to retrieve PsExec path." } $Script = @" @@ -295,8 +295,8 @@ function Generate-NewCredential { ) Get-CredentialManager $PSExecPath = Get-PSExec - if (-not (Test-Path $PSExecPath)) { - throw "PsExec not found at $PSExecPath" + if (($null -eq $PSExecPath) -or (-not (Test-Path $PSExecPath))) { + throw "Failed to retrieve PsExec path." } $Script = @" @@ -317,7 +317,7 @@ function Generate-NewCredential { } # Use the Retrieve-StoredCredential function to verify that the credential was stored correctly. - return (Retrieve-StoredCredential -PsExecPath $PsExecPath -Target $Target) + return (Retrieve-StoredCredential -Target $Target) } catch { throw "An error occurred while storing the credential: $_" } finally { From d7b4837403d1c2dee4af1f31ea6bb2d89750e95a Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Sat, 25 Jan 2025 14:18:11 -0800 Subject: [PATCH 163/190] fix --- scripts/config_test_vm.psm1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index ec0706db2f..4d5c5ab172 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -604,6 +604,9 @@ function Execute-CommandOnVM { .PARAMETER VmName The name of the VM to create. +.PARAMETER UserPassword + The plain text password to use for the user accounts on the VM. + .PARAMETER VhdPath The path to the VHD file to use for the VM. From 635faa11e9207d2b9139e04ea34e3acdd398346d Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Sun, 26 Jan 2025 14:26:54 -0800 Subject: [PATCH 164/190] fixes --- 1es/Setup.ps1 | 1 - scripts/config_test_vm.psm1 | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/1es/Setup.ps1 b/1es/Setup.ps1 index 7479f11250..7ed73c8f27 100644 --- a/1es/Setup.ps1 +++ b/1es/Setup.ps1 @@ -79,7 +79,6 @@ foreach ($vhd in $vhds) { Initialize-VM ` -VmName $vmName ` - -UserPassword $password ` -VMCpuCount $VMCpuCount Write-Log "VM $vmName created successfully" diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index 4d5c5ab172..6fd29846a7 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -637,6 +637,7 @@ function Create-VM { ) try { + Write-Log "Creating VM: with Name: $VmName Password: $UserPassword VhdPath: $VhdPath VmStoragePath: $VmStoragePath Memory: $VMMemory UnattendPath: $UnattendPath VMSwitchName: $VmSwitchName" ## Check for any pre-requisites # Check that the VHD exists if (-not (Test-Path -Path $VhdPath)) { From 8c308cc8d0d1a83491f955fc5d2ccb99a73bb3d0 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Sun, 26 Jan 2025 17:39:43 -0800 Subject: [PATCH 165/190] fixes --- scripts/config_test_vm.psm1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index 6fd29846a7..c12c3473b6 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -741,8 +741,7 @@ function Initialize-VM { # Copy setup script to the VM and execute it. Write-Log "Executing VM configuration script ($VMSetupScript) on VM: $VmName" Copy-VMFile -VMName $VmName -FileSource Host -SourcePath $VMSetupScript -DestinationPath "$VMWorkingDirectory\$VMSetupScript" -CreateFullPath - $vmCredential = New-Credential -Username $Admin -AdminPassword $AdminPassword - Execute-CommandOnVM -VMName $VmName -VmCredential $vmCredential -Command "cd $VMWorkingDirectory; .\$VMSetupScript" + Execute-CommandOnVM -VMName $VmName -Command "cd $VMWorkingDirectory; .\$VMSetupScript" Write-Log "Sleeping for 1 minute to let the VM get into a steady state" Sleep -Seconds 60 # Sleep for 1 minute to let the VM get into a steady state. Write-Log "Successfully executed VM configuration script ($VMSetupScript) on VM: $VmName" -ForegroundColor Green From e4cd0c4226dcf9d97d6ed579b3557d51d4abfa81 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 27 Jan 2025 08:06:00 -0800 Subject: [PATCH 166/190] WIP --- scripts/common.psm1 | 1 + scripts/execute_ebpf_cicd_tests.ps1 | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/scripts/common.psm1 b/scripts/common.psm1 index 30b2123ddf..7589b28b07 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -255,6 +255,7 @@ function Retrieve-StoredCredential { throw "PsExec failed with exit code $($process.ExitCode). Error: $error" } + Write-Log "(Debug) Retrieved credential: $output" $lines = $output -split "`n" $Username = $lines[0].Trim() $Password = ConvertTo-SecureString -String $lines[1].Trim() -AsPlainText -Force diff --git a/scripts/execute_ebpf_cicd_tests.ps1 b/scripts/execute_ebpf_cicd_tests.ps1 index 4457a149eb..cb3f0c1514 100644 --- a/scripts/execute_ebpf_cicd_tests.ps1 +++ b/scripts/execute_ebpf_cicd_tests.ps1 @@ -21,10 +21,14 @@ if ($SelfHostedRunnerName -eq "1ESRunner") { $TestVMCredential = Retrieve-StoredCredential -Target $AdminTarget if ($null -eq $TestVMCredential) { ThrowWithErrorMessage "Failed to retrieve the test VM credential." + } else { + Write-Log "Fetched the test VM credential using target: $AdminTarget" } $StandardUserTestVMCredential = Retrieve-StoredCredential -Target $StandardUserTarget if ($null -eq $StandardUserTestVMCredential) { ThrowWithErrorMessage "Failed to retrieve the standard user test VM credential." + } else { + Write-Log "Fetched the standard user test VM credential using target: $StandardUserTarget" } } else { $AdminTestVMCredential = Get-StoredCredential -Target $AdminTarget -ErrorAction Stop From 979ce34b9f18d7cd64d7452687f3af3199d0cdcf Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 27 Jan 2025 08:45:24 -0800 Subject: [PATCH 167/190] fixes --- .github/workflows/cicd.yml | 6 +++--- scripts/cleanup_ebpf_cicd_tests.ps1 | 3 +++ scripts/common.psm1 | 10 ++++++---- scripts/execute_ebpf_cicd_tests.ps1 | 13 +++++++++---- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 62f9495b30..390ca0082e 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -302,9 +302,9 @@ jobs: if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') uses: ./.github/workflows/reusable-test.yml with: - pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" - test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" - post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" -SelfHostedRunnerName '1ESRunner' + test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" -SelfHostedRunnerName '1ESRunner' + post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true -SelfHostedRunnerName '1ESRunner' name: driver_native_only_ws2025 build_artifact: Build-x64-native-only environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2025"]' diff --git a/scripts/cleanup_ebpf_cicd_tests.ps1 b/scripts/cleanup_ebpf_cicd_tests.ps1 index c7f0d9d2e5..be7dd23edb 100644 --- a/scripts/cleanup_ebpf_cicd_tests.ps1 +++ b/scripts/cleanup_ebpf_cicd_tests.ps1 @@ -13,10 +13,13 @@ Push-Location $WorkingDirectory Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue if ($SelfHostedRunnerName -eq "1ESRunner") { + Write-Log "Fetching the test VM credential using target: $Target" $TestVMCredential = Retrieve-StoredCredential -Target $Target if ($null -eq $TestVMCredential) { ThrowWithErrorMessage "Failed to retrieve the test VM credential." } + $debugCred = $TestVMCredential.GetNetworkCredential() | Out-String + Write-Log "Cred: $debugCred" } else { $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop } diff --git a/scripts/common.psm1 b/scripts/common.psm1 index 7589b28b07..f851b40e5f 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -233,6 +233,8 @@ function Retrieve-StoredCredential { $PSExecPath = Get-PSExec if (($null -eq $PSExecPath) -or (-not (Test-Path $PSExecPath))) { throw "Failed to retrieve PsExec path." + } else { + Write-Log "(Debug) PsExec path: $PSExecPath" } $Script = @" @@ -249,13 +251,13 @@ function Retrieve-StoredCredential { try { $process = Start-Process -FilePath $PsExecPath -ArgumentList "-accepteula -nobanner -s powershell.exe -command `"$Script`"" -NoNewWindow -PassThru -Wait -RedirectStandardOutput $outputFile -RedirectStandardError $errorFile $output = Get-Content $outputFile - $error = Get-Content $errorFile + $err = Get-Content $errorFile if ($process.ExitCode -ne 0) { throw "PsExec failed with exit code $($process.ExitCode). Error: $error" } - Write-Log "(Debug) Retrieved credential: $output" + Write-Log "(Debug) Retrieved credential: $output and error: $err" $lines = $output -split "`n" $Username = $lines[0].Trim() $Password = ConvertTo-SecureString -String $lines[1].Trim() -AsPlainText -Force @@ -311,10 +313,10 @@ function Generate-NewCredential { try { $process = Start-Process -FilePath $PsExecPath -ArgumentList "-accepteula -nobanner -s powershell.exe -command `"$Script`"" -NoNewWindow -PassThru -Wait -RedirectStandardOutput $outputFile -RedirectStandardError $errorFile $output = Get-Content $outputFile - $error = Get-Content $errorFile + $err = Get-Content $errorFile if ($process.ExitCode -ne 0) { - throw "PsExec failed with exit code $($process.ExitCode). Error: $error" + throw "PsExec failed with exit code $($process.ExitCode). Error: $err" } # Use the Retrieve-StoredCredential function to verify that the credential was stored correctly. diff --git a/scripts/execute_ebpf_cicd_tests.ps1 b/scripts/execute_ebpf_cicd_tests.ps1 index cb3f0c1514..45abb5680d 100644 --- a/scripts/execute_ebpf_cicd_tests.ps1 +++ b/scripts/execute_ebpf_cicd_tests.ps1 @@ -18,17 +18,22 @@ Push-Location $WorkingDirectory Import-Module $WorkingDirectory\common.psm1 -Force -ArgumentList ($LogFileName) -ErrorAction Stop if ($SelfHostedRunnerName -eq "1ESRunner") { + Write-Log "Fetching the test VM credential using target: $AdminTarget" $TestVMCredential = Retrieve-StoredCredential -Target $AdminTarget if ($null -eq $TestVMCredential) { - ThrowWithErrorMessage "Failed to retrieve the test VM credential." + ThrowWithErrorMessage "Failed to retrieve the test VM credential for $AdminTarget" } else { - Write-Log "Fetched the test VM credential using target: $AdminTarget" + $debugCred = $TestVMCredential.GetNetworkCredential() | Out-String + Write-Log "Cred: $debugCred" } + + Write-Log "Fetching the test VM credential using target: $StandardUserTarget" $StandardUserTestVMCredential = Retrieve-StoredCredential -Target $StandardUserTarget if ($null -eq $StandardUserTestVMCredential) { - ThrowWithErrorMessage "Failed to retrieve the standard user test VM credential." + ThrowWithErrorMessage "Failed to retrieve the test VM credential for $StandardUserTarget" } else { - Write-Log "Fetched the standard user test VM credential using target: $StandardUserTarget" + $debugCred = $StandardUserTestVMCredential.GetNetworkCredential() | Out-String + Write-Log "Cred: $debugCred" } } else { $AdminTestVMCredential = Get-StoredCredential -Target $AdminTarget -ErrorAction Stop From e2690bc8543dc8423167e417241917f9d00a7567 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 27 Jan 2025 09:54:29 -0800 Subject: [PATCH 168/190] WIP --- scripts/common.psm1 | 123 +++++++++++++++------------- scripts/execute_ebpf_cicd_tests.ps1 | 3 + 2 files changed, 71 insertions(+), 55 deletions(-) diff --git a/scripts/common.psm1 b/scripts/common.psm1 index f851b40e5f..948b3c5bb0 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -178,6 +178,66 @@ function Replace-PlaceholderStrings { } } +<# +.SYNOPSIS + Helper function to invoke a script using PsExec. + +.DESCRIPTION + This function uses PsExec to run a PowerShell script in the LocalSystem account context. + +.PARAMETER Script + The script to execute using PsExec. + +.PARAMETER MaxRetries + The maximum number of times to retry executing the script. Default is 3. + +.EXAMPLE + Invoke-PsExecScript -Script "Get-Process" +#> +function Invoke-PsExecScript { + param ( + [Parameter(Mandatory=$true)][string]$Script + [Parameter(Mandatory=$false)][int]$MaxRetries = 3 + ) + $PSExecPath = Get-PSExec + if (($null -eq $PSExecPath) -or (-not (Test-Path $PSExecPath))) { + throw "Failed to retrieve PsExec path." + } else { + # TODO - remove this. + Write-Log "(Debug) PsExec path: $PSExecPath" + } + + $attempt = 0 + while ($attempt -lt $MaxRetries) { + $outputFile = [System.IO.Path]::GetTempFileName() + $errorFile = [System.IO.Path]::GetTempFileName() + + try { + $process = Start-Process -FilePath $PsExecPath -ArgumentList "-accepteula -nobanner -s powershell.exe -command `"$Script`"" -NoNewWindow -PassThru -Wait -RedirectStandardOutput $outputFile -RedirectStandardError $errorFile + $output = Get-Content $outputFile + $err = Get-Content $errorFile + + if ($process.ExitCode -ne 0) { + throw "PsExec failed with exit code $($process.ExitCode). Error: $err" + } + + return $output + } catch { + Write-Log "(Error) Attempt $($attempt + 1) failed: $_" + $attempt++ + if ($attempt -lt $MaxRetries) { + Write-Log "(Info) Retrying in $RetryDelay seconds..." + Start-Sleep -Seconds $RetryDelay + } else { + throw "Failed to execute the script with PsExec after $MaxRetries attempts." + } + } finally { + Remove-Item $outputFile -Force -ErrorAction Ignore + Remove-Item $errorFile -Force -ErrorAction Ignore + } + } +} + <# .SYNOPSIS Imports the CredentialManager, and installs it if necessary. @@ -228,14 +288,7 @@ function Retrieve-StoredCredential { param ( [Parameter(Mandatory=$True)][string]$Target ) - Get-CredentialManager - $PSExecPath = Get-PSExec - if (($null -eq $PSExecPath) -or (-not (Test-Path $PSExecPath))) { - throw "Failed to retrieve PsExec path." - } else { - Write-Log "(Debug) PsExec path: $PSExecPath" - } $Script = @" Import-Module CredentialManager -ErrorAction Stop; @@ -245,29 +298,12 @@ function Retrieve-StoredCredential { \"`$UserName`n`$Password\" "@ - $outputFile = [System.IO.Path]::GetTempFileName() - $errorFile = [System.IO.Path]::GetTempFileName() - - try { - $process = Start-Process -FilePath $PsExecPath -ArgumentList "-accepteula -nobanner -s powershell.exe -command `"$Script`"" -NoNewWindow -PassThru -Wait -RedirectStandardOutput $outputFile -RedirectStandardError $errorFile - $output = Get-Content $outputFile - $err = Get-Content $errorFile - - if ($process.ExitCode -ne 0) { - throw "PsExec failed with exit code $($process.ExitCode). Error: $error" - } - - Write-Log "(Debug) Retrieved credential: $output and error: $err" - $lines = $output -split "`n" - $Username = $lines[0].Trim() - $Password = ConvertTo-SecureString -String $lines[1].Trim() -AsPlainText -Force - return [System.Management.Automation.PSCredential]::new($Username, $Password) - } catch { - throw "An error occurred while retrieving the credential: $_" - } finally { - if (Test-Path $outputFile) { Remove-Item $outputFile } - if (Test-Path $errorFile) { Remove-Item $errorFile } - } + $output = Invoke-PsExecScript -Script $Script + Write-Log "(Debug) Retrieved credential: $output" + $lines = $output -split "`n" + $Username = $lines[0].Trim() + $Password = ConvertTo-SecureString -String $lines[1].Trim() -AsPlainText -Force + return [System.Management.Automation.PSCredential]::new($Username, $Password) } <# @@ -297,36 +333,13 @@ function Generate-NewCredential { [Parameter(Mandatory=$True)][string]$Target ) Get-CredentialManager - $PSExecPath = Get-PSExec - if (($null -eq $PSExecPath) -or (-not (Test-Path $PSExecPath))) { - throw "Failed to retrieve PsExec path." - } - $Script = @" Import-Module CredentialManager -ErrorAction Stop; New-StoredCredential -Target '$Target' -UserName '$Username' -Password '$Password' -Persist LocalMachine; "@ - $outputFile = [System.IO.Path]::GetTempFileName() - $errorFile = [System.IO.Path]::GetTempFileName() - - try { - $process = Start-Process -FilePath $PsExecPath -ArgumentList "-accepteula -nobanner -s powershell.exe -command `"$Script`"" -NoNewWindow -PassThru -Wait -RedirectStandardOutput $outputFile -RedirectStandardError $errorFile - $output = Get-Content $outputFile - $err = Get-Content $errorFile - - if ($process.ExitCode -ne 0) { - throw "PsExec failed with exit code $($process.ExitCode). Error: $err" - } - - # Use the Retrieve-StoredCredential function to verify that the credential was stored correctly. - return (Retrieve-StoredCredential -Target $Target) - } catch { - throw "An error occurred while storing the credential: $_" - } finally { - if (Test-Path $outputFile) { Remove-Item $outputFile } - if (Test-Path $errorFile) { Remove-Item $errorFile } - } + $output = Invoke-PsExecScript -Script $Script + return (Retrieve-StoredCredential -Target $Target) } diff --git a/scripts/execute_ebpf_cicd_tests.ps1 b/scripts/execute_ebpf_cicd_tests.ps1 index 45abb5680d..873bdd9202 100644 --- a/scripts/execute_ebpf_cicd_tests.ps1 +++ b/scripts/execute_ebpf_cicd_tests.ps1 @@ -56,9 +56,11 @@ $Job = Start-Job -ScriptBlock { [Parameter(Mandatory = $True)] [int] $TestHangTimeout, [Parameter(Mandatory = $True)] [string] $UserModeDumpFolder) + Write-Host "Executing test..." Push-Location $WorkingDirectory # Load other utility modules. + Write-Host "Importing modules" Import-Module $WorkingDirectory\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue Import-Module $WorkingDirectory\vm_run_tests.psm1 ` -Force ` @@ -79,6 +81,7 @@ $Job = Start-Job -ScriptBlock { # currently one VM runs per runner. $TestVMName = $VMList[0].Name + Write-Host "Starting eBPF CICD tests on $TestVMName" try { # Run Kernel tests on test VM. Write-Log "Running kernel tests on $TestVMName" From 5e8088149316ba6d4615e398ee63cd100d1523a5 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 27 Jan 2025 10:19:30 -0800 Subject: [PATCH 169/190] fix typo --- scripts/common.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/common.psm1 b/scripts/common.psm1 index 948b3c5bb0..efeb307737 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -196,7 +196,7 @@ function Replace-PlaceholderStrings { #> function Invoke-PsExecScript { param ( - [Parameter(Mandatory=$true)][string]$Script + [Parameter(Mandatory=$true)][string]$Script, [Parameter(Mandatory=$false)][int]$MaxRetries = 3 ) $PSExecPath = Get-PSExec From a9c46c891fc844a36ee09b9e328bc4500f3d3d49 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 27 Jan 2025 11:28:15 -0800 Subject: [PATCH 170/190] WIP --- scripts/common.psm1 | 6 ------ scripts/execute_ebpf_cicd_tests.ps1 | 20 ++++++++++++++------ scripts/setup_ebpf_cicd_tests.ps1 | 6 ++++-- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/scripts/common.psm1 b/scripts/common.psm1 index efeb307737..90fd2cf0a6 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -202,9 +202,6 @@ function Invoke-PsExecScript { $PSExecPath = Get-PSExec if (($null -eq $PSExecPath) -or (-not (Test-Path $PSExecPath))) { throw "Failed to retrieve PsExec path." - } else { - # TODO - remove this. - Write-Log "(Debug) PsExec path: $PSExecPath" } $attempt = 0 @@ -223,10 +220,8 @@ function Invoke-PsExecScript { return $output } catch { - Write-Log "(Error) Attempt $($attempt + 1) failed: $_" $attempt++ if ($attempt -lt $MaxRetries) { - Write-Log "(Info) Retrying in $RetryDelay seconds..." Start-Sleep -Seconds $RetryDelay } else { throw "Failed to execute the script with PsExec after $MaxRetries attempts." @@ -299,7 +294,6 @@ function Retrieve-StoredCredential { "@ $output = Invoke-PsExecScript -Script $Script - Write-Log "(Debug) Retrieved credential: $output" $lines = $output -split "`n" $Username = $lines[0].Trim() $Password = ConvertTo-SecureString -String $lines[1].Trim() -AsPlainText -Force diff --git a/scripts/execute_ebpf_cicd_tests.ps1 b/scripts/execute_ebpf_cicd_tests.ps1 index 873bdd9202..e60b95143a 100644 --- a/scripts/execute_ebpf_cicd_tests.ps1 +++ b/scripts/execute_ebpf_cicd_tests.ps1 @@ -19,12 +19,13 @@ Push-Location $WorkingDirectory Import-Module $WorkingDirectory\common.psm1 -Force -ArgumentList ($LogFileName) -ErrorAction Stop if ($SelfHostedRunnerName -eq "1ESRunner") { Write-Log "Fetching the test VM credential using target: $AdminTarget" - $TestVMCredential = Retrieve-StoredCredential -Target $AdminTarget - if ($null -eq $TestVMCredential) { + $AdminTestVMCredential = Retrieve-StoredCredential -Target $AdminTarget + if ($null -eq $AdminTestVMCredential) { ThrowWithErrorMessage "Failed to retrieve the test VM credential for $AdminTarget" } else { - $debugCred = $TestVMCredential.GetNetworkCredential() | Out-String - Write-Log "Cred: $debugCred" + $type = $AdminTestVMCredential.GetType() + Write-Log "Type: $type" + Write-Log "Successfully retrieved the test VM credential for $AdminTarget" } Write-Log "Fetching the test VM credential using target: $StandardUserTarget" @@ -32,8 +33,9 @@ if ($SelfHostedRunnerName -eq "1ESRunner") { if ($null -eq $StandardUserTestVMCredential) { ThrowWithErrorMessage "Failed to retrieve the test VM credential for $StandardUserTarget" } else { - $debugCred = $StandardUserTestVMCredential.GetNetworkCredential() | Out-String - Write-Log "Cred: $debugCred" + $type = $StandardUserTestVMCredential.GetType() + Write-Log "Type: $type" + Write-Log "Successfully retrieved the test VM credential for $StandardUserTarget" } } else { $AdminTestVMCredential = Get-StoredCredential -Target $AdminTarget -ErrorAction Stop @@ -112,6 +114,12 @@ $Job = Start-Job -ScriptBlock { $TestHangTimeout, $UserModeDumpFolder) +if ($Job -eq $null) { + ThrowWithErrorMessage "Failed to start the job" +} else { + Write-Log "Job started successfully" +} + # Keep track of the last received output count $JobTimedOut = ` Wait-TestJobToComplete -Job $Job ` diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index 5978cc4df6..4995043f90 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -23,9 +23,11 @@ if ($SelfHostedRunnerName -eq "1ESRunner") { $TestVMCredential = Retrieve-StoredCredential -Target $Target if ($null -eq $TestVMCredential) { ThrowWithErrorMessage "Failed to retrieve the test VM credential." + } else { + $type = $TestVMCredential.GetType() + Write-Log "Type: $type" + Write-Log "Successfully retrieved the test VM credential." } - $debugCred = $TestVMCredential.GetNetworkCredential() | Out-String - Write-Log "Cred: $debugCred" } else { $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop } From 6d8fe3f85151ae6c1d5da5a0a354f0f83cc432b3 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 27 Jan 2025 12:02:38 -0800 Subject: [PATCH 171/190] add retry logic around fetching cred --- scripts/cleanup_ebpf_cicd_tests.ps1 | 4 +- scripts/common.psm1 | 89 ++++++++++++++++++++--------- scripts/execute_ebpf_cicd_tests.ps1 | 4 -- scripts/setup_ebpf_cicd_tests.ps1 | 2 - 4 files changed, 63 insertions(+), 36 deletions(-) diff --git a/scripts/cleanup_ebpf_cicd_tests.ps1 b/scripts/cleanup_ebpf_cicd_tests.ps1 index be7dd23edb..620184524a 100644 --- a/scripts/cleanup_ebpf_cicd_tests.ps1 +++ b/scripts/cleanup_ebpf_cicd_tests.ps1 @@ -17,9 +17,9 @@ if ($SelfHostedRunnerName -eq "1ESRunner") { $TestVMCredential = Retrieve-StoredCredential -Target $Target if ($null -eq $TestVMCredential) { ThrowWithErrorMessage "Failed to retrieve the test VM credential." + } else { + Write-Log "Successfully retrieved the test VM credential." } - $debugCred = $TestVMCredential.GetNetworkCredential() | Out-String - Write-Log "Cred: $debugCred" } else { $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop } diff --git a/scripts/common.psm1 b/scripts/common.psm1 index 90fd2cf0a6..554774479e 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -204,33 +204,52 @@ function Invoke-PsExecScript { throw "Failed to retrieve PsExec path." } - $attempt = 0 - while ($attempt -lt $MaxRetries) { - $outputFile = [System.IO.Path]::GetTempFileName() - $errorFile = [System.IO.Path]::GetTempFileName() - - try { - $process = Start-Process -FilePath $PsExecPath -ArgumentList "-accepteula -nobanner -s powershell.exe -command `"$Script`"" -NoNewWindow -PassThru -Wait -RedirectStandardOutput $outputFile -RedirectStandardError $errorFile - $output = Get-Content $outputFile - $err = Get-Content $errorFile + $outputFile = [System.IO.Path]::GetTempFileName() + $errorFile = [System.IO.Path]::GetTempFileName() - if ($process.ExitCode -ne 0) { - throw "PsExec failed with exit code $($process.ExitCode). Error: $err" - } + # TODO - possibly remove maxretries param + try { + $process = Start-Process -FilePath $PsExecPath -ArgumentList "-accepteula -nobanner -s powershell.exe -command `"$Script`"" -NoNewWindow -PassThru -Wait -RedirectStandardOutput $outputFile -RedirectStandardError $errorFile + $output = Get-Content $outputFile + $err = Get-Content $errorFile - return $output - } catch { - $attempt++ - if ($attempt -lt $MaxRetries) { - Start-Sleep -Seconds $RetryDelay - } else { - throw "Failed to execute the script with PsExec after $MaxRetries attempts." - } - } finally { - Remove-Item $outputFile -Force -ErrorAction Ignore - Remove-Item $errorFile -Force -ErrorAction Ignore + if ($process.ExitCode -ne 0) { + throw "PsExec failed with exit code $($process.ExitCode). Output: $output Error: $err" } + + return $output + } finally { + Remove-Item $outputFile -Force -ErrorAction Ignore + Remove-Item $errorFile -Force -ErrorAction Ignore } + + # $attempt = 0 + # while ($attempt -lt $MaxRetries) { + # $outputFile = [System.IO.Path]::GetTempFileName() + # $errorFile = [System.IO.Path]::GetTempFileName() + + # try { + # $process = Start-Process -FilePath $PsExecPath -ArgumentList "-accepteula -nobanner -s powershell.exe -command `"$Script`"" -NoNewWindow -PassThru -Wait -RedirectStandardOutput $outputFile -RedirectStandardError $errorFile + # $output = Get-Content $outputFile + # $err = Get-Content $errorFile + + # if ($process.ExitCode -ne 0) { + # throw "PsExec failed with exit code $($process.ExitCode). Error: $err" + # } + + # return $output + # } catch { + # $attempt++ + # if ($attempt -lt $MaxRetries) { + # Start-Sleep -Seconds $RetryDelay + # } else { + # throw "Failed to execute the script with PsExec after $MaxRetries attempts." + # } + # } finally { + # Remove-Item $outputFile -Force -ErrorAction Ignore + # Remove-Item $errorFile -Force -ErrorAction Ignore + # } + # } } <# @@ -293,11 +312,25 @@ function Retrieve-StoredCredential { \"`$UserName`n`$Password\" "@ - $output = Invoke-PsExecScript -Script $Script - $lines = $output -split "`n" - $Username = $lines[0].Trim() - $Password = ConvertTo-SecureString -String $lines[1].Trim() -AsPlainText -Force - return [System.Management.Automation.PSCredential]::new($Username, $Password) + # PSExec sometimes fails to fetch the output. Retry up to 3 times to improve reliability. + $attempt = 0 + $maxRetries = 5 + while ($attempt -lt $maxRetries) { + try { + $output = Invoke-PsExecScript -Script $Script + $lines = $output -split "`n" + $Username = $lines[0].Trim() + $Password = ConvertTo-SecureString -String $lines[1].Trim() -AsPlainText -Force + return [System.Management.Automation.PSCredential]::new($Username, $Password) + } catch { + $attempt++ + if ($attempt -lt $maxRetries) { + Start-Sleep -Seconds 5 + } else { + throw "Failed to retrieve the stored credential after $maxRetries attempts." + } + } + } } <# diff --git a/scripts/execute_ebpf_cicd_tests.ps1 b/scripts/execute_ebpf_cicd_tests.ps1 index e60b95143a..8750a604ed 100644 --- a/scripts/execute_ebpf_cicd_tests.ps1 +++ b/scripts/execute_ebpf_cicd_tests.ps1 @@ -23,8 +23,6 @@ if ($SelfHostedRunnerName -eq "1ESRunner") { if ($null -eq $AdminTestVMCredential) { ThrowWithErrorMessage "Failed to retrieve the test VM credential for $AdminTarget" } else { - $type = $AdminTestVMCredential.GetType() - Write-Log "Type: $type" Write-Log "Successfully retrieved the test VM credential for $AdminTarget" } @@ -33,8 +31,6 @@ if ($SelfHostedRunnerName -eq "1ESRunner") { if ($null -eq $StandardUserTestVMCredential) { ThrowWithErrorMessage "Failed to retrieve the test VM credential for $StandardUserTarget" } else { - $type = $StandardUserTestVMCredential.GetType() - Write-Log "Type: $type" Write-Log "Successfully retrieved the test VM credential for $StandardUserTarget" } } else { diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index 4995043f90..b6856b55dc 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -24,8 +24,6 @@ if ($SelfHostedRunnerName -eq "1ESRunner") { if ($null -eq $TestVMCredential) { ThrowWithErrorMessage "Failed to retrieve the test VM credential." } else { - $type = $TestVMCredential.GetType() - Write-Log "Type: $type" Write-Log "Successfully retrieved the test VM credential." } } else { From 25788cc46ed330ac9cae2da098517e02c234d463 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 27 Jan 2025 13:40:54 -0800 Subject: [PATCH 172/190] code cleanup - remove debugging logs --- scripts/cleanup_ebpf_cicd_tests.ps1 | 6 --- scripts/common.psm1 | 72 ++++++----------------------- scripts/config_test_vm.psm1 | 4 +- scripts/execute_ebpf_cicd_tests.ps1 | 23 --------- scripts/setup_ebpf_cicd_tests.ps1 | 7 --- 5 files changed, 15 insertions(+), 97 deletions(-) diff --git a/scripts/cleanup_ebpf_cicd_tests.ps1 b/scripts/cleanup_ebpf_cicd_tests.ps1 index 620184524a..520f154bab 100644 --- a/scripts/cleanup_ebpf_cicd_tests.ps1 +++ b/scripts/cleanup_ebpf_cicd_tests.ps1 @@ -13,13 +13,7 @@ Push-Location $WorkingDirectory Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue if ($SelfHostedRunnerName -eq "1ESRunner") { - Write-Log "Fetching the test VM credential using target: $Target" $TestVMCredential = Retrieve-StoredCredential -Target $Target - if ($null -eq $TestVMCredential) { - ThrowWithErrorMessage "Failed to retrieve the test VM credential." - } else { - Write-Log "Successfully retrieved the test VM credential." - } } else { $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop } diff --git a/scripts/common.psm1 b/scripts/common.psm1 index 554774479e..b75a9aca62 100644 --- a/scripts/common.psm1 +++ b/scripts/common.psm1 @@ -43,6 +43,7 @@ function New-Credential return $Credential } + function Compress-File { param ([Parameter(Mandatory = $True)] [string] $SourcePath, @@ -130,16 +131,14 @@ function Create-DirectoryIfNotExists { [Parameter(Mandatory=$True)][string]$Path ) - try { - if (-not (Test-Path -Path $Path -PathType Container)) { - New-Item -Path $Path -ItemType Directory -Force # -ErrorAction Ignore | Out-Null - } + # Create the directory if it does not already exist. + if (-not (Test-Path -Path $Path -PathType Container)) { + New-Item -Path $Path -ItemType Directory -Force + } - if (-not (Test-Path -PathType Container $Path)) { - throw "Failed to create directory: $Path" - } - } catch { - throw "Failed to create directory: $Path with error $_" + # Check if the directory was successfully created. + if (-not (Test-Path -PathType Container $Path)) { + throw "Failed to create directory: $Path" } } @@ -188,16 +187,12 @@ function Replace-PlaceholderStrings { .PARAMETER Script The script to execute using PsExec. -.PARAMETER MaxRetries - The maximum number of times to retry executing the script. Default is 3. - .EXAMPLE Invoke-PsExecScript -Script "Get-Process" #> function Invoke-PsExecScript { param ( - [Parameter(Mandatory=$true)][string]$Script, - [Parameter(Mandatory=$false)][int]$MaxRetries = 3 + [Parameter(Mandatory=$true)][string]$Script ) $PSExecPath = Get-PSExec if (($null -eq $PSExecPath) -or (-not (Test-Path $PSExecPath))) { @@ -207,7 +202,6 @@ function Invoke-PsExecScript { $outputFile = [System.IO.Path]::GetTempFileName() $errorFile = [System.IO.Path]::GetTempFileName() - # TODO - possibly remove maxretries param try { $process = Start-Process -FilePath $PsExecPath -ArgumentList "-accepteula -nobanner -s powershell.exe -command `"$Script`"" -NoNewWindow -PassThru -Wait -RedirectStandardOutput $outputFile -RedirectStandardError $errorFile $output = Get-Content $outputFile @@ -222,34 +216,6 @@ function Invoke-PsExecScript { Remove-Item $outputFile -Force -ErrorAction Ignore Remove-Item $errorFile -Force -ErrorAction Ignore } - - # $attempt = 0 - # while ($attempt -lt $MaxRetries) { - # $outputFile = [System.IO.Path]::GetTempFileName() - # $errorFile = [System.IO.Path]::GetTempFileName() - - # try { - # $process = Start-Process -FilePath $PsExecPath -ArgumentList "-accepteula -nobanner -s powershell.exe -command `"$Script`"" -NoNewWindow -PassThru -Wait -RedirectStandardOutput $outputFile -RedirectStandardError $errorFile - # $output = Get-Content $outputFile - # $err = Get-Content $errorFile - - # if ($process.ExitCode -ne 0) { - # throw "PsExec failed with exit code $($process.ExitCode). Error: $err" - # } - - # return $output - # } catch { - # $attempt++ - # if ($attempt -lt $MaxRetries) { - # Start-Sleep -Seconds $RetryDelay - # } else { - # throw "Failed to execute the script with PsExec after $MaxRetries attempts." - # } - # } finally { - # Remove-Item $outputFile -Force -ErrorAction Ignore - # Remove-Item $errorFile -Force -ErrorAction Ignore - # } - # } } <# @@ -321,6 +287,9 @@ function Retrieve-StoredCredential { $lines = $output -split "`n" $Username = $lines[0].Trim() $Password = ConvertTo-SecureString -String $lines[1].Trim() -AsPlainText -Force + if ($null -eq $Username -or $null -eq $Password) { + throw "Failed to retrieve the stored credential." + } return [System.Management.Automation.PSCredential]::new($Username, $Password) } catch { $attempt++ @@ -381,33 +350,28 @@ function Expand-ZipFile { for ($i = 0; $i -lt $maxRetries; $i++) { try { - Write-Log "Extract attempt $($i + 1) started" $job = Start-Job -ScriptBlock { param ($DownloadFilePath, $OutputDir) Expand-Archive -Path $DownloadFilePath -DestinationPath $OutputDir -Force } -ArgumentList $DownloadFilePath, $OutputDir if (Wait-Job -Job $job -Timeout $timeout) { - Write-Log "Extraction completed" + Write-Log "Extraction completed. $DownloadFilePath -> $OutputDir" Receive-Job -Job $job break } else { Stop-Job -Job $job Remove-Job -Job $job - Write-Log "Extract attempt $($i + 1) timed out after $timeout seconds." if ($i -eq ($maxRetries - 1)) { throw "Failed to extract $DownloadFilePath after $maxRetries attempts." } else { - Write-Log "Retrying in $retryDelay seconds..." Start-Sleep -Seconds $retryDelay } } } catch { - Write-Log "Iteration $($i + 1) failed to extract $DownloadFilePath" -ForegroundColor Red if ($i -eq ($maxRetries - 1)) { throw "Failed to extract $DownloadFilePath after $maxRetries attempts." } else { - Write-Log "Retrying in $retryDelay seconds..." Start-Sleep -Seconds $retryDelay } } @@ -433,7 +397,6 @@ function Get-ZipFileFromUrl { throw "Failed to reach $Url HTTP status code: $($response.StatusCode)" } - Write-Log "Download attempt $($i + 1) started" $ProgressPreference = 'SilentlyContinue' $job = Start-Job -ScriptBlock { @@ -442,7 +405,6 @@ function Get-ZipFileFromUrl { } -ArgumentList $Url, $DownloadFilePath, $timeout if (Wait-Job -Job $job -Timeout $timeout) { - Write-Log "Download completed" Receive-Job -Job $job Write-Log "Extracting $DownloadFilePath to $OutputDir" @@ -451,28 +413,22 @@ function Get-ZipFileFromUrl { } else { Stop-Job -Job $job Remove-Job -Job $job - Write-Log "Download attempt $($i + 1) timed out after $timeout seconds." if (Test-Path $DownloadFilePath) { - Remove-Item -Path $DownloadFilePath -Force - Write-Log "Removed partially downloaded file." + Remove-Item -Path $DownloadFilePath -Force -ErrorAction Ignore } if ($i -eq ($maxRetries - 1)) { throw "Failed to download $Url after $maxRetries attempts." } else { - Write-Log "Retrying in $retryDelay seconds..." Start-Sleep -Seconds $retryDelay } } } catch { - Write-Log "Iteration $($i + 1) failed to download $Url. Removing $DownloadFilePath" -ForegroundColor Red if (Test-Path $DownloadFilePath) { Remove-Item -Path $DownloadFilePath -Force -ErrorAction Ignore - Write-Log "Removed partially downloaded file." } if ($i -eq ($maxRetries - 1)) { throw "Failed to download $Url after $maxRetries attempts." } else { - Write-Log "Retrying in $retryDelay seconds..." Start-Sleep -Seconds $retryDelay } } diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index c12c3473b6..f3f316d59e 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -139,8 +139,6 @@ function Initialize-AllVMs { param ([Parameter(Mandatory=$True)] $VMList) - Write-Log "Initializing VMs..." - # Restore the VMs. Restore-AllVMs -VMList $VMList @@ -637,7 +635,7 @@ function Create-VM { ) try { - Write-Log "Creating VM: with Name: $VmName Password: $UserPassword VhdPath: $VhdPath VmStoragePath: $VmStoragePath Memory: $VMMemory UnattendPath: $UnattendPath VMSwitchName: $VmSwitchName" + Write-Log "Creating VM: with Name: $VmName VhdPath: $VhdPath VmStoragePath: $VmStoragePath Memory: $VMMemory UnattendPath: $UnattendPath VMSwitchName: $VmSwitchName" ## Check for any pre-requisites # Check that the VHD exists if (-not (Test-Path -Path $VhdPath)) { diff --git a/scripts/execute_ebpf_cicd_tests.ps1 b/scripts/execute_ebpf_cicd_tests.ps1 index 8750a604ed..396072e2d2 100644 --- a/scripts/execute_ebpf_cicd_tests.ps1 +++ b/scripts/execute_ebpf_cicd_tests.ps1 @@ -18,21 +18,8 @@ Push-Location $WorkingDirectory Import-Module $WorkingDirectory\common.psm1 -Force -ArgumentList ($LogFileName) -ErrorAction Stop if ($SelfHostedRunnerName -eq "1ESRunner") { - Write-Log "Fetching the test VM credential using target: $AdminTarget" $AdminTestVMCredential = Retrieve-StoredCredential -Target $AdminTarget - if ($null -eq $AdminTestVMCredential) { - ThrowWithErrorMessage "Failed to retrieve the test VM credential for $AdminTarget" - } else { - Write-Log "Successfully retrieved the test VM credential for $AdminTarget" - } - - Write-Log "Fetching the test VM credential using target: $StandardUserTarget" $StandardUserTestVMCredential = Retrieve-StoredCredential -Target $StandardUserTarget - if ($null -eq $StandardUserTestVMCredential) { - ThrowWithErrorMessage "Failed to retrieve the test VM credential for $StandardUserTarget" - } else { - Write-Log "Successfully retrieved the test VM credential for $StandardUserTarget" - } } else { $AdminTestVMCredential = Get-StoredCredential -Target $AdminTarget -ErrorAction Stop $StandardUserTestVMCredential = Get-StoredCredential -Target $StandardUserTarget -ErrorAction Stop @@ -41,7 +28,6 @@ if ($SelfHostedRunnerName -eq "1ESRunner") { # Read the test execution json. $Config = Get-Content ("{0}\{1}" -f $PSScriptRoot, $TestExecutionJsonFileName) | ConvertFrom-Json -Write-Log "Starting eBPF CICD tests on $SelfHostedRunnerName" $Job = Start-Job -ScriptBlock { param ([Parameter(Mandatory = $True)] [PSCredential] $AdminTestVMCredential, [Parameter(Mandatory = $True)] [PSCredential] $StandardUserTestVMCredential, @@ -54,11 +40,9 @@ $Job = Start-Job -ScriptBlock { [Parameter(Mandatory = $True)] [int] $TestHangTimeout, [Parameter(Mandatory = $True)] [string] $UserModeDumpFolder) - Write-Host "Executing test..." Push-Location $WorkingDirectory # Load other utility modules. - Write-Host "Importing modules" Import-Module $WorkingDirectory\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue Import-Module $WorkingDirectory\vm_run_tests.psm1 ` -Force ` @@ -79,7 +63,6 @@ $Job = Start-Job -ScriptBlock { # currently one VM runs per runner. $TestVMName = $VMList[0].Name - Write-Host "Starting eBPF CICD tests on $TestVMName" try { # Run Kernel tests on test VM. Write-Log "Running kernel tests on $TestVMName" @@ -110,12 +93,6 @@ $Job = Start-Job -ScriptBlock { $TestHangTimeout, $UserModeDumpFolder) -if ($Job -eq $null) { - ThrowWithErrorMessage "Failed to start the job" -} else { - Write-Log "Job started successfully" -} - # Keep track of the last received output count $JobTimedOut = ` Wait-TestJobToComplete -Job $Job ` diff --git a/scripts/setup_ebpf_cicd_tests.ps1 b/scripts/setup_ebpf_cicd_tests.ps1 index b6856b55dc..33b04ba91f 100644 --- a/scripts/setup_ebpf_cicd_tests.ps1 +++ b/scripts/setup_ebpf_cicd_tests.ps1 @@ -19,13 +19,7 @@ Push-Location $WorkingDirectory Import-Module .\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue if ($SelfHostedRunnerName -eq "1ESRunner") { - Write-Log "Fetching the test VM credential using target: $Target" $TestVMCredential = Retrieve-StoredCredential -Target $Target - if ($null -eq $TestVMCredential) { - ThrowWithErrorMessage "Failed to retrieve the test VM credential." - } else { - Write-Log "Successfully retrieved the test VM credential." - } } else { $TestVMCredential = Get-StoredCredential -Target $Target -ErrorAction Stop } @@ -58,7 +52,6 @@ if ($TestMode -eq "CI/CD" -or $TestMode -eq "Regression") { Get-CoreNetTools Get-PSExec -Write-Log "Finished downloading the required tools. Installing tools on the test VM." $Job = Start-Job -ScriptBlock { param ([Parameter(Mandatory = $True)] [PSCredential] $TestVMCredential, From 2671ba3d3e947e211b6a9a4944c12dbe5b2de65d Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 27 Jan 2025 14:15:31 -0800 Subject: [PATCH 173/190] Update test job to produce 1es artifacts --- .github/workflows/reusable-build.yml | 5 +++-- 1es/artifacts.json | 2 +- 1es/prepare_1es_artifacts.ps1 | 27 +++++++++++++++++++++++++++ scripts/config_test_vm.psm1 | 2 +- 4 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 1es/prepare_1es_artifacts.ps1 diff --git a/.github/workflows/reusable-build.yml b/.github/workflows/reusable-build.yml index 2fc0812d25..01b4e9c2e8 100644 --- a/.github/workflows/reusable-build.yml +++ b/.github/workflows/reusable-build.yml @@ -226,9 +226,10 @@ jobs: - name: Prepare 1ES artifacts if: steps.skip_check.outputs.should_skip != 'true' && (inputs.build_artifact == 'Build-x64' && matrix.configurations == 'Release') + working-directory: ${{env.GITHUB_WORKSPACE}} run: | - cp scripts/common.psm1 1es/ - cp scripts/config_test_vm.psm1 1es/ + cd .\1es + .\prepare_1es_artifacts.ps1 - name: Upload 1ES artifacts if: steps.skip_check.outputs.should_skip != 'true' && (inputs.build_artifact == 'Build-x64' && matrix.configurations == 'Release') diff --git a/1es/artifacts.json b/1es/artifacts.json index b2639d688b..33fed8cc0c 100644 --- a/1es/artifacts.json +++ b/1es/artifacts.json @@ -20,7 +20,7 @@ "Name": "windows-azcopy-downloadfile-msi", "Parameters": { - "BlobUri": "https://ebpfcicdstorage.blob.core.windows.net/server-2025/*", + "BlobUri": "https://ebpfcicdstorage.blob.core.windows.net/IMAGETYPE/*", "Destination": "C:\\work", "Identity": "/subscriptions/15cd5cd8-c222-405e-bb37-c5c6712a075f/resourceGroups/ebpf-cicd-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/ebpf-cicd-identity" } diff --git a/1es/prepare_1es_artifacts.ps1 b/1es/prepare_1es_artifacts.ps1 new file mode 100644 index 0000000000..25309b06ac --- /dev/null +++ b/1es/prepare_1es_artifacts.ps1 @@ -0,0 +1,27 @@ +# Copyright (c) eBPF for Windows contributors +# SPDX-License-Identifier: MIT + +$LogFileName = "prepare_1es_artifacts.log" +Import-Module ..\scripts\common.psm1 -Force -ArgumentList ($LogFileName) -WarningAction SilentlyContinue + +# Replace the placeholder strings in the artifacts.json file with the appropriate values. +Write-Log "Replacing placeholder strings in artifacts.json file." +$images = ('server-2025') +foreach ($image in $images) { + Write-Log "Replacing placeholder strings for image $image." + $outFileName = "artifacts_$image.json" + Copy-Item -Path .\artifacts.json -Destination $outFileName + # The IMAGETYPE name MUST match the Azure Storage Blob Container that holds the necessary dependencies for configuring the 1ES runner. + Replace-PlaceholderStrings -Path $outFileName -SearchString 'IMAGETYPE' -ReplaceString $image +} + +# Copy any shared scripts into the 1ES folder. +$scripts = @( + '..\scripts\common.psm1', + '..\scripts\config_test_vm.psm1' +) +Write-Log "Copying shared scripts into the 1ES folder." +foreach ($script in $scripts) { + Write-Log "Copying $script into $pwd" + Copy-Item -Path $script -Destination $pwd -Force +} diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index f3f316d59e..204821bf5c 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -555,7 +555,7 @@ function Log-OSBuildInformationOnVM $TestCredential = New-Credential -Username $Admin -AdminPassword $AdminPassword Invoke-Command -VMName $VMName -Credential $TestCredential -ScriptBlock { $buildLabEx = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name 'BuildLabEx' - Write-Output "OS Build Information: $($buildLabEx.BuildLabEx)" + Write-Log "OS Build Information: $($buildLabEx.BuildLabEx)" } } From c49a86f209e286538b4f90ea0ece6f70366feac5 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 27 Jan 2025 14:56:51 -0800 Subject: [PATCH 174/190] fix --- 1es/prepare_1es_artifacts.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1es/prepare_1es_artifacts.ps1 b/1es/prepare_1es_artifacts.ps1 index 25309b06ac..6640878da7 100644 --- a/1es/prepare_1es_artifacts.ps1 +++ b/1es/prepare_1es_artifacts.ps1 @@ -12,7 +12,7 @@ foreach ($image in $images) { $outFileName = "artifacts_$image.json" Copy-Item -Path .\artifacts.json -Destination $outFileName # The IMAGETYPE name MUST match the Azure Storage Blob Container that holds the necessary dependencies for configuring the 1ES runner. - Replace-PlaceholderStrings -Path $outFileName -SearchString 'IMAGETYPE' -ReplaceString $image + Replace-PlaceholderStrings -FilePath $outFileName -SearchString 'IMAGETYPE' -ReplaceString $image } # Copy any shared scripts into the 1ES folder. From 52f2335ccb86fd164389931eed2efa57207c6b1b Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Mon, 27 Jan 2025 16:04:21 -0800 Subject: [PATCH 175/190] fix typo --- scripts/config_test_vm.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/config_test_vm.psm1 b/scripts/config_test_vm.psm1 index 204821bf5c..8c6f0ef992 100644 --- a/scripts/config_test_vm.psm1 +++ b/scripts/config_test_vm.psm1 @@ -555,7 +555,7 @@ function Log-OSBuildInformationOnVM $TestCredential = New-Credential -Username $Admin -AdminPassword $AdminPassword Invoke-Command -VMName $VMName -Credential $TestCredential -ScriptBlock { $buildLabEx = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name 'BuildLabEx' - Write-Log "OS Build Information: $($buildLabEx.BuildLabEx)" + Write-Host "OS Build Information: $($buildLabEx.BuildLabEx)" } } From 9902f1363465badd1810a62d8b22514799a0657b Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 28 Jan 2025 09:35:30 -0800 Subject: [PATCH 176/190] update license --- 1es/prepare_1es_artifacts.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/1es/prepare_1es_artifacts.ps1 b/1es/prepare_1es_artifacts.ps1 index 6640878da7..8341a5f6bd 100644 --- a/1es/prepare_1es_artifacts.ps1 +++ b/1es/prepare_1es_artifacts.ps1 @@ -13,6 +13,8 @@ foreach ($image in $images) { Copy-Item -Path .\artifacts.json -Destination $outFileName # The IMAGETYPE name MUST match the Azure Storage Blob Container that holds the necessary dependencies for configuring the 1ES runner. Replace-PlaceholderStrings -FilePath $outFileName -SearchString 'IMAGETYPE' -ReplaceString $image + # Remove the license text line in this output, as it is not compatible with the expected json format. + (Get-Content $outFileName) | Where-Object { $_ -notmatch 'license' } | Set-Content $outFileName } # Copy any shared scripts into the 1ES folder. From aed4a3e6730a8c30107e2107b4bb15986c03138b Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 28 Jan 2025 17:07:07 -0800 Subject: [PATCH 177/190] Add README file --- 1es/README.md | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 1es/README.md diff --git a/1es/README.md b/1es/README.md new file mode 100644 index 0000000000..f5290609df --- /dev/null +++ b/1es/README.md @@ -0,0 +1,103 @@ +# Background +The driver tests utilize a 1ES hosted pool for execution. This document details information about +the setup and how to update it. + +Note that this configuration relies on Azure resources that only Microsoft employees have access +to. If any changes are required, please raise issues in the weekly triage meeting. + +# Architecture +The tests execute on a 1ES runner machine. This machine is an Azure VM, which has been configured +with our setup scripts. The setup scripts create an inner VM with a particular OS image to execute +the tests on. By using this nested VM structure, we are able to extract crash dumps and logs from +any failures. + +# Azure Resources +All of the azure resources are stored in the `ebpf-cicd-rg` resource group in the +`CoreOS_LIOF_eBPF_for_Windows_Dev` subscription. + +The current set of pools and images are as follows: +- Pool: `ebpf-cicd-runner-pool-server-2019`: + - Images: + - `server2025` + +# Image Creation and Update +The following sections explain how one can make changes to the 1ES runner image, including +onboarding a new OS version or updating the runner configuration scripts. + +## Image Creation Scripts +This repo holds a few scripts that are used for configuring the 1ES runners. The scripts are +currently stored in the `1ES` and `scripts` directories. A build artifact called `1ES Artifacts` +also gets populated, which holds the unified set of scripts that can be copied to the Azure +Storage Blob. + +### Scripts: +- `Setup.ps1` - This script is executed on the 1ES runner at image creation time to prepare the VM. Notably, this includes creating the inner VM and running an initial configuration script on it. +- `configure_vm.ps1` - This script is invoked by `Setup.ps1` and executes within the inner VM to configure any necessary state on it. +- `prepare_1es_artifacts.ps1` - This script is invoked by the build pipeline to package together all necessary scripts. +- `artifacts.json` - This holds the artifacts that must be configured in the 1ES image. This file itself contains placeholder text, which `prepare_1es_artifacts.ps1` updates in the produced build artifacts. +- `scripts\common.psm1` - This holds some common helper functions that the runtime tests also utilize. It is used by `Setup.ps1`. +- `scripts\config_test_vm.psm1` - This holds some common helper functions that the runtime tests also utilize, focusing on functionality related to the inner VM. It is used by `Setup.ps1` + +## Creating a New Image +The following steps can be used to onboard a new test image. +- Create a new azure storage blob container within the `ebpfcicdstorage` storage account +- Update the `prepare_1es_artifacts.ps1` script with the new storage blob name +- Upload files from the `1ES Artifacts` build artifact into the storage blob. +- Upload a `.zip` file containing the `.vhd` file containing the base OS image to be used in the inner VM. +- Using the Azure Portal, give the `Storage Blob Data Reader` permission to `1ES Resource Management` Service Principal for this storage blob container. +- Using the Azure Portal, create the 1ES image. Use the following parameters: +``` +-Resource Group - ebpf-cicd-rg +-Region - West US 2 +-Image Type - Define a custom image(1ES Managed) +-Image - WindowsServer 2022-datacenter-g2 +-Artifacts - This must be non-empty, but will be overwritten in subsequent steps below. Initially, this can just be: +{ + "artifacts": [ + { + "name": "windows-enabledismfeature", + "parameters": { + "FeatureName": "Microsoft-Hyper-V" + } + }, + { + "name": "windows-enabledismfeature", + "parameters": { + "FeatureName": "Microsoft-Hyper-V-Management-PowerShell" + } + }, + { + "name": "windows-restart" + } + ] +} +-Advanced > Enable Trusted Launch (Make sure it is enabled) +``` +- Wait for the image creation to complete. +- Follow the steps in the `Updating an Existing Image` section in this document to add the managed identity and script execution to build the runner VM in this image. +- Once the image has been successfully created, navigate to the `1ES Hosted Pool`, and in the `Pool` section, update the `Images` to add the newly created image. +- Follow the steps in the `Onboarding a TEst to Utilize 1ES Runner` section in this document to configure a test to utilize the runner. +- Test by queueing a CICD run, and observe that the test runs successfully. The `pre-test` command outputs the build image of the inner VM that the test executes on. This should be validated to ensure that the test is actually running on the expected VM image. + +## Updating an Existing Image +The following steps can be used to update the Image. +- Make any script changes as necessary to the files in the ebpf-for-windows Github repo. +- Navigate to the appropriate storage blob container for this image and update the scripts in the appropriate storage container. +- Navigate to the 1ES image in the Azure portal. Under `Identity` add the `ebpf-cicd-identity` if not already added. +- Ensure the image Artifact is up to date (i.e consistent with the artifact.json that is generated in the `1ES Artifacts` build artifact). Note that the build artifact produces a unique `artifact.json` file for each image, which notably contains the updated storage blob name. +- Click `apply`. Look under `Monitoring` and `Image Logs` to look for any errors in image creation. +- Ensure that any script changes are checked in to the ebpf-for-windows Github repo, to ensure that all build images continue to use the same set of scripts. + +## Onboarding a Test to Utilize 1ES Runner +- In the `cicd.yml`, configure the following properties: +``` +Set the pool and image name: + environment: '["self-hosted", "1ES.Pool=<POOL_NAME>", "1ES.ImageOverride=<IMAGE_NAME>"]' +For example: + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2025"]' + +Pass the appropriate parameters to the pre_test, test_command, and post_test arguments: + -SelfHostedRunnerName '1ESRunner' +``` + +In the `reusable-test.yml`, the `runs_on` parameter for the job using the 1ES runner should be set. This value is derived from the above mentioned `environment` parameter. Note that this has been configured as part of the initial onboard to utilize 1ES runners, and should not need any adjustments for individual images to be onboarded. It is mentioned here for completeness, should anything with 1ES or Github change in the future. \ No newline at end of file From 70276a9d0aae56660c373dc4eefbf6b6872fdee0 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Tue, 28 Jan 2025 17:11:27 -0800 Subject: [PATCH 178/190] reset 2019 and 2022 tests to validate that we didn't break them --- .github/workflows/cicd.yml | 146 ++++++++++++++++++------------------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 390ca0082e..ae84272404 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -199,43 +199,43 @@ jobs: # gather_dumps: true # capture_etw: true - # # Run the driver tests on self-hosted runners. - # driver_ws2019: - # # Always run this job. - # # Only run this on repos that have self-host runners. - # needs: regular - # if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') - # uses: ./.github/workflows/reusable-test.yml - # with: - # pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" - # test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" - # post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - # name: driver_ws2019 - # build_artifact: Build-x64 - # environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2019"]' - # # driver test copies dumps to testlog folder. - # gather_dumps: false - # # driver tests manually gather code coverage - # code_coverage: false + # Run the driver tests on self-hosted runners. + driver_ws2019: + # Always run this job. + # Only run this on repos that have self-host runners. + needs: regular + if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') + uses: ./.github/workflows/reusable-test.yml + with: + pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" + test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" + post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + name: driver_ws2019 + build_artifact: Build-x64 + environment: '["ebpf_cicd_tests_ws2019"]' + # driver test copies dumps to testlog folder. + gather_dumps: false + # driver tests manually gather code coverage + code_coverage: false - # # Run the driver tests on self-hosted runners. - # driver_ws2022: - # # Always run this job. - # # Only run this on repos that have self-host runners. - # needs: regular - # if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') - # uses: ./.github/workflows/reusable-test.yml - # with: - # pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" - # test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" - # post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - # name: driver_ws2022 - # build_artifact: Build-x64 - # environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2022"]' - # # driver test copies dumps to testlog folder. - # gather_dumps: false - # # driver tests manually gather code coverage - # code_coverage: false + # Run the driver tests on self-hosted runners. + driver_ws2022: + # Always run this job. + # Only run this on repos that have self-host runners. + needs: regular + if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') + uses: ./.github/workflows/reusable-test.yml + with: + pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" + test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" + post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + name: driver_ws2022 + build_artifact: Build-x64 + environment: '["ebpf_cicd_tests_ws2022"]' + # driver test copies dumps to testlog folder. + gather_dumps: false + # driver tests manually gather code coverage + code_coverage: false # Run the driver tests on self-hosted runners. driver_ws2025: @@ -256,44 +256,44 @@ jobs: # driver tests manually gather code coverage code_coverage: false - # # Run the native-only driver tests on self-hosted runners. - # driver_native_only_ws2019: - # # Always run this job. - # # Only run this on repos that have self-host runners. - # needs: regular_native-only - # if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') - # uses: ./.github/workflows/reusable-test.yml - # with: - # pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" - # test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" - # post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - # name: driver_native_only_ws2019 - # build_artifact: Build-x64-native-only - # environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2019"]' - # # driver test copies dumps to testlog folder. - # gather_dumps: false - # # driver tests manually gather code coverage - # code_coverage: false - # configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' + # Run the native-only driver tests on self-hosted runners. + driver_native_only_ws2019: + # Always run this job. + # Only run this on repos that have self-host runners. + needs: regular_native-only + if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') + uses: ./.github/workflows/reusable-test.yml + with: + pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" + test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" + post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + name: driver_native_only_ws2019 + build_artifact: Build-x64-native-only + environment: '["ebpf_cicd_tests_ws2019"]' + # driver test copies dumps to testlog folder. + gather_dumps: false + # driver tests manually gather code coverage + code_coverage: false + configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' - # driver_native_only_ws2022: - # # Always run this job. - # # Only run this on repos that have self-host runners. - # needs: regular_native-only - # if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') - # uses: ./.github/workflows/reusable-test.yml - # with: - # pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" - # test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" - # post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - # name: driver_native_only_ws2022 - # build_artifact: Build-x64-native-only - # environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2022"]' - # # driver test copies dumps to testlog folder. - # gather_dumps: false - # # driver tests manually gather code coverage - # code_coverage: false - # configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' + driver_native_only_ws2022: + # Always run this job. + # Only run this on repos that have self-host runners. + needs: regular_native-only + if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') + uses: ./.github/workflows/reusable-test.yml + with: + pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" + test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" + post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + name: driver_native_only_ws2022 + build_artifact: Build-x64-native-only + environment: '["ebpf_cicd_tests_ws2022"]' + # driver test copies dumps to testlog folder. + gather_dumps: false + # driver tests manually gather code coverage + code_coverage: false + configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' driver_native_only_ws2025: # Always run this job. From 861351a0ee6d1e932f1014768c50b53de1a2183c Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 29 Jan 2025 08:53:46 -0800 Subject: [PATCH 179/190] fixes --- .github/workflows/reusable-test.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index f90a31854f..f6edfaf76e 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -111,7 +111,7 @@ jobs: # Perform shallow checkout for self-hosted runner. - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - if: contains(inputs.environment, 'self-hosted') && (steps.skip_check.outputs.should_skip != 'true') + if: (contains(inputs.environment, 'ebpf_cicd') || contains(inputs.environment, 'self-hosted')) && (steps.skip_check.outputs.should_skip != 'true') with: ref: ${{ github.event.workflow_run.head_branch }} @@ -160,7 +160,7 @@ jobs: - name: Set up OpenCppCoverage and add to PATH id: set_up_opencppcoverage - if: (inputs.code_coverage == true) && !contains(inputs.environment, 'self-hosted') && (steps.skip_check.outputs.should_skip != 'true') + if: (inputs.code_coverage == true) && (!contains(inputs.environment, 'ebpf_cicd') && !contains(inputs.environment, 'self-hosted')) && (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 @@ -177,7 +177,7 @@ jobs: 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: contains(inputs.environment, 'self-hosted') && (steps.skip_check.outputs.should_skip != 'true') + 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 @@ -234,18 +234,18 @@ jobs: .\export_program_info_sample.exe - name: Run pre test command - if: steps.skip_check.outputs.should_skip != 'true' && !contains(inputs.environment, 'self-hosted') + if: steps.skip_check.outputs.should_skip != 'true' && (!contains(inputs.environment, 'ebpf_cicd') && !contains(inputs.environment, 'self-hosted')) id: run_pre_test_command working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | ${{env.PRE_COMMAND}} - name: Run pre test command on self-hosted runner - if: steps.skip_check.outputs.should_skip != 'true' && contains(inputs.environment, 'self-hosted') + if: steps.skip_check.outputs.should_skip != 'true' && (contains(inputs.environment, 'ebpf_cicd') || contains(inputs.environment, 'self-hosted')) id: run_pre_test_command_self_hosted working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | - ${{env.PRE_COMMAND}} -RegressionArtifactsConfiguration ${{env.BUILD_CONFIGURATION}} + ${{env.PRE_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} -RegressionArtifactsConfiguration ${{env.BUILD_CONFIGURATION}} # TODO: Clean up the combination of options: https://github.com/microsoft/ebpf-for-windows/issues/1590 - name: Run test with Code Coverage in VS Dev environment @@ -283,14 +283,14 @@ jobs: 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 on self-hosted runner - if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && contains(inputs.environment, 'self-hosted') && (inputs.fault_injection != true) + if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && (contains(inputs.environment, 'ebpf_cicd') || contains(inputs.environment, 'self-hosted')) && (inputs.fault_injection != true) id: run_test_self_hosted working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | - ${{env.TEST_COMMAND}} + ${{env.TEST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} - name: Run test without Code Coverage - if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && !contains(inputs.environment, 'self-hosted') && (inputs.fault_injection != true) + if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && (!contains(inputs.environment, 'ebpf_cicd') && !contains(inputs.environment, 'self-hosted')) && (inputs.fault_injection != true) id: run_test_without_code_coverage working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} shell: cmd @@ -300,7 +300,7 @@ jobs: - 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') && !contains(inputs.environment, 'self-hosted') + if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && (!contains(inputs.environment, 'ebpf_cicd') && !contains(inputs.environment, 'self-hosted')) id: run_post_test_command working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | @@ -308,11 +308,11 @@ jobs: - name: Run post test command on self-hosted runner # Run the post test command even if the workflow has failed. - if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && contains(inputs.environment, 'self-hosted') + if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && (contains(inputs.environment, 'ebpf_cicd') || contains(inputs.environment, 'self-hosted')) id: run_post_test_command_self_hosted working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | - ${{env.POST_COMMAND}} + ${{env.POST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} - name: Check for CodeCoverage if: steps.skip_check.outputs.should_skip != 'true' From c597682d1c0b2f4a1cba537be76c617b5336c8fc Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 29 Jan 2025 09:29:43 -0800 Subject: [PATCH 180/190] update ymls for 1es test jobs --- .github/workflows/cicd.yml | 12 ++++----- .github/workflows/reusable-test.yml | 38 +++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index ae84272404..92d7f48de6 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -245,9 +245,9 @@ jobs: if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') uses: ./.github/workflows/reusable-test.yml with: - pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" -SelfHostedRunnerName '1ESRunner' - test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" -SelfHostedRunnerName '1ESRunner' - post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true -SelfHostedRunnerName '1ESRunner' + pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" + test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" + post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_ws2025 build_artifact: Build-x64 environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2025"]' @@ -302,9 +302,9 @@ jobs: if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') uses: ./.github/workflows/reusable-test.yml with: - pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" -SelfHostedRunnerName '1ESRunner' - test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" -SelfHostedRunnerName '1ESRunner' - post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true -SelfHostedRunnerName '1ESRunner' + pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" + test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "CI/CD" + post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: driver_native_only_ws2025 build_artifact: Build-x64-native-only environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2025"]' diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index f6edfaf76e..188b9cec91 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -111,7 +111,7 @@ jobs: # Perform shallow checkout for self-hosted runner. - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - if: (contains(inputs.environment, 'ebpf_cicd') || contains(inputs.environment, 'self-hosted')) && (steps.skip_check.outputs.should_skip != 'true') + if: (contains(inputs.environment, 'ebpf_cicd') || contains(inputs.environment, '1ES')) && (steps.skip_check.outputs.should_skip != 'true') with: ref: ${{ github.event.workflow_run.head_branch }} @@ -160,7 +160,7 @@ jobs: - name: Set up OpenCppCoverage and add to PATH id: set_up_opencppcoverage - if: (inputs.code_coverage == true) && (!contains(inputs.environment, 'ebpf_cicd') && !contains(inputs.environment, 'self-hosted')) && (steps.skip_check.outputs.should_skip != 'true') + if: (inputs.code_coverage == true) && (!contains(inputs.environment, 'ebpf_cicd') && !contains(inputs.environment, '1ES')) && (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 @@ -234,19 +234,26 @@ jobs: .\export_program_info_sample.exe - name: Run pre test command - if: steps.skip_check.outputs.should_skip != 'true' && (!contains(inputs.environment, 'ebpf_cicd') && !contains(inputs.environment, 'self-hosted')) + if: steps.skip_check.outputs.should_skip != 'true' && (!contains(inputs.environment, 'ebpf_cicd') && !contains(inputs.environment, '1ES')) id: run_pre_test_command working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | ${{env.PRE_COMMAND}} - name: Run pre test command on self-hosted runner - if: steps.skip_check.outputs.should_skip != 'true' && (contains(inputs.environment, 'ebpf_cicd') || contains(inputs.environment, 'self-hosted')) + if: steps.skip_check.outputs.should_skip != 'true' && contains(inputs.environment, 'ebpf_cicd') id: run_pre_test_command_self_hosted working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | ${{env.PRE_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} -RegressionArtifactsConfiguration ${{env.BUILD_CONFIGURATION}} + - name: Run pre test command on 1ES runner + if: steps.skip_check.outputs.should_skip != 'true' && contains(inputs.environment, '1ES') + id: run_pre_test_command_self_hosted + working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} + run: | + ${{env.PRE_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName '1ESRunner' -RegressionArtifactsConfiguration ${{env.BUILD_CONFIGURATION}} + # TODO: Clean up the combination of options: https://github.com/microsoft/ebpf-for-windows/issues/1590 - name: Run test with Code Coverage in VS Dev environment if: (inputs.code_coverage == true) && (inputs.vs_dev == true) && (steps.skip_check.outputs.should_skip != 'true') @@ -283,14 +290,21 @@ jobs: 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 on self-hosted runner - if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && (contains(inputs.environment, 'ebpf_cicd') || contains(inputs.environment, 'self-hosted')) && (inputs.fault_injection != true) + if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && contains(inputs.environment, 'ebpf_cicd') && (inputs.fault_injection != true) id: run_test_self_hosted working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | ${{env.TEST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} + - name: Run test on 1ES runner + if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && contains(inputs.environment, '1ES') && (inputs.fault_injection != true) + id: run_test_self_hosted + working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} + run: | + ${{env.TEST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName '1ESRunner' + - name: Run test without Code Coverage - if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && (!contains(inputs.environment, 'ebpf_cicd') && !contains(inputs.environment, 'self-hosted')) && (inputs.fault_injection != true) + if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && (!contains(inputs.environment, 'ebpf_cicd') && !contains(inputs.environment, '1ES')) && (inputs.fault_injection != true) id: run_test_without_code_coverage working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} shell: cmd @@ -300,7 +314,7 @@ jobs: - 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') && (!contains(inputs.environment, 'ebpf_cicd') && !contains(inputs.environment, 'self-hosted')) + if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && (!contains(inputs.environment, 'ebpf_cicd') && !contains(inputs.environment, '1ES')) id: run_post_test_command working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | @@ -308,12 +322,20 @@ jobs: - name: Run post test command on self-hosted runner # Run the post test command even if the workflow has failed. - if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && (contains(inputs.environment, 'ebpf_cicd') || contains(inputs.environment, 'self-hosted')) + if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && contains(inputs.environment, 'ebpf_cicd') id: run_post_test_command_self_hosted working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | ${{env.POST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName ${{ runner.name }} + - name: Run post test command on 1ES runner + # Run the post test command even if the workflow has failed. + if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && contains(inputs.environment, '1ES') + id: run_post_test_command_self_hosted + working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} + run: | + ${{env.POST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName '1ESRunner' + - name: Check for CodeCoverage if: steps.skip_check.outputs.should_skip != 'true' uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 From 58d38cce85481105cabf3be6fcae0f4424d586e9 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 29 Jan 2025 09:50:44 -0800 Subject: [PATCH 181/190] 1es yml fixes --- .github/workflows/reusable-test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/reusable-test.yml b/.github/workflows/reusable-test.yml index 188b9cec91..d4b95e5974 100644 --- a/.github/workflows/reusable-test.yml +++ b/.github/workflows/reusable-test.yml @@ -249,7 +249,7 @@ jobs: - name: Run pre test command on 1ES runner if: steps.skip_check.outputs.should_skip != 'true' && contains(inputs.environment, '1ES') - id: run_pre_test_command_self_hosted + id: run_pre_test_command_1es working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | ${{env.PRE_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName '1ESRunner' -RegressionArtifactsConfiguration ${{env.BUILD_CONFIGURATION}} @@ -298,7 +298,7 @@ jobs: - name: Run test on 1ES runner if: (inputs.code_coverage == false) && (steps.skip_check.outputs.should_skip != 'true') && contains(inputs.environment, '1ES') && (inputs.fault_injection != true) - id: run_test_self_hosted + id: run_test_1es working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | ${{env.TEST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName '1ESRunner' @@ -331,7 +331,7 @@ jobs: - name: Run post test command on 1ES runner # Run the post test command even if the workflow has failed. if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && contains(inputs.environment, '1ES') - id: run_post_test_command_self_hosted + id: run_post_test_command_1es working-directory: ./${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}} run: | ${{env.POST_COMMAND}} -LogFileName ${{ runner.name }}.log -SelfHostedRunnerName '1ESRunner' From a365b66f01f1cb3d73e7831fa4cb1739b6d27db4 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 29 Jan 2025 11:27:51 -0800 Subject: [PATCH 182/190] update README --- 1es/README.md | 77 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 23 deletions(-) diff --git a/1es/README.md b/1es/README.md index f5290609df..242ce7be7c 100644 --- a/1es/README.md +++ b/1es/README.md @@ -31,27 +31,37 @@ also gets populated, which holds the unified set of scripts that can be copied t Storage Blob. ### Scripts: -- `Setup.ps1` - This script is executed on the 1ES runner at image creation time to prepare the VM. Notably, this includes creating the inner VM and running an initial configuration script on it. -- `configure_vm.ps1` - This script is invoked by `Setup.ps1` and executes within the inner VM to configure any necessary state on it. -- `prepare_1es_artifacts.ps1` - This script is invoked by the build pipeline to package together all necessary scripts. -- `artifacts.json` - This holds the artifacts that must be configured in the 1ES image. This file itself contains placeholder text, which `prepare_1es_artifacts.ps1` updates in the produced build artifacts. -- `scripts\common.psm1` - This holds some common helper functions that the runtime tests also utilize. It is used by `Setup.ps1`. -- `scripts\config_test_vm.psm1` - This holds some common helper functions that the runtime tests also utilize, focusing on functionality related to the inner VM. It is used by `Setup.ps1` +- `Setup.ps1` - This script is executed on the 1ES runner at image creation time to prepare the VM. +Notably, this includes creating the inner VM and running an initial configuration script on it. +- `configure_vm.ps1` - This script is invoked by `Setup.ps1` and executes within the inner VM to +configure any necessary state on it. +- `prepare_1es_artifacts.ps1` - This script is invoked by the build pipeline to package together +all necessary scripts. +- `artifacts.json` - This holds the artifacts that must be configured in the 1ES image. This file +itself contains placeholder text, which `prepare_1es_artifacts.ps1` updates in the produced build +artifacts. +- `scripts\common.psm1` - This holds some common helper functions that the runtime tests also +utilize. It is used by `Setup.ps1`. +- `scripts\config_test_vm.psm1` - This holds some common helper functions that the runtime tests +also utilize, focusing on functionality related to the inner VM. It is used by `Setup.ps1` ## Creating a New Image The following steps can be used to onboard a new test image. - Create a new azure storage blob container within the `ebpfcicdstorage` storage account - Update the `prepare_1es_artifacts.ps1` script with the new storage blob name - Upload files from the `1ES Artifacts` build artifact into the storage blob. -- Upload a `.zip` file containing the `.vhd` file containing the base OS image to be used in the inner VM. -- Using the Azure Portal, give the `Storage Blob Data Reader` permission to `1ES Resource Management` Service Principal for this storage blob container. +- Upload a `.zip` file containing the `.vhd` file containing the base OS image to be used in the +inner VM. +- Using the Azure Portal, give the `Storage Blob Data Reader` permission to +`1ES Resource Management` Service Principal for this storage blob container. - Using the Azure Portal, create the 1ES image. Use the following parameters: ``` -Resource Group - ebpf-cicd-rg -Region - West US 2 -Image Type - Define a custom image(1ES Managed) -Image - WindowsServer 2022-datacenter-g2 --Artifacts - This must be non-empty, but will be overwritten in subsequent steps below. Initially, this can just be: +-Artifacts - This must be non-empty, but will be overwritten in subsequent steps below. +Initially, this utilize the subset of tasks that do not require the managed identity, i.e: { "artifacts": [ { @@ -74,30 +84,51 @@ The following steps can be used to onboard a new test image. -Advanced > Enable Trusted Launch (Make sure it is enabled) ``` - Wait for the image creation to complete. -- Follow the steps in the `Updating an Existing Image` section in this document to add the managed identity and script execution to build the runner VM in this image. -- Once the image has been successfully created, navigate to the `1ES Hosted Pool`, and in the `Pool` section, update the `Images` to add the newly created image. -- Follow the steps in the `Onboarding a TEst to Utilize 1ES Runner` section in this document to configure a test to utilize the runner. -- Test by queueing a CICD run, and observe that the test runs successfully. The `pre-test` command outputs the build image of the inner VM that the test executes on. This should be validated to ensure that the test is actually running on the expected VM image. +- Follow the steps in the `Updating an Existing Image` section in this document to add the managed +identity and script execution to build the runner VM in this image. +- Once the image has been successfully created, navigate to the `1ES Hosted Pool`, and in the +`Pool` section, update the `Images` to add the newly created image. +- Follow the steps in the `Onboarding a TEst to Utilize 1ES Runner` section in this document to +configure a test to utilize the runner. +- Test by queueing a CICD run, and observe that the test runs successfully. The `pre-test` command +outputs the build image of the inner VM that the test executes on. This should be validated to +ensure that the test is actually running on the expected VM image. ## Updating an Existing Image The following steps can be used to update the Image. - Make any script changes as necessary to the files in the ebpf-for-windows Github repo. -- Navigate to the appropriate storage blob container for this image and update the scripts in the appropriate storage container. -- Navigate to the 1ES image in the Azure portal. Under `Identity` add the `ebpf-cicd-identity` if not already added. -- Ensure the image Artifact is up to date (i.e consistent with the artifact.json that is generated in the `1ES Artifacts` build artifact). Note that the build artifact produces a unique `artifact.json` file for each image, which notably contains the updated storage blob name. +- Navigate to the appropriate storage blob container for this image and update the scripts in the +appropriate storage container. +- Navigate to the 1ES image in the Azure portal. Under `Identity` add the `ebpf-cicd-identity` if +not already added. +- Ensure the image Artifact is up to date (i.e consistent with the artifact.json that is generated +in the `1ES Artifacts` build artifact). Note that the build artifact produces a unique +`artifact.json` file for each image, which notably contains the updated storage blob name. - Click `apply`. Look under `Monitoring` and `Image Logs` to look for any errors in image creation. -- Ensure that any script changes are checked in to the ebpf-for-windows Github repo, to ensure that all build images continue to use the same set of scripts. +- Ensure that any script changes are checked in to the ebpf-for-windows Github repo, to ensure that +all build images continue to use the same set of scripts. ## Onboarding a Test to Utilize 1ES Runner -- In the `cicd.yml`, configure the following properties: +- In the `cicd.yml`, set the `envrionment` parameter: ``` Set the pool and image name: environment: '["self-hosted", "1ES.Pool=<POOL_NAME>", "1ES.ImageOverride=<IMAGE_NAME>"]' For example: - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2025"]' - -Pass the appropriate parameters to the pre_test, test_command, and post_test arguments: - -SelfHostedRunnerName '1ESRunner' + environment: + '[ + "self-hosted", + "1ES.Pool=ebpf-cicd-runner-pool-server-2019", + "1ES.ImageOverride=server2025" + ]' ``` -In the `reusable-test.yml`, the `runs_on` parameter for the job using the 1ES runner should be set. This value is derived from the above mentioned `environment` parameter. Note that this has been configured as part of the initial onboard to utilize 1ES runners, and should not need any adjustments for individual images to be onboarded. It is mentioned here for completeness, should anything with 1ES or Github change in the future. \ No newline at end of file +The changes in `reusable-test.yml` have been made once as part of onboarding our repo to utilize +1ES runners. This section is noted here to help guide any future changes in this area. The following +has been done: +- The `runs_on` parameter is set (notably using the `self-hosted` tag, along with the `1ES.Pool` +and `1ES.ImageOverride` values as specified in the specific testcase) +- A new task for the pre, run, and post test jobs were added. Notably, this passes a fixed +`-SelfHostedRunnerName '1ESRunner'` value. This is done to give a predictable name, instead of the +dynamic name which may change whenver a new 1ES image is used. +- Existing tests were updated to use `contains(inputs.environment, '1ES')` as an indicator that the +job is using the 1ES runner (and negation of this condition to indicate it is not using the 1ES runner). \ No newline at end of file From 2dd130c0f80c8e22200cb8beafe795cad0d36002 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 29 Jan 2025 11:28:06 -0800 Subject: [PATCH 183/190] try and use minimal changes to run_driver_tests.psm1 script --- scripts/run_driver_tests.psm1 | 45 ++++++++++------------------------- 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index 8834e13554..ad240f5141 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -69,8 +69,6 @@ function Generate-KernelDump # This will/should not return (test system will/should bluescreen and reboot). $NotMyFaultProc = Start-Process -NoNewWindow -Passthru -FilePath $NotMyFaultBinaryPath -ArgumentList "/crash" - # Cache the process handle to ensure subsequent access of the process is accurate - $handle = $NotMyFaultProc.Handle # wait for 30 minutes to generate the kernel dump. $NotMyFaultProc.WaitForExit(30*60*1000) @@ -123,8 +121,6 @@ function Generate-ProcessDump -FilePath $ProcDumpBinaryPath ` -ArgumentList $ProcDumpArguments ` -Wait -PassThru - # Cache the process handle to ensure subsequent access of the process is accurate - $handle = $ProcDumpProcess.Handle Write-Log "Waiting for user mode dump to complete..." $ProcDumpProcess.WaitForExit() @@ -160,8 +156,6 @@ function Process-TestCompletion [Parameter(Mandatory = $false)] [bool] $NestedProcess, [Parameter(Mandatory = $false)] [int] $TestHangTimeout = (10*60), # 10 minutes default timeout. [Parameter(Mandatory = $false)] [bool] $NeedKernelDump = $true) - # Cache the process handle to ensure subsequent access of the process is accurate - $handle = $TestProcess.Handle if ($TestProcess -eq $null) { ThrowWithErrorMessage -ErrorMessage "*** ERROR *** Test $TestCommand failed to start." @@ -198,6 +192,9 @@ function Process-TestCompletion Write-Log "Throwing TestHungException for $TestCommand" -ForegroundColor Red throw [System.TimeoutException]::new("Test $TestCommand execution hang timeout ($TestHangTimeout seconds) expired.") } else { + # Ensure the process has completely exited. + Wait-Process -InputObject $TestProcess + # Read and display the output (if any) from the temporary output file. $TempOutputFile = "$env:TEMP\app_output.log" # Log for standard output # Process the log file line-by-line @@ -210,7 +207,6 @@ function Process-TestCompletion } $TestExitCode = $TestProcess.ExitCode - Write-Log "Test exit code: $TestExitCode" if ($TestExitCode -ne 0) { $TempErrorFile = "$env:TEMP\app_error.log" # Log for standard error if ((Test-Path $TempErrorFile) -and (Get-Item $TempErrorFile).Length -gt 0) { @@ -288,7 +284,9 @@ function Invoke-Test } else { $TestProcess = Start-Process -FilePath $TestFilePath -PassThru -NoNewWindow -RedirectStandardOutput $TempOutputFile -RedirectStandardError $TempErrorFile -ErrorAction Stop } - + # Cache the process handle to ensure subsequent access of the process is accurate + $handle = $TestProcess.Handle + Write-Log "Started process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" if ($InnerTestName -ne "") { Process-TestCompletion -TestProcess $TestProcess -TestCommand $InnerTestName -NestedProcess $True -TestHangTimeout $TestHangTimeout } else { @@ -315,7 +313,6 @@ function New-TestTuple { } } - function Invoke-CICDTests { param([parameter(Mandatory = $true)][bool] $VerboseLogs, @@ -336,7 +333,6 @@ function Invoke-CICDTests (New-TestTuple -Test "socket_tests.exe" -Timeout 1800) ) - foreach ($Test in $TestList) { Invoke-Test -TestName $($Test.Test) -TestArgs $($Test.Arguments) -VerboseLogs $VerboseLogs -TestHangTimeout $($Test.Timeout) } @@ -371,21 +367,12 @@ function Invoke-XDPTest Write-Log "Executing $XDPTestName with remote address: $RemoteIPV4Address" $TestCommand = ".\xdp_tests.exe" $TestArguments = "$XDPTestName --remote-ip $RemoteIPV4Address" - $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - # Cache the process handle to ensure subsequent access of the process is accurate - $handle = $TestProcess.Handle - - Write-Log "Started process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" - Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand + Invoke-Test -TestName $TestCommand -TestArgs $TestArguments -VerboseLogs $false -TestHangTimeout $TestHangTimeout Write-Log "Executing $XDPTestName with remote address: $RemoteIPV6Address" $TestCommand = ".\xdp_tests.exe" $TestArguments = "$XDPTestName --remote-ip $RemoteIPV6Address" - $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - # Cache the process handle to ensure subsequent access of the process is accurate - $handle = $TestProcess.Handle - Write-Log "Started process pid: $($TestProcess.Id) name: $($TestProcess.ProcessName) and start: $($TestProcess.StartTime)" - Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand + Invoke-Test -TestName $TestCommand -TestArgs $TestArguments -VerboseLogs $false -TestHangTimeout $TestHangTimeout Write-Log "$XDPTestName Test Passed" -ForegroundColor Green Write-Log "`n`n" @@ -427,9 +414,7 @@ function Invoke-ConnectRedirectTest " --user-type $UserType" Write-Log "Executing connect redirect tests with v4 and v6 programs. Arguments: $TestArguments" - $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand - + Invoke-Test -TestName $TestCommand -TestArgs $TestArguments -VerboseLogs $false -TestHangTimeout $TestHangTimeout ## Run test with only v4 program attached. $TestArguments = @@ -444,9 +429,7 @@ function Invoke-ConnectRedirectTest " [connect_authorize_redirect_tests_v4]" Write-Log "Executing connect redirect tests with v4 programs. Arguments: $TestArguments" - $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand - + Invoke-Test -TestName $TestCommand -TestArgs $TestArguments -VerboseLogs $false -TestHangTimeout $TestHangTimeout ## Run tests with only v6 program attached. $TestArguments = @@ -461,9 +444,7 @@ function Invoke-ConnectRedirectTest " [connect_authorize_redirect_tests_v6]" Write-Log "Executing connect redirect tests with v6 programs. Arguments: $TestArguments" - $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand - + Invoke-Test -TestName $TestCommand -TestArgs $TestArguments -VerboseLogs $false -TestHangTimeout $TestHangTimeout Write-Log "Connect-Redirect Test Passed" -ForegroundColor Green @@ -493,9 +474,7 @@ function Invoke-CICDStressTests $TestArguments = "-tt=8 -td=5 -erd=1000 -er=1" } - $TestProcess = Start-Process -FilePath $TestCommand -ArgumentList $TestArguments -PassThru -NoNewWindow - Process-TestCompletion -TestProcess $TestProcess -TestCommand $TestCommand - + Invoke-Test -TestName $TestCommand -TestArgs $TestArguments -VerboseLogs $VerboseLogs -TestHangTimeout $TestHangTimeout Pop-Location } From f227c95c7d29bbab954394263d42aa307ea39d26 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 29 Jan 2025 12:56:31 -0800 Subject: [PATCH 184/190] fixes --- scripts/run_driver_tests.psm1 | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/run_driver_tests.psm1 b/scripts/run_driver_tests.psm1 index ad240f5141..39d00b65d4 100644 --- a/scripts/run_driver_tests.psm1 +++ b/scripts/run_driver_tests.psm1 @@ -192,9 +192,6 @@ function Process-TestCompletion Write-Log "Throwing TestHungException for $TestCommand" -ForegroundColor Red throw [System.TimeoutException]::new("Test $TestCommand execution hang timeout ($TestHangTimeout seconds) expired.") } else { - # Ensure the process has completely exited. - Wait-Process -InputObject $TestProcess - # Read and display the output (if any) from the temporary output file. $TempOutputFile = "$env:TEMP\app_output.log" # Log for standard output # Process the log file line-by-line From 698b58241d2db25243e11e9a781f884d75310da1 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 29 Jan 2025 14:54:41 -0800 Subject: [PATCH 185/190] peform full build --- .github/workflows/cicd.yml | 1010 ++++++++++++++++++------------------ 1 file changed, 502 insertions(+), 508 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 92d7f48de6..4d401eddd0 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -57,25 +57,25 @@ jobs: build_options: /p:ReleaseJIT='True' configurations: '["Debug", "FuzzerDebug", "Release"]' - # onebranch: - # strategy: - # matrix: - # Architecture: ['x64', 'ARM64'] - # # Always run this job. - # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-build.yml - # with: - # ref: ${{ github.ref }} - # repository: ${{ github.repository }} - # build_artifact: Build-${{ matrix.Architecture }}-onebranch - # generate_release_package: true - # build_msi: true - # build_nuget: true - # configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' - # build_options: /p:BuildOneBranch='True' /t:tools\onebranch /t:installer\ebpf-for-windows - # solution_file: "ebpf-for-windows.sln" - # architecture: ${{ matrix.Architecture }} - # download_demo_repository: false + onebranch: + strategy: + matrix: + Architecture: ['x64', 'ARM64'] + # Always run this job. + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-build.yml + with: + ref: ${{ github.ref }} + repository: ${{ github.repository }} + build_artifact: Build-${{ matrix.Architecture }}-onebranch + generate_release_package: true + build_msi: true + build_nuget: true + configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' + build_options: /p:BuildOneBranch='True' /t:tools\onebranch /t:installer\ebpf-for-windows + solution_file: "ebpf-for-windows.sln" + architecture: ${{ matrix.Architecture }} + download_demo_repository: false # Perform the native-only build. regular_native-only: @@ -95,109 +95,109 @@ jobs: architecture: ${{ matrix.Architecture }} configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' - # # Run the unit tests in GitHub. - # unit_tests_appverif: - # # Always run this job. - # needs: regular - # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: unit_tests - # pre_test: appverif -enable Exceptions Handles Heaps Leak Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe - # # Exclude [processes] test that CodeCoverage can't work with. - # test_command: .\unit_tests.exe -d yes ~[processes] - # build_artifact: Build-x64 - # environment: '["windows-2022"]' - # code_coverage: true - # gather_dumps: true - # capture_etw: true - # leak_detection: true - - # # Run the unit tests in GitHub. - # unit_tests: - # # Always run this job. - # needs: regular - # if: github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: unit_tests - # pre_test: appverif -enable Exceptions Handles Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe - # # Exclude [processes] test that CodeCoverage can't work with. - # test_command: .\unit_tests.exe -d yes ~[processes] - # build_artifact: Build-x64 - # environment: '["windows-2022"]' - # code_coverage: true - # gather_dumps: true - # capture_etw: true - # leak_detection: true - - # # Run the unit tests for NativeOnly build in GitHub. - # unit_tests_native_only: - # # Always run this job. - # needs: regular_native-only - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: unit_tests - # pre_test: appverif -enable Exceptions Handles Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe - # # Exclude [processes] test that CodeCoverage can't work with. - # test_command: .\unit_tests.exe -d yes ~[processes] - # build_artifact: Build-x64-native-only - # environment: '["windows-2022"]' - # code_coverage: true - # gather_dumps: true - # capture_etw: true - # leak_detection: true - # configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' - - # # Run the netebpfext unit tests in GitHub. - # netebpf_ext_unit_tests: - # # Always run this job. - # needs: regular - # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: netebpf_ext_unit_tests - # pre_test: appverif -enable Exceptions Handles Heaps Leak Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe - # test_command: .\netebpfext_unit.exe -d yes - # build_artifact: Build-x64 - # environment: '["windows-2022"]' - # code_coverage: true - # gather_dumps: true - # capture_etw: true - # leak_detection: true - - # # Run the bpf2c tests in GitHub. - # bpf2c: - # # Always run this job. - # needs: regular - # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-test.yml - # with: - # test_command: .\bpf2c_tests.exe -d yes - # name: bpf2c - # build_artifact: Build-x64 - # environment: '["windows-2022"]' - # vs_dev: true - # code_coverage: true - # gather_dumps: true - # capture_etw: true - - # # Run the bpf2c conformance tests in GitHub. - # bpf2c_conformance: - # # Always run this job. - # needs: regular - # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-test.yml - # with: - # pre_test: Invoke-WebRequest https://github.com/Alan-Jowett/bpf_conformance/releases/download/v0.0.6/bpf_conformance_runner.exe -OutFile bpf_conformance_runner.exe - # test_command: .\bpf_conformance_runner.exe --test_file_directory %SOURCE_ROOT%\external\ebpf-verifier\external\bpf_conformance\tests --cpu_version v4 --plugin_path bpf2c_plugin.exe --debug true --plugin_options "--include %SOURCE_ROOT%\include" - # name: bpf2c_conformance - # build_artifact: Build-x64 - # environment: '["windows-2022"]' - # vs_dev: true - # code_coverage: true - # gather_dumps: true - # capture_etw: true + # Run the unit tests in GitHub. + unit_tests_appverif: + # Always run this job. + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: unit_tests + pre_test: appverif -enable Exceptions Handles Heaps Leak Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe + # Exclude [processes] test that CodeCoverage can't work with. + test_command: .\unit_tests.exe -d yes ~[processes] + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: true + gather_dumps: true + capture_etw: true + leak_detection: true + + # Run the unit tests in GitHub. + unit_tests: + # Always run this job. + needs: regular + if: github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' + uses: ./.github/workflows/reusable-test.yml + with: + name: unit_tests + pre_test: appverif -enable Exceptions Handles Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe + # Exclude [processes] test that CodeCoverage can't work with. + test_command: .\unit_tests.exe -d yes ~[processes] + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: true + gather_dumps: true + capture_etw: true + leak_detection: true + + # Run the unit tests for NativeOnly build in GitHub. + unit_tests_native_only: + # Always run this job. + needs: regular_native-only + uses: ./.github/workflows/reusable-test.yml + with: + name: unit_tests + pre_test: appverif -enable Exceptions Handles Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe + # Exclude [processes] test that CodeCoverage can't work with. + test_command: .\unit_tests.exe -d yes ~[processes] + build_artifact: Build-x64-native-only + environment: '["windows-2022"]' + code_coverage: true + gather_dumps: true + capture_etw: true + leak_detection: true + configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' + + # Run the netebpfext unit tests in GitHub. + netebpf_ext_unit_tests: + # Always run this job. + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: netebpf_ext_unit_tests + pre_test: appverif -enable Exceptions Handles Heaps Leak Locks Memory SRWLock Threadpool TLS DangerousAPIs DirtyStacks TimeRollOver -for unit_tests.exe + test_command: .\netebpfext_unit.exe -d yes + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: true + gather_dumps: true + capture_etw: true + leak_detection: true + + # Run the bpf2c tests in GitHub. + bpf2c: + # Always run this job. + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + test_command: .\bpf2c_tests.exe -d yes + name: bpf2c + build_artifact: Build-x64 + environment: '["windows-2022"]' + vs_dev: true + code_coverage: true + gather_dumps: true + capture_etw: true + + # Run the bpf2c conformance tests in GitHub. + bpf2c_conformance: + # Always run this job. + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + pre_test: Invoke-WebRequest https://github.com/Alan-Jowett/bpf_conformance/releases/download/v0.0.6/bpf_conformance_runner.exe -OutFile bpf_conformance_runner.exe + test_command: .\bpf_conformance_runner.exe --test_file_directory %SOURCE_ROOT%\external\ebpf-verifier\external\bpf_conformance\tests --cpu_version v4 --plugin_path bpf2c_plugin.exe --debug true --plugin_options "--include %SOURCE_ROOT%\include" + name: bpf2c_conformance + build_artifact: Build-x64 + environment: '["windows-2022"]' + vs_dev: true + code_coverage: true + gather_dumps: true + capture_etw: true # Run the driver tests on self-hosted runners. driver_ws2019: @@ -314,389 +314,383 @@ jobs: code_coverage: false configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' - # # Run the regression driver tests on self-hosted runners (only for 2022). - # regression_driver_ws2022: - # # Always run this job. - # # Only run this on repos that have self-host runners. - # needs: regular - # if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') - # uses: ./.github/workflows/reusable-test.yml - # with: - # pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" -TestMode "Regression" -RegressionArtifactsVersion "0.17.0" - # test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Regression" - # post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - # name: regression_driver_ws2022 - # build_artifact: Build-x64 - # environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2022"]' - # # driver test copies dumps to testlog folder. - # gather_dumps: false - # # driver tests manually gather code coverage - # code_coverage: false - - # ossar: - # # Always run this job. - # needs: regular - # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/ossar-scan.yml - # with: - # build_artifact: Build-x64 - - # # Additional jobs to run on pull and schedule only (skip push). - # # --------------------------------------------------------------------------- - # # Build with C++ static analyzer. - # analyze: - # # Only run on schedule and pull request. - # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-build.yml - # with: - # ref: ${{ github.ref }} - # repository: ${{ github.repository }} - # build_artifact: Build-x64-Analyze - # # Analysis on external projects is conditional, as on small CI/CD VMs the compiler can run OOM - # build_options: /p:Analysis='True' /p:AnalysisOnExternal='False' - - # # Build with C++ address sanitizer. - # sanitize: - # # Only run on schedule and pull request. - # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-build.yml - # with: - # ref: ${{ github.ref }} - # repository: ${{ github.repository }} - # build_artifact: Build-x64-Sanitize - # build_options: /p:AddressSanitizer='True' - - # bpf2c_fuzzer: - # needs: regular - # if: github.event_name == 'pull_request' || github.event_name == 'merge_group' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: bpf2c_fuzzer - # test_command: .\bpf2c_fuzzer.exe bpf2c_fuzzer_corpus -use_value_profile=1 -max_total_time=300 -artifact_prefix=Artifacts\ - # build_artifact: Build-x64 - # environment: '["windows-2022"]' - # code_coverage: false - # gather_dumps: true - # configurations: '["FuzzerDebug"]' - - # bpf2c_fuzzer_scheduled: - # needs: regular - # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: bpf2c_fuzzer - # test_command: .\bpf2c_fuzzer.exe bpf2c_fuzzer_corpus -use_value_profile=1 -max_total_time=900 -artifact_prefix=Artifacts\ - # build_artifact: Build-x64 - # environment: '["windows-2022"]' - # code_coverage: false - # gather_dumps: true - # configurations: '["FuzzerDebug"]' - - # execution_context_fuzzer: - # needs: regular - # # Always run this job. - # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: execution_context_fuzzer - # test_command: .\execution_context_fuzzer.exe execution_context_fuzzer_corpus -use_value_profile=1 -runs=3000 -artifact_prefix=Artifacts\ - # build_artifact: Build-x64 - # environment: '["windows-2022"]' - # code_coverage: false - # gather_dumps: true - # configurations: '["FuzzerDebug"]' - - # # Run the verifier fuzzer. - # verifier_fuzzer: - # needs: regular - # # Always run this job. - # if: github.event_name == 'pull_request' || github.event_name == 'merge_group' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: verifier_fuzzer - # test_command: .\verifier_fuzzer.exe verifier_corpus -use_value_profile=1 -max_total_time=300 -artifact_prefix=Artifacts\ - # build_artifact: Build-x64 - # environment: '["windows-2022"]' - # code_coverage: false - # gather_dumps: true - # configurations: '["FuzzerDebug"]' - - # verifier_fuzzer_scheduled: - # needs: regular - # # Always run this job. - # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: verifier_fuzzer - # test_command: .\verifier_fuzzer.exe verifier_corpus -use_value_profile=1 -max_total_time=900 -artifact_prefix=Artifacts\ - # build_artifact: Build-x64 - # environment: '["windows-2022"]' - # code_coverage: false - # gather_dumps: true - # configurations: '["FuzzerDebug"]' - - # core_helper_fuzzer: - # needs: regular - # # Always run this job. - # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: core_helper_fuzzer - # test_command: .\core_helper_fuzzer core_helper_corpus -max_len=139 -runs=1000 -use_value_profile=1 -artifact_prefix=Artifacts\ - # build_artifact: Build-x64 - # environment: '["windows-2022"]' - # code_coverage: false - # gather_dumps: true - # configurations: '["FuzzerDebug"]' - - # netebpfext_fuzzer: - # needs: regular - # # Always run this job. - # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: netebpfext_fuzzer - # test_command: .\netebpfext_fuzzer netebpfext_corpus -max_len=12 -runs=1000 -use_value_profile=1 -artifact_prefix=Artifacts\ - # build_artifact: Build-x64 - # environment: '["windows-2022"]' - # code_coverage: false - # gather_dumps: true - # configurations: '["FuzzerDebug"]' - - # # Run Cilium regression tests in GitHub. - # cilium_tests: - # needs: regular - # # Only run on schedule and pull request. - # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: cilium_tests - # test_command: .\cilium_tests.exe -d yes - # build_artifact: Build-x64 - # environment: '["windows-2022"]' - # code_coverage: false - # gather_dumps: true - - # # Run the quick stress tests in GitHub. - # stress: - # needs: regular - # # Only run on schedule and pull request. - # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: stress - # # Until there is a dedicated stress test, re-use the perf test. - # test_command: .\ebpf_performance.exe -d yes - # build_artifact: Build-x64 - # environment: '["windows-2022"]' - # # No code coverage on stress. - # code_coverage: false - # gather_dumps: true - - # # Run the unit tests in GitHub with address sanitizer. - # sanitize_unit_tests: - # needs: sanitize - # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: unit_tests - # # Exclude [processes] test that ASAN can't work with. - # test_command: .\unit_tests.exe -d yes ~[processes] - # build_artifact: Build-x64-Sanitize - # environment: '["windows-2022"]' - # code_coverage: false - # gather_dumps: true - # capture_etw: true - - # # Run the fault injection simulator in GitHub. - # fault_injection: - # needs: regular - # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: fault_injection - # test_command: .\unit_tests.exe - # build_artifact: Build-x64 - # environment: '["windows-2022"]' - # code_coverage: true - # gather_dumps: true - # fault_injection: true - # leak_detection: true - - # # Run the low memory simulator for netebpfext_unit tests. - # fault_injection_netebpfext_unit: - # needs: regular - # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: netebpfext_fault_injection - # test_command: .\netebpfext_unit.exe - # build_artifact: Build-x64 - # environment: '["windows-2022"]' - # code_coverage: true - # gather_dumps: true - # fault_injection: true - # leak_detection: true - - # # Run a fast multi-threaded stress test pass against the usersim user-mode 'mock' framework. - # # Added as a 'per-PR' test to catch usersim regressions and/or run-time usage issues. - # quick_user_mode_multi_threaded_stress_test: - # needs: regular - # if: github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: quick_user_mode_multi_threaded_stress - # test_command: .\ebpf_stress_tests_um -tt=8 -td=2 - # build_artifact: Build-x64 - # environment: '["windows-2022"]' - # code_coverage: false - # leak_detection: false - # gather_dumps: true - # capture_etw: true - - # # Additional jobs to run on a schedule only (skip push and pull request). - # # --------------------------------------------------------------------------- - # codeql: - # # Only run during daily scheduled run - # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-build.yml - # with: - # ref: ${{ github.ref }} - # repository: ${{ github.repository }} - # build_artifact: Build-x64-CodeQl - # build_codeql: true - - - # # Run the complete fault injection simulator in GitHub. - # # Runs on a schedule as this takes a long time to run. - # fault_injection_full: - # needs: regular - # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: fault_injection_full - # test_command: .\unit_tests.exe - # build_artifact: Build-x64 - # environment: '["windows-2022"]' - # code_coverage: false - # gather_dumps: true - # fault_injection: true - # leak_detection: true - - # # Run the complete fault injection simulator for netebpfext in GitHub. - # # Runs on a schedule as this takes a long time to run. - # netebpfext_fault_injection_full: - # needs: regular - # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: netebpfext_fault_injection_full - # test_command: .\netebpfext_unit.exe - # build_artifact: Build-x64 - # environment: '["windows-2022"]' - # code_coverage: false - # gather_dumps: true - # fault_injection: true - - # # Run multi-threaded stress tests against the user mode 'mock' framework. - # user_mode_multi_threaded_stress_test: - # needs: regular - # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: user_mode_multi_threaded_stress - # test_command: .\ebpf_stress_tests_um -tt=8 -td=10 - # build_artifact: Build-x64 - # environment: '["windows-2022"]' - # code_coverage: false - # leak_detection: false - # gather_dumps: true - # capture_etw: true - - # # Run multi-threaded stress tests with 'restart extension' disabled (default behavior) - # # against the kernel mode eBPF sub-system. - # km_mt_stress_tests: - # needs: regular - # # TODO - revert this back - # # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: km_mt_stress_tests - # pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "memory" - # test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Stress" - # post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - # build_artifact: Build-x64 - # environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2019"]' - # code_coverage: false - # # For this test, we only want kernel mode dumps and not user mode dumps. - # gather_dumps: false - - # # Run multi-threaded stress tests with 'restart extension' enabled - # # against the kernel mode eBPF sub-system. - # km_mt_stress_tests_restart_extension: - # needs: regular - # # TODO - revert this back - # # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - # if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: km_mt_stress_tests_restart_extension - # pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "memory" - # test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Stress" -Options @("RestartExtension") - # post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - # build_artifact: Build-x64 - # environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2019"]' - # code_coverage: false - # # For this test, we only want kernel mode dumps and not user mode dumps. - # gather_dumps: false - - # # TODO - figure this out... - # # Not sure what perf is - probably selfhosted runner, but do we need to support this now? - # performance: - # needs: regular - # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/reusable-test.yml - # with: - # name: km_performance - # pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" - # test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Performance" - # post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true - # build_artifact: Build-x64 - # environment: ebpf_cicd_perf_ws2022 - # configurations: '["Release"]' - - # netperf: - # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/netperf.yml - # with: - # sha: ${{ github.sha }} - # ref: ${{ github.ref }} - # pull_request: ${{ github.event.pull_request.number }} - # secrets: - # NET_PERF_TRIGGER: ${{ secrets.NET_PERF_TRIGGER }} - - # upload_perf_results: - # needs: performance - # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/upload-perf-results.yml - # with: - # name: upload_perf_results - # result_artifact: km_performance-x64-Release - # secrets: - # AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} - # AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} - # AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - - # upload_netperf_results_lab_2022: - # needs: netperf - # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - # uses: ./.github/workflows/upload-perf-results.yml - # with: - # name: upload_netperf_results_lab_2022 - # result_artifact: netperf_lab_2022_x64 - # platform: Lab Windows 2022 - # secrets: - # AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} - # AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} - # AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + # Run the regression driver tests on self-hosted runners (only for 2022). + regression_driver_ws2022: + # Always run this job. + # Only run this on repos that have self-host runners. + needs: regular + if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') + uses: ./.github/workflows/reusable-test.yml + with: + pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" -TestMode "Regression" -RegressionArtifactsVersion "0.17.0" + test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Regression" + post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + name: regression_driver_ws2022 + build_artifact: Build-x64 + environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2022"]' + # driver test copies dumps to testlog folder. + gather_dumps: false + # driver tests manually gather code coverage + code_coverage: false + + ossar: + # Always run this job. + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/ossar-scan.yml + with: + build_artifact: Build-x64 + + # Additional jobs to run on pull and schedule only (skip push). + # --------------------------------------------------------------------------- + # Build with C++ static analyzer. + analyze: + # Only run on schedule and pull request. + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-build.yml + with: + ref: ${{ github.ref }} + repository: ${{ github.repository }} + build_artifact: Build-x64-Analyze + # Analysis on external projects is conditional, as on small CI/CD VMs the compiler can run OOM + build_options: /p:Analysis='True' /p:AnalysisOnExternal='False' + + # Build with C++ address sanitizer. + sanitize: + # Only run on schedule and pull request. + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-build.yml + with: + ref: ${{ github.ref }} + repository: ${{ github.repository }} + build_artifact: Build-x64-Sanitize + build_options: /p:AddressSanitizer='True' + + bpf2c_fuzzer: + needs: regular + if: github.event_name == 'pull_request' || github.event_name == 'merge_group' + uses: ./.github/workflows/reusable-test.yml + with: + name: bpf2c_fuzzer + test_command: .\bpf2c_fuzzer.exe bpf2c_fuzzer_corpus -use_value_profile=1 -max_total_time=300 -artifact_prefix=Artifacts\ + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + gather_dumps: true + configurations: '["FuzzerDebug"]' + + bpf2c_fuzzer_scheduled: + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: bpf2c_fuzzer + test_command: .\bpf2c_fuzzer.exe bpf2c_fuzzer_corpus -use_value_profile=1 -max_total_time=900 -artifact_prefix=Artifacts\ + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + gather_dumps: true + configurations: '["FuzzerDebug"]' + + execution_context_fuzzer: + needs: regular + # Always run this job. + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: execution_context_fuzzer + test_command: .\execution_context_fuzzer.exe execution_context_fuzzer_corpus -use_value_profile=1 -runs=3000 -artifact_prefix=Artifacts\ + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + gather_dumps: true + configurations: '["FuzzerDebug"]' + + # Run the verifier fuzzer. + verifier_fuzzer: + needs: regular + # Always run this job. + if: github.event_name == 'pull_request' || github.event_name == 'merge_group' + uses: ./.github/workflows/reusable-test.yml + with: + name: verifier_fuzzer + test_command: .\verifier_fuzzer.exe verifier_corpus -use_value_profile=1 -max_total_time=300 -artifact_prefix=Artifacts\ + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + gather_dumps: true + configurations: '["FuzzerDebug"]' + + verifier_fuzzer_scheduled: + needs: regular + # Always run this job. + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: verifier_fuzzer + test_command: .\verifier_fuzzer.exe verifier_corpus -use_value_profile=1 -max_total_time=900 -artifact_prefix=Artifacts\ + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + gather_dumps: true + configurations: '["FuzzerDebug"]' + + core_helper_fuzzer: + needs: regular + # Always run this job. + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: core_helper_fuzzer + test_command: .\core_helper_fuzzer core_helper_corpus -max_len=139 -runs=1000 -use_value_profile=1 -artifact_prefix=Artifacts\ + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + gather_dumps: true + configurations: '["FuzzerDebug"]' + + netebpfext_fuzzer: + needs: regular + # Always run this job. + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: netebpfext_fuzzer + test_command: .\netebpfext_fuzzer netebpfext_corpus -max_len=12 -runs=1000 -use_value_profile=1 -artifact_prefix=Artifacts\ + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + gather_dumps: true + configurations: '["FuzzerDebug"]' + + # Run Cilium regression tests in GitHub. + cilium_tests: + needs: regular + # Only run on schedule and pull request. + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: cilium_tests + test_command: .\cilium_tests.exe -d yes + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + gather_dumps: true + + # Run the quick stress tests in GitHub. + stress: + needs: regular + # Only run on schedule and pull request. + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: stress + # Until there is a dedicated stress test, re-use the perf test. + test_command: .\ebpf_performance.exe -d yes + build_artifact: Build-x64 + environment: '["windows-2022"]' + # No code coverage on stress. + code_coverage: false + gather_dumps: true + + # Run the unit tests in GitHub with address sanitizer. + sanitize_unit_tests: + needs: sanitize + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: unit_tests + # Exclude [processes] test that ASAN can't work with. + test_command: .\unit_tests.exe -d yes ~[processes] + build_artifact: Build-x64-Sanitize + environment: '["windows-2022"]' + code_coverage: false + gather_dumps: true + capture_etw: true + + # Run the fault injection simulator in GitHub. + fault_injection: + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: fault_injection + test_command: .\unit_tests.exe + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: true + gather_dumps: true + fault_injection: true + leak_detection: true + + # Run the low memory simulator for netebpfext_unit tests. + fault_injection_netebpfext_unit: + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: netebpfext_fault_injection + test_command: .\netebpfext_unit.exe + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: true + gather_dumps: true + fault_injection: true + leak_detection: true + + # Run a fast multi-threaded stress test pass against the usersim user-mode 'mock' framework. + # Added as a 'per-PR' test to catch usersim regressions and/or run-time usage issues. + quick_user_mode_multi_threaded_stress_test: + needs: regular + if: github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' + uses: ./.github/workflows/reusable-test.yml + with: + name: quick_user_mode_multi_threaded_stress + test_command: .\ebpf_stress_tests_um -tt=8 -td=2 + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + leak_detection: false + gather_dumps: true + capture_etw: true + + # Additional jobs to run on a schedule only (skip push and pull request). + # --------------------------------------------------------------------------- + codeql: + # Only run during daily scheduled run + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-build.yml + with: + ref: ${{ github.ref }} + repository: ${{ github.repository }} + build_artifact: Build-x64-CodeQl + build_codeql: true + + + # Run the complete fault injection simulator in GitHub. + # Runs on a schedule as this takes a long time to run. + fault_injection_full: + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: fault_injection_full + test_command: .\unit_tests.exe + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + gather_dumps: true + fault_injection: true + leak_detection: true + + # Run the complete fault injection simulator for netebpfext in GitHub. + # Runs on a schedule as this takes a long time to run. + netebpfext_fault_injection_full: + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: netebpfext_fault_injection_full + test_command: .\netebpfext_unit.exe + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + gather_dumps: true + fault_injection: true + + # Run multi-threaded stress tests against the user mode 'mock' framework. + user_mode_multi_threaded_stress_test: + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: user_mode_multi_threaded_stress + test_command: .\ebpf_stress_tests_um -tt=8 -td=10 + build_artifact: Build-x64 + environment: '["windows-2022"]' + code_coverage: false + leak_detection: false + gather_dumps: true + capture_etw: true + + # Run multi-threaded stress tests with 'restart extension' disabled (default behavior) + # against the kernel mode eBPF sub-system. + km_mt_stress_tests: + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: km_mt_stress_tests + pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "memory" + test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Stress" + post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + build_artifact: Build-x64 + environment: '["ebpf_cicd_tests_ws2019"]' + code_coverage: false + # For this test, we only want kernel mode dumps and not user mode dumps. + gather_dumps: false + + # Run multi-threaded stress tests with 'restart extension' enabled + # against the kernel mode eBPF sub-system. + km_mt_stress_tests_restart_extension: + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: km_mt_stress_tests_restart_extension + pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "memory" + test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Stress" -Options @("RestartExtension") + post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + build_artifact: Build-x64 + environment: '["ebpf_cicd_tests_ws2019"]' + code_coverage: false + # For this test, we only want kernel mode dumps and not user mode dumps. + gather_dumps: false + + performance: + needs: regular + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/reusable-test.yml + with: + name: km_performance + pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" + test_command: .\execute_ebpf_cicd_tests.ps1 -TestMode "Performance" + post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true + build_artifact: Build-x64 + environment: '["ebpf_cicd_perf_ws2022"]' + configurations: '["Release"]' + + netperf: + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/netperf.yml + with: + sha: ${{ github.sha }} + ref: ${{ github.ref }} + pull_request: ${{ github.event.pull_request.number }} + secrets: + NET_PERF_TRIGGER: ${{ secrets.NET_PERF_TRIGGER }} + + upload_perf_results: + needs: performance + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/upload-perf-results.yml + with: + name: upload_perf_results + result_artifact: km_performance-x64-Release + secrets: + AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} + AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} + AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + + upload_netperf_results_lab_2022: + needs: netperf + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + uses: ./.github/workflows/upload-perf-results.yml + with: + name: upload_netperf_results_lab_2022 + result_artifact: netperf_lab_2022_x64 + platform: Lab Windows 2022 + secrets: + AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} + AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} + AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} From 82dfbe3ef61d5870373d860b991c25397cabeb61 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 29 Jan 2025 14:55:40 -0800 Subject: [PATCH 186/190] move WS2025 to scheduled runs only for now --- .github/workflows/cicd.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 4d401eddd0..9a733ff3e7 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -239,10 +239,8 @@ jobs: # Run the driver tests on self-hosted runners. driver_ws2025: - # Always run this job. - # Only run this on repos that have self-host runners. - needs: regular - if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') + # Only run during daily scheduled run + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' uses: ./.github/workflows/reusable-test.yml with: pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" @@ -296,10 +294,8 @@ jobs: configurations: '["NativeOnlyDebug", "NativeOnlyRelease"]' driver_native_only_ws2025: - # Always run this job. - # Only run this on repos that have self-host runners. - needs: regular_native-only - if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') + # Only run during daily scheduled run + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' uses: ./.github/workflows/reusable-test.yml with: pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" From 66a7fde7956f6ec5520b640b0a3b9a8b5b238e34 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 29 Jan 2025 15:22:40 -0800 Subject: [PATCH 187/190] fix --- .github/workflows/cicd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 9a733ff3e7..32b59ce81c 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -323,7 +323,7 @@ jobs: post_test: .\cleanup_ebpf_cicd_tests.ps1 -KmTracing $true name: regression_driver_ws2022 build_artifact: Build-x64 - environment: '["self-hosted", "1ES.Pool=ebpf-cicd-runner-pool-server-2019", "1ES.ImageOverride=server2022"]' + environment: '["ebpf_cicd_tests_ws2022"]' # driver test copies dumps to testlog folder. gather_dumps: false # driver tests manually gather code coverage From 3eca94cabaa077fa991bd8c7345f00f5afba54ff Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 29 Jan 2025 15:46:07 -0800 Subject: [PATCH 188/190] run 2025 tests one final time --- .github/workflows/cicd.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 32b59ce81c..f8c71f852c 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -240,7 +240,9 @@ jobs: # Run the driver tests on self-hosted runners. driver_ws2025: # Only run during daily scheduled run - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + # TODO - revert this after a successful build + # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') uses: ./.github/workflows/reusable-test.yml with: pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" @@ -295,7 +297,9 @@ jobs: driver_native_only_ws2025: # Only run during daily scheduled run - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + # TODO - revert this after a successful build + # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') uses: ./.github/workflows/reusable-test.yml with: pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" From 843a8cd6e98352303ced1dce44cccc0b5f305020 Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 29 Jan 2025 17:03:55 -0800 Subject: [PATCH 189/190] fix missing field in yml --- .github/workflows/cicd.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index f8c71f852c..2081a4c43d 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -240,6 +240,7 @@ jobs: # Run the driver tests on self-hosted runners. driver_ws2025: # Only run during daily scheduled run + needs: regular # TODO - revert this after a successful build # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') @@ -298,6 +299,7 @@ jobs: driver_native_only_ws2025: # Only run during daily scheduled run # TODO - revert this after a successful build + needs: regular_native-only # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') uses: ./.github/workflows/reusable-test.yml From 6bfbd43b5621ef60fb77905c74174302b94aa95b Mon Sep 17 00:00:00 2001 From: "Matt Ige (from Dev Box)" <maige@microsoft.com> Date: Wed, 29 Jan 2025 19:31:34 -0800 Subject: [PATCH 190/190] set the ws2025 tests to scheduled --- .github/workflows/cicd.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 2081a4c43d..b0bf1c162f 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -241,9 +241,7 @@ jobs: driver_ws2025: # Only run during daily scheduled run needs: regular - # TODO - revert this after a successful build - # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' uses: ./.github/workflows/reusable-test.yml with: pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file" @@ -298,10 +296,8 @@ jobs: driver_native_only_ws2025: # Only run during daily scheduled run - # TODO - revert this after a successful build needs: regular_native-only - # if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' - if: github.repository == 'microsoft/ebpf-for-windows' && (github.event_name == 'schedule' || github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' uses: ./.github/workflows/reusable-test.yml with: pre_test: .\setup_ebpf_cicd_tests.ps1 -KmTracing $true -KmTraceType "file"