16cd6a6acSopenharmony_ci#include "test-ebitmap.h"
26cd6a6acSopenharmony_ci
36cd6a6acSopenharmony_ci#include <stdlib.h>
46cd6a6acSopenharmony_ci#include <time.h>
56cd6a6acSopenharmony_ci
66cd6a6acSopenharmony_ci#include <sepol/debug.h>
76cd6a6acSopenharmony_ci#include <sepol/policydb/ebitmap.h>
86cd6a6acSopenharmony_ci
96cd6a6acSopenharmony_ci#define RANDOM_ROUNDS 10
106cd6a6acSopenharmony_ci
116cd6a6acSopenharmony_ci
126cd6a6acSopenharmony_cistatic int ebitmap_init_random(ebitmap_t *e, unsigned int length, int set_chance)
136cd6a6acSopenharmony_ci{
146cd6a6acSopenharmony_ci	unsigned int i;
156cd6a6acSopenharmony_ci	int rc;
166cd6a6acSopenharmony_ci
176cd6a6acSopenharmony_ci	if (set_chance <= 0 || set_chance > 100)
186cd6a6acSopenharmony_ci		return -EINVAL;
196cd6a6acSopenharmony_ci
206cd6a6acSopenharmony_ci	ebitmap_init(e);
216cd6a6acSopenharmony_ci
226cd6a6acSopenharmony_ci	for (i = 0; i < length; i++) {
236cd6a6acSopenharmony_ci		if ((random() % 100) < set_chance) {
246cd6a6acSopenharmony_ci			rc = ebitmap_set_bit(e, i, 1);
256cd6a6acSopenharmony_ci			if (rc)
266cd6a6acSopenharmony_ci				return rc;
276cd6a6acSopenharmony_ci		}
286cd6a6acSopenharmony_ci	}
296cd6a6acSopenharmony_ci
306cd6a6acSopenharmony_ci	return 0;
316cd6a6acSopenharmony_ci}
326cd6a6acSopenharmony_ci
336cd6a6acSopenharmony_cistatic void test_ebitmap_init_destroy(void)
346cd6a6acSopenharmony_ci{
356cd6a6acSopenharmony_ci	ebitmap_t e;
366cd6a6acSopenharmony_ci
376cd6a6acSopenharmony_ci	/* verify idempotence */
386cd6a6acSopenharmony_ci	ebitmap_init(&e);
396cd6a6acSopenharmony_ci	ebitmap_init(&e);
406cd6a6acSopenharmony_ci	ebitmap_init(&e);
416cd6a6acSopenharmony_ci
426cd6a6acSopenharmony_ci	CU_ASSERT(ebitmap_is_empty(&e));
436cd6a6acSopenharmony_ci	CU_ASSERT_PTR_NULL(ebitmap_startnode(&e));
446cd6a6acSopenharmony_ci
456cd6a6acSopenharmony_ci	/* verify idempotence */
466cd6a6acSopenharmony_ci	ebitmap_destroy(&e);
476cd6a6acSopenharmony_ci	ebitmap_destroy(&e);
486cd6a6acSopenharmony_ci	ebitmap_destroy(&e);
496cd6a6acSopenharmony_ci
506cd6a6acSopenharmony_ci	CU_ASSERT(ebitmap_is_empty(&e));
516cd6a6acSopenharmony_ci	CU_ASSERT_PTR_NULL(ebitmap_startnode(&e));
526cd6a6acSopenharmony_ci}
536cd6a6acSopenharmony_ci
546cd6a6acSopenharmony_cistatic void test_ebitmap_cmp(void)
556cd6a6acSopenharmony_ci{
566cd6a6acSopenharmony_ci	ebitmap_t e1, e2;
576cd6a6acSopenharmony_ci
586cd6a6acSopenharmony_ci	ebitmap_init(&e1);
596cd6a6acSopenharmony_ci	ebitmap_init(&e2);
606cd6a6acSopenharmony_ci
616cd6a6acSopenharmony_ci	CU_ASSERT(ebitmap_cmp(&e1, &e2));
626cd6a6acSopenharmony_ci
636cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 10, 1), 0);
646cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_cmp(&e1, &e2));
656cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 10, 1), 0);
666cd6a6acSopenharmony_ci	CU_ASSERT(ebitmap_cmp(&e1, &e2));
676cd6a6acSopenharmony_ci
686cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 63, 1), 0);
696cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_cmp(&e1, &e2));
706cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 63, 1), 0);
716cd6a6acSopenharmony_ci	CU_ASSERT(ebitmap_cmp(&e1, &e2));
726cd6a6acSopenharmony_ci
736cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 64, 1), 0);
746cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_cmp(&e1, &e2));
756cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 64, 1), 0);
766cd6a6acSopenharmony_ci	CU_ASSERT(ebitmap_cmp(&e1, &e2));
776cd6a6acSopenharmony_ci
786cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 1022, 1), 0);
796cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_cmp(&e1, &e2));
806cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 1022, 1), 0);
816cd6a6acSopenharmony_ci	CU_ASSERT(ebitmap_cmp(&e1, &e2));
826cd6a6acSopenharmony_ci
836cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 1023, 1), 0);
846cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_cmp(&e1, &e2));
856cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 1023, 1), 0);
866cd6a6acSopenharmony_ci	CU_ASSERT(ebitmap_cmp(&e1, &e2));
876cd6a6acSopenharmony_ci
886cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 1024, 1), 0);
896cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_cmp(&e1, &e2));
906cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 1024, 1), 0);
916cd6a6acSopenharmony_ci	CU_ASSERT(ebitmap_cmp(&e1, &e2));
926cd6a6acSopenharmony_ci
936cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 1025, 1), 0);
946cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_cmp(&e1, &e2));
956cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 1025, 1), 0);
966cd6a6acSopenharmony_ci	CU_ASSERT(ebitmap_cmp(&e1, &e2));
976cd6a6acSopenharmony_ci
986cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 255, 1), 0);
996cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_cmp(&e1, &e2));
1006cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 255, 1), 0);
1016cd6a6acSopenharmony_ci	CU_ASSERT(ebitmap_cmp(&e1, &e2));
1026cd6a6acSopenharmony_ci
1036cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 256, 1), 0);
1046cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_cmp(&e1, &e2));
1056cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 256, 1), 0);
1066cd6a6acSopenharmony_ci	CU_ASSERT(ebitmap_cmp(&e1, &e2));
1076cd6a6acSopenharmony_ci
1086cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 639, 1), 0);
1096cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_cmp(&e1, &e2));
1106cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 639, 1), 0);
1116cd6a6acSopenharmony_ci	CU_ASSERT(ebitmap_cmp(&e1, &e2));
1126cd6a6acSopenharmony_ci
1136cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 640, 1), 0);
1146cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_cmp(&e1, &e2));
1156cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 640, 1), 0);
1166cd6a6acSopenharmony_ci	CU_ASSERT(ebitmap_cmp(&e1, &e2));
1176cd6a6acSopenharmony_ci
1186cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 900, 1), 0);
1196cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_cmp(&e1, &e2));
1206cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 900, 1), 0);
1216cd6a6acSopenharmony_ci	CU_ASSERT(ebitmap_cmp(&e1, &e2));
1226cd6a6acSopenharmony_ci
1236cd6a6acSopenharmony_ci	ebitmap_destroy(&e2);
1246cd6a6acSopenharmony_ci
1256cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_cmp(&e1, &e2));
1266cd6a6acSopenharmony_ci
1276cd6a6acSopenharmony_ci	ebitmap_destroy(&e1);
1286cd6a6acSopenharmony_ci
1296cd6a6acSopenharmony_ci	CU_ASSERT(ebitmap_cmp(&e1, &e2));
1306cd6a6acSopenharmony_ci}
1316cd6a6acSopenharmony_ci
1326cd6a6acSopenharmony_cistatic void test_ebitmap_set_and_get(void)
1336cd6a6acSopenharmony_ci{
1346cd6a6acSopenharmony_ci	ebitmap_t e;
1356cd6a6acSopenharmony_ci
1366cd6a6acSopenharmony_ci	ebitmap_init(&e);
1376cd6a6acSopenharmony_ci
1386cd6a6acSopenharmony_ci	CU_ASSERT(ebitmap_is_empty(&e));
1396cd6a6acSopenharmony_ci	CU_ASSERT_TRUE(ebitmap_is_empty(&e));
1406cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_cardinality(&e), 0);
1416cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_highest_set_bit(&e), 0);
1426cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_get_bit(&e, 10), 0);
1436cd6a6acSopenharmony_ci
1446cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e, UINT32_MAX, 1), -EINVAL);
1456cd6a6acSopenharmony_ci
1466cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e, 10, 0), 0);
1476cd6a6acSopenharmony_ci	CU_ASSERT(ebitmap_is_empty(&e));
1486cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_cardinality(&e), 0);
1496cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_highest_set_bit(&e), 0);
1506cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_get_bit(&e, 10), 0);
1516cd6a6acSopenharmony_ci
1526cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e, 10, 1), 0);
1536cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_is_empty(&e));
1546cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_cardinality(&e), 1);
1556cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_highest_set_bit(&e), 10);
1566cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_get_bit(&e, 10), 1);
1576cd6a6acSopenharmony_ci
1586cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e, 100, 1), 0);
1596cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_is_empty(&e));
1606cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_cardinality(&e), 2);
1616cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_highest_set_bit(&e), 100);
1626cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_get_bit(&e, 100), 1);
1636cd6a6acSopenharmony_ci
1646cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e, 50, 1), 0);
1656cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_is_empty(&e));
1666cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_cardinality(&e), 3);
1676cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_highest_set_bit(&e), 100);
1686cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_get_bit(&e, 50), 1);
1696cd6a6acSopenharmony_ci
1706cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e, 1023, 1), 0);
1716cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_is_empty(&e));
1726cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_cardinality(&e), 4);
1736cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_highest_set_bit(&e), 1023);
1746cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_get_bit(&e, 1023), 1);
1756cd6a6acSopenharmony_ci
1766cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e, 1024, 1), 0);
1776cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_is_empty(&e));
1786cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_cardinality(&e), 5);
1796cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_highest_set_bit(&e), 1024);
1806cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_get_bit(&e, 1024), 1);
1816cd6a6acSopenharmony_ci
1826cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e, 1050, 1), 0);
1836cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_is_empty(&e));
1846cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_cardinality(&e), 6);
1856cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_highest_set_bit(&e), 1050);
1866cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_get_bit(&e, 1050), 1);
1876cd6a6acSopenharmony_ci
1886cd6a6acSopenharmony_ci	{
1896cd6a6acSopenharmony_ci		ebitmap_node_t *n;
1906cd6a6acSopenharmony_ci		unsigned int bit, count;
1916cd6a6acSopenharmony_ci
1926cd6a6acSopenharmony_ci		/* iterate all allocated bits */
1936cd6a6acSopenharmony_ci		count = 0;
1946cd6a6acSopenharmony_ci		ebitmap_for_each_bit(&e, n, bit) {
1956cd6a6acSopenharmony_ci			CU_ASSERT(                bit <   64  ||
1966cd6a6acSopenharmony_ci			          (64   <= bit && bit <  128) ||
1976cd6a6acSopenharmony_ci			          (960  <= bit && bit < 1024) ||
1986cd6a6acSopenharmony_ci			          (1024 <= bit && bit < 1088));
1996cd6a6acSopenharmony_ci			count++;
2006cd6a6acSopenharmony_ci		}
2016cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(count, 4 * 64);
2026cd6a6acSopenharmony_ci
2036cd6a6acSopenharmony_ci		count = 0;
2046cd6a6acSopenharmony_ci		ebitmap_for_each_positive_bit(&e, n, bit) {
2056cd6a6acSopenharmony_ci			CU_ASSERT(bit == 10 ||
2066cd6a6acSopenharmony_ci			          bit == 50 ||
2076cd6a6acSopenharmony_ci			          bit == 100 ||
2086cd6a6acSopenharmony_ci			          bit == 1023 ||
2096cd6a6acSopenharmony_ci			          bit == 1024 ||
2106cd6a6acSopenharmony_ci			          bit == 1050);
2116cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_get_bit(&e, bit), 1);
2126cd6a6acSopenharmony_ci			count++;
2136cd6a6acSopenharmony_ci		}
2146cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(count, 6);
2156cd6a6acSopenharmony_ci	}
2166cd6a6acSopenharmony_ci
2176cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e, 1024, 0), 0);
2186cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_is_empty(&e));
2196cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_cardinality(&e), 5);
2206cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_highest_set_bit(&e), 1050);
2216cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_get_bit(&e, 1024), 0);
2226cd6a6acSopenharmony_ci
2236cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e, 1050, 0), 0);
2246cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_is_empty(&e));
2256cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_cardinality(&e), 4);
2266cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_highest_set_bit(&e), 1023);
2276cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_get_bit(&e, 1050), 0);
2286cd6a6acSopenharmony_ci
2296cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e, 100, 0), 0);
2306cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_is_empty(&e));
2316cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_cardinality(&e), 3);
2326cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_highest_set_bit(&e), 1023);
2336cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_get_bit(&e, 100), 0);
2346cd6a6acSopenharmony_ci
2356cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e, 10, 0), 0);
2366cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_is_empty(&e));
2376cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_cardinality(&e), 2);
2386cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_highest_set_bit(&e), 1023);
2396cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_get_bit(&e, 10), 0);
2406cd6a6acSopenharmony_ci
2416cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e, 50, 0), 0);
2426cd6a6acSopenharmony_ci	CU_ASSERT_FALSE(ebitmap_is_empty(&e));
2436cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_cardinality(&e), 1);
2446cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_highest_set_bit(&e), 1023);
2456cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_get_bit(&e, 50), 0);
2466cd6a6acSopenharmony_ci
2476cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e, 1023, 0), 0);
2486cd6a6acSopenharmony_ci	CU_ASSERT_TRUE(ebitmap_is_empty(&e));
2496cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_cardinality(&e), 0);
2506cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_highest_set_bit(&e), 0);
2516cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_get_bit(&e, 1023), 0);
2526cd6a6acSopenharmony_ci
2536cd6a6acSopenharmony_ci	ebitmap_destroy(&e);
2546cd6a6acSopenharmony_ci}
2556cd6a6acSopenharmony_ci
2566cd6a6acSopenharmony_cistatic void test_ebitmap_init_range(void)
2576cd6a6acSopenharmony_ci{
2586cd6a6acSopenharmony_ci	ebitmap_t e1, e2, e3, e4, e5, e6;
2596cd6a6acSopenharmony_ci
2606cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_init_range(&e1, 0, 0), 0);
2616cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_highest_set_bit(&e1), 0);
2626cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_cardinality(&e1), 1);
2636cd6a6acSopenharmony_ci
2646cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_init_range(&e2, 0, 5), 0);
2656cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_highest_set_bit(&e2), 5);
2666cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_cardinality(&e2), 6);
2676cd6a6acSopenharmony_ci
2686cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_init_range(&e3, 20, 100), 0);
2696cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_highest_set_bit(&e3), 100);
2706cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_cardinality(&e3), 81);
2716cd6a6acSopenharmony_ci
2726cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_init_range(&e4, 100, 400), 0);
2736cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_highest_set_bit(&e4), 400);
2746cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_cardinality(&e4), 301);
2756cd6a6acSopenharmony_ci
2766cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_init_range(&e5, 10, 5), -EINVAL);
2776cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_init_range(&e6, 0, UINT32_MAX), -EOVERFLOW);
2786cd6a6acSopenharmony_ci
2796cd6a6acSopenharmony_ci	ebitmap_destroy(&e6);
2806cd6a6acSopenharmony_ci	ebitmap_destroy(&e5);
2816cd6a6acSopenharmony_ci	ebitmap_destroy(&e4);
2826cd6a6acSopenharmony_ci	ebitmap_destroy(&e3);
2836cd6a6acSopenharmony_ci	ebitmap_destroy(&e2);
2846cd6a6acSopenharmony_ci	ebitmap_destroy(&e1);
2856cd6a6acSopenharmony_ci}
2866cd6a6acSopenharmony_ci
2876cd6a6acSopenharmony_cistatic void test_ebitmap_or(void)
2886cd6a6acSopenharmony_ci{
2896cd6a6acSopenharmony_ci	ebitmap_t e1, e2, e3, e4;
2906cd6a6acSopenharmony_ci
2916cd6a6acSopenharmony_ci	ebitmap_init(&e1);
2926cd6a6acSopenharmony_ci	ebitmap_init(&e2);
2936cd6a6acSopenharmony_ci	ebitmap_init(&e3);
2946cd6a6acSopenharmony_ci	ebitmap_init(&e4);
2956cd6a6acSopenharmony_ci
2966cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 10, 1), 0);
2976cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 100, 1), 0);
2986cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 101, 1), 0);
2996cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 318, 1), 0);
3006cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 319, 1), 0);
3016cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 383, 1), 0);
3026cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 384, 1), 0);
3036cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 449, 1), 0);
3046cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 1013, 1), 0);
3056cd6a6acSopenharmony_ci
3066cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 11, 1), 0);
3076cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 101, 1), 0);
3086cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 430, 1), 0);
3096cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 665, 1), 0);
3106cd6a6acSopenharmony_ci
3116cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 10, 1), 0);
3126cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 11, 1), 0);
3136cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 100, 1), 0);
3146cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 101, 1), 0);
3156cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 318, 1), 0);
3166cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 319, 1), 0);
3176cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 383, 1), 0);
3186cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 384, 1), 0);
3196cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 430, 1), 0);
3206cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 449, 1), 0);
3216cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 665, 1), 0);
3226cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 1013, 1), 0);
3236cd6a6acSopenharmony_ci
3246cd6a6acSopenharmony_ci	{
3256cd6a6acSopenharmony_ci		ebitmap_t dst;
3266cd6a6acSopenharmony_ci
3276cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_or(&dst, &e1, &e1), 0);
3286cd6a6acSopenharmony_ci		CU_ASSERT(ebitmap_cmp(&dst, &e1));
3296cd6a6acSopenharmony_ci
3306cd6a6acSopenharmony_ci		ebitmap_destroy(&dst);
3316cd6a6acSopenharmony_ci	}
3326cd6a6acSopenharmony_ci
3336cd6a6acSopenharmony_ci	{
3346cd6a6acSopenharmony_ci		ebitmap_t dst;
3356cd6a6acSopenharmony_ci
3366cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_or(&dst, &e2, &e2), 0);
3376cd6a6acSopenharmony_ci		CU_ASSERT(ebitmap_cmp(&dst, &e2));
3386cd6a6acSopenharmony_ci
3396cd6a6acSopenharmony_ci		ebitmap_destroy(&dst);
3406cd6a6acSopenharmony_ci	}
3416cd6a6acSopenharmony_ci
3426cd6a6acSopenharmony_ci	{
3436cd6a6acSopenharmony_ci		ebitmap_t dst;
3446cd6a6acSopenharmony_ci
3456cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_or(&dst, &e1, &e2), 0);
3466cd6a6acSopenharmony_ci		CU_ASSERT(ebitmap_cmp(&dst, &e3));
3476cd6a6acSopenharmony_ci
3486cd6a6acSopenharmony_ci		ebitmap_destroy(&dst);
3496cd6a6acSopenharmony_ci	}
3506cd6a6acSopenharmony_ci
3516cd6a6acSopenharmony_ci	{
3526cd6a6acSopenharmony_ci		ebitmap_t dst;
3536cd6a6acSopenharmony_ci
3546cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_or(&dst, &e3, &e3), 0);
3556cd6a6acSopenharmony_ci		CU_ASSERT(ebitmap_cmp(&dst, &e3));
3566cd6a6acSopenharmony_ci
3576cd6a6acSopenharmony_ci		ebitmap_destroy(&dst);
3586cd6a6acSopenharmony_ci	}
3596cd6a6acSopenharmony_ci
3606cd6a6acSopenharmony_ci	{
3616cd6a6acSopenharmony_ci		ebitmap_t dst;
3626cd6a6acSopenharmony_ci
3636cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_or(&dst, &e3, &e4), 0);
3646cd6a6acSopenharmony_ci		CU_ASSERT(ebitmap_cmp(&dst, &e3));
3656cd6a6acSopenharmony_ci
3666cd6a6acSopenharmony_ci		ebitmap_destroy(&dst);
3676cd6a6acSopenharmony_ci	}
3686cd6a6acSopenharmony_ci
3696cd6a6acSopenharmony_ci	{
3706cd6a6acSopenharmony_ci		ebitmap_t dst;
3716cd6a6acSopenharmony_ci
3726cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_or(&dst, &e4, &e4), 0);
3736cd6a6acSopenharmony_ci		CU_ASSERT(ebitmap_cmp(&dst, &e4));
3746cd6a6acSopenharmony_ci
3756cd6a6acSopenharmony_ci		ebitmap_destroy(&dst);
3766cd6a6acSopenharmony_ci	}
3776cd6a6acSopenharmony_ci
3786cd6a6acSopenharmony_ci	ebitmap_destroy(&e4);
3796cd6a6acSopenharmony_ci	ebitmap_destroy(&e3);
3806cd6a6acSopenharmony_ci	ebitmap_destroy(&e2);
3816cd6a6acSopenharmony_ci	ebitmap_destroy(&e1);
3826cd6a6acSopenharmony_ci}
3836cd6a6acSopenharmony_ci
3846cd6a6acSopenharmony_cistatic void test_ebitmap_and(void)
3856cd6a6acSopenharmony_ci{
3866cd6a6acSopenharmony_ci	{
3876cd6a6acSopenharmony_ci		ebitmap_t e1, e2, e12, e3, e4;
3886cd6a6acSopenharmony_ci
3896cd6a6acSopenharmony_ci		ebitmap_init(&e1);
3906cd6a6acSopenharmony_ci		ebitmap_init(&e2);
3916cd6a6acSopenharmony_ci		ebitmap_init(&e12);
3926cd6a6acSopenharmony_ci		ebitmap_init(&e3);
3936cd6a6acSopenharmony_ci		ebitmap_init(&e4);
3946cd6a6acSopenharmony_ci
3956cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 10, 1), 0);
3966cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 100, 1), 0);
3976cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 101, 1), 0);
3986cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 318, 1), 0);
3996cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 319, 1), 0);
4006cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 383, 1), 0);
4016cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 384, 1), 0);
4026cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 449, 1), 0);
4036cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 1013, 1), 0);
4046cd6a6acSopenharmony_ci
4056cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 11, 1), 0);
4066cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 101, 1), 0);
4076cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 319, 1), 0);
4086cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 665, 1), 0);
4096cd6a6acSopenharmony_ci
4106cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e12, 101, 1), 0);
4116cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e12, 319, 1), 0);
4126cd6a6acSopenharmony_ci
4136cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 10, 1), 0);
4146cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 11, 1), 0);
4156cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 100, 1), 0);
4166cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 101, 1), 0);
4176cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 318, 1), 0);
4186cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 319, 1), 0);
4196cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 383, 1), 0);
4206cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 384, 1), 0);
4216cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 430, 1), 0);
4226cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 449, 1), 0);
4236cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 665, 1), 0);
4246cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 1013, 1), 0);
4256cd6a6acSopenharmony_ci
4266cd6a6acSopenharmony_ci		{
4276cd6a6acSopenharmony_ci			ebitmap_t dst;
4286cd6a6acSopenharmony_ci
4296cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_and(&dst, &e1, &e1), 0);
4306cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e1));
4316cd6a6acSopenharmony_ci
4326cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
4336cd6a6acSopenharmony_ci		}
4346cd6a6acSopenharmony_ci
4356cd6a6acSopenharmony_ci		{
4366cd6a6acSopenharmony_ci			ebitmap_t dst;
4376cd6a6acSopenharmony_ci
4386cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_and(&dst, &e2, &e2), 0);
4396cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e2));
4406cd6a6acSopenharmony_ci
4416cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
4426cd6a6acSopenharmony_ci		}
4436cd6a6acSopenharmony_ci
4446cd6a6acSopenharmony_ci		{
4456cd6a6acSopenharmony_ci			ebitmap_t dst;
4466cd6a6acSopenharmony_ci
4476cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_and(&dst, &e1, &e2), 0);
4486cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e12));
4496cd6a6acSopenharmony_ci
4506cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
4516cd6a6acSopenharmony_ci		}
4526cd6a6acSopenharmony_ci
4536cd6a6acSopenharmony_ci		{
4546cd6a6acSopenharmony_ci			ebitmap_t dst;
4556cd6a6acSopenharmony_ci
4566cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_and(&dst, &e3, &e3), 0);
4576cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e3));
4586cd6a6acSopenharmony_ci
4596cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
4606cd6a6acSopenharmony_ci		}
4616cd6a6acSopenharmony_ci
4626cd6a6acSopenharmony_ci		{
4636cd6a6acSopenharmony_ci			ebitmap_t dst;
4646cd6a6acSopenharmony_ci
4656cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_and(&dst, &e1, &e3), 0);
4666cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e1));
4676cd6a6acSopenharmony_ci
4686cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
4696cd6a6acSopenharmony_ci		}
4706cd6a6acSopenharmony_ci
4716cd6a6acSopenharmony_ci		{
4726cd6a6acSopenharmony_ci			ebitmap_t dst;
4736cd6a6acSopenharmony_ci
4746cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_and(&dst, &e2, &e3), 0);
4756cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e2));
4766cd6a6acSopenharmony_ci
4776cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
4786cd6a6acSopenharmony_ci		}
4796cd6a6acSopenharmony_ci
4806cd6a6acSopenharmony_ci		{
4816cd6a6acSopenharmony_ci			ebitmap_t dst;
4826cd6a6acSopenharmony_ci
4836cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_and(&dst, &e4, &e4), 0);
4846cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e4));
4856cd6a6acSopenharmony_ci
4866cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
4876cd6a6acSopenharmony_ci		}
4886cd6a6acSopenharmony_ci
4896cd6a6acSopenharmony_ci		{
4906cd6a6acSopenharmony_ci			ebitmap_t dst;
4916cd6a6acSopenharmony_ci
4926cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_and(&dst, &e3, &e4), 0);
4936cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e4));
4946cd6a6acSopenharmony_ci
4956cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
4966cd6a6acSopenharmony_ci		}
4976cd6a6acSopenharmony_ci
4986cd6a6acSopenharmony_ci		ebitmap_destroy(&e4);
4996cd6a6acSopenharmony_ci		ebitmap_destroy(&e3);
5006cd6a6acSopenharmony_ci		ebitmap_destroy(&e12);
5016cd6a6acSopenharmony_ci		ebitmap_destroy(&e2);
5026cd6a6acSopenharmony_ci		ebitmap_destroy(&e1);
5036cd6a6acSopenharmony_ci	}
5046cd6a6acSopenharmony_ci
5056cd6a6acSopenharmony_ci	{
5066cd6a6acSopenharmony_ci		ebitmap_t e5;
5076cd6a6acSopenharmony_ci		ebitmap_t e6;
5086cd6a6acSopenharmony_ci		ebitmap_t e56;
5096cd6a6acSopenharmony_ci		ebitmap_t dst;
5106cd6a6acSopenharmony_ci
5116cd6a6acSopenharmony_ci		ebitmap_init(&e5);
5126cd6a6acSopenharmony_ci		ebitmap_init(&e6);
5136cd6a6acSopenharmony_ci		ebitmap_init(&e56);
5146cd6a6acSopenharmony_ci
5156cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e5, 63, 1), 0);
5166cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e5, 191, 1), 0);
5176cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e5, 192, 1), 0);
5186cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e5, 318, 1), 0);
5196cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e5, 319, 1), 0);
5206cd6a6acSopenharmony_ci
5216cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e6, 64, 1), 0);
5226cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e6, 192, 1), 0);
5236cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e6, 319, 1), 0);
5246cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e6, 320, 1), 0);
5256cd6a6acSopenharmony_ci
5266cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e56, 192, 1), 0);
5276cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e56, 319, 1), 0);
5286cd6a6acSopenharmony_ci
5296cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_and(&dst, &e5, &e6), 0);
5306cd6a6acSopenharmony_ci		CU_ASSERT(ebitmap_cmp(&dst, &e56));
5316cd6a6acSopenharmony_ci
5326cd6a6acSopenharmony_ci		ebitmap_destroy(&dst);
5336cd6a6acSopenharmony_ci		ebitmap_destroy(&e56);
5346cd6a6acSopenharmony_ci		ebitmap_destroy(&e6);
5356cd6a6acSopenharmony_ci		ebitmap_destroy(&e5);
5366cd6a6acSopenharmony_ci	}
5376cd6a6acSopenharmony_ci}
5386cd6a6acSopenharmony_ci
5396cd6a6acSopenharmony_cistatic void test_ebitmap_xor(void)
5406cd6a6acSopenharmony_ci{
5416cd6a6acSopenharmony_ci	{
5426cd6a6acSopenharmony_ci		ebitmap_t e1, e2, e3, e4;
5436cd6a6acSopenharmony_ci
5446cd6a6acSopenharmony_ci		ebitmap_init(&e1);
5456cd6a6acSopenharmony_ci		ebitmap_init(&e2);
5466cd6a6acSopenharmony_ci		ebitmap_init(&e3);
5476cd6a6acSopenharmony_ci		ebitmap_init(&e4);
5486cd6a6acSopenharmony_ci
5496cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 1, 1), 0);
5506cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 5, 1), 0);
5516cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 10, 1), 0);
5526cd6a6acSopenharmony_ci
5536cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 1, 1), 0);
5546cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 3, 1), 0);
5556cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 6, 1), 0);
5566cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 9, 1), 0);
5576cd6a6acSopenharmony_ci
5586cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 3, 1), 0);
5596cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 5, 1), 0);
5606cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 6, 1), 0);
5616cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 9, 1), 0);
5626cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 10, 1), 0);
5636cd6a6acSopenharmony_ci
5646cd6a6acSopenharmony_ci		{
5656cd6a6acSopenharmony_ci			ebitmap_t dst1, dst2;
5666cd6a6acSopenharmony_ci
5676cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_xor(&dst1, &e1, &e1), 0);
5686cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst1, &e4));
5696cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_xor(&dst2, &dst1, &e1), 0);
5706cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst2, &e1));
5716cd6a6acSopenharmony_ci
5726cd6a6acSopenharmony_ci			ebitmap_destroy(&dst2);
5736cd6a6acSopenharmony_ci			ebitmap_destroy(&dst1);
5746cd6a6acSopenharmony_ci		}
5756cd6a6acSopenharmony_ci
5766cd6a6acSopenharmony_ci		{
5776cd6a6acSopenharmony_ci			ebitmap_t dst;
5786cd6a6acSopenharmony_ci
5796cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_xor(&dst, &e2, &e2), 0);
5806cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e4));
5816cd6a6acSopenharmony_ci
5826cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
5836cd6a6acSopenharmony_ci		}
5846cd6a6acSopenharmony_ci
5856cd6a6acSopenharmony_ci		{
5866cd6a6acSopenharmony_ci			ebitmap_t dst;
5876cd6a6acSopenharmony_ci
5886cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_xor(&dst, &e3, &e3), 0);
5896cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e4));
5906cd6a6acSopenharmony_ci
5916cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
5926cd6a6acSopenharmony_ci		}
5936cd6a6acSopenharmony_ci
5946cd6a6acSopenharmony_ci		{
5956cd6a6acSopenharmony_ci			ebitmap_t dst;
5966cd6a6acSopenharmony_ci
5976cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_xor(&dst, &e4, &e4), 0);
5986cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e4));
5996cd6a6acSopenharmony_ci
6006cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
6016cd6a6acSopenharmony_ci		}
6026cd6a6acSopenharmony_ci
6036cd6a6acSopenharmony_ci		{
6046cd6a6acSopenharmony_ci			ebitmap_t dst;
6056cd6a6acSopenharmony_ci
6066cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_xor(&dst, &e1, &e2), 0);
6076cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e3));
6086cd6a6acSopenharmony_ci
6096cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
6106cd6a6acSopenharmony_ci		}
6116cd6a6acSopenharmony_ci
6126cd6a6acSopenharmony_ci		{
6136cd6a6acSopenharmony_ci			ebitmap_t dst;
6146cd6a6acSopenharmony_ci
6156cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_xor(&dst, &e2, &e4), 0);
6166cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e2));
6176cd6a6acSopenharmony_ci
6186cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
6196cd6a6acSopenharmony_ci		}
6206cd6a6acSopenharmony_ci
6216cd6a6acSopenharmony_ci		ebitmap_destroy(&e4);
6226cd6a6acSopenharmony_ci		ebitmap_destroy(&e3);
6236cd6a6acSopenharmony_ci		ebitmap_destroy(&e2);
6246cd6a6acSopenharmony_ci		ebitmap_destroy(&e1);
6256cd6a6acSopenharmony_ci	}
6266cd6a6acSopenharmony_ci
6276cd6a6acSopenharmony_ci	{
6286cd6a6acSopenharmony_ci		ebitmap_t e5;
6296cd6a6acSopenharmony_ci		ebitmap_t e6;
6306cd6a6acSopenharmony_ci		ebitmap_t e56;
6316cd6a6acSopenharmony_ci		ebitmap_t dst;
6326cd6a6acSopenharmony_ci
6336cd6a6acSopenharmony_ci		ebitmap_init(&e5);
6346cd6a6acSopenharmony_ci		ebitmap_init(&e6);
6356cd6a6acSopenharmony_ci		ebitmap_init(&e56);
6366cd6a6acSopenharmony_ci
6376cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e5, 63, 1), 0);
6386cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e5, 191, 1), 0);
6396cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e5, 192, 1), 0);
6406cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e5, 318, 1), 0);
6416cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e5, 319, 1), 0);
6426cd6a6acSopenharmony_ci
6436cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e6, 64, 1), 0);
6446cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e6, 192, 1), 0);
6456cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e6, 319, 1), 0);
6466cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e6, 320, 1), 0);
6476cd6a6acSopenharmony_ci
6486cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e56, 63, 1), 0);
6496cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e56, 64, 1), 0);
6506cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e56, 191, 1), 0);
6516cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e56, 318, 1), 0);
6526cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e56, 320, 1), 0);
6536cd6a6acSopenharmony_ci
6546cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_xor(&dst, &e5, &e6), 0);
6556cd6a6acSopenharmony_ci		CU_ASSERT(ebitmap_cmp(&dst, &e56));
6566cd6a6acSopenharmony_ci
6576cd6a6acSopenharmony_ci		ebitmap_destroy(&dst);
6586cd6a6acSopenharmony_ci		ebitmap_destroy(&e56);
6596cd6a6acSopenharmony_ci		ebitmap_destroy(&e6);
6606cd6a6acSopenharmony_ci		ebitmap_destroy(&e5);
6616cd6a6acSopenharmony_ci	}
6626cd6a6acSopenharmony_ci}
6636cd6a6acSopenharmony_ci
6646cd6a6acSopenharmony_cistatic void test_ebitmap_not(void)
6656cd6a6acSopenharmony_ci{
6666cd6a6acSopenharmony_ci	{
6676cd6a6acSopenharmony_ci		ebitmap_t e1, e2, e3, e4;
6686cd6a6acSopenharmony_ci
6696cd6a6acSopenharmony_ci		ebitmap_init(&e1);
6706cd6a6acSopenharmony_ci		ebitmap_init(&e2);
6716cd6a6acSopenharmony_ci		ebitmap_init(&e3);
6726cd6a6acSopenharmony_ci		ebitmap_init(&e4);
6736cd6a6acSopenharmony_ci
6746cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 0, 1), 0);
6756cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 1, 1), 0);
6766cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 5, 1), 0);
6776cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 10, 1), 0);
6786cd6a6acSopenharmony_ci
6796cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 2, 1), 0);
6806cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 3, 1), 0);
6816cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 4, 1), 0);
6826cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 6, 1), 0);
6836cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 7, 1), 0);
6846cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 8, 1), 0);
6856cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 9, 1), 0);
6866cd6a6acSopenharmony_ci
6876cd6a6acSopenharmony_ci		{
6886cd6a6acSopenharmony_ci			ebitmap_t dst1, dst2;
6896cd6a6acSopenharmony_ci
6906cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_not(&dst1, &e3, 10), 0);
6916cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_highest_set_bit(&dst1), 9);
6926cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_cardinality(&dst1), 10);
6936cd6a6acSopenharmony_ci
6946cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_not(&dst2, &dst1, 10), 0);
6956cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst2, &e3));
6966cd6a6acSopenharmony_ci
6976cd6a6acSopenharmony_ci			ebitmap_destroy(&dst2);
6986cd6a6acSopenharmony_ci			ebitmap_destroy(&dst1);
6996cd6a6acSopenharmony_ci		}
7006cd6a6acSopenharmony_ci
7016cd6a6acSopenharmony_ci		{
7026cd6a6acSopenharmony_ci			ebitmap_t dst1, dst2;
7036cd6a6acSopenharmony_ci
7046cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_not(&dst1, &e1, 11), 0);
7056cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst1, &e2));
7066cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_not(&dst2, &dst1, 11), 0);
7076cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst2, &e1));
7086cd6a6acSopenharmony_ci
7096cd6a6acSopenharmony_ci			ebitmap_destroy(&dst2);
7106cd6a6acSopenharmony_ci			ebitmap_destroy(&dst1);
7116cd6a6acSopenharmony_ci		}
7126cd6a6acSopenharmony_ci
7136cd6a6acSopenharmony_ci		{
7146cd6a6acSopenharmony_ci			ebitmap_t dst;
7156cd6a6acSopenharmony_ci
7166cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_not(&dst, &e1, 8), 0);
7176cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_highest_set_bit(&dst), 7);
7186cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_cardinality(&dst), 5);
7196cd6a6acSopenharmony_ci
7206cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
7216cd6a6acSopenharmony_ci		}
7226cd6a6acSopenharmony_ci
7236cd6a6acSopenharmony_ci		{
7246cd6a6acSopenharmony_ci			ebitmap_t dst;
7256cd6a6acSopenharmony_ci
7266cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_not(&dst, &e1, 12), 0);
7276cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_highest_set_bit(&dst), 11);
7286cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_cardinality(&dst), 8);
7296cd6a6acSopenharmony_ci
7306cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
7316cd6a6acSopenharmony_ci		}
7326cd6a6acSopenharmony_ci
7336cd6a6acSopenharmony_ci		ebitmap_destroy(&e3);
7346cd6a6acSopenharmony_ci		ebitmap_destroy(&e2);
7356cd6a6acSopenharmony_ci		ebitmap_destroy(&e1);
7366cd6a6acSopenharmony_ci	}
7376cd6a6acSopenharmony_ci
7386cd6a6acSopenharmony_ci	{
7396cd6a6acSopenharmony_ci		ebitmap_t e5;
7406cd6a6acSopenharmony_ci		ebitmap_t e5not;
7416cd6a6acSopenharmony_ci		ebitmap_node_t *n;
7426cd6a6acSopenharmony_ci		unsigned int bit;
7436cd6a6acSopenharmony_ci
7446cd6a6acSopenharmony_ci		ebitmap_init(&e5);
7456cd6a6acSopenharmony_ci		ebitmap_init(&e5not);
7466cd6a6acSopenharmony_ci
7476cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e5, 63, 1), 0);
7486cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e5, 191, 1), 0);
7496cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e5, 192, 1), 0);
7506cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e5, 318, 1), 0);
7516cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e5, 319, 1), 0);
7526cd6a6acSopenharmony_ci
7536cd6a6acSopenharmony_ci		for (bit = 0; bit < 317; bit++)
7546cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_set_bit(&e5not, bit, 1), 0);
7556cd6a6acSopenharmony_ci		ebitmap_for_each_positive_bit(&e5, n, bit)
7566cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_set_bit(&e5not, bit, 0), 0);
7576cd6a6acSopenharmony_ci
7586cd6a6acSopenharmony_ci		{
7596cd6a6acSopenharmony_ci			ebitmap_t dst;
7606cd6a6acSopenharmony_ci
7616cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_not(&dst, &e5, 317), 0);
7626cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e5not));
7636cd6a6acSopenharmony_ci
7646cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
7656cd6a6acSopenharmony_ci		}
7666cd6a6acSopenharmony_ci
7676cd6a6acSopenharmony_ci		{
7686cd6a6acSopenharmony_ci			ebitmap_t dst;
7696cd6a6acSopenharmony_ci
7706cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_not(&dst, &e5, 318), 0);
7716cd6a6acSopenharmony_ci			CU_ASSERT_FALSE(ebitmap_cmp(&dst, &e5not));
7726cd6a6acSopenharmony_ci
7736cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_set_bit(&e5not, 317, 1), 0);
7746cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e5not));
7756cd6a6acSopenharmony_ci
7766cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
7776cd6a6acSopenharmony_ci		}
7786cd6a6acSopenharmony_ci
7796cd6a6acSopenharmony_ci		{
7806cd6a6acSopenharmony_ci			ebitmap_t dst;
7816cd6a6acSopenharmony_ci
7826cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_not(&dst, &e5, 319), 0);
7836cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e5not));
7846cd6a6acSopenharmony_ci
7856cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
7866cd6a6acSopenharmony_ci		}
7876cd6a6acSopenharmony_ci
7886cd6a6acSopenharmony_ci		ebitmap_destroy(&e5not);
7896cd6a6acSopenharmony_ci		ebitmap_destroy(&e5);
7906cd6a6acSopenharmony_ci	}
7916cd6a6acSopenharmony_ci}
7926cd6a6acSopenharmony_ci
7936cd6a6acSopenharmony_cistatic void test_ebitmap_andnot(void)
7946cd6a6acSopenharmony_ci{
7956cd6a6acSopenharmony_ci	{
7966cd6a6acSopenharmony_ci		ebitmap_t e1, e2, e12, e3, e4;
7976cd6a6acSopenharmony_ci
7986cd6a6acSopenharmony_ci		ebitmap_init(&e1);
7996cd6a6acSopenharmony_ci		ebitmap_init(&e2);
8006cd6a6acSopenharmony_ci		ebitmap_init(&e12);
8016cd6a6acSopenharmony_ci		ebitmap_init(&e3);
8026cd6a6acSopenharmony_ci		ebitmap_init(&e4);
8036cd6a6acSopenharmony_ci
8046cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 10, 1), 0);
8056cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 100, 1), 0);
8066cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 101, 1), 0);
8076cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 430, 1), 0);
8086cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e1, 1013, 1), 0);
8096cd6a6acSopenharmony_ci
8106cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 11, 1), 0);
8116cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 101, 1), 0);
8126cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e2, 665, 1), 0);
8136cd6a6acSopenharmony_ci
8146cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e12, 10, 1), 0);
8156cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e12, 100, 1), 0);
8166cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e12, 430, 1), 0);
8176cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e12, 1013, 1), 0);
8186cd6a6acSopenharmony_ci
8196cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 10, 1), 0);
8206cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 11, 1), 0);
8216cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 100, 1), 0);
8226cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 101, 1), 0);
8236cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 430, 1), 0);
8246cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 665, 1), 0);
8256cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e3, 1013, 1), 0);
8266cd6a6acSopenharmony_ci
8276cd6a6acSopenharmony_ci		{
8286cd6a6acSopenharmony_ci			ebitmap_t dst;
8296cd6a6acSopenharmony_ci
8306cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_andnot(&dst, &e1, &e1, 1024), 0);
8316cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e4));
8326cd6a6acSopenharmony_ci
8336cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
8346cd6a6acSopenharmony_ci		}
8356cd6a6acSopenharmony_ci
8366cd6a6acSopenharmony_ci		{
8376cd6a6acSopenharmony_ci			ebitmap_t dst;
8386cd6a6acSopenharmony_ci
8396cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_andnot(&dst, &e2, &e2, 1024), 0);
8406cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e4));
8416cd6a6acSopenharmony_ci
8426cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
8436cd6a6acSopenharmony_ci		}
8446cd6a6acSopenharmony_ci
8456cd6a6acSopenharmony_ci		{
8466cd6a6acSopenharmony_ci			ebitmap_t dst;
8476cd6a6acSopenharmony_ci
8486cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_andnot(&dst, &e1, &e2, 1024), 0);
8496cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e12));
8506cd6a6acSopenharmony_ci
8516cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
8526cd6a6acSopenharmony_ci		}
8536cd6a6acSopenharmony_ci
8546cd6a6acSopenharmony_ci		{
8556cd6a6acSopenharmony_ci			ebitmap_t dst;
8566cd6a6acSopenharmony_ci
8576cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_andnot(&dst, &e3, &e3, 1024), 0);
8586cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e4));
8596cd6a6acSopenharmony_ci
8606cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
8616cd6a6acSopenharmony_ci		}
8626cd6a6acSopenharmony_ci
8636cd6a6acSopenharmony_ci		{
8646cd6a6acSopenharmony_ci			ebitmap_t dst;
8656cd6a6acSopenharmony_ci
8666cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_andnot(&dst, &e1, &e3, 1024), 0);
8676cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e4));
8686cd6a6acSopenharmony_ci
8696cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
8706cd6a6acSopenharmony_ci		}
8716cd6a6acSopenharmony_ci
8726cd6a6acSopenharmony_ci		{
8736cd6a6acSopenharmony_ci			ebitmap_t dst;
8746cd6a6acSopenharmony_ci
8756cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_andnot(&dst, &e2, &e12, 1024), 0);
8766cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e2));
8776cd6a6acSopenharmony_ci
8786cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
8796cd6a6acSopenharmony_ci		}
8806cd6a6acSopenharmony_ci
8816cd6a6acSopenharmony_ci		{
8826cd6a6acSopenharmony_ci			ebitmap_t dst;
8836cd6a6acSopenharmony_ci
8846cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_andnot(&dst, &e4, &e4, 1024), 0);
8856cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e4));
8866cd6a6acSopenharmony_ci
8876cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
8886cd6a6acSopenharmony_ci		}
8896cd6a6acSopenharmony_ci
8906cd6a6acSopenharmony_ci		{
8916cd6a6acSopenharmony_ci			ebitmap_t dst;
8926cd6a6acSopenharmony_ci
8936cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_andnot(&dst, &e3, &e4, 1024), 0);
8946cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e3));
8956cd6a6acSopenharmony_ci
8966cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
8976cd6a6acSopenharmony_ci		}
8986cd6a6acSopenharmony_ci
8996cd6a6acSopenharmony_ci		ebitmap_destroy(&e4);
9006cd6a6acSopenharmony_ci		ebitmap_destroy(&e3);
9016cd6a6acSopenharmony_ci		ebitmap_destroy(&e12);
9026cd6a6acSopenharmony_ci		ebitmap_destroy(&e2);
9036cd6a6acSopenharmony_ci		ebitmap_destroy(&e1);
9046cd6a6acSopenharmony_ci	}
9056cd6a6acSopenharmony_ci
9066cd6a6acSopenharmony_ci	{
9076cd6a6acSopenharmony_ci		ebitmap_t e5;
9086cd6a6acSopenharmony_ci		ebitmap_t e6;
9096cd6a6acSopenharmony_ci		ebitmap_t e56;
9106cd6a6acSopenharmony_ci
9116cd6a6acSopenharmony_ci		ebitmap_init(&e5);
9126cd6a6acSopenharmony_ci		ebitmap_init(&e6);
9136cd6a6acSopenharmony_ci		ebitmap_init(&e56);
9146cd6a6acSopenharmony_ci
9156cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e5, 63, 1), 0);
9166cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e5, 191, 1), 0);
9176cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e5, 192, 1), 0);
9186cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e5, 318, 1), 0);
9196cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e5, 319, 1), 0);
9206cd6a6acSopenharmony_ci
9216cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e6, 64, 1), 0);
9226cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e6, 192, 1), 0);
9236cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e6, 319, 1), 0);
9246cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e6, 320, 1), 0);
9256cd6a6acSopenharmony_ci
9266cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e56, 63, 1), 0);
9276cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_set_bit(&e56, 191, 1), 0);
9286cd6a6acSopenharmony_ci
9296cd6a6acSopenharmony_ci		{
9306cd6a6acSopenharmony_ci			ebitmap_t dst;
9316cd6a6acSopenharmony_ci
9326cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_andnot(&dst, &e5, &e6, 317), 0);
9336cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e56));
9346cd6a6acSopenharmony_ci
9356cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
9366cd6a6acSopenharmony_ci		}
9376cd6a6acSopenharmony_ci
9386cd6a6acSopenharmony_ci		{
9396cd6a6acSopenharmony_ci			ebitmap_t dst;
9406cd6a6acSopenharmony_ci
9416cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_andnot(&dst, &e5, &e6, 318), 0);
9426cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e56));
9436cd6a6acSopenharmony_ci
9446cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
9456cd6a6acSopenharmony_ci		}
9466cd6a6acSopenharmony_ci
9476cd6a6acSopenharmony_ci		{
9486cd6a6acSopenharmony_ci			ebitmap_t dst;
9496cd6a6acSopenharmony_ci
9506cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_andnot(&dst, &e5, &e6, 319), 0);
9516cd6a6acSopenharmony_ci			CU_ASSERT_FALSE(ebitmap_cmp(&dst, &e56));
9526cd6a6acSopenharmony_ci
9536cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_set_bit(&e56, 318, 1), 0);
9546cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e56));
9556cd6a6acSopenharmony_ci
9566cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
9576cd6a6acSopenharmony_ci		}
9586cd6a6acSopenharmony_ci
9596cd6a6acSopenharmony_ci		{
9606cd6a6acSopenharmony_ci			ebitmap_t dst;
9616cd6a6acSopenharmony_ci
9626cd6a6acSopenharmony_ci			CU_ASSERT_EQUAL(ebitmap_andnot(&dst, &e5, &e6, 320), 0);
9636cd6a6acSopenharmony_ci			CU_ASSERT(ebitmap_cmp(&dst, &e56));
9646cd6a6acSopenharmony_ci
9656cd6a6acSopenharmony_ci			ebitmap_destroy(&dst);
9666cd6a6acSopenharmony_ci		}
9676cd6a6acSopenharmony_ci
9686cd6a6acSopenharmony_ci		ebitmap_destroy(&e56);
9696cd6a6acSopenharmony_ci		ebitmap_destroy(&e6);
9706cd6a6acSopenharmony_ci		ebitmap_destroy(&e5);
9716cd6a6acSopenharmony_ci	}
9726cd6a6acSopenharmony_ci}
9736cd6a6acSopenharmony_ci
9746cd6a6acSopenharmony_cistatic void test_ebitmap__random_impl(unsigned int length, int set_chance)
9756cd6a6acSopenharmony_ci{
9766cd6a6acSopenharmony_ci	ebitmap_t e1, e2, dst_cpy, dst_or, dst_and, dst_xor1, dst_xor2, dst_not1, dst_not2, dst_andnot;
9776cd6a6acSopenharmony_ci	unsigned int i;
9786cd6a6acSopenharmony_ci
9796cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_init_random(&e1, length, set_chance), 0);
9806cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_init_random(&e2, length, set_chance), 0);
9816cd6a6acSopenharmony_ci
9826cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_cpy(&dst_cpy, &e1), 0);
9836cd6a6acSopenharmony_ci	CU_ASSERT(ebitmap_cmp(&dst_cpy, &e1));
9846cd6a6acSopenharmony_ci
9856cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_or(&dst_or, &e1, &e2), 0);
9866cd6a6acSopenharmony_ci	for (i = 0; i < length; i++)
9876cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_get_bit(&dst_or, i), ebitmap_get_bit(&e1, i) | ebitmap_get_bit(&e2, i));
9886cd6a6acSopenharmony_ci
9896cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_and(&dst_and, &e1, &e2), 0);
9906cd6a6acSopenharmony_ci	for (i = 0; i < length; i++)
9916cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_get_bit(&dst_and, i), ebitmap_get_bit(&e1, i) & ebitmap_get_bit(&e2, i));
9926cd6a6acSopenharmony_ci
9936cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_xor(&dst_xor1, &e1, &e2), 0);
9946cd6a6acSopenharmony_ci	for (i = 0; i < length; i++)
9956cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_get_bit(&dst_xor1, i), ebitmap_get_bit(&e1, i) ^ ebitmap_get_bit(&e2, i));
9966cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_xor(&dst_xor2, &dst_xor1, &e2), 0);
9976cd6a6acSopenharmony_ci	CU_ASSERT(ebitmap_cmp(&dst_xor2, &e1));
9986cd6a6acSopenharmony_ci
9996cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_not(&dst_not1, &e1, length), 0);
10006cd6a6acSopenharmony_ci	for (i = 0; i < length; i++)
10016cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_get_bit(&dst_not1, i), !ebitmap_get_bit(&e1, i));
10026cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_not(&dst_not2, &dst_not1, length), 0);
10036cd6a6acSopenharmony_ci	CU_ASSERT(ebitmap_cmp(&dst_not2, &e1));
10046cd6a6acSopenharmony_ci
10056cd6a6acSopenharmony_ci	CU_ASSERT_EQUAL(ebitmap_andnot(&dst_andnot, &e1, &e2, length), 0);
10066cd6a6acSopenharmony_ci	for (i = 0; i < length; i++)
10076cd6a6acSopenharmony_ci		CU_ASSERT_EQUAL(ebitmap_get_bit(&dst_andnot, i), ebitmap_get_bit(&e1, i) & !ebitmap_get_bit(&e2, i));
10086cd6a6acSopenharmony_ci
10096cd6a6acSopenharmony_ci	ebitmap_destroy(&dst_andnot);
10106cd6a6acSopenharmony_ci	ebitmap_destroy(&dst_not2);
10116cd6a6acSopenharmony_ci	ebitmap_destroy(&dst_not1);
10126cd6a6acSopenharmony_ci	ebitmap_destroy(&dst_xor2);
10136cd6a6acSopenharmony_ci	ebitmap_destroy(&dst_xor1);
10146cd6a6acSopenharmony_ci	ebitmap_destroy(&dst_and);
10156cd6a6acSopenharmony_ci	ebitmap_destroy(&dst_or);
10166cd6a6acSopenharmony_ci	ebitmap_destroy(&dst_cpy);
10176cd6a6acSopenharmony_ci	ebitmap_destroy(&e2);
10186cd6a6acSopenharmony_ci	ebitmap_destroy(&e1);
10196cd6a6acSopenharmony_ci}
10206cd6a6acSopenharmony_ci
10216cd6a6acSopenharmony_cistatic void test_ebitmap__random(void)
10226cd6a6acSopenharmony_ci{
10236cd6a6acSopenharmony_ci	unsigned int i;
10246cd6a6acSopenharmony_ci
10256cd6a6acSopenharmony_ci	for (i = 0; i < RANDOM_ROUNDS; i++)
10266cd6a6acSopenharmony_ci		test_ebitmap__random_impl(5, 10);
10276cd6a6acSopenharmony_ci
10286cd6a6acSopenharmony_ci	for (i = 0; i < RANDOM_ROUNDS; i++)
10296cd6a6acSopenharmony_ci		test_ebitmap__random_impl(5, 90);
10306cd6a6acSopenharmony_ci
10316cd6a6acSopenharmony_ci	for (i = 0; i < RANDOM_ROUNDS; i++)
10326cd6a6acSopenharmony_ci		test_ebitmap__random_impl(1024, 50);
10336cd6a6acSopenharmony_ci
10346cd6a6acSopenharmony_ci	for (i = 0; i < RANDOM_ROUNDS; i++)
10356cd6a6acSopenharmony_ci		test_ebitmap__random_impl(8000, 5);
10366cd6a6acSopenharmony_ci
10376cd6a6acSopenharmony_ci	for (i = 0; i < RANDOM_ROUNDS; i++)
10386cd6a6acSopenharmony_ci		test_ebitmap__random_impl(8000, 95);
10396cd6a6acSopenharmony_ci}
10406cd6a6acSopenharmony_ci
10416cd6a6acSopenharmony_ci/*
10426cd6a6acSopenharmony_ci * External hooks
10436cd6a6acSopenharmony_ci */
10446cd6a6acSopenharmony_ci
10456cd6a6acSopenharmony_ciint ebitmap_test_init(void)
10466cd6a6acSopenharmony_ci{
10476cd6a6acSopenharmony_ci	srandom(time(NULL));
10486cd6a6acSopenharmony_ci
10496cd6a6acSopenharmony_ci	/* silence ebitmap_set_bit() failure message */
10506cd6a6acSopenharmony_ci	sepol_debug(0);
10516cd6a6acSopenharmony_ci
10526cd6a6acSopenharmony_ci	return 0;
10536cd6a6acSopenharmony_ci}
10546cd6a6acSopenharmony_ci
10556cd6a6acSopenharmony_ciint ebitmap_test_cleanup(void)
10566cd6a6acSopenharmony_ci{
10576cd6a6acSopenharmony_ci	return 0;
10586cd6a6acSopenharmony_ci}
10596cd6a6acSopenharmony_ci
10606cd6a6acSopenharmony_ci#define ADD_TEST(name) \
10616cd6a6acSopenharmony_ci	do { \
10626cd6a6acSopenharmony_ci		if (NULL == CU_add_test(suite, #name, test_##name)) { \
10636cd6a6acSopenharmony_ci			return CU_get_error(); \
10646cd6a6acSopenharmony_ci		} \
10656cd6a6acSopenharmony_ci	} while (0)
10666cd6a6acSopenharmony_ci
10676cd6a6acSopenharmony_ciint ebitmap_add_tests(CU_pSuite suite)
10686cd6a6acSopenharmony_ci{
10696cd6a6acSopenharmony_ci	ADD_TEST(ebitmap_init_destroy);
10706cd6a6acSopenharmony_ci	ADD_TEST(ebitmap_cmp);
10716cd6a6acSopenharmony_ci	ADD_TEST(ebitmap_set_and_get);
10726cd6a6acSopenharmony_ci	ADD_TEST(ebitmap_init_range);
10736cd6a6acSopenharmony_ci	ADD_TEST(ebitmap_or);
10746cd6a6acSopenharmony_ci	ADD_TEST(ebitmap_and);
10756cd6a6acSopenharmony_ci	ADD_TEST(ebitmap_xor);
10766cd6a6acSopenharmony_ci	ADD_TEST(ebitmap_not);
10776cd6a6acSopenharmony_ci	ADD_TEST(ebitmap_andnot);
10786cd6a6acSopenharmony_ci	ADD_TEST(ebitmap__random);
10796cd6a6acSopenharmony_ci	return 0;
10806cd6a6acSopenharmony_ci}
1081