Skip to content

utHelperClass Manual

Ulrond edited this page Oct 15, 2024 · 3 revisions

Overview

The utHelperClass module provides a collection of helper functions designed to streamline unit testing, particularly for embedded systems or devices. It extends the testController class and offers functionalities for device interaction, file management, and log manipulation.

Class Definition

class utHelperClass(testController):
    """
    Unit Test Helper Code

    This module provides basic common extensions for unit testing, interacting with devices,
    and managing files.
    """
    def __init__(self, testName:str, qcId:str, log:logModule=None ):
        # ... (Initialization logic) ...

    def waitForBoot(self):
        """
        Waits for the system to boot.
        ...
        """
        # ... (Implementation) ...

    def reboot(self, commandLine=False):
        """
        Reboots the DUT (Device Under Test).
        ...
        """
        # ... (Implementation) ...

    # ... (Other methods) ...

Initialization

To use the utHelperClass, create an instance by providing the following arguments:

  • testName: A string representing the name of the test.
  • qcId: A string representing the quality control identifier.
  • log (optional): A logModule object for logging. If not provided, a default logger is created.

Key Functionalities

  • Device Interaction:
    • waitForBoot(): Pings the device under test ("dut") to check if it's online and logs the boot time.
    • reboot(): Reboots the DUT, either through a command line instruction or using a power control interface.
  • File Management:
    • createDirectoryOnDevice(): Creates a directory on the target device.
    • copyFolder(): Copies a folder on the target device.
    • changeFolderPermission(): Changes file or directory permissions on the target device.
    • copyFileFromHost(): Copies a file from the host machine to the target device via SCP.
    • downloadToDevice(): Downloads a file from a URL and copies it to the target device.
    • deleteFromDevice(): Deletes files from the target device.
  • Command Execution:
    • writeCommands(): Executes a series of commands on the device's console session.
    • writeCommandsOnPrompt(): Executes commands and waits for a specific prompt before proceeding.
  • Utility Functions:
    • isStringInList(): Checks if a string exists within a list of strings.
  • Log Handling:
    • catFile(): Retrieves the content of a file on the device.
    • saveLogForAnalysis(): Saves log data to a file for analysis.

Example Usage

# Create an instance of the utHelperClass
helper = utHelperClass(testName="myTest", qcId="123")

# Wait for the device to boot
helper.waitForBoot()

# Reboot the device
helper.reboot()

# Create a directory on the device
helper.createDirectoryOnDevice("/tmp/mydir")

# ... (Other operations) ...

This manual provides a general overview of the utHelperClass module. Refer to the inline code documentation for detailed information about each function and its arguments.