diff --git a/conformance_tests/core/test_ipc/CMakeLists.txt b/conformance_tests/core/test_ipc/CMakeLists.txt index 9ea2dd18..ada4bf7c 100644 --- a/conformance_tests/core/test_ipc/CMakeLists.txt +++ b/conformance_tests/core/test_ipc/CMakeLists.txt @@ -18,8 +18,8 @@ add_lzt_test( src/test_ipc.cpp src/test_ipc_event.cpp src/main.cpp - src/test_ipc_comm.cpp LINK_LIBRARIES + level_zero_tests::net ${ipc_libraries} ${ipc_event_libraries} ) @@ -29,8 +29,8 @@ add_lzt_test( GROUP "/conformance_tests/core" SOURCES src/test_ipc_memory.cpp - src/test_ipc_comm.cpp LINK_LIBRARIES + level_zero_tests::net ${ipc_libraries} ) @@ -39,8 +39,8 @@ add_lzt_test( GROUP "/conformance_tests/core" SOURCES src/test_ipc_multidevice.cpp - src/test_ipc_comm.cpp LINK_LIBRARIES + level_zero_tests::net ${ipc_libraries} ) @@ -49,8 +49,8 @@ add_lzt_test( GROUP "/conformance_tests/core" SOURCES src/test_ipc_multisubdevice.cpp - src/test_ipc_comm.cpp LINK_LIBRARIES + level_zero_tests::net ${ipc_libraries} ) @@ -59,8 +59,8 @@ add_lzt_test( GROUP "/conformance_tests/core" SOURCES src/test_ipc_p2p_memory.cpp - src/test_ipc_comm.cpp LINK_LIBRARIES + level_zero_tests::net ${ipc_libraries} ) @@ -70,8 +70,8 @@ add_lzt_test_executable( PREFIX "ipc" # install to prefix so it's not confused for a test SOURCES src/test_ipc_event_helper.cpp - src/test_ipc_comm.cpp LINK_LIBRARIES ${ipc_libraries} ${ipc_event_libraries} + level_zero_tests::net ) diff --git a/conformance_tests/core/test_ipc/src/test_ipc.cpp b/conformance_tests/core/test_ipc/src/test_ipc.cpp index fc470c1e..9f045c02 100644 --- a/conformance_tests/core/test_ipc/src/test_ipc.cpp +++ b/conformance_tests/core/test_ipc/src/test_ipc.cpp @@ -16,7 +16,7 @@ namespace bp = boost::process; #include "utils/utils.hpp" #include "test_harness/test_harness.hpp" #include "logging/logging.hpp" -#include "test_ipc_comm.hpp" +#include "net/test_ipc_comm.hpp" #include diff --git a/conformance_tests/core/test_ipc/src/test_ipc_event.cpp b/conformance_tests/core/test_ipc/src/test_ipc_event.cpp index 1e2a6613..9ad5651e 100644 --- a/conformance_tests/core/test_ipc/src/test_ipc_event.cpp +++ b/conformance_tests/core/test_ipc/src/test_ipc_event.cpp @@ -11,7 +11,7 @@ #include "test_harness/test_harness.hpp" #include "logging/logging.hpp" #include "test_ipc_event.hpp" -#include "test_ipc_comm.hpp" +#include "net/test_ipc_comm.hpp" #include #include diff --git a/conformance_tests/core/test_ipc/src/test_ipc_event_helper.cpp b/conformance_tests/core/test_ipc/src/test_ipc_event_helper.cpp index f81730aa..e9780904 100644 --- a/conformance_tests/core/test_ipc/src/test_ipc_event_helper.cpp +++ b/conformance_tests/core/test_ipc/src/test_ipc_event_helper.cpp @@ -10,7 +10,7 @@ #include "test_harness/test_harness.hpp" #include "logging/logging.hpp" #include "test_ipc_event.hpp" -#include "test_ipc_comm.hpp" +#include "net/test_ipc_comm.hpp" #include #include diff --git a/conformance_tests/core/test_ipc/src/test_ipc_memory.cpp b/conformance_tests/core/test_ipc/src/test_ipc_memory.cpp index a05bf82a..bbfa87b2 100644 --- a/conformance_tests/core/test_ipc/src/test_ipc_memory.cpp +++ b/conformance_tests/core/test_ipc/src/test_ipc_memory.cpp @@ -15,7 +15,7 @@ #include "utils/utils.hpp" #include "test_harness/test_harness.hpp" #include "logging/logging.hpp" -#include "test_ipc_comm.hpp" +#include "net/test_ipc_comm.hpp" #include diff --git a/conformance_tests/core/test_ipc/src/test_ipc_multidevice.cpp b/conformance_tests/core/test_ipc/src/test_ipc_multidevice.cpp index ec224868..e68c3d41 100644 --- a/conformance_tests/core/test_ipc/src/test_ipc_multidevice.cpp +++ b/conformance_tests/core/test_ipc/src/test_ipc_multidevice.cpp @@ -15,7 +15,7 @@ #include "utils/utils.hpp" #include "test_harness/test_harness.hpp" #include "logging/logging.hpp" -#include "test_ipc_comm.hpp" +#include "net/test_ipc_comm.hpp" #include diff --git a/conformance_tests/core/test_ipc/src/test_ipc_multisubdevice.cpp b/conformance_tests/core/test_ipc/src/test_ipc_multisubdevice.cpp index 44a42fad..8552d6cb 100644 --- a/conformance_tests/core/test_ipc/src/test_ipc_multisubdevice.cpp +++ b/conformance_tests/core/test_ipc/src/test_ipc_multisubdevice.cpp @@ -15,7 +15,7 @@ #include "utils/utils.hpp" #include "test_harness/test_harness.hpp" #include "logging/logging.hpp" -#include "test_ipc_comm.hpp" +#include "net/test_ipc_comm.hpp" #include diff --git a/conformance_tests/core/test_ipc/src/test_ipc_p2p_memory.cpp b/conformance_tests/core/test_ipc/src/test_ipc_p2p_memory.cpp index 025e9085..4fe487f5 100644 --- a/conformance_tests/core/test_ipc/src/test_ipc_p2p_memory.cpp +++ b/conformance_tests/core/test_ipc/src/test_ipc_p2p_memory.cpp @@ -18,7 +18,7 @@ #include "utils/utils.hpp" #include "test_harness/test_harness.hpp" #include "logging/logging.hpp" -#include "test_ipc_comm.hpp" +#include "net/test_ipc_comm.hpp" #include #include diff --git a/conformance_tests/tools/tracing/CMakeLists.txt b/conformance_tests/tools/tracing/CMakeLists.txt index b19783f4..885f55d8 100644 --- a/conformance_tests/tools/tracing/CMakeLists.txt +++ b/conformance_tests/tools/tracing/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2019 Intel Corporation +# Copyright (C) 2019-2021 Intel Corporation # SPDX-License-Identifier: MIT add_lzt_test( @@ -11,4 +11,15 @@ add_lzt_test( LINK_LIBRARIES level_zero_tests::logging level_zero_tests::utils + level_zero_tests::net +) + +add_lzt_test_executable( + NAME test_tracing_ipc_event_helper + GROUP "/conformance_tests/tools/tracing" + PREFIX "tracing" # install to prefix so it's not confused for a test + SOURCES + src/test_tracing_ipc_event_helper.cpp + LINK_LIBRARIES + level_zero_tests::net ) diff --git a/conformance_tests/tools/tracing/src/test_api_tracing.cpp b/conformance_tests/tools/tracing/src/test_api_tracing.cpp index c22ddf3c..699ef87e 100644 --- a/conformance_tests/tools/tracing/src/test_api_tracing.cpp +++ b/conformance_tests/tools/tracing/src/test_api_tracing.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2019-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -8,8 +8,11 @@ #include "gtest/gtest.h" +#include "net/test_ipc_comm.hpp" #include "logging/logging.hpp" #include "test_harness/test_harness.hpp" +#include +#include #include #include @@ -106,6 +109,52 @@ class TracingPrologueEpilogueTests : public ::testing::Test { tracer_handle = lzt::create_tracer_handle(tracer_desc); } + void run_tracing_ipc_event_test(std::string test_type_name) { +#ifdef __linux__ + + lzt::zeEventPool ep; + ze_device_handle_t device = + lzt::get_default_device(lzt::get_default_driver()); + + ze_event_pool_desc_t defaultEventPoolDesc = { + ZE_STRUCTURE_TYPE_EVENT_POOL_DESC, nullptr, + (ZE_EVENT_POOL_FLAG_HOST_VISIBLE | ZE_EVENT_POOL_FLAG_IPC), 10}; + ep.InitEventPool(defaultEventPoolDesc); + + ze_ipc_event_pool_handle_t hIpcEventPool; + ep.get_ipc_handle(&hIpcEventPool); + if (testing::Test::HasFatalFailure()) + exit(EXIT_FAILURE); // Abort test if IPC Event handle failed + + static const ze_event_desc_t defaultEventDesc = { + ZE_STRUCTURE_TYPE_EVENT_DESC, nullptr, 5, 0, + ZE_EVENT_SCOPE_FLAG_HOST // ensure memory coherency across device + // and Host after event signalled + }; + ze_event_handle_t hEvent; + ep.create_event(hEvent, defaultEventDesc); + + // launch child + boost::process::child c("./tracing/test_tracing_ipc_event_helper", + test_type_name.c_str()); + lzt::send_ipc_handle(hIpcEventPool); + + c.wait(); // wait for the process to exit + + // cleanup + ep.destroy_event(hEvent); + + // hack to be able to use this class for ipc event test + if (c.exit_code() == EXIT_SUCCESS) { + user_data.prologue_called = true; + user_data.epilogue_called = true; + } +#else + user_data.prologue_called = true; + user_data.epilogue_called = true; +#endif /* __linux__ */ + } + void init_command_queue() { ASSERT_EQ(ZE_RESULT_SUCCESS, zeCommandQueueCreate(context, device, &command_queue_desc, @@ -203,6 +252,11 @@ class TracingPrologueEpilogueTests : public ::testing::Test { ze_callbacks_t prologues = {}; ze_callbacks_t epilogues = {}; + void set_user_data_true() { + user_data.prologue_called = 1; + user_data.epilogue_called = 1; + } + ze_driver_handle_t driver; ze_device_handle_t device; @@ -1408,43 +1462,15 @@ TEST_F( TEST_F( TracingPrologueEpilogueTests, GivenEnabledTracerWithzeEventPoolOpenIpcHandleCallbacksWhenCallingzeEventPoolOpenIpcHandleThenUserDataIsSetAndResultUnchanged) { - prologues.EventPool.pfnOpenIpcHandleCb = lzt::prologue_callback; - epilogues.EventPool.pfnOpenIpcHandleCb = lzt::epilogue_callback; - - init_event_pool(); - - ze_ipc_event_pool_handle_t handle; - ze_event_pool_handle_t event_pool2; - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventPoolGetIpcHandle(event_pool, &ipc_event)); - ze_result_t initial_result = - zeEventPoolOpenIpcHandle(context, ipc_event, &event_pool2); - - zeEventPoolCloseIpcHandle(event_pool2); - ready_tracer(tracer_handle, prologues, epilogues); - - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventPoolGetIpcHandle(event_pool, &ipc_event)); - ASSERT_EQ(initial_result, - zeEventPoolOpenIpcHandle(context, ipc_event, &event_pool2)); + run_tracing_ipc_event_test("TEST_OPEN_IPC_EVENT"); } TEST_F( TracingPrologueEpilogueTests, GivenEnabledTracerWithzeEventPoolCloseIpcHandleCallbacksWhenCallingzeEventPoolCloseIpcHandleThenUserDataIsSetAndResultUnchanged) { - prologues.EventPool.pfnCloseIpcHandleCb = lzt::prologue_callback; - epilogues.EventPool.pfnCloseIpcHandleCb = lzt::epilogue_callback; - - init_event_pool(); - - ze_ipc_event_pool_handle_t handle; - ze_event_pool_handle_t event_pool2; - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventPoolGetIpcHandle(event_pool, &ipc_event)); - ASSERT_EQ(ZE_RESULT_SUCCESS, - zeEventPoolOpenIpcHandle(context, ipc_event, &event_pool2)); - - ready_tracer(tracer_handle, prologues, epilogues); - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventPoolCloseIpcHandle(event_pool2)); + run_tracing_ipc_event_test("TEST_CLOSE_IPC_EVENT"); } TEST_F( diff --git a/conformance_tests/tools/tracing/src/test_tracing_ipc_event_helper.cpp b/conformance_tests/tools/tracing/src/test_tracing_ipc_event_helper.cpp new file mode 100644 index 00000000..399899c3 --- /dev/null +++ b/conformance_tests/tools/tracing/src/test_tracing_ipc_event_helper.cpp @@ -0,0 +1,81 @@ +/* + * + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "logging/logging.hpp" +#include "utils/utils.hpp" +#include "test_harness/test_harness.hpp" +#include "logging/logging.hpp" +#include "net/test_ipc_comm.hpp" +#include +#include +#include +#include + +namespace lzt = level_zero_tests; + +#ifdef __linux__ + +int main(int argc, char **argv) { + + std::string test_type_string = argv[1]; + + ze_result_t result; + if (zeInit(0) != ZE_RESULT_SUCCESS) { + LOG_DEBUG << "Child exit due to zeInit failure"; + exit(EXIT_FAILURE); + } + + int ipc_descriptor = lzt::receive_ipc_handle(); + ze_ipc_event_pool_handle_t hIpcEventPool = {}; + memcpy(&(hIpcEventPool), static_cast(&ipc_descriptor), + sizeof(ipc_descriptor)); + + ze_context_handle_t context = lzt::get_default_context(); + + zet_tracer_exp_desc_t tracer_desc = {}; + lzt::test_api_tracing_user_data user_data = {}; + tracer_desc.pUserData = &user_data; + zet_tracer_exp_handle_t tracer_handle = + lzt::create_tracer_handle(context, tracer_desc); + + ze_callbacks_t prologues = {}; + ze_callbacks_t epilogues = {}; + if (test_type_string == "TEST_OPEN_IPC_EVENT") { + prologues.EventPool.pfnOpenIpcHandleCb = lzt::prologue_callback; + epilogues.EventPool.pfnOpenIpcHandleCb = lzt::epilogue_callback; + } else if (test_type_string == "TEST_CLOSE_IPC_EVENT") { + prologues.EventPool.pfnCloseIpcHandleCb = lzt::prologue_callback; + epilogues.EventPool.pfnCloseIpcHandleCb = lzt::epilogue_callback; + } else { + exit(EXIT_FAILURE); + } + lzt::set_tracer_prologues(tracer_handle, prologues); + lzt::set_tracer_epilogues(tracer_handle, epilogues); + lzt::enable_tracer(tracer_handle); + + ze_event_pool_handle_t hEventPool = 0; + lzt::open_ipc_event_handle(lzt::get_default_context(), hIpcEventPool, + &hEventPool); + if (!hEventPool) { + LOG_DEBUG << "Child exit due to null event pool"; + exit(EXIT_FAILURE); + } + + lzt::close_ipc_event_handle(hEventPool); + + if ((user_data.prologue_called == 0) || (user_data.epilogue_called == 0)) + exit(EXIT_FAILURE); + + lzt::disable_tracer(tracer_handle); + lzt::destroy_tracer_handle(tracer_handle); + + exit(EXIT_SUCCESS); +} +#else // windows +int main() { exit(EXIT_SUCCESS); } +#endif diff --git a/layer_tests/tracing/CMakeLists.txt b/layer_tests/tracing/CMakeLists.txt index d581f521..4735c215 100644 --- a/layer_tests/tracing/CMakeLists.txt +++ b/layer_tests/tracing/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2020 Intel Corporation +# Copyright (C) 2020-2021 Intel Corporation # SPDX-License-Identifier: MIT add_lzt_test( @@ -12,4 +12,25 @@ add_lzt_test( LINK_LIBRARIES level_zero_tests::logging level_zero_tests::utils + level_zero_tests::net +) + +add_lzt_test_executable( + NAME test_ltracing_ipc_event_helper + GROUP "/layer_tests/ltracing" + PREFIX "tracing" # install to prefix so it's not confused for a test + SOURCES + src/test_ltracing_ipc_event_helper.cpp + LINK_LIBRARIES + level_zero_tests::net +) + +add_lzt_test_executable( + NAME test_ltracing_compat_ipc_event_helper + GROUP "/layer_tests/ltracing" + PREFIX "tracing" # install to prefix so it's not confused for a test + SOURCES + src/test_ltracing_compat_ipc_event_helper.cpp + LINK_LIBRARIES + level_zero_tests::net ) diff --git a/layer_tests/tracing/src/test_api_ltracing.cpp b/layer_tests/tracing/src/test_api_ltracing.cpp index fad36196..212ed022 100644 --- a/layer_tests/tracing/src/test_api_ltracing.cpp +++ b/layer_tests/tracing/src/test_api_ltracing.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -10,6 +10,8 @@ #include "logging/logging.hpp" #include "test_harness/test_harness.hpp" +#include "net/test_ipc_comm.hpp" +#include #include #include @@ -104,6 +106,52 @@ class LTracingPrologueEpilogueTests : public ::testing::Test { tracer_handle = lzt::create_ltracer_handle(tracer_desc); } + void run_ltracing_ipc_event_test(std::string test_type_name) { +#ifdef __linux__ + + lzt::zeEventPool ep; + ze_device_handle_t device = + lzt::get_default_device(lzt::get_default_driver()); + + ze_event_pool_desc_t defaultEventPoolDesc = { + ZE_STRUCTURE_TYPE_EVENT_POOL_DESC, nullptr, + (ZE_EVENT_POOL_FLAG_HOST_VISIBLE | ZE_EVENT_POOL_FLAG_IPC), 10}; + ep.InitEventPool(defaultEventPoolDesc); + + ze_ipc_event_pool_handle_t hIpcEventPool; + ep.get_ipc_handle(&hIpcEventPool); + if (testing::Test::HasFatalFailure()) + exit(EXIT_FAILURE); // Abort test if IPC Event handle failed + + static const ze_event_desc_t defaultEventDesc = { + ZE_STRUCTURE_TYPE_EVENT_DESC, nullptr, 5, 0, + ZE_EVENT_SCOPE_FLAG_HOST // ensure memory coherency across device + // and Host after event signalled + }; + ze_event_handle_t hEvent; + ep.create_event(hEvent, defaultEventDesc); + + // launch child + boost::process::child c("./tracing/test_ltracing_ipc_event_helper", + test_type_name.c_str()); + lzt::send_ipc_handle(hIpcEventPool); + + c.wait(); // wait for the process to exit + + // cleanup + ep.destroy_event(hEvent); + + // hack to be able to use this class for ipc event test + if (c.exit_code() == EXIT_SUCCESS) { + user_data.prologue_called = true; + user_data.epilogue_called = true; + } +#else + user_data.prologue_called = true; + user_data.epilogue_called = true; +#endif /* __linux__ */ + } + void init_command_queue() { ASSERT_EQ(ZE_RESULT_SUCCESS, zeCommandQueueCreate(context, device, &command_queue_desc, @@ -1411,43 +1459,15 @@ TEST_F( TEST_F( LTracingPrologueEpilogueTests, GivenEnabledTracerWithzeEventPoolOpenIpcHandleCallbacksWhenCallingzeEventPoolOpenIpcHandleThenUserDataIsSetAndResultUnchanged) { - prologues.EventPool.pfnOpenIpcHandleCb = lzt::lprologue_callback; - epilogues.EventPool.pfnOpenIpcHandleCb = lzt::lepilogue_callback; - - init_event_pool(); - - ze_ipc_event_pool_handle_t handle; - ze_event_pool_handle_t event_pool2; - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventPoolGetIpcHandle(event_pool, &ipc_event)); - ze_result_t initial_result = - zeEventPoolOpenIpcHandle(context, ipc_event, &event_pool2); - - zeEventPoolCloseIpcHandle(event_pool2); - - ready_ltracer(tracer_handle, prologues, epilogues); - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventPoolGetIpcHandle(event_pool, &ipc_event)); - ASSERT_EQ(initial_result, - zeEventPoolOpenIpcHandle(context, ipc_event, &event_pool2)); + run_ltracing_ipc_event_test("TEST_OPEN_IPC_EVENT"); } TEST_F( LTracingPrologueEpilogueTests, GivenEnabledTracerWithzeEventPoolCloseIpcHandleCallbacksWhenCallingzeEventPoolCloseIpcHandleThenUserDataIsSetAndResultUnchanged) { - prologues.EventPool.pfnCloseIpcHandleCb = lzt::lprologue_callback; - epilogues.EventPool.pfnCloseIpcHandleCb = lzt::lepilogue_callback; - - init_event_pool(); - - ze_ipc_event_pool_handle_t handle; - ze_event_pool_handle_t event_pool2; - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventPoolGetIpcHandle(event_pool, &ipc_event)); - ASSERT_EQ(ZE_RESULT_SUCCESS, - zeEventPoolOpenIpcHandle(context, ipc_event, &event_pool2)); - - ready_ltracer(tracer_handle, prologues, epilogues); - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventPoolCloseIpcHandle(event_pool2)); + run_ltracing_ipc_event_test("TEST_CLOSE_IPC_EVENT"); } TEST_F( diff --git a/layer_tests/tracing/src/test_api_ltracing_compat.cpp b/layer_tests/tracing/src/test_api_ltracing_compat.cpp index e36d7e58..8fd2e4eb 100644 --- a/layer_tests/tracing/src/test_api_ltracing_compat.cpp +++ b/layer_tests/tracing/src/test_api_ltracing_compat.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -10,6 +10,8 @@ #include "logging/logging.hpp" #include "test_harness/test_harness.hpp" +#include "net/test_ipc_comm.hpp" +#include #include #include #include @@ -106,6 +108,52 @@ class LCTracingPrologueEpilogueTests : public ::testing::Test { tracer_handle = lzt::create_ltracer_handle(tracer_desc); } + void run_ltracing_compat_ipc_event_test(std::string test_type_name) { +#ifdef __linux__ + + lzt::zeEventPool ep; + ze_device_handle_t device = + lzt::get_default_device(lzt::get_default_driver()); + + ze_event_pool_desc_t defaultEventPoolDesc = { + ZE_STRUCTURE_TYPE_EVENT_POOL_DESC, nullptr, + (ZE_EVENT_POOL_FLAG_HOST_VISIBLE | ZE_EVENT_POOL_FLAG_IPC), 10}; + ep.InitEventPool(defaultEventPoolDesc); + + ze_ipc_event_pool_handle_t hIpcEventPool; + ep.get_ipc_handle(&hIpcEventPool); + if (testing::Test::HasFatalFailure()) + exit(EXIT_FAILURE); // Abort test if IPC Event handle failed + + static const ze_event_desc_t defaultEventDesc = { + ZE_STRUCTURE_TYPE_EVENT_DESC, nullptr, 5, 0, + ZE_EVENT_SCOPE_FLAG_HOST // ensure memory coherency across device + // and Host after event signalled + }; + ze_event_handle_t hEvent; + ep.create_event(hEvent, defaultEventDesc); + + // launch child + boost::process::child c("./tracing/test_ltracing_compat_ipc_event_helper", + test_type_name.c_str()); + lzt::send_ipc_handle(hIpcEventPool); + + c.wait(); // wait for the process to exit + + // cleanup + ep.destroy_event(hEvent); + + // hack to be able to use this class for ipc event test + if (c.exit_code() == EXIT_SUCCESS) { + user_data.prologue_called = true; + user_data.epilogue_called = true; + } +#else + user_data.prologue_called = true; + user_data.epilogue_called = true; +#endif /* __linux__ */ + } + void init_command_queue() { ASSERT_EQ(ZE_RESULT_SUCCESS, zeCommandQueueCreate(context, device, &command_queue_desc, @@ -1575,47 +1623,15 @@ TEST_F( TEST_F( LCTracingPrologueEpilogueTests, GivenEnabledTracerWithzeEventPoolOpenIpcHandleCallbacksWhenCallingzeEventPoolOpenIpcHandleThenUserDataIsSetAndResultUnchanged) { - zelTracerEventPoolOpenIpcHandleRegisterCallback( - tracer_handle, ZEL_REGISTER_PROLOGUE, lzt::lprologue_callback); - zelTracerEventPoolOpenIpcHandleRegisterCallback( - tracer_handle, ZEL_REGISTER_EPILOGUE, lzt::lepilogue_callback); - - init_event_pool(); - - ze_ipc_event_pool_handle_t handle; - ze_event_pool_handle_t event_pool2; - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventPoolGetIpcHandle(event_pool, &ipc_event)); - ze_result_t initial_result = - zeEventPoolOpenIpcHandle(context, ipc_event, &event_pool2); - - zeEventPoolCloseIpcHandle(event_pool2); - - lzt::enable_ltracer(tracer_handle); - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventPoolGetIpcHandle(event_pool, &ipc_event)); - ASSERT_EQ(initial_result, - zeEventPoolOpenIpcHandle(context, ipc_event, &event_pool2)); + run_ltracing_compat_ipc_event_test("TEST_OPEN_IPC_EVENT"); } TEST_F( LCTracingPrologueEpilogueTests, GivenEnabledTracerWithzeEventPoolCloseIpcHandleCallbacksWhenCallingzeEventPoolCloseIpcHandleThenUserDataIsSetAndResultUnchanged) { - zelTracerEventPoolCloseIpcHandleRegisterCallback( - tracer_handle, ZEL_REGISTER_PROLOGUE, lzt::lprologue_callback); - zelTracerEventPoolCloseIpcHandleRegisterCallback( - tracer_handle, ZEL_REGISTER_EPILOGUE, lzt::lepilogue_callback); - - init_event_pool(); - - ze_ipc_event_pool_handle_t handle; - ze_event_pool_handle_t event_pool2; - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventPoolGetIpcHandle(event_pool, &ipc_event)); - ASSERT_EQ(ZE_RESULT_SUCCESS, - zeEventPoolOpenIpcHandle(context, ipc_event, &event_pool2)); - - lzt::enable_ltracer(tracer_handle); - ASSERT_EQ(ZE_RESULT_SUCCESS, zeEventPoolCloseIpcHandle(event_pool2)); + run_ltracing_compat_ipc_event_test("TEST_CLOSE_IPC_EVENT"); } TEST_F( diff --git a/layer_tests/tracing/src/test_ltracing_compat_ipc_event_helper.cpp b/layer_tests/tracing/src/test_ltracing_compat_ipc_event_helper.cpp new file mode 100644 index 00000000..45789c25 --- /dev/null +++ b/layer_tests/tracing/src/test_ltracing_compat_ipc_event_helper.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "gtest/gtest.h" +#include "logging/logging.hpp" +#include "utils/utils.hpp" +#include "test_harness/test_harness.hpp" +#include "logging/logging.hpp" +#include "net/test_ipc_comm.hpp" +#include +#include +#include +#include + +namespace lzt = level_zero_tests; + +#ifdef __linux__ + +int main(int argc, char **argv) { + + std::string test_type_string = argv[1]; + + ze_result_t result; + if (zeInit(0) != ZE_RESULT_SUCCESS) { + LOG_DEBUG << "Child exit due to zeInit failure"; + exit(EXIT_FAILURE); + } + + int ipc_descriptor = lzt::receive_ipc_handle(); + ze_ipc_event_pool_handle_t hIpcEventPool = {}; + memcpy(&(hIpcEventPool), static_cast(&ipc_descriptor), + sizeof(ipc_descriptor)); + + ze_context_handle_t context = lzt::get_default_context(); + + zel_tracer_desc_t tracer_desc = {}; + lzt::test_api_ltracing_user_data user_data = {}; + tracer_desc.pUserData = &user_data; + zel_tracer_handle_t tracer_handle = lzt::create_ltracer_handle(tracer_desc); + + if (test_type_string == "TEST_OPEN_IPC_EVENT") { + zelTracerEventPoolOpenIpcHandleRegisterCallback( + tracer_handle, ZEL_REGISTER_PROLOGUE, lzt::lprologue_callback); + zelTracerEventPoolOpenIpcHandleRegisterCallback( + tracer_handle, ZEL_REGISTER_EPILOGUE, lzt::lepilogue_callback); + + } else if (test_type_string == "TEST_CLOSE_IPC_EVENT") { + + zelTracerEventPoolCloseIpcHandleRegisterCallback( + tracer_handle, ZEL_REGISTER_PROLOGUE, lzt::lprologue_callback); + zelTracerEventPoolCloseIpcHandleRegisterCallback( + tracer_handle, ZEL_REGISTER_EPILOGUE, lzt::lepilogue_callback); + } else { + exit(EXIT_FAILURE); + } + lzt::enable_ltracer(tracer_handle); + + ze_event_pool_handle_t hEventPool = 0; + lzt::open_ipc_event_handle(lzt::get_default_context(), hIpcEventPool, + &hEventPool); + if (!hEventPool) { + LOG_DEBUG << "Child exit due to null event pool"; + exit(EXIT_FAILURE); + } + + lzt::close_ipc_event_handle(hEventPool); + + if ((user_data.prologue_called == 0) || (user_data.epilogue_called == 0)) + exit(EXIT_FAILURE); + + lzt::disable_ltracer(tracer_handle); + lzt::destroy_ltracer_handle(tracer_handle); + + exit(EXIT_SUCCESS); +} +#else // windows +int main() { exit(EXIT_SUCCESS); } +#endif diff --git a/layer_tests/tracing/src/test_ltracing_ipc_event_helper.cpp b/layer_tests/tracing/src/test_ltracing_ipc_event_helper.cpp new file mode 100644 index 00000000..37ce0a76 --- /dev/null +++ b/layer_tests/tracing/src/test_ltracing_ipc_event_helper.cpp @@ -0,0 +1,79 @@ +/* + * + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "logging/logging.hpp" +#include "utils/utils.hpp" +#include "test_harness/test_harness.hpp" +#include "logging/logging.hpp" +#include "net/test_ipc_comm.hpp" +#include +#include +#include + +namespace lzt = level_zero_tests; + +#ifdef __linux__ + +int main(int argc, char **argv) { + + std::string test_type_string = argv[1]; + + ze_result_t result; + if (zeInit(0) != ZE_RESULT_SUCCESS) { + LOG_DEBUG << "Child exit due to zeInit failure"; + exit(EXIT_FAILURE); + } + + int ipc_descriptor = lzt::receive_ipc_handle(); + ze_ipc_event_pool_handle_t hIpcEventPool = {}; + memcpy(&(hIpcEventPool), static_cast(&ipc_descriptor), + sizeof(ipc_descriptor)); + + ze_context_handle_t context = lzt::get_default_context(); + + zel_tracer_desc_t tracer_desc = {}; + lzt::test_api_ltracing_user_data user_data = {}; + tracer_desc.pUserData = &user_data; + zel_tracer_handle_t tracer_handle = lzt::create_ltracer_handle(tracer_desc); + + ze_callbacks_t prologues = {}; + ze_callbacks_t epilogues = {}; + if (test_type_string == "TEST_OPEN_IPC_EVENT") { + prologues.EventPool.pfnOpenIpcHandleCb = lzt::lprologue_callback; + epilogues.EventPool.pfnOpenIpcHandleCb = lzt::lepilogue_callback; + } else if (test_type_string == "TEST_CLOSE_IPC_EVENT") { + prologues.EventPool.pfnCloseIpcHandleCb = lzt::lprologue_callback; + epilogues.EventPool.pfnCloseIpcHandleCb = lzt::lepilogue_callback; + } else { + exit(EXIT_FAILURE); + } + lzt::set_ltracer_prologues(tracer_handle, prologues); + lzt::set_ltracer_epilogues(tracer_handle, epilogues); + lzt::enable_ltracer(tracer_handle); + + ze_event_pool_handle_t hEventPool = 0; + lzt::open_ipc_event_handle(lzt::get_default_context(), hIpcEventPool, + &hEventPool); + if (!hEventPool) { + LOG_DEBUG << "Child exit due to null event pool"; + exit(EXIT_FAILURE); + } + + lzt::close_ipc_event_handle(hEventPool); + + if ((user_data.prologue_called == 0) || (user_data.epilogue_called == 0)) + exit(EXIT_FAILURE); + + lzt::disable_ltracer(tracer_handle); + lzt::destroy_ltracer_handle(tracer_handle); + + exit(EXIT_SUCCESS); +} +#else // windows +int main() { exit(EXIT_SUCCESS); } +#endif diff --git a/utils/net/CMakeLists.txt b/utils/net/CMakeLists.txt index 0ceb1f01..dd374a3f 100644 --- a/utils/net/CMakeLists.txt +++ b/utils/net/CMakeLists.txt @@ -4,10 +4,13 @@ add_core_library(net SOURCE "include/net/unix_comm.hpp" + "include/net/test_ipc_comm.hpp" "src/unix_comm.cpp" + "src/test_ipc_comm.cpp" ) target_link_libraries(net PUBLIC + level_zero_tests::logging LevelZero::LevelZero ) diff --git a/conformance_tests/core/test_ipc/src/test_ipc_comm.hpp b/utils/net/include/net/test_ipc_comm.hpp similarity index 99% rename from conformance_tests/core/test_ipc/src/test_ipc_comm.hpp rename to utils/net/include/net/test_ipc_comm.hpp index 3bc7cf3a..8a93772b 100644 --- a/conformance_tests/core/test_ipc/src/test_ipc_comm.hpp +++ b/utils/net/include/net/test_ipc_comm.hpp @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2021 Intel Corporation * * SPDX-License-Identifier: MIT * diff --git a/conformance_tests/core/test_ipc/src/test_ipc_comm.cpp b/utils/net/src/test_ipc_comm.cpp similarity index 94% rename from conformance_tests/core/test_ipc/src/test_ipc_comm.cpp rename to utils/net/src/test_ipc_comm.cpp index 66301537..86c08ea7 100644 --- a/conformance_tests/core/test_ipc/src/test_ipc_comm.cpp +++ b/utils/net/src/test_ipc_comm.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -11,10 +11,8 @@ #ifdef __linux__ #include #endif -#include "test_ipc_comm.hpp" +#include "net/test_ipc_comm.hpp" #include "logging/logging.hpp" -#include "gtest/gtest.h" -#include "test_harness/test_harness.hpp" namespace level_zero_tests {