Skip to content

Commit 27522de

Browse files
committed
tests: mcumgr: Improve compatibility with 64-bit platforms
Use %zu format specifier for size_t type to ensure compatibility with both 32-bit and 64-bit platforms. Signed-off-by: Tim Pambor <[email protected]>
1 parent 2d72d86 commit 27522de

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

tests/subsys/mgmt/mcumgr/os_mgmt_echo/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ ZTEST(os_mgmt_echo, test_echo)
5656
smp_dummy_disable();
5757

5858
zassert_equal(sizeof(expected_response), nb->len,
59-
"Expected to receive %d bytes but got %d\n", sizeof(expected_response),
59+
"Expected to receive %zu bytes but got %d\n", sizeof(expected_response),
6060
nb->len);
6161

6262
zassert_mem_equal(expected_response, nb->data, nb->len,

tests/subsys/mgmt/mcumgr/os_mgmt_info/src/build_date.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ ZTEST(os_mgmt_info_build_date, test_info_build_date_1_build_date)
129129
zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element\n");
130130

131131
zassert_equal(strlen(test_date_time), output.len,
132-
"Expected to receive %d bytes but got %d\n",
132+
"Expected to receive %zu bytes but got %zu\n",
133133
strlen(test_date_time), output.len);
134134

135135
/* Check left and right sides of date which should match */
@@ -208,7 +208,7 @@ ZTEST(os_mgmt_info_build_date, test_info_build_date_2_all)
208208
/* Check with board revision */
209209
zassert_equal((strlen(test_date_time) + strlen(response_all_board_revision_left) +
210210
strlen(response_all_board_revision_right)), output.len,
211-
"Expected to receive %d bytes but got %d\n",
211+
"Expected to receive %zu bytes but got %zu\n",
212212
(strlen(test_date_time) + strlen(response_all_board_revision_left) +
213213
strlen(response_all_board_revision_right)), output.len);
214214

@@ -224,7 +224,7 @@ ZTEST(os_mgmt_info_build_date, test_info_build_date_2_all)
224224
/* Check without board revision */
225225
zassert_equal((strlen(test_date_time) + strlen(response_all_left) +
226226
strlen(response_all_right)), output.len,
227-
"Expected to receive %d bytes but got %d\n",
227+
"Expected to receive %zu bytes but got %zu\n",
228228
(strlen(test_date_time) + strlen(response_all_left) +
229229
strlen(response_all_right)), output.len);
230230

tests/subsys/mgmt/mcumgr/os_mgmt_info/src/limited.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ ZTEST(os_mgmt_info_limited, test_info_1_kernel_name)
8989
zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element\n");
9090

9191
zassert_equal((sizeof(response_kernel_name) - 1), output.len,
92-
"Expected to receive %d bytes but got %d\n",
92+
"Expected to receive %zu bytes but got %zu\n",
9393
(sizeof(response_kernel_name) - 1), output.len);
9494

9595
zassert_mem_equal(response_kernel_name, output.value, output.len,
@@ -160,7 +160,7 @@ ZTEST(os_mgmt_info_limited, test_info_2_all)
160160

161161
zassert_true(ok, "Expected decode to be successful\n");
162162
zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element\n");
163-
zassert_equal(output.len, 0, "Expected to receive 0 bytes but got %d\n", output.len);
163+
zassert_equal(output.len, 0, "Expected to receive 0 bytes but got %zu\n", output.len);
164164
zassert_equal(rc, MGMT_ERR_EMSGSIZE, "Expected to receive EMSGSIZE error but got %d\n",
165165
rc);
166166
}

tests/subsys/mgmt/mcumgr/os_mgmt_info/src/main.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ ZTEST(os_mgmt_info, test_info_1)
247247
smp_dummy_disable();
248248

249249
zassert_equal(sizeof(expected_response), nb->len,
250-
"Expected to receive %d bytes but got %d\n", sizeof(expected_response),
250+
"Expected to receive %zu bytes but got %d\n", sizeof(expected_response),
251251
nb->len);
252252

253253
zassert_mem_equal(expected_response, nb->data, nb->len,
@@ -285,7 +285,7 @@ ZTEST(os_mgmt_info, test_info_1)
285285
smp_dummy_disable();
286286

287287
zassert_equal(sizeof(expected_response), nb->len,
288-
"Expected to receive %d bytes but got %d\n", sizeof(expected_response),
288+
"Expected to receive %zu bytes but got %d\n", sizeof(expected_response),
289289
nb->len);
290290

291291
zassert_mem_equal(expected_response, nb->data, nb->len,
@@ -346,7 +346,7 @@ ZTEST(os_mgmt_info, test_info_2_kernel_name)
346346
zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element\n");
347347

348348
zassert_equal((sizeof(response_kernel_name) - 1), output.len,
349-
"Expected to receive %d bytes but got %d\n",
349+
"Expected to receive %zu bytes but got %zu\n",
350350
(sizeof(response_kernel_name) - 1), output.len);
351351

352352
zassert_mem_equal(response_kernel_name, output.value, output.len,
@@ -407,7 +407,7 @@ ZTEST(os_mgmt_info, test_info_3_node_name)
407407
zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element\n");
408408

409409
zassert_equal((sizeof(response_node_name) - 1), output.len,
410-
"Expected to receive %d bytes but got %d\n",
410+
"Expected to receive %zu bytes but got %zu\n",
411411
(sizeof(response_node_name) - 1), output.len);
412412

413413
zassert_mem_equal(response_node_name, output.value, output.len,
@@ -469,7 +469,7 @@ ZTEST(os_mgmt_info, test_info_4_kernel_release)
469469
zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element\n");
470470

471471
zassert_equal((sizeof(response_kernel_release) - 1), output.len,
472-
"Expected to receive %d bytes but got %d\n",
472+
"Expected to receive %zu bytes but got %zu\n",
473473
(sizeof(response_kernel_release) - 1), output.len);
474474

475475
zassert_mem_equal(response_kernel_release, output.value, output.len,
@@ -531,7 +531,7 @@ ZTEST(os_mgmt_info, test_info_5_kernel_version)
531531
zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element\n");
532532

533533
zassert_equal((sizeof(response_kernel_version) - 1), output.len,
534-
"Expected to receive %d bytes but got %d\n",
534+
"Expected to receive %zu bytes but got %zu\n",
535535
(sizeof(response_kernel_version) - 1), output.len);
536536

537537
zassert_mem_equal(response_kernel_version, output.value, output.len,
@@ -592,7 +592,7 @@ ZTEST(os_mgmt_info, test_info_6_machine)
592592
zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element\n");
593593

594594
zassert_equal((sizeof(response_machine) - 1), output.len,
595-
"Expected to receive %d bytes but got %d\n", (sizeof(response_machine) - 1),
595+
"Expected to receive %zu bytes but got %zu\n", (sizeof(response_machine) - 1),
596596
output.len);
597597

598598
zassert_mem_equal(response_machine, output.value, output.len,
@@ -653,7 +653,7 @@ ZTEST(os_mgmt_info, test_info_7_processor)
653653
zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element\n");
654654

655655
zassert_equal((sizeof(response_processor) - 1), output.len,
656-
"Expected to receive %d bytes but got %d\n", (sizeof(response_processor) - 1),
656+
"Expected to receive %zu bytes but got %zu\n", (sizeof(response_processor) - 1),
657657
output.len);
658658

659659
zassert_mem_equal(response_processor, output.value, output.len,
@@ -716,15 +716,15 @@ ZTEST(os_mgmt_info, test_info_8_platform)
716716
if (sizeof(CONFIG_BOARD_REVISION) > 1) {
717717
/* Check with board revision */
718718
zassert_equal((sizeof(response_board_revision) - 1), output.len,
719-
"Expected to receive %d bytes but got %d\n",
719+
"Expected to receive %zu bytes but got %zu\n",
720720
(sizeof(response_board_revision) - 1), output.len);
721721

722722
zassert_mem_equal(response_board_revision, output.value, output.len,
723723
"Expected received data mismatch");
724724
} else {
725725
/* Check without board revision */
726726
zassert_equal((sizeof(response_board) - 1), output.len,
727-
"Expected to receive %d bytes but got %d\n",
727+
"Expected to receive %zu bytes but got %zu\n",
728728
(sizeof(response_board) - 1), output.len);
729729

730730
zassert_mem_equal(response_board, output.value, output.len,
@@ -786,7 +786,7 @@ ZTEST(os_mgmt_info, test_info_9_os)
786786
zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element\n");
787787

788788
zassert_equal((sizeof(response_os) - 1), output.len,
789-
"Expected to receive %d bytes but got %d\n", (sizeof(response_os) - 1),
789+
"Expected to receive %zu bytes but got %zu\n", (sizeof(response_os) - 1),
790790
output.len);
791791

792792
zassert_mem_equal(response_os, output.value, output.len,
@@ -849,15 +849,15 @@ ZTEST(os_mgmt_info, test_info_10_all)
849849
if (sizeof(CONFIG_BOARD_REVISION) > 1) {
850850
/* Check with board revision */
851851
zassert_equal((sizeof(response_all_board_revision) - 1), output.len,
852-
"Expected to receive %d bytes but got %d\n",
852+
"Expected to receive %zu bytes but got %zu\n",
853853
(sizeof(response_all_board_revision) - 1), output.len);
854854

855855
zassert_mem_equal(response_all_board_revision, output.value, output.len,
856856
"Expected received data mismatch");
857857
} else {
858858
/* Check without board revision */
859859
zassert_equal((sizeof(response_all) - 1), output.len,
860-
"Expected to receive %d bytes but got %d\n",
860+
"Expected to receive %zu bytes but got %zu\n",
861861
(sizeof(response_all) - 1), output.len);
862862

863863
zassert_mem_equal(response_all, output.value, output.len,
@@ -924,7 +924,7 @@ ZTEST(os_mgmt_info, test_info_11_multi_1)
924924
/* Construct expected response to be compared against */
925925
sprintf(buffer, "%s %s %s", response_kernel_release, response_processor, response_os);
926926

927-
zassert_equal(strlen(buffer), output.len, "Expected to receive %d bytes but got %d\n",
927+
zassert_equal(strlen(buffer), output.len, "Expected to receive %zu bytes but got %zu\n",
928928
strlen(buffer), output.len);
929929

930930
zassert_mem_equal(buffer, output.value, output.len, "Expected received data mismatch");
@@ -991,7 +991,7 @@ ZTEST(os_mgmt_info, test_info_12_multi_2)
991991
*/
992992
sprintf(buffer, "%s %s", response_node_name, response_kernel_version);
993993

994-
zassert_equal(strlen(buffer), output.len, "Expected to receive %d bytes but got %d\n",
994+
zassert_equal(strlen(buffer), output.len, "Expected to receive %zu bytes but got %zu\n",
995995
strlen(buffer), output.len);
996996

997997
zassert_mem_equal(buffer, output.value, output.len, "Expected received data mismatch");
@@ -1064,7 +1064,7 @@ ZTEST(os_mgmt_info, test_info_13_invalid_1)
10641064

10651065
zassert_true(ok, "Expected decode to be successful\n");
10661066
zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element\n");
1067-
zassert_equal(output.len, 0, "Expected to receive 0 bytes but got %d\n", output.len);
1067+
zassert_equal(output.len, 0, "Expected to receive 0 bytes but got %zu\n", output.len);
10681068
zassert_equal(rc, MGMT_ERR_EINVAL, "Expected to receive EINVAL error but got %d\n", rc);
10691069
}
10701070

@@ -1135,7 +1135,7 @@ ZTEST(os_mgmt_info, test_info_14_invalid_2)
11351135

11361136
zassert_true(ok, "Expected decode to be successful\n");
11371137
zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element\n");
1138-
zassert_equal(output.len, 0, "Expected to receive 0 bytes but got %d\n", output.len);
1138+
zassert_equal(output.len, 0, "Expected to receive 0 bytes but got %zu\n", output.len);
11391139
zassert_equal(rc, MGMT_ERR_EINVAL, "Expected to receive EINVAL error but got %d\n", rc);
11401140
}
11411141

@@ -1207,7 +1207,7 @@ ZTEST(os_mgmt_info_custom_os, test_info_os_custom)
12071207
zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element\n");
12081208

12091209
zassert_equal((sizeof(response_os_custom) - 1), output.len,
1210-
"Expected to receive %d bytes but got %d\n",
1210+
"Expected to receive %zu bytes but got %zu\n",
12111211
(sizeof(response_os_custom) - 1), output.len);
12121212

12131213
zassert_mem_equal(response_os_custom, output.value, output.len,
@@ -1268,7 +1268,7 @@ ZTEST(os_mgmt_info_custom_os_disabled, test_info_os_custom_disabled)
12681268
zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element\n");
12691269

12701270
zassert_equal((sizeof(response_os) - 1), output.len,
1271-
"Expected to receive %d bytes but got %d\n",
1271+
"Expected to receive %zu bytes but got %zu\n",
12721272
(sizeof(response_os) - 1), output.len);
12731273

12741274
zassert_mem_equal(response_os, output.value, output.len,
@@ -1341,7 +1341,7 @@ ZTEST(os_mgmt_info_custom_cmd, test_info_cmd_custom)
13411341
zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element\n");
13421342

13431343
zassert_equal((sizeof(response_custom_cmd) - 1), output.len,
1344-
"Expected to receive %d bytes but got %d\n",
1344+
"Expected to receive %zu bytes but got %zu\n",
13451345
(sizeof(response_custom_cmd) - 1), output.len);
13461346

13471347
zassert_mem_equal(response_custom_cmd, output.value, output.len,
@@ -1412,7 +1412,7 @@ ZTEST(os_mgmt_info_custom_cmd_disabled, test_info_cmd_custom_disabled)
14121412
zassert_true(ok, "Expected decode to be successful\n");
14131413
zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element\n");
14141414

1415-
zassert_equal(output.len, 0, "Expected to receive 0 bytes but got %d\n", output.len);
1415+
zassert_equal(output.len, 0, "Expected to receive 0 bytes but got %zu\n", output.len);
14161416

14171417
zassert_equal(rc, MGMT_ERR_EINVAL, "Expected to receive EINVAL error but got %d\n", rc);
14181418
}
@@ -1481,7 +1481,7 @@ ZTEST(os_mgmt_info_custom_cmd_disabled_verify, test_info_cmd_custom_disabled)
14811481
zassert_true(ok, "Expected decode to be successful\n");
14821482
zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element\n");
14831483

1484-
zassert_equal(output.len, 0, "Expected to receive 0 bytes but got %d\n", output.len);
1484+
zassert_equal(output.len, 0, "Expected to receive 0 bytes but got %zu\n", output.len);
14851485

14861486
zassert_equal(rc, MGMT_ERR_EINVAL, "Expected to receive EINVAL error but got %d\n", rc);
14871487

0 commit comments

Comments
 (0)