2023-08-28 12:31:18 +02:00
|
|
|
/* Unit tests for kernel functions.
|
2018-08-22 11:29:39 +02:00
|
|
|
*
|
2023-08-31 11:17:07 +02:00
|
|
|
* Author: Steffen Vogel <post@steffenvogel.de>
|
|
|
|
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2023-08-28 12:31:18 +02:00
|
|
|
*/
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2024-03-12 10:07:00 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2018-08-22 11:29:39 +02:00
|
|
|
#include <criterion/criterion.h>
|
|
|
|
|
2018-10-19 16:31:51 +02:00
|
|
|
#include <villas/kernel/kernel.hpp>
|
2024-03-12 10:36:03 +00:00
|
|
|
#include <villas/utils.hpp>
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2019-10-27 20:23:47 +01:00
|
|
|
using namespace villas::kernel;
|
|
|
|
|
2020-09-11 15:16:53 +02:00
|
|
|
// cppcheck-suppress unknownMacro
|
2018-10-19 14:33:10 +02:00
|
|
|
TestSuite(kernel, .description = "Kernel features");
|
2018-08-23 13:14:39 +02:00
|
|
|
|
2018-08-22 11:29:39 +02:00
|
|
|
#if defined(__x86_64__) || defined(__i386__)
|
2023-09-07 13:19:19 +02:00
|
|
|
#define PAGESIZE (1 << 12)
|
|
|
|
#define CACHELINESIZE 64
|
|
|
|
|
|
|
|
#if defined(__x86_64__)
|
|
|
|
#define HUGEPAGESIZE (1 << 21)
|
|
|
|
#elif defined(__i386__)
|
|
|
|
#define HUGEPAGESIZE (1 << 22)
|
|
|
|
#endif
|
2018-08-22 11:29:39 +02:00
|
|
|
#else
|
2023-09-07 13:19:19 +02:00
|
|
|
#error "Unsupported architecture"
|
2018-08-22 11:29:39 +02:00
|
|
|
#endif
|
|
|
|
|
2022-12-02 17:16:44 +01:00
|
|
|
// This test is not portable, but we currently support x86 only
|
2023-09-07 13:19:19 +02:00
|
|
|
Test(kernel, sizes) {
|
|
|
|
int sz;
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2023-09-07 13:19:19 +02:00
|
|
|
sz = getPageSize();
|
|
|
|
cr_assert_eq(sz, PAGESIZE);
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2023-09-07 13:19:19 +02:00
|
|
|
sz = getHugePageSize();
|
|
|
|
cr_assert(sz == HUGEPAGESIZE);
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2023-09-07 13:19:19 +02:00
|
|
|
sz = getCachelineSize();
|
|
|
|
cr_assert_eq(sz, CACHELINESIZE);
|
2018-08-22 11:29:39 +02:00
|
|
|
}
|
|
|
|
|
2018-10-21 20:25:07 +01:00
|
|
|
#ifdef __linux__
|
2023-09-07 13:19:19 +02:00
|
|
|
Test(kernel, hugepages) {
|
|
|
|
int ret;
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2024-03-12 10:36:03 +00:00
|
|
|
if (!villas::utils::isPrivileged()) {
|
2024-03-12 10:07:00 +00:00
|
|
|
cr_skip("Super-user permissions required.");
|
|
|
|
}
|
|
|
|
|
2023-09-07 13:19:19 +02:00
|
|
|
ret = setNrHugepages(25);
|
|
|
|
cr_assert_eq(ret, 0);
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2023-09-07 13:19:19 +02:00
|
|
|
ret = getNrHugepages();
|
|
|
|
cr_assert_eq(ret, 25);
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2023-09-07 13:19:19 +02:00
|
|
|
ret = setNrHugepages(10);
|
|
|
|
cr_assert_eq(ret, 0);
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2023-09-07 13:19:19 +02:00
|
|
|
ret = getNrHugepages();
|
|
|
|
cr_assert_eq(ret, 10);
|
2018-08-22 11:29:39 +02:00
|
|
|
}
|
|
|
|
|
2023-09-07 13:19:19 +02:00
|
|
|
Test(kernel, version) {
|
|
|
|
using villas::utils::Version;
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2023-09-07 13:19:19 +02:00
|
|
|
Version ver = villas::kernel::getVersion();
|
|
|
|
Version ver1 = {100, 5};
|
|
|
|
Version ver2 = {2, 6};
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2023-09-07 13:19:19 +02:00
|
|
|
cr_assert_lt(ver, ver1);
|
|
|
|
cr_assert_gt(ver, ver2);
|
2018-08-22 11:29:39 +02:00
|
|
|
}
|
|
|
|
|
2023-09-07 13:19:19 +02:00
|
|
|
Test(kernel, module, .disabled = true) {
|
|
|
|
int ret;
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2023-09-07 13:19:19 +02:00
|
|
|
ret = isModuleLoaded("nf_nat");
|
|
|
|
cr_assert_eq(ret, 0);
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2023-09-07 13:19:19 +02:00
|
|
|
ret = isModuleLoaded("does_not_exist");
|
|
|
|
cr_assert_neq(ret, 0);
|
2018-08-22 11:29:39 +02:00
|
|
|
}
|
|
|
|
|
2023-09-07 13:19:19 +02:00
|
|
|
Test(kernel, frequency) {
|
|
|
|
int ret;
|
|
|
|
uint64_t freq;
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2023-09-07 13:19:19 +02:00
|
|
|
ret = get_cpu_frequency(&freq);
|
|
|
|
cr_assert_eq(ret, 0);
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2023-09-07 13:19:19 +02:00
|
|
|
// Check for plausability only
|
|
|
|
cr_assert(freq > 1e9 && freq < 5e9);
|
2018-08-22 11:29:39 +02:00
|
|
|
}
|
2018-10-21 20:25:07 +01:00
|
|
|
#endif
|