-
Notifications
You must be signed in to change notification settings - Fork 117
Add progress counter to ./mfc.sh test
#980
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -19,6 +19,8 @@ | |||||||||||
nFAIL = 0 | ||||||||||||
nPASS = 0 | ||||||||||||
nSKIP = 0 | ||||||||||||
current_test_number = 0 | ||||||||||||
total_test_count = 0 | ||||||||||||
errors = [] | ||||||||||||
|
||||||||||||
# pylint: disable=too-many-branches, trailing-whitespace | ||||||||||||
|
@@ -95,7 +97,7 @@ def __filter(cases_) -> typing.List[TestCase]: | |||||||||||
|
||||||||||||
def test(): | ||||||||||||
# pylint: disable=global-statement, global-variable-not-assigned | ||||||||||||
global nFAIL, nPASS, nSKIP | ||||||||||||
global nFAIL, nPASS, nSKIP, total_test_count | ||||||||||||
global errors | ||||||||||||
|
||||||||||||
cases = list_cases() | ||||||||||||
|
@@ -113,6 +115,7 @@ def test(): | |||||||||||
|
||||||||||||
cases, skipped_cases = __filter(cases) | ||||||||||||
cases = [ _.to_case() for _ in cases ] | ||||||||||||
total_test_count = len(cases) | ||||||||||||
|
||||||||||||
if ARG("list"): | ||||||||||||
table = rich.table.Table(title="MFC Test Cases", box=rich.table.box.SIMPLE) | ||||||||||||
|
@@ -150,7 +153,7 @@ def test(): | |||||||||||
|
||||||||||||
# Run cases with multiple threads (if available) | ||||||||||||
cons.print() | ||||||||||||
cons.print(" tests/[bold magenta]UUID[/bold magenta] (s) Summary") | ||||||||||||
cons.print(" Progress [bold magenta]UUID[/bold magenta] (s) Summary") | ||||||||||||
cons.print() | ||||||||||||
|
||||||||||||
# Select the correct number of threads to use to launch test cases | ||||||||||||
|
@@ -185,6 +188,7 @@ def test(): | |||||||||||
# pylint: disable=too-many-locals, too-many-branches, too-many-statements, trailing-whitespace | ||||||||||||
def _handle_case(case: TestCase, devices: typing.Set[int]): | ||||||||||||
# pylint: disable=global-statement, global-variable-not-assigned | ||||||||||||
global current_test_number | ||||||||||||
start_time = time.time() | ||||||||||||
|
||||||||||||
tol = case.compute_tolerance() | ||||||||||||
|
@@ -269,7 +273,9 @@ def _handle_case(case: TestCase, devices: typing.Set[int]): | |||||||||||
end_time = time.time() | ||||||||||||
duration = end_time - start_time | ||||||||||||
|
||||||||||||
cons.print(f" [bold magenta]{case.get_uuid()}[/bold magenta] {duration:6.2f} {case.trace}") | ||||||||||||
current_test_number += 1 | ||||||||||||
progress_str = f"({current_test_number:3d}/{total_test_count:3d})" | ||||||||||||
Comment on lines
+276
to
+277
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. This increment operation is not thread-safe. When multiple test cases run concurrently, the progress counter will be inaccurate due to race conditions. Consider using a thread-safe counter or moving this logic to a synchronized section.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||
cons.print(f" {progress_str} [bold magenta]{case.get_uuid()}[/bold magenta] {duration:6.2f} {case.trace}") | ||||||||||||
|
||||||||||||
|
||||||||||||
def handle_case(case: TestCase, devices: typing.Set[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 global variable
current_test_number
is being modified in_handle_case
which appears to be called from multiple threads based on the comment 'Run cases with multiple threads'. This creates a race condition where multiple threads could increment the counter simultaneously, leading to incorrect progress reporting.Copilot uses AI. Check for mistakes.