1 /*
2  * Copyright 2023 Meta
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/sys/util.h>
8 #include <zephyr/ztest.h>
9 
10 static const uint8_t val = LOG2CEIL(42);
11 static const uint8_t val64 = LOG2CEIL(42 + BIT64(32));
12 
ZTEST(pot,test_LOG2CEIL)13 ZTEST(pot, test_LOG2CEIL)
14 {
15 	zassert_equal(0, LOG2CEIL(LLONG_MIN));
16 	zassert_equal(0, LOG2CEIL(LONG_MIN));
17 	zassert_equal(0, LOG2CEIL(INT_MIN));
18 	zassert_equal(0, LOG2CEIL(-1));
19 	zassert_equal(0, LOG2CEIL(0));
20 	zassert_equal(0, LOG2CEIL(1));
21 	zassert_equal(1, LOG2CEIL(2));
22 	zassert_equal(2, LOG2CEIL(3));
23 	zassert_equal(2, LOG2CEIL(4));
24 	zassert_equal(3, LOG2CEIL(5));
25 	zassert_equal(31, LOG2CEIL(BIT(31)));
26 	zassert_equal(32, LOG2CEIL(BIT(31) + 1));
27 	zassert_equal(32, LOG2CEIL(UINT32_MAX));
28 	zassert_equal(32, LOG2CEIL(BIT64(32)));
29 	zassert_equal(33, LOG2CEIL(BIT64(32) + 1));
30 	zassert_equal(63, LOG2CEIL(BIT64(63) - 1));
31 	zassert_equal(63, LOG2CEIL(BIT64(63)));
32 	zassert_equal(64, LOG2CEIL(BIT64(63) + 1));
33 	zassert_equal(64, LOG2CEIL(UINT64_MAX));
34 
35 	zassert_equal(6, val);
36 	zassert_equal(33, val64);
37 }
38