test_ProductionCode.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # QUTEST script corresponding to the test_ProductionCode.c test fixture.
  2. # This test fixture corresponds to ../test_unity/TestProductionCode.c fixture.
  3. # see https://www.state-machine.com/qtools/qutest.html/qutest.html
  4. # preamble...
  5. def on_setup():
  6. # This is run before EACH TEST
  7. current_obj(OBJ_AP, "Counter")
  8. poke(0, 4, pack('<L', 0x5A5A))
  9. # tests...
  10. test("FindFunction_WhichIsBroken() Should Return Zero If Item Is Not In List, Which Works Even In Our Broken Code")
  11. # All of these should pass
  12. command(0, 78)
  13. expect("0000000001 USER+000 FindFunction_WhichIsBroken 0 78")
  14. expect("0000000002 Trg-Done QS_RX_COMMAND")
  15. command(0, 2)
  16. expect("0000000003 USER+000 FindFunction_WhichIsBroken 0 2")
  17. expect("0000000004 Trg-Done QS_RX_COMMAND")
  18. command(0, 33)
  19. expect("@timestamp USER+000 FindFunction_WhichIsBroken 0 33")
  20. expect("@timestamp Trg-Done QS_RX_COMMAND")
  21. command(0, 999)
  22. expect("@timestamp USER+000 FindFunction_WhichIsBroken 0 999")
  23. expect("@timestamp Trg-Done QS_RX_COMMAND")
  24. command(0, (-1) & 0xFFFFFFFF)
  25. expect("@timestamp USER+000 FindFunction_WhichIsBroken 0 -1")
  26. expect("@timestamp Trg-Done QS_RX_COMMAND")
  27. test("FindFunction_WhichIsBroken() Should Return The Index For Items In List, Which Will Fail Because Our Function Under Test Is Broken")
  28. command(0, 34)
  29. expect("@timestamp USER+000 FindFunction_WhichIsBroken 1 34")
  30. # Notice the rest of these didn't get a chance to run because the line above failed.
  31. # Unit tests abort each test on the first sign of trouble.
  32. # Then NEXT test runs as normal.
  33. expect("@timestamp Trg-Done QS_RX_COMMAND")
  34. command(0, 8888)
  35. expect("@timestamp USER+000 FindFunction_WhichIsBroken 8 8888")
  36. expect("@timestamp Trg-Done QS_RX_COMMAND")
  37. test("FunctionWhichReturnsLocalVariable() Should Return The Current Counter Value")
  38. command(1)
  39. expect("@timestamp USER+001 FunctionWhichReturnsLocalVariable 0x5A5A")
  40. expect("@timestamp Trg-Done QS_RX_COMMAND")
  41. # This should be true because we can still change our answer
  42. poke(0, 4, pack('<L', 0x1234))
  43. command(1)
  44. expect("@timestamp USER+001 FunctionWhichReturnsLocalVariable 0x1234")
  45. expect("@timestamp Trg-Done QS_RX_COMMAND")
  46. test("FunctionWhichReturnsLocalVariable() Should Return The Current Counter Value Again", NORESET)
  47. # This should be true again because setup was rerun before this test (and after we changed it to 0x1234)
  48. command(1)
  49. expect("@timestamp USER+001 FunctionWhichReturnsLocalVariable 0x5A5A")
  50. expect("@timestamp Trg-Done QS_RX_COMMAND")
  51. test("FunctionWhichReturnsLocalVariable() Should Return Current Counter, But Fails Because This Test Is Actually Flawed", NORESET)
  52. # Sometimes you get the test wrong. When that happens, you get a failure too... and a quick look should tell
  53. # you what actually happened...which in this case was a failure to setup the initial condition.
  54. command(1)
  55. expect("@timestamp USER+001 FunctionWhichReturnsLocalVariable 0x1234")
  56. expect("@timestamp Trg-Done QS_RX_COMMAND")