-
Notifications
You must be signed in to change notification settings - Fork 12
[MrBot] Add timed test suite validation to build_test_folder #277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
parth21999
wants to merge
4
commits into
master
Choose a base branch
from
paaggarwal/timed-test-suite-validation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
853d82e
Add timed test suite validation to build_test_folder
parth21999 6688eed
Address PR comments: rename param, remove exemption logic
parth21999 fddeee3
Remove -Fix logic, move script to scripts/ and tests to tests/
parth21999 5404fa5
Add NumExpectedViolations flag, use CMake function in tests, add skip…
parth21999 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| # Copyright (c) Microsoft. All rights reserved. | ||
| # Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| Validates that integration test files use TIMED_TEST_SUITE_INITIALIZE/CLEANUP macros. | ||
|
|
||
| .DESCRIPTION | ||
| This script checks integration test files (*_int.c) in a given test folder to ensure | ||
| they use the timed versions of TEST_SUITE_INITIALIZE and TEST_SUITE_CLEANUP macros. | ||
| The timed macros (TIMED_TEST_SUITE_INITIALIZE / TIMED_TEST_SUITE_CLEANUP) wrap the | ||
| vanilla versions with a process watchdog that crashes the process and produces a dump | ||
| on timeout, allowing dumps to be collected if the test hangs. | ||
|
|
||
| .PARAMETER TestFolder | ||
| The path to the test folder to validate. | ||
|
|
||
| .PARAMETER NumExpectedViolations | ||
| The number of files expected to have violations. When the actual violation count matches | ||
| this value, the script exits with code 0. Default is 0 (no violations expected). | ||
|
|
||
| .EXAMPLE | ||
| .\validate_timed_test_suite.ps1 -TestFolder "C:\repo\tests\my_module_int" | ||
|
|
||
| Validates integration test files in the folder and reports files using non-timed macros. | ||
|
|
||
| .NOTES | ||
| Returns exit code 0 if violation count matches NumExpectedViolations, 1 otherwise. | ||
| #> | ||
|
|
||
| param( | ||
| [Parameter(Mandatory=$true)] | ||
| [string]$TestFolder, | ||
|
|
||
| [Parameter(Mandatory=$false)] | ||
| [int]$NumExpectedViolations = 0 | ||
| ) | ||
|
|
||
| # Set error action preference | ||
| $ErrorActionPreference = "Stop" | ||
|
|
||
| Write-Host "========================================" -ForegroundColor Cyan | ||
| Write-Host "Timed Test Suite Validation" -ForegroundColor Cyan | ||
| Write-Host "========================================" -ForegroundColor Cyan | ||
| Write-Host "Test Folder: $TestFolder" -ForegroundColor White | ||
| if ($NumExpectedViolations -gt 0) { | ||
| Write-Host "Expected Violations: $NumExpectedViolations" -ForegroundColor White | ||
| } | ||
| Write-Host "" | ||
|
|
||
| # Get all integration test files in the folder | ||
| Write-Host "Searching for integration test files (*_int.c)..." -ForegroundColor White | ||
| $allFiles = @(Get-ChildItem -Path $TestFolder -Recurse -Filter "*_int.c" -ErrorAction SilentlyContinue) | ||
|
|
||
| Write-Host "Found $($allFiles.Count) integration test files to check" -ForegroundColor White | ||
| Write-Host "" | ||
|
|
||
| # Pattern to match non-timed TEST_SUITE_INITIALIZE/CLEANUP | ||
| # Uses negative lookbehind to exclude lines that already have TIMED_ prefix | ||
| $initPattern = '(?<!TIMED_)TEST_SUITE_INITIALIZE\s*\(' | ||
| $cleanupPattern = '(?<!TIMED_)TEST_SUITE_CLEANUP\s*\(' | ||
|
|
||
| $totalFiles = 0 | ||
| $filesWithViolations = @() | ||
|
|
||
| foreach ($file in $allFiles) { | ||
| $totalFiles++ | ||
|
|
||
| # Read file content as lines | ||
| try { | ||
| $lines = Get-Content -Path $file.FullName -ErrorAction Stop | ||
| } | ||
| catch { | ||
| Write-Host " [WARN] Cannot read file: $($file.FullName)" -ForegroundColor Yellow | ||
| continue | ||
| } | ||
|
|
||
| $matchingLines = @() | ||
| $lineNumber = 0 | ||
| foreach ($line in $lines) { | ||
| $lineNumber++ | ||
| if ($line -match $initPattern -or $line -match $cleanupPattern) { | ||
| $matchingLines += [PSCustomObject]@{ | ||
| LineNumber = $lineNumber | ||
| Content = $line.Trim() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if ($matchingLines.Count -gt 0) { | ||
| Write-Host " [FAIL] $($file.FullName)" -ForegroundColor Red | ||
| Write-Host " Contains $($matchingLines.Count) non-timed TEST_SUITE macro(s)" -ForegroundColor Yellow | ||
|
|
||
| foreach ($match in $matchingLines) { | ||
| Write-Host " Line $($match.LineNumber): $($match.Content)" -ForegroundColor Yellow | ||
| } | ||
|
|
||
| $filesWithViolations += [PSCustomObject]@{ | ||
| FilePath = $file.FullName | ||
| MatchCount = $matchingLines.Count | ||
| Matches = $matchingLines | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Write-Host "" | ||
| Write-Host "========================================" -ForegroundColor Cyan | ||
| Write-Host "Validation Summary" -ForegroundColor Cyan | ||
| Write-Host "========================================" -ForegroundColor Cyan | ||
| Write-Host "Total integration test files checked: $totalFiles" -ForegroundColor White | ||
parth21999 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if ($filesWithViolations.Count -gt 0) { | ||
| Write-Host "Files with non-timed macros: $($filesWithViolations.Count)" -ForegroundColor Red | ||
| Write-Host "" | ||
| Write-Host "The following files use TEST_SUITE_INITIALIZE/CLEANUP instead of timed versions:" -ForegroundColor Yellow | ||
|
|
||
| foreach ($item in $filesWithViolations) { | ||
| Write-Host " - $($item.FilePath) ($($item.MatchCount) macro(s))" -ForegroundColor White | ||
| } | ||
|
|
||
| Write-Host "" | ||
| Write-Host "Integration tests should use TIMED_TEST_SUITE_INITIALIZE and" -ForegroundColor Cyan | ||
| Write-Host "TIMED_TEST_SUITE_CLEANUP from c_pal/timed_test_suite.h to allow" -ForegroundColor Cyan | ||
| Write-Host "dumps to be collected if the test hangs." -ForegroundColor Cyan | ||
| Write-Host "" | ||
| } | ||
|
|
||
| if ($filesWithViolations.Count -eq $NumExpectedViolations) { | ||
| Write-Host "[VALIDATION PASSED]" -ForegroundColor Green | ||
| exit 0 | ||
| } else { | ||
| Write-Host "[VALIDATION FAILED] Expected $NumExpectedViolations violation(s), found $($filesWithViolations.Count)" -ForegroundColor Red | ||
| exit 1 | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
build_functions/tests/validate_timed_test_suite/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Copyright (c) Microsoft. All rights reserved. | ||
| # Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| # | ||
| # Timed Test Suite Validation Tests | ||
| # | ||
| # Tests the validate_timed_test_suite CMake function and underlying script. | ||
| # | ||
|
|
||
| # Test 1: Clean files pass validation (0 expected violations) | ||
| validate_timed_test_suite(no_violations) | ||
|
|
||
| # Test 2: Detection of violations (3 files with violations expected) | ||
| validate_timed_test_suite(has_violations NUM_EXPECTED_VIOLATIONS 3) | ||
|
|
||
| # Test 3: Skip regex causes check to be skipped | ||
| set(timed_test_suite_skip_regex "skipped_folder_int") | ||
| validate_timed_test_suite(skipped_folder_int) | ||
| if(TARGET skipped_folder_int_timed_suite_check) | ||
| message(FATAL_ERROR "skipped_folder_int should have been skipped by regex but target was created") | ||
| endif() | ||
| unset(timed_test_suite_skip_regex) | ||
|
|
||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests should use the cmake function validate_timed_test_suite. Add a test cases where the skip regex causes the check to be skipped. |
||
| # Master target for all timed test suite validation tests | ||
| add_custom_target(test_validate_timed_test_suite | ||
| COMMENT "Running all timed test suite validation tests" | ||
| ) | ||
|
|
||
| add_dependencies(test_validate_timed_test_suite | ||
| no_violations_timed_suite_check | ||
| has_violations_timed_suite_check | ||
| ) | ||
16 changes: 16 additions & 0 deletions
16
build_functions/tests/validate_timed_test_suite/has_violations/has_include_int.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #include "testrunnerswitcher.h" | ||
| #include "c_pal/gballoc_hl.h" | ||
| #include "c_pal/timed_test_suite.h" | ||
|
|
||
| BEGIN_TEST_SUITE(has_include_int) | ||
| TEST_SUITE_INITIALIZE(suite_init) | ||
| { | ||
| } | ||
| TEST_SUITE_CLEANUP(suite_cleanup) | ||
| { | ||
| } | ||
| TEST_FUNCTION(test1) | ||
| { | ||
| ASSERT_IS_TRUE(1); | ||
| } | ||
| END_TEST_SUITE(has_include_int) |
15 changes: 15 additions & 0 deletions
15
build_functions/tests/validate_timed_test_suite/has_violations/multi_arg_int.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #include "testrunnerswitcher.h" | ||
| #include "c_pal/gballoc_hl.h" | ||
|
|
||
| BEGIN_TEST_SUITE(multi_arg_int) | ||
| TEST_SUITE_INITIALIZE(suite_init, setup_gballoc) | ||
| { | ||
| } | ||
| TEST_SUITE_CLEANUP(suite_cleanup, cleanup_gballoc) | ||
| { | ||
| } | ||
| TEST_FUNCTION(test1) | ||
| { | ||
| ASSERT_IS_TRUE(1); | ||
| } | ||
| END_TEST_SUITE(multi_arg_int) |
15 changes: 15 additions & 0 deletions
15
build_functions/tests/validate_timed_test_suite/has_violations/sample_module_int.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #include "testrunnerswitcher.h" | ||
| #include "c_pal/gballoc_hl.h" | ||
|
|
||
| BEGIN_TEST_SUITE(sample_module_int) | ||
| TEST_SUITE_INITIALIZE(suite_init) | ||
| { | ||
| } | ||
| TEST_SUITE_CLEANUP(suite_cleanup) | ||
| { | ||
| } | ||
| TEST_FUNCTION(test1) | ||
| { | ||
| ASSERT_IS_TRUE(1); | ||
| } | ||
| END_TEST_SUITE(sample_module_int) |
9 changes: 9 additions & 0 deletions
9
build_functions/tests/validate_timed_test_suite/no_violations/no_init_int.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #include "testrunnerswitcher.h" | ||
| #include "c_pal/gballoc_hl.h" | ||
|
|
||
| BEGIN_TEST_SUITE(no_init_int) | ||
| TEST_FUNCTION(test1) | ||
| { | ||
| ASSERT_IS_TRUE(1); | ||
| } | ||
| END_TEST_SUITE(no_init_int) |
16 changes: 16 additions & 0 deletions
16
build_functions/tests/validate_timed_test_suite/no_violations/timed_module_int.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #include "testrunnerswitcher.h" | ||
| #include "c_pal/gballoc_hl.h" | ||
| #include "c_pal/timed_test_suite.h" | ||
|
|
||
| BEGIN_TEST_SUITE(timed_module_int) | ||
| TIMED_TEST_SUITE_INITIALIZE(suite_init, TIMED_TEST_DEFAULT_TIMEOUT_MS) | ||
| { | ||
| } | ||
| TIMED_TEST_SUITE_CLEANUP(suite_cleanup) | ||
| { | ||
| } | ||
| TEST_FUNCTION(test1) | ||
| { | ||
| ASSERT_IS_TRUE(1); | ||
| } | ||
| END_TEST_SUITE(timed_module_int) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.