MCPcopy Create free account
hub / github.com/F-Stack/f-stack / test_macros

Function test_macros

dpdk/app/test/test_common.c:24–79  ·  view source on GitHub ↗

this is really a sanity check */

Source from the content-addressed store, hash-verified

22
23/* this is really a sanity check */
24static int
25test_macros(int __rte_unused unused_parm)
26{
27#define SMALLER 0x1000U
28#define BIGGER 0x2000U
29#define PTR_DIFF BIGGER - SMALLER
30
31 uintptr_t unused = 0;
32 unsigned int smaller = SMALLER, bigger = BIGGER;
33 uint32_t arr[3];
34
35 RTE_SET_USED(unused);
36
37 RTE_SWAP(smaller, bigger);
38 RTE_TEST_ASSERT(smaller == BIGGER && bigger == SMALLER,
39 "RTE_SWAP");
40 RTE_TEST_ASSERT_EQUAL((uintptr_t)RTE_PTR_ADD(SMALLER, PTR_DIFF), BIGGER,
41 "RTE_PTR_ADD");
42 RTE_TEST_ASSERT_EQUAL((uintptr_t)RTE_PTR_SUB(BIGGER, PTR_DIFF), SMALLER,
43 "RTE_PTR_SUB");
44 RTE_TEST_ASSERT_EQUAL(RTE_PTR_DIFF(BIGGER, SMALLER), PTR_DIFF,
45 "RTE_PTR_DIFF");
46 RTE_TEST_ASSERT_EQUAL(RTE_MAX(SMALLER, BIGGER), BIGGER,
47 "RTE_MAX");
48 RTE_TEST_ASSERT_EQUAL(RTE_MIN(SMALLER, BIGGER), SMALLER,
49 "RTE_MIN");
50
51 RTE_TEST_ASSERT_EQUAL(RTE_PTR_ADD(arr + 1, sizeof(arr[0])), &arr[2],
52 "RTE_PTR_ADD(expr, x)");
53 RTE_TEST_ASSERT_EQUAL(RTE_PTR_SUB(arr + 1, sizeof(arr[0])), &arr[0],
54 "RTE_PTR_SUB(expr, x)");
55 RTE_TEST_ASSERT_EQUAL(RTE_PTR_ALIGN_FLOOR(arr + 2, 4), &arr[2],
56 "RTE_PTR_ALIGN_FLOOR(expr, x)");
57 RTE_TEST_ASSERT_EQUAL(RTE_PTR_ALIGN_CEIL(arr + 2, 4), &arr[2],
58 "RTE_PTR_ALIGN_CEIL(expr, x)");
59 RTE_TEST_ASSERT_EQUAL(RTE_PTR_ALIGN(arr + 2, 4), &arr[2],
60 "RTE_PTR_ALIGN(expr, x)");
61
62 RTE_TEST_ASSERT_EQUAL(
63 RTE_PTR_ALIGN_FLOOR(RTE_PTR_ADD(&arr[1], 1), 4), &arr[1],
64 "RTE_PTR_ALIGN_FLOOR(x < y/2, y)");
65 RTE_TEST_ASSERT_EQUAL(
66 RTE_PTR_ALIGN_FLOOR(RTE_PTR_ADD(&arr[1], 3), 4), &arr[1],
67 "RTE_PTR_ALIGN_FLOOR(x > y/2, y)");
68 RTE_TEST_ASSERT_EQUAL(
69 RTE_PTR_ALIGN_CEIL(RTE_PTR_ADD(&arr[1], 3), 4), &arr[2],
70 "RTE_PTR_ALIGN_CEIL(x < y/2, y)");
71 RTE_TEST_ASSERT_EQUAL(
72 RTE_PTR_ALIGN_CEIL(RTE_PTR_ADD(&arr[1], 1), 4), &arr[2],
73 "RTE_PTR_ALIGN_CEIL(x > y/2, y)");
74
75 RTE_TEST_ASSERT(strncmp(RTE_STR(test), "test", sizeof("test")) == 0,
76 "RTE_STR");
77
78 return 0;
79}
80
81static int

Callers 1

test_commonFunction · 0.85

Calls 1

strncmpFunction · 0.85

Tested by

no test coverage detected