test_programmer_error_logs.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. """Programmer reports must reject real TD errors even with success markers."""
  2. from contextlib import redirect_stdout
  3. import io
  4. from pathlib import Path
  5. import tempfile
  6. import unittest
  7. from unittest.mock import patch
  8. from tools import remote_flash_cpld as flash
  9. class ProgrammerErrorLogTests(unittest.TestCase):
  10. def test_actual_program_done_failure_overrides_success_marker(self):
  11. log = ('PRG-2014 : Chip validation success: EF2L45\n'
  12. 'PRG-9507 ERROR: line 2361 read = 0x00 ref = 0x01\n'
  13. 'PRG-9524 ERROR: Program done check failed!\n'
  14. 'RUN-1003 : finish command "download -mode jtag"\n'
  15. 'PROD2U_SRAM_OK\n')
  16. self.assertFalse(flash.td_result_ok(0, log, '', 'PROD2U_SRAM_OK'))
  17. self.assertEqual(len(flash.td_error_lines(log, '')), 2)
  18. def test_errors_in_either_stream_cannot_pass_burn_or_sram(self):
  19. failures = ['PRG-9505 USB device open error', 'ERROR: download failed',
  20. 'FATAL: connection lost', 'RUN-9000 ERROR: execution failed']
  21. with tempfile.TemporaryDirectory() as directory:
  22. bit = Path(directory) / 'fixture.bit'
  23. bit.write_bytes(b'not a real firmware')
  24. bit.with_suffix('.bmk').write_bytes(b'fixture mask')
  25. for command, marker in [(flash.cmd_sram, 'PROD2U_SRAM_VERIFIED'),
  26. (flash.cmd_burn, 'PROD2U_FLASH_PROGRAMMED_VERIFIED')]:
  27. for error in failures:
  28. for stderr in (False, True):
  29. stdout = marker + '\n' + ('' if stderr else error)
  30. err = error if stderr else ''
  31. with self.subTest(command=command.__name__, error=error, stderr=stderr), \
  32. patch.object(flash, 'run_tcl', return_value=(0, stdout, err)), \
  33. redirect_stdout(io.StringIO()):
  34. self.assertEqual(command(str(bit)), 1)
  35. def test_error_free_completion_with_nonfatal_warning_passes(self):
  36. log = ('PRG-2014 : Chip validation success: EF2L45\n'
  37. 'PRG-1000 : Detect risk, will automatic deceleration when reading spi flash data.\n'
  38. 'RUN-1003 : finish command "download -mode jtag"\nPROD2U_SRAM_OK\n')
  39. self.assertTrue(flash.td_result_ok(0, log, '', 'PROD2U_SRAM_OK'))
  40. self.assertFalse(flash.td_result_ok(1, log, '', 'PROD2U_SRAM_OK'))
  41. self.assertFalse(flash.td_result_ok(0, 'puts "PROD2U_SRAM_OK"\n', '', 'PROD2U_SRAM_OK'))
  42. def test_device_mention_in_error_output_is_not_detection(self):
  43. class Result:
  44. stdout = 'Bus 002 Device 006: ID 336c:1002 Anlogic USB-JTAG-Cable\n'
  45. for log in ['PRG-9505 ERROR: EF2L45 device open error\n',
  46. 'DEVICE_DETECTED: EF2L45\nPRG-9507 ERROR: bad ID\n']:
  47. with patch.object(flash.subprocess, 'run', return_value=Result()), \
  48. patch.object(flash, 'run_tcl', return_value=(0, log, '')), \
  49. redirect_stdout(io.StringIO()):
  50. self.assertEqual(flash.cmd_check(), 1)
  51. def test_sram_requires_real_vector_generation_and_readback_at_200k(self):
  52. with tempfile.TemporaryDirectory() as directory:
  53. bit = Path(directory) / 'fixture.bit'
  54. bit.write_bytes(b'fixture')
  55. bit.with_suffix('.bmk').write_bytes(b'mask')
  56. with patch.object(flash, 'run_tcl', return_value=(0, 'PROD2U_SRAM_VERIFIED\n', '')) as run, redirect_stdout(io.StringIO()):
  57. self.assertEqual(flash.cmd_sram(str(bit)), 0)
  58. tcl = run.call_args.args[0]
  59. self.assertIn('download -mode jtag -spd 3 -cable 0', tcl)
  60. self.assertIn('download -mode x_rdbk -spd 3 -cable 0', tcl)
  61. self.assertEqual(tcl.count(' -vec '), 2)
  62. with patch.object(flash, 'run_tcl', return_value=(0, 'PROD2U_SRAM_PROGRAMMED\n', '')), redirect_stdout(io.StringIO()):
  63. self.assertEqual(flash.cmd_sram(str(bit)), 1)
  64. def test_missing_sram_mask_does_not_program(self):
  65. with tempfile.TemporaryDirectory() as directory:
  66. bit = Path(directory) / 'fixture.bit'
  67. bit.write_bytes(b'fixture')
  68. with patch.object(flash, 'run_tcl') as run, redirect_stdout(io.StringIO()):
  69. self.assertEqual(flash.cmd_sram(str(bit)), 1)
  70. run.assert_not_called()
  71. def test_flash_stages_are_real_verified_and_stop_on_error(self):
  72. markers = ['PROD2U_FLASH_PROGRAMMED_VERIFIED',
  73. 'PROD2U_FLASH_REFRESHED', 'PROD2U_FLASH_BOOT_VERIFIED']
  74. modes = ['program_spi -v', 'refresh', 'x_rdbk']
  75. with tempfile.TemporaryDirectory() as directory:
  76. bit = Path(directory) / 'fixture.bit'
  77. bit.write_bytes(b'fixture')
  78. with patch.object(flash, 'run_tcl') as run, redirect_stdout(io.StringIO()):
  79. self.assertEqual(flash.cmd_burn(str(bit)), 1)
  80. run.assert_not_called()
  81. bit.with_suffix('.bmk').write_bytes(b'mask')
  82. good = [(0, marker + '\n', '') for marker in markers]
  83. with patch.object(flash, 'run_tcl', side_effect=good) as run, redirect_stdout(io.StringIO()):
  84. self.assertEqual(flash.cmd_burn(str(bit)), 0)
  85. for call, mode in zip(run.call_args_list, modes):
  86. self.assertIn('download -mode ' + mode + ' -spd 3 -cable 0', call.args[0])
  87. self.assertIn(' -vec ', call.args[0])
  88. for failing in range(len(modes)):
  89. bad = good[:failing] + [(0, markers[failing] + '\nPRG-9507 ERROR: mismatch\n', '')]
  90. with patch.object(flash, 'run_tcl', side_effect=bad) as run, redirect_stdout(io.StringIO()):
  91. self.assertEqual(flash.cmd_burn(str(bit)), 1)
  92. self.assertEqual(run.call_count, failing + 1)
  93. if __name__ == '__main__':
  94. unittest.main()