Skip to content

Commit

Permalink
Enable testing with ctest
Browse files Browse the repository at this point in the history
Adds a single loader API test using googletest.

Adds the ZEL_LIBRARY_PATH environment variable, which allows using a
local copy of the loader for the purposes of testing.

Signed-off-by: Lisanna Dettwyler <lisanna.dettwyler@intel.com>
Co-authored-by: Jemale Lockett <jemale.lockett@intel.com>
  • Loading branch information
lisanna-dettwyler and Jemale committed Aug 19, 2024
1 parent c1f6e28 commit 785c6fe
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 100 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/build-quick.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,26 @@ jobs:
-D CMAKE_C_COMPILER_LAUNCHER=ccache \
-D CMAKE_CXX_COMPILER_LAUNCHER=ccache \
-D CMAKE_BUILD_TYPE=Release \
-D BUILD_L0_LOADER_TESTS=1 \
..
make -j$(nproc)
- env:
ZE_ENABLE_LOADER_DEBUG_TRACE: '1'
working-directory: build
run: ctest -V

build-windows:
if: github.repository_owner == 'oneapi-src'
runs-on: [windows-latest]
steps:
- uses: actions/checkout@v3
- name: Build Loader on Latest Windows
shell: pwsh
run: |
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release ..
cmake --build . --config Release
cmake -D BUILD_L0_LOADER_TESTS=1 ..
cmake --build . --config Release
- env:
ZE_ENABLE_LOADER_DEBUG_TRACE: '1'
working-directory: build
run: ctest -C Release -V
19 changes: 18 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ else()
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/third_party/spdlog_headers")
endif()

include(FetchContent)

if(BUILD_L0_LOADER_TESTS)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip
)

# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(googletest)

enable_testing()
endif()

# Update other relevant variables to include the patch
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
set(CMAKE_PROJECT_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
Expand Down Expand Up @@ -206,7 +222,8 @@ add_subdirectory(source)
add_subdirectory(samples)

if(BUILD_L0_LOADER_TESTS)
add_subdirectory(test)
include(CTest)
add_subdirectory(test)
endif()

include("os_release_info.cmake")
Expand Down
24 changes: 17 additions & 7 deletions source/loader/ze_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,24 @@ namespace loader
if (zel_logger->logging_enabled)
zel_logger->get_base_logger()->info("Loader Version {}.{}.{} {}", LOADER_VERSION_MAJOR, LOADER_VERSION_MINOR, LOADER_VERSION_PATCH, LOADER_VERSION_SHA);

add_loader_version();
std::string loaderLibraryPath;
auto loaderLibraryPathEnv = getenv_string("ZEL_LIBRARY_PATH");
if (!loaderLibraryPathEnv.empty()) {
loaderLibraryPath = loaderLibraryPathEnv;
}
#ifdef _WIN32
else {
loaderLibraryPath = readLevelZeroLoaderLibraryPath();
}
#endif
debug_trace_message("Using Loader Library Path: ", loaderLibraryPath);

drivers.reserve( discoveredDrivers.size() + getenv_tobool( "ZE_ENABLE_NULL_DRIVER" ) );
if( getenv_tobool( "ZE_ENABLE_NULL_DRIVER" ) )
{
zel_logger->log_info("Enabling Null Driver");
auto handle = LOAD_DRIVER_LIBRARY( MAKE_LIBRARY_NAME( "ze_null", L0_LOADER_VERSION ) );
auto handle = LOAD_DRIVER_LIBRARY( create_library_path( MAKE_LIBRARY_NAME( "ze_null", L0_LOADER_VERSION ), loaderLibraryPath.c_str()).c_str());
if (debugTraceEnabled) {
std::string message = "ze_null Driver Init";
debug_trace_message(message, "");
Expand All @@ -300,7 +312,7 @@ namespace loader
drivers.rbegin()->name = "ze_null";
} else if (debugTraceEnabled) {
GET_LIBRARY_ERROR(loadLibraryErrorValue);
std::string errorMessage = "Load Library of " + std::string(MAKE_LIBRARY_NAME( "ze_null", L0_LOADER_VERSION )) + " failed with ";
std::string errorMessage = "Load Library of " + create_library_path( MAKE_LIBRARY_NAME( "ze_null", L0_LOADER_VERSION ), loaderLibraryPath.c_str()) + " failed with ";
debug_trace_message(errorMessage, loadLibraryErrorValue);
loadLibraryErrorValue.clear();
}
Expand All @@ -326,15 +338,12 @@ namespace loader
}
}
if(drivers.size()==0){
std::string message = "0 Drivers Discovered";
debug_trace_message(message, "");
zel_logger->log_error("0 Drivers Discovered");
return ZE_RESULT_ERROR_UNINITIALIZED;
}

add_loader_version();
std::string loaderLibraryPath;
#ifdef _WIN32
loaderLibraryPath = readLevelZeroLoaderLibraryPath();
#endif
typedef ze_result_t (ZE_APICALL *getVersion_t)(zel_component_version_t *version);
if( getenv_tobool( "ZE_ENABLE_VALIDATION_LAYER" ) )
{
Expand Down Expand Up @@ -363,6 +372,7 @@ namespace loader
tracingLayerEnabled = true;
}
std::string tracingLayerLibraryPath = create_library_path(MAKE_LAYER_NAME( "ze_tracing_layer" ), loaderLibraryPath.c_str());
debug_trace_message("Tracing Layer Library Path: ", tracingLayerLibraryPath);
tracingLayer = LOAD_DRIVER_LIBRARY( tracingLayerLibraryPath.c_str() );
if(tracingLayer)
{
Expand Down
27 changes: 25 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: MIT
add_subdirectory(layers)
add_subdirectory(test_api)

add_executable(
tests
loader_api.cpp
)
target_include_directories(tests PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_link_libraries(
tests
GTest::gtest_main
${TARGET_LOADER_NAME}
)

# For some reason the MSVC runtime libraries used by googletest and test
# binaries don't match, so force the test binary to use the dynamic runtime.
if(MSVC)
target_compile_options(tests PRIVATE "/MD$<$<CONFIG:Debug>:d>")
endif()

add_test(NAME tests COMMAND tests)
if(MSVC)
get_target_property(binary_dir ${TARGET_LOADER_NAME} RUNTIME_OUTPUT_DIRECTORY)
else()
get_target_property(binary_dir ${TARGET_LOADER_NAME} LIBRARY_OUTPUT_DIRECTORY)
endif()
set_property(TEST tests PROPERTY ENVIRONMENT "ZEL_LIBRARY_PATH=${binary_dir};ZE_ENABLE_NULL_DRIVER=1")
3 changes: 0 additions & 3 deletions test/layers/CMakeLists.txt

This file was deleted.

3 changes: 0 additions & 3 deletions test/layers/validation/CMakeLists.txt

This file was deleted.

This file was deleted.

45 changes: 45 additions & 0 deletions test/loader_api.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
*
* Copyright (C) 2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/

#include "gtest/gtest.h"

#include "loader/ze_loader.h"
#include "ze_api.h"

namespace {

TEST(
LoaderAPI,
GivenLevelZeroLoaderPresentWhenCallingzeGetLoaderVersionsAPIThenValidVersionIsReturned) {

EXPECT_EQ(ZE_RESULT_SUCCESS, zeInit(0));

size_t size = 0;
EXPECT_EQ(ZE_RESULT_SUCCESS, zelLoaderGetVersions(&size, nullptr));
EXPECT_GT(size, 0);

std::vector<zel_component_version_t> versions(size);
EXPECT_EQ(ZE_RESULT_SUCCESS, zelLoaderGetVersions(&size, versions.data()));

std::cout << "Found " << versions.size() << " versions" << std::endl;
std::cout << std::endl;
const std::string loader_name = "loader";
for (auto &component : versions) {
std::cout << "component.component_name: " << component.component_name << std::endl;
std::cout << "component.component_lib_version.major: " << component.component_lib_version.major << std::endl;
std::cout << "component.spec_version: " << component.spec_version << std::endl;
std::cout << "component.component_lib_name: " << component.component_name << std::endl;
std::cout << std::endl;

if (loader_name == component.component_name) {
EXPECT_GE(component.component_lib_version.major, 1);
}
}
}

} // namespace
17 changes: 0 additions & 17 deletions test/test_api/CMakeLists.txt

This file was deleted.

19 changes: 0 additions & 19 deletions test/test_api/src/main.cpp

This file was deleted.

43 changes: 0 additions & 43 deletions test/test_api/src/test_api.cpp

This file was deleted.

0 comments on commit 785c6fe

Please sign in to comment.