Skip to content
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

[Bug]: T2/Snappi_tests: Use round() instead of ceil() or int() for approximate calculations #16080

Open
rraghav-cisco opened this issue Dec 16, 2024 · 0 comments

Comments

@rraghav-cisco
Copy link
Contributor

Issue Description

Many of the scripts use ceil() or int() to find some approximate values. This sometimes results in unnecessary failures. One example is below:

        background_loss = 0
        for row in rows:
            if 'Test Flow' in row.name:
                pytest_assert(int(row.loss) == 0, "FAIL: {} must have 0% loss".format(row.name))
            elif 'Background Flow' in row.name:
                background_loss += float(row.loss)
>       pytest_assert(int(background_loss/4) == 10, "Each Background Flow must have an avg of 10% loss ")
E       Failed: Each Background Flow must have an avg of 10% loss

background_loss = 39.998999999999995
row        = <snappi.snappi.FlowMetric object at 0x7f90adb90d40>
rows       = <snappi.snappi.FlowMetricIter object at 0x7f90adce1340>
rx_port    = {'api_server_ip': '172.27.147.46', 'asic_type': 'cisco-8000', 'asic_value': 'asic0', 'card_id': '1', ...}
tx_port    = [{'api_server_ip': '172.27.147.46', 'asic_type': 'cisco-8000', 'asic_value': 'asic0', 'card_id': '1', ...}, {'api_server_ip': '172.27.147.46', 'asic_type': 'cisco-8000', 'asic_value': 'asic0', 'card_id': '1', ...}]

snappi_tests/multidut/pfc/files/m2o_fluctuating_lossless_helper.py:418: Failed

As we can see, the background_loss value is nearly 40, but the int() call changes it to 9 instead of 10, and above check fails. We should use round() function as below:

>>> background_loss = 39.998999999999995
>>> int(background_loss/4)
9
>>> round(background_loss/4)
10
>>> 

@selldinesh , @kamalsahu0001 , @sdszhang , @auspham : FYI

Results you see

Test fails on approximate calculations.

Results you expected to see

The test should pass.

Is it platform specific

generic

Relevant log output

Pls see above.
There are others as well:

sonic@sonic-ucs-m4-3:~/rraghav/Ixia/whitebox/vanilla_202405_nov_21_2024/sonic-mgmt/tests/snappi_tests/multidut$ grep -rl ceil . | grep -v pyc
./bgp/files/bgp_outbound_helper.py
./pfc/files/m2o_fluctuating_lossless_helper.py
./pfc/files/m2o_oversubscribe_lossless_lossy_helper.py
./pfc/files/lossless_response_to_throttling_pause_storms_helper.py
./pfc/files/m2o_oversubscribe_lossless_helper.py
./pfc/files/m2o_oversubscribe_lossy_helper.py
./pfc/files/lossless_response_to_external_pause_storms_helper.py
./pfcwd/files/pfcwd_multidut_basic_helper.py
./pfcwd/files/pfcwd_multidut_burst_storm_helper.py
./pfcwd/files/pfcwd_multidut_multi_node_helper.py
sonic@sonic-ucs-m4-3:~/rraghav/Ixia/whitebox/vanilla_202405_nov_21_2024/sonic-mgmt/tests/snappi_tests/multidut$ 


### Output of `show version`

_No response_

### Attach files (if any)

_No response_
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

No branches or pull requests

1 participant