mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-25 13:33:02 +08:00
Parametrize wait operation
Related-To: NEO-4759 Signed-off-by: Zbigniew Zdanowicz <zbigniew.zdanowicz@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
2f59fafb96
commit
b9ed7de40a
@@ -14,7 +14,9 @@
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
namespace CpuIntrinsicsTests {
|
||||
extern std::atomic<uintptr_t> lastClFlushedPtr;
|
||||
}
|
||||
|
||||
struct DirectSubmissionFixture : public DeviceFixture {
|
||||
void SetUp() {
|
||||
|
||||
@@ -133,6 +133,7 @@ class MockCsrHw2 : public CommandStreamReceiverHw<GfxFamily> {
|
||||
using CommandStreamReceiver::pageTableManagerInitialized;
|
||||
using CommandStreamReceiver::requiredScratchSize;
|
||||
using CommandStreamReceiver::requiredThreadArbitrationPolicy;
|
||||
using CommandStreamReceiver::tagAddress;
|
||||
using CommandStreamReceiver::taskCount;
|
||||
using CommandStreamReceiver::taskLevel;
|
||||
using CommandStreamReceiver::timestampPacketWriteEnabled;
|
||||
|
||||
@@ -35,11 +35,11 @@ HWTEST_F(DirectSubmissionTest, whenDebugCacheFlushDisabledSetThenExpectNoCpuCach
|
||||
EXPECT_TRUE(directSubmission.disableCpuCacheFlush);
|
||||
|
||||
uintptr_t expectedPtrVal = 0;
|
||||
lastClFlushedPtr = 0;
|
||||
CpuIntrinsicsTests::lastClFlushedPtr = 0;
|
||||
void *ptr = reinterpret_cast<void *>(0xABCD00u);
|
||||
size_t size = 64;
|
||||
directSubmission.cpuCachelineFlush(ptr, size);
|
||||
EXPECT_EQ(expectedPtrVal, lastClFlushedPtr);
|
||||
EXPECT_EQ(expectedPtrVal, CpuIntrinsicsTests::lastClFlushedPtr);
|
||||
}
|
||||
|
||||
HWTEST_F(DirectSubmissionTest, whenDebugCacheFlushDisabledNotSetThenExpectCpuCacheFlush) {
|
||||
@@ -51,11 +51,11 @@ HWTEST_F(DirectSubmissionTest, whenDebugCacheFlushDisabledNotSetThenExpectCpuCac
|
||||
EXPECT_FALSE(directSubmission.disableCpuCacheFlush);
|
||||
|
||||
uintptr_t expectedPtrVal = 0xABCD00u;
|
||||
lastClFlushedPtr = 0;
|
||||
CpuIntrinsicsTests::lastClFlushedPtr = 0;
|
||||
void *ptr = reinterpret_cast<void *>(expectedPtrVal);
|
||||
size_t size = 64;
|
||||
directSubmission.cpuCachelineFlush(ptr, size);
|
||||
EXPECT_EQ(expectedPtrVal, lastClFlushedPtr);
|
||||
EXPECT_EQ(expectedPtrVal, CpuIntrinsicsTests::lastClFlushedPtr);
|
||||
}
|
||||
|
||||
HWTEST_F(DirectSubmissionTest, givenDirectSubmissionInitializedWhenRingIsStartedThenExpectAllocationsCreatedAndCommandsDispatched) {
|
||||
|
||||
@@ -22,6 +22,7 @@ target_sources(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spinlock_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/timer_util_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vec_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/wait_util_tests.cpp
|
||||
)
|
||||
|
||||
add_subdirectories()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
* Copyright (C) 2019-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -10,19 +10,27 @@
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
|
||||
namespace CpuIntrinsicsTests {
|
||||
//std::atomic is used for sake of sanitation in MT tests
|
||||
std::atomic<uintptr_t> lastClFlushedPtr(0u);
|
||||
std::atomic<uint32_t> pauseCounter(0u);
|
||||
|
||||
volatile uint32_t *pauseAddress = nullptr;
|
||||
uint32_t pauseValue = 0u;
|
||||
} // namespace CpuIntrinsicsTests
|
||||
|
||||
namespace NEO {
|
||||
namespace CpuIntrinsics {
|
||||
|
||||
void clFlush(void const *ptr) {
|
||||
lastClFlushedPtr = reinterpret_cast<uintptr_t>(ptr);
|
||||
CpuIntrinsicsTests::lastClFlushedPtr = reinterpret_cast<uintptr_t>(ptr);
|
||||
}
|
||||
|
||||
void pause() {
|
||||
pauseCounter++;
|
||||
CpuIntrinsicsTests::pauseCounter++;
|
||||
if (CpuIntrinsicsTests::pauseAddress != nullptr) {
|
||||
*CpuIntrinsicsTests::pauseAddress = CpuIntrinsicsTests::pauseValue;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace CpuIntrinsics
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
* Copyright (C) 2019-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -12,18 +12,20 @@
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
|
||||
namespace CpuIntrinsicsTests {
|
||||
extern std::atomic<uintptr_t> lastClFlushedPtr;
|
||||
extern std::atomic<uint32_t> pauseCounter;
|
||||
} // namespace CpuIntrinsicsTests
|
||||
|
||||
TEST(CpuIntrinsicsTest, whenClFlushIsCalledThenExpectToPassPtrToSystemCall) {
|
||||
uintptr_t flushAddr = 0x1234;
|
||||
void const *ptr = reinterpret_cast<void const *>(flushAddr);
|
||||
NEO::CpuIntrinsics::clFlush(ptr);
|
||||
EXPECT_EQ(flushAddr, lastClFlushedPtr);
|
||||
EXPECT_EQ(flushAddr, CpuIntrinsicsTests::lastClFlushedPtr);
|
||||
}
|
||||
|
||||
TEST(CpuIntrinsicsTest, whenPauseCalledThenExpectToIncreaseCounter) {
|
||||
uint32_t oldCount = pauseCounter.load();
|
||||
uint32_t oldCount = CpuIntrinsicsTests::pauseCounter.load();
|
||||
NEO::CpuIntrinsics::pause();
|
||||
EXPECT_EQ(oldCount + 1, pauseCounter);
|
||||
EXPECT_EQ(oldCount + 1, CpuIntrinsicsTests::pauseCounter);
|
||||
}
|
||||
|
||||
93
shared/test/unit_test/utilities/wait_util_tests.cpp
Normal file
93
shared/test/unit_test/utilities/wait_util_tests.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/utilities/wait_util.h"
|
||||
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
||||
#include "shared/test/common/helpers/variable_backup.h"
|
||||
|
||||
#include "test.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
namespace CpuIntrinsicsTests {
|
||||
extern std::atomic<uint32_t> pauseCounter;
|
||||
} // namespace CpuIntrinsicsTests
|
||||
|
||||
TEST(WaitTest, givenDefaultSettingsWhenNoPollAddressProvidedThenPauseDefaultTimeAndReturnFalse) {
|
||||
EXPECT_EQ(64u, WaitUtils::defaultWaitCount);
|
||||
|
||||
WaitUtils::init();
|
||||
EXPECT_EQ(WaitUtils::defaultWaitCount, WaitUtils::waitCount);
|
||||
|
||||
uint32_t oldCount = CpuIntrinsicsTests::pauseCounter.load();
|
||||
bool ret = WaitUtils::waitFunction(nullptr, 0u);
|
||||
EXPECT_FALSE(ret);
|
||||
EXPECT_EQ(oldCount + WaitUtils::waitCount, CpuIntrinsicsTests::pauseCounter);
|
||||
}
|
||||
|
||||
TEST(WaitTest, givenDebugFlagOverridesWhenNoPollAddressProvidedThenPauseDefaultTimeAndReturnFalse) {
|
||||
DebugManagerStateRestore restore;
|
||||
VariableBackup<uint32_t> backupWaitCount(&WaitUtils::waitCount);
|
||||
|
||||
uint32_t count = 10u;
|
||||
DebugManager.flags.WaitLoopCount.set(count);
|
||||
|
||||
WaitUtils::init();
|
||||
EXPECT_EQ(count, WaitUtils::waitCount);
|
||||
|
||||
uint32_t oldCount = CpuIntrinsicsTests::pauseCounter.load();
|
||||
bool ret = WaitUtils::waitFunction(nullptr, 0u);
|
||||
EXPECT_FALSE(ret);
|
||||
EXPECT_EQ(oldCount + count, CpuIntrinsicsTests::pauseCounter);
|
||||
}
|
||||
|
||||
TEST(WaitTest, givenDefaultSettingsWhenPollAddressProvidedDoesNotMeetCriteriaThenPauseDefaultTimeAndReturnFalse) {
|
||||
WaitUtils::init();
|
||||
EXPECT_EQ(WaitUtils::defaultWaitCount, WaitUtils::waitCount);
|
||||
|
||||
volatile uint32_t pollValue = 1u;
|
||||
uint32_t expectedValue = 3;
|
||||
|
||||
uint32_t oldCount = CpuIntrinsicsTests::pauseCounter.load();
|
||||
bool ret = WaitUtils::waitFunction(&pollValue, expectedValue);
|
||||
EXPECT_FALSE(ret);
|
||||
EXPECT_EQ(oldCount + WaitUtils::waitCount, CpuIntrinsicsTests::pauseCounter);
|
||||
}
|
||||
|
||||
TEST(WaitTest, givenDefaultSettingsWhenPollAddressProvidedMeetsCriteriaThenPauseDefaultTimeAndReturnTrue) {
|
||||
WaitUtils::init();
|
||||
EXPECT_EQ(WaitUtils::defaultWaitCount, WaitUtils::waitCount);
|
||||
|
||||
volatile uint32_t pollValue = 3u;
|
||||
uint32_t expectedValue = 1;
|
||||
|
||||
uint32_t oldCount = CpuIntrinsicsTests::pauseCounter.load();
|
||||
bool ret = WaitUtils::waitFunction(&pollValue, expectedValue);
|
||||
EXPECT_TRUE(ret);
|
||||
EXPECT_EQ(oldCount + WaitUtils::waitCount, CpuIntrinsicsTests::pauseCounter);
|
||||
}
|
||||
|
||||
TEST(WaitTest, givenDebugFlagSetZeroWhenPollAddressProvidedMeetsCriteriaThenPauseZeroTimesAndReturnTrue) {
|
||||
DebugManagerStateRestore restore;
|
||||
VariableBackup<uint32_t> backupWaitCount(&WaitUtils::waitCount);
|
||||
|
||||
uint32_t count = 0u;
|
||||
DebugManager.flags.WaitLoopCount.set(count);
|
||||
|
||||
WaitUtils::init();
|
||||
EXPECT_EQ(count, WaitUtils::waitCount);
|
||||
|
||||
volatile uint32_t pollValue = 3u;
|
||||
uint32_t expectedValue = 1;
|
||||
|
||||
uint32_t oldCount = CpuIntrinsicsTests::pauseCounter.load();
|
||||
bool ret = WaitUtils::waitFunction(&pollValue, expectedValue);
|
||||
EXPECT_TRUE(ret);
|
||||
EXPECT_EQ(oldCount + WaitUtils::waitCount, CpuIntrinsicsTests::pauseCounter);
|
||||
}
|
||||
Reference in New Issue
Block a user