Skip to content

Commit

Permalink
Enable test_api unit test to run in build-quick.yml
Browse files Browse the repository at this point in the history
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 18, 2024
1 parent 35fa646 commit 0600e4f
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 48 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/build-quick.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,24 @@ 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:
LD_LIBRARY_PATH: build/lib
ZE_ENABLE_NULL_DRIVER: '1'
run: ./build/bin/test_loader_api
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 CMAKE_BUILD_TYPE=Release -D BUILD_L0_LOADER_TESTS=1 ..
cmake --build . --config Release
- env:
ZE_ENABLE_NULL_DRIVER: '1'
run: ./build/bin/Release/test_loader_api.exe
16 changes: 16 additions & 0 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
28 changes: 15 additions & 13 deletions test/test_api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: MIT

# function(add_test)
add_executable(
test_loader_api
src/test_api.cpp
)
target_include_directories(test_loader_api PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_link_libraries(
test_loader_api
GTest::gtest_main
${TARGET_LOADER_NAME}
)

# endfunction()

# add_loader_test(
# NAME test_loader_api
# GROUP "/layer_tests/loader_api"
# SOURCES
# src/test_loader_api.cpp
# src/main.cpp
# LINK_LIBRARIES
# level_zero_tests::logging
# level_zero_tests::utils
# )
# 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(test_loader_api PRIVATE "/MD$<$<CONFIG:Debug>:d>")
endif()
19 changes: 0 additions & 19 deletions test/test_api/src/main.cpp

This file was deleted.

28 changes: 15 additions & 13 deletions test/test_api/src/test_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,35 @@

#include "gtest/gtest.h"

#include "logging/logging.hpp"
#include "test_harness/test_harness.hpp"
#include <level_zero/loader/ze_loader.h>
#include <level_zero/ze_api.h>

namespace lzt = level_zero_tests;
#include "loader/ze_loader.h"
#include "ze_api.h"

namespace {

TEST(
LoaderTest,
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;

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) {
LOG_INFO << "component.component_name: " << component.component_name;
LOG_INFO << " " << component.component_lib_version.major;
LOG_INFO << "component.spec_version: " << component.spec_version;
LOG_INFO << "component.component_lib_name: " << component.component_name;
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" == component.component_name) {
if (loader_name == component.component_name) {
EXPECT_GE(component.component_lib_version.major, 1);
}
}
Expand Down

0 comments on commit 0600e4f

Please sign in to comment.