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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6be2b01
Add global constant varaibles; TODO backend
zhezhouzz Jun 11, 2024
82637c6
Updated BuildGlobalScope
zhezhouzz Jun 11, 2024
7b55329
add global variable
zhezhouzz Jun 12, 2024
8cfe5c9
fix global variable types
zhezhouzz Jun 12, 2024
d630b9f
Allow multiple tests
zhezhouzz Jun 12, 2024
f39c431
Add int list literal syntax
zhezhouzz Jun 13, 2024
246d1d6
add parametric test
zhezhouzz Jun 13, 2024
71b519b
Quick-fix
zhezhouzz Jun 13, 2024
740de07
fix bad quick-fix
zhezhouzz Jun 13, 2024
5def42a
add rich syntax
zhezhouzz Jun 13, 2024
38dbf6d
Merge branch 'master' into paramtest
zhezhouzz Jun 17, 2024
08ee970
Merge branch 'mainp' into paramtest
zhezhouzz Jul 16, 2024
57d7c4b
Merge branch 'paramtest' of github.com:p-org/P-TestGeneration into pa…
zhezhouzz Jul 16, 2024
1a9754d
Merge branch 'master' into paramtest
zhezhouzz Aug 21, 2024
50463f5
Merge branch 'master' into paramtest
ankushdesai Dec 4, 2024
658c304
Merge branch 'paramtest' of https://github.com/p-org/P-TestGeneration…
ankushdesai Dec 4, 2024
924eced
Merge branch 'p-org-paramtest' into dev_p3.0/param_testcases
ankushdesai Dec 4, 2024
60d3fb4
Small merge error
ankushdesai Dec 4, 2024
bd3d167
Param (#833)
zhezhouzz Mar 19, 2025
c7e86ab
T-wise combinatorial test (#837)
zhezhouzz Mar 31, 2025
ef898a0
T-wise combinatorial (Solved Concerns from Lewis) (#838)
zhezhouzz Apr 8, 2025
55a1199
Dev/remove libhandler (#847)
ankushdesai Apr 24, 2025
c5c6c72
Update build system and Java compiler, remove dependency JARs (#849)
ankushdesai Apr 24, 2025
28833bf
Merge branch 'master' into major/P3.0
ankushdesai Apr 25, 2025
5c77847
Merge branch 'major/P3.0' into dev_p3.0/param_testcases
ankushdesai Apr 29, 2025
a4a6195
Modified regression tests to run in process, added test cases for par…
ChristineZh0u Jun 29, 2025
e8c605a
resolve merging conflict
Jun 30, 2025
5320e40
Fix pex regression test
Jun 30, 2025
936c47e
remove unnecessary line
Jul 2, 2025
0a8c3b8
Addressing PR comments
Jul 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/macosci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ jobs:
- name: Build
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.

- name: Upload Test Results
uses: actions/upload-artifact@v4
if: always() # This ensures it runs even after test failure
with:
name: test-results
path: Tst/UnitTests/TestResults/**/*.xml
5 changes: 5 additions & 0 deletions Src/PChecker/CheckerCore/Checker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public static void Run(CheckerConfiguration configuration)
switch (configuration.Mode)
{
case CheckerMode.BugFinding:
if (configuration.ListTestCases)
{
TestingProcess.FetchTestCases(configuration);
break;
}
TestingProcess.Create(configuration).Run();
break;
case CheckerMode.PEx:
Expand Down
24 changes: 2 additions & 22 deletions Src/PChecker/CheckerCore/SystematicTesting/TestingEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,28 +176,8 @@ public static TestingEngine Create(CheckerConfiguration checkerConfiguration) =>
/// <summary>
/// Creates a new systematic testing engine.
/// </summary>
public static TestingEngine Create(CheckerConfiguration checkerConfiguration, Assembly assembly)
private static TestingEngine Create(CheckerConfiguration checkerConfiguration, Assembly assembly)
{
if (checkerConfiguration.ListTestCases)
{
try
{
var testMethods = TestMethodInfo.GetAllTestMethodsFromAssembly(assembly);
Console.Out.WriteLine($".. List of test cases (total {testMethods.Count})");

foreach (var mi in testMethods)
{
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.

}
catch
{
Error.ReportAndExit($"Failed to list test methods from assembly '{assembly.FullName}'");
}
}

TestMethodInfo testMethodInfo = null;
try
{
Expand Down Expand Up @@ -891,7 +871,7 @@ private T Activate<T>(string assemblyQualifiedName)
/// <summary>
/// Loads and returns the specified assembly.
/// </summary>
private static Assembly LoadAssembly(string assemblyFile)
public static Assembly LoadAssembly(string assemblyFile)
{
Assembly assembly = null;

Expand Down
22 changes: 22 additions & 0 deletions Src/PChecker/CheckerCore/Testing/TestingProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

using System;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using PChecker.IO.Debugging;
using PChecker.SystematicTesting;
using PChecker.Utilities;

Expand Down Expand Up @@ -99,6 +101,26 @@ private async Task RunAsync()
}
}

public static void FetchTestCases(CheckerConfiguration checkerConfiguration)
{
Assembly assembly = TestingEngine.LoadAssembly(checkerConfiguration.AssemblyToBeAnalyzed);
try
{
var testMethods = TestMethodInfo.GetAllTestMethodsFromAssembly(assembly);
Console.Out.WriteLine($".. List of test cases (total {testMethods.Count})");

foreach (var mi in testMethods)
{
Console.Out.WriteLine($"{mi.DeclaringType.Name}");
}
}
catch
{
Error.ReportAndExit($"Failed to list test methods from assembly '{assembly.FullName}'");
}

}

/// <summary>
/// Initializes a new instance of the <see cref="TestingProcess"/> class.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.IO;
using System.Linq;
using System.Reflection;
Expand All @@ -21,7 +22,8 @@ public class PCheckerCodeGenerator : ICodeGenerator
/// This compiler has a compilation stage.
/// </summary>
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.


private string GetGlobalParamAndLocalVariableName(CompilationContext context, Variable v)
{
Expand Down
7 changes: 4 additions & 3 deletions Src/PCompiler/CompilerCore/Parser/PParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,11 @@ modExpr : LPAREN modExpr RPAREN # ParenModuleExpr
bindExpr : (mName=iden | mName=iden RARROW iName=iden) ;

namedModuleDecl : MODULE name=iden ASSIGN modExpr SEMI ;
seqLiteralBody : primitive
| seqLiteral
| primitive (COMMA primitive)+
seqPrimitive : BoolLiteral
| IntLiteral
| SUB IntLiteral
;
seqLiteralBody : seqPrimitive (COMMA seqPrimitive)* ;
seqLiteral : LBRACK seqLiteralBody RBRACK;
paramBody : name=iden IN value=seqLiteral
| name=iden IN value=seqLiteral (COMMA names=iden IN value=seqLiteral)+
Expand Down
2 changes: 0 additions & 2 deletions Src/PCompiler/CompilerCore/TypeChecker/DeclarationVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public override object VisitGlobalParamDecl(PParser.GlobalParamDeclContext conte
{
// COLON type
var variableType = ResolveType(context.type());
// Console.WriteLine("variableType:" + variableType);

// VAR idenList
foreach (var t in context.idenList()._names)
Expand Down Expand Up @@ -423,7 +422,6 @@ public override object VisitVarDecl(PParser.VarDeclContext context)
for (var i = 0; i < varNameCtxs.Count; i++)
{
var variable = (Variable) nodesToDeclarations.Get(varNameCtxs[i]);
// Console.WriteLine("Local Variable:" + variable.Name);
CheckGlobalParamsRedeclare(variable);
variable.Type = variableType;
variables[i] = variable;
Expand Down
2 changes: 0 additions & 2 deletions Src/PCompiler/CompilerCore/TypeChecker/ExprVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,6 @@ public override IPExpr VisitPrimitive(PParser.PrimitiveContext context)
if (context.iden() != null)
{
var symbolName = context.iden().GetText();
// Console.WriteLine("Looking up " + symbolName);
// Console.WriteLine("Table: " + String.Join(", ", table.GetVariables().Select(x =>x.Name).ToArray()));
if (table.Lookup(symbolName, out Variable variable))
{
return new VariableAccessExpr(context, variable);
Expand Down
20 changes: 18 additions & 2 deletions Src/PCompiler/CompilerCore/TypeChecker/ParamAssignment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using Plang.Compiler.TypeChecker.AST;
using Plang.Compiler.TypeChecker.AST.Declarations;
using Plang.Compiler.TypeChecker.AST.Expressions;

namespace Plang.Compiler.TypeChecker;

Expand Down Expand Up @@ -110,6 +111,11 @@ private static Dictionary<Variable, IPExpr> IndexDic2Dic(List<Variable> globalPa
foreach (var (k, i) in indexDic)
{
var values = paramExprDic[k];
if (!globalParams.Any(v => v.Name == k))
{
throw new Exception($"Variable name '{k}' not found in globalParams. " +
$"GlobalParams are: [{string.Join(", ", globalParams.Select(v => v.Name))}]");
}
var variable = globalParams.First(v => v.Name == k);
if (i >= values.Count) throw new ArgumentException("Index out of range in global variable config.");
dic[variable] = values[i];
Expand All @@ -119,8 +125,18 @@ private static Dictionary<Variable, IPExpr> IndexDic2Dic(List<Variable> globalPa

public static string RenameSafetyTestByAssignment(string name, Dictionary<Variable, IPExpr> dic)
{
var postfix = $"{string.Join("__", Dic2StrDic(dic).ToList().Select(p => $"{p.Key}_{p.Value}"))}";
return postfix.Length == 0 ? name : $"{name}___{postfix}";
var postfix = string.Join("__", Dic2StrDic(dic).Select(p => $"{p.Key}_{MangleExprForName(p.Value)}"));
return string.IsNullOrEmpty(postfix) ? name : $"{name}___{postfix}";
}

private static string MangleExprForName(IPExpr expr)
{
return expr switch
{
IntLiteralExpr intLit => intLit.Value < 0 ? $"neg{Math.Abs(intLit.Value)}" : intLit.Value.ToString(),
BoolLiteralExpr boolLit => boolLit.Value ? "true" : "false",
_ => throw new NotImplementedException($"Unhandled param expr type: {expr.GetType().Name}")
};
}

private static bool Next((string, int)[] indexArr, IDictionary<string, List<IPExpr>> globalParams)
Expand Down
64 changes: 50 additions & 14 deletions Src/PCompiler/CompilerCore/TypeChecker/ParamVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,62 @@ public override IPExpr VisitSeqLiteral([NotNull] PParser.SeqLiteralContext conte
return Visit(context.seqLiteralBody());
}

public override IPExpr VisitSeqLiteralBody([NotNull] PParser.SeqLiteralBodyContext context)
public override IPExpr VisitSeqPrimitive(PParser.SeqPrimitiveContext context)
{
if (context.primitive() != null)
if (context.BoolLiteral() != null)
{
return new BoolLiteralExpr(context, context.BoolLiteral().GetText().Equals("true"));
}

if (context.SUB() != null && context.IntLiteral() != null)
{
int value = -int.Parse(context.IntLiteral().GetText());
return new IntLiteralExpr(context, value);
}

if (context.IntLiteral() != null)
{
int value = int.Parse(context.IntLiteral().GetText());
return new IntLiteralExpr(context, value);
}

throw handler.InternalError(context, new Exception("Unrecognized seqPrimitive input"));
}

public override IPExpr VisitSeqLiteralBody(PParser.SeqLiteralBodyContext context)
{
var values = context.seqPrimitive().Select(p =>
{
var values = context.primitive().Select(Visit).ToList();
if (values.Count == 0) return new SeqLiteralExpr(context, values, PrimitiveType.Int);
// Console.WriteLine($"value[0] = {values[0].GetType()}");
var type = values[0].Type;
foreach (var v in values.Where(v => !v.Type.Equals(type)))
var expr = Visit(p) as IPExpr;
if (expr is null)
{
throw handler.TypeMismatch(v.SourceLocation, v.Type, type);
throw handler.InternalError(p, new Exception("Visit returned null for a seqPrimitive."));
}
return new SeqLiteralExpr(context, values, new SequenceType(type));

}
if (context.seqLiteral() != null)
return expr;
}).ToList();

var baseType = values[0].Type;
var seenIntValues = new HashSet<int>();

foreach (var v in values)
{
return Visit(context.seqLiteral());
if (!v.Type.Equals(baseType))
{
throw handler.TypeMismatch(v.SourceLocation, v.Type, baseType);
}

if (v is IntLiteralExpr intLiteral && !seenIntValues.Add(intLiteral.Value))
{
throw handler.InternalError(
context,
new Exception(
$"Invalid parameter list: Duplicate integer value '{intLiteral.Value}' found. " +
$"All test values must be unique (e.g., [2, 2] is not allowed)."
));
}
}
throw handler.InternalError(context, new ArgumentOutOfRangeException(nameof(context), "unknown primitive literal"));

return new SeqLiteralExpr(context, values, new SequenceType(baseType));
}

public override IPExpr VisitPrimitive(PParser.PrimitiveContext context)
Expand Down
2 changes: 1 addition & 1 deletion Src/PCompiler/PCommandLine/CommandLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class CommandLine

private static readonly object ConsoleLock = new object();

private static void Main(string[] args)
public static void Main(string[] args)
{
// Save these so we can force output to happen even if TestingProcess has re-routed it.
StdOut = Console.Out;
Expand Down
4 changes: 4 additions & 0 deletions Src/PEx/src/test/java/pex/TestPEx.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ Collection<DynamicTest> loadTests(String testDirPath) {
pathKeys.sort(String.CASE_INSENSITIVE_ORDER);

if (testDir.contains("Correct")) {

for (String key : pathKeys) {
if (key.contains("ParamTest")) {
continue;
}
runDynamicTest(0, paths.get(key), key, dynamicTests);
}
} else if (testDir.contains("DynamicError")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
[
{
"type": "CreateStateMachine",
"details": {
"log": "Main(1) was created by task \u00272\u0027.",
"id": "Main(1)",
"payload": "null",
"clock": {
"Main(1)": 1
}
}
},
[
{
"type": "StateTransition",
"details": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<TestLog> Running test 'DefaultImpl'.
<CreateLog> Main(1) was created by task '2'.
<StateLog> Main(1) enters state 'S'.
<RaiseLog> 'Main(1)' raised event 'x with payload (<a,3,>)' in state 'S'.
<RaiseLog> 'Main(1)' raised event 'a with payload (3)' in state 'S'.
Expand Down
Loading
Loading