Skip to content

Commit

Permalink
Add tests for xeon cpu name parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
imwints committed Aug 11, 2024
1 parent 38f9cf0 commit 792f5ca
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
13 changes: 13 additions & 0 deletions tests/cpu_names.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <string>

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";
27 changes: 27 additions & 0 deletions tests/test_parse_xeon_name.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: Apache-2.0

// TODO: Use GTest or Catch or something
#undef NDEBUG
#include <cassert>
#include <optional>
#include <string>

#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);
}

0 comments on commit 792f5ca

Please sign in to comment.