Skip to content

Commit 5ed07c2

Browse files
author
Cruz Monrreal
authored
Merge pull request #8328 from kjbracey-arm/noreturn
Error path tightening: use MBED_NORETURN; add+use core_util_atomic_flag
2 parents c9eaddd + 90a731d commit 5ed07c2

File tree

20 files changed

+158
-201
lines changed

20 files changed

+158
-201
lines changed

TESTS/mbed_hal/sleep_manager/main.cpp

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,6 @@ using utest::v1::Case;
3434
using utest::v1::Specification;
3535
using utest::v1::Harness;
3636

37-
static uint32_t num_test_errors = 0UL;
38-
39-
mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value,
40-
const char *filename, int line_number)
41-
{
42-
(void) error_status;
43-
(void) error_msg;
44-
(void) error_value;
45-
(void) filename;
46-
(void) line_number;
47-
48-
num_test_errors++;
49-
return MBED_SUCCESS;
50-
}
51-
5237
void test_lock_unlock()
5338
{
5439
TEST_ASSERT_TRUE(sleep_manager_can_deep_sleep());
@@ -60,16 +45,6 @@ void test_lock_unlock()
6045
TEST_ASSERT_TRUE(sleep_manager_can_deep_sleep());
6146
}
6247

63-
void test_lone_unlock()
64-
{
65-
uint32_t expected_err_count = num_test_errors + 1;
66-
sleep_manager_unlock_deep_sleep();
67-
TEST_ASSERT_EQUAL_UINT32(expected_err_count, num_test_errors);
68-
69-
// Make sure upcoming tests won't be broken.
70-
TEST_ASSERT_TRUE(sleep_manager_can_deep_sleep());
71-
}
72-
7348
void test_lock_eq_ushrt_max()
7449
{
7550
uint32_t lock_count = 0;
@@ -87,27 +62,6 @@ void test_lock_eq_ushrt_max()
8762
TEST_ASSERT_TRUE(sleep_manager_can_deep_sleep());
8863
}
8964

90-
void test_lock_gt_ushrt_max()
91-
{
92-
uint32_t lock_count = 0;
93-
while (lock_count < USHRT_MAX) {
94-
sleep_manager_lock_deep_sleep();
95-
lock_count++;
96-
TEST_ASSERT_FALSE(sleep_manager_can_deep_sleep());
97-
}
98-
99-
uint32_t expected_err_count = num_test_errors + 1;
100-
sleep_manager_lock_deep_sleep();
101-
TEST_ASSERT_EQUAL_UINT32(expected_err_count, num_test_errors);
102-
103-
// Make sure upcoming tests won't be broken.
104-
while (lock_count > 0) {
105-
sleep_manager_unlock_deep_sleep();
106-
lock_count--;
107-
}
108-
TEST_ASSERT_TRUE(sleep_manager_can_deep_sleep());
109-
}
110-
11165
#if DEVICE_LPTICKER
11266
#if DEVICE_USTICKER
11367
utest::v1::status_t testcase_setup(const Case *const source, const size_t index_of_case)
@@ -279,9 +233,7 @@ utest::v1::status_t testsuite_setup(const size_t number_of_cases)
279233

280234
Case cases[] = {
281235
Case("deep sleep lock/unlock", test_lock_unlock),
282-
Case("deep sleep unbalanced unlock", test_lone_unlock),
283236
Case("deep sleep locked USHRT_MAX times", test_lock_eq_ushrt_max),
284-
Case("deep sleep locked more than USHRT_MAX times", test_lock_gt_ushrt_max),
285237
#if DEVICE_LPTICKER
286238
#if DEVICE_USTICKER
287239
Case("sleep_auto calls sleep/deep sleep based on lock",

TESTS/mbed_hal/sleep_manager/sleep_manager_api_tests.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@
3838
*/
3939
void test_lock_unlock();
4040

41-
/** Test an unbalanced unlock call
42-
*
43-
* Given the deep sleep has not been locked
44-
* When the deep sleep mode is unlocked
45-
* Then an mbed_error is raised
46-
*/
47-
void test_lone_unlock();
48-
4941
/** Test lock USHRT_MAX times
5042
*
5143
* Given a device with sleep mode support
@@ -58,14 +50,6 @@ void test_lone_unlock();
5850
*/
5951
void test_lock_eq_ushrt_max();
6052

61-
/** Test lock more than USHRT_MAX times
62-
*
63-
* Given the deep sleep has already been locked USHRT_MAX times
64-
* When the deep sleep mode is locked again
65-
* Then an mbed_error is raised
66-
*/
67-
void test_lock_gt_ushrt_max();
68-
6953
/** Test sleep_auto calls sleep and deep sleep based on lock
7054
*
7155
* Given a device with sleep mode support

TESTS/mbedmicro-rtos-mbed/event_flags/main.cpp

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,6 @@ using utest::v1::Case;
4848

4949
Semaphore sync_sem(0, 1);
5050

51-
/* In order to successfully run this test suite when compiled with --profile=debug
52-
* error() has to be redefined as noop.
53-
*
54-
* EventFlags calls RTX API which uses Event Recorder functionality. When compiled
55-
* with MBED_TRAP_ERRORS_ENABLED=1 (set in debug profile) EvrRtxEventFlagsError() calls error()
56-
* which aborts test program.
57-
*/
58-
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
59-
void error(const char *format, ...)
60-
{
61-
(void) format;
62-
}
63-
64-
//Override the set_error function to trap the errors
65-
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)
66-
{
67-
return MBED_SUCCESS;
68-
}
69-
#endif
70-
7151
template<uint32_t flags, uint32_t wait_ms>
7252
void send_thread(EventFlags *ef)
7353
{
@@ -167,14 +147,18 @@ void test_prohibited(void)
167147

168148
ev.set(FLAG01 | FLAG02 | FLAG03);
169149

150+
#if !MBED_TRAP_ERRORS_ENABLED
170151
flags = ev.clear(PROHIBITED_FLAG);
171152
TEST_ASSERT_EQUAL(osFlagsErrorParameter, flags);
153+
#endif
172154

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

158+
#if !MBED_TRAP_ERRORS_ENABLED
176159
flags = ev.set(PROHIBITED_FLAG);
177160
TEST_ASSERT_EQUAL(osFlagsErrorParameter, flags);
161+
#endif
178162

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

TESTS/mbedmicro-rtos-mbed/rtostimer/main.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,6 @@ void sem_callback(Semaphore *sem)
7777
sem->release();
7878
}
7979

80-
/* In order to successfully run this test suite when compiled with --profile=debug
81-
* error() has to be redefined as noop.
82-
*
83-
* RtosTimer calls RTX API which uses Event Recorder functionality. When compiled
84-
* with MBED_TRAP_ERRORS_ENABLED=1 (set in debug profile) EvrRtxTimerError() calls error()
85-
* which aborts test program.
86-
*/
87-
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
88-
void error(const char *format, ...)
89-
{
90-
(void) format;
91-
}
92-
93-
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)
94-
{
95-
return MBED_SUCCESS;
96-
}
97-
#endif
98-
9980
/** Test one-shot not restarted when elapsed
10081
*
10182
* Given a one-shot RtosTimer
@@ -121,8 +102,11 @@ void test_oneshot_not_restarted()
121102

122103
slots = stopwatch.wait_until_stopped(DELAY_MS + DELTA_MS);
123104
TEST_ASSERT_EQUAL(0, slots);
105+
106+
#if !MBED_TRAP_ERRORS_ENABLED
124107
status = rtostimer.stop();
125108
TEST_ASSERT_EQUAL(osErrorResource, status);
109+
#endif
126110
}
127111

128112
/** Test periodic repeats continuously
@@ -160,8 +144,11 @@ void test_periodic_repeats()
160144

161145
slots = stopwatch.wait_until_stopped(DELAY_MS + DELTA_MS);
162146
TEST_ASSERT_EQUAL(0, slots);
147+
148+
#if !MBED_TRAP_ERRORS_ENABLED
163149
status = rtostimer.stop();
164150
TEST_ASSERT_EQUAL(osErrorResource, status);
151+
#endif
165152
}
166153

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

175+
#if !MBED_TRAP_ERRORS_ENABLED
188176
status = rtostimer.stop();
189177
TEST_ASSERT_EQUAL(osErrorResource, status);
178+
#endif
190179

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

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

186+
#if !MBED_TRAP_ERRORS_ENABLED
197187
status = rtostimer.stop();
198188
TEST_ASSERT_EQUAL(osErrorResource, status);
189+
#endif
199190
}
200191

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

222+
#if !MBED_TRAP_ERRORS_ENABLED
231223
status = rtostimer.stop();
232224
TEST_ASSERT_EQUAL(osErrorResource, status);
225+
#endif
233226
}
234227

235228
/** Test timer is created in stopped state
@@ -241,8 +234,10 @@ void test_restart_updates_delay()
241234
void test_created_stopped()
242235
{
243236
RtosTimer rtostimer(mbed::callback(sem_callback, (Semaphore *) NULL), osTimerOnce);
237+
#if !MBED_TRAP_ERRORS_ENABLED
244238
osStatus status = rtostimer.stop();
245239
TEST_ASSERT_EQUAL(osErrorResource, status);
240+
#endif
246241
}
247242

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

267+
#if !MBED_TRAP_ERRORS_ENABLED
272268
status = rtostimer.stop();
273269
TEST_ASSERT_EQUAL(osErrorResource, status);
270+
#endif
274271
}
275272

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

290+
#if !MBED_TRAP_ERRORS_ENABLED
293291
/** Test timer started with zero delay
294292
*
295293
* Given a one-shot RtosTimer
@@ -331,6 +329,7 @@ void test_isr_calls_fail()
331329

332330
wait_ms(DELAY_MS + DELTA_MS);
333331
}
332+
#endif // !MBED_TRAP_ERRORS_ENABLED
334333

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

353354
Specification specification(test_setup, cases);

TESTS/mbedmicro-rtos-mbed/signals/main.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,6 @@ struct Sync {
4646
Semaphore &sem_child;
4747
};
4848

49-
50-
/* In order to successfully run this test suite when compiled with --profile=debug
51-
* error() has to be redefined as noop.
52-
*
53-
* ThreadFlags calls RTX API which uses Event Recorder functionality. When compiled
54-
* with MBED_TRAP_ERRORS_ENABLED=1 (set in debug profile) EvrRtxEventFlagsError() calls error()
55-
* which aborts test program.
56-
*/
57-
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
58-
void error(const char *format, ...)
59-
{
60-
(void) format;
61-
}
62-
63-
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)
64-
{
65-
return MBED_SUCCESS;
66-
}
67-
#endif
68-
69-
7049
template <int32_t signals, uint32_t timeout, int32_t test_val>
7150
void run_signal_wait(void)
7251
{
@@ -214,8 +193,10 @@ void test_set_prohibited(void)
214193
sem_parent.wait();
215194
t.signal_set(ALL_SIGNALS);
216195

196+
#if !MBED_TRAP_ERRORS_ENABLED
217197
ret = t.signal_set(PROHIBITED_SIGNAL);
218198
TEST_ASSERT_EQUAL(osErrorParameter, ret);
199+
#endif
219200

220201
sem_child.release();
221202
t.join();

features/lwipstack/lwip-sys/arch/cc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
void lwip_mbed_tracef_debug(const char *fmt, ...);
9898
void lwip_mbed_tracef_error(const char *fmt, ...);
9999
void lwip_mbed_tracef_warn(const char *fmt, ...);
100-
void lwip_mbed_assert_fail(const char *msg, const char *func, const char *file, unsigned int line);
100+
MBED_NORETURN void lwip_mbed_assert_fail(const char *msg, const char *func, const char *file, unsigned int line);
101101

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

112-
void assert_printf(char *msg, int line, char *file);
112+
MBED_NORETURN void assert_printf(char *msg, int line, char *file);
113113

114114
/* Plaform specific diagnostic output */
115115
#define LWIP_PLATFORM_DIAG(vars) printf vars

features/lwipstack/lwip-sys/arch/lwip_sys_arch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ void lwip_mbed_tracef_error(const char *fmt, ...)
589589
va_end(ap);
590590
}
591591

592-
void lwip_mbed_assert_fail(const char *msg, const char *func, const char *file, unsigned int line)
592+
MBED_NORETURN void lwip_mbed_assert_fail(const char *msg, const char *func, const char *file, unsigned int line)
593593
{
594594
mbed_tracef(TRACE_LEVEL_ERROR, "lwIP", "Assertion failed: %s, function %s, file %s, line %u.", msg, func, file, line);
595595
exit(EXIT_FAILURE); // XXX how about abort? mbed_assert uses exit, so follow suit
@@ -605,7 +605,7 @@ void lwip_mbed_assert_fail(const char *msg, const char *func, const char *file,
605605
\param[in] line Line number in file with error
606606
\param[in] file Filename with error
607607
*/
608-
void assert_printf(char *msg, int line, char *file) {
608+
MBED_NORETURN void assert_printf(char *msg, int line, char *file) {
609609
if (msg)
610610
error("%s:%d in file %s\n", msg, line, file);
611611
else

hal/mbed_sleep_manager.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,6 @@ void sleep_manager_lock_deep_sleep_internal(void)
163163
if (deep_sleep_lock == USHRT_MAX) {
164164
core_util_critical_section_exit();
165165
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_HAL, MBED_ERROR_CODE_OVERFLOW), "DeepSleepLock overflow (> USHRT_MAX)", deep_sleep_lock);
166-
// When running sleep_manager tests, the mbed_error() is overridden
167-
// and no longer calls mbed_halt_system(). Return to prevent
168-
// execution of the following code.
169-
return;
170166
}
171167
core_util_atomic_incr_u16(&deep_sleep_lock, 1);
172168
core_util_critical_section_exit();
@@ -178,10 +174,6 @@ void sleep_manager_unlock_deep_sleep_internal(void)
178174
if (deep_sleep_lock == 0) {
179175
core_util_critical_section_exit();
180176
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_HAL, MBED_ERROR_CODE_UNDERFLOW), "DeepSleepLock underflow (< 0)", deep_sleep_lock);
181-
// When running sleep_manager tests, the mbed_error() is overridden
182-
// and no longer calls mbed_halt_system(). Return to prevent
183-
// execution of the following code.
184-
return;
185177
}
186178
core_util_atomic_decr_u16(&deep_sleep_lock, 1);
187179
core_util_critical_section_exit();

platform/mbed_assert.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "platform/mbed_critical.h"
2121
#include "platform/mbed_error.h"
2222

23-
void mbed_assert_internal(const char *expr, const char *file, int line)
23+
MBED_NORETURN void mbed_assert_internal(const char *expr, const char *file, int line)
2424
{
2525
core_util_critical_section_enter();
2626
mbed_error(MBED_ERROR_ASSERTION_FAILED, expr, 0, file, line);

0 commit comments

Comments
 (0)