From 329c86fb779d08b89329be12e89e390165e95f36 Mon Sep 17 00:00:00 2001 From: srinivasgtl <71806084+srinivasgtl@users.noreply.github.com> Date: Thu, 5 Dec 2024 11:39:20 +0000 Subject: [PATCH] gh #44 Updated test cases to use cec adaptor --- .vscode/launch.json | 35 ++++++++++++++ host/tests/classes/hdmiCEC.py | 29 +++++++----- .../hdmiCEC_L3_Tests/hdmiCECHelperClass.py | 9 ++-- .../hdmiCEC_L3_Tests/hdmiCECTestCommands.yml | 14 ++++++ .../hdmiCEC_L3_Tests/hdmiCEC_L3_testSetup.yml | 4 -- ...nsmitSingleStandbyCommandandValidateAck.py | 47 +++++++++++++++---- src/main.c | 26 ++-------- 7 files changed, 112 insertions(+), 52 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 host/tests/hdmiCEC_L3_Tests/hdmiCECTestCommands.yml diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..51fc070 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,35 @@ +{ + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python Debugger: Current File", + "type": "debugpy", + "request": "launch", + "program": "${file}", + "args": [ "--config", "example_rack_config.yml", + "--deviceConfig", "deviceConfig.yml"], + "console": "integratedTerminal" + }, + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "stopAtEntry": false, + "externalConsole": false, + "cwd": "${workspaceFolder}", + "program": "${workspaceFolder}/bin/hal_test", + "environment": [ {"name": "LD_LIBRARY_PATH", "value":"${workspaceFolder}/bin/"} ], + "args": [ "-l", "${workspaceFolder}/logs/", "-p", "${workspaceFolder}/profiles/sink/Sink_AudioSettings.yaml" ], + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} diff --git a/host/tests/classes/hdmiCEC.py b/host/tests/classes/hdmiCEC.py index b61f3ee..9a1ecfb 100644 --- a/host/tests/classes/hdmiCEC.py +++ b/host/tests/classes/hdmiCEC.py @@ -56,8 +56,8 @@ def __init__(self, moduleConfigProfileFile :str, session=None, targetWorkspace=" None """ self.moduleName = "hdmiCEC" - self.testConfigFile = os:.path.join(dir_path, "hdmiCEC_testConfig.yml") - self.testSuite = "L3 hdmicec - Sink" + self.testConfigFile = os.path.join(dir_path, "hdmiCEC_testConfig.yml") + self.testSuite = "L3 HDMICEC Sink Functions" # Load configurations for device profile and menu self.moduleConfigProfile = ConfigRead( moduleConfigProfileFile , self.moduleName) @@ -146,7 +146,7 @@ def removeLogicalAddress(self, logicalAddress:int): Remove logical address. Args: - logicalAddress (int): The Logical address of the DUT that should be removed. + logicalAddress (int): The Logical address of the DUT that should be removed. Returns: None @@ -190,8 +190,6 @@ def getPhysicalAddress(self): Returns: int: Physical Address of the DUT. """ - - result = self.utMenu.select( self.testSuite, "L3_GetPhyiscalAddress") typeStatusPattern = r"HdmiCecGetPhysicalAddress\(IN: handle: [.*\], physicalAddress: [.*\]), status:[.*\]" physicalAddress = self.searchPattern(result, typeStatusPattern) @@ -200,7 +198,7 @@ def getPhysicalAddress(self): def cecTransmitCmd(self, sourceLogicalAddress:int, destLogicalAddress:int, cecCommand:int, cecData:list=None): """ - Transmit/Broadcast the CEC command and data to the respective destination. + Transmit/Broadcast the CEC command and data to the respective destination. Args: None. @@ -233,8 +231,8 @@ def cecTransmitCmd(self, sourceLogicalAddress:int, destLogicalAddress:int, cecCo { "query_type": "direct", "query": "Enter Databyte", - "input": str(byte) - }) + "input": str(byte) + }) result = self.utMenu.select( self.testSuite, "L3_TransmitCecCommand",promptWithAnswers) @@ -257,16 +255,21 @@ def __del__(self): shell = InteractiveShell() shell.open() - platformProfile = dir_path + "/../../../profiles/sink/Sink_AudioSettings.yaml" + platformProfile = dir_path + "/../../../profiles/sink/sink_hdmiCEC.yaml" + # test the class assuming that it's optional - test = dsAudioClass(platformProfile, shell) + test = hdmiCECClass(platformProfile, shell) + # Initialize the hdmiCEC module test.initialise() - ports = test.getSupportedPorts() - test.enablePort(ports[0][0], ports[0][1]) - test.disablePort(ports[0][0], ports[0][1]) + # Add the logical Address. For now 0 only. + test.addLogicalAddress(0) + + # Get Physical Address + physicalAddress = test.getPhysicalAddress() + # Close the device test.terminate() shell.close() diff --git a/host/tests/hdmiCEC_L3_Tests/hdmiCECHelperClass.py b/host/tests/hdmiCEC_L3_Tests/hdmiCECHelperClass.py index a95ded8..dcabad0 100755 --- a/host/tests/hdmiCEC_L3_Tests/hdmiCECHelperClass.py +++ b/host/tests/hdmiCEC_L3_Tests/hdmiCECHelperClass.py @@ -26,12 +26,13 @@ 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, "../")) from raft.framework.plugins.ut_raft.configRead import ConfigRead from raft.framework.plugins.ut_raft.utUserResponse import utUserResponse from raft.framework.plugins.ut_raft import utHelperClass from raft.framework.core.logModule import logModule -from classes.hdmCEC import hdmiCECClass +from classes.hdmiCEC import hdmiCECClass class hdmiCECHelperClass(utHelperClass): @@ -45,7 +46,7 @@ def __init__(self, testName:str, qcId:str, log:logModule=None ): log (class, optional): Parent log class. Defaults to None. """ self.testName = "" - self.testSetupPath = os.path.join(dir_path, "hdmiCEC__L3_testSetup.yml") + self.testSetupPath = os.path.join(dir_path, "hdmiCEC_L3_testSetup.yml") self.moduleName = "hdmiCEC" self.rackDevice = "dut" @@ -130,7 +131,7 @@ def testPrepareFunction(self): # Run Prerequisites listed in the test setup configuration file - self.testRunPrerequisites() + #self.testRunPrerequisites() # Create the hdmiCEC class self.testhdmiCEC = hdmiCECClass(self.moduleConfigProfileFile, self.hal_session, self.targetWorkspace) @@ -139,7 +140,7 @@ def testPrepareFunction(self): def testEndFunction(self, powerOff=True): # Clean the assets downloaded to the device - self.testCleanAssets() + #self.testCleanAssets() # Clean up the hdmiCEC instance del self.testhdmiCEC diff --git a/host/tests/hdmiCEC_L3_Tests/hdmiCECTestCommands.yml b/host/tests/hdmiCEC_L3_Tests/hdmiCECTestCommands.yml new file mode 100644 index 0000000..e3ae591 --- /dev/null +++ b/host/tests/hdmiCEC_L3_Tests/hdmiCECTestCommands.yml @@ -0,0 +1,14 @@ +hdmiCEC: + test01_TransmitSingleStandbyCommandandValidateAck: + - command: "0x36" # Standby + responses: + - type: "power_status" + loop_devices: true # Apply this response to all devices in the device map + payload: "[:sender]:90:[:power_status]" # Response pattern with placeholders + description: "Devices report their power status" + - command: "0x8F" # Request Power Status + responses: + - type: "power_status_response" + loop_devices: true # Apply this response to all devices in the device map + payload: "[:sender]:90:[:power_status]" # Response pattern with placeholders + description: "Devices respond with their current power status" \ 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 index bf903d3..9abc501 100755 --- a/host/tests/hdmiCEC_L3_Tests/hdmiCEC_L3_testSetup.yml +++ b/host/tests/hdmiCEC_L3_Tests/hdmiCEC_L3_testSetup.yml @@ -26,10 +26,6 @@ hdmiCEC: # Prefix must always exist assets: device: test01_TransmitSingleStandbyCommandandValidateAck: - <<: *defaults test02_BroadcastStandbyCommand: - <<: *defaults test03_TransmitOSDCommandandValidateAck: - <<: *defaults test04_TransmitLargerOSDCommandRepeatedlyandValidate: - <<: *defaults diff --git a/host/tests/hdmiCEC_L3_Tests/hdmiCEC_test01_TransmitSingleStandbyCommandandValidateAck.py b/host/tests/hdmiCEC_L3_Tests/hdmiCEC_test01_TransmitSingleStandbyCommandandValidateAck.py index ae2a09d..bd21665 100755 --- a/host/tests/hdmiCEC_L3_Tests/hdmiCEC_test01_TransmitSingleStandbyCommandandValidateAck.py +++ b/host/tests/hdmiCEC_L3_Tests/hdmiCEC_test01_TransmitSingleStandbyCommandandValidateAck.py @@ -30,6 +30,7 @@ from hdmiCECHelperClass import hdmiCECHelperClass from raft.framework.core.logModule import logModule +from raft.framework.plugins.ut_raft.configRead import ConfigRead class hdmiCEC_test01_TransmitSingleStandbyCommandandValidateAck(hdmiCECHelperClass): """ @@ -50,6 +51,13 @@ def __init__(self, log:logModule=None): self.testName = "test01_TransmitSingleStanbyCommandandValidateAck" self.qcID = '1' + self.testCECCommands = os.path.join(dir_path, "hdmiCECTestCommands.yml") + hdmicec = ConfigRead(self.testCECCommands, "hdmiCEC") + self.cecCommands = hdmicec.fields.get("test01_TransmitSingleStandbyCommandandValidateAck") + for command in self.cecCommands: + cec = command.get("command") + payload = command.get("payload") + print(cec, payload) super().__init__(self.testName, self.qcID, log) #TODO: Current version supports only manual verification. @@ -57,7 +65,7 @@ def testVerifyStanbyStatus(self, ack, manual=False): """ Verifies the CEC Transmit Status through the result and also through the manual input. - For manual verification, it prompts the user to confirm if CEC data is received by the destination + For manual verification, it prompts the user to confirm if CEC data is received by the destination device and the action has been performed. Args: @@ -69,7 +77,7 @@ def testVerifyStanbyStatus(self, ack, manual=False): bool: True if ACK verification succeeds, False otherwise.Also True if Manual test is Y and Flase if N """ if manual == True: - return self.testUserResponse.getUserYN(f"Is Stanby Command honored {port}? (Y/N):") + return self.testUserResponse.getUserYN(f"Is Stanby Command honored? (Y/N):") else : #TODO: Add automation verification methods return False @@ -79,7 +87,7 @@ def testFunction(self): The main test function that Transmits the Stanby Command and checks the ACK and validates it. This function: - - Send a standby command to a device that is connected on the CEC network and get the ack. + - Send a standby command to a device that is connected on the CEC network and get the ack. - User to confirm whether the targetted device had recieved this command or not. Returns: @@ -89,17 +97,36 @@ def testFunction(self): # Initialize the hdmiCEC module self.testhdmiCEC.initialise() - # Add the logical Address + # Add the logical Address. For now 0 only. self.testhdmiCEC.addLogicalAddress(0) - # Transmit Standby command to a specific destination address - self.testhdmiCEC.cecTransmitCmd(0,3,65,[0]) + self.cecDevices = [1,2,3]#self.cecAdapter.listDevices() - #Verify the test result - result = self.testVerifyStandbyStatus(ack, True) + for device in self.cecDevices: + logicalAddress = 1#int(device["address"].split('.')[0]) - # Remove the Logical Address - self.testhdmiCEC.removeLogicalAddress(0) + # To bypass sending the message to TV + if logicalAddress == 0 or logicalAddress == 14: + continue + + # self.log.stepStart(f'HdmiCecTx(IN: handle: [0x%0X], IN: length: [%d], result: [%d], status:[%d]') + + for command in self.cecCommands: + cec = command.get("command") + payload = command.get("payload") + #result = self.cecAdapter.startMonitoring() + #print(result) + # Transmit Standby command to a specific destination address + self.testhdmiCEC.cecTransmitCmd(0, logicalAddress,cec,payload) + #self.cecAdapter.stopMonitoring() + + #Verify the test result + result = self.testVerifyStanbyStatus(logicalAddress, True) + + self.log.stepResult() + + # Remove the Logical Address + self.testhdmiCEC.removeLogicalAddress(0) # Terminate dsAudio Module self.testdsAudio.terminate() diff --git a/src/main.c b/src/main.c index f2eb0ba..5c18bb2 100644 --- a/src/main.c +++ b/src/main.c @@ -113,36 +113,20 @@ int main(int argc, char** argv) } optind = 1; //Reset argv[] element pointer for further processing #endif - + /* Register tests as required, then call the UT-main to support switches and triggering */ UT_init( argc, argv ); - status = ut_kvp_getStringField(ut_kvp_profile_getInstance(), "hdmicec/type", szReturnedString, UT_KVP_MAX_ELEMENT_SIZE); - if (status == UT_KVP_STATUS_SUCCESS ) { - UT_LOG_DEBUG("Device Type: %s", szReturnedString); - } - else { - UT_LOG_ERROR("Failed to get the platform Device Type"); - return -1; - } - register_hdmicec_hal_common_l1_tests(); #ifdef VCOMPONENT register_vcomponent_tests(pProfilePath); test_l3_hdmi_cec_driver_register (pValidationProfilePath); #endif - - if(strncmp(szReturnedString,"source",UT_KVP_MAX_ELEMENT_SIZE) == 0) { - register_hdmicec_hal_source_l1_tests (); - register_hdmicec_hal_source_l2_tests (); - } - - if(strncmp(szReturnedString,"sink",UT_KVP_MAX_ELEMENT_SIZE) == 0) { - register_hdmicec_hal_sink_l1_tests (); - register_hdmicec_hal_sink_l2_tests (); + register_hdmicec_hal_source_l1_tests (); + register_hdmicec_hal_source_l2_tests (); + register_hdmicec_hal_sink_l1_tests (); + register_hdmicec_hal_sink_l2_tests (); register_hdmicec_hal_sink_l3_tests (); - } - UT_run_tests(); #ifdef VCOMPONENT