Skip to content

Commit

Permalink
Fix Ipc Event test failures
Browse files Browse the repository at this point in the history
Signed-off-by: davidoli <[email protected]>
  • Loading branch information
dmichaelo1 authored and nrspruit committed Oct 27, 2021
1 parent aff26cb commit 2787ffa
Show file tree
Hide file tree
Showing 19 changed files with 454 additions and 117 deletions.
12 changes: 6 additions & 6 deletions conformance_tests/core/test_ipc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)
Expand All @@ -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}
)

Expand All @@ -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}
)

Expand All @@ -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}
)

Expand All @@ -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}
)

Expand All @@ -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
)
2 changes: 1 addition & 1 deletion conformance_tests/core/test_ipc/src/test_ipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <level_zero/ze_api.h>

Expand Down
2 changes: 1 addition & 1 deletion conformance_tests/core/test_ipc/src/test_ipc_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/mapped_region.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/mapped_region.hpp>
Expand Down
2 changes: 1 addition & 1 deletion conformance_tests/core/test_ipc/src/test_ipc_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <level_zero/ze_api.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <level_zero/ze_api.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <level_zero/ze_api.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <level_zero/ze_api.h>
#include <math.h>
Expand Down
13 changes: 12 additions & 1 deletion conformance_tests/tools/tracing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2019 Intel Corporation
# Copyright (C) 2019-2021 Intel Corporation
# SPDX-License-Identifier: MIT

add_lzt_test(
Expand All @@ -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
)
88 changes: 57 additions & 31 deletions conformance_tests/tools/tracing/src/test_api_tracing.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
/*
*
* Copyright (C) 2019 Intel Corporation
* Copyright (C) 2019-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/

#include "gtest/gtest.h"

#include "net/test_ipc_comm.hpp"
#include "logging/logging.hpp"
#include "test_harness/test_harness.hpp"
#include <boost/process.hpp>
#include <string>
#include <level_zero/ze_api.h>
#include <level_zero/zet_api.h>

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <boost/process.hpp>
#include <level_zero/ze_api.h>
#include <level_zero/zet_api.h>
#include <string>

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>();
ze_ipc_event_pool_handle_t hIpcEventPool = {};
memcpy(&(hIpcEventPool), static_cast<void *>(&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
23 changes: 22 additions & 1 deletion layer_tests/tracing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2020 Intel Corporation
# Copyright (C) 2020-2021 Intel Corporation
# SPDX-License-Identifier: MIT

add_lzt_test(
Expand All @@ -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
)
Loading

0 comments on commit 2787ffa

Please sign in to comment.