Skip to content

Commit

Permalink
Merge pull request #13466 from gschorcht/fix_compilation_with_ndebug
Browse files Browse the repository at this point in the history
tests: fix compilation problems with NDEBUG
  • Loading branch information
miri64 committed Mar 12, 2020
2 parents 20e30ec + 953a4af commit 5defa1a
Show file tree
Hide file tree
Showing 44 changed files with 1,418 additions and 1,308 deletions.
7 changes: 7 additions & 0 deletions cpu/nrf51/periph/pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ uint32_t pwm_init(pwm_t dev, pwm_mode_t mode, uint32_t freq, uint16_t res)

void pwm_set(pwm_t dev, uint8_t channel, uint16_t value)
{
#ifdef NDEBUG
(void)dev;
(void)channel;
#endif
assert((dev == 0) && (channel == 0));

/*
Expand Down Expand Up @@ -192,6 +196,9 @@ void pwm_set(pwm_t dev, uint8_t channel, uint16_t value)

uint8_t pwm_channels(pwm_t dev)
{
#ifdef NDEBUG
(void)dev;
#endif
assert(dev == 0);
return 1;
}
Expand Down
7 changes: 5 additions & 2 deletions cpu/stm32_common/periph/usbdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ void usbdev_init_lowlevel(void)
for (size_t i = 0; i < USBDEV_NUMOF; i++) {
ep_idx += _setup(&_usbdevs[i], &stm32_usb_otg_fshs_config[i], ep_idx);
}
#ifdef NDEBUG
(void)ep_idx;
#endif
assert(ep_idx == _TOTAL_NUM_ENDPOINTS);
}

Expand Down Expand Up @@ -416,7 +419,7 @@ static usbdev_ep_t *_get_ep(stm32_usb_otg_fshs_t *usbdev, unsigned num,
return dir == USB_EP_DIR_IN ? &usbdev->in[num] : &usbdev->out[num];
}

#ifdef DEVELHELP
#if defined(DEVELHELP) && !defined(NDEBUG)
static size_t _total_fifo_size(const stm32_usb_otg_fshs_config_t *conf)
{
if (conf->type == STM32_USB_OTG_FS) {
Expand All @@ -435,7 +438,7 @@ static size_t _total_fifo_size(const stm32_usb_otg_fshs_config_t *conf)
}

}
#endif /* DEVELHELP */
#endif /* defined(DEVELHELP) && !defined(NDEBUG) */

static void _configure_tx_fifo(stm32_usb_otg_fshs_t *usbdev, size_t num,
size_t len)
Expand Down
3 changes: 3 additions & 0 deletions drivers/mtd_mapper/mtd_mapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ static int _init(mtd_dev_t *mtd)
backing_mtd->pages_per_sector * backing_mtd->sector_count *
backing_mtd->page_size);

/* avoid unused variable warning if compiled with NDEBUG */
(void)backing_mtd;

_lock(region);
int res = _init_target(region);
_unlock(region);
Expand Down
9 changes: 5 additions & 4 deletions examples/ndn-ping/ndn_ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "thread.h"
#include "random.h"
#include "test_utils/expect.h"

#include "ndn-riot/app.h"
#include "ndn-riot/ndn.h"
Expand Down Expand Up @@ -57,16 +58,16 @@ static int on_data(ndn_block_t* interest, ndn_block_t* data)

ndn_block_t name;
int r = ndn_data_get_name(data, &name);
assert(r == 0);
expect(r == 0);
printf("client (pid=%" PRIkernel_pid "): data received, name=",
handle->id);
ndn_name_print(&name);
putchar('\n');

ndn_block_t content;
r = ndn_data_get_content(data, &content);
assert(r == 0);
assert(content.len == 6);
expect(r == 0);
expect(content.len == 6);

printf("client (pid=%" PRIkernel_pid "): content=%02X%02X%02X%02X\n",
handle->id, *(content.buf + 2), *(content.buf + 3),
Expand All @@ -90,7 +91,7 @@ static int on_timeout(ndn_block_t* interest)
{
ndn_block_t name;
int r = ndn_interest_get_name(interest, &name);
assert(r == 0);
expect(r == 0);

printf("client (pid=%" PRIkernel_pid "): interest timeout, name=",
handle->id);
Expand Down
61 changes: 61 additions & 0 deletions pkg/ubasic/patches/0001-replace-assert-by-expect.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
From 6b996a7060a746023011ee60eb4ea2c5b4d76970 Mon Sep 17 00:00:00 2001
From: Gunar Schorcht <gunar@schorcht.net>
Date: Tue, 25 Feb 2020 15:42:53 +0100
Subject: [PATCH 1/1] replace assert by expect

---
tests.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/tests.c b/tests.c
index 96f60b8..a7bab89 100644
--- a/tests.c
+++ b/tests.c
@@ -31,7 +31,7 @@

#include <time.h>
#include <stdio.h>
-#include <assert.h>
+#include "test_utils/expect.h"
#include "ubasic.h"

static const char program_let[] =
@@ -82,7 +82,7 @@ VARIABLE_TYPE peek(VARIABLE_TYPE arg) {

/*---------------------------------------------------------------------------*/
void poke(VARIABLE_TYPE arg, VARIABLE_TYPE value) {
- assert(arg == value);
+ expect(arg == value);
}

/*---------------------------------------------------------------------------*/
@@ -114,20 +114,20 @@ int
main(void)
{
run(program_let);
- assert(ubasic_get_variable(0) == 42);
+ expect(ubasic_get_variable(0) == 42);

run(program_goto);
- assert(ubasic_get_variable(2) == 108);
+ expect(ubasic_get_variable(2) == 108);

run(program_loop);
- assert(ubasic_get_variable(0) == (VARIABLE_TYPE)(126 * 126 * 10));
+ expect(ubasic_get_variable(0) == (VARIABLE_TYPE)(126 * 126 * 10));

run(program_fibs);
- assert(ubasic_get_variable(1) == 89);
+ expect(ubasic_get_variable(1) == 89);

run(program_peek_poke);
- assert(ubasic_get_variable(0) == 123);
- assert(ubasic_get_variable(25) == 123);
+ expect(ubasic_get_variable(0) == 123);
+ expect(ubasic_get_variable(25) == 123);

return 0;
}
--
2.17.1

3 changes: 2 additions & 1 deletion tests/bench_timers/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "board.h"
#include "cpu.h"
#include "periph/timer.h"
#include "test_utils/expect.h"

#include "print_results.h"
#include "spin_random.h"
Expand Down Expand Up @@ -676,7 +677,7 @@ int main(void)
print_str("state vector total memory usage = ");
print_u32_dec(sizeof(ref_states));
print_str(" bytes\n");
assert(log2test < TEST_LOG2NUM);
expect(log2test < TEST_LOG2NUM);
print_str("TIM_TEST_DEV = ");
print_u32_dec(TIM_TEST_DEV);
print_str(", TIM_TEST_FREQ = ");
Expand Down
3 changes: 2 additions & 1 deletion tests/bench_xtimer/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
*/

#include <stdio.h>
#include <test_utils/expect.h>

#include "test_utils/expect.h"

#include "msg.h"
#include "thread.h"
Expand Down
9 changes: 5 additions & 4 deletions tests/cpp11_condition_variable/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@

#include <string>
#include <cstdio>
#include <cassert>
#include <system_error>

#include "riot/mutex.hpp"
#include "riot/chrono.hpp"
#include "riot/thread.hpp"
#include "riot/condition_variable.hpp"

#include "test_utils/expect.h"

using namespace std;
using namespace riot;

Expand Down Expand Up @@ -62,7 +63,7 @@ int main() {
cv.wait(lk, [&processed] { return processed; });
}
string expected = "Example data after processing";
assert(data == expected);
expect(data == expected);
worker.join();
}
puts("Done\n");
Expand Down Expand Up @@ -102,7 +103,7 @@ int main() {
cv.wait_for(lk, chrono::seconds(timeout));
xtimer_now_timex(&after);
auto diff = timex_sub(after, before);
assert(diff.seconds >= timeout);
expect(diff.seconds >= timeout);
}
puts("Done\n");

Expand All @@ -119,7 +120,7 @@ int main() {
cv.wait_until(lk, time);
xtimer_now_timex(&after);
auto diff = timex_sub(after, before);
assert(diff.seconds >= timeout);
expect(diff.seconds >= timeout);
}
puts("Done\n");

Expand Down
15 changes: 11 additions & 4 deletions tests/cpp11_mutex/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
*/
#include <string>
#include <cstdio>
#include <cassert>
#include <system_error>

#include "riot/mutex.hpp"
#include "riot/chrono.hpp"
#include "riot/thread.hpp"
#include "riot/condition_variable.hpp"

#include "test_utils/expect.h"

using namespace std;
using namespace riot;

Expand All @@ -46,16 +47,22 @@ int main() {
m.unlock();
}
};
#ifndef NDEBUG
/* We can't use expect here, otherwise cppcheck will produce errors */
assert(resource == 0);
#endif
auto start = std::chrono::system_clock::now();
thread t1(f);
thread t2(f);
t1.join();
t2.join();
#ifndef NDEBUG
/* We can't use expect here, otherwise cppcheck will produce errors */
assert(resource == 6);
#endif
auto duration = std::chrono::duration_cast
<chrono::milliseconds>(std::chrono::system_clock::now() - start);
assert(duration.count() >= 600);
expect(duration.count() >= 600);
}
puts("Done\n");

Expand All @@ -65,7 +72,7 @@ int main() {
m.lock();
thread([&m] {
auto res = m.try_lock();
assert(res == false);
expect(res == false);
}).detach();
m.unlock();
}
Expand All @@ -74,7 +81,7 @@ int main() {
mutex m;
thread([&m] {
auto res = m.try_lock();
assert(res == true);
expect(res == true);
m.unlock();
}).detach();
}
Expand Down

0 comments on commit 5defa1a

Please sign in to comment.