Skip to content

Chore/utils unitests #1400

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 18 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
abb5d7f
fix/mistral-nemo-chat-template
nguyenhoangthuan99 Sep 25, 2024
bf8fc8f
Merge branch 'dev' of github.com:janhq/cortex.cpp into dev
nguyenhoangthuan99 Sep 26, 2024
efaf823
Merge branch 'dev' of github.com:janhq/cortex.cpp into dev
nguyenhoangthuan99 Sep 30, 2024
3819573
Merge branch 'dev' of github.com:janhq/cortex.cpp into dev
nguyenhoangthuan99 Sep 30, 2024
2c6c75f
Merge branch 'dev' of github.com:janhq/cortex.cpp into dev
nguyenhoangthuan99 Sep 30, 2024
3c49bc0
Merge branch 'dev' of github.com:janhq/cortex.cpp into dev
nguyenhoangthuan99 Oct 1, 2024
b3d63bb
Merge branch 'dev' of github.com:janhq/cortex.cpp into dev
nguyenhoangthuan99 Oct 1, 2024
b31da0f
Merge branch 'dev' of github.com:janhq/cortex.cpp into dev
nguyenhoangthuan99 Oct 1, 2024
4174187
Merge branch 'dev' of github.com:janhq/cortex.cpp into dev
nguyenhoangthuan99 Oct 1, 2024
59bc889
Merge branch 'dev' of github.com:janhq/cortex.cpp into dev
nguyenhoangthuan99 Oct 1, 2024
011161a
Merge branch 'dev' of github.com:janhq/cortex.cpp into dev
nguyenhoangthuan99 Oct 2, 2024
c0498d7
Merge branch 'dev' of github.com:janhq/cortex.cpp into dev
nguyenhoangthuan99 Oct 2, 2024
c81aa28
Merge branch 'dev' of github.com:janhq/cortex.cpp into dev
nguyenhoangthuan99 Oct 3, 2024
3126a41
Merge branch 'dev' of github.com:janhq/cortex.cpp into dev
nguyenhoangthuan99 Oct 3, 2024
67c2a8a
chore: add unitest for file manager utils and yaml config utils
nguyenhoangthuan99 Oct 3, 2024
b3db890
chore: add unitest for cuda toolkit utils and semantic version utils
nguyenhoangthuan99 Oct 3, 2024
c9817c1
Merge branch 'dev' into chore/utils-unitests
nguyenhoangthuan99 Oct 3, 2024
500abd0
Merge branch 'dev' into chore/utils-unitests
nguyenhoangthuan99 Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion engine/test/components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ find_package(LibArchive REQUIRED)
find_package(CURL REQUIRED)
find_package(SQLiteCpp REQUIRED)

target_link_libraries(${PROJECT_NAME} PRIVATE Drogon::Drogon GTest::gtest GTest::gtest_main yaml-cpp::yaml-cpp
target_link_libraries(${PROJECT_NAME} PRIVATE Drogon::Drogon GTest::gtest GTest::gtest_main yaml-cpp::yaml-cpp
${CMAKE_THREAD_LIBS_INIT})

target_link_libraries(${PROJECT_NAME} PRIVATE httplib::httplib)
Expand Down
43 changes: 43 additions & 0 deletions engine/test/components/test_cuda_toolkit_utils.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <gtest/gtest.h>
#include "utils/cuda_toolkit_utils.h"

// Test fixture for cuda_toolkit_utils
class CudaToolkitUtilsTest : public ::testing::Test {};

// Tests for cuda_toolkit_utils

TEST_F(CudaToolkitUtilsTest, WindowsCompatibleVersions) {
EXPECT_EQ("12.4", cuda_toolkit_utils::GetCompatibleCudaToolkitVersion(
"527.41", "windows", ""));
EXPECT_EQ("11.7", cuda_toolkit_utils::GetCompatibleCudaToolkitVersion(
"452.39", "windows", ""));
}

TEST_F(CudaToolkitUtilsTest, LinuxCompatibleVersions) {
EXPECT_EQ("12.4", cuda_toolkit_utils::GetCompatibleCudaToolkitVersion(
"525.60.13", "linux", ""));
EXPECT_EQ("11.7", cuda_toolkit_utils::GetCompatibleCudaToolkitVersion(
"450.80.02", "linux", ""));
}

TEST_F(CudaToolkitUtilsTest, TensorRTLLMEngine) {
EXPECT_EQ("12.4", cuda_toolkit_utils::GetCompatibleCudaToolkitVersion(
"527.41", "windows", "cortex.tensorrt-llm"));
EXPECT_EQ("12.4", cuda_toolkit_utils::GetCompatibleCudaToolkitVersion(
"525.60.13", "linux", "cortex.tensorrt-llm"));
}

TEST_F(CudaToolkitUtilsTest, UnsupportedDriverVersion) {
EXPECT_THROW(cuda_toolkit_utils::GetCompatibleCudaToolkitVersion(
"450.00", "windows", ""),
std::runtime_error);
EXPECT_THROW(cuda_toolkit_utils::GetCompatibleCudaToolkitVersion("450.00",
"linux", ""),
std::runtime_error);
}

TEST_F(CudaToolkitUtilsTest, UnsupportedOS) {
EXPECT_THROW(cuda_toolkit_utils::GetCompatibleCudaToolkitVersion("527.41",
"macos", ""),
std::runtime_error);
}
94 changes: 94 additions & 0 deletions engine/test/components/test_file_manager_config_yaml_utils.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <filesystem>
#include "utils/config_yaml_utils.h"
#include "utils/file_manager_utils.h"

// Mock for filesystem operations

// Test fixture
class FileManagerConfigTest : public ::testing::Test {};

// Tests for file_manager_utils

TEST_F(FileManagerConfigTest, GetExecutableFolderContainerPath) {
auto path = file_manager_utils::GetExecutableFolderContainerPath();
EXPECT_FALSE(path.empty());
EXPECT_TRUE(std::filesystem::is_directory(path));
}

TEST_F(FileManagerConfigTest, GetHomeDirectoryPath) {
auto path = file_manager_utils::GetHomeDirectoryPath();
EXPECT_FALSE(path.empty());
EXPECT_TRUE(std::filesystem::is_directory(path));
}

TEST_F(FileManagerConfigTest, GetConfigurationPath) {
auto path = file_manager_utils::GetConfigurationPath();
EXPECT_FALSE(path.empty());
EXPECT_TRUE(path.has_filename());
}

TEST_F(FileManagerConfigTest, GetDefaultDataFolderName) {
auto folder_name = file_manager_utils::GetDefaultDataFolderName();
EXPECT_FALSE(folder_name.empty());
EXPECT_TRUE(folder_name.find("cortexcpp") != std::string::npos);
}

TEST_F(FileManagerConfigTest, CreateConfigFileIfNotExist) {

file_manager_utils::CreateConfigFileIfNotExist();
EXPECT_TRUE(
std::filesystem::exists(file_manager_utils::GetConfigurationPath()));
std::filesystem::remove(file_manager_utils::GetConfigurationPath());
}

TEST_F(FileManagerConfigTest, GetCortexConfig) {
file_manager_utils::CreateConfigFileIfNotExist();
auto config = file_manager_utils::GetCortexConfig();
EXPECT_FALSE(config.dataFolderPath.empty());
EXPECT_FALSE(config.logFolderPath.empty());
EXPECT_GT(config.maxLogLines, 0);
}

// Tests for config_yaml_utils

TEST_F(FileManagerConfigTest, DumpYamlConfig) {
config_yaml_utils::CortexConfig config{.logFolderPath = "/path/to/logs",
.dataFolderPath = "/path/to/data",
.maxLogLines = 1000,
.apiServerHost = "localhost",
.apiServerPort = "8080"};

std::string test_file = "test_config.yaml";
config_yaml_utils::DumpYamlConfig(config, test_file);

EXPECT_TRUE(std::filesystem::exists(test_file));

// Clean up
std::filesystem::remove(test_file);
}

TEST_F(FileManagerConfigTest, FromYaml) {
// Create a test YAML file
std::string test_file = "test_config.yaml";
std::ofstream out_file(test_file);
out_file << "logFolderPath: /path/to/logs\n"
<< "dataFolderPath: /path/to/data\n"
<< "maxLogLines: 1000\n"
<< "apiServerHost: localhost\n"
<< "apiServerPort: '8080'\n";
out_file.close();

config_yaml_utils::CortexConfig default_config{};
auto config = config_yaml_utils::FromYaml(test_file, default_config);

EXPECT_EQ(config.logFolderPath, "/path/to/logs");
EXPECT_EQ(config.dataFolderPath, "/path/to/data");
EXPECT_EQ(config.maxLogLines, 1000);
EXPECT_EQ(config.apiServerHost, "localhost");
EXPECT_EQ(config.apiServerPort, "8080");

// Clean up
std::filesystem::remove(test_file);
}
43 changes: 43 additions & 0 deletions engine/test/components/test_semantic_version.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <gtest/gtest.h>
#include "utils/semantic_version_utils.h"

class SemanticVersionUtilsTest : public ::testing::Test {
protected:
void SetUp() override {
// Setup code if needed
}

void TearDown() override {
// Teardown code if needed
}
};

// Tests for semantic_version_utils

TEST_F(SemanticVersionUtilsTest, SplitVersion) {
auto version = semantic_version_utils::SplitVersion("1.2.3");
EXPECT_EQ(1, version.major);
EXPECT_EQ(2, version.minor);
EXPECT_EQ(3, version.patch);
}

TEST_F(SemanticVersionUtilsTest, SplitVersionPartial) {
auto version = semantic_version_utils::SplitVersion("1.2");
EXPECT_EQ(1, version.major);
EXPECT_EQ(2, version.minor);
EXPECT_EQ(0, version.patch);
}

TEST_F(SemanticVersionUtilsTest, SplitVersionEmpty) {
auto version = semantic_version_utils::SplitVersion("");
EXPECT_EQ(0, version.major);
EXPECT_EQ(0, version.minor);
EXPECT_EQ(0, version.patch);
}

TEST_F(SemanticVersionUtilsTest, CompareSemanticVersion) {
EXPECT_EQ(0, semantic_version_utils::CompareSemanticVersion("1.2.3", "1.2.3"));
EXPECT_EQ(-1, semantic_version_utils::CompareSemanticVersion("1.2.3", "1.2.4"));
EXPECT_EQ(1, semantic_version_utils::CompareSemanticVersion("1.3.0", "1.2.9"));
EXPECT_EQ(-1, semantic_version_utils::CompareSemanticVersion("1.9.9", "2.0.0"));
}
Loading