The RdkbGMock repository provides Google Mock-based implementations and utilities to support robust unit testing of RDK-B (RDK Broadband) components. It includes mocks for a wide range of APIs, system libraries, and hardware abstraction layers (HALs), simplifying the creation of test cases and ensuring consistency across RDK-B development.
Use the container from ghcr.io/rdkcentral/docker-rdk-ci and follow these commands:
docker run --name=<x> --volume=$HOME/<y>:/home/$USER --restart=no --runtime=runc -t -d ghcr.io/rdkcentral/docker-rdk-ci:latest
docker start <x>
docker exec <x> groupadd $USER --gid=$(id -g $USER)
docker exec <x> useradd -m $USER -G users --uid=$(id -u $USER) --gid=$(id -g $USER)
docker exec --user $USER -it <x> /bin/bash
Replace the placeholders:
- x: A name you choose for your Docker container (e.g.,
rdk-ci-dev
). - y: A directory on your host machine that will be mounted into the container (e.g.,
rdk_workspace
).
RdkbGMock/
├── docker_scripts/ # Scripts for Docker-based development and testing
├── source/
│ ├── mocks/ # Mock implementations grouped by category
│ │ ├── HAL/ # Hardware Abstraction Layer mocks
│ │ ├── syscfg/ # Mocks for Syscfg APIs
│ │ ├── file_io/ # File I/O-related mocks
│ │ └── ... # Additional mocks (scheduler, telemetry, etc.)
├── autogen.sh # Script to initialize autotools
├── configure.ac # Configuration for autotools
├── Makefile.am # Makefile template for building
├── LICENSE # License information
├── README.md # Repository documentation
- Comprehensive Mocks: Includes mocks for HAL layers, system libraries, and RDK-B-specific utilities.
- Organized Structure: Mocks are categorized for ease of use and modularity.
- Docker Support: Contains scripts to enable building and testing in Docker environments.
- Scalable Testing: Easily add new mocks and integrate with existing RDK-B test cases.
- Standardized Framework: Supports Google Test (GTest) and Google Mock (GMock).
Note: These build instructions are not necessary, as the run_ut.sh
script automatically performs the steps required to retrieve the mock shared libraries for linking to your component.
-
Clone the RdkbGMock repository:
git clone <rdkb_repository_url>
-
Navigate to the RdkbGMock directory:
cd RdkbGMock
-
Run the
autogen.sh
script:./autogen.sh
-
Export the following path variables to configure C and C++ include paths for RDKB headers in the user's home directory:
export C_INCLUDE_PATH=$HOME/usr/include/rdkb export CPLUS_INCLUDE_PATH=$HOME/usr/include/rdkb export C_INCLUDE_PATH=$HOME/usr/include/rdkb/rbus:$C_INCLUDE_PATH export CPLUS_INCLUDE_PATH=$HOME/usr/include/rdkb/rbus:$CPLUS_INCLUDE_PATH
-
Build and install the mocks:
make install
-
Copy the
.la
files from the locallib
directory to$HOME/usr/local/lib
:cp lib/*.la "$HOME/usr/local/lib"
-
Include Necessary Mock Headers: Add the required mock headers in your test files and declare the mock global variables as
extern
.
Example:#include "mocks_hal/mock_platform_hal.h" extern PlatformHalMock *g_platformHALMock;
-
Link the RdkbGMock Mock's Shared Library: Update your
Makefile.am
to link the required shared libraries. Use the_LDADD
variable as shown below:
Example:_LDADD = \ $(HOME)/usr/local/lib/libmock_platform_hal.la
-
Write and Run Test Cases: Use Google Mock to write test cases leveraging the linked mocks. Ensure the mocks are correctly initialized and used in your tests.
-
Validate Your Changes: Export the following variables, and run the
make
command in the component-specificsource/test/<test_directory>
, or use your preferred testing command to validate the integration of mocks.export C_INCLUDE_PATH=$HOME/usr/include/rdkb export CPLUS_INCLUDE_PATH=$HOME/usr/include/rdkb export C_INCLUDE_PATH=$HOME/usr/include/rdkb/rbus:$C_INCLUDE_PATH export CPLUS_INCLUDE_PATH=$HOME/usr/include/rdkb/rbus:$CPLUS_INCLUDE_PATH
- Create a new mock in the appropriate
source/mocks/
directory. - Update
Makefile.am
to include the new mock. - Write test cases to validate the new mock.
This guide explains how to use the dependency_repos.conf
file to configure dependency component repositories for your project.
Note: The branch varies based on the repository being used. Before running the run_ut.sh
script, export the BRANCH
variable for local Docker. This step is not required for CI Docker Jenkins.
Example:
export BRANCH=rdk-next
Each line in the dependency_repos.conf
file should follow this format:
repository_url branch_name repository_alias src_path dest_path
-
GitHub Repository:
https://github.com/org/repo.git main alias src_path dest_path
-
Gerrit or CMF Repository:
ssh://host/repo_path branch alias src_path dest_path
- Use
main
as the primary branch.
- Specify the branch as
branch
keyword. This uses the$BRANCH
variable from the Jenkins environment, which maps to the latest sprint branch.
- Choose a descriptive
repository_alias
. This should reflect the repo name as it appears in Gerrit (generic) or GitHub.
- Specify the source path (
src_path
) where the headers are located in the repository. - Specify the destination path (
dest_path
) where the headers should be copied.
When configuring multiple paths for the same repository, the dependency_repos.conf
file allows you to specify multiple entries. The repository cloning process is optimized to avoid redundant operations. Here’s how it works:
- Initial Clone: The first entry of a repository in the
dependency_repos.conf
file triggers the git clone operation. - Subsequent Entries: If the repository is listed again with different
src_path
anddest_path
values, the system does not clone it again. Instead, it reuses the initially cloned repository to copy files from the new source to the designated destination path.
Consider you have multiple configurations for the same repository in your dependency_repos.conf
file:
https://github.com/rdkcentral/rdkb-halif-platform.git main platform_hal include $HOME/usr/include/rdkb
https://github.com/rdkcentral/rdkb-halif-platform.git main platform_hal src/new_include $HOME/usr/include/rdkb/new_include
In this case:
- The repository
rdkcentral/rdkb-halif-platform
is cloned once and performs copying operation frominclude
to$HOME/usr/include/rdkb
. - For the second entry, the system uses the existing clone and only performs the copying operation from
src/new_include
to$HOME/usr/include/rdkb/new_include
.
When adding new repositories, ensure that branch_name
, src_path
, and dest_path
match your development requirements. Follow the format and guidelines provided above.
Example:
https://github.com/rdkcentral/rbus.git main rbus include $HOME/usr/include/rdkb/rbus
Example:
<x>://<y>/<z> branch <brach_name> . $HOME/usr/include/rdkb
- x: Either
ssh
orhttps
or if any. - y: Either
code.rdkcentral.com
orgithub.com/rdkcentral
or if any. - z: Any rdkcentral repositories.
- branch_name: Any rdkcentral repositories branch name.
By following these guidelines and using the provided format, you can ensure proper configuration of repositories for your project.
- Fork the Repository: Work on a feature or bug fix in a separate branch.
- Test Your Changes: Ensure that all tests pass before submission.
- Pull Request: Submit a PR with a description of the changes.
For issues, contact the rdkb-gmock maintainers.
This project is licensed under the Apache-2.0. See the LICENSE
file for details.
Thanks to all contributors and the RDK-B community for their support and efforts in maintaining this repository.