From a6a8a69f4c908e70193273b36a175b8b55120132 Mon Sep 17 00:00:00 2001 From: Jaime Arteaga Date: Wed, 29 Apr 2020 23:30:53 -0700 Subject: [PATCH] Return build number in Level Zero driverVersion Change-Id: I5c1790b291fe536801bfe4aa5f9ac9b7ed230f66 Signed-off: Jaime Arteaga --- level_zero/CMakeLists.txt | 1 + .../core/source/driver/driver_handle_imp.cpp | 9 +++-- .../unit_tests/sources/driver/CMakeLists.txt | 10 ++++++ .../unit_tests/sources/driver/test_driver.cpp | 33 +++++++++++++++++++ 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 level_zero/core/test/unit_tests/sources/driver/CMakeLists.txt create mode 100644 level_zero/core/test/unit_tests/sources/driver/test_driver.cpp diff --git a/level_zero/CMakeLists.txt b/level_zero/CMakeLists.txt index 5be3047a49..467be1974e 100644 --- a/level_zero/CMakeLists.txt +++ b/level_zero/CMakeLists.txt @@ -42,6 +42,7 @@ if(BUILD_WITH_L0 AND "${NEO_BITS}" STREQUAL "64") add_definitions( -DL0_PROJECT_VERSION_MAJOR="${PROJECT_VERSION_MAJOR}" ) add_definitions( -DL0_PROJECT_VERSION_MINOR="${PROJECT_VERSION_MINOR}" ) + add_definitions( -DNEO_VERSION_BUILD="${NEO_VERSION_BUILD}" ) add_definitions( -DZE_ENABLE_OCL_INTEROP=1) diff --git a/level_zero/core/source/driver/driver_handle_imp.cpp b/level_zero/core/source/driver/driver_handle_imp.cpp index 8bc0af4869..1f59263370 100644 --- a/level_zero/core/source/driver/driver_handle_imp.cpp +++ b/level_zero/core/source/driver/driver_handle_imp.cpp @@ -39,10 +39,13 @@ ze_result_t DriverHandleImp::getApiVersion(ze_api_version_t *version) { } ze_result_t DriverHandleImp::getProperties(ze_driver_properties_t *properties) { - uint32_t versionMajor = (uint32_t)strtoul(L0_PROJECT_VERSION_MAJOR, NULL, 16); - uint32_t versionMinor = (uint32_t)strtoul(L0_PROJECT_VERSION_MINOR, NULL, 16); + uint32_t versionMajor = static_cast(strtoul(L0_PROJECT_VERSION_MAJOR, NULL, 10)); + uint32_t versionMinor = static_cast(strtoul(L0_PROJECT_VERSION_MINOR, NULL, 10)); + uint32_t versionBuild = static_cast(strtoul(NEO_VERSION_BUILD, NULL, 10)); - properties->driverVersion = ZE_MAKE_VERSION(versionMajor, versionMinor); + properties->driverVersion = ((versionMajor << 24) & 0xFF000000) | + ((versionMinor << 16) & 0x00FF0000) | + (versionBuild & 0x0000FFFF); return ZE_RESULT_SUCCESS; } diff --git a/level_zero/core/test/unit_tests/sources/driver/CMakeLists.txt b/level_zero/core/test/unit_tests/sources/driver/CMakeLists.txt new file mode 100644 index 0000000000..3e1a8c3b44 --- /dev/null +++ b/level_zero/core/test/unit_tests/sources/driver/CMakeLists.txt @@ -0,0 +1,10 @@ +# +# Copyright (C) 2020 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +target_sources(${TARGET_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/test_driver.cpp +) \ No newline at end of file diff --git a/level_zero/core/test/unit_tests/sources/driver/test_driver.cpp b/level_zero/core/test/unit_tests/sources/driver/test_driver.cpp new file mode 100644 index 0000000000..c467c68b34 --- /dev/null +++ b/level_zero/core/test/unit_tests/sources/driver/test_driver.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "test.h" + +#include "level_zero/core/source/driver/driver_handle_imp.h" +#include "level_zero/core/test/unit_tests/fixtures/device_fixture.h" + +namespace L0 { +namespace ult { + +using DriverVersionTest = Test; + +TEST_F(DriverVersionTest, returnsExpectedDriverVersion) { + ze_driver_properties_t properties; + ze_result_t res = driverHandle->getProperties(&properties); + EXPECT_EQ(ZE_RESULT_SUCCESS, res); + + uint32_t versionMajor = static_cast((properties.driverVersion & 0xFF000000) >> 24); + uint32_t versionMinor = static_cast((properties.driverVersion & 0x00FF0000) >> 16); + uint32_t versionBuild = static_cast(properties.driverVersion & 0x0000FFFF); + + EXPECT_EQ(static_cast(strtoul(L0_PROJECT_VERSION_MAJOR, NULL, 10)), versionMajor); + EXPECT_EQ(static_cast(strtoul(L0_PROJECT_VERSION_MINOR, NULL, 10)), versionMinor); + EXPECT_EQ(static_cast(strtoul(NEO_VERSION_BUILD, NULL, 10)), versionBuild); +} + +} // namespace ult +} // namespace L0 \ No newline at end of file