This library provides utilities to quickly deploy cocotb tests with Gradescope autograders.
git clone https://github.com/CSE140L/cocotb_gradescope
cd cocotb_gradescope
pip install .To use the library, please refer to the following example which should outline everything.
import cocotb
from pathlib import Path
from cocotb_gradescope.reporter import GradescopeReporter, Visibility
results_path = Path("results.json")
reporter = GradescopeReporter(results_path)
@cocotb.test()
@reporter.report_test(visibility=Visibility.HIDDEN, max_score=10)
async def test_part1(dut):
# If set_score isn't provided then if the test passes then the final score will set it to max_score
assert 1 == 1
@cocotb.test()
# If the test is a failure, we can make it available to students
@reporter.report_test(visibility=Visibility.HIDDEN, max_score=10, visibility_on_failure=Visibility.VISIBLE)
async def test_part1(dut, set_score):
assert 1 == 1
set_score(5)
assert 1 == 2
set_score(10)If you have generated multiple results.json files (say for different testing modules), then please ensure to merge
them all together with:
python -m cocotb_gradescope.reporter [test1.json ...] <output_file.json>This will create one big output_file.json that is a naive concatenation of all the test results.