From 624957252eb4a5a4380a0f4c207cec12f113905b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Wed, 11 Sep 2019 17:07:06 +0200 Subject: [PATCH 1/3] pthread_cond.h: use 'sys/types.h' value of 'clockid_t' for avr This enables 'pthread' support on arduino. avr-libc C90 'time.h' does not include 'sys/types.h' as POSIX expects it. However, the type previously defined conflicts with the one in 'cpu/atmega_common/avr_libc_extra/include/sys/types.h' when both are included, so include 'sys/types.h'. Maybe it should alway be included by 'time.h' but this would need its specific review. --- sys/posix/pthread/include/pthread_cond.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sys/posix/pthread/include/pthread_cond.h b/sys/posix/pthread/include/pthread_cond.h index a0cfc444af..683a24f5a4 100644 --- a/sys/posix/pthread/include/pthread_cond.h +++ b/sys/posix/pthread/include/pthread_cond.h @@ -25,14 +25,18 @@ # include "msp430_types.h" #endif +#if defined(__WITH_AVRLIBC__) +/* avr-libc 'time.h' does not include 'sys/types.h' but we need 'clockid_t' */ +# include +#endif + #ifdef __MACH__ /* needed for AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER */ #include -#endif - -#if defined(__WITH_AVRLIBC__) || (defined(__MACH__) && !defined(AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER)) +#if !defined(AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER) typedef int clockid_t; #endif +#endif #ifdef __cplusplus extern "C" { From 5c405b56f846235843bc2801f61e8e9bd6bf735c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Wed, 11 Sep 2019 18:19:26 +0200 Subject: [PATCH 2/3] tests/pthread_condition_variable: adapt for slow boards Reduce the number of required iterations on boards. This will allow running it on 'arduino-mega2560'. --- tests/pthread_condition_variable/main.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/pthread_condition_variable/main.c b/tests/pthread_condition_variable/main.c index e16b6ef6ca..c61d113297 100644 --- a/tests/pthread_condition_variable/main.c +++ b/tests/pthread_condition_variable/main.c @@ -26,7 +26,6 @@ static mutex_t mutex = MUTEX_INIT; static pthread_cond_t cv; static volatile int is_finished; static volatile long count; -static volatile long expected_value; static char stack[THREAD_STACKSIZE_MAIN]; /** @@ -50,12 +49,17 @@ static void *second_thread(void *arg) return NULL; } +#ifdef BOARD_NATIVE +#define ITERATION_STEPS 100000 +#else +#define ITERATION_STEPS 10000 +#endif + int main(void) { puts("START"); count = 0; is_finished = 0; - expected_value = 1000ul * 1000ul; pthread_cond_init(&cv, NULL); kernel_pid_t pid = thread_create(stack,sizeof(stack), THREAD_PRIORITY_MAIN - 1, @@ -67,11 +71,11 @@ int main(void) thread_wakeup(pid); count++; - if ((count % 100000) == 0) { + if ((count % ITERATION_STEPS) == 0) { printf("Still alive alternated [count: %ldk] times.\n", count / 1000); } - if (count == expected_value) { + if (count == (10ul * ITERATION_STEPS)) { puts("condition fulfilled."); is_finished = 1; mutex_unlock(&mutex); From 9ee84c62c948fc287f08c7bc4e2c4ae46b329eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Wed, 11 Sep 2019 17:31:25 +0200 Subject: [PATCH 3/3] tests/pthread*: enable pthread tests on avr 'pthread' is now compatible with 'avr' so enable them in tests. All the tests ran on 'arduino-mega2560' when supported. --- tests/pthread/Makefile | 7 ----- tests/pthread_barrier/Makefile | 12 ++++----- tests/pthread_cleanup/Makefile | 7 ----- tests/pthread_condition_variable/Makefile | 7 ----- tests/pthread_cooperation/Makefile | 26 ++++++++++++++----- tests/pthread_flood/Makefile | 14 +++++----- tests/pthread_rwlock/Makefile | 31 ++++++++++++++--------- tests/pthread_tls/Makefile | 13 +++++----- 8 files changed, 55 insertions(+), 62 deletions(-) diff --git a/tests/pthread/Makefile b/tests/pthread/Makefile index 91e9a583e5..56fab8e685 100644 --- a/tests/pthread/Makefile +++ b/tests/pthread/Makefile @@ -1,12 +1,5 @@ include ../Makefile.tests_common -BOARD_BLACKLIST := arduino-duemilanove arduino-leonardo arduino-mega2560 \ - arduino-nano arduino-uno jiminy-mega256rfr2 mega-xplained \ - waspmote-pro -# arduino mega2560 uno duemilanove : unknown type name: clockid_t -# jiminy-mega256rfr2: unknown type name: clockid_t -# mega-xplained: unknown type name: clockid_t - USEMODULE += posix_headers USEMODULE += pthread diff --git a/tests/pthread_barrier/Makefile b/tests/pthread_barrier/Makefile index c0be0fd9a7..2c34c8a8eb 100644 --- a/tests/pthread_barrier/Makefile +++ b/tests/pthread_barrier/Makefile @@ -1,12 +1,10 @@ include ../Makefile.tests_common -BOARD_BLACKLIST := arduino-duemilanove arduino-leonardo arduino-mega2560 \ - arduino-nano arduino-uno i-nucleo-lrwan1 jiminy-mega256rfr2 \ - mega-xplained stm32l0538-disco waspmote-pro -# AVR platform: unknown type name: clockid_t - -# exclude boards with insufficient memory -BOARD_INSUFFICIENT_MEMORY := nucleo-f031k6 +BOARD_INSUFFICIENT_MEMORY = \ + i-nucleo-lrwan1 \ + nucleo-f031k6 \ + stm32l0538-disco \ + # # Modules to include. USEMODULE += pthread diff --git a/tests/pthread_cleanup/Makefile b/tests/pthread_cleanup/Makefile index 0eb46a22be..a655477524 100644 --- a/tests/pthread_cleanup/Makefile +++ b/tests/pthread_cleanup/Makefile @@ -1,12 +1,5 @@ include ../Makefile.tests_common -BOARD_BLACKLIST := arduino-duemilanove arduino-leonardo arduino-mega2560 \ - arduino-nano arduino-uno jiminy-mega256rfr2 mega-xplained \ - waspmote-pro -# arduino mega2560 uno duemilanove : unknown type name: clockid_t -# jiminy-mega256rfr2: unknown type name: clockid_t -# mega-xplained: unknown type name: clockid_t - USEMODULE += pthread include $(RIOTBASE)/Makefile.include diff --git a/tests/pthread_condition_variable/Makefile b/tests/pthread_condition_variable/Makefile index ad55d08c60..e1353f4b69 100644 --- a/tests/pthread_condition_variable/Makefile +++ b/tests/pthread_condition_variable/Makefile @@ -1,12 +1,5 @@ include ../Makefile.tests_common -BOARD_BLACKLIST := arduino-duemilanove arduino-leonardo arduino-mega2560 \ - arduino-nano arduino-uno jiminy-mega256rfr2 mega-xplained \ - waspmote-pro -# arduino mega2560 uno duemilanove : unknown type name: clockid_t -# jiminy-mega256rfr2: unknown type name: clockid_t -# mega-xplained: unknown type name: clockid_t - BOARD_INSUFFICIENT_MEMORY := nucleo-f031k6 USEMODULE += posix_headers diff --git a/tests/pthread_cooperation/Makefile b/tests/pthread_cooperation/Makefile index 234482deb1..3cd83bd7e1 100644 --- a/tests/pthread_cooperation/Makefile +++ b/tests/pthread_cooperation/Makefile @@ -1,13 +1,25 @@ include ../Makefile.tests_common -BOARD_BLACKLIST := arduino-duemilanove arduino-leonardo arduino-mega2560 \ - arduino-nano arduino-uno hifive1 hifive1b i-nucleo-lrwan1 \ - jiminy-mega256rfr2 mega-xplained stm32l0538-disco waspmote-pro +BOARD_INSUFFICIENT_MEMORY := \ + arduino-duemilanove \ + arduino-nano \ + arduino-uno \ + nucleo-f031k6 \ + hifive1 \ + hifive1b \ + i-nucleo-lrwan1 \ + stm32l0538-disco \ + # -# AVR platform: unknown type name: clockid_t -# hifive1: not enough memory for thread stacks - -BOARD_INSUFFICIENT_MEMORY := nucleo-f031k6 +# The test reboots on 'arduino-mega2560' because it mallocs too much memory. +# So I disabled all the other avr boards. Re-enable after success test. +BOARD_INSUFFICIENT_MEMORY += \ + arduino-leonardo \ + arduino-mega2560 \ + jiminy-mega256rfr2 \ + mega-xplained \ + waspmote-pro \ + # USEMODULE += posix_headers USEMODULE += pthread diff --git a/tests/pthread_flood/Makefile b/tests/pthread_flood/Makefile index 89544eb304..862b87d269 100644 --- a/tests/pthread_flood/Makefile +++ b/tests/pthread_flood/Makefile @@ -1,13 +1,11 @@ include ../Makefile.tests_common -BOARD_INSUFFICIENT_MEMORY := nucleo-f031k6 - -BOARD_BLACKLIST := arduino-duemilanove arduino-leonardo arduino-mega2560 \ - arduino-nano arduino-uno jiminy-mega256rfr2 mega-xplained \ - waspmote-pro -# arduino mega2560 uno duemilanove : unknown type name: clockid_t -# jiminy-mega256rfr2: unknown type name: clockid_t -# mega-xplained: unknown type name: clockid_t +BOARD_INSUFFICIENT_MEMORY = \ + arduino-duemilanove \ + arduino-nano \ + arduino-uno \ + nucleo-f031k6 \ + # USEMODULE += posix_headers USEMODULE += pthread diff --git a/tests/pthread_rwlock/Makefile b/tests/pthread_rwlock/Makefile index 0da8558322..3ff6a523f4 100644 --- a/tests/pthread_rwlock/Makefile +++ b/tests/pthread_rwlock/Makefile @@ -1,21 +1,28 @@ include ../Makefile.tests_common -BOARD_BLACKLIST := arduino-duemilanove arduino-leonardo arduino-mega2560 \ - arduino-nano arduino-uno jiminy-mega256rfr2 mega-xplained \ - waspmote-pro -# arduino mega2560 uno duemilanove : unknown type name: clockid_t -# jiminy-mega256rfr2: unknown type name: clockid_t -# mega-xplained: unknown type name: clockid_t - USEMODULE += pthread USEMODULE += xtimer USEMODULE += random -BOARD_INSUFFICIENT_MEMORY += chronos i-nucleo-lrwan1 \ - msb-430 msb-430h nucleo-f031k6 \ - nucleo-f042k6 nucleo-l031k6 nucleo-f030r8 \ - nucleo-f303k8 nucleo-f334r8 nucleo-l053r8 \ - stm32f0discovery stm32l0538-disco +BOARD_INSUFFICIENT_MEMORY = \ + arduino-duemilanove \ + arduino-leonardo \ + arduino-nano \ + arduino-uno \ + chronos \ + i-nucleo-lrwan1 \ + msb-430 \ + msb-430h \ + nucleo-f030r8 \ + nucleo-f031k6 \ + nucleo-f042k6 \ + nucleo-f303k8 \ + nucleo-f334r8 \ + nucleo-l031k6 \ + nucleo-l053r8 \ + stm32f0discovery \ + stm32l0538-disco \ + # # HACK Blacklist native as `murdock` fails on utf-8 characters for native tests TEST_ON_CI_BLACKLIST += native diff --git a/tests/pthread_tls/Makefile b/tests/pthread_tls/Makefile index 91e9a583e5..538c50e5ee 100644 --- a/tests/pthread_tls/Makefile +++ b/tests/pthread_tls/Makefile @@ -1,13 +1,12 @@ include ../Makefile.tests_common -BOARD_BLACKLIST := arduino-duemilanove arduino-leonardo arduino-mega2560 \ - arduino-nano arduino-uno jiminy-mega256rfr2 mega-xplained \ - waspmote-pro -# arduino mega2560 uno duemilanove : unknown type name: clockid_t -# jiminy-mega256rfr2: unknown type name: clockid_t -# mega-xplained: unknown type name: clockid_t - USEMODULE += posix_headers USEMODULE += pthread +BOARD_INSUFFICIENT_MEMORY = \ + arduino-duemilanove \ + arduino-nano \ + arduino-uno \ + # + include $(RIOTBASE)/Makefile.include