As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>. This patch proposes to then include <zephyr/kernel.h> instead of <zephyr/zephyr.h> since it is more clear that you are including the Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a catch-all header that may be confusing. Most applications need to include a bunch of other things to compile, e.g. driver headers or subsystem headers like BT, logging, etc. The idea of a catch-all header in Zephyr is probably not feasible anyway. Reason is that Zephyr is not a library, like it could be for example `libpython`. Zephyr provides many utilities nowadays: a kernel, drivers, subsystems, etc and things will likely grow. A catch-all header would be massive, difficult to keep up-to-date. It is also likely that an application will only build a small subset. Note that subsystem-level headers may use a catch-all approach to make things easier, though. NOTE: This patch is **NOT** removing the header, just removing its usage in-tree. I'd advocate for its deprecation (add a #warning on it), but I understand many people will have concerns. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
78 lines
1.8 KiB
C
78 lines
1.8 KiB
C
/*
|
|
* Copyright (c) 2022 BayLibre SAS
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include <zephyr/ztest.h>
|
|
#include <zephyr/kernel.h>
|
|
|
|
/**
|
|
* @brief Test the Z_POW2_CEIL() macro
|
|
*
|
|
* @defgroup test_pow2_ceil Z_POW2_CEIL() tests
|
|
*
|
|
* @ingroup all_tests
|
|
*
|
|
* @{
|
|
* @}
|
|
*/
|
|
|
|
/**
|
|
* @brief Verify compile-time constant results
|
|
*
|
|
* @ingroup test_pow2_ceil
|
|
*
|
|
* @details Check if static array allocations are sized as expected.
|
|
*/
|
|
|
|
char static_array1[Z_POW2_CEIL(1)];
|
|
char static_array2[Z_POW2_CEIL(2)];
|
|
char static_array3[Z_POW2_CEIL(3)];
|
|
char static_array4[Z_POW2_CEIL(4)];
|
|
char static_array5[Z_POW2_CEIL(5)];
|
|
char static_array7[Z_POW2_CEIL(7)];
|
|
char static_array8[Z_POW2_CEIL(8)];
|
|
char static_array9[Z_POW2_CEIL(9)];
|
|
|
|
BUILD_ASSERT(sizeof(static_array1) == 1);
|
|
BUILD_ASSERT(sizeof(static_array2) == 2);
|
|
BUILD_ASSERT(sizeof(static_array3) == 4);
|
|
BUILD_ASSERT(sizeof(static_array4) == 4);
|
|
BUILD_ASSERT(sizeof(static_array5) == 8);
|
|
BUILD_ASSERT(sizeof(static_array7) == 8);
|
|
BUILD_ASSERT(sizeof(static_array8) == 8);
|
|
BUILD_ASSERT(sizeof(static_array9) == 16);
|
|
|
|
/**
|
|
* @brief Verify run-time non-constant results
|
|
*
|
|
* @ingroup test_pow2_ceil
|
|
*
|
|
* @details Check if run-time non-constant results are as expected.
|
|
* Use a volatile variable to prevent compiler optimizations.
|
|
*/
|
|
|
|
static void test_pow2_ceil_x(unsigned long test_value,
|
|
unsigned long expected_result)
|
|
{
|
|
volatile unsigned int x = test_value;
|
|
unsigned int result = Z_POW2_CEIL(x);
|
|
|
|
zassert_equal(result, expected_result,
|
|
"ZPOW2_CEIL(%lu) returned %lu, expected %lu",
|
|
test_value, result, expected_result);
|
|
}
|
|
|
|
ZTEST(pow2, test_pow2_ceil)
|
|
{
|
|
test_pow2_ceil_x(1, 1);
|
|
test_pow2_ceil_x(2, 2);
|
|
test_pow2_ceil_x(3, 4);
|
|
test_pow2_ceil_x(4, 4);
|
|
test_pow2_ceil_x(5, 8);
|
|
test_pow2_ceil_x(7, 8);
|
|
test_pow2_ceil_x(8, 8);
|
|
test_pow2_ceil_x(9, 16);
|
|
}
|