Skip to content

Commit

Permalink
Merge pull request RIOT-OS#16133 from miri64/congure_mock/enh/real-me…
Browse files Browse the repository at this point in the history
…thods

congure_mock: add capability to provide actual methods
  • Loading branch information
fjmolinas authored May 4, 2021
2 parents 38062c4 + 384df31 commit 3cb3b5a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
28 changes: 27 additions & 1 deletion sys/congure/mock/congure_mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ static const congure_snd_driver_t _driver = {
.report_ecn_ce = _snd_report_ecn_ce,
};

void congure_mock_snd_setup(congure_mock_snd_t *c)
void congure_mock_snd_setup(congure_mock_snd_t *c,
const congure_snd_driver_t *methods)
{
c->super.driver = &_driver;
c->methods = methods;
}

static void _snd_init(congure_snd_t *cong, void *ctx)
Expand All @@ -49,6 +51,9 @@ static void _snd_init(congure_snd_t *cong, void *ctx)
c->init_calls++;
c->init_args.c = &c->super;
c->init_args.ctx = ctx;
if (c->methods && c->methods->init) {
c->methods->init(cong, ctx);
}
}

static int32_t _snd_inter_msg_interval(congure_snd_t *cong, unsigned msg_size)
Expand All @@ -58,6 +63,9 @@ static int32_t _snd_inter_msg_interval(congure_snd_t *cong, unsigned msg_size)
c->inter_msg_interval_calls++;
c->inter_msg_interval_args.c = &c->super;
c->inter_msg_interval_args.msg_size = msg_size;
if (c->methods && c->methods->inter_msg_interval) {
return c->methods->inter_msg_interval(cong, msg_size);
}
return -1;
}

Expand All @@ -68,6 +76,9 @@ static void _snd_report_msg_sent(congure_snd_t *cong, unsigned msg_size)
c->report_msg_sent_calls++;
c->report_msg_sent_args.c = &c->super;
c->report_msg_sent_args.msg_size = msg_size;
if (c->methods && c->methods->report_msg_sent) {
c->methods->report_msg_sent(cong, msg_size);
}
}

static void _snd_report_msg_discarded(congure_snd_t *cong, unsigned msg_size)
Expand All @@ -77,6 +88,9 @@ static void _snd_report_msg_discarded(congure_snd_t *cong, unsigned msg_size)
c->report_msg_discarded_calls++;
c->report_msg_discarded_args.c = &c->super;
c->report_msg_discarded_args.msg_size = msg_size;
if (c->methods && c->methods->report_msg_discarded) {
c->methods->report_msg_discarded(cong, msg_size);
}
}

static void _snd_report_msgs_lost(congure_snd_t *cong, congure_snd_msg_t *msgs)
Expand All @@ -86,6 +100,9 @@ static void _snd_report_msgs_lost(congure_snd_t *cong, congure_snd_msg_t *msgs)
c->report_msgs_lost_calls++;
c->report_msgs_lost_args.c = &c->super;
c->report_msgs_lost_args.msgs = msgs;
if (c->methods && c->methods->report_msgs_lost) {
c->methods->report_msgs_lost(cong, msgs);
}
}

static void _snd_report_msgs_timeout(congure_snd_t *cong,
Expand All @@ -96,6 +113,9 @@ static void _snd_report_msgs_timeout(congure_snd_t *cong,
c->report_msgs_timeout_calls++;
c->report_msgs_timeout_args.c = &c->super;
c->report_msgs_timeout_args.msgs = msgs;
if (c->methods && c->methods->report_msgs_timeout) {
c->methods->report_msgs_timeout(cong, msgs);
}
}

static void _snd_report_msg_acked(congure_snd_t *cong, congure_snd_msg_t *msg,
Expand All @@ -107,6 +127,9 @@ static void _snd_report_msg_acked(congure_snd_t *cong, congure_snd_msg_t *msg,
c->report_msg_acked_args.c = &c->super;
c->report_msg_acked_args.msg = msg;
c->report_msg_acked_args.ack = ack;
if (c->methods && c->methods->report_msg_acked) {
c->methods->report_msg_acked(cong, msg, ack);
}
}

static void _snd_report_ecn_ce(congure_snd_t *cong, ztimer_now_t time)
Expand All @@ -116,6 +139,9 @@ static void _snd_report_ecn_ce(congure_snd_t *cong, ztimer_now_t time)
c->report_ecn_ce_calls++;
c->report_ecn_ce_args.c = &c->super;
c->report_ecn_ce_args.time = time;
if (c->methods && c->methods->report_ecn_ce) {
c->methods->report_ecn_ce(cong, time);
}
}

/** @} */
14 changes: 11 additions & 3 deletions sys/include/congure/mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ extern "C" {
* @extends congure_snd_t
*/
typedef struct {
congure_snd_t super; /**< see @ref congure_snd_t */
congure_snd_t super; /**< see @ref congure_snd_t */
/**
* @brief Optional methods called in addition to the tracking functions
* of the mock driver
*/
const congure_snd_driver_t *methods;
/**
* @brief How often was the congure_snd_driver_t::init() method called?
*/
Expand Down Expand Up @@ -152,9 +157,12 @@ typedef struct {
/**
* @brief Sets up the driver for CongURE mock object
*
* @param[in] c A CongURE mock object
* @param[in] c A CongURE mock object
* @param[in] methods Methods to call in addition to the tracking of the mock
* driver. May be NULL.
*/
void congure_mock_snd_setup(congure_mock_snd_t *c);
void congure_mock_snd_setup(congure_mock_snd_t *c,
const congure_snd_driver_t *methods);

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion tests/congure_test/congure_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ int congure_test_snd_setup(congure_test_snd_t *c, unsigned id)
if (id > 0) {
return -1;
}
congure_mock_snd_setup(c);
congure_mock_snd_setup(c, NULL);
return 0;
}

Expand Down

0 comments on commit 3cb3b5a

Please sign in to comment.