Skip to content

Commit

Permalink
gh #44 L3 test case development
Browse files Browse the repository at this point in the history
Updated the code with comments and cleanup
  • Loading branch information
bhanucbp authored and Bhanu Prakash committed Dec 17, 2024
1 parent 079741e commit 3e943a3
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 189 deletions.
63 changes: 38 additions & 25 deletions host/tests/classes/hdmiCEC.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,20 @@

class hdmiCECClass():
"""
HDMI CEC Class.
HDMI CEC Class.
This module provides common functionalities and extensions for the HDMI CEC Module.
Provides functionalities for initializing, configuring, and controlling
HDMI CEC (Consumer Electronics Control) operations in the test environment.
"""

def __init__(self, moduleConfigProfileFile :str, session=None, targetWorkspace="/tmp"):
def __init__(self, moduleConfigProfileFile:str, session=None, targetWorkspace:str="/tmp"):
"""
Initializes the HDMI CEC Class instance with configuration settings.
Initialize the HDMI CEC Class with configuration settings.
Args:
moduleConfigProfileFile (str): Path to the device profile configuration file.
session: Optional; session object for the user interface.
moduleConfigProfileFile (str): Path to the profile configuration file for the HDMI CEC module.
session: Optional session object for managing interactions with the device.
targetWorkspace (str, optional): Target workspace directory on the device. Defaults to "/tmp".
Returns:
None
Expand All @@ -56,19 +58,22 @@ def __init__(self, moduleConfigProfileFile :str, session=None, targetWorkspace="
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)
# Prepare the profile file on the target workspace
profileOnTarget = os.path.join(targetWorkspace, os.path.basename(moduleConfigProfileFile))
self.testConfig = ConfigRead(self.testConfigFile, self.moduleName)
self.testConfig.test.execute = os.path.join(targetWorkspace, self.testConfig.test.execute)
self.testConfig.test.execute = os.path.join(targetWorkspace, self.testConfig.test.execute) + f" -p {profileOnTarget}"
self.utMenu = UTSuiteNavigatorClass(self.testConfig, None, session)
self.testSession = session
self.utils = utBaseUtils()
self.ports = self.moduleConfigProfile.fields.get("Ports")

# Copy required artifacts to the target workspace
for artifact in self.testConfig.test.artifacts:
filesPath = os.path.join(dir_path, artifact)
self.utils.rsync(self.testSession, filesPath, targetWorkspace)

# Copy the profile configuration to the target workspace
self.utils.scpCopy(self.testSession, moduleConfigProfileFile, targetWorkspace)

# Start the user interface menu
self.utMenu.start()

Expand Down Expand Up @@ -118,11 +123,10 @@ def terminate(self):

def addLogicalAddress(self, logicalAddress:str='0'):
"""
Adding the logical address of a specific device.
For now Sink to support only the logical address 0.
Add a logical address for the device.
Args:
logicalAddress (str): The Logical address of the DUT. This will be fixed to zero for a sink device for now.
logicalAddress (str, optional): Logical address of the device. Defaults to '0'. Value ranges from '0' - 'f'
Returns:
None
Expand All @@ -138,10 +142,10 @@ def addLogicalAddress(self, logicalAddress:str='0'):

def removeLogicalAddress(self):
"""
Remove logical address.
Remove the logical address of the device.
Args:
logicalAddress (int): The Logical address of the DUT that should be removed.
None
Returns:
None
Expand All @@ -150,13 +154,13 @@ def removeLogicalAddress(self):

def getLogicalAddress(self):
"""
Retrieves the Logical Address of the DUT.
Get the logical address of the device.
Args:
None.
Returns:
int: Logical address of the device.
str: Logical address of the device. Value ranges from '0' - 'f'
"""
result = self.utMenu.select( self.testSuite, "Get Logical Address")
connectionStatusPattern = r"Result HdmiCecGetLogicalAddress\(IN:handle:\[0x[0-9A-F]+\], OUT:logicalAddress:\[([0-9A-Fa-f]+)\]\)"
Expand All @@ -166,13 +170,13 @@ def getLogicalAddress(self):

def getPhysicalAddress(self):
"""
Retrieve the Physical Address of the DUT.
Get the physical address of the device.
Args:
None.
Returns:
int: Physical Address of the DUT.
str: Physical Address of the DUT.
"""
result = self.utMenu.select( self.testSuite, "Get Phyiscal Address")
typeStatusPattern = r"Result HdmiCecGetPhysicalAddress\(IN:handle:[.*\], OUT:physicalAddress:[.*\]) HDMI_CEC_STATUS:[.*\]"
Expand All @@ -182,10 +186,12 @@ def getPhysicalAddress(self):

def cecTransmitCmd(self, destLogicalAddress:str, cecCommand:str, cecData:list=None):
"""
Transmit/Broadcast the CEC command and data to the respective destination.
Transmit or broadcast a CEC command to a specified destination.
Args:
None.
destLogicalAddress (str): Destination logical address.
cecCommand (str): CEC command in hexadecimal.
cecData (list, optional): List of data bytes to include in the transmission.
Returns:
None
Expand Down Expand Up @@ -233,10 +239,8 @@ def readCallbackDetails (self):
- "Destination" (str): The destination address in hexadecimal.
- "Data" (list): The data associated with the opcode.
"""
result = {
"Received": [],
"Response": []
}
result = {"Received": [], "Response": []}

callbackLogs = self.testSession.read_all()

received_pattern = re.compile(
Expand Down Expand Up @@ -304,6 +308,15 @@ def __del__(self):
# Get Physical Address
physicalAddress = test.getPhysicalAddress()

# Broadcast 0x85 cec command
test.cecTransmitCmd('f', '0x85')

# Transmitt 0x04 cec command to '1'
test.cecTransmitCmd('1', '0x85')

# Read the callback details
result = test.readCallbackDetails()

# Close the device
test.terminate()

Expand Down
2 changes: 1 addition & 1 deletion host/tests/classes/hdmiCEC_testConfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ hdmicec:
#List of artifacts folders, test class copies the content of folder to the target device workspace
- "../../../bin/"
# exectute command, this will appended with the target device workspace path
execute: "run.sh -p sink_hdmiCEC.yml"
execute: "run.sh"
type: UT-C # C (UT-C Cunit) / C++ (UT-G (g++ ut-core gtest backend))
suites:
0:
Expand Down
4 changes: 1 addition & 3 deletions host/tests/configs/deviceConfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ deviceConfig:
target_directory: "/tmp/" # Target Directory on device
prompt: "" # Prompt string on console
test:
#TODO: Use the single profile file which contains all details (ds, hdmi, etc)
profile: "../../../../profiles/sink/sink_hdmiCEC_test.yaml"
streams_download_url: "<URL_Path>" #URL path from which the streams are downloaded to the device
profile: "../../../profiles/sink/sink_hdmiCEC.yml"
cpe2:
platform: "test"
model: "test"
Expand Down
43 changes: 19 additions & 24 deletions host/tests/configs/example_rack_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,6 @@ globalConfig:
# [ includes: ]
# [ deviceConfig: "required.yml file" ]
deviceConfig: "example_device_config.yml"
capture:
# [capture: optional]
# [ocrEnginePath: "/usr/bin/tesseract"] # "C:\\Program Files\\Tesseract-OCR\\tesseract.exe" (For Windows) - tesseract binary
# [resolution: "1080p"] - Capture resolution
# [input: 0] - which input is connected to the video path
# Note: Video capture will not be installed unless screenRegions: is defined in deviceConfig:
ocrEnginePath: "/usr/bin/tesseract" # "C:\\Program Files\\Tesseract-OCR\\tesseract.exe" (For Windows)
resolution: "1080p"
input: 0
cec-adaptor:
type: cec-client
adaptor: /dev/ttyACM0
local:
log: # log for each slot
directory: "./logs"
Expand All @@ -68,29 +56,36 @@ rackConfig:
# [ type: "ssh": port: 22 username: "test" password: "test" ]
# [ type: "telnet": port: 23 username: "test" password: "test" ]
- dut:
ip: "127.0.0.1" # IP Address of the ADA Hub
description: "local PC"
platform: "PC"
ip: "127.0.0.1"
description: "element"
platform: "element"
consoles:
- default:
type: "ssh"
port: 22
username: "srr07"
ip: "127.0.0.1" #IP address
password: '1234'
username: "root"
ip: "127.0.0.1"
password: ' '
- ssh_player:
type: "ssh"
port: 22
username: "srr07"
ip: "127.0.0.1" #IP address
password: '1234'
username: "root"
ip: "127.0.0.1"
password: ' '
- ssh_hal_test:
type: "ssh"
port: 22
username: "srr07"
ip: "127.0.0.1" #IP address
password: '1234'
username: "root"
ip: "127.0.0.1"
password: ' '
outbound:
download_url: "http://localhost:8000/" # download location for the CPE device
httpProxy: # Local Proxy if required
workspaceDirectory: './logs/workspace' # Local working directory
hdmiCECController:
type: remote-cec-client
vendor: "Pulse Eight"
adaptor: /dev/ttyACM0 # Adaptor device entry
address: "127.0.0.1" # Needs to be be filled out with IP address
username: "root" # Needs to be filled out with login username
password: ' ' # Needs to be filled out with login password
81 changes: 15 additions & 66 deletions host/tests/hdmiCEC_L3_Tests/hdmiCECHelperClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,28 @@

class hdmiCECHelperClass(utHelperClass):

"""
Helper class for managing HDMI CEC tests.
This class extends the `utHelperClass` and provides functionality for preparing
and cleaning up HDMI CEC tests.
"""

def __init__(self, testName:str, qcId:str, log:logModule=None ):
"""
Initializes the test class with test name, setup configuration, and sessions for the device.
Initializes the test helper class with test name, setup configuration, and session management.
Args:
testName (str) : name of the test
qcId (str): QC ID of the test.
log (class, optional): Parent log class. Defaults to None.
testName (str): Name of the test.
qcId (str): Quality Control (QC) ID of the test.
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
Expand All @@ -74,82 +82,23 @@ def __init__(self, testName:str, qcId:str, log:logModule=None ):
self.cecCommands = hdmicec.fields.get(self.testName)
self.hdmiCECController = self.dut.hdmiCECController

# def testDownloadAssets(self):
# """
# Downloads the test artifacts listed in the test setup configuration.
#
# This function retrieves the necessary files and saves them on the DUT.
#
# Args:
# None
# """
#
# # List of streams with path
# self.testStreams = []
# url = []
#
# streamPaths = self.testSetup.get("assets").get("device").get(self.testName).get("streams")
#
# # Download test streams to device
# if streamPaths and self.streamDownloadURL:
# for streamPath in streamPaths:
# url.append(os.path.join(self.streamDownloadURL, streamPath))
# self.testStreams.append(os.path.join(self.targetWorkspace, os.path.basename(streamPath)))
# self.downloadToDevice(url, self.targetWorkspace, self.rackDevice)

# def testCleanAssets(self):
# """
# Removes the downloaded assets and test streams from the DUT after test execution.
#
# Args:
# None
# """
# self.deleteFromDevice(self.testStreams)
#
def testRunPrerequisites(self):
"""
Executes prerequisite commands listed in the test setup configuration file on the DUT.
Args:
None
"""

# Run commands as part of test prerequisites
test = self.testSetup.get("assets").get("device").get(self.testName)
cmds = test.get("execute")
if cmds is not None:
for cmd in cmds:
self.writeCommands(cmd)

def testPrepareFunction(self):
"""
Prepares the environment and assets required for the test.
Cleans up the test environment by deinitializing the HDMI CEC instance.
This function:
- Downloads the required assets.
- Runs the prerequisite commands.
- Creates hdmiCEC
Args:
powerOff (bool, optional): Flag to indicate whether to power off the device. Defaults to True.
Returns:
bool
"""


# Run Prerequisites listed in the test setup configuration file
#self.testRunPrerequisites()

# Create the hdmiCEC class
self.testhdmiCEC = hdmiCECClass(self.moduleConfigProfileFile, self.hal_session, self.targetWorkspace)

return True

def testEndFunction(self, powerOff=True):
# Clean the assets downloaded to the device
#self.testCleanAssets()

# Clean up the hdmiCEC instance
del self.testhdmiCEC

def testExceptionCleanUp (self):
# Clean the assets downloaded to the device
self.testCleanAssets()
22 changes: 22 additions & 0 deletions host/tests/hdmiCEC_L3_Tests/hdmiCECTestCommands.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
#** *****************************************************************************
# *
# * 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:
test01_TransmitCECCommands:
- command: "0x82" # Active Soruce
Expand Down
Loading

0 comments on commit 3e943a3

Please sign in to comment.