Overview #
Google Test integration with VxWorks® 7 provides developers with a robust testing framework that helps improve code quality and streamline testing workflows. This guide explains how to build and configure Google Test to a static library, which can then be linked with Dynamic Kernel Modules (DKMs) and Real-Time Processes (RTPs) for testing purposes.
The source files for Google Test are derived from Google’s official repository, and VxWorks-specific configuration files are provided for seamless integration. The static library compiled from these files can be easily included in your VxWorks projects, ensuring you can run unit tests within your system.
Project License #
The source code for this project is licensed under the BSD 3-Clause License, which permits redistribution and use in source and binary forms, with or without modification. However, it prohibits the use of the project’s name or its contributors to promote derived products without written consent.
You can find the full text of all applicable license notices, including those for Google Test dependencies, in the License_Notices.txt
file located in the project’s top-level directory. Note that different files may be under different licenses, with each source file containing its respective license notice.
Prerequisites #
Before you begin, ensure you have the following:
- Wind River® VxWorks® 7 Operating System (version SR0610 or later).
- Git installed and properly configured for command-line use.
- A working Internet connection to download necessary files from GitHub.
Setup Instructions #
-
Download Google Test for VxWorks: Download the Google Test support package for VxWorks from the following GitHub repository: vxworks7-google-test.
-
Set the WIND_LAYER_PATHS Environment Variable: Set the
WIND_LAYER_PATHS
variable to point to the directory where you downloaded the Google Test package. You can set this environment variable directly from the command line (usingexport
on Linux orset
on Windows) or via your system’s environment settings on Windows. -
Verify Layer Availability: Confirm that the Google Test layer is present in your VxWorks 7 installation by running the following command in a VxWorks development shell:
vxprj vsb listAll
Look for
GTEST_1_8_0_0
to verify the presence of the layer.
Building the VSB and VIP with WrTool #
Creating the VSB (VxWorks Source Build) #
To build the VSB, follow these steps:
-
Set the environment variable and navigate to your workspace directory:
export WIND_WRTOOL_WORKSPACE=$HOME/WindRiver/workspace cd $WIND_WRTOOL_WORKSPACE
-
Create the VSB using WrTool:
wrtool prj vsb create -force -bsp vxsim_linux myVSB -S cd myVSB wrtool prj vsb config -w -add _WRS_CONFIG_GTEST=y make -j[jobs] cd ..
Creating the VIP (VxWorks Image Project) #
Next, create the VIP:
-
Use the following command to create the VIP:
wrtool prj vip create -force -vsb myVSB -profile PROFILE_STANDALONE_DEVELOPMENT vxsim_linux llvm myVIP cd myVIP wrtool prj vip component add INCLUDE_GTEST cd ..
Building RTP Projects with Google Test #
To build an RTP (Real-Time Process) project that integrates Google Test:
-
Create a test file: In your RTP project, create a
.cc
file and add your test code. Google Test will automatically generate the test entry. -
Link the Google Test Library: Add the following to your build properties under Libraries:
-l ${VSB_DIR}/usr/*/common/libgtest.a
-
Build the RTP project: Compile your RTP project as usual, ensuring that the Google Test library is included.
Building DKM Projects with Google Test #
To build a DKM (Dynamic Kernel Module) project with Google Test:
-
Create a test file: Add a
.cc
file to your DKM project and write the test code. Ensure to include the test entry in your.cc
file as shown below:int main() { int argc = 1; char *argv = (char *)"your dkm binary path, empty string also works"; ::testing::InitGoogleTest(&argc, &argv); return RUN_ALL_TESTS_AND_UNLOAD_SELF(); }
-
Link the Google Test Library: Add the following to your build properties:
-L $(VSB_DIR)/krnl/SIMLINUX/common -l gtest
-
Build the DKM project: Compile your DKM project with the Google Test library linked.
Important Considerations #
-
Single Instance of Google Test: The namespace in the kernel isn’t isolated between different DKMs, so only one instance of Google Test can be active at a time. You must unload the current DKM before the next can be tested.
-
Test Unloading Functions: To handle unloading, use the provided helper functions
GTEST_UNLOAD_SELF
andRUN_ALL_TESTS_AND_UNLOAD_SELF
to ensure proper unloading of the DKM after tests. -
Test Result Handling: You can choose whether or not to return the test results. Two example
main()
functions demonstrate how to handle this:a. Return Test Result:
int main() { int argc = 1; char *argv = (char *)"your dkm binary path"; ::testing::InitGoogleTest(&argc, &argv); int ret = RUN_ALL_TESTS(); if (ret > 0) { // Perform additional work if tests fail } return GTEST_UNLOAD_SELF(); }
b. No Test Result:
int main() { int argc = 1; char *argv = (char *)"your dkm binary path"; ::testing::InitGoogleTest(&argc, &argv); return RUN_ALL_TESTS_AND_UNLOAD_SELF(); }
Legal Notices #
Google Test has been modified for interoperability with the VxWorks real-time operating system. Google is a trademark of Google LLC. All product names, logos, and brands are property of their respective owners.
Disclaimer of Warranty #
This software is provided “as-is,” without warranties of any kind. Wind River does not provide support or maintenance services for this software under the standard support agreement. Use and redistribution are at your own risk.