Skip to content

Commit 46a57fe

Browse files
Merge pull request #8 from covemountainsoftware/5-break-up-into-library-specific-project-and-example-container-project
5 break up into library specific project and example container project
2 parents 80bafd9 + 173fc43 commit 46a57fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+117
-1234
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "externals/qpcpp"]
2-
path = externals/qpcpp
3-
url = https://github.com/QuantumLeaps/qpcpp.git

CMakeLists.txt

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
cmake_minimum_required(VERSION 3.16)
2-
project(cpputest-for-qpcpp)
2+
project(cpputest-for-qpcpp-lib VERSION 1.0.1)
3+
include(FetchContent)
34

45
set(CMAKE_CXX_STANDARD 14)
6+
set(CMAKE_C_STANDARD 11)
57

68
add_compile_options(-Wall -Wextra -Werror)
79

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

12-
set(TEST_SUPPORT_TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test_support)
13-
set(MOCKS_TOP_DIR ${TEST_SUPPORT_TOP_DIR}/mocks)
14-
set(SERVICES_TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/services)
15-
set(EXTERNALS_TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/externals)
16-
set(DRIVERS_TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/drivers)
13+
if(NOT DEFINED CMS_QPCPP_TOP_DIR)
14+
set(CMS_QPCPP_TOP_DIR ${CMS_EXTERNALS_TOP_DIR}/qpcpp)
15+
FetchContent_Declare(qpcpp
16+
GIT_REPOSITORY https://github.com/QuantumLeaps/qpcpp.git
17+
GIT_TAG 6b7d766521a5c9681f61922a64027690721c2478 #7.2.1
18+
SOURCE_DIR ${CMS_QPCPP_TOP_DIR}
19+
)
20+
message("Fetching QP/C++ git repository")
21+
FetchContent_MakeAvailable(qpcpp)
22+
endif(NOT DEFINED CMS_QPCPP_TOP_DIR)
1723

18-
add_subdirectory(utilities)
19-
add_subdirectory(test_support)
20-
add_subdirectory(drivers)
21-
add_subdirectory(examples)
24+
include(${CMS_CMAKE_DIR}/qpcppCMakeSupport.cmake)
25+
add_subdirectory(cpputest-for-qpcpp-lib)

LICENSE.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
The software supporting this CppUTest port of the
2-
QP/C++ Real-Time Embedded Framework is licensed under a
3-
dual-licensing model. Most of the files present in this
4-
repository are only needed for host PC based test execution.
5-
However, a few of the examples and files may find their way
6-
into a product's build. To request a commercial
7-
license see contact information below.
2+
QP/C++ Real-Time Embedded Framework (qpcpp) is licensed under a
3+
dual-licensing model, with the default license being GPL.
4+
5+
Most of the files present in this repository are only needed for
6+
host PC based test execution. However, a few of the examples
7+
and files may find their way into a product's build.
8+
9+
To request a commercial license see contact information
10+
below.
811

912
Contact Information:
1013
====================

README.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ Build and Test status: ![Build and Tests](https://github.com/covemountainsoftwar
44

55
Copyright Matthew Eshleman
66

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

1313
# Introduction
1414

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

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

4747
# Environment
4848

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

5353
## Prerequisites
5454

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

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

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

175-
176174
## The basic active object test pattern
177175

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

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

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

cpputest-for-qpcpp-lib/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
include_directories(include)
2+
include_directories(${CMS_QPCPP_SRC_DIR})
3+
include_directories(${CMS_CPPUTEST_QP_PORT_TOP_DIR}/include)
4+
5+
add_definitions(-DCPPUTEST_FOR_QPCPP_LIB_VERSION=\"${cpputest-for-qpcpp-lib_VERSION}\")
6+
7+
add_library(cpputest-for-qpcpp-lib
8+
src/cpputest_qf_port.cpp
9+
src/cms_cpputest_qf_ctrl.cpp
10+
src/cms_cpputest_q_onAssert.cpp
11+
src/cms_cpputest_qf_onCleanup.cpp
12+
src/cpputestMain.cpp
13+
${CMS_QPCPP_QF_SRCS})
14+
15+
add_subdirectory(tests)
16+
17+
target_include_directories(cpputest-for-qpcpp-lib PUBLIC
18+
${CMS_QPCPP_INCLUDE_DIR}
19+
include)
20+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
set(CMS_QPCPP_SRC_DIR ${CMS_QPCPP_TOP_DIR}/src)
2+
set(CMS_QPCPP_INCLUDE_DIR ${CMS_QPCPP_TOP_DIR}/include)
3+
set(CMS_QPCPP_QF_SRC_DIR ${CMS_QPCPP_SRC_DIR}/qf)
4+
5+
set(CMS_QPCPP_QF_SRCS
6+
${CMS_QPCPP_QF_SRC_DIR}/qep_hsm.cpp
7+
${CMS_QPCPP_QF_SRC_DIR}/qep_msm.cpp
8+
${CMS_QPCPP_QF_SRC_DIR}/qf_act.cpp
9+
${CMS_QPCPP_QF_SRC_DIR}/qf_actq.cpp
10+
${CMS_QPCPP_QF_SRC_DIR}/qf_defer.cpp
11+
${CMS_QPCPP_QF_SRC_DIR}/qf_dyn.cpp
12+
${CMS_QPCPP_QF_SRC_DIR}/qf_mem.cpp
13+
${CMS_QPCPP_QF_SRC_DIR}/qf_ps.cpp
14+
${CMS_QPCPP_QF_SRC_DIR}/qf_qact.cpp
15+
${CMS_QPCPP_QF_SRC_DIR}/qf_qeq.cpp
16+
${CMS_QPCPP_QF_SRC_DIR}/qf_qmact.cpp
17+
${CMS_QPCPP_QF_SRC_DIR}/qf_time.cpp)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include_directories(${CMS_QPCPP_TOP_DIR}/include)
2+
include_directories(${CMS_QPCPP_TOP_DIR}/ports/posix)

0 commit comments

Comments
 (0)