Skip to content

5 break up into library specific project and example container project #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "externals/qpcpp"]
path = externals/qpcpp
url = https://github.com/QuantumLeaps/qpcpp.git
30 changes: 17 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
cmake_minimum_required(VERSION 3.16)
project(cpputest-for-qpcpp)
project(cpputest-for-qpcpp-lib VERSION 1.0.1)
include(FetchContent)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_C_STANDARD 11)

add_compile_options(-Wall -Wextra -Werror)

include_directories(include)
include_directories(utilities/include)
include(externals/qpcppCMakeSupport.txt)
set(CMS_EXTERNALS_TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/externals)
set(CMS_CMAKE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cpputest-for-qpcpp-lib/cmake CACHE INTERNAL "")

set(TEST_SUPPORT_TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test_support)
set(MOCKS_TOP_DIR ${TEST_SUPPORT_TOP_DIR}/mocks)
set(SERVICES_TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/services)
set(EXTERNALS_TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/externals)
set(DRIVERS_TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/drivers)
if(NOT DEFINED CMS_QPCPP_TOP_DIR)
set(CMS_QPCPP_TOP_DIR ${CMS_EXTERNALS_TOP_DIR}/qpcpp)
FetchContent_Declare(qpcpp
GIT_REPOSITORY https://github.com/QuantumLeaps/qpcpp.git
GIT_TAG 6b7d766521a5c9681f61922a64027690721c2478 #7.2.1
SOURCE_DIR ${CMS_QPCPP_TOP_DIR}
)
message("Fetching QP/C++ git repository")
FetchContent_MakeAvailable(qpcpp)
endif(NOT DEFINED CMS_QPCPP_TOP_DIR)

add_subdirectory(utilities)
add_subdirectory(test_support)
add_subdirectory(drivers)
add_subdirectory(examples)
include(${CMS_CMAKE_DIR}/qpcppCMakeSupport.cmake)
add_subdirectory(cpputest-for-qpcpp-lib)
15 changes: 9 additions & 6 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
The software supporting this CppUTest port of the
QP/C++ Real-Time Embedded Framework is licensed under a
dual-licensing model. Most of the files present in this
repository are only needed for host PC based test execution.
However, a few of the examples and files may find their way
into a product's build. To request a commercial
license see contact information below.
QP/C++ Real-Time Embedded Framework (qpcpp) is licensed under a
dual-licensing model, with the default license being GPL.

Most of the files present in this repository are only needed for
host PC based test execution. However, a few of the examples
and files may find their way into a product's build.

To request a commercial license see contact information
below.

Contact Information:
====================
Expand Down
37 changes: 18 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ Build and Test status: ![Build and Tests](https://github.com/covemountainsoftwar

Copyright Matthew Eshleman

If this project inspires your team to select the qpcpp
If this project inspires your team to select the QP/C++ (qpcpp)
framework for commercial use, please note
"Matthew Eshleman" or "Cove Mountain Software" in the referral
field when acquiring a commercial license from Quantum Leaps. Referrals
encourage and support this effort. Thank you!
encourage and support efforts like this. Thank you!

# Introduction

The `cpputest-for-qpcpp` project enables CppUTest for the
The `cpputest-for-qpcpp` library project enables CppUTest for the
QP/C++ Real-Time Embedded Framework. This project provides for the
following capabilities:

Expand Down Expand Up @@ -46,22 +46,20 @@ Benefits of this approach to unit testing active objects include:

# Environment

This project was developed and proven in Ubuntu 20.04. In theory any
This project was developed and proven in Ubuntu 20.04 and 22.04. In theory any
build or host operating system environment supported by CppUTest will
be compatible with this code.

## Prerequisites

* qpcpp (pulled in as a git submodule)
* After cloning this repository, do not forget to:
* `git submodule init`
* `git submodule update --recursive`
* NOTE: As of January 2023, qpcpp is also using submodules. Developers
may need to perform similar steps within the externals/qpcpp/
directory as well.
* CppUTest (version 3.8-7, the default in Ubuntu 20.04)
* CMake and associated build tools were used to develop
and prove out this project.
* QP/C++
* You can override the QP/C++ to another directory with your project's exact QP/C++ source code.
Define the cmake variable CMS_QPCPP_TOP_DIR before including the internal CMakeLists.txt.
* or:
* Do not define CMS_QPCPP_TOP_DIR, and the internal cmake will fetch the appropriate QP/C++ repo.
* CppUTest (version 3.8-7 or version 4.0) (3.8 is the default in Ubuntu 20.04 while 4.0 is the default in Ubuntu 22.04)
* This project requires support for C++14.

## Continuous Integration
Expand Down Expand Up @@ -131,13 +129,14 @@ behavior, using the exact same interfaces the active object would use
in the production target. CppUTest provides for the mocking capabilities to
ensure that the active object under test is calling the expected APIs.

Within this project, please see the tests for `cms::HwLockCtrl::Service` which
Within the associated examples project, please see the tests for `examples/hwLockCtrlService` which
provides examples of:
* Testing for reaction to a published event, where the reaction is observed
through a CppUTest `mock()`.
* Testing to ensure the active object published an expected event. This project
provides for functionality (`cms::test::PublishedEventRecorder`) to record all
events published during a test. The recorded events can be retrieved and verified by the test.
events published during a test. The recorded events can be retrieved and verified
by the test.
* Testing of time related behavior. This project provides for the ability to
`MoveTimeForward` within a test.
* Direct POST of events and testing of direct POST responses. See
Expand Down Expand Up @@ -172,16 +171,16 @@ provides for convenience and helper methods such as:
events published into the framework. Useful when a test expects an
active object under test to publish an event.


## The basic active object test pattern

To create tests for an active object, the following outline is considered:

1. Implement the `setup()` handler for the test. Initialize the QF framework as
desired using `cms::test::qf_ctrl::Setup(...)`.
2. Instantiate the active object under test.
3. `start` the active object under test.
4. Begin writing a test.
2. Instantiate or otherwise initialize the active object under test.
3. `start` the active object under test, perhaps as part of the `setup`
or as a separate step.
4. Prep a single test.
5. Prepare a CppUTest mock() or other resources as needed for the test.
6. Stimulate the unit under test as appropriate. For example, publish an
event into the framework that the active object is expected to be subscribed to
Expand All @@ -196,7 +195,7 @@ examples at: `examples/hwLockCtrlService/test/hwLockCtrlServiceTests.cpp` to
learn more.

Other tips:
* Avoid internal state knowledge as much as is reasonable. This allows for internal
* Avoid internal state knowledge as much as possible. This allows for internal
state machine refactoring without impacting the tests.
* Follow best practices in your test code, especially follow the DRY principle.

Expand Down
20 changes: 20 additions & 0 deletions cpputest-for-qpcpp-lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
include_directories(include)
include_directories(${CMS_QPCPP_SRC_DIR})
include_directories(${CMS_CPPUTEST_QP_PORT_TOP_DIR}/include)

add_definitions(-DCPPUTEST_FOR_QPCPP_LIB_VERSION=\"${cpputest-for-qpcpp-lib_VERSION}\")

add_library(cpputest-for-qpcpp-lib
src/cpputest_qf_port.cpp
src/cms_cpputest_qf_ctrl.cpp
src/cms_cpputest_q_onAssert.cpp
src/cms_cpputest_qf_onCleanup.cpp
src/cpputestMain.cpp
${CMS_QPCPP_QF_SRCS})

add_subdirectory(tests)

target_include_directories(cpputest-for-qpcpp-lib PUBLIC
${CMS_QPCPP_INCLUDE_DIR}
include)

17 changes: 17 additions & 0 deletions cpputest-for-qpcpp-lib/cmake/qpcppCMakeSupport.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
set(CMS_QPCPP_SRC_DIR ${CMS_QPCPP_TOP_DIR}/src)
set(CMS_QPCPP_INCLUDE_DIR ${CMS_QPCPP_TOP_DIR}/include)
set(CMS_QPCPP_QF_SRC_DIR ${CMS_QPCPP_SRC_DIR}/qf)

set(CMS_QPCPP_QF_SRCS
${CMS_QPCPP_QF_SRC_DIR}/qep_hsm.cpp
${CMS_QPCPP_QF_SRC_DIR}/qep_msm.cpp
${CMS_QPCPP_QF_SRC_DIR}/qf_act.cpp
${CMS_QPCPP_QF_SRC_DIR}/qf_actq.cpp
${CMS_QPCPP_QF_SRC_DIR}/qf_defer.cpp
${CMS_QPCPP_QF_SRC_DIR}/qf_dyn.cpp
${CMS_QPCPP_QF_SRC_DIR}/qf_mem.cpp
${CMS_QPCPP_QF_SRC_DIR}/qf_ps.cpp
${CMS_QPCPP_QF_SRC_DIR}/qf_qact.cpp
${CMS_QPCPP_QF_SRC_DIR}/qf_qeq.cpp
${CMS_QPCPP_QF_SRC_DIR}/qf_qmact.cpp
${CMS_QPCPP_QF_SRC_DIR}/qf_time.cpp)
2 changes: 2 additions & 0 deletions cpputest-for-qpcpp-lib/cmake/qpcppPosixPortCMakeSupport.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include_directories(${CMS_QPCPP_TOP_DIR}/include)
include_directories(${CMS_QPCPP_TOP_DIR}/ports/posix)
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ void PublishAndProcess(enum_t sig,
void PublishAndProcess(QP::QEvt const * e,
PublishedEventRecorder* recorder = nullptr);

/// Get the internal library version string.
/// Uses semantic versioning.
const char * GetVersion();

} //namespace qf_ctrl
} //namespace test
} //namespace cms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,19 @@ void Teardown()
// Instead, we modified the QF port stop() method, which
// internally will perform the memory check, as it has
// friend access.
if (l_memPoolOption == MemPoolTeardownOption::CHECK_FOR_LEAKS) {
for (size_t i = 0; i < l_pubSubEventMemPoolConfigs->size(); ++i) {
if (l_pubSubEventMemPoolConfigs != nullptr) {
if (l_memPoolOption == MemPoolTeardownOption::CHECK_FOR_LEAKS) {
for (size_t i = 0; i < l_pubSubEventMemPoolConfigs->size(); ++i) {

const size_t poolNumOfEvents = l_pubSubEventMemPoolConfigs->at(i).config.numberOfEvents;
const size_t poolNumOfEvents =
l_pubSubEventMemPoolConfigs->at(i).config.numberOfEvents;

CHECK_TRUE_TEXT(poolNumOfEvents == QP::QF::ePool_[i].getNFree(),
"A leak was detected in an internal QF event pool!");
CHECK_TRUE_TEXT(
poolNumOfEvents == QP::QF::ePool_[i].getNFree(),
"A leak was detected in an internal QF event pool!");
}
}
}

if (l_pubSubEventMemPoolConfigs != nullptr) {
delete l_pubSubEventMemPoolConfigs;
l_pubSubEventMemPoolConfigs = nullptr;
}
Expand Down Expand Up @@ -202,6 +204,11 @@ void CreatePoolConfigsFromArg(const MemPoolConfigs& pubSubEventMemPoolConfigs)
}
}

const char * GetVersion()
{
return CPPUTEST_FOR_QPCPP_LIB_VERSION;
}

} // namespace qf_ctrl
} // namespace test
} // namespace cms
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@

# prep for cpputest based build
set(TEST_APP_NAME cpputest-qpcpp-portTests)
set(TEST_APP_NAME cpputest-for-qpcpp-lib-tests)
set(TEST_SOURCES
qassertTests.cpp
cms_cpputest_qf_ctrlTests.cpp
cms_cpputest_qf_ctrlPublishTests.cpp
publishedEventRecorderTests.cpp
backedQueueTests.cpp
orthogonalComponentTests.cpp
orthogonalContainerTests.cpp
)

# this include expects TEST_SOURCES and TEST_APP_NAME to be
# defined, and creates the cpputest based test executable target
include(${TEST_SUPPORT_TOP_DIR}/common/cpputestCMake.txt)
include(${CMS_CMAKE_DIR}/cpputestCMake.cmake)

target_link_libraries(${TEST_APP_NAME} cpputestqpcpplib ${CPPUTEST_LDFLAGS})
target_link_libraries(${TEST_APP_NAME} cpputest-for-qpcpp-lib ${CPPUTEST_LDFLAGS})
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,13 @@ TEST(qf_ctrlTests,

CHECK_EQUAL(1, sigOneCount);
CHECK_EQUAL(3, sigTwoCount);
}

TEST(qf_ctrlTests, qf_ctrl_provides_cpputest_for_qpcpp_lib_version)
{
auto version = qf_ctrl::GetVersion();
CHECK_TRUE(version != nullptr);

std::string version_str(version);
CHECK_FALSE(version_str.empty());
}
1 change: 0 additions & 1 deletion drivers/CMakeLists.txt

This file was deleted.

3 changes: 0 additions & 3 deletions drivers/hwLockCtrl/CMakeLists.txt

This file was deleted.

92 changes: 0 additions & 92 deletions drivers/hwLockCtrl/include/hwLockCtrl.h

This file was deleted.

Loading
Loading