zephyr/tests/kernel/common/src/main.c
Yong Cong Sin bbe5e1e6eb build: namespace the generated headers with zephyr/
Namespaced the generated headers with `zephyr` to prevent
potential conflict with other headers.

Introduce a temporary Kconfig `LEGACY_GENERATED_INCLUDE_PATH`
that is enabled by default. This allows the developers to
continue the use of the old include paths for the time being
until it is deprecated and eventually removed. The Kconfig will
generate a build-time warning message, similar to the
`CONFIG_TIMER_RANDOM_GENERATOR`.

Updated the includes path of in-tree sources accordingly.

Most of the changes here are scripted, check the PR for more
info.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-05-28 22:03:55 +02:00

79 lines
1.6 KiB
C

/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/ztest.h>
#include <zephyr/kernel_version.h>
#include <zephyr/sys/speculation.h>
#include <zephyr/version.h>
/**
* @defgroup kernel_common_tests Common Tests
* @ingroup all_tests
* @{
* @}
*
*/
#ifndef CONFIG_PRINTK
ZTEST(printk, test_printk)
{
ztest_test_skip();
}
#endif
/**
* @brief Test sys_kernel_version_get() functionality
*
* @ingroup kernel_common_tests
*
* @see sys_kernel_version_get()
*/
ZTEST(common, test_version)
{
uint32_t version = sys_kernel_version_get();
zassert_true(SYS_KERNEL_VER_MAJOR(version) == KERNEL_VERSION_MAJOR,
"major version mismatch");
zassert_true(SYS_KERNEL_VER_MINOR(version) == KERNEL_VERSION_MINOR,
"minor version mismatch");
zassert_true(SYS_KERNEL_VER_PATCHLEVEL(version) == KERNEL_PATCHLEVEL,
"patchlevel version match");
}
ZTEST(common, test_bounds_check_mitigation)
{
/* Very hard to test against speculation attacks, but we can
* at least assert that logically this function does
* what it says it does.
*/
int index = 17;
index = k_array_index_sanitize(index, 24);
zassert_equal(index, 17, "bad index");
#ifdef CONFIG_USERSPACE
index = k_array_index_sanitize(index, 5);
zassert_equal(index, 0, "bad index");
#endif
}
extern struct k_stack eno_stack;
extern struct k_thread eno_thread;
void *common_setup(void)
{
#if CONFIG_USERSPACE
k_thread_access_grant(k_current_get(), &eno_thread, &eno_stack);
#endif
return NULL;
}
ZTEST_SUITE(common, NULL, common_setup, NULL, NULL, NULL);