Skip to content

utCFramework Manual (utSuiteNavigator.py)

Ulrond edited this page Oct 15, 2024 · 1 revision

Overview

The utCFramework class facilitates interaction with and execution of C-based unit test suites built with the ut-core framework (https://github.com/rdkcentral/ut-core). It provides methods for starting the test suite, selecting specific tests or suites, providing input to interactive tests, and collecting test results.

Class Definition

class utCFramework:
    """This module supports the selection of C Type tests
    """

    def __init__(self, session:consoleInterface, log:logModule = None):
        # ... (Initialization logic) ...

    def start(self, command:str ):
        """start the suite
        ...
        """
        # ... (Implementation) ...

    def stop(self):
        """stops the active suite
        ...
        """
        # ... (Implementation) ...

    def select(self, suite_name: str, test_name:str = None, promptWithAnswers: list = None ):
        """select a test from the suite to execute and wait for Prompt
        ...
        """
        # ... (Implementation) ...

    def inputPrompts(self, promptsWithAnswers: dict):
        """
        Sends the specific prompts and sends corresponding input values.
        ...
        """
        # ... (Implementation) ...

    def find_index_in_output(self, output, target_name):
        """
        Finds the index of a target name in the shell output.
        ...
        """
        # ... (Implementation) ...

    def collect_results(self, output):
        """
        Collects and interprets the results from the test execution output.
        ...
        """
        # ... (Implementation) ...

Initialization

To use the utCFramework class, create an instance with the following arguments:

  • session: A consoleInterface object, which provides methods for interacting with the device's console (e.g., sending commands and reading output).
  • log (optional): A logModule object for logging purposes. If not provided, a default logger is created.

Methods

  • start(command): Starts the ut-core based C unit test suite using the provided command.
  • stop(): Stops the currently running test suite.
  • select(suite_name, test_name=None, promptWithAnswers=None): Navigates the test suite menu to select and run a specific test suite or test case.
    • suite_name: The name of the test suite.
    • test_name (optional): The name of the test case within the suite. If None, the entire suite is run.
    • promptWithAnswers (optional): A list of dictionaries, each containing information about an interactive prompt expected during the test execution.
  • inputPrompts(promptsWithAnswers): Handles interactive prompts during test execution by providing predefined answers.
  • find_index_in_output(output, target_name): Helper function to find the index of a specific test suite or test case in the console output.
  • collect_results(output): Analyzes the output from the test execution and determines whether the test passed or failed.

Example Usage

# Assuming 'shell' is a consoleInterface object
framework = utCFramework(session=shell)

# Start the ut-core test suite
framework.start(command="./run_tests.sh")

# Select and run a specific test case
framework.select(suite_name="TestSuite1", test_name="TestCase2")

# Stop the test suite
framework.stop()

This manual provides a basic understanding of the utCFramework class, specifically designed for interacting with the ut-core C unit testing framework. Refer to the code and inline comments for more detailed information and advanced usage scenarios.