Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ChristineZh0u
Copy link
Contributor

Merging param test cases branch into major 3.0

zhezhouzz and others added 28 commits June 11, 2024 13:58
* 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
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"
Copy link
Member

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?

Copy link
Contributor Author

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Contributor Author

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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);
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

@ankushdesai
Copy link
Member

@lewisbru @aishu-j can I get reviews on this PR; would like to get this merged.

Copy link
Contributor

Copilot AI left a 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

Copy link
Contributor

@lewisbru lewisbru left a 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;
Copy link
Contributor

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.

Copy link
Contributor Author

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

{
case CheckerMode.BugFinding:
TestingProcess.Create(configuration).Run();
var testingEngine = TestingProcess.Create(configuration);
Copy link
Contributor

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?

Copy link
Contributor Author

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;
Copy link
Contributor

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?

if (values.Count == 2 &&
values[0] is IntLiteralExpr first &&
values[1] is IntLiteralExpr second &&
first.Value == second.Value)
Copy link
Contributor

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);
Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Contributor

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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};
Copy link
Contributor

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

@p-org p-org deleted a comment from Copilot AI Jul 13, 2025
@p-org p-org deleted a comment from Copilot AI Jul 13, 2025
@ChristineZh0u ChristineZh0u force-pushed the dev_p3.0/param_testcases branch from 7ab51ff to ef6b7b5 Compare July 13, 2025 19:48
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);
Copy link
Contributor

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};
Copy link
Contributor

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.

Copy link
Contributor Author

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

@ChristineZh0u ChristineZh0u force-pushed the dev_p3.0/param_testcases branch from ef6b7b5 to 0a8c3b8 Compare July 14, 2025 16:35
@ankushdesai ankushdesai merged commit cedacd2 into major/P3.0 Jul 22, 2025
10 checks passed
@ankushdesai ankushdesai deleted the dev_p3.0/param_testcases branch July 22, 2025 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants