56 lines
3.0 KiB
Python
56 lines
3.0 KiB
Python
"""Prevent packaging a new GUI with a stale native DSView component."""
|
|
import hashlib
|
|
import importlib.util
|
|
import json
|
|
from pathlib import Path
|
|
import tempfile
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
RECIPE = Path(__file__).resolve().parents[1] / 'build.py'
|
|
SPEC = importlib.util.spec_from_file_location('dsview_runtime_build', RECIPE)
|
|
BUILD = importlib.util.module_from_spec(SPEC)
|
|
SPEC.loader.exec_module(BUILD)
|
|
|
|
|
|
class RuntimeTests(unittest.TestCase):
|
|
def test_legacy_runtime_and_mismatched_binary_or_recipe_require_rebuild(self):
|
|
with tempfile.TemporaryDirectory() as temporary:
|
|
output = Path(temporary)
|
|
(output / 'DSView.exe').write_bytes(b'native fixture')
|
|
(output / 'host-protocol-1').write_text('DSView host protocol 1\n')
|
|
self.assertFalse(BUILD.runtime_is_current(output))
|
|
stamp = {'recipe': 'new', 'executable': hashlib.sha256(b'native fixture').hexdigest()}
|
|
(output / 'host-build.json').write_text(json.dumps(stamp))
|
|
with patch.object(BUILD, 'recipe_digest', return_value='new'):
|
|
self.assertTrue(BUILD.runtime_is_current(output))
|
|
(output / 'DSView.exe').write_bytes(b'old native fixture')
|
|
self.assertFalse(BUILD.runtime_is_current(output))
|
|
(output / 'DSView.exe').write_bytes(b'native fixture')
|
|
with patch.object(BUILD, 'recipe_digest', return_value='changed'):
|
|
self.assertFalse(BUILD.runtime_is_current(output))
|
|
(output / 'host-build.json').write_text('partial JSON')
|
|
self.assertFalse(BUILD.runtime_is_current(output))
|
|
|
|
def test_patch_adapters_and_shared_cores_all_invalidate_runtime(self):
|
|
with tempfile.TemporaryDirectory() as temporary:
|
|
root = Path(temporary)
|
|
recipe = root / 'tools/dsview'
|
|
core = root / 'python/logic_analyzer/decoders'
|
|
core.mkdir(parents=True)
|
|
(recipe / 'decoders/gate_driver_timing').mkdir(parents=True)
|
|
(recipe / 'native').mkdir()
|
|
files = [recipe / 'build.py', recipe / 'setgui-host.patch', recipe / 'gate-pair-checkbox.patch', recipe / 'decoder-panel.patch', recipe / 'driver-summary.patch', recipe / 'windows-usb-events.patch', recipe / 'native/gate_summary.h',
|
|
recipe / 'decoders/gate_driver_timing/pd.py']
|
|
files += [core / (name + '.py') for name in ('gate_timing', 'transistor_pair', 'set_uart', 'set_can', 'pm35_uart')]
|
|
for item in files:
|
|
item.write_text('initial')
|
|
with patch.object(BUILD, '__file__', str(recipe / 'build.py')):
|
|
initial = BUILD.recipe_digest()
|
|
for item in files:
|
|
with self.subTest(file=item.name):
|
|
item.write_text('changed')
|
|
self.assertNotEqual(initial, BUILD.recipe_digest())
|
|
item.write_text('initial')
|
|
self.assertEqual(initial, BUILD.recipe_digest())
|