From 792f5cac90d796dc4646761904ea6dcf5e4e9a9d Mon Sep 17 00:00:00 2001 From: Steffen Winter Date: Sun, 11 Aug 2024 22:20:34 +0200 Subject: [PATCH] Add tests for xeon cpu name parsing --- CMakeLists.txt | 5 +++++ tests/CMakeLists.txt | 6 ++++++ tests/cpu_names.hpp | 13 +++++++++++++ tests/test_parse_xeon_name.cpp | 27 +++++++++++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/cpu_names.hpp create mode 100644 tests/test_parse_xeon_name.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d7cfe6080..701b279e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -241,6 +241,11 @@ else() message(WARNING "Command 'lowdown' not found: skipping generating man page btop.1") endif() +include(CTest) +if(BUILD_TESTING) + add_subdirectory(tests) +endif() + install(TARGETS btop RUNTIME) install(FILES "btop.desktop" DESTINATION "share/applications") install(FILES "Img/icon.png" DESTINATION "share/icons/hicolor/48x48/apps" RENAME "btop.png") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 000000000..a65481708 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: Apache-2.0 + +include_directories(${PROJECT_SOURCE_DIR}/src) + +add_executable(test_parse_xeon_name test_parse_xeon_name.cpp ${PROJECT_SOURCE_DIR}/src/linux/parse_cpu_names.cpp) +add_test(parse_xeon_name test_parse_xeon_name) diff --git a/tests/cpu_names.hpp b/tests/cpu_names.hpp new file mode 100644 index 000000000..51820d97e --- /dev/null +++ b/tests/cpu_names.hpp @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +const static std::string xeon_E5_2623_v3 = "Intel(R) Xeon(R) CPU E5-2623 v3 @ 3.00GHz"; +const static std::string xeon_gold_6240 = "Intel(R) Xeon(R) Gold 6240 CPU @ 2.60GHz"; +const static std::string xeon_gold_6338N = "Intel(R) Xeon(R) Gold 6338N CPU @ 2.20GHz"; + +const static std::string core_i9_13900H = "13th Gen Intel(R) Core(TM) i9-13900H"; + +const static std::string pentium_III = "Intel(R) Pentium(R) III CPU family 1400MHz"; diff --git a/tests/test_parse_xeon_name.cpp b/tests/test_parse_xeon_name.cpp new file mode 100644 index 000000000..c32d80b8b --- /dev/null +++ b/tests/test_parse_xeon_name.cpp @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: Apache-2.0 + +// TODO: Use GTest or Catch or something +#undef NDEBUG +#include +#include +#include + +#include "cpu_names.hpp" +#include "linux/parse_cpu_names.hpp" + +auto main() -> int { + auto result = parse_xeon_name(xeon_E5_2623_v3); + assert(result.value() == "E5-2623 v3"); + + result = parse_xeon_name(xeon_gold_6240); + assert(result.value() == "Gold 6240"); + + result = parse_xeon_name(xeon_gold_6338N); + assert(result.value() == "Gold 6338N"); + + result = parse_xeon_name(core_i9_13900H); + assert(result == std::nullopt); + + result = parse_xeon_name(pentium_III); + assert(result == std::nullopt); +}