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 = LOG2(42);
11 static const uint8_t val64 = LOG2(42 + BIT64(32));
12
ZTEST(pot,test_LOG2)13 ZTEST(pot, test_LOG2)
14 {
15 zassert_equal(-1, LOG2(LLONG_MIN));
16 zassert_equal(-1, LOG2(LONG_MIN));
17 zassert_equal(-1, LOG2(INT_MIN));
18 zassert_equal(-1, LOG2(-1));
19 zassert_equal(-1, LOG2(0));
20 zassert_equal(0, LOG2(1));
21 zassert_equal(1, LOG2(2));
22 zassert_equal(1, LOG2(3));
23 zassert_equal(2, LOG2(4));
24 zassert_equal(2, LOG2(5));
25 zassert_equal(31, LOG2(BIT(31)));
26 zassert_equal(31, LOG2(BIT(31) + 1));
27 zassert_equal(31, LOG2(UINT32_MAX));
28 zassert_equal(32, LOG2(BIT64(32)));
29 zassert_equal(62, LOG2(BIT64(63) - 1));
30 zassert_equal(63, LOG2(BIT64(63)));
31 zassert_equal(63, LOG2(BIT64(63) + 1));
32 zassert_equal(63, LOG2(UINT64_MAX));
33
34 zassert_equal(5, val);
35 zassert_equal(32, val64);
36 }
37