From 2104b005a4c0b2395f6bef3dcb28a944ece4ef65 Mon Sep 17 00:00:00 2001 From: bhanucbp <141142298+bhanucbp@users.noreply.github.com> Date: Thu, 12 Dec 2024 19:56:55 +0000 Subject: [PATCH] gh #44 L3 test case development Added python file to run all tests Used monitor function to get the adaptor logs --- .../hdmiCEC_L3_Tests/hdmiCECHelperClass.py | 7 +- .../hdmiCEC_L3_Tests/hdmiCEC_L3_Runall.py | 73 +++++++++++++++++++ .../hdmiCEC_L3_Tests/hdmiCEC_L3_testSetup.yml | 29 -------- .../hdmiCEC_test01_TransmitCECCommands.py | 8 +- .../hdmiCEC_test02_ReceiveCECCommands.py | 3 + 5 files changed, 85 insertions(+), 35 deletions(-) create mode 100644 host/tests/hdmiCEC_L3_Tests/hdmiCEC_L3_Runall.py delete mode 100755 host/tests/hdmiCEC_L3_Tests/hdmiCEC_L3_testSetup.yml diff --git a/host/tests/hdmiCEC_L3_Tests/hdmiCECHelperClass.py b/host/tests/hdmiCEC_L3_Tests/hdmiCECHelperClass.py index d6d113d..f75eb56 100755 --- a/host/tests/hdmiCEC_L3_Tests/hdmiCECHelperClass.py +++ b/host/tests/hdmiCEC_L3_Tests/hdmiCECHelperClass.py @@ -53,16 +53,12 @@ def __init__(self, testName:str, qcId:str, log:logModule=None ): log (logModule, optional): Parent log module instance for logging. Defaults to None. """ self.testName = "" - self.testSetupPath = os.path.join(dir_path, "hdmiCEC_L3_testSetup.yml") self.moduleName = "hdmicec" self.rackDevice = "dut" # Initialize the base helper class super().__init__(testName, qcId, log) - # Load test setup configuration - self.testSetup = ConfigRead(self.testSetupPath, self.moduleName) - # Open Sessions hal test self.hal_session = self.dut.getConsoleSession("ssh_hal_test") @@ -80,7 +76,6 @@ def __init__(self, testName:str, qcId:str, log:logModule=None ): self.testCECCommands = os.path.join(dir_path, "hdmiCECTestCommands.yml") hdmicec = ConfigRead(self.testCECCommands, self.moduleName) self.cecCommands = hdmicec.fields.get(self.testName) - self.hdmiCECController = self.dut.hdmiCECController def testPrepareFunction(self): """ @@ -100,5 +95,7 @@ def testPrepareFunction(self): def testEndFunction(self, powerOff=True): + super().testEndFunction(powerOff) # Clean up the hdmiCEC instance del self.testhdmiCEC + diff --git a/host/tests/hdmiCEC_L3_Tests/hdmiCEC_L3_Runall.py b/host/tests/hdmiCEC_L3_Tests/hdmiCEC_L3_Runall.py new file mode 100644 index 0000000..05748ec --- /dev/null +++ b/host/tests/hdmiCEC_L3_Tests/hdmiCEC_L3_Runall.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 +#** ***************************************************************************** +# * +# * If not stated otherwise in this file or this component's LICENSE file the +# * following copyright and licenses apply: +# * +# * Copyright 2024 RDK Management +# * +# * Licensed under the Apache License, Version 2.0 (the "License"); +# * you may not use this file except in compliance with the License. +# * You may obtain a copy of the License at +# * +# * +# http://www.apache.org/licenses/LICENSE-2.0 +# * +# * Unless required by applicable law or agreed to in writing, software +# * distributed under the License is distributed on an "AS IS" BASIS, +# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# * See the License for the specific language governing permissions and +# * limitations under the License. +# * +#* ****************************************************************************** + +import os +import sys +import importlib +from pathlib import Path + +dir_path = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(dir_path)) +sys.path.append(os.path.join(dir_path, "../")) +sys.path.append(os.path.join(dir_path, "../raft")) + +from raft.framework.core.logModule import logModule + +def Runall_L3(): + skipTests = [] + # Summery log for all the tests + hdmiCECSummerLog = logModule("hdmiCEC_Sink", level=logModule.INFO) + + testDirectory = Path(dir_path) + + # Find all test modules in the directory + test_modules = sorted(testDirectory.glob("hdmiCEC_test*.py")) + + # Run each test by dynamically importing and instantiating + for test_module_path in test_modules: + # Construct module name from file name, excluding .py extension + module_name = test_module_path.stem + skip = False + for skipTest in skipTests: + if skipTest in module_name: + skip = True + break + if skip: + continue + try: + # Dynamically import the module + module = importlib.import_module(module_name) + + # Dynamically access the test class from the module + # Assuming each test file has only one class named the same as the module + test_class = getattr(module, module_name) + + # Instantiate and run the test + test_instance = test_class(hdmiCECSummerLog) + test_instance.run(False) + + except (ImportError, AttributeError) as e: + hdmiCECSummerLog.error(f"Failed to import {module_name}: {e}") + +if __name__ == '__main__': + Runall_L3() \ No newline at end of file diff --git a/host/tests/hdmiCEC_L3_Tests/hdmiCEC_L3_testSetup.yml b/host/tests/hdmiCEC_L3_Tests/hdmiCEC_L3_testSetup.yml deleted file mode 100755 index 8da1aa5..0000000 --- a/host/tests/hdmiCEC_L3_Tests/hdmiCEC_L3_testSetup.yml +++ /dev/null @@ -1,29 +0,0 @@ -#** ***************************************************************************** -# * -# * If not stated otherwise in this file or this component's LICENSE file the -# * following copyright and licenses apply: -# * -# * Copyright 2024 RDK Management -# * -# * Licensed under the Apache License, Version 2.0 (the "License"); -# * you may not use this file except in compliance with the License. -# * You may obtain a copy of the License at -# * -# * -# http://www.apache.org/licenses/LICENSE-2.0 -# * -# * Unless required by applicable law or agreed to in writing, software -# * distributed under the License is distributed on an "AS IS" BASIS, -# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# * See the License for the specific language governing permissions and -# * limitations under the License. -# * -#* ****************************************************************************** - -hdmicec: - description: "hdmiCEC test setup" - assets: - device: - test01_TransmitCECCommands: - test02_ReceiveCECCommands: - diff --git a/host/tests/hdmiCEC_L3_Tests/hdmiCEC_test01_TransmitCECCommands.py b/host/tests/hdmiCEC_L3_Tests/hdmiCEC_test01_TransmitCECCommands.py index 8f3919c..f45a26f 100755 --- a/host/tests/hdmiCEC_L3_Tests/hdmiCEC_test01_TransmitCECCommands.py +++ b/host/tests/hdmiCEC_L3_Tests/hdmiCEC_test01_TransmitCECCommands.py @@ -23,6 +23,7 @@ import os import sys +import time # Append the current and parent directory paths to sys.path for module imports dir_path = os.path.dirname(os.path.realpath(__file__)) @@ -32,7 +33,6 @@ # Importing helper classes and modules for HDMI-CEC testing and logging from hdmiCECHelperClass import hdmiCECHelperClass from raft.framework.core.logModule import logModule -from raft.framework.plugins.ut_raft.configRead import ConfigRead class hdmiCEC_test01_TransmitCECCommands(hdmiCECHelperClass): """ @@ -86,6 +86,8 @@ def testFunction(self): # Final test result finalResult = True + self.hdmiCECController.startMonitoring() + for device in self.cecDevices: logicalAddress = device["logical address"] @@ -107,6 +109,8 @@ def testFunction(self): # Transmit the CEC command self.testhdmiCEC.cecTransmitCmd(destinationLogicalAddress, cec, payload) + time.sleep(2) + self.log.stepStart(f'HdmiCecTx Source: {deviceLogicalAddress} Destination: {destinationLogicalAddress} CEC OPCode: {cec} Payload: {payload}') # Validate the transmission @@ -116,6 +120,8 @@ def testFunction(self): finalResult &= result + self.hdmiCECController.stopMonitoring() + # Remove the Logical Address self.testhdmiCEC.removeLogicalAddress() diff --git a/host/tests/hdmiCEC_L3_Tests/hdmiCEC_test02_ReceiveCECCommands.py b/host/tests/hdmiCEC_L3_Tests/hdmiCEC_test02_ReceiveCECCommands.py index b433ae0..5151309 100644 --- a/host/tests/hdmiCEC_L3_Tests/hdmiCEC_test02_ReceiveCECCommands.py +++ b/host/tests/hdmiCEC_L3_Tests/hdmiCEC_test02_ReceiveCECCommands.py @@ -120,6 +120,7 @@ def testFunction(self): # Get the logical address of the HDMI-CEC adapter cecAdapterLogicalAddress = self.cecAdaptor["logical address"] + self.hdmiCECController.startMonitoring() finalResult = True for command in self.cecCommands: result = False @@ -160,6 +161,8 @@ def testFunction(self): finalResult &= result + self.hdmiCECController.stopMonitoring() + # Remove the Logical Address self.testhdmiCEC.removeLogicalAddress()