From 55271ffa4d6235de5c6167b2ec8d07a6805f6003 Mon Sep 17 00:00:00 2001 From: charles37 Date: Fri, 15 Nov 2024 11:43:44 -0500 Subject: [PATCH] fix lua-hello --- hwci/tests/lua-hello.py | 43 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/hwci/tests/lua-hello.py b/hwci/tests/lua-hello.py index 318f5bc..708ad34 100644 --- a/hwci/tests/lua-hello.py +++ b/hwci/tests/lua-hello.py @@ -2,6 +2,47 @@ # SPDX-License-Identifier: Apache-2.0 OR MIT # Copyright Tock Contributors 2024. +import logging +import os +import subprocess from utils.test_helpers import WaitForConsoleMessageTest +from utils.test_helpers import OneshotTest -test = WaitForConsoleMessageTest(["lua-hello"], "Hello from Lua!") + +class LuaHelloTest(WaitForConsoleMessageTest): + def __init__(self): + super().__init__(["lua-hello"], "Hello from Lua!") + + def test(self, board): + # Initialize and update Lua submodule before running the test + libtock_c_dir = os.path.join( + os.path.dirname( + os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + ), + "libtock-c", + ) + lua_dir = os.path.join(libtock_c_dir, "examples", "lua-hello") + + try: + # Initialize the Lua submodule + logging.info("Initializing Lua submodule...") + subprocess.run( + ["git", "submodule", "init", "--", "lua"], cwd=lua_dir, check=True + ) + + # Update the Lua submodule + logging.info("Updating Lua submodule...") + subprocess.run(["git", "submodule", "update"], cwd=lua_dir, check=True) + + # Run the parent class's test method + super().test(board) + + except subprocess.CalledProcessError as e: + logging.error(f"Failed to initialize/update Lua submodule: {e}") + raise + except Exception as e: + logging.error(f"Error during test execution: {e}") + raise + + +test = LuaHelloTest()