Skip to content

Commit 64c787f

Browse files
committed
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
1 parent 0b925c2 commit 64c787f

File tree

30 files changed

+111
-89
lines changed

30 files changed

+111
-89
lines changed

tests/core/msg_queue_print/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ int main(void)
3535
msg_init_queue(msg_queue, QUEUE_SIZE);
3636
msg_queue_print();
3737

38-
for (int i = 0; i < QUEUE_SIZE; i++) {
38+
for (uintptr_t i = 0; i < QUEUE_SIZE; i++) {
3939
messages[i].type = i;
40-
messages[i].content.value = i;
40+
messages[i].content.ptr = (void *) i;
4141
msg_send_to_self(&messages[i]);
4242
}
4343

tests/core/thread_zombie/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ static char t4_stack[TEST_THREAD_STACKSIZE];
3535
/* function for testing threads */
3636
void *second_thread(void *arg)
3737
{
38-
printf("Thread: %d is starting\n", (int)arg);
39-
printf("Thread: %d calls zombify\n", (int)arg);
38+
printf("Thread: %" PRIdPTR " is starting\n", (intptr_t)arg);
39+
printf("Thread: %" PRIdPTR " calls zombify\n", (intptr_t)arg);
4040
thread_zombify();
4141
puts("ERROR zombie runs again!");
4242
return NULL;

tests/cpu/native_backtrace/Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,11 @@ USEMODULE += backtrace
44

55
BOARD_WHITELIST := native
66

7+
# Tests if native returns a backtrace of size three.
8+
# The following function should be included in the backtrace:
9+
# `main`/`main_trampoline`/ return to a user context function (e.g. `makecontext`)
10+
# Depending on the implementation of the ucontext functions, the backtrace size
11+
# may be longer, but this test only checks if it is at least three.
12+
CFLAGS += -DBACKTRACE_SIZE=3
13+
714
include $(RIOTBASE)/Makefile.include

tests/drivers/at86rf215/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ int netdev_ieee802154_minimal_init_devs(netdev_event_cb_t cb) {
191191
at86rf215_t *at86rf215_subghz = NULL;
192192
at86rf215_t *at86rf215_24ghz = NULL;
193193

194-
printf("%d out of %d\n", i + 1, AT86RF215_NUM);
194+
printf("%d out of %u\n", i + 1, (unsigned)AT86RF215_NUM);
195195

196196
if (IS_USED(MODULE_AT86RF215_SUBGHZ)) {
197197
puts("Sub-GHz");

tests/drivers/at86rf2xx/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ int netdev_ieee802154_minimal_init_devs(netdev_event_cb_t cb) {
7373
puts("Initializing AT86RF2XX devices");
7474

7575
for (unsigned i = 0; i < AT86RF2XX_NUM; i++) {
76-
printf("%d out of %d\n", i + 1, AT86RF2XX_NUM);
76+
printf("%d out of %u\n", i + 1, (unsigned)AT86RF2XX_NUM);
7777
/* setup the specific driver */
7878
at86rf2xx_setup(&at86rf2xx[i], &at86rf2xx_params[i], i);
7979

tests/drivers/cc2420/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int netdev_ieee802154_minimal_init_devs(netdev_event_cb_t cb) {
3131
puts("Initializing CC2420 devices");
3232

3333
for (unsigned i = 0; i < CC2420_NUM; i++) {
34-
printf("%d out of %d\n", i + 1, CC2420_NUM);
34+
printf("%d out of %u\n", i + 1, (unsigned)CC2420_NUM);
3535
netdev_t *netdev = &cc2420[i].netdev.netdev;
3636

3737
/* setup the specific driver */

tests/drivers/mrf24j40/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int netdev_ieee802154_minimal_init_devs(netdev_event_cb_t cb) {
4747
ieee802154_hal_test_init_devs(_reg_callback, &c);
4848

4949
for (unsigned i = 0; i < MRF24J40_NUM; i++) {
50-
printf("%d out of %d\n", i + 1, MRF24J40_NUM);
50+
printf("%d out of %u\n", i + 1, (unsigned)MRF24J40_NUM);
5151
netdev_register(&mrf24j40_netdev[i].dev.netdev, NETDEV_MRF24J40, 0);
5252
netdev_ieee802154_submac_init(&mrf24j40_netdev[i]);
5353

tests/drivers/mtd_raw/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ static void _print_info(mtd_dev_t *dev)
279279
static int cmd_info(int argc, char **argv)
280280
{
281281
if (argc < 2) {
282-
printf("mtd devices: %d\n", MTD_NUMOF);
282+
printf("mtd devices: %d\n", (unsigned)MTD_NUMOF);
283283

284284
for (unsigned i = 0; i < MTD_NUMOF; ++i) {
285285
printf(" -=[ MTD_%d ]=-\n", i);

tests/drivers/sds011/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static void _print_measurement(sds011_data_t *data)
7676
void measure_cb(sds011_data_t *data, void *ctx)
7777
{
7878
msg_t msg = { .content.value = (((uint32_t)data->pm_10) << 16 | data->pm_2_5) };
79-
kernel_pid_t target_pid = (int)ctx;
79+
kernel_pid_t target_pid = (intptr_t)ctx;
8080
msg_send(&msg, target_pid);
8181
}
8282

@@ -194,7 +194,7 @@ int main(void)
194194
}
195195
}
196196

197-
sds011_register_callback(&dev, measure_cb, (void*)(int)thread_getpid());
197+
sds011_register_callback(&dev, measure_cb, (void*)(intptr_t)thread_getpid());
198198

199199
printf("switching to active reporting mode for %u measurements...\n",
200200
ACTIVE_REPORTING_TEST_CNT);

tests/drivers/soft_uart/main.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static int parse_dev(char *arg)
7272

7373
static void rx_cb(void *arg, uint8_t data)
7474
{
75-
uart_t dev = (soft_uart_t)arg;
75+
uart_t dev = (soft_uart_t)(intptr_t)arg;
7676

7777
ringbuffer_add_one(&(ctx[dev].rx_buf), data);
7878
if (data == '\n' || ringbuffer_full(&(ctx[dev].rx_buf))) {
@@ -139,7 +139,7 @@ static int cmd_init(int argc, char **argv)
139139
baud = strtol(argv[2], NULL, 0);
140140

141141
/* initialize UART */
142-
res = soft_uart_init(dev, baud, rx_cb, (void *)dev);
142+
res = soft_uart_init(dev, baud, rx_cb, (void *)(intptr_t)dev);
143143
if (res == UART_NOBAUD) {
144144
printf("Error: Given baudrate (%u) not possible\n", (unsigned int)baud);
145145
return 1;
@@ -269,7 +269,7 @@ int main(void)
269269
"NOTE: all strings need to be '\\n' terminated!\n");
270270

271271
puts("\nUART INFO:");
272-
printf("Available devices: %i\n", SOFT_UART_NUMOF);
272+
printf("Available devices: %u\n", (unsigned)SOFT_UART_NUMOF);
273273

274274
/* initialize ringbuffers */
275275
for (unsigned i = 0; i < SOFT_UART_NUMOF; i++) {

tests/net/gnrc_sixlowpan_frag_minfwd/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ USEMODULE += netdev_test
1111

1212
CFLAGS += -DTEST_SUITES
1313

14+
INCLUDES += -I$(RIOTBASE)/sys/net/gnrc/pktbuf_static/include
15+
1416
include $(RIOTBASE)/Makefile.include
1517

1618
ifndef CONFIG_GNRC_IPV6_NIB_NO_RTR_SOL

tests/net/gnrc_sixlowpan_frag_minfwd/main.c

+15-6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include "utlist.h"
4242
#include "xtimer.h"
4343

44+
#include "pktbuf_static.h"
45+
4446
#define SEND_PACKET_TIMEOUT (500U)
4547

4648
#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)
624626
gnrc_pktsnip_t *pkt, *frag, *filled_space;
625627

626628
vrbe->super.arrival = xtimer_now_usec();
627-
TEST_ASSERT_NOT_NULL((filled_space = gnrc_pktbuf_add(
628-
NULL, NULL,
629-
/* 115U == 2 * sizeof(gnrc_pktsnip_t) + movement due to mark */
630-
CONFIG_GNRC_PKTBUF_SIZE - sizeof(_test_nth_frag) - 115U,
631-
GNRC_NETTYPE_UNDEF
632-
)));
629+
630+
size_t test_pkt_size = _align(sizeof(gnrc_pktsnip_t)) + _align(sizeof(_test_nth_frag));
631+
size_t marked_pkt_size = _align(sizeof(gnrc_pktsnip_t)) + _align(sizeof(sixlowpan_frag_n_t))
632+
+ _align(sizeof(_test_nth_frag) - sizeof(sixlowpan_frag_n_t));
633+
634+
/* Calculate the maximum payload size to fill the buffer with the following three packets */
635+
size_t dummy_pkt_payload_size = CONFIG_GNRC_PKTBUF_SIZE - _align(sizeof(gnrc_pktsnip_t))
636+
- test_pkt_size - marked_pkt_size;
637+
638+
TEST_ASSERT_NOT_NULL((filled_space = gnrc_pktbuf_add(NULL, NULL,
639+
dummy_pkt_payload_size,
640+
GNRC_NETTYPE_UNDEF)));
641+
633642
TEST_ASSERT_NOT_NULL((pkt = gnrc_pktbuf_add(NULL, _test_nth_frag,
634643
sizeof(_test_nth_frag),
635644
GNRC_NETTYPE_SIXLOWPAN)));

tests/net/gnrc_sixlowpan_frag_sfr/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ USEMODULE += netdev_test
1111

1212
CFLAGS += -DTEST_SUITES
1313

14+
INCLUDES += -I$(RIOTBASE)/sys/net/gnrc/pktbuf_static/include
15+
1416
# microbit qemu failing currently
1517
TEST_ON_CI_BLACKLIST += microbit
1618

tests/net/gnrc_sixlowpan_frag_sfr/main.c

+14-6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
#include "utlist.h"
4444
#include "xtimer.h"
4545

46+
#include "pktbuf_static.h"
47+
4648
#define SEND_PACKET_TIMEOUT (500U)
4749

4850
#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)
540542
);
541543
gnrc_pktsnip_t *pkt, *frag, *filled_space;
542544

543-
TEST_ASSERT_NOT_NULL((filled_space = gnrc_pktbuf_add(
544-
NULL, NULL,
545-
/* 115U == 2 * sizeof(gnrc_pktsnip_t) + movement due to mark */
546-
CONFIG_GNRC_PKTBUF_SIZE - sizeof(_test_nth_frag) - 115U,
547-
GNRC_NETTYPE_UNDEF
548-
)));
545+
size_t test_pkt_size = _align(sizeof(gnrc_pktsnip_t)) + _align(sizeof(_test_nth_frag));
546+
size_t marked_pkt_size = _align(sizeof(gnrc_pktsnip_t)) + _align(sizeof(sixlowpan_frag_n_t))
547+
+ _align(sizeof(_test_nth_frag) - sizeof(sixlowpan_frag_n_t));
548+
549+
/* Calculate the maximum payload size to fill the buffer with the following three packets */
550+
size_t dummy_pkt_payload_size = CONFIG_GNRC_PKTBUF_SIZE - _align(sizeof(gnrc_pktsnip_t))
551+
- test_pkt_size - marked_pkt_size;
552+
553+
TEST_ASSERT_NOT_NULL((filled_space = gnrc_pktbuf_add(NULL, NULL,
554+
dummy_pkt_payload_size,
555+
GNRC_NETTYPE_UNDEF)));
556+
549557
TEST_ASSERT_NOT_NULL((pkt = gnrc_pktbuf_add(NULL, _test_nth_frag,
550558
sizeof(_test_nth_frag),
551559
GNRC_NETTYPE_SIXLOWPAN)));

tests/periph/flashpage/main.c

+5-18
Original file line numberDiff line numberDiff line change
@@ -204,42 +204,29 @@ static int cmd_write(int argc, char **argv)
204204
}
205205
#endif
206206

207-
static uint32_t getaddr(const char *str)
207+
static uintptr_t getaddr(const char *str)
208208
{
209-
uint32_t addr = strtol(str, NULL, 16);
209+
uintptr_t addr = (uintptr_t)strtol(str, NULL, 16);
210210

211211
return addr;
212212
}
213213

214214
static int cmd_write_raw(int argc, char **argv)
215215
{
216-
#if (__SIZEOF_POINTER__ == 2)
217-
uint16_t addr;
218-
#else
219-
uint32_t addr;
220-
#endif
216+
uintptr_t addr;
221217

222218
if (argc < 3) {
223219
printf("usage: %s <addr> <data>\n", argv[0]);
224220
return 1;
225221
}
226222

227-
#if (__SIZEOF_POINTER__ == 2)
228-
addr = (uint16_t) getaddr(argv[1]);
229-
#else
230223
addr = getaddr(argv[1]);
231-
#endif
232224
/* try to align */
233225
memcpy(raw_buf, argv[2], strlen(argv[2]));
234226

235-
flashpage_write((void*)addr, raw_buf, strlen(raw_buf));
236-
#if (__SIZEOF_POINTER__ == 2)
237-
printf("wrote local data to flash address %#" PRIx16 " of len %" PRIuSIZE "\n",
227+
flashpage_write((void*)(uintptr_t)addr, raw_buf, strlen(raw_buf));
228+
printf("wrote local data to flash address %#" PRIxPTR " of len %" PRIuSIZE "\n",
238229
addr, strlen(raw_buf));
239-
#else
240-
printf("wrote local data to flash address %#" PRIx32 " of len %" PRIuSIZE "\n",
241-
addr, strlen(raw_buf));
242-
#endif
243230
return 0;
244231
}
245232

tests/periph/flashpage_unittest/main.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ static void test_flashbase_addr(void)
4747
void *addr;
4848

4949
addr = flashpage_addr(0);
50-
TEST_ASSERT_EQUAL_INT((unsigned int)CPU_FLASH_BASE, (unsigned int)addr);
50+
TEST_ASSERT_EQUAL_INT((unsigned int)CPU_FLASH_BASE, (uintptr_t)addr);
5151
addr = flashpage_addr(FLASHPAGE_NUMOF - 1);
5252
TEST_ASSERT_EQUAL_INT((long)CPU_FLASH_BASE + (((unsigned)FLASHPAGE_NUMOF - 1) * FLASHPAGE_SIZE),
53-
(unsigned int)addr);
53+
(uintptr_t)addr);
5454
addr = flashpage_addr(12);
55-
TEST_ASSERT_EQUAL_INT((unsigned int)CPU_FLASH_BASE + (12 * FLASHPAGE_SIZE), (unsigned int)addr);
55+
TEST_ASSERT_EQUAL_INT((unsigned int)CPU_FLASH_BASE + (12 * FLASHPAGE_SIZE), (uintptr_t)addr);
5656
}
5757

5858
static void test_flashbase_page(void)

tests/periph/gpio/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#ifdef MODULE_PERIPH_GPIO_IRQ
3434
static void cb(void *arg)
3535
{
36-
printf("INT: external interrupt from pin %i\n", (int)arg);
36+
printf("INT: external interrupt from pin %" PRIiPTR "\n", (intptr_t)arg);
3737
}
3838
#endif
3939

@@ -145,7 +145,7 @@ static int init_int(int argc, char **argv)
145145
}
146146
}
147147

148-
if (gpio_init_int(GPIO_PIN(po, pi), mode, flank, cb, (void *)pi) < 0) {
148+
if (gpio_init_int(GPIO_PIN(po, pi), mode, flank, cb, (void *)(intptr_t)pi) < 0) {
149149
printf("error: init_int of GPIO_PIN(%i, %i) failed\n", po, pi);
150150
return 1;
151151
}

tests/periph/timer/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static unsigned args[TIMER_CHANNEL_NUMOF];
5959
static void cb(void *arg, int chan)
6060
{
6161
timeouts[chan] = sw_count;
62-
args[chan] = (unsigned)arg + chan;
62+
args[chan] = (uintptr_t)arg + chan;
6363
fired++;
6464
}
6565

@@ -104,7 +104,7 @@ static int test_timer(unsigned num, uint32_t timer_freq)
104104
printf(" - Calling timer_init(%u, %" PRIu32 ")\n ",
105105
num, timer_freq);
106106
/* initialize and halt timer */
107-
if (timer_init(TIMER_DEV(num), timer_freq, cb, (void *)(COOKIE * num)) != 0) {
107+
if (timer_init(TIMER_DEV(num), timer_freq, cb, (void *)(uintptr_t)(COOKIE * num)) != 0) {
108108
printf("ERROR: timer_init() failed\n\n");
109109
return 0;
110110
}

tests/periph/uart/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ static int cmd_init(int argc, char **argv)
238238
baud = strtol(argv[2], NULL, 0);
239239

240240
/* initialize UART */
241-
res = uart_init(UART_DEV(dev), baud, rx_cb, (void *)dev);
241+
res = uart_init(UART_DEV(dev), baud, rx_cb, (void *)(intptr_t)dev);
242242
if (res == UART_NOBAUD) {
243243
printf("Error: Given baudrate (%u) not possible\n", (unsigned int)baud);
244244
return 1;

tests/pkg/cayenne-lpp/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "cayenne_lpp.h"
2525

2626
#define TEST_BUFFER1 { 0x03, 0x67, 0x01, 0x10, 0x05, 0x67, 0x00, 0xff }
27-
#if defined(BOARD_NATIVE)
27+
#if defined(BOARD_NATIVE) && !(__SIZEOF_POINTER__ == 8)
2828
#define TEST_BUFFER2 { 0x01, 0x67, 0xFF, 0xD8, \
2929
0x06, 0x71, 0x04, 0xD1, 0xFB, 0x2F, 0x00, 0x00 }
3030
#else

tests/pkg/lora-serialization/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <stdio.h>
2424
#include "lora_serialization.h"
2525

26-
#if defined(BOARD_NATIVE)
26+
#if defined(BOARD_NATIVE) && !(__SIZEOF_POINTER__ == 8)
2727
#define TEST_01_EXPECTED { 0x1f, 0x4c, 0x0e, 0x27 }
2828
#define TEST_02_EXPECTED { 0x65, 0xa6, 0xfa, 0xfd, \
2929
0x6a, 0x24, 0x04, 0x09, \

tests/sys/architecture/Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ include ../Makefile.sys_common
33

44
include $(RIOTBASE)/Makefile.include
55

6+
ifneq (,$(filter arch_64bit,$(FEATURES_USED)))
7+
CFLAGS += -DCORRECT_WORD_BITS=64
8+
endif
9+
610
ifneq (,$(filter arch_32bit,$(FEATURES_USED)))
711
CFLAGS += -DCORRECT_WORD_BITS=32
812
endif

tests/sys/cb_mux/main.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ int main(void)
5353

5454
for (num = 0; num < 5; num++) {
5555
entries[num].cb = cb;
56-
entries[num].arg = (void *)num;
56+
entries[num].arg = (void *)(uintptr_t)num;
5757
entries[num].cbid = num;
5858
}
5959

@@ -114,7 +114,7 @@ int main(void)
114114
while (num < 5) {
115115
cb_mux_add(&cb_mux_head, &(entries[num]));
116116

117-
printf("Added entry %i\n", num);
117+
printf("Added entry %u\n", (unsigned)num);
118118

119119
num = cb_mux_find_free_id(cb_mux_head);
120120
}
@@ -125,7 +125,7 @@ int main(void)
125125

126126
for (num = 0; num < 5; num++) {
127127
if ((uintptr_t)entries[num].info & (1 << ITER_TEST)) {
128-
printf("Entry %i was updated correctly\n", num);
128+
printf("Entry %u was updated correctly\n", (unsigned)num);
129129
}
130130
}
131131

tests/sys/conn_can/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ static int _can_handler(int argc, char **argv)
592592

593593
static void *_receive_thread(void *args)
594594
{
595-
int thread_nb = (int)args;
595+
int thread_nb = (intptr_t)args;
596596
struct can_frame frame;
597597
msg_t msg, msg_queue[RECEIVE_THREAD_MSG_QUEUE_SIZE];
598598

@@ -729,7 +729,7 @@ static const shell_command_t _commands[] = {
729729

730730
int main(void)
731731
{
732-
for (int i = 0; i < RCV_THREAD_NUMOF; i++) {
732+
for (intptr_t i = 0; i < RCV_THREAD_NUMOF; i++) {
733733
receive_pid[i] = thread_create(thread_stack[i], THREAD_STACKSIZE,
734734
THREAD_PRIORITY_MAIN - 1,
735735
THREAD_CREATE_STACKTEST, _receive_thread,

0 commit comments

Comments
 (0)