def run_tests(self): """ Runs all tests in the given test-case.""" self.successes = 0 self.failures = 0 self.exceptions = 0 # Create our device under test connection. dut = self.dut = ApolloDebugger() logging.info( f"Connected to onboard debugger; hardware revision r{dut.major}.{dut.minor} (s/n: {dut.serial_number})." ) # Find all test methods attached to this object... logging.info("Running tests...") sys.stdout.flush() sys.stderr.flush() with dut.jtag as jtag: pprint(HTML("\n\n<b><u>Automated tests:</u></b>")) for name, member in inspect.getmembers(self): if inspect.ismethod(member) and name.startswith('test_'): self._run_as_test_case(member, self.dut)
def _run_as_test_case(self, method: callable, dut: ApolloDebugger): """ Runs a given method as a test case. """ # Try to run the method... try: method(dut) # If nothing went wrong, succeed. result = "<green>✓ PASSED</green>" self.successes += 1 except AssertionError as e: result = f"<red>✗ FAILED</red>\t({e})" self.failures += 1 except Exception as e: result = f"<red>⚠ EXCEPTION </red>\t({e})" self.exceptions += 1 # ... and print the result. name = method.__name__.replace("test_", "") pprint(HTML(f"\t{name}:\t{result}"))
dut.registers.register_write(REGISTER_RAM_REG_ADDR, 0x0) return dut.registers.register_read(REGISTER_RAM_VALUE) in (0x0c81, 0x0c86) def test_config_read(): dut.registers.register_write(REGISTER_RAM_REG_ADDR, 0x800) dut.registers.register_write(REGISTER_RAM_REG_ADDR, 0x800) return dut.registers.register_read(REGISTER_RAM_VALUE) in (0x8f1f, 0x8f2f) # Run each of our tests. for test in (test_id_read, test_config_read): for i in range(iterations): if test(): pprint(f".", end="") passes += 1 else: pprint(f"✗", end="") failures += 1 failed_tests.add(test) fail_text = "<red>✗ FAILED</red>" pass_text = "<green>✓ PASSED</green>" pprint(HTML("\n\n<b><u>Results:</u></b>")) pprint( HTML( f" ID READ: {fail_text if test_id_read in failed_tests else pass_text}" ))