From 689839143c39e9241143e8abc29cd108de3fe039 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Fri, 4 Jul 2025 13:07:20 +0000 Subject: [PATCH] test: reduce file system usage in L0 tools/sysman tests Signed-off-by: Mateusz Jablonski --- .../linux/test_zes_sysman_diagnostics.cpp | 4 +++- .../linux/test_zes_global_operations.cpp | 9 +++++---- .../linux/test_zes_sysman_diagnostics.cpp | 4 +++- .../linux/test_zes_global_operations.cpp | 12 +++++++----- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/level_zero/sysman/test/unit_tests/sources/diagnostics/linux/test_zes_sysman_diagnostics.cpp b/level_zero/sysman/test/unit_tests/sources/diagnostics/linux/test_zes_sysman_diagnostics.cpp index 4325c86aef..b908f4534e 100644 --- a/level_zero/sysman/test/unit_tests/sources/diagnostics/linux/test_zes_sysman_diagnostics.cpp +++ b/level_zero/sysman/test/unit_tests/sources/diagnostics/linux/test_zes_sysman_diagnostics.cpp @@ -441,8 +441,10 @@ TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenGPUProcessCleanupSu pPublicLinuxDiagnosticsImp->pLinuxSysmanImp = pMockDiagLinuxSysmanImp.get(); pMockDiagProcfsAccess->ourDevicePid = getpid(); pMockDiagLinuxSysmanImp->ourDevicePid = getpid(); - pMockDiagLinuxSysmanImp->ourDeviceFd = NEO::SysCalls::open("/dev/null", 0); + constexpr auto deviceFd = 0xF00; + pMockDiagLinuxSysmanImp->ourDeviceFd = deviceFd; EXPECT_EQ(ZE_RESULT_SUCCESS, pPublicLinuxDiagnosticsImp->pLinuxSysmanImp->gpuProcessCleanup(true)); + EXPECT_EQ(deviceFd, NEO::SysCalls::closeFuncArgPassed); } TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenGPUProcessCleanupFailsThenWaitForQuiescentCompletionsFails) { diff --git a/level_zero/sysman/test/unit_tests/sources/global_operations/linux/test_zes_global_operations.cpp b/level_zero/sysman/test/unit_tests/sources/global_operations/linux/test_zes_global_operations.cpp index 045554c960..471b89f8d0 100644 --- a/level_zero/sysman/test/unit_tests/sources/global_operations/linux/test_zes_global_operations.cpp +++ b/level_zero/sysman/test/unit_tests/sources/global_operations/linux/test_zes_global_operations.cpp @@ -1003,8 +1003,10 @@ TEST_F(SysmanGlobalOperationsIntegratedFixture, GivenDeviceNotInUseWhenCallingRe // Pretend we have the device open pProcfsAccess->ourDevicePid = getpid(); - pProcfsAccess->ourDeviceFd = ::open("/dev/null", 0); + constexpr auto deviceFd = 0xF00; + pProcfsAccess->ourDeviceFd = deviceFd; + NEO::SysCalls::closeFuncCalled = 0u; // The first time we get the process list, include our own process, that has the file open // Reset should close the file (we verify after reset). On subsequent calls, return // the process list without our process @@ -1015,9 +1017,8 @@ TEST_F(SysmanGlobalOperationsIntegratedFixture, GivenDeviceNotInUseWhenCallingRe ze_result_t result = zesDeviceReset(device, false); EXPECT_EQ(ZE_RESULT_SUCCESS, result); // Check that reset closed the device - // If the device is already closed, then close will fail with errno of EBADF - EXPECT_NE(0, ::close(pProcfsAccess->ourDevicePid)); - EXPECT_EQ(errno, EBADF); + EXPECT_LT(0u, NEO::SysCalls::closeFuncCalled); + EXPECT_EQ(deviceFd, NEO::SysCalls::closeFuncArgPassed); } TEST_F(SysmanGlobalOperationsIntegratedFixture, GivenForceTrueAndDeviceInUseWhenCallingResetThenSuccessIsReturned) { diff --git a/level_zero/tools/test/unit_tests/sources/sysman/diagnostics/linux/test_zes_sysman_diagnostics.cpp b/level_zero/tools/test/unit_tests/sources/sysman/diagnostics/linux/test_zes_sysman_diagnostics.cpp index e02e9bdd61..a51bb46e0b 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/diagnostics/linux/test_zes_sysman_diagnostics.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/diagnostics/linux/test_zes_sysman_diagnostics.cpp @@ -500,8 +500,10 @@ TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenGPUProcessCleanupSu pMockDiagProcfsAccess->ourDevicePid = getpid(); pMockDiagLinuxSysmanImp->ourDevicePid = getpid(); - pMockDiagLinuxSysmanImp->ourDeviceFd = ::open("/dev/null", 0); + constexpr auto deviceFd = 0xF00; + pMockDiagLinuxSysmanImp->ourDeviceFd = deviceFd; EXPECT_EQ(ZE_RESULT_SUCCESS, pPublicLinuxDiagnosticsImp->pLinuxSysmanImp->gpuProcessCleanup(true)); + EXPECT_EQ(deviceFd, NEO::SysCalls::closeFuncArgPassed); } TEST_F(ZesDiagnosticsFixture, GivenValidDiagnosticsHandleWhenGPUProcessCleanupFailsThenWaitForQuiescentCompletionsFails) { diff --git a/level_zero/tools/test/unit_tests/sources/sysman/global_operations/linux/test_zes_global_operations.cpp b/level_zero/tools/test/unit_tests/sources/sysman/global_operations/linux/test_zes_global_operations.cpp index a41c5d7b96..74c2a29152 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/global_operations/linux/test_zes_global_operations.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/global_operations/linux/test_zes_global_operations.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2024 Intel Corporation + * Copyright (C) 2020-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -906,8 +906,11 @@ TEST_F(SysmanGlobalOperationsIntegratedFixture, GivenDeviceNotInUseWhenCallingRe // Pretend we have the device open pProcfsAccess->ourDevicePid = getpid(); - pProcfsAccess->ourDeviceFd = ::open("/dev/null", 0); + constexpr auto deviceFd = 0xF00; + pProcfsAccess->ourDeviceFd = deviceFd; + + NEO::SysCalls::closeFuncCalled = 0u; // The first time we get the process list, include our own process, that has the file open // Reset should close the file (we verify after reset). On subsequent calls, return // the process list without our process @@ -918,9 +921,8 @@ TEST_F(SysmanGlobalOperationsIntegratedFixture, GivenDeviceNotInUseWhenCallingRe ze_result_t result = zesDeviceReset(device, false); EXPECT_EQ(ZE_RESULT_SUCCESS, result); // Check that reset closed the device - // If the device is already closed, then close will fail with errno of EBADF - EXPECT_NE(0, ::close(pProcfsAccess->ourDevicePid)); - EXPECT_EQ(errno, EBADF); + EXPECT_LT(0u, NEO::SysCalls::closeFuncCalled); + EXPECT_EQ(deviceFd, NEO::SysCalls::closeFuncArgPassed); } TEST_F(SysmanGlobalOperationsIntegratedFixture, GivenForceTrueAndDeviceInUseWhenCallingResetThenSuccessIsReturned) {