-
Notifications
You must be signed in to change notification settings - Fork 205
Dev p3.0/param testcases #879
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
Conversation
…into p-org-paramtest
* update assumption * fix: add deps back * refactor: constant -> param * fix * clean the code * unify normal/param/assume tests * clean the code * rename * merging safety test parser rules * clean the code * Update github CI action v2 to v3 * iUpdate github CI action v2 to v3 on ubuntu * rename variable "param" into "parameter" to avoid keyword conflicts
* add twise * clean the code
* Solved Concerns from Lewis: + new allow twise number be 1 + unify twise number valid condition + add unit test * add new test case * unit test for ParamAssignment.IterateAssignments
* Update build system and Java compiler, remove dependency JARs * Update CheckerCore logging and state machine components
…ametric test (#875) Co-authored-by: Christine Zhou <[email protected]>
| run: dotnet build --configuration Release | ||
| - name: Test | ||
| run: dotnet test --configuration Release | ||
| run: dotnet test --configuration Release --blame-crash --blame-hang --blame-hang-timeout 300s --logger:"console;verbosity=detailed" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please explain this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is to get better logs when the GitHub Action fails. Without it, we just see that something crashed, but not what caused it. With these flags, we get more detailed output and can tell which test hung or crashed, which makes debugging a lot easier.
| Console.Out.WriteLine($"{mi.DeclaringType.Name}"); | ||
| } | ||
|
|
||
| Environment.Exit(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed because, for parametric tests, we have to fetch all the test case names using this function. The problem is that it calls Environment.Exit(0), which ends the entire regression test run early. So we had to handle it differently to avoid stopping the whole suite.
| public bool HasCompilationStage => true; | ||
| private static List<Variable> _globalParams = []; | ||
| [ThreadStatic] | ||
| private static List<Variable> _globalParams; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was causing issues when I ran regression tests in parallel. Since _globalParams was static, all the tests were sharing the same list, which led to conflicts. Adding [ThreadStatic] makes sure each test thread gets its own copy, so they don’t mess with each other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead, can we just make it non-static?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a global variable which can't be made non-static, otherwise it defeats the purpose of global variable.
| // write the top level declarations | ||
| foreach (var decl in globalScope.AllDecls) | ||
| { | ||
| // Console.WriteLine("top-level decl: " + decl.Name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make a pass to remove unwanted changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR merges parametric test cases into major version 3.0, introducing support for parameterized testing functionality within the P language testing framework. The changes implement a comprehensive system for running and validating parametric tests with various parameter combinations.
- Adds parametric test infrastructure with test case discovery and validation
- Enhances test runners to handle parameter-based test execution
- Improves test reliability with retry mechanisms and better error handling
Reviewed Changes
Copilot reviewed 20 out of 21 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| Tst/UnitTests/TestAssertions.cs | Added Thread.Sleep retry logic for directory deletion and improved error output |
| Tst/UnitTests/Runners/PCheckerRunner.cs | Major refactor to support parametric test discovery, validation, and in-process execution |
| Tst/UnitTests/PCheckerLogGeneratorTests.cs | Updated test to use source-based naming instead of hardcoded "Main" |
| Multiple .p test files | Added new parametric test cases with parameter definitions and test declarations |
| Src/PCompiler/CompilerCore/TypeChecker/ParamVisitor.cs | Added validation to prevent equal start/end values in parameter ranges |
| Src/PChecker/CheckerCore/Checker.cs | Enhanced checker to handle test case listing mode |
| .github/workflows/macosci.yml | Improved CI configuration with detailed logging and test result uploads |
Tst/RegressionTests/Feature1SMLevelDecls/Correct/ParamTest/ParamTest.p
Outdated
Show resolved
Hide resolved
Tst/RegressionTests/Feature1SMLevelDecls/Correct/ParamTest/ParamTest.p
Outdated
Show resolved
Hide resolved
Tst/RegressionTests/Feature1SMLevelDecls/Correct/ParamTest/ParamTest.p
Outdated
Show resolved
Hide resolved
Tst/RegressionTests/Feature1SMLevelDecls/Correct/ParamTest/ParamTest.p
Outdated
Show resolved
Hide resolved
Tst/RegressionTests/Feature1SMLevelDecls/StaticError/ParamTest3/ParamTest3.p
Outdated
Show resolved
Hide resolved
Tst/RegressionTests/Feature1SMLevelDecls/StaticError/ParamTest4/ParamTest4.p
Outdated
Show resolved
Hide resolved
Tst/RegressionTests/Feature1SMLevelDecls/DynamicError/ParamTest2/ParamTest2.p
Outdated
Show resolved
Hide resolved
Tst/RegressionTests/Feature1SMLevelDecls/DynamicError/ParamTest2/ParamTest2.p
Outdated
Show resolved
Hide resolved
lewisbru
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, resolve the various copilot recommendations and fix the typos
| using PChecker.IO.Logging; | ||
| using PChecker.SystematicTesting; | ||
| using PChecker.Testing; | ||
| using PChecker.SystematicTesting; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: why the reordering? All of the formatting conventions I know of recommend alike imports/usings to be in alphabetical order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will revert the reordering change here
Src/PChecker/CheckerCore/Checker.cs
Outdated
| { | ||
| case CheckerMode.BugFinding: | ||
| TestingProcess.Create(configuration).Run(); | ||
| var testingEngine = TestingProcess.Create(configuration); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why create the testingEngine before checking configuration.ListTestCases? TestingProcess.Create() change the configuration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still call TestingProcess.Create() even when configuration.ListTestCases is true because the logic to list test cases lives inside the Create() method. That method is responsible for discovering and printing the available test cases, so we need to call it regardless.
The reason for making this change now is that the original implementation used Environment.Exit to terminate after listing test cases. This caused issues when running tests in-process because Environment.Exit would terminate the entire test run, not just the individual test. To fix this, I replaced the exit call with a simple return, which exits the method cleanly without affecting other tests.
| public bool HasCompilationStage => true; | ||
| private static List<Variable> _globalParams = []; | ||
| [ThreadStatic] | ||
| private static List<Variable> _globalParams; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead, can we just make it non-static?
Src/PCompiler/CompilerCore/Backend/PChecker/PCheckerCodeGenerator.cs
Outdated
Show resolved
Hide resolved
| if (values.Count == 2 && | ||
| values[0] is IntLiteralExpr first && | ||
| values[1] is IntLiteralExpr second && | ||
| first.Value == second.Value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this exception check too limited? I think it should verify that first.Value < secondValue.
| start state Init { | ||
| entry { | ||
| print format("global varaible g1 = {0}", g1); | ||
| print format("global varaible g2 = {0}", g2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix indent
| { | ||
| throw handler.InternalError(context, new Exception("Invalid range: start and end must not be equal (e.g., [2, 2] is not allowed)")); } | ||
|
|
||
| if (values.Count == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is copied from the original code, but what does a sequence of 0 values mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it is supposed to be an empty sequence, I don't think PrimitiveType.Int is an appropriate default?
| @@ -0,0 +1,33 @@ | |||
| param g1 : int; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The param types in the test should include all of the allowed types; if they have to be int, then there should be a negative test with non-int param types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a new param (g5) for boolean
|
|
||
| test BasicNonParametricTest [main=Main]:{Main}; | ||
|
|
||
| test param (g1 in [1, 2], g2 in [3, 4], g3 in [5, 6], g4 in [7, 8]) FullCartesianProductParametricTest [main=Main]:{Main}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Especially given the special handling of two int sequences above; there should be more variation of possible values:
- single int sequence
- two int sequence that is a range
- two int sequence that is not a range?
-
two int sequence
7ab51ff to
ef6b7b5
Compare
| print format("global variable g1 = {0}", g1); | ||
| print format("global variable g2 = {0}", g2); | ||
| print format("global variable g3 = {0}", g3); | ||
| print format("global variable g4 = {0}", g4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add print for g5 here.
| test BasicNonParametricTest [main=Main]:{Main}; | ||
|
|
||
| test param (g1 in [1, 2], g2 in [3, 4], g3 in [5, 6], g4 in [7, 8]) FullCartesianProductParametricTest [main=Main]:{Main}; | ||
| test param (g1 in [-1, 2], g2 in [3, 4], g3 in [5, 6], g4 in [7, 8], g5 in [true, false]) FullCartesianProductParametricTest [main=Main]:{Main}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhere in here include some cases where one of the parameters has more than two values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point! I'll add some cases for that
ef6b7b5 to
0a8c3b8
Compare
Merging param test cases branch into major 3.0