Skip to content

Error path tightening: use MBED_NORETURN; add+use core_util_atomic_flag #8328

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
merged 6 commits into from
Oct 30, 2018
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
48 changes: 0 additions & 48 deletions TESTS/mbed_hal/sleep_manager/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,6 @@ using utest::v1::Case;
using utest::v1::Specification;
using utest::v1::Harness;

static uint32_t num_test_errors = 0UL;

mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value,
const char *filename, int line_number)
{
(void) error_status;
(void) error_msg;
(void) error_value;
(void) filename;
(void) line_number;

num_test_errors++;
return MBED_SUCCESS;
}

void test_lock_unlock()
{
TEST_ASSERT_TRUE(sleep_manager_can_deep_sleep());
Expand All @@ -60,16 +45,6 @@ void test_lock_unlock()
TEST_ASSERT_TRUE(sleep_manager_can_deep_sleep());
}

void test_lone_unlock()
{
uint32_t expected_err_count = num_test_errors + 1;
sleep_manager_unlock_deep_sleep();
TEST_ASSERT_EQUAL_UINT32(expected_err_count, num_test_errors);

// Make sure upcoming tests won't be broken.
TEST_ASSERT_TRUE(sleep_manager_can_deep_sleep());
}

void test_lock_eq_ushrt_max()
{
uint32_t lock_count = 0;
Expand All @@ -87,27 +62,6 @@ void test_lock_eq_ushrt_max()
TEST_ASSERT_TRUE(sleep_manager_can_deep_sleep());
}

void test_lock_gt_ushrt_max()
{
uint32_t lock_count = 0;
while (lock_count < USHRT_MAX) {
sleep_manager_lock_deep_sleep();
lock_count++;
TEST_ASSERT_FALSE(sleep_manager_can_deep_sleep());
}

uint32_t expected_err_count = num_test_errors + 1;
sleep_manager_lock_deep_sleep();
TEST_ASSERT_EQUAL_UINT32(expected_err_count, num_test_errors);

// Make sure upcoming tests won't be broken.
while (lock_count > 0) {
sleep_manager_unlock_deep_sleep();
lock_count--;
}
TEST_ASSERT_TRUE(sleep_manager_can_deep_sleep());
}

#if DEVICE_LPTICKER
#if DEVICE_USTICKER
utest::v1::status_t testcase_setup(const Case * const source, const size_t index_of_case)
Expand Down Expand Up @@ -279,9 +233,7 @@ utest::v1::status_t testsuite_setup(const size_t number_of_cases)

Case cases[] = {
Case("deep sleep lock/unlock", test_lock_unlock),
Case("deep sleep unbalanced unlock", test_lone_unlock),
Case("deep sleep locked USHRT_MAX times", test_lock_eq_ushrt_max),
Case("deep sleep locked more than USHRT_MAX times", test_lock_gt_ushrt_max),
#if DEVICE_LPTICKER
#if DEVICE_USTICKER
Case("sleep_auto calls sleep/deep sleep based on lock",
Expand Down
16 changes: 0 additions & 16 deletions TESTS/mbed_hal/sleep_manager/sleep_manager_api_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@
*/
void test_lock_unlock();

/** Test an unbalanced unlock call
*
* Given the deep sleep has not been locked
* When the deep sleep mode is unlocked
* Then an mbed_error is raised
*/
void test_lone_unlock();

/** Test lock USHRT_MAX times
*
* Given a device with sleep mode support
Expand All @@ -58,14 +50,6 @@ void test_lone_unlock();
*/
void test_lock_eq_ushrt_max();

/** Test lock more than USHRT_MAX times
*
* Given the deep sleep has already been locked USHRT_MAX times
* When the deep sleep mode is locked again
* Then an mbed_error is raised
*/
void test_lock_gt_ushrt_max();

/** Test sleep_auto calls sleep and deep sleep based on lock
*
* Given a device with sleep mode support
Expand Down
24 changes: 4 additions & 20 deletions TESTS/mbedmicro-rtos-mbed/event_flags/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,6 @@ using utest::v1::Case;

Semaphore sync_sem(0, 1);

/* In order to successfully run this test suite when compiled with --profile=debug
* error() has to be redefined as noop.
*
* EventFlags calls RTX API which uses Event Recorder functionality. When compiled
* with MBED_TRAP_ERRORS_ENABLED=1 (set in debug profile) EvrRtxEventFlagsError() calls error()
* which aborts test program.
*/
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
void error(const char *format, ...)
{
(void) format;
}

//Override the set_error function to trap the errors
mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
{
return MBED_SUCCESS;
}
#endif

template<uint32_t flags, uint32_t wait_ms>
void send_thread(EventFlags *ef)
{
Expand Down Expand Up @@ -167,14 +147,18 @@ void test_prohibited(void)

ev.set(FLAG01 | FLAG02 | FLAG03);

#if !MBED_TRAP_ERRORS_ENABLED
flags = ev.clear(PROHIBITED_FLAG);
TEST_ASSERT_EQUAL(osFlagsErrorParameter, flags);
#endif

flags = ev.get();
TEST_ASSERT_EQUAL(FLAG01 | FLAG02 | FLAG03, flags);

#if !MBED_TRAP_ERRORS_ENABLED
flags = ev.set(PROHIBITED_FLAG);
TEST_ASSERT_EQUAL(osFlagsErrorParameter, flags);
#endif

flags = ev.get();
TEST_ASSERT_EQUAL(FLAG01 | FLAG02 | FLAG03, flags);
Expand Down
39 changes: 20 additions & 19 deletions TESTS/mbedmicro-rtos-mbed/rtostimer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,6 @@ void sem_callback(Semaphore *sem)
sem->release();
}

/* In order to successfully run this test suite when compiled with --profile=debug
* error() has to be redefined as noop.
*
* RtosTimer calls RTX API which uses Event Recorder functionality. When compiled
* with MBED_TRAP_ERRORS_ENABLED=1 (set in debug profile) EvrRtxTimerError() calls error()
* which aborts test program.
*/
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
void error(const char *format, ...)
{
(void) format;
}

mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
{
return MBED_SUCCESS;
}
#endif

/** Test one-shot not restarted when elapsed
*
* Given a one-shot RtosTimer
Expand All @@ -121,8 +102,11 @@ void test_oneshot_not_restarted()

slots = stopwatch.wait_until_stopped(DELAY_MS + DELTA_MS);
TEST_ASSERT_EQUAL(0, slots);

#if !MBED_TRAP_ERRORS_ENABLED
status = rtostimer.stop();
TEST_ASSERT_EQUAL(osErrorResource, status);
#endif
}

/** Test periodic repeats continuously
Expand Down Expand Up @@ -160,8 +144,11 @@ void test_periodic_repeats()

slots = stopwatch.wait_until_stopped(DELAY_MS + DELTA_MS);
TEST_ASSERT_EQUAL(0, slots);

#if !MBED_TRAP_ERRORS_ENABLED
status = rtostimer.stop();
TEST_ASSERT_EQUAL(osErrorResource, status);
#endif
}

/** Test timer can be started again
Expand All @@ -185,17 +172,21 @@ void test_start_again()
int32_t slots = sem.wait(DELAY_MS + DELTA_MS);
TEST_ASSERT_EQUAL(1, slots);

#if !MBED_TRAP_ERRORS_ENABLED
status = rtostimer.stop();
TEST_ASSERT_EQUAL(osErrorResource, status);
#endif

status = rtostimer.start(DELAY_MS);
TEST_ASSERT_EQUAL(osOK, status);

slots = sem.wait(DELAY_MS + DELTA_MS);
TEST_ASSERT_EQUAL(1, slots);

#if !MBED_TRAP_ERRORS_ENABLED
status = rtostimer.stop();
TEST_ASSERT_EQUAL(osErrorResource, status);
#endif
}

/** Test timer restart updates delay
Expand Down Expand Up @@ -228,8 +219,10 @@ void test_restart_updates_delay()
TEST_ASSERT_EQUAL(1, slots);
TEST_ASSERT_INT_WITHIN(DELTA_MS, DELAY2_MS, stopwatch.read_ms());

#if !MBED_TRAP_ERRORS_ENABLED
status = rtostimer.stop();
TEST_ASSERT_EQUAL(osErrorResource, status);
#endif
}

/** Test timer is created in stopped state
Expand All @@ -241,8 +234,10 @@ void test_restart_updates_delay()
void test_created_stopped()
{
RtosTimer rtostimer(mbed::callback(sem_callback, (Semaphore *) NULL), osTimerOnce);
#if !MBED_TRAP_ERRORS_ENABLED
osStatus status = rtostimer.stop();
TEST_ASSERT_EQUAL(osErrorResource, status);
#endif
}

/** Test one-shot can be stopped
Expand All @@ -269,8 +264,10 @@ void test_stop()
slots = sem.wait(DELAY_MS + DELTA_MS);
TEST_ASSERT_EQUAL(0, slots);

#if !MBED_TRAP_ERRORS_ENABLED
status = rtostimer.stop();
TEST_ASSERT_EQUAL(osErrorResource, status);
#endif
}

/** Test timer started with infinite delay
Expand All @@ -290,6 +287,7 @@ void test_wait_forever()
TEST_ASSERT_EQUAL(osOK, status);
}

#if !MBED_TRAP_ERRORS_ENABLED
/** Test timer started with zero delay
*
* Given a one-shot RtosTimer
Expand Down Expand Up @@ -331,6 +329,7 @@ void test_isr_calls_fail()

wait_ms(DELAY_MS + DELTA_MS);
}
#endif // !MBED_TRAP_ERRORS_ENABLED

utest::v1::status_t test_setup(const size_t number_of_cases)
{
Expand All @@ -346,8 +345,10 @@ Case cases[] = {
Case("Timer can be stopped", test_stop),
Case("Timer is created in stopped state", test_created_stopped),
Case("Timer started with infinite delay", test_wait_forever),
#if !MBED_TRAP_ERRORS_ENABLED
Case("Timer started with zero delay", test_no_wait),
Case("Calls from ISR fail", test_isr_calls_fail)
#endif
};

Specification specification(test_setup, cases);
Expand Down
23 changes: 2 additions & 21 deletions TESTS/mbedmicro-rtos-mbed/signals/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,6 @@ struct Sync {
Semaphore &sem_child;
};


/* In order to successfully run this test suite when compiled with --profile=debug
* error() has to be redefined as noop.
*
* ThreadFlags calls RTX API which uses Event Recorder functionality. When compiled
* with MBED_TRAP_ERRORS_ENABLED=1 (set in debug profile) EvrRtxEventFlagsError() calls error()
* which aborts test program.
*/
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
void error(const char *format, ...)
{
(void) format;
}

mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
{
return MBED_SUCCESS;
}
#endif


template <int32_t signals, uint32_t timeout, int32_t test_val>
void run_signal_wait(void)
{
Expand Down Expand Up @@ -214,8 +193,10 @@ void test_set_prohibited(void)
sem_parent.wait();
t.signal_set(ALL_SIGNALS);

#if !MBED_TRAP_ERRORS_ENABLED
ret = t.signal_set(PROHIBITED_SIGNAL);
TEST_ASSERT_EQUAL(osErrorParameter, ret);
#endif

sem_child.release();
t.join();
Expand Down
4 changes: 2 additions & 2 deletions features/lwipstack/lwip-sys/arch/cc.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
void lwip_mbed_tracef_debug(const char *fmt, ...);
void lwip_mbed_tracef_error(const char *fmt, ...);
void lwip_mbed_tracef_warn(const char *fmt, ...);
void lwip_mbed_assert_fail(const char *msg, const char *func, const char *file, unsigned int line);
MBED_NORETURN void lwip_mbed_assert_fail(const char *msg, const char *func, const char *file, unsigned int line);

#define LWIP_PLATFORM_DIAG(vars) lwip_mbed_tracef_debug vars
#define LWIP_PLATFORM_DIAG_SEVERE(vars) lwip_mbed_tracef_error vars
Expand All @@ -109,7 +109,7 @@ void lwip_mbed_assert_fail(const char *msg, const char *func, const char *file,
#else // MBED_CONF_LWIP_USE_MBED_TRACE
#include <stdio.h>

void assert_printf(char *msg, int line, char *file);
MBED_NORETURN void assert_printf(char *msg, int line, char *file);

/* Plaform specific diagnostic output */
#define LWIP_PLATFORM_DIAG(vars) printf vars
Expand Down
4 changes: 2 additions & 2 deletions features/lwipstack/lwip-sys/arch/lwip_sys_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ void lwip_mbed_tracef_error(const char *fmt, ...)
va_end(ap);
}

void lwip_mbed_assert_fail(const char *msg, const char *func, const char *file, unsigned int line)
MBED_NORETURN void lwip_mbed_assert_fail(const char *msg, const char *func, const char *file, unsigned int line)
{
mbed_tracef(TRACE_LEVEL_ERROR, "lwIP", "Assertion failed: %s, function %s, file %s, line %u.", msg, func, file, line);
exit(EXIT_FAILURE); // XXX how about abort? mbed_assert uses exit, so follow suit
Expand All @@ -605,7 +605,7 @@ void lwip_mbed_assert_fail(const char *msg, const char *func, const char *file,
\param[in] line Line number in file with error
\param[in] file Filename with error
*/
void assert_printf(char *msg, int line, char *file) {
MBED_NORETURN void assert_printf(char *msg, int line, char *file) {
if (msg)
error("%s:%d in file %s\n", msg, line, file);
else
Expand Down
8 changes: 0 additions & 8 deletions hal/mbed_sleep_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ void sleep_manager_lock_deep_sleep_internal(void)
if (deep_sleep_lock == USHRT_MAX) {
core_util_critical_section_exit();
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_HAL, MBED_ERROR_CODE_OVERFLOW), "DeepSleepLock overflow (> USHRT_MAX)", deep_sleep_lock);
// When running sleep_manager tests, the mbed_error() is overridden
// and no longer calls mbed_halt_system(). Return to prevent
// execution of the following code.
return;
}
core_util_atomic_incr_u16(&deep_sleep_lock, 1);
core_util_critical_section_exit();
Expand All @@ -178,10 +174,6 @@ void sleep_manager_unlock_deep_sleep_internal(void)
if (deep_sleep_lock == 0) {
core_util_critical_section_exit();
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_HAL, MBED_ERROR_CODE_UNDERFLOW), "DeepSleepLock underflow (< 0)", deep_sleep_lock);
// When running sleep_manager tests, the mbed_error() is overridden
// and no longer calls mbed_halt_system(). Return to prevent
// execution of the following code.
return;
}
core_util_atomic_decr_u16(&deep_sleep_lock, 1);
core_util_critical_section_exit();
Expand Down
2 changes: 1 addition & 1 deletion platform/mbed_assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "platform/mbed_critical.h"
#include "platform/mbed_error.h"

void mbed_assert_internal(const char *expr, const char *file, int line)
MBED_NORETURN void mbed_assert_internal(const char *expr, const char *file, int line)
{
core_util_critical_section_enter();
mbed_error(MBED_ERROR_ASSERTION_FAILED, expr, 0, file, line);
Expand Down
Loading