|
| 1 | +from datastore import CodeStore, ImageStore, KvStore |
| 2 | +from dock import DockControl |
| 3 | +from splashscreen import Splashscreen |
| 4 | +from wakeup import wakeup |
| 5 | + |
| 6 | + |
| 7 | +splashscreen = Splashscreen() |
| 8 | + |
| 9 | + |
| 10 | +class Result: |
| 11 | + aborted = """<span color="red" weight="bold">Aborted</span>""" |
| 12 | + failure = """<span color="red" weight="bold">Failed</span>""" |
| 13 | + success = """<span color="green" weight="bold">Success</span>""" |
| 14 | + started = """<span color="orange" weight="bold">Started</span>""" |
| 15 | + |
| 16 | + |
| 17 | +class Test: |
| 18 | + total_tests = 0 |
| 19 | + |
| 20 | + def __init__(self, name): |
| 21 | + self.id = self.total_tests |
| 22 | + self.name = name |
| 23 | + Test.total_tests += 1 |
| 24 | + self.start() |
| 25 | + |
| 26 | + def aborted(self): |
| 27 | + splashscreen.add_text_box( |
| 28 | + f"{self.name}: {Result.started}", |
| 29 | + {"x": 960, "y": 480 + (60 * self.id)}, |
| 30 | + ) |
| 31 | + |
| 32 | + def start(self): |
| 33 | + splashscreen.add_text_box( |
| 34 | + f"{self.name}: {Result.started}", |
| 35 | + {"x": 960, "y": 480 + (60 * self.id)}, |
| 36 | + ) |
| 37 | + |
| 38 | + def success(self): |
| 39 | + splashscreen.add_text_box( |
| 40 | + f"{self.name}: {Result.success}", |
| 41 | + {"x": 960, "y": 480 + (60 * self.id)}, |
| 42 | + ) |
| 43 | + |
| 44 | + def failure(self): |
| 45 | + splashscreen.add_text_box( |
| 46 | + f"{self.name}: {Result.failure}", |
| 47 | + {"x": 960, "y": 480 + (60 * self.id)}, |
| 48 | + ) |
| 49 | + |
| 50 | + |
| 51 | +# Verbose testing of the ROM store, likely largely unnecessary - a subset should be sufficient to verify things have flashed correctly. |
| 52 | +class TestFactorySettings: |
| 53 | + def __init__(self, on_fail, on_pass): |
| 54 | + self.key_store = KvStore() |
| 55 | + self.image_store = ImageStore() |
| 56 | + self.completed_checks = [] |
| 57 | + self.on_pass = on_pass |
| 58 | + self.on_fail = on_fail |
| 59 | + self.test() |
| 60 | + |
| 61 | + def test(self): |
| 62 | + self.image_test = Test("Images") |
| 63 | + self.key_test = Test("Key Values") |
| 64 | + self.code_test = Test("Factory App") |
| 65 | + self.image_timer = wakeup(self.test_images, 0) |
| 66 | + self.key_timer = wakeup(self.test_key_values, 0) |
| 67 | + self.code_timer = wakeup(self.test_factory_app, 0) |
| 68 | + |
| 69 | + def show_next_image(self): |
| 70 | + if not self.images: |
| 71 | + self.image_timer.cancel() |
| 72 | + # self.on_pass(self.scenario) |
| 73 | + self.image_test.success() |
| 74 | + self.check_complete("images") |
| 75 | + else: |
| 76 | + image = self.images.pop() |
| 77 | + token = self.image_store.get_token(image) |
| 78 | + splashscreen.set_background(token) |
| 79 | + |
| 80 | + def test_images(self): |
| 81 | + self.images = self.image_store.list() |
| 82 | + expected_images = ["default"] |
| 83 | + if self.images != expected_images: |
| 84 | + self.image_timer = wakeup(self.show_next_image, 0, 2000) |
| 85 | + else: |
| 86 | + self.image_test.failure() |
| 87 | + self.abort() |
| 88 | + |
| 89 | + def test_key_values(self): |
| 90 | + self.keys = self.key_store.list() |
| 91 | + if self.keys != []: |
| 92 | + self.key_test.failure() |
| 93 | + self.abort() |
| 94 | + else: |
| 95 | + self.key_test.success() |
| 96 | + self.check_complete("key_values") |
| 97 | + |
| 98 | + def test_factory_app(self): |
| 99 | + self.code_store = CodeStore() |
| 100 | + checksum = self.code_store.info()["checksum"] |
| 101 | + if checksum != 2340183109: |
| 102 | + self.code_test.failure() |
| 103 | + self.abort() |
| 104 | + else: |
| 105 | + self.code_test.success() |
| 106 | + self.check_complete("factory_app") |
| 107 | + |
| 108 | + def abort(self): |
| 109 | + self.image_timer.cancel() |
| 110 | + self.key_timer.cancel() |
| 111 | + self.code_timer.cancel() |
| 112 | + self.on_fail("", "") |
| 113 | + |
| 114 | + def check_complete(self, check): |
| 115 | + self.completed_checks.append(check) |
| 116 | + if len(self.completed_checks) == 3: |
| 117 | + self.on_pass("") |
| 118 | + |
| 119 | + |
| 120 | +class TestRosewood: |
| 121 | + def __init__(self): |
| 122 | + self.dock_control = DockControl() |
| 123 | + self.tests = [TestFactorySettings] |
| 124 | + |
| 125 | + def next_test(self): |
| 126 | + if self.tests: |
| 127 | + test_class = self.tests.pop() |
| 128 | + test = test_class(self.fail, self.passed) |
| 129 | + else: |
| 130 | + self.exit_test_mode(True) |
| 131 | + |
| 132 | + def fail(self, scenario, reason): |
| 133 | + splashscreen.add_text_box( |
| 134 | + f"Overall: {Result.failure}", |
| 135 | + {"x": 960, "y": 800}, |
| 136 | + ) |
| 137 | + self.exit_test_mode(False) |
| 138 | + |
| 139 | + def enter_test_mode(self): |
| 140 | + splashscreen.add_text_box("ROSEWOOD TEST MODE") |
| 141 | + # self.dock_control.set_test_mode(True) |
| 142 | + wakeup(self.next_test, 2000) |
| 143 | + |
| 144 | + def exit_test_mode(self, passed): |
| 145 | + if passed: |
| 146 | + splashscreen.add_text_box( |
| 147 | + f"Final result: {Result.success}", |
| 148 | + {"x": 960, "y": 800}, |
| 149 | + ) |
| 150 | + # self.dock_control.set_test_mode(False) |
| 151 | + |
| 152 | + def passed(self, scenario): |
| 153 | + self.next_test() |
| 154 | + |
| 155 | + |
| 156 | +application = TestRosewood() |
| 157 | +application.enter_test_mode() |
0 commit comments