跳过正文

Google Test on VxWorks 7: DKM and RTP Integration Guide

·681 字·4 分钟
VxWorks Google Test Unit Testing DKM RTP Embedded Systems VxWorks 7
目录

Google Test on VxWorks 7: DKM and RTP Integration Guide

Unit testing in embedded systems is often overlooked due to tooling complexity and runtime constraints. However, integrating Google Test (gtest) into VxWorks 7 enables a modern, structured testing workflow across both kernel-space (DKM) and user-space (RTP) components.

This guide provides a practical, production-oriented approach to building and integrating Google Test into VxWorks projects.

🚀 Overview
#

Google Test support for VxWorks is delivered as a static library layer, which can be linked into:

  • DKM (Dynamic Kernel Modules)
  • RTP (Real-Time Processes)

The integration leverages VxWorks’ layer mechanism and standard build system, allowing test execution directly within the target environment.

Key Benefits
#

  • Consistent unit testing across kernel and user space
  • Familiar C++ testing framework (fixtures, assertions, test runners)
  • Improved code quality and regression detection

⚙️ Prerequisites
#

Before integration, ensure the following environment is ready:

  • VxWorks 7 (SR0610 or later)
  • Git installed and accessible
  • Network access to retrieve source packages

Required Package
#

Download the VxWorks-compatible Google Test layer:

  • Repository: vxworks7-google-test (Wind River GitHub)

🧩 Environment Setup
#

Configure Layer Path
#

Set the WIND_LAYER_PATHS environment variable to include the downloaded package:

export WIND_LAYER_PATHS=/path/to/vxworks7-google-test

Verify Layer Availability
#

Confirm that the Google Test layer is recognized:

vxprj vsb listAll

Expected entry:

GTEST_1_8_0_0

🏗️ Building VSB and VIP
#

Google Test must be enabled at the VSB (source build) level and included in the runtime image (VIP).

Create and Configure VSB
#

export WIND_WRTOOL_WORKSPACE=$HOME/WindRiver/workspace
cd $WIND_WRTOOL_WORKSPACE

wrtool prj vsb create -force -bsp vxsim_linux myVSB -S
cd myVSB

wrtool prj vsb config -w -add _WRS_CONFIG_GTEST=y
make -j$(nproc)
cd ..

Create VIP with Google Test
#

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 ..

This ensures the gtest runtime is available in the target image.

🧪 Using Google Test in RTP Projects
#

RTPs provide user-space isolation, making them ideal for most unit testing scenarios.

Steps
#

  1. Create a .cc test file
  2. Write standard Google Test cases
  3. Link against the gtest static library

Linker Configuration
#

-l ${VSB_DIR}/usr/*/common/libgtest.a

Build
#

Compile the RTP project normally. The test entry point is automatically generated by gtest.

🔧 Using Google Test in DKM Projects
#

DKMs run in kernel space, requiring explicit test initialization and cleanup.

Minimal Test Entry
#

int main() {
    int argc = 1;
    char *argv = (char *)"dkm path";
    ::testing::InitGoogleTest(&argc, &argv);
    return RUN_ALL_TESTS_AND_UNLOAD_SELF();
}

Linker Configuration
#

-L $(VSB_DIR)/krnl/SIMLINUX/common
-l gtest

Key Constraints
#

  • Only one gtest instance can exist in kernel space
  • Each DKM must be unloaded before running another test

⚠️ DKM-Specific Considerations
#

Namespace Limitations
#

  • Kernel space does not isolate symbols between modules
  • Avoid multiple simultaneous test modules

Unloading Strategy
#

Use helper macros:

  • GTEST_UNLOAD_SELF
  • RUN_ALL_TESTS_AND_UNLOAD_SELF

Optional Result Handling
#

int main() {
    int argc = 1;
    char *argv = (char *)"dkm path";
    ::testing::InitGoogleTest(&argc, &argv);

    int ret = RUN_ALL_TESTS();
    if (ret > 0) {
        // Handle failures if needed
    }

    return GTEST_UNLOAD_SELF();
}

🔍 Best Practices
#

Test Placement
#

  • Use RTP for most unit tests (safer, isolated)
  • Reserve DKM tests for kernel-specific logic

Build Strategy
#

  • Integrate gtest at VSB level for consistency
  • Maintain separate test targets from production builds

Debugging
#

  • Use VxWorks shell and logging for runtime inspection
  • Combine with system tools for deeper analysis

Maintainability
#

  • Organize tests by module or feature
  • Use fixtures for reusable setup/teardown logic

⚖️ Licensing Notes
#

Google Test is distributed under the BSD 3-Clause License, allowing flexible usage and redistribution. Some files may include additional license notices, which should be reviewed individually.

This VxWorks integration layer adapts Google Test for compatibility but is typically provided without official support, and should be validated within your development workflow.

📌 Conclusion
#

Integrating Google Test into VxWorks 7 brings modern unit testing practices into embedded development. By supporting both RTP and DKM environments, developers gain flexibility in validating code across system boundaries.

With proper integration at the VSB level and disciplined test design, gtest can significantly improve code reliability, accelerate debugging, and enable scalable testing pipelines in VxWorks-based systems.

相关文章

VxWorks Build Guide: VSB, VIP, RTP, and DKM Configuration
·750 字·4 分钟
VxWorks RTOS VSB VIP RTP DKM Workbench Embedded Systems Build Systems
VxWorks 5.5 to VxWorks 7 Migration Guide: Architecture, Networking, and Real-Time Modernization
·675 字·4 分钟
VxWorks RTOS Migration VxWorks 7 Embedded Systems
The Ultimate VxWorks Programming Guide
·647 字·4 分钟
VxWorks RTOS Embedded Systems RTP Device Drivers