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 Jul 29, 2024
1 parent 35fa646 commit 3af58ae
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 102 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/build-quick.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,23 @@ jobs:
-D CMAKE_BUILD_TYPE=Release \
..
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 ..
cmake --build . --config Release
- env:
ZE_ENABLE_LOADER_DEBUG_TRACE: '1'
working-directory: build
run: ctest -C Release -V
21 changes: 18 additions & 3 deletions 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 @@ -205,9 +221,8 @@ set(TARGET_LOADER_NAME ze_loader)
add_subdirectory(source)
add_subdirectory(samples)

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

include("os_release_info.cmake")
get_os_release_info(os_name os_version os_codename)
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 @@ -282,12 +282,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 @@ -299,7 +311,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 @@ -325,15 +337,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 @@ -362,6 +371,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
23 changes: 21 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
# 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)
get_target_property(binary_dir ${TARGET_LOADER_NAME} RUNTIME_OUTPUT_DIRECTORY)
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 3af58ae

Please sign in to comment.