Skip to content
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

tests: exit native with error value on failure #20445

Merged
merged 5 commits into from
Mar 4, 2024
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
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 @@ -166,7 +166,7 @@
sched_run();
}

DEBUG("isr_cpu_switch_context_exit: calling setcontext(%" PRIkernel_pid ")\n\n", thread_getpid());

Check warning on line 169 in cpu/native/native_cpu.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
/* Use intermediate cast to uintptr_t to silence -Wcast-align.
* stacks are manually word aligned in thread_static_init() */
ctx = (ucontext_t *)(uintptr_t)(thread_get_active()->sp);
Expand All @@ -184,8 +184,9 @@
{
#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 @@ -43,20 +43,20 @@
static Test* root_;
int TestRunnerHadErrors;

static void TestRunner_startTest(TestListner* self,Test* test)

Check warning on line 46 in sys/embunit/TestRunner.c

View workflow job for this annotation

GitHub Actions / static-tests

comma should be followed by whitespace
{
(void)self;
(void)test;
stdimpl_print(".");
}

static void TestRunner_endTest(TestListner* self,Test* test)

Check warning on line 53 in sys/embunit/TestRunner.c

View workflow job for this annotation

GitHub Actions / static-tests

comma should be followed by whitespace
{
(void)self;
(void)test;
}

static void TestRunner_addFailure(TestListner* self,Test* test,char* msg,int line,char* file)

Check warning on line 59 in sys/embunit/TestRunner.c

View workflow job for this annotation

GitHub Actions / static-tests

comma should be followed by whitespace
{
(void)self;
stdimpl_print("\n");
Expand Down Expand Up @@ -99,7 +99,7 @@
Test_run(test, &result_);
}

void TestRunner_end(void)
int TestRunner_end(void)
{
char buf[16];
if (result_.failureCount) {
Expand All @@ -118,4 +118,6 @@
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();
}
Loading