Skip to content

Commit

Permalink
Merge pull request RIOT-OS#20445 from benpicco/cpu/native-AUTO_EXIT
Browse files Browse the repository at this point in the history
tests: exit `native` with error value on failure
  • Loading branch information
benpicco committed Mar 4, 2024
2 parents 3084086 + b274e8a commit 31d2300
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 8 deletions.
11 changes: 11 additions & 0 deletions core/lib/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ static void *main_trampoline(void *arg)
}
#endif

#ifdef CPU_NATIVE
extern unsigned _native_retval;
if (!_native_retval) {
_native_retval = res;
}
#endif

if (IS_ACTIVE(CONFIG_CORE_EXIT_WITH_MAIN)) {
pm_off();
}

return NULL;
}

Expand Down
3 changes: 2 additions & 1 deletion cpu/native/native_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@ void cpu_switch_context_exit(void)
{
#ifdef NATIVE_AUTO_EXIT
if (sched_num_threads <= 1) {
extern unsigned _native_retval;
DEBUG("cpu_switch_context_exit: last task has ended. exiting.\n");
real_exit(EXIT_SUCCESS);
real_exit(_native_retval);
}
#endif

Expand Down
4 changes: 3 additions & 1 deletion sys/embunit/TestRunner.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void TestRunner_runTest(Test* test)
Test_run(test, &result_);
}

void TestRunner_end(void)
int TestRunner_end(void)
{
char buf[16];
if (result_.failureCount) {
Expand All @@ -118,4 +118,6 @@ void TestRunner_end(void)
stdimpl_print(buf);
stdimpl_print(" tests)\n");
}

return TestRunnerHadErrors;
}
2 changes: 1 addition & 1 deletion sys/include/embUnit/TestRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern "C" {

void TestRunner_start(void);
void TestRunner_runTest(Test* test);
void TestRunner_end(void);
int TestRunner_end(void);

extern int TestRunnerHadErrors;

Expand Down
3 changes: 3 additions & 0 deletions tests/Makefile.tests_common
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ ifneq (,$(wildcard $(CURDIR)/tests*/.))
endif
endif

# terminate native when the test is complete
CFLAGS += -DNATIVE_AUTO_EXIT=1

BOARD ?= native
RIOTBASE ?= $(CURDIR)/../..
QUIET ?= 1
Expand Down
2 changes: 0 additions & 2 deletions tests/sys/pthread_condition_variable/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ USEMODULE += posix_headers
USEMODULE += pthread
USEMODULE += xtimer

CFLAGS += -DNATIVE_AUTO_EXIT

include $(RIOTBASE)/Makefile.include
1 change: 1 addition & 0 deletions tests/unittests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ INCLUDES += -I$(RIOTBASE)/tests/unittests/common

# some tests need more stack
CFLAGS += -DTHREAD_STACKSIZE_MAIN=THREAD_STACKSIZE_LARGE
CFLAGS += -DCONFIG_CORE_EXIT_WITH_MAIN=1

# for these boards, enable asan (Address Sanitizer)
ASAN_BOARDS ?= native native64
Expand Down
4 changes: 1 addition & 3 deletions tests/unittests/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,5 @@ int main(void)
#ifndef NO_TEST_SUITES
UNCURRY(RUN_TEST_SUITES, TEST_SUITES)
#endif
TESTS_END();

return 0;
return TESTS_END();
}

0 comments on commit 31d2300

Please sign in to comment.