feat: first working set
This commit is contained in:
parent
cccebf674a
commit
bed7360063
5 changed files with 59 additions and 42 deletions
|
@ -4,22 +4,39 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace glimpses {
|
||||
#include "glimpses/version.h"
|
||||
|
||||
/**
|
||||
* @brief A class for saying hello in multiple languages
|
||||
*/
|
||||
class Glimpses
|
||||
namespace glimpses
|
||||
{
|
||||
|
||||
/** @brief A class for saying retrieving system information */
|
||||
class Glimpses
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Creates a new glimpses
|
||||
* @param name the name to greet
|
||||
*/
|
||||
/** @brief Type for representing the number of CPU cores. */
|
||||
using CPUCount = uint32_t;
|
||||
|
||||
/** @brief Type for representing a set of CPU cores, mapped by their names. */
|
||||
using CPUSet = std::map<std::string, CPUCount>;
|
||||
|
||||
/** @brief Maximum number of CPU cores supported by Glimpses. */
|
||||
constexpr static CPUCount MAX_CPU_COUNT = 1024;
|
||||
|
||||
/** @brief Version of the Glimpses library. */
|
||||
constexpr static const char *VERSION = GLIMPSES_VERSION;
|
||||
|
||||
/** @brief Creates a new glimpses */
|
||||
Glimpses();
|
||||
|
||||
/**
|
||||
* @brief Returns the number of CPU cores available on the system.
|
||||
* @return The number of CPU cores available on the system.
|
||||
*/
|
||||
CPUSet getCPUCount() const;
|
||||
};
|
||||
|
||||
} // namespace glimpses
|
||||
|
|
|
@ -3,7 +3,25 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
#include <glimpses/glimpses.hpp>
|
||||
#include <sched.h>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
|
||||
using namespace glimpses;
|
||||
|
||||
Glimpses::Glimpses() {}
|
||||
Glimpses::Glimpses()
|
||||
{
|
||||
}
|
||||
|
||||
Glimpses::CPUSet Glimpses::getCPUCount() const
|
||||
{
|
||||
cpu_set_t cpuset;
|
||||
auto minmax = [](int64_t min, int64_t value, int64_t max) -> CPUCount {
|
||||
return std::min(std::max(value, min), max);
|
||||
};
|
||||
sched_getaffinity(0, sizeof(cpuset), &cpuset);
|
||||
return CPUSet{{"configured", minmax(0, sysconf(_SC_NPROCESSORS_CONF), MAX_CPU_COUNT)},
|
||||
{"logical", minmax(0, std::thread::hardware_concurrency(), MAX_CPU_COUNT)},
|
||||
{"online", minmax(0, sysconf(_SC_NPROCESSORS_ONLN), MAX_CPU_COUNT)},
|
||||
{"allowed", minmax(0, CPU_COUNT(&cpuset), MAX_CPU_COUNT)}};
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ include(../cmake/tools.cmake)
|
|||
|
||||
include(../cmake/get_cpm.cmake)
|
||||
|
||||
# CPMAddPackage("gh:doctest/doctest@2.4.9")
|
||||
CPMAddPackage("gh:TheLartians/Format.cmake@1.7.3")
|
||||
CPMAddPackage(NAME Catch2 GITHUB_REPOSITORY catchorg/Catch2 VERSION 3.8.1)
|
||||
CPMAddPackage("gh:TheLartians/Format.cmake@1.8.3")
|
||||
|
||||
if(TEST_INSTALLED_VERSION)
|
||||
find_package(Glimpses REQUIRED)
|
||||
|
@ -31,11 +31,7 @@ endif()
|
|||
|
||||
file(GLOB sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp)
|
||||
add_executable(${PROJECT_NAME} ${sources})
|
||||
target_link_libraries(
|
||||
${PROJECT_NAME}
|
||||
# doctest::doctest
|
||||
Glimpses::Glimpses
|
||||
)
|
||||
target_link_libraries(${PROJECT_NAME} Catch2::Catch2WithMain Glimpses::Glimpses)
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17)
|
||||
|
||||
# enable compiler warnings
|
||||
|
@ -52,6 +48,9 @@ endif()
|
|||
|
||||
enable_testing()
|
||||
|
||||
include(CTest)
|
||||
add_test(GlimpsesTests GlimpsesTests)
|
||||
|
||||
# Note: doctest and similar testing frameworks can automatically configure CMake tests. For other testing frameworks add the tests target
|
||||
# instead: add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})
|
||||
|
||||
|
|
|
@ -2,24 +2,21 @@
|
|||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <glimpses/glimpses.hpp>
|
||||
#include <glimpses/version.h>
|
||||
|
||||
#include <string>
|
||||
/*
|
||||
TEST_CASE("Glimpses") {
|
||||
using namespace greeter;
|
||||
|
||||
Glimpses greeter("Tests");
|
||||
TEST_CASE("CPU count")
|
||||
{
|
||||
|
||||
CHECK(greeter.greet(LanguageCode::EN) == "Hello, Tests!");
|
||||
CHECK(greeter.greet(LanguageCode::DE) == "Hallo Tests!");
|
||||
CHECK(greeter.greet(LanguageCode::ES) == "¡Hola Tests!");
|
||||
CHECK(greeter.greet(LanguageCode::FR) == "Bonjour Tests!");
|
||||
glimpses::Glimpses glimpses{};
|
||||
|
||||
CHECK(glimpses.getCPUCount().size() > 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Glimpses version") {
|
||||
static_assert(std::string_view(GREETER_VERSION) == std::string_view("1.0"));
|
||||
/*
|
||||
TEST_CASE("Glimpses version") { static_assert(std::string_view(GREETER_VERSION) == std::string_view("0.1.0"));
|
||||
CHECK(std::string(GREETER_VERSION) == std::string("1.0"));
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2023 Tobias Schmidl
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
#if 0
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#endif
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue