forked from intel/perfmon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request intel#161 from edwarddavidbaker/fix-inefficient-regex
create_perf_json: Fix inefficient regex warning
- Loading branch information
Showing
3 changed files
with
69 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 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,57 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
import unittest | ||
import sys | ||
from pathlib import Path | ||
|
||
# Add create_perf_json.py directory to the path before importing. | ||
_script_dir = Path(__file__).resolve().parent | ||
sys.path.append(str(_script_dir.parent)) | ||
|
||
from create_perf_json import Model | ||
|
||
|
||
class TestModel(unittest.TestCase): | ||
|
||
def test_extract_pebs_formula(self): | ||
"""Test formulas which use $PEBS but do not include min() or max().""" | ||
tests = [ | ||
( | ||
'EVENT.A*$PEBS', | ||
'( EVENT.A * EVENT.A:R )', | ||
), | ||
( | ||
'EVENT.A + [email protected]@*$PEBS', | ||
'EVENT.A + ( [email protected]@ * [email protected]@R )', | ||
), | ||
] | ||
|
||
for input, expected_result in tests: | ||
with self.subTest(input=input, expected_result=expected_result): | ||
self.assertEqual(expected_result, Model.extract_pebs_formula(input)) | ||
|
||
def test_extract_pebs_formula_with_min_max(self): | ||
"""Test formulas which use $PEBS and also min() or max().""" | ||
tests = [ | ||
( | ||
'EVENT.A*min( $PEBS, 4) / EVENT.B', | ||
'EVENT.A * min(EVENT.A:R, 4) / EVENT.B', | ||
), | ||
( | ||
'EVENT.A*min($PEBS, 2) / (1 + EVENT.B*max($PEBS, 8))', | ||
'EVENT.A * min(EVENT.A:R, 2) / (1 + EVENT.B * max(EVENT.B:R, 8))', | ||
), | ||
( | ||
'EVENT.A*min($PEBS, 9 * test_info) * (1 + ([email protected]@ / [email protected]@) / 2) / test_info_2', | ||
'EVENT.A * min(EVENT.A:R, 9 * test_info) * (1 + ([email protected]@ / [email protected]@) / 2) / test_info_2', | ||
), | ||
( | ||
'([email protected]@*min($PEBS, 24 * test_info) + [email protected]@*min($PEBS, 24 - test_info) * (1 - ([email protected]@ / ([email protected]@ + [email protected]@)))) * 5', | ||
'([email protected]@ * min([email protected]@R, 24 * test_info) + [email protected]@ * min([email protected]@R, 24 - test_info) * (1 - ([email protected]@ / ([email protected]@ + [email protected]@)))) * 5', | ||
) | ||
] | ||
|
||
for input, expected_result in tests: | ||
with self.subTest(input=input, expected_result=expected_result): | ||
self.assertEqual(expected_result, Model.extract_pebs_formula(input)) |