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

Better support test reproducibility #2721

Merged
merged 4 commits into from Nov 10, 2021

Conversation

ktbarrett
Copy link
Member

@ktbarrett ktbarrett commented Sep 24, 2021

Closes #2672. Pinging @walt3k.

Tests are now reproducible if:

  • the test name and module does not change
  • the test body does not change
  • the test is "pure", meaning it's not affected by its environment (the state of the DUT, the state of the Python environment)
  • the same RANDOM_SEED is used

@codecov
Copy link

codecov bot commented Sep 24, 2021

Codecov Report

Merging #2721 (ce02357) into master (0346c03) will decrease coverage by 2.27%.
The diff coverage is 100.00%.

❗ Current head ce02357 differs from pull request most recent head 0243f26. Consider uploading reports for the commit 0243f26 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2721      +/-   ##
==========================================
- Coverage   76.47%   74.19%   -2.28%     
==========================================
  Files          45       45              
  Lines        7846     7848       +2     
  Branches      633     1249     +616     
==========================================
- Hits         6000     5823     -177     
+ Misses       1662     1633      -29     
- Partials      184      392     +208     
Impacted Files Coverage Δ
cocotb/regression.py 80.54% <100.00%> (+0.43%) ⬆️
cocotb/share/lib/fli/FliImpl.h 75.43% <0.00%> (-8.78%) ⬇️
cocotb/share/lib/vhpi/VhpiCbHdl.cpp 57.55% <0.00%> (-7.80%) ⬇️
cocotb/share/lib/fli/FliImpl.cpp 72.69% <0.00%> (-7.20%) ⬇️
cocotb/share/lib/vhpi/VhpiImpl.cpp 56.26% <0.00%> (-7.13%) ⬇️
cocotb/share/lib/fli/FliObjHdl.cpp 59.21% <0.00%> (-7.06%) ⬇️
cocotb/share/lib/fli/FliCbHdl.cpp 86.95% <0.00%> (-5.44%) ⬇️
cocotb/share/lib/gpi_log/gpi_logging.cpp 68.00% <0.00%> (-4.00%) ⬇️
cocotb/share/lib/vpi/VpiCbHdl.cpp 81.50% <0.00%> (-3.41%) ⬇️
cocotb/share/lib/vpi/VpiImpl.h 70.45% <0.00%> (-2.28%) ⬇️
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0346c03...0243f26. Read the comment docs.

# seed random number generator based on test module, name, and RANDOM_SEED
hasher = hashlib.sha1()
hasher.update(test.__qualname__.encode())
hasher.update(test.__module__.encode())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I commented, it's not unusual where I work for people to collect failing tests from many different test files (MODULE files) into one big regression MODULE file. Users will often call this file "The Kitchen Sink" or something creative like that. :-) If the MODULE name is used here then users would not be able to do that i.e. if they had a hundred failing tests they could potentially be forced to have a hundred separate MODULE files as well... rather than one. Not a deal breaker but I thought I should mention it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__module__ will be the name of the module they were defined in, not the module they were discovered in. So importing tests from other modules into a "kitchen sink" module will continue to work.

@ktbarrett
Copy link
Member Author

Needs newsfragment.

cocotb/regression.py Outdated Show resolved Hide resolved
tests/test_cases/test_seed/test_seed.py Outdated Show resolved Hide resolved
Co-authored-by: Colin Marquardt <cmarqu42@gmail.com>
Copy link
Contributor

@marlonjames marlonjames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for now.
After we improve GPI extension support, we should provide a central mechanism for updating the PRNG seed and being notified of the updates.

@ktbarrett ktbarrett merged commit 0dd9eb9 into cocotb:master Nov 10, 2021
@ktbarrett ktbarrett deleted the random-seed-reproducibility branch November 10, 2021 16:46
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

Successfully merging this pull request may close these issues.

Potential rerun/reproducibility problem when using TESTCASE with multi-test MODULE
4 participants