tests: kernel: Test endian-specific buffer convert and copy functions
Test endian-specific buffer convert and copy functions. Signed-off-by: Joakim Andersson <joerchan@gmail.com>
This commit is contained in:
parent
6a3f885408
commit
7faafda9e7
1 changed files with 116 additions and 0 deletions
|
|
@ -588,6 +588,122 @@ ZTEST(byteorder, test_sys_uint64_to_array)
|
|||
#undef VAL
|
||||
}
|
||||
|
||||
ZTEST(byteorder, test_sys_le_to_cpu)
|
||||
{
|
||||
uint8_t val[9] = { 0x87, 0x95, 0xa5, 0xb4, 0xc3, 0xd2, 0xe1, 0xf0, 0xab };
|
||||
uint8_t exp[9] = {
|
||||
COND_CODE_1(CONFIG_LITTLE_ENDIAN,
|
||||
(0x87, 0x95, 0xa5, 0xb4, 0xc3, 0xd2, 0xe1, 0xf0, 0xab),
|
||||
(0xab, 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x95, 0x87))
|
||||
};
|
||||
|
||||
sys_le_to_cpu(val, sizeof(val));
|
||||
|
||||
zassert_mem_equal(val, exp, sizeof(exp), "sys_le_to_cpu() failed");
|
||||
}
|
||||
|
||||
ZTEST(byteorder, test_sys_cpu_to_le)
|
||||
{
|
||||
uint8_t val[9] = { 0x87, 0x96, 0xa5, 0xb4, 0xc3, 0xd2, 0xe1, 0xf0, 0xab };
|
||||
uint8_t exp[9] = {
|
||||
COND_CODE_1(CONFIG_LITTLE_ENDIAN,
|
||||
(0x87, 0x96, 0xa5, 0xb4, 0xc3, 0xd2, 0xe1, 0xf0, 0xab),
|
||||
(0xab, 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87))
|
||||
};
|
||||
|
||||
sys_cpu_to_le(val, sizeof(val));
|
||||
|
||||
zassert_mem_equal(val, exp, sizeof(exp), "sys_cpu_to_le() failed");
|
||||
}
|
||||
|
||||
ZTEST(byteorder, test_sys_be_to_cpu)
|
||||
{
|
||||
uint8_t val[9] = { 0x87, 0x97, 0xa5, 0xb4, 0xc3, 0xd2, 0xe1, 0xf0, 0xab };
|
||||
uint8_t exp[9] = {
|
||||
COND_CODE_1(CONFIG_LITTLE_ENDIAN,
|
||||
(0xab, 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x97, 0x87),
|
||||
(0x87, 0x97, 0xa5, 0xb4, 0xc3, 0xd2, 0xe1, 0xf0, 0xab))
|
||||
};
|
||||
|
||||
sys_be_to_cpu(val, sizeof(val));
|
||||
|
||||
zassert_mem_equal(val, exp, sizeof(exp), "sys_be_to_cpu() failed");
|
||||
}
|
||||
|
||||
ZTEST(byteorder, test_sys_cpu_to_be)
|
||||
{
|
||||
uint8_t val[9] = { 0x87, 0x98, 0xa5, 0xb4, 0xc3, 0xd2, 0xe1, 0xf0, 0xab };
|
||||
uint8_t exp[9] = {
|
||||
COND_CODE_1(CONFIG_LITTLE_ENDIAN,
|
||||
(0xab, 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x98, 0x87),
|
||||
(0x87, 0x98, 0xa5, 0xb4, 0xc3, 0xd2, 0xe1, 0xf0, 0xab))
|
||||
};
|
||||
|
||||
sys_cpu_to_be(val, sizeof(val));
|
||||
|
||||
zassert_mem_equal(val, exp, sizeof(exp), "sys_cpu_to_be() failed");
|
||||
}
|
||||
|
||||
ZTEST(byteorder, test_sys_put_le)
|
||||
{
|
||||
uint8_t host[9] = { 0x87, 0x12, 0xa5, 0xb4, 0xc3, 0xd2, 0xe1, 0xf0, 0xba };
|
||||
uint8_t prot[9] = { 0 };
|
||||
uint8_t exp[9] = {
|
||||
COND_CODE_1(CONFIG_LITTLE_ENDIAN,
|
||||
(0x87, 0x12, 0xa5, 0xb4, 0xc3, 0xd2, 0xe1, 0xf0, 0xba),
|
||||
(0xba, 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x12, 0x87))
|
||||
};
|
||||
|
||||
sys_put_le(prot, host, sizeof(prot));
|
||||
|
||||
zassert_mem_equal(prot, exp, sizeof(exp), "sys_put_le() failed");
|
||||
}
|
||||
|
||||
ZTEST(byteorder, test_sys_put_be)
|
||||
{
|
||||
uint8_t host[9] = { 0x87, 0x13, 0xa5, 0xb4, 0xc3, 0xd2, 0xe1, 0xf0, 0xba };
|
||||
uint8_t prot[9] = { 0 };
|
||||
uint8_t exp[9] = {
|
||||
COND_CODE_1(CONFIG_LITTLE_ENDIAN,
|
||||
(0xba, 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x13, 0x87),
|
||||
(0x87, 0x13, 0xa5, 0xb4, 0xc3, 0xd2, 0xe1, 0xf0, 0xba))
|
||||
};
|
||||
|
||||
sys_put_be(prot, host, sizeof(prot));
|
||||
|
||||
zassert_mem_equal(prot, exp, sizeof(exp), "sys_put_be() failed");
|
||||
}
|
||||
|
||||
ZTEST(byteorder, test_sys_get_le)
|
||||
{
|
||||
uint8_t prot[9] = { 0x87, 0x14, 0xa5, 0xb4, 0xc3, 0xd2, 0xe1, 0xf0, 0xba };
|
||||
uint8_t host[9] = { 0 };
|
||||
uint8_t exp[9] = {
|
||||
COND_CODE_1(CONFIG_LITTLE_ENDIAN,
|
||||
(0x87, 0x14, 0xa5, 0xb4, 0xc3, 0xd2, 0xe1, 0xf0, 0xba),
|
||||
(0xba, 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x14, 0x87))
|
||||
};
|
||||
|
||||
sys_get_le(host, prot, sizeof(host));
|
||||
|
||||
zassert_mem_equal(host, exp, sizeof(exp), "sys_get_le() failed");
|
||||
}
|
||||
|
||||
ZTEST(byteorder, test_sys_get_be)
|
||||
{
|
||||
uint8_t prot[9] = { 0x87, 0x15, 0xa5, 0xb4, 0xc3, 0xd2, 0xe1, 0xf0, 0xba };
|
||||
uint8_t host[9] = { 0 };
|
||||
uint8_t exp[9] = {
|
||||
COND_CODE_1(CONFIG_LITTLE_ENDIAN,
|
||||
(0xba, 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x15, 0x87),
|
||||
(0x87, 0x15, 0xa5, 0xb4, 0xc3, 0xd2, 0xe1, 0xf0, 0xba))
|
||||
};
|
||||
|
||||
sys_get_be(host, prot, sizeof(host));
|
||||
|
||||
zassert_mem_equal(host, exp, sizeof(exp), "sys_get_be() failed");
|
||||
}
|
||||
|
||||
extern void *common_setup(void);
|
||||
ZTEST_SUITE(byteorder, NULL, common_setup, NULL, NULL, NULL);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue