-
Notifications
You must be signed in to change notification settings - Fork 718
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
Optimize the matching rule of conditional marks #14395
Optimize the matching rule of conditional marks #14395
Conversation
#14434) What is the motivation for this PR? Previously, we use temporary workaround #13602 to skip traffic test in VS platform because conditional mark could only match longest prefix, but now, it's fixed in #14395, so it would be better to use a common way -- conditional mark to skip traffic test but not hardcode How did you do it? Remove skip_traffic_test fixture in duthost_utils and use fixture in ptfhost_utils Add condition with tests need to skip traffic test in tests_mark_conditions_skip_traffic_test.yaml
…rk. (#14515) Description of PR We changed the matching rule of conditional mark in PR #14395. There is a bug when getting the maximum matching length. In this PR, we fix this bug. Approach What is the motivation for this PR? We changed the matching rule of conditional mark in PR #14395. There is a bug when getting the maximum matching length. In this PR, we fix this bug. co-authorized by: jianquanye@microsoft.com
What is the motivation for this PR? Previously, the matching rule of the conditional marks was based on the longest match. This meant that when a test case had multiple potential matches, we only applied the mark with the longest matching entry. In this PR, we've optimized this rule: we now consider all potential matches. If a mark is unique across these matches, it will be applied to the test case. Otherwise, we will still use the longest matching entry. How did you do it? In this PR, we've optimized this rule of conditional mark: we now consider all potential matches. If a mark is unique across these matches, it will be applied to the test case. Otherwise, we will still use the longest matching entry. How did you verify/test it? We have conditional marks below mark: skip: reason: "Skip mark" conditions: - "topo_type in ['vs']" mark/test_mark.py: xfail: reason: "Xfail mark/test_mark.py" conditions: - "asic_type in ['vs']" skip: reason: "Skip mark/test_mark.py" conditions: - "asic_type in ['vs']" mark/test_mark.py::test_conditional_mark: skip: reason: "Skip mark/test_mark.py::test_conditional_mark" conditions: - "asic_type in ['vs']" And we run test case mark/test_mark.py::test_conditional_mark on kvm testbed. We get the expected match of this test case and add them to the case 08:25:40 __init__.pytest_collection_modifyitems L0611 INFO | Found match "[{'mark/test_mark.py::test_conditional_mark': {'skip': {'reason': 'Skip mark/test_mark.py::test_conditional_mark', 'conditions': ["asic_type in ['vs']"]}}}, {'mark/test_mark.py': {'xfail': {'reason': 'Xfail mark/test_mark.py', 'conditions': ["asic_type in ['vs']"]}}}]" for test case "mark/test_mark.py::test_conditional_mark" 08:25:40 __init__.pytest_collection_modifyitems L0649 INFO | Adding mark MarkDecorator(mark=Mark(name='skip', args=(), kwargs={'reason': 'Skip mark/test_mark.py::test_conditional_mark'})) to mark/test_mark.py::test_conditional_mark 08:25:40 __init__.pytest_collection_modifyitems L0649 INFO | Adding mark MarkDecorator(mark=Mark(name='xfail', args=(), kwargs={'reason': 'Xfail mark/test_mark.py', 'strict': False})) to mark/test_mark.py::test_conditional_mark Any platform specific information?
sonic-net#14434) What is the motivation for this PR? Previously, we use temporary workaround sonic-net#13602 to skip traffic test in VS platform because conditional mark could only match longest prefix, but now, it's fixed in sonic-net#14395, so it would be better to use a common way -- conditional mark to skip traffic test but not hardcode How did you do it? Remove skip_traffic_test fixture in duthost_utils and use fixture in ptfhost_utils Add condition with tests need to skip traffic test in tests_mark_conditions_skip_traffic_test.yaml
…rk. (sonic-net#14515) Description of PR We changed the matching rule of conditional mark in PR sonic-net#14395. There is a bug when getting the maximum matching length. In this PR, we fix this bug. Approach What is the motivation for this PR? We changed the matching rule of conditional mark in PR sonic-net#14395. There is a bug when getting the maximum matching length. In this PR, we fix this bug. co-authorized by: jianquanye@microsoft.com
What is the motivation for this PR? Previously, the matching rule of the conditional marks was based on the longest match. This meant that when a test case had multiple potential matches, we only applied the mark with the longest matching entry. In this PR, we've optimized this rule: we now consider all potential matches. If a mark is unique across these matches, it will be applied to the test case. Otherwise, we will still use the longest matching entry. How did you do it? In this PR, we've optimized this rule of conditional mark: we now consider all potential matches. If a mark is unique across these matches, it will be applied to the test case. Otherwise, we will still use the longest matching entry. How did you verify/test it? We have conditional marks below mark: skip: reason: "Skip mark" conditions: - "topo_type in ['vs']" mark/test_mark.py: xfail: reason: "Xfail mark/test_mark.py" conditions: - "asic_type in ['vs']" skip: reason: "Skip mark/test_mark.py" conditions: - "asic_type in ['vs']" mark/test_mark.py::test_conditional_mark: skip: reason: "Skip mark/test_mark.py::test_conditional_mark" conditions: - "asic_type in ['vs']" And we run test case mark/test_mark.py::test_conditional_mark on kvm testbed. We get the expected match of this test case and add them to the case 08:25:40 __init__.pytest_collection_modifyitems L0611 INFO | Found match "[{'mark/test_mark.py::test_conditional_mark': {'skip': {'reason': 'Skip mark/test_mark.py::test_conditional_mark', 'conditions': ["asic_type in ['vs']"]}}}, {'mark/test_mark.py': {'xfail': {'reason': 'Xfail mark/test_mark.py', 'conditions': ["asic_type in ['vs']"]}}}]" for test case "mark/test_mark.py::test_conditional_mark" 08:25:40 __init__.pytest_collection_modifyitems L0649 INFO | Adding mark MarkDecorator(mark=Mark(name='skip', args=(), kwargs={'reason': 'Skip mark/test_mark.py::test_conditional_mark'})) to mark/test_mark.py::test_conditional_mark 08:25:40 __init__.pytest_collection_modifyitems L0649 INFO | Adding mark MarkDecorator(mark=Mark(name='xfail', args=(), kwargs={'reason': 'Xfail mark/test_mark.py', 'strict': False})) to mark/test_mark.py::test_conditional_mark Any platform specific information?
sonic-net#14434) What is the motivation for this PR? Previously, we use temporary workaround sonic-net#13602 to skip traffic test in VS platform because conditional mark could only match longest prefix, but now, it's fixed in sonic-net#14395, so it would be better to use a common way -- conditional mark to skip traffic test but not hardcode How did you do it? Remove skip_traffic_test fixture in duthost_utils and use fixture in ptfhost_utils Add condition with tests need to skip traffic test in tests_mark_conditions_skip_traffic_test.yaml
…rk. (sonic-net#14515) Description of PR We changed the matching rule of conditional mark in PR sonic-net#14395. There is a bug when getting the maximum matching length. In this PR, we fix this bug. Approach What is the motivation for this PR? We changed the matching rule of conditional mark in PR sonic-net#14395. There is a bug when getting the maximum matching length. In this PR, we fix this bug. co-authorized by: jianquanye@microsoft.com
…arks (#14912) What is the motivation for this PR? As part of #11968, a bugfix was introduced in the find_longest_matches function to identify only the longest matching entry in tests_mark_conditions.yaml. The previous bug led to incorrect behavior in finding the matching entries, deviating from our intended logic before: Our expected behavior was to retrieve only the longest matching entry and evaluate the conditions under this single, unique entry. Instead, the bug caused the function to retrieve all entries matching the test case prefix, evaluating conditions from all matching entries. This resulted in an unintended situation where conditions from shorter matching entries which are absent in the longest one would still be considered during evaluation. In PR #14395, we optimized the logic for finding marks in conditional marking. Now, although we will retrieve all entries matching the test case prefix but only the longest matching entry is evaluated if the mark is identical across all matching entries, which aligns with our original expectations. Additionally, conditions that exist only in shorter matching entries with the same mark are now ignored. To maintain consistency with previous behavior(although unexpected), we have added these conditions to the longer matching entry. How did you do it? To maintain consistency with previous behavior(although unexpected), we have added these conditions to the longer matching entry.
marks = match[case_starting_substring].keys() | ||
for mark in marks: | ||
if mark in conditional_marks: | ||
if length > max_length: |
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.
Shouldn't the max_length
be a per-mark attribute?
Otherwise if you had the following:
package:
skip:
condition:
-<conditionA>
xfail:
condition:
-<conditionB>
package/test.py::testName:
skip:
condition:
-<conditionC>
package/test.py:
xfail:
condition:
-<conditionD>
When the match package/test.py::testName
is processed against the skip
mark it will cause the max_length
to be set to len('package/test.py::testName')
but then later when package/test.py
is processed for xfail
it won't be added because it's incorrectly comparing against the max_length
of the skip
mark.
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.
Hi, @arista-nwolfe, in our yaml file of conditional mark, we set all conditions in alphabet order. So we will check the case_starting_substring
from short to long.
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.
Hi, @arista-nwolfe, in our yaml file of conditional mark, we set all conditions in alphabet order. So we will check the
case_starting_substring
from short to long.
Can we rely on the yaml file being populated that way? If we are then you technically don't even need a if length >= max_length:
check since the latter processed match will always be the same length or longer than the previous matches.
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.
Hi, @arista-nwolfe, in our yaml file of conditional mark, we set all conditions in alphabet order. So we will check the
case_starting_substring
from short to long.Can we rely on the yaml file being populated that way? If we are then you technically don't even need a
if length >= max_length:
check since the latter processed match will always be the same length or longer than the previous matches.
Yes, we have a pre-commit checker to check.
@yutongzhang-microsoft PR conflicts with 202405 branch |
Description of PR
Previously, the matching rule of the conditional marks was based on the longest match. This meant that when a test case had multiple potential matches, we only applied the mark with the longest matching entry. In this PR, we've optimized this rule: we now consider all potential matches. If a mark is unique across these matches, it will be applied to the test case. Otherwise, we will still use the longest matching entry.
Summary:
Fixes # (issue)
Type of change
Back port request
Approach
What is the motivation for this PR?
Previously, the matching rule of the conditional marks was based on the longest match. This meant that when a test case had multiple potential matches, we only applied the mark with the longest matching entry. In this PR, we've optimized this rule: we now consider all potential matches. If a mark is unique across these matches, it will be applied to the test case. Otherwise, we will still use the longest matching entry.
How did you do it?
In this PR, we've optimized this rule of conditional mark: we now consider all potential matches. If a mark is unique across these matches, it will be applied to the test case. Otherwise, we will still use the longest matching entry.
How did you verify/test it?
We have conditional marks below
And we run test case
mark/test_mark.py::test_conditional_mark
on kvm testbed.We get the expected match of this test case and add them to the case
Any platform specific information?
Supported testbed topology if it's a new test case?
Documentation