Modify makro HWTEST2_F and HWTEST2_P

to not call SetUp and TearDown when not matched

Change-Id: I00b43a738fa3b33ba743f4f92f8ee16674bf9a50
Signed-off-by: Katarzyna Cencelewska <katarzyna.cencelewska@intel.com>
This commit is contained in:
Katarzyna Cencelewska 2020-05-22 14:38:08 +02:00
parent d6fb463f16
commit f4759425b9
15 changed files with 129 additions and 12 deletions

View File

@ -78,7 +78,7 @@ target_include_directories(${TARGET_NAME}
$<TARGET_PROPERTY:${TARGET_NAME_L0},SOURCE_DIR>/tools
$<TARGET_PROPERTY:${TARGET_NAME_L0},SOURCE_DIR>/../../../../instrumentation/inc/common/instrumentation/api/
$<TARGET_PROPERTY:${TARGET_NAME_L0},SOURCE_DIR>/core/os_interface
${NEO_SHARED_TEST_DIRECTORY}/unit_test/test_macros${BRANCH_DIR_SUFFIX}
${NEO_SHARED_TEST_DIRECTORY}/unit_test/test_macros/header${BRANCH_DIR_SUFFIX}
)
if (UNIX)

View File

@ -113,6 +113,7 @@ HWTEST2_F(ImageCreate, givenValidImageDescriptionWhenImageCreateThenImageIsCreat
}
class TestImageFormats : public DeviceFixture, public testing::TestWithParam<std::pair<ze_image_format_layout_t, ze_image_format_type_t>> {
public:
void SetUp() override {
DeviceFixture::SetUp();
}

View File

@ -37,7 +37,15 @@ class SamplerCreateTest
: public Test<DeviceFixture>,
public ::testing::WithParamInterface<std::tuple<ze_sampler_address_mode_t,
ze_sampler_filter_mode_t,
ze_bool_t>> {};
ze_bool_t>> {
public:
void SetUp() {
Test<DeviceFixture>::SetUp();
}
void TearDown() {
Test<DeviceFixture>::TearDown();
}
};
HWTEST2_P(SamplerCreateTest, givenDifferentDescriptorValuesThenSamplerIsCorrectlyCreated, SamplerCreateSupport) {
using SAMPLER_STATE = typename FamilyType::SAMPLER_STATE;

View File

@ -71,7 +71,7 @@ target_include_directories(${TARGET_NAME}
BEFORE
PRIVATE
$<TARGET_PROPERTY:${TARGET_NAME_L0},SOURCE_DIR>/tools
${NEO_SHARED_TEST_DIRECTORY}/unit_test/test_macros${BRANCH_DIR_SUFFIX}
${NEO_SHARED_TEST_DIRECTORY}/unit_test/test_macros/header${BRANCH_DIR_SUFFIX}
)
if (UNIX)

View File

@ -188,7 +188,7 @@ set_target_properties(unit_tests PROPERTIES FOLDER ${OPENCL_TEST_PROJECTS_FOLDER
set_target_properties(prepare_test_kernels PROPERTIES FOLDER ${OPENCL_TEST_PROJECTS_FOLDER})
set_target_properties(run_unit_tests PROPERTIES FOLDER ${OPENCL_TEST_PROJECTS_FOLDER})
target_include_directories(igdrcl_tests BEFORE PRIVATE ${NEO_SHARED_TEST_DIRECTORY}/unit_test/test_macros${BRANCH_DIR_SUFFIX})
target_include_directories(igdrcl_tests BEFORE PRIVATE ${NEO_SHARED_TEST_DIRECTORY}/unit_test/test_macros/header${BRANCH_DIR_SUFFIX})
if(NOT DEFINED cloc_cmd_prefix)
if(WIN32)

View File

@ -81,6 +81,6 @@ else()
${NEO_SHARED_DIRECTORY}/os_interface/windows/gmm_interface_win.cpp
)
endif()
target_include_directories(igdrcl_aub_tests BEFORE PRIVATE ${NEO_SHARED_TEST_DIRECTORY}/unit_test/test_macros${BRANCH_DIR_SUFFIX})
target_include_directories(igdrcl_aub_tests BEFORE PRIVATE ${NEO_SHARED_TEST_DIRECTORY}/unit_test/test_macros/header${BRANCH_DIR_SUFFIX})
create_project_source_tree(igdrcl_aub_tests)

View File

@ -11,7 +11,7 @@ set(IGDRCL_SRCS_tests_gen_common
${CMAKE_CURRENT_SOURCE_DIR}/gen_commands_common_validation.h
${CMAKE_CURRENT_SOURCE_DIR}/hw_cmds_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/matchers.h
${NEO_SHARED_TEST_DIRECTORY}/unit_test/test_macros${BRANCH_DIR_SUFFIX}/test.h
${NEO_SHARED_TEST_DIRECTORY}/unit_test/test_macros/header${BRANCH_DIR_SUFFIX}/test.h
)
target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_gen_common})

View File

@ -37,7 +37,7 @@ target_link_libraries(igdrcl_${target_name} ${NEO_STATICALLY_LINKED_LIBRARIES_MO
set_property(TARGET igdrcl_${target_name} APPEND_STRING PROPERTY COMPILE_FLAGS ${ASAN_FLAGS})
target_include_directories(igdrcl_${target_name} PRIVATE
${NEO_SHARED_TEST_DIRECTORY}/unit_test/test_macros${BRANCH_DIR_SUFFIX}
${NEO_SHARED_TEST_DIRECTORY}/unit_test/test_macros/header${BRANCH_DIR_SUFFIX}
${NEO_SOURCE_DIR}/opencl/source/dll/linux/devices${BRANCH_DIR_SUFFIX}
${NEO_SOURCE_DIR}/opencl/test/unit_test/gen_common${BRANCH_DIR_SUFFIX}
${CMAKE_CURRENT_SOURCE_DIR}

View File

@ -30,7 +30,7 @@ add_executable(igdrcl_mt_tests EXCLUDE_FROM_ALL
target_include_directories(igdrcl_mt_tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${NEO_SHARED_TEST_DIRECTORY}/unit_test/test_macros${BRANCH_DIR_SUFFIX}
${NEO_SHARED_TEST_DIRECTORY}/unit_test/test_macros/header${BRANCH_DIR_SUFFIX}
${NEO_SOURCE_DIR}/opencl/source/gen_common
)

View File

@ -35,4 +35,4 @@ bool TestChecks::supportsDeviceEnqueue(const Context *pContext) {
}
bool TestChecks::supportsDeviceEnqueue(const std::unique_ptr<HardwareInfo> &pHardwareInfo) {
return pHardwareInfo->capabilityTable.supportsDeviceEnqueue;
}
}

View File

@ -30,7 +30,7 @@ add_executable(igdrcl_windows_dll_tests
target_link_libraries(igdrcl_windows_dll_tests ${NEO_MOCKABLE_LIB_NAME} ${NEO_SHARED_MOCKABLE_LIB_NAME} igdrcl_mocks gmock-gtest ${IGDRCL_EXTRA_LIBS})
target_include_directories(igdrcl_windows_dll_tests PRIVATE
${NEO_SHARED_TEST_DIRECTORY}/unit_test/test_macros${BRANCH_DIR_SUFFIX}
${NEO_SHARED_TEST_DIRECTORY}/unit_test/test_macros/header${BRANCH_DIR_SUFFIX}
${NEO_SOURCE_DIR}/opencl/test/unit_test/gen_common${BRANCH_DIR_SUFFIX}
${CMAKE_CURRENT_SOURCE_DIR}
)

View File

@ -85,7 +85,7 @@ set_property(TARGET ${TARGET_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${ASAN_F
target_include_directories(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${ENGINE_NODE_DIR}
${NEO_SHARED_TEST_DIRECTORY}/unit_test/test_macros${BRANCH_DIR_SUFFIX}
${NEO_SHARED_TEST_DIRECTORY}/unit_test/test_macros/header${BRANCH_DIR_SUFFIX}
)
if (UNIX)

View File

@ -6,6 +6,7 @@
set(NEO_CORE_test_macros
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/header${BRANCH_DIR_SUFFIX}/test.h
${CMAKE_CURRENT_SOURCE_DIR}/test_checks_shared.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_checks_shared.h
)

View File

@ -231,7 +231,21 @@ extern GFXCORE_FAMILY renderCoreFamily;
template <unsigned int matcherOrdinal> \
void checkForMatch(PRODUCT_FAMILY matchProduct); \
\
template <unsigned int matcherOrdinal> \
bool checkMatch(PRODUCT_FAMILY matchProduct); \
\
void SetUp() override { \
if (checkMatch<SupportedProductFamilies::size - 1u>(::productFamily)) { \
parent_class::SetUp(); \
} \
} \
void TearDown() override { \
if (checkMatch<SupportedProductFamilies::size - 1u>(::productFamily)) { \
parent_class::TearDown(); \
} \
} \
void TestBody() override; \
\
static ::testing::TestInfo *const test_info_ GTEST_ATTRIBUTE_UNUSED_; \
GTEST_DISALLOW_COPY_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)); \
}; \
@ -276,6 +290,32 @@ extern GFXCORE_FAMILY renderCoreFamily;
MatcherFalse>::type; \
Matcher::template matched<productFamily>(); \
} \
} \
template <unsigned int matcherOrdinal> \
bool GTEST_TEST_CLASS_NAME_(test_suite_name, \
test_name)::checkMatch(PRODUCT_FAMILY matchProduct) { \
const PRODUCT_FAMILY productFamily = At<ContainerType, matcherOrdinal>::productFamily; \
\
if (matchProduct == productFamily) { \
const bool isMatched = MatcherType::isMatched<productFamily>(); \
return isMatched; \
} else { \
return checkMatch<matcherOrdinal - 1u>(matchProduct); \
} \
} \
\
template <> \
bool GTEST_TEST_CLASS_NAME_(test_suite_name, \
test_name)::checkMatch<0>(PRODUCT_FAMILY matchProduct) { \
const int matcherOrdinal = 0u; \
const PRODUCT_FAMILY productFamily = At<ContainerType, matcherOrdinal>::productFamily; \
\
if (matchProduct == productFamily) { \
const bool isMatched = MatcherType::isMatched<productFamily>(); \
return isMatched; \
} else { \
return false; \
} \
} \
\
void GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::TestBody() { \
@ -600,7 +640,21 @@ extern GFXCORE_FAMILY renderCoreFamily;
template <unsigned int matcherOrdinal> \
void checkForMatch(PRODUCT_FAMILY matchProduct); \
\
virtual void TestBody(); \
template <unsigned int matcherOrdinal> \
bool checkMatch(PRODUCT_FAMILY matchProduct); \
\
void SetUp() override { \
if (checkMatch<SupportedProductFamilies::size - 1u>(::productFamily)) { \
test_suite_name::SetUp(); \
} \
} \
void TearDown() override { \
if (checkMatch<SupportedProductFamilies::size - 1u>(::productFamily)) { \
test_suite_name::TearDown(); \
} \
} \
\
void TestBody() override; \
\
static int AddToRegistry() { \
::testing::UnitTest::GetInstance() \
@ -647,6 +701,32 @@ extern GFXCORE_FAMILY renderCoreFamily;
MatcherFalse>::type; \
Matcher::template matched<productFamily>(); \
} \
} \
template <unsigned int matcherOrdinal> \
bool GTEST_TEST_CLASS_NAME_(test_suite_name, \
test_name)::checkMatch(PRODUCT_FAMILY matchProduct) { \
const PRODUCT_FAMILY productFamily = At<ContainerType, matcherOrdinal>::productFamily; \
\
if (matchProduct == productFamily) { \
const bool isMatched = MatcherType::isMatched<productFamily>(); \
return isMatched; \
} else { \
return checkMatch<matcherOrdinal - 1u>(matchProduct); \
} \
} \
\
template <> \
bool GTEST_TEST_CLASS_NAME_(test_suite_name, \
test_name)::checkMatch<0>(PRODUCT_FAMILY matchProduct) { \
const int matcherOrdinal = 0u; \
const PRODUCT_FAMILY productFamily = At<ContainerType, matcherOrdinal>::productFamily; \
\
if (matchProduct == productFamily) { \
const bool isMatched = MatcherType::isMatched<productFamily>(); \
return isMatched; \
} else { \
return false; \
} \
} \
\
void GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::TestBody() { \

View File

@ -8,6 +8,9 @@
#include "shared/test/unit_test/test_macros/test_checks_shared.h"
#include "shared/source/device/device.h"
#include "shared/test/unit_test/helpers/default_hw_info.h"
#include "test.h"
using namespace NEO;
@ -20,3 +23,27 @@ bool TestChecks::supportsSvm(const std::unique_ptr<HardwareInfo> &pHardwareInfo)
bool TestChecks::supportsSvm(const Device *pDevice) {
return supportsSvm(&pDevice->getHardwareInfo());
}
class TestMacrosIfNotMatchTearDownCall : public ::testing::Test {
public:
void expectCorrectPlatform() {
EXPECT_EQ(IGFX_SKYLAKE, NEO::defaultHwInfo->platform.eProductFamily);
}
void SetUp() override {
expectCorrectPlatform();
}
void TearDown() override {
expectCorrectPlatform();
}
};
HWTEST2_F(TestMacrosIfNotMatchTearDownCall, givenNotMatchPlatformWhenUseHwTest2FThenSetUpAndTearDownAreNotCalled, IsSKL) {
expectCorrectPlatform();
}
class TestMacrosWithParamIfNotMatchTearDownCall : public TestMacrosIfNotMatchTearDownCall, public ::testing::WithParamInterface<int> {};
HWTEST2_P(TestMacrosWithParamIfNotMatchTearDownCall, givenNotMatchPlatformWhenUseHwTest2PThenSetUpAndTearDownAreNotCalled, IsSKL) {
expectCorrectPlatform();
}
INSTANTIATE_TEST_CASE_P(givenNotMatchPlatformWhenUseHwTest2PThenSetUpAndTearDownAreNotCalled,
TestMacrosWithParamIfNotMatchTearDownCall,
::testing::Values(0));