From 7a1c099e7bea56b98523043893f3fccf6cf13660 Mon Sep 17 00:00:00 2001 From: Frederik Haxel Date: Thu, 11 Jan 2024 13:16:17 +0100 Subject: [PATCH] tests: 64 bit compatibility Fixed compilation errors. Mostly DEBUG/printf formatting and void pointer casting. Other changes are: * net/gnrc_sixlowpan_frag_*: Generalized packet size calculation * cpu/native_backtrace: Reduced required backtrace size to 3 for 64-bit * periph/flashpage: Simplified test * unittests/tests-pktbuf: Generalized alignment * sys/architecture: Extended test for 64-bit --- tests/core/msg_queue_print/main.c | 4 ++-- tests/core/thread_zombie/main.c | 4 ++-- tests/cpu/native_backtrace/Makefile | 7 ++++++ tests/drivers/at86rf215/main.c | 2 +- tests/drivers/at86rf2xx/main.c | 2 +- tests/drivers/cc2420/main.c | 2 +- tests/drivers/mrf24j40/main.c | 2 +- tests/drivers/mtd_raw/main.c | 2 +- tests/drivers/sds011/main.c | 4 ++-- tests/drivers/soft_uart/main.c | 6 ++--- tests/net/gnrc_sixlowpan_frag_minfwd/Makefile | 2 ++ tests/net/gnrc_sixlowpan_frag_minfwd/main.c | 21 ++++++++++++----- tests/net/gnrc_sixlowpan_frag_sfr/Makefile | 2 ++ tests/net/gnrc_sixlowpan_frag_sfr/main.c | 20 +++++++++++----- tests/periph/flashpage/main.c | 23 ++++--------------- tests/periph/flashpage_unittest/main.c | 6 ++--- tests/periph/gpio/main.c | 4 ++-- tests/periph/timer/main.c | 4 ++-- tests/periph/uart/main.c | 2 +- tests/pkg/cayenne-lpp/main.c | 2 +- tests/pkg/lora-serialization/main.c | 2 +- tests/sys/architecture/Makefile | 4 ++++ tests/sys/cb_mux/main.c | 6 ++--- tests/sys/conn_can/main.c | 4 ++-- tests/sys/events/main.c | 11 +++++---- tests/sys/heap_cmd/main.c | 2 +- tests/sys/ps_schedstatistics/main.c | 6 ++--- tests/sys/pthread_cooperation/main.c | 6 ++--- tests/sys/pthread_tls/main.c | 22 +++++++++--------- tests/unittests/tests-pktbuf/tests-pktbuf.c | 16 +++++++------ 30 files changed, 111 insertions(+), 89 deletions(-) diff --git a/tests/core/msg_queue_print/main.c b/tests/core/msg_queue_print/main.c index 0a2523471b..f52ee7dede 100644 --- a/tests/core/msg_queue_print/main.c +++ b/tests/core/msg_queue_print/main.c @@ -35,9 +35,9 @@ int main(void) msg_init_queue(msg_queue, QUEUE_SIZE); msg_queue_print(); - for (int i = 0; i < QUEUE_SIZE; i++) { + for (uintptr_t i = 0; i < QUEUE_SIZE; i++) { messages[i].type = i; - messages[i].content.value = i; + messages[i].content.ptr = (void *) i; msg_send_to_self(&messages[i]); } diff --git a/tests/core/thread_zombie/main.c b/tests/core/thread_zombie/main.c index b2880fa0ff..47df0995dc 100644 --- a/tests/core/thread_zombie/main.c +++ b/tests/core/thread_zombie/main.c @@ -35,8 +35,8 @@ static char t4_stack[TEST_THREAD_STACKSIZE]; /* function for testing threads */ void *second_thread(void *arg) { - printf("Thread: %d is starting\n", (int)arg); - printf("Thread: %d calls zombify\n", (int)arg); + printf("Thread: %" PRIdPTR " is starting\n", (intptr_t)arg); + printf("Thread: %" PRIdPTR " calls zombify\n", (intptr_t)arg); thread_zombify(); puts("ERROR zombie runs again!"); return NULL; diff --git a/tests/cpu/native_backtrace/Makefile b/tests/cpu/native_backtrace/Makefile index 6310e24231..4555e942a1 100644 --- a/tests/cpu/native_backtrace/Makefile +++ b/tests/cpu/native_backtrace/Makefile @@ -4,4 +4,11 @@ USEMODULE += backtrace BOARD_WHITELIST := native +# Tests if native returns a backtrace of size three. +# The following function should be included in the backtrace: +# `main`/`main_trampoline`/ return to a user context function (e.g. `makecontext`) +# Depending on the implementation of the ucontext functions, the backtrace size +# may be longer, but this test only checks if it is at least three. +CFLAGS += -DBACKTRACE_SIZE=3 + include $(RIOTBASE)/Makefile.include diff --git a/tests/drivers/at86rf215/main.c b/tests/drivers/at86rf215/main.c index c91f43a0ac..7729433c28 100644 --- a/tests/drivers/at86rf215/main.c +++ b/tests/drivers/at86rf215/main.c @@ -191,7 +191,7 @@ int netdev_ieee802154_minimal_init_devs(netdev_event_cb_t cb) { at86rf215_t *at86rf215_subghz = NULL; at86rf215_t *at86rf215_24ghz = NULL; - printf("%d out of %d\n", i + 1, AT86RF215_NUM); + printf("%d out of %u\n", i + 1, (unsigned)AT86RF215_NUM); if (IS_USED(MODULE_AT86RF215_SUBGHZ)) { puts("Sub-GHz"); diff --git a/tests/drivers/at86rf2xx/main.c b/tests/drivers/at86rf2xx/main.c index a24251eab3..3b7685a121 100644 --- a/tests/drivers/at86rf2xx/main.c +++ b/tests/drivers/at86rf2xx/main.c @@ -73,7 +73,7 @@ int netdev_ieee802154_minimal_init_devs(netdev_event_cb_t cb) { puts("Initializing AT86RF2XX devices"); for (unsigned i = 0; i < AT86RF2XX_NUM; i++) { - printf("%d out of %d\n", i + 1, AT86RF2XX_NUM); + printf("%d out of %u\n", i + 1, (unsigned)AT86RF2XX_NUM); /* setup the specific driver */ at86rf2xx_setup(&at86rf2xx[i], &at86rf2xx_params[i], i); diff --git a/tests/drivers/cc2420/main.c b/tests/drivers/cc2420/main.c index 8ec9fcb014..6c87f76759 100644 --- a/tests/drivers/cc2420/main.c +++ b/tests/drivers/cc2420/main.c @@ -31,7 +31,7 @@ int netdev_ieee802154_minimal_init_devs(netdev_event_cb_t cb) { puts("Initializing CC2420 devices"); for (unsigned i = 0; i < CC2420_NUM; i++) { - printf("%d out of %d\n", i + 1, CC2420_NUM); + printf("%d out of %u\n", i + 1, (unsigned)CC2420_NUM); netdev_t *netdev = &cc2420[i].netdev.netdev; /* setup the specific driver */ diff --git a/tests/drivers/mrf24j40/main.c b/tests/drivers/mrf24j40/main.c index 9783083ceb..a6b5650faf 100644 --- a/tests/drivers/mrf24j40/main.c +++ b/tests/drivers/mrf24j40/main.c @@ -47,7 +47,7 @@ int netdev_ieee802154_minimal_init_devs(netdev_event_cb_t cb) { ieee802154_hal_test_init_devs(_reg_callback, &c); for (unsigned i = 0; i < MRF24J40_NUM; i++) { - printf("%d out of %d\n", i + 1, MRF24J40_NUM); + printf("%d out of %u\n", i + 1, (unsigned)MRF24J40_NUM); netdev_register(&mrf24j40_netdev[i].dev.netdev, NETDEV_MRF24J40, 0); netdev_ieee802154_submac_init(&mrf24j40_netdev[i]); diff --git a/tests/drivers/mtd_raw/main.c b/tests/drivers/mtd_raw/main.c index 1252f28e86..8a7a03873f 100644 --- a/tests/drivers/mtd_raw/main.c +++ b/tests/drivers/mtd_raw/main.c @@ -279,7 +279,7 @@ static void _print_info(mtd_dev_t *dev) static int cmd_info(int argc, char **argv) { if (argc < 2) { - printf("mtd devices: %d\n", MTD_NUMOF); + printf("mtd devices: %d\n", (unsigned)MTD_NUMOF); for (unsigned i = 0; i < MTD_NUMOF; ++i) { printf(" -=[ MTD_%d ]=-\n", i); diff --git a/tests/drivers/sds011/main.c b/tests/drivers/sds011/main.c index 78e5cbd76f..8817b42d51 100644 --- a/tests/drivers/sds011/main.c +++ b/tests/drivers/sds011/main.c @@ -76,7 +76,7 @@ static void _print_measurement(sds011_data_t *data) void measure_cb(sds011_data_t *data, void *ctx) { msg_t msg = { .content.value = (((uint32_t)data->pm_10) << 16 | data->pm_2_5) }; - kernel_pid_t target_pid = (int)ctx; + kernel_pid_t target_pid = (intptr_t)ctx; msg_send(&msg, target_pid); } @@ -194,7 +194,7 @@ int main(void) } } - sds011_register_callback(&dev, measure_cb, (void*)(int)thread_getpid()); + sds011_register_callback(&dev, measure_cb, (void*)(intptr_t)thread_getpid()); printf("switching to active reporting mode for %u measurements...\n", ACTIVE_REPORTING_TEST_CNT); diff --git a/tests/drivers/soft_uart/main.c b/tests/drivers/soft_uart/main.c index d5763a55ad..95a36e051e 100644 --- a/tests/drivers/soft_uart/main.c +++ b/tests/drivers/soft_uart/main.c @@ -72,7 +72,7 @@ static int parse_dev(char *arg) static void rx_cb(void *arg, uint8_t data) { - uart_t dev = (soft_uart_t)arg; + uart_t dev = (soft_uart_t)(intptr_t)arg; ringbuffer_add_one(&(ctx[dev].rx_buf), data); if (data == '\n' || ringbuffer_full(&(ctx[dev].rx_buf))) { @@ -139,7 +139,7 @@ static int cmd_init(int argc, char **argv) baud = strtol(argv[2], NULL, 0); /* initialize UART */ - res = soft_uart_init(dev, baud, rx_cb, (void *)dev); + res = soft_uart_init(dev, baud, rx_cb, (void *)(intptr_t)dev); if (res == UART_NOBAUD) { printf("Error: Given baudrate (%u) not possible\n", (unsigned int)baud); return 1; @@ -269,7 +269,7 @@ int main(void) "NOTE: all strings need to be '\\n' terminated!\n"); puts("\nUART INFO:"); - printf("Available devices: %i\n", SOFT_UART_NUMOF); + printf("Available devices: %u\n", (unsigned)SOFT_UART_NUMOF); /* initialize ringbuffers */ for (unsigned i = 0; i < SOFT_UART_NUMOF; i++) { diff --git a/tests/net/gnrc_sixlowpan_frag_minfwd/Makefile b/tests/net/gnrc_sixlowpan_frag_minfwd/Makefile index 961e8c010a..4026d0a91a 100644 --- a/tests/net/gnrc_sixlowpan_frag_minfwd/Makefile +++ b/tests/net/gnrc_sixlowpan_frag_minfwd/Makefile @@ -11,6 +11,8 @@ USEMODULE += netdev_test CFLAGS += -DTEST_SUITES +INCLUDES += -I$(RIOTBASE)/sys/net/gnrc/pktbuf_static/include + include $(RIOTBASE)/Makefile.include ifndef CONFIG_GNRC_IPV6_NIB_NO_RTR_SOL diff --git a/tests/net/gnrc_sixlowpan_frag_minfwd/main.c b/tests/net/gnrc_sixlowpan_frag_minfwd/main.c index dfe4908925..f65e518b48 100644 --- a/tests/net/gnrc_sixlowpan_frag_minfwd/main.c +++ b/tests/net/gnrc_sixlowpan_frag_minfwd/main.c @@ -41,6 +41,8 @@ #include "utlist.h" #include "xtimer.h" +#include "pktbuf_static.h" + #define SEND_PACKET_TIMEOUT (500U) #define LOC_L2 { _LL0, _LL1, _LL2, _LL3, _LL4, _LL5, _LL6, _LL7 } @@ -624,12 +626,19 @@ static void test_minfwd_forward__ENOMEM__netif_hdr_build_fail(void) gnrc_pktsnip_t *pkt, *frag, *filled_space; vrbe->super.arrival = xtimer_now_usec(); - TEST_ASSERT_NOT_NULL((filled_space = gnrc_pktbuf_add( - NULL, NULL, - /* 115U == 2 * sizeof(gnrc_pktsnip_t) + movement due to mark */ - CONFIG_GNRC_PKTBUF_SIZE - sizeof(_test_nth_frag) - 115U, - GNRC_NETTYPE_UNDEF - ))); + + size_t test_pkt_size = _align(sizeof(gnrc_pktsnip_t)) + _align(sizeof(_test_nth_frag)); + size_t marked_pkt_size = _align(sizeof(gnrc_pktsnip_t)) + _align(sizeof(sixlowpan_frag_n_t)) + + _align(sizeof(_test_nth_frag) - sizeof(sixlowpan_frag_n_t)); + + /* Calculate the maximum payload size to fill the buffer with the following three packets */ + size_t dummy_pkt_payload_size = CONFIG_GNRC_PKTBUF_SIZE - _align(sizeof(gnrc_pktsnip_t)) + - test_pkt_size - marked_pkt_size; + + TEST_ASSERT_NOT_NULL((filled_space = gnrc_pktbuf_add(NULL, NULL, + dummy_pkt_payload_size, + GNRC_NETTYPE_UNDEF))); + TEST_ASSERT_NOT_NULL((pkt = gnrc_pktbuf_add(NULL, _test_nth_frag, sizeof(_test_nth_frag), GNRC_NETTYPE_SIXLOWPAN))); diff --git a/tests/net/gnrc_sixlowpan_frag_sfr/Makefile b/tests/net/gnrc_sixlowpan_frag_sfr/Makefile index 5fe020e3d7..34b4c2146b 100644 --- a/tests/net/gnrc_sixlowpan_frag_sfr/Makefile +++ b/tests/net/gnrc_sixlowpan_frag_sfr/Makefile @@ -11,6 +11,8 @@ USEMODULE += netdev_test CFLAGS += -DTEST_SUITES +INCLUDES += -I$(RIOTBASE)/sys/net/gnrc/pktbuf_static/include + # microbit qemu failing currently TEST_ON_CI_BLACKLIST += microbit diff --git a/tests/net/gnrc_sixlowpan_frag_sfr/main.c b/tests/net/gnrc_sixlowpan_frag_sfr/main.c index c2e9504ad5..6310de3cd7 100644 --- a/tests/net/gnrc_sixlowpan_frag_sfr/main.c +++ b/tests/net/gnrc_sixlowpan_frag_sfr/main.c @@ -43,6 +43,8 @@ #include "utlist.h" #include "xtimer.h" +#include "pktbuf_static.h" + #define SEND_PACKET_TIMEOUT (500U) #define LOC_L2 { _LL0, _LL1, _LL2, _LL3, _LL4, _LL5, _LL6, _LL7 } @@ -540,12 +542,18 @@ static void test_sfr_forward__ENOMEM__netif_hdr_build_fail(void) ); gnrc_pktsnip_t *pkt, *frag, *filled_space; - TEST_ASSERT_NOT_NULL((filled_space = gnrc_pktbuf_add( - NULL, NULL, - /* 115U == 2 * sizeof(gnrc_pktsnip_t) + movement due to mark */ - CONFIG_GNRC_PKTBUF_SIZE - sizeof(_test_nth_frag) - 115U, - GNRC_NETTYPE_UNDEF - ))); + size_t test_pkt_size = _align(sizeof(gnrc_pktsnip_t)) + _align(sizeof(_test_nth_frag)); + size_t marked_pkt_size = _align(sizeof(gnrc_pktsnip_t)) + _align(sizeof(sixlowpan_frag_n_t)) + + _align(sizeof(_test_nth_frag) - sizeof(sixlowpan_frag_n_t)); + + /* Calculate the maximum payload size to fill the buffer with the following three packets */ + size_t dummy_pkt_payload_size = CONFIG_GNRC_PKTBUF_SIZE - _align(sizeof(gnrc_pktsnip_t)) + - test_pkt_size - marked_pkt_size; + + TEST_ASSERT_NOT_NULL((filled_space = gnrc_pktbuf_add(NULL, NULL, + dummy_pkt_payload_size, + GNRC_NETTYPE_UNDEF))); + TEST_ASSERT_NOT_NULL((pkt = gnrc_pktbuf_add(NULL, _test_nth_frag, sizeof(_test_nth_frag), GNRC_NETTYPE_SIXLOWPAN))); diff --git a/tests/periph/flashpage/main.c b/tests/periph/flashpage/main.c index 3bdc087fdd..4f80a653da 100644 --- a/tests/periph/flashpage/main.c +++ b/tests/periph/flashpage/main.c @@ -204,42 +204,29 @@ static int cmd_write(int argc, char **argv) } #endif -static uint32_t getaddr(const char *str) +static uintptr_t getaddr(const char *str) { - uint32_t addr = strtol(str, NULL, 16); + uintptr_t addr = (uintptr_t)strtol(str, NULL, 16); return addr; } static int cmd_write_raw(int argc, char **argv) { -#if (__SIZEOF_POINTER__ == 2) - uint16_t addr; -#else - uint32_t addr; -#endif + uintptr_t addr; if (argc < 3) { printf("usage: %s \n", argv[0]); return 1; } -#if (__SIZEOF_POINTER__ == 2) - addr = (uint16_t) getaddr(argv[1]); -#else addr = getaddr(argv[1]); -#endif /* try to align */ memcpy(raw_buf, argv[2], strlen(argv[2])); - flashpage_write((void*)addr, raw_buf, strlen(raw_buf)); -#if (__SIZEOF_POINTER__ == 2) - printf("wrote local data to flash address %#" PRIx16 " of len %" PRIuSIZE "\n", + flashpage_write((void*)(uintptr_t)addr, raw_buf, strlen(raw_buf)); + printf("wrote local data to flash address %#" PRIxPTR " of len %" PRIuSIZE "\n", addr, strlen(raw_buf)); -#else - printf("wrote local data to flash address %#" PRIx32 " of len %" PRIuSIZE "\n", - addr, strlen(raw_buf)); -#endif return 0; } diff --git a/tests/periph/flashpage_unittest/main.c b/tests/periph/flashpage_unittest/main.c index 6e3d231e12..da530a9e80 100644 --- a/tests/periph/flashpage_unittest/main.c +++ b/tests/periph/flashpage_unittest/main.c @@ -47,12 +47,12 @@ static void test_flashbase_addr(void) void *addr; addr = flashpage_addr(0); - TEST_ASSERT_EQUAL_INT((unsigned int)CPU_FLASH_BASE, (unsigned int)addr); + TEST_ASSERT_EQUAL_INT((unsigned int)CPU_FLASH_BASE, (uintptr_t)addr); addr = flashpage_addr(FLASHPAGE_NUMOF - 1); TEST_ASSERT_EQUAL_INT((long)CPU_FLASH_BASE + (((unsigned)FLASHPAGE_NUMOF - 1) * FLASHPAGE_SIZE), - (unsigned int)addr); + (uintptr_t)addr); addr = flashpage_addr(12); - TEST_ASSERT_EQUAL_INT((unsigned int)CPU_FLASH_BASE + (12 * FLASHPAGE_SIZE), (unsigned int)addr); + TEST_ASSERT_EQUAL_INT((unsigned int)CPU_FLASH_BASE + (12 * FLASHPAGE_SIZE), (uintptr_t)addr); } static void test_flashbase_page(void) diff --git a/tests/periph/gpio/main.c b/tests/periph/gpio/main.c index 22a78e00cf..d6e0cb6dd2 100644 --- a/tests/periph/gpio/main.c +++ b/tests/periph/gpio/main.c @@ -33,7 +33,7 @@ #ifdef MODULE_PERIPH_GPIO_IRQ static void cb(void *arg) { - printf("INT: external interrupt from pin %i\n", (int)arg); + printf("INT: external interrupt from pin %" PRIiPTR "\n", (intptr_t)arg); } #endif @@ -145,7 +145,7 @@ static int init_int(int argc, char **argv) } } - if (gpio_init_int(GPIO_PIN(po, pi), mode, flank, cb, (void *)pi) < 0) { + if (gpio_init_int(GPIO_PIN(po, pi), mode, flank, cb, (void *)(intptr_t)pi) < 0) { printf("error: init_int of GPIO_PIN(%i, %i) failed\n", po, pi); return 1; } diff --git a/tests/periph/timer/main.c b/tests/periph/timer/main.c index 8f2a1626b6..132677dc90 100644 --- a/tests/periph/timer/main.c +++ b/tests/periph/timer/main.c @@ -59,7 +59,7 @@ static unsigned args[TIMER_CHANNEL_NUMOF]; static void cb(void *arg, int chan) { timeouts[chan] = sw_count; - args[chan] = (unsigned)arg + chan; + args[chan] = (uintptr_t)arg + chan; fired++; } @@ -104,7 +104,7 @@ static int test_timer(unsigned num, uint32_t timer_freq) printf(" - Calling timer_init(%u, %" PRIu32 ")\n ", num, timer_freq); /* initialize and halt timer */ - if (timer_init(TIMER_DEV(num), timer_freq, cb, (void *)(COOKIE * num)) != 0) { + if (timer_init(TIMER_DEV(num), timer_freq, cb, (void *)(uintptr_t)(COOKIE * num)) != 0) { printf("ERROR: timer_init() failed\n\n"); return 0; } diff --git a/tests/periph/uart/main.c b/tests/periph/uart/main.c index 132f508ea4..7f9e76e04e 100644 --- a/tests/periph/uart/main.c +++ b/tests/periph/uart/main.c @@ -238,7 +238,7 @@ static int cmd_init(int argc, char **argv) baud = strtol(argv[2], NULL, 0); /* initialize UART */ - res = uart_init(UART_DEV(dev), baud, rx_cb, (void *)dev); + res = uart_init(UART_DEV(dev), baud, rx_cb, (void *)(intptr_t)dev); if (res == UART_NOBAUD) { printf("Error: Given baudrate (%u) not possible\n", (unsigned int)baud); return 1; diff --git a/tests/pkg/cayenne-lpp/main.c b/tests/pkg/cayenne-lpp/main.c index e0f92a9c1e..ed12968be5 100644 --- a/tests/pkg/cayenne-lpp/main.c +++ b/tests/pkg/cayenne-lpp/main.c @@ -24,7 +24,7 @@ #include "cayenne_lpp.h" #define TEST_BUFFER1 { 0x03, 0x67, 0x01, 0x10, 0x05, 0x67, 0x00, 0xff } -#if defined(BOARD_NATIVE) +#if defined(BOARD_NATIVE) && !(__SIZEOF_POINTER__ == 8) #define TEST_BUFFER2 { 0x01, 0x67, 0xFF, 0xD8, \ 0x06, 0x71, 0x04, 0xD1, 0xFB, 0x2F, 0x00, 0x00 } #else diff --git a/tests/pkg/lora-serialization/main.c b/tests/pkg/lora-serialization/main.c index 7986df8a0d..cd1e4112a8 100644 --- a/tests/pkg/lora-serialization/main.c +++ b/tests/pkg/lora-serialization/main.c @@ -23,7 +23,7 @@ #include #include "lora_serialization.h" -#if defined(BOARD_NATIVE) +#if defined(BOARD_NATIVE) && !(__SIZEOF_POINTER__ == 8) #define TEST_01_EXPECTED { 0x1f, 0x4c, 0x0e, 0x27 } #define TEST_02_EXPECTED { 0x65, 0xa6, 0xfa, 0xfd, \ 0x6a, 0x24, 0x04, 0x09, \ diff --git a/tests/sys/architecture/Makefile b/tests/sys/architecture/Makefile index 7a7d9d76b5..f2fa71be65 100644 --- a/tests/sys/architecture/Makefile +++ b/tests/sys/architecture/Makefile @@ -3,6 +3,10 @@ include ../Makefile.sys_common include $(RIOTBASE)/Makefile.include +ifneq (,$(filter arch_64bit,$(FEATURES_USED))) + CFLAGS += -DCORRECT_WORD_BITS=64 +endif + ifneq (,$(filter arch_32bit,$(FEATURES_USED))) CFLAGS += -DCORRECT_WORD_BITS=32 endif diff --git a/tests/sys/cb_mux/main.c b/tests/sys/cb_mux/main.c index 872834ed7b..be81ab75ce 100644 --- a/tests/sys/cb_mux/main.c +++ b/tests/sys/cb_mux/main.c @@ -53,7 +53,7 @@ int main(void) for (num = 0; num < 5; num++) { entries[num].cb = cb; - entries[num].arg = (void *)num; + entries[num].arg = (void *)(uintptr_t)num; entries[num].cbid = num; } @@ -114,7 +114,7 @@ int main(void) while (num < 5) { cb_mux_add(&cb_mux_head, &(entries[num])); - printf("Added entry %i\n", num); + printf("Added entry %u\n", (unsigned)num); num = cb_mux_find_free_id(cb_mux_head); } @@ -125,7 +125,7 @@ int main(void) for (num = 0; num < 5; num++) { if ((uintptr_t)entries[num].info & (1 << ITER_TEST)) { - printf("Entry %i was updated correctly\n", num); + printf("Entry %u was updated correctly\n", (unsigned)num); } } diff --git a/tests/sys/conn_can/main.c b/tests/sys/conn_can/main.c index 637755be5d..246b603119 100644 --- a/tests/sys/conn_can/main.c +++ b/tests/sys/conn_can/main.c @@ -592,7 +592,7 @@ static int _can_handler(int argc, char **argv) static void *_receive_thread(void *args) { - int thread_nb = (int)args; + int thread_nb = (intptr_t)args; struct can_frame frame; msg_t msg, msg_queue[RECEIVE_THREAD_MSG_QUEUE_SIZE]; @@ -729,7 +729,7 @@ static const shell_command_t _commands[] = { int main(void) { - for (int i = 0; i < RCV_THREAD_NUMOF; i++) { + for (intptr_t i = 0; i < RCV_THREAD_NUMOF; i++) { receive_pid[i] = thread_create(thread_stack[i], THREAD_STACKSIZE, THREAD_PRIORITY_MAIN - 1, THREAD_CREATE_STACKTEST, _receive_thread, diff --git a/tests/sys/events/main.c b/tests/sys/events/main.c index ee5c038f7e..ed7f4442bb 100644 --- a/tests/sys/events/main.c +++ b/tests/sys/events/main.c @@ -62,7 +62,7 @@ static void callback(event_t *arg) order++; expect(order == 4); expect(arg == &event); - printf("triggered 0x%08x\n", (unsigned)arg); + printf("triggered 0x%08" PRIxPTR "\n", (uintptr_t)arg); } typedef struct { @@ -94,7 +94,8 @@ static void timed_callback(void *arg) uint32_t now = xtimer_now_usec(); #endif expect((now - before >= 100000LU)); - printf("triggered timed callback with arg 0x%08x after %" PRIu32 "us\n", (unsigned)arg, now - before); + printf("triggered timed callback with arg 0x%08" PRIxPTR " after %" PRIu32 "us\n", + (uintptr_t)arg, now - before); puts("[SUCCESS]"); } @@ -176,12 +177,12 @@ int main(void) /* test posting different kind of events in order to a statically * initialized queue */ event_queue_t queue = EVENT_QUEUE_INIT; - printf("posting 0x%08x\n", (unsigned)&event); + printf("posting 0x%08" PRIxPTR "\n", (uintptr_t)&event); event_post(&queue, &event); - printf("posting 0x%08x\n", (unsigned)&event2); + printf("posting 0x%08" PRIxPTR "\n", (uintptr_t)&event2); event_post(&queue, &event2); - printf("canceling 0x%08x\n", (unsigned)&event2); + printf("canceling 0x%08" PRIxPTR "\n", (uintptr_t)&event2); event_cancel(&queue, &event2); puts("posting custom event"); diff --git a/tests/sys/heap_cmd/main.c b/tests/sys/heap_cmd/main.c index 8fb24e4520..49faf78142 100644 --- a/tests/sys/heap_cmd/main.c +++ b/tests/sys/heap_cmd/main.c @@ -41,7 +41,7 @@ static int free_cmd(int argc, char **argv) return 1; } - unsigned int p = strtoul(argv[1], NULL, 16); + uintptr_t p = strtoul(argv[1], NULL, 16); void *ptr = (void *)p; printf("freeing %p\n", ptr); free(ptr); diff --git a/tests/sys/ps_schedstatistics/main.c b/tests/sys/ps_schedstatistics/main.c index a4990c8aef..308c891d4d 100644 --- a/tests/sys/ps_schedstatistics/main.c +++ b/tests/sys/ps_schedstatistics/main.c @@ -36,9 +36,9 @@ static kernel_pid_t pids[NB_THREADS]; static void *_thread_fn(void *arg) { - int next = ((int)arg + 1) % NB_THREADS; + int next = ((uintptr_t)arg + 1) % NB_THREADS; - printf("Creating thread #%d, next=%d\n", (int)arg, next); + printf("Creating thread #%" PRIuPTR ", next=%d\n", (uintptr_t)arg, next); while (1) { msg_t m1, m2; @@ -59,7 +59,7 @@ int main(void) { test_utils_interactive_sync(); - for (unsigned i = 0; i < NB_THREADS; ++i) { + for (uintptr_t i = 0; i < NB_THREADS; ++i) { pids[i] = thread_create(stacks[i], sizeof(stacks[i]), THREAD_PRIORITY_MAIN - 1, THREAD_CREATE_STACKTEST, diff --git a/tests/sys/pthread_cooperation/main.c b/tests/sys/pthread_cooperation/main.c index b12357de16..1c0098d943 100644 --- a/tests/sys/pthread_cooperation/main.c +++ b/tests/sys/pthread_cooperation/main.c @@ -32,7 +32,7 @@ volatile uint32_t storage = 1; void *run(void *parameter) { - int arg = (int) parameter; + int arg = (intptr_t) parameter; printf("My arg: %d\n", arg); int err = pthread_mutex_lock(&mtx); @@ -56,8 +56,8 @@ int main(void) pthread_attr_init(&th_attr); pthread_mutex_init(&mtx, NULL); - for (int i = 0; i < NUM_THREADS; ++i) { - printf("Creating thread with arg %d\n", (i + 1)); + for (intptr_t i = 0; i < NUM_THREADS; ++i) { + printf("Creating thread with arg %" PRIdPTR "\n", (i + 1)); pthread_create(&ths[i], &th_attr, run, (void *)(i + 1)); } diff --git a/tests/sys/pthread_tls/main.c b/tests/sys/pthread_tls/main.c index 2c1f59be99..c45e692b6e 100644 --- a/tests/sys/pthread_tls/main.c +++ b/tests/sys/pthread_tls/main.c @@ -45,8 +45,8 @@ void *run(void *parameter) aTLS_values[i]++; } - printf("pick deliberate storage (key[3]:%d) and change the value\n", - (int)aKeys[3]); + printf("pick deliberate storage (key[3]:%" PRIuPTR ") and change the value\n", + (uintptr_t)aKeys[3]); void *val = pthread_getspecific(aKeys[3]); *((int *)val) = 42; @@ -55,11 +55,11 @@ void *run(void *parameter) for (int i = 0; i < NUMBER_OF_TLS; ++i) { void *val = pthread_getspecific(aKeys[i]); int x = *(int *)val; - printf("key[%d]: %d, val: %d\n",i, (int)aKeys[i], x); + printf("key[%d]: %" PRIuPTR ", val: %d\n", i, (uintptr_t)aKeys[i], x); } - printf("\n -= TEST 2 - delete deliberate key (key[5]:%d) =-\n", - (int)aKeys[5]); + printf("\n -= TEST 2 - delete deliberate key (key[5]:%" PRIuPTR ") =-\n", + (uintptr_t)aKeys[5]); pthread_key_delete(aKeys[5]); puts("show tls values:"); @@ -69,7 +69,7 @@ void *run(void *parameter) if (val != NULL) { int x = *(int *)val; - printf("key[%d]: %d, val: %d\n",i, (int)aKeys[i], x); + printf("key[%d]: %" PRIuPTR ", val: %d\n", i, (uintptr_t)aKeys[i], x); } } @@ -80,7 +80,7 @@ void *run(void *parameter) pthread_key_create(&new_key, NULL); pthread_setspecific(new_key, &new_val); - printf("added new tls, key: %d, val: %d\n", (int)new_key, new_val); + printf("added new tls, key: %" PRIuPTR ", val: %d\n", (uintptr_t)new_key, new_val); printf("show tls values:\n"); for (int i = 0; i < NUMBER_OF_TLS; ++i) { @@ -88,7 +88,7 @@ void *run(void *parameter) if (val != NULL) { int x = *(int *)val; - printf("key[%d]: %d, val: %d\n",i, (int)aKeys[i], x); + printf("key[%d]: %" PRIuPTR ", val: %d\n", i, (uintptr_t)aKeys[i], x); } } @@ -106,7 +106,7 @@ void *run(void *parameter) if (val != NULL) { int x = *(int *)val; - printf("key[%d]: %d, val: %d\n",i, (int)aKeys[i], x); + printf("key[%d]: %" PRIuPTR ", val: %d\n", i, (uintptr_t)aKeys[i], x); } } @@ -119,13 +119,13 @@ void *run(void *parameter) puts("-= TEST 6 - add key and delete without a tls =-"); pthread_key_create(&new_key, NULL); - printf("created key: %d\n", (int)new_key); + printf("created key: %" PRIuPTR "\n", (uintptr_t)new_key); printf("try to delete returns: %d\n", pthread_key_delete(new_key)); puts(""); puts("-= TEST 7 - add key without tls =-"); pthread_key_create(&new_key, NULL); - printf("created key: %d\n", (int)new_key); + printf("created key: %" PRIuPTR "\n", (uintptr_t)new_key); void* test_7_val = pthread_getspecific(new_key); printf("test_7_val: %p\n", test_7_val); diff --git a/tests/unittests/tests-pktbuf/tests-pktbuf.c b/tests/unittests/tests-pktbuf/tests-pktbuf.c index f1abee38d4..a78fd16c84 100644 --- a/tests/unittests/tests-pktbuf/tests-pktbuf.c +++ b/tests/unittests/tests-pktbuf/tests-pktbuf.c @@ -25,6 +25,8 @@ #include "unittests-constants.h" #include "tests-pktbuf.h" +#define ALIGNMENT_SIZE (2 * sizeof(uintptr_t)) + typedef struct __attribute__((packed)) { uint8_t u8; uint16_t u16; @@ -250,14 +252,14 @@ static void test_pktbuf_add__packed_struct(void) #ifndef MODULE_GNRC_PKTBUF_MALLOC /* alignment-handling left to malloc, so no certainty here */ static void test_pktbuf_add__unaligned_in_aligned_hole(void) { - gnrc_pktsnip_t *pkt1 = gnrc_pktbuf_add(NULL, NULL, 8, GNRC_NETTYPE_TEST); - gnrc_pktsnip_t *pkt2 = gnrc_pktbuf_add(NULL, NULL, 8, GNRC_NETTYPE_TEST); - gnrc_pktsnip_t *pkt3 = gnrc_pktbuf_add(NULL, NULL, 8, GNRC_NETTYPE_TEST); + gnrc_pktsnip_t *pkt1 = gnrc_pktbuf_add(NULL, NULL, ALIGNMENT_SIZE, GNRC_NETTYPE_TEST); + gnrc_pktsnip_t *pkt2 = gnrc_pktbuf_add(NULL, NULL, ALIGNMENT_SIZE, GNRC_NETTYPE_TEST); + gnrc_pktsnip_t *pkt3 = gnrc_pktbuf_add(NULL, NULL, ALIGNMENT_SIZE, GNRC_NETTYPE_TEST); gnrc_pktsnip_t *pkt4; void *tmp_data2 = pkt2->data; gnrc_pktbuf_release(pkt2); - pkt4 = gnrc_pktbuf_add(NULL, TEST_STRING12, 9, GNRC_NETTYPE_TEST); + pkt4 = gnrc_pktbuf_add(NULL, TEST_STRING64, ALIGNMENT_SIZE + 1, GNRC_NETTYPE_TEST); TEST_ASSERT(tmp_data2 != pkt4->data); @@ -820,14 +822,14 @@ static void test_pktbuf_start_write__pkt_users_2(void) static void test_pktbuf_reverse_snips__too_full(void) { gnrc_pktsnip_t *pkt, *pkt_next, *pkt_huge; - const size_t pkt_huge_size = CONFIG_GNRC_PKTBUF_SIZE - (3 * 8) - + const size_t pkt_huge_size = CONFIG_GNRC_PKTBUF_SIZE - (3 * ALIGNMENT_SIZE) - (3 * sizeof(gnrc_pktsnip_t)) - 4; - pkt_next = gnrc_pktbuf_add(NULL, TEST_STRING8, 8, GNRC_NETTYPE_TEST); + pkt_next = gnrc_pktbuf_add(NULL, TEST_STRING16, ALIGNMENT_SIZE, GNRC_NETTYPE_TEST); TEST_ASSERT_NOT_NULL(pkt_next); /* hold to enforce duplication */ gnrc_pktbuf_hold(pkt_next, 1); - pkt = gnrc_pktbuf_add(pkt_next, TEST_STRING8, 8, GNRC_NETTYPE_TEST); + pkt = gnrc_pktbuf_add(pkt_next, TEST_STRING16, 8, GNRC_NETTYPE_TEST); TEST_ASSERT_NOT_NULL(pkt); /* filling up rest of packet buffer */ pkt_huge = gnrc_pktbuf_add(NULL, NULL, pkt_huge_size, GNRC_NETTYPE_UNDEF);