Skip to content

Commit a7df77c

Browse files
yonschnashif
authored andcommitted
tests: byteorder: Add tests for sys_uint*_to_array macros
Add tests for sys_uint*_to_array macros to the byteorder suite. Signed-off-by: Yonatan Schachter <[email protected]>
1 parent 111b181 commit a7df77c

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

tests/kernel/common/src/byteorder.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,69 @@ ZTEST(byteorder, test_sys_put_le64)
456456
zassert_mem_equal(tmp, buf, sizeof(uint64_t), "sys_put_le64() failed");
457457
}
458458

459+
/**
460+
* @brief Test sys_uint16_to_array() functionality
461+
*
462+
* @details Test if sys_uint16_to_array() correctly handles endianness.
463+
*
464+
* @see sys_uint16_to_array()
465+
*/
466+
ZTEST(byteorder, test_sys_uint16_to_array)
467+
{
468+
#define VAL 0xf0e1
469+
uint8_t tmp[sizeof(uint16_t)] = sys_uint16_to_array(VAL);
470+
uint8_t buf[] = {
471+
COND_CODE_1(CONFIG_LITTLE_ENDIAN,
472+
(0xe1, 0xf0),
473+
(0xf0, 0xe1))
474+
};
475+
476+
zassert_mem_equal(tmp, buf, sizeof(uint16_t), "sys_uint16_to_array() failed");
477+
#undef VAL
478+
}
479+
480+
/**
481+
* @brief Test sys_uint32_to_array() functionality
482+
*
483+
* @details Test if sys_uint32_to_array() correctly handles endianness.
484+
*
485+
* @see sys_uint32_to_array()
486+
*/
487+
ZTEST(byteorder, test_sys_uint32_to_array)
488+
{
489+
#define VAL 0xf0e1d2c3
490+
uint8_t tmp[sizeof(uint32_t)] = sys_uint32_to_array(VAL);
491+
uint8_t buf[] = {
492+
COND_CODE_1(CONFIG_LITTLE_ENDIAN,
493+
(0xc3, 0xd2, 0xe1, 0xf0),
494+
(0xf0, 0xe1, 0xd2, 0xc3))
495+
};
496+
497+
zassert_mem_equal(tmp, buf, sizeof(uint32_t), "sys_uint32_to_array() failed");
498+
#undef VAL
499+
}
500+
501+
/**
502+
* @brief Test sys_uint64_to_array() functionality
503+
*
504+
* @details Test if sys_uint64_to_array() correctly handles endianness.
505+
*
506+
* @see sys_uint64_to_array()
507+
*/
508+
ZTEST(byteorder, test_sys_uint64_to_array)
509+
{
510+
#define VAL 0xf0e1d2c3b4a59687
511+
uint8_t tmp[sizeof(uint64_t)] = sys_uint64_to_array(VAL);
512+
uint8_t buf[] = {
513+
COND_CODE_1(CONFIG_LITTLE_ENDIAN,
514+
(0x87, 0x96, 0xa5, 0xb4, 0xc3, 0xd2, 0xe1, 0xf0),
515+
(0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87))
516+
};
517+
518+
zassert_mem_equal(tmp, buf, sizeof(uint64_t), "sys_uint64_to_array() failed");
519+
#undef VAL
520+
}
521+
459522
extern void *common_setup(void);
460523
ZTEST_SUITE(byteorder, NULL, common_setup, NULL, NULL, NULL);
461524

0 commit comments

Comments
 (0)