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

Function test_align

dpdk/app/test/test_common.c:132–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130}
131
132static int
133test_align(void)
134{
135#define FAIL_ALIGN(x, i, p)\
136 {printf(x "() test failed: %u %u\n", i, p);\
137 return -1;}
138#define FAIL_ALIGN64(x, j, q)\
139 {printf(x "() test failed: %"PRIu64" %"PRIu64"\n", j, q);\
140 return -1; }
141#define ERROR_FLOOR(res, i, pow) \
142 (res % pow) || /* check if not aligned */ \
143 ((res / pow) != (i / pow)) /* check if correct alignment */
144#define ERROR_CEIL(res, i, pow) \
145 (res % pow) || /* check if not aligned */ \
146 ((i % pow) == 0 ? /* check if ceiling is invoked */ \
147 val / pow != i / pow : /* if aligned */ \
148 val / pow != (i / pow) + 1) /* if not aligned, hence +1 */
149
150 uint32_t i, p, val;
151 uint64_t j, q;
152
153 for (i = 1, p = 1; i <= MAX_NUM; i ++) {
154 if (rte_align32pow2(i) != p)
155 FAIL_ALIGN("rte_align32pow2", i, p);
156 if (i == p)
157 p <<= 1;
158 }
159
160 for (i = 1, p = 1; i <= MAX_NUM; i++) {
161 if (rte_align32prevpow2(i) != p)
162 FAIL_ALIGN("rte_align32prevpow2", i, p);
163 if (rte_is_power_of_2(i + 1))
164 p = i + 1;
165 }
166
167 for (j = 1, q = 1; j <= MAX_NUM ; j++) {
168 if (rte_align64pow2(j) != q)
169 FAIL_ALIGN64("rte_align64pow2", j, q);
170 if (j == q)
171 q <<= 1;
172 }
173
174 for (j = 1, q = 1; j <= MAX_NUM ; j++) {
175 if (rte_align64prevpow2(j) != q)
176 FAIL_ALIGN64("rte_align64prevpow2", j, q);
177 if (rte_is_power_of_2(j + 1))
178 q = j + 1;
179 }
180
181 for (p = 2; p <= MAX_NUM; p <<= 1) {
182
183 if (!rte_is_power_of_2(p))
184 FAIL("rte_is_power_of_2");
185
186 for (i = 1; i <= MAX_NUM; i++) {
187 /* align floor */
188 if (RTE_ALIGN_FLOOR((uintptr_t)i, p) % p)
189 FAIL_ALIGN("RTE_ALIGN_FLOOR", i, p);

Callers 1

test_commonFunction · 0.85

Calls 7

rte_rand_maxFunction · 0.85
rte_align32pow2Function · 0.50
rte_align32prevpow2Function · 0.50
rte_is_power_of_2Function · 0.50
rte_align64pow2Function · 0.50
rte_align64prevpow2Function · 0.50
rte_is_alignedFunction · 0.50

Tested by

no test coverage detected