Skip to content

Commit 86da6a0

Browse files
Update project to use latest QP/C v7.3.3.
1 parent 2e37312 commit 86da6a0

File tree

13 files changed

+93
-89
lines changed

13 files changed

+93
-89
lines changed

examples/hwLockCtrlService/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ target_link_libraries(hwLockCtrlService hwLockCtrl)
55
target_include_directories(hwLockCtrlService PUBLIC include)
66

77
# TODO: setting up QP should probably be a higher level build option
8+
add_compile_definitions(QACTIVE_CAN_STOP)
89
include_directories(${QP_CPP_INCLUDE_DIR})
910
include(${EXTERNALS_TOP_DIR}/qpcPosixPortCMakeSupport.txt)

examples/hwLockCtrlService/src/hwLockCtrlService.c

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@
2525

2626
#include "hwLockCtrlService.h"
2727
#include "hwLockCtrl.h"
28-
#include "pub_sub_signals.h"
2928
#include "hwLockCtrlSelfTestEvent.h"
3029
#include "pingPongEvents.h"
3130
#include "bspTicks.h"
32-
#include "qassert.h"
31+
#include "qsafe.h"
3332
#include <stddef.h>
3433

3534
Q_DEFINE_THIS_FILE
@@ -95,11 +94,7 @@ void HwLockCtrlService_ctor()
9594

9695
void HwLockCtrlService_dtor()
9796
{
98-
static const QEvt selfDestructEvent = {
99-
SERVICE_DESTRUCTOR_SIG,
100-
0U,
101-
0U
102-
};
97+
static QEvt const selfDestructEvent = QEVT_INITIALIZER(SERVICE_DESTRUCTOR_SIG);
10398

10499
Q_ASSERT(g_theHwLockCtrlService != NULL);
105100

@@ -291,7 +286,8 @@ void PerformSelfTest(HwLockCtrlService * const me)
291286
//
292287
// https://covemountainsoftware.com/2020/03/08/uml-statechart-handling-errors-when-entering-a-state/
293288
//
294-
static const QEvt event = {REQUEST_GOTO_HISTORY_SIG, 0U, 0U};
289+
static QEvt const event = QEVT_INITIALIZER(REQUEST_GOTO_HISTORY_SIG);
290+
295291
QACTIVE_POST_LIFO(&me->super, &event);
296292
}
297293

@@ -300,17 +296,8 @@ void NotifyChangedState(HwLockCtrlService * const me, HwLockCtrlLockState state)
300296
(void)me; //the QF_PUBLISH macro may not be using that member
301297
//in some build configurations
302298

303-
static const QEvt lockedEvent = {
304-
HW_LOCK_CTRL_SERVICE_IS_LOCKED_SIG,
305-
0U,
306-
0U
307-
};
308-
309-
static const QEvt unlockedEvent = {
310-
HW_LOCK_CTRL_SERVICE_IS_UNLOCKED_SIG,
311-
0U,
312-
0U
313-
};
299+
static QEvt const lockedEvent = QEVT_INITIALIZER(HW_LOCK_CTRL_SERVICE_IS_LOCKED_SIG);
300+
static QEvt const unlockedEvent = QEVT_INITIALIZER(HW_LOCK_CTRL_SERVICE_IS_UNLOCKED_SIG);
314301

315302
switch (state) {
316303
case LOCK_STATE_LOCKED:

examples/hwLockCtrlService/test/hwLockCtrlServiceTests.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <chrono>
2828
#include "qpc.h"
2929
#include "hwLockCtrl.h"
30-
#include "pub_sub_signals.h"
3130
#include "hwLockCtrlService.h"
3231
#include "cms_cpputest_qf_ctrl.hpp"
3332
#include "cmsTestPublishedEventRecorder.hpp"
@@ -414,8 +413,7 @@ TEST(HwLockCtrlServiceTests, the_service_responds_to_a_ping_with_a_pong)
414413
// to an event with a POST directly to an external requesting AO.
415414

416415
PongEvent pongEvent;
417-
pongEvent.super.sig = 0;
418-
pongEvent.source = nullptr;
416+
QEvt_ctor(&pongEvent.super, 0);
419417

420418
auto dummy = std::unique_ptr<cms::DefaultDummyActiveObject>(
421419
new cms::DefaultDummyActiveObject());
@@ -432,9 +430,7 @@ TEST(HwLockCtrlServiceTests, the_service_responds_to_a_ping_with_a_pong)
432430
// Send the Ping to our AO under test and give it
433431
// some processing time.
434432
PingEvent pingEvent;
435-
pingEvent.super.sig = HW_LOCK_CTRL_PING_SIG;
436-
pingEvent.super.poolId_ = 0;
437-
pingEvent.super.refCtr_ = 0;
433+
QEvt_ctor(&pingEvent.super, HW_LOCK_CTRL_PING_SIG);
438434
pingEvent.requester = dummy->getQActive();
439435
pingEvent.response_sig = RESPONSE_SIG;
440436

test_support/cpputest-qpc-port/include/qassertMockSupport.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,29 @@
2424
#ifndef QASSERT_MOCK_SUPPORT_HPP
2525
#define QASSERT_MOCK_SUPPORT_HPP
2626

27-
#include "qassert.h"
27+
#include "qp_port.h"
28+
#include "qsafe.h"
2829
#include "CppUTestExt/MockSupport.h"
2930

3031
namespace cms {
3132
namespace test {
3233

3334
static constexpr const char* QASSERT_MOCK_NAME = "QASSERT";
34-
static constexpr const char* ONASSERT_FUNC_NAME = "Q_onAssert";
35+
static constexpr const char* ONERROR_FUNC_NAME = "Q_onError";
3536

3637
inline void MockExpectQAssert()
3738
{
3839
mock(QASSERT_MOCK_NAME)
39-
.expectOneCall(ONASSERT_FUNC_NAME)
40+
.expectOneCall(ONERROR_FUNC_NAME)
4041
.ignoreOtherParameters();
4142
}
4243

43-
inline void MockExpectQAssert(const char* file, int loc)
44+
inline void MockExpectQAssert(const char* module, int id)
4445
{
4546
mock(QASSERT_MOCK_NAME)
46-
.expectOneCall(ONASSERT_FUNC_NAME)
47-
.withParameter("file", file)
48-
.withParameter("loc", loc);
47+
.expectOneCall(ONERROR_FUNC_NAME)
48+
.withParameter("module", module)
49+
.withParameter("id", id);
4950
}
5051

5152
} // namespace test

test_support/cpputest-qpc-port/include/qep_port.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
#include <stdint.h> /* Exact-width types. WG14/N843 C99 Standard */
1010
#include <stdbool.h> /* Boolean type. WG14/N843 C99 Standard */
1111

12-
#include "qep.h" /* QEP platform-independent public interface */
12+
#include "qp.h" /* QEP platform-independent public interface */
1313

1414
#endif // CPPUTEST_FOR_QPC_QEP_PORT_H

test_support/cpputest-qpc-port/include/qf_port.h renamed to test_support/cpputest-qpc-port/include/qp_port.h

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,36 @@
2525
#ifndef CPPUTEST_FOR_QPC_QF_PORT_H
2626
#define CPPUTEST_FOR_QPC_QF_PORT_H
2727

28+
#include <stdint.h> // Exact-width types. WG14/N843 C99 Standard
29+
#include <stdbool.h> // Boolean type. WG14/N843 C99 Standard
30+
2831
#ifdef __cplusplus
2932
extern "C" {
3033
#endif
3134

35+
#define Q_NORETURN void
36+
37+
#define QACTIVE_EQUEUE_TYPE QEQueue
38+
#define QACTIVE_THREAD_TYPE bool
39+
3240
#define QF_EQUEUE_TYPE QEQueue
3341
#define QF_MAX_ACTIVE 64U
3442
#define QF_MAX_TICK_RATE 2U
35-
#define QF_ACTIVE_STOP 1
43+
#define QACTIVE_CAN_STOP 1
3644
#define QF_EVENT_SIZ_SIZE 4U
3745
#define QF_EQUEUE_CTR_SIZE 4U
3846
#define QF_MPOOL_SIZ_SIZE 4U
3947
#define QF_MPOOL_CTR_SIZE 4U
4048
#define QF_TIMEEVT_CTR_SIZE 4U
4149

50+
//cpputest port, no critical sections are necessary
51+
#define QF_CRIT_STAT
4252
#define QF_CRIT_ENTRY(dummy)
4353
#define QF_CRIT_EXIT(dummy)
4454

45-
#include "qep_port.h"
4655
#include "qequeue.h"
4756
#include "qmpool.h"
48-
#include "qf.h"
57+
#include "qp.h"
4958

5059
void QF_runUntilNoReadyActiveObjects(void);
5160

@@ -62,15 +71,15 @@ void QF_runUntilNoReadyActiveObjects(void);
6271
QPSet_insert(&cpputest_readySet_, (me_)->prio); \
6372
} while (false)
6473

65-
#define QF_EPOOL_TYPE_ QMPool
74+
// native QF event pool operations
75+
#define QF_EPOOL_TYPE_ QMPool
6676
#define QF_EPOOL_INIT_(p_, poolSto_, poolSize_, evtSize_) \
6777
(QMPool_init(&(p_), (poolSto_), (poolSize_), (evtSize_)))
68-
#define QF_EPOOL_EVENT_SIZE_(p_) ((uint_fast16_t)(p_).blockSize)
69-
#define QF_EPOOL_GET_(p_, e_, m_, qs_id_) \
70-
((e_) = (QEvt*)QMPool_get(&(p_), (m_), (qs_id_)))
71-
#define QF_EPOOL_PUT_(p_, e_, qs_id_) (QMPool_put(&(p_), (e_), (qs_id_)))
72-
73-
#include "qf_pkg.h" /* internal QF interface */
78+
#define QF_EPOOL_EVENT_SIZE_(p_) ((uint_fast16_t)(p_).blockSize)
79+
#define QF_EPOOL_GET_(p_, e_, m_, qsId_) \
80+
((e_) = (QEvt *)QMPool_get(&(p_), (m_), (qsId_)))
81+
#define QF_EPOOL_PUT_(p_, e_, qsId_) \
82+
(QMPool_put(&(p_), (e_), (qsId_)))
7483

7584
extern QPSet cpputest_readySet_; /* QV-ready set of active objects */
7685

test_support/cpputest-qpc-port/src/cms_cpputest_q_onAssert.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@
2727
/// @endcond
2828

2929
#include "CppUTest/TestHarness.h"
30-
#include "qassert.h"
30+
#include "qp_port.h" //required for Q_NORETURN definition, needed by qsafe.h
31+
#include "qsafe.h"
3132
#include "qassertMockSupport.hpp"
3233

33-
Q_NORETURN Q_onAssert(char const* const file, int_t const loc)
34+
void Q_onError(char const* const module, int_t const id)
3435
{
35-
// fprintf(stderr, "%s(%s , %d)\n", __FUNCTION__ , file, loc);
36+
//fprintf(stderr, "%s(%s , %d)\n", __FUNCTION__ , module, id);
3637

3738
// The TEST_EXIT macro used below is throwing an exception.
3839
// However, many of QP/QF methods are marked as 'noexcept'
@@ -46,9 +47,9 @@ Q_NORETURN Q_onAssert(char const* const file, int_t const loc)
4647
// the function std::terminate ... is called ..."
4748
//
4849
mock(cms::test::QASSERT_MOCK_NAME)
49-
.actualCall(cms::test::ONASSERT_FUNC_NAME)
50-
.withParameter("file", file)
51-
.withParameter("loc", loc);
50+
.actualCall(cms::test::ONERROR_FUNC_NAME)
51+
.withParameter("module", module)
52+
.withParameter("id", id);
5253

5354
TEST_EXIT
5455
}

test_support/cpputest-qpc-port/src/cms_cpputest_qf_ctrl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "cmsTestPublishedEventRecorder.hpp"
2828
#include <algorithm>
2929
#include <cassert>
30-
#include <cstdint>
3130
#include <vector>
3231
#include "CppUTest/TestHarness.h"
3332

@@ -68,7 +67,9 @@ void Setup(enum_t const maxPubSubSignalValue, uint32_t ticksPerSecond,
6867
l_ticksPerSecond = ticksPerSecond;
6968
l_subscriberStorage = new SubscriberList();
7069
l_subscriberStorage->resize(maxPubSubSignalValue);
71-
QSubscrList nullValue = {0};
70+
QSubscrList nullValue;
71+
QPSet_setEmpty(&nullValue.set);
72+
QPSet_setEmpty(&nullValue.set_dis);
7273
std::fill(l_subscriberStorage->begin(), l_subscriberStorage->end(),
7374
nullValue);
7475

@@ -132,7 +133,7 @@ void MoveTimeForward(const std::chrono::milliseconds& duration)
132133
ONCE, static_cast<LoopCounter_t>(duration.count() / millisecondsPerTick));
133134

134135
for (LoopCounter_t i = 0; i < ticks; ++i) {
135-
QF_tickX_(0U);
136+
QTIMEEVT_TICK_X(0U, nullptr);
136137
ProcessEvents();
137138
}
138139
}

test_support/cpputest-qpc-port/src/cms_cpputest_qf_onCleanup.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
#define QP_IMPL //allow access to some QF/QP internals for test purposes
2525
#include "qpc.h"
2626
#include "CppUTest/TestHarness.h"
27+
#include "qp_pkg.h"
2728

2829
extern "C" void QF_onCleanup(void)
2930
{
30-
for (int i = 0; i < QF_maxPool_; ++i) {
31-
CHECK_TRUE_TEXT(QF_pool_[i].nTot == QF_pool_[i].nFree,
31+
for (int i = 0; i < QF_priv_.maxPool_; ++i) {
32+
CHECK_TRUE_TEXT(QF_priv_.ePool_[i].nTot == QF_priv_.ePool_[i].nFree,
3233
"A leak was detected in an internal QF event pool!");
3334
}
3435
}

test_support/cpputest-qpc-port/src/cpputest_qf_port.cpp

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,73 +24,79 @@
2424
/// @endcond
2525

2626
#define QP_IMPL //allow access to some QF/QP internals for test purposes
27-
#include "qf_port.h" /* QF port */
28-
#include "qf_pkg.h"
29-
#include "qassert.h"
27+
#include "qp_port.h"
28+
#include "qsafe.h"
29+
#include "qp_pkg.h"
3030
#include <cstring>
31-
#include <cstdint>
3231

3332
Q_DEFINE_THIS_MODULE("cpputest_qf_port")
3433

3534
QPSet cpputest_readySet_;
3635

3736
extern "C" void QF_init(void)
3837
{
39-
QF_maxPool_ = static_cast<uint_fast8_t>(0);
40-
bzero(&QF_timeEvtHead_[0],
41-
static_cast<uint_fast16_t>(sizeof(QF_timeEvtHead_)));
42-
bzero(&QF_active_[0], static_cast<uint_fast16_t>(sizeof(QF_active_)));
38+
QF_priv_.maxPool_ = static_cast<uint_fast8_t>(0);
39+
for (uint_fast8_t tickRate = 0U;
40+
tickRate < Q_DIM(QTimeEvt_timeEvtHead_);
41+
++tickRate)
42+
{
43+
QTimeEvt_ctorX(&QTimeEvt_timeEvtHead_[tickRate],
44+
(QActive *)0, Q_USER_SIG, tickRate);
45+
}
46+
47+
bzero(&QActive_registry_[0], static_cast<uint_fast16_t>(sizeof(QActive_registry_)));
4348
}
4449

4550
extern "C" void QF_stop(void)
4651
{
4752
QF_onCleanup();
4853
}
4954

50-
extern "C" void QActive_start_(QActive * const me, uint_fast8_t prio,
51-
QEvt const * * const qSto, uint_fast16_t const qLen,
52-
void * const stkSto, uint_fast16_t const stkSize,
53-
void const * const par)
55+
extern "C" void QActive_start_(QActive * const me,
56+
QPrioSpec const prioSpec,
57+
QEvt const * * const qSto,
58+
uint_fast16_t const qLen,
59+
void * const stkSto,
60+
uint_fast16_t const stkSize,
61+
void const * const par)
5462
{
55-
(void)stkSize; /* unused parameter in this port */
63+
Q_UNUSED_PAR(stkSto);
64+
Q_UNUSED_PAR(stkSize);
5665

57-
Q_REQUIRE_ID(600, (0U < prio) /* priority...*/
58-
&& (prio <= QF_MAX_ACTIVE) /*... in range */
59-
&& (stkSto == (void *)0)); /* stack storage must NOT...
60-
* ... be provided */
6166
QEQueue_init(&me->eQueue, qSto, qLen);
62-
me->prio = (uint8_t)prio;
63-
QF_add_(me); /* make QF aware of this active object */
67+
me->prio = (uint8_t)(prioSpec & 0xFFU); // QF-priority of the AO
68+
69+
QActive_register_(me); // register this AO
6470

65-
/* the top-most initial tran. (virtual) */
66-
QHSM_INIT(&me->super, par, me->prio);
71+
// top-most initial tran. (virtual call)
72+
(*me->super.vptr->init)(&me->super, par, me->prio);
6773
}
6874

69-
#ifdef QF_ACTIVE_STOP
75+
#ifdef QACTIVE_CAN_STOP
7076
extern "C" void QActive_stop(QActive * const me) {
7177

7278
QActive_unsubscribeAll(me); /* unsubscribe from all events */
7379

7480
/* make sure the AO is no longer in "ready set" */
7581
QPSet_remove(&cpputest_readySet_, me->prio);
7682

77-
QF_remove_(me); /* remove this AO from QF */
83+
QActive_unregister_(me); // un-register this active object
7884
}
7985
#endif
8086

8187
extern "C" void QF_runUntilNoReadyActiveObjects()
8288
{
8389
while (QPSet_notEmpty(&cpputest_readySet_)) {
8490
uint_fast8_t p = QPSet_findMax(&cpputest_readySet_);
85-
QActive* a = QF_active_[p];
91+
QActive* a = QActive_registry_[p];
8692

8793
// the active object 'a' must still be registered in QF
8894
// (e.g., it must not be stopped)
8995
Q_ASSERT_ID(320, a != nullptr);
9096

9197
while (a->eQueue.frontEvt != nullptr) {
9298
QEvt const *e = QActive_get_(a);
93-
QHSM_DISPATCH(&a->super, e, a->prio);
99+
(*a->super.vptr->dispatch)(&a->super, e, a->prio);
94100
QF_gc(e);
95101
}
96102

0 commit comments

Comments
 (0)