2021-03-30 18:11:00 +00:00
|
|
|
/*
|
2025-03-07 10:32:00 +00:00
|
|
|
* Copyright (C) 2021-2025 Intel Corporation
|
2021-03-30 18:11:00 +00:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "shared/source/utilities/wait_util.h"
|
|
|
|
|
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
2025-03-26 12:53:38 +00:00
|
|
|
#include "shared/test/common/helpers/default_hw_info.h"
|
2021-03-30 18:11:00 +00:00
|
|
|
#include "shared/test/common/helpers/variable_backup.h"
|
2022-06-29 19:17:47 +00:00
|
|
|
#include "shared/test/common/test_macros/hw_test.h"
|
2021-03-30 18:11:00 +00:00
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
|
|
using namespace NEO;
|
|
|
|
|
|
|
|
|
|
namespace CpuIntrinsicsTests {
|
|
|
|
|
extern std::atomic<uint32_t> pauseCounter;
|
|
|
|
|
} // namespace CpuIntrinsicsTests
|
|
|
|
|
|
2024-01-18 11:39:39 +00:00
|
|
|
struct WaitPredicateOnlyFixture {
|
|
|
|
|
void setUp() {
|
|
|
|
|
debugManager.flags.EnableWaitpkg.set(0);
|
|
|
|
|
backupWaitCount = std::make_unique<VariableBackup<uint32_t>>(&WaitUtils::waitCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void tearDown() {}
|
|
|
|
|
|
|
|
|
|
DebugManagerStateRestore restore;
|
|
|
|
|
std::unique_ptr<VariableBackup<uint32_t>> backupWaitCount;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using WaitPredicateOnlyTest = Test<WaitPredicateOnlyFixture>;
|
|
|
|
|
|
|
|
|
|
TEST_F(WaitPredicateOnlyTest, givenDefaultSettingsWhenNoPollAddressProvidedThenPauseDefaultTimeAndReturnFalse) {
|
2021-04-01 12:22:47 +00:00
|
|
|
EXPECT_EQ(1u, WaitUtils::defaultWaitCount);
|
2021-03-30 18:11:00 +00:00
|
|
|
|
2025-03-26 12:53:38 +00:00
|
|
|
WaitUtils::init(WaitUtils::WaitpkgUse::noUse, *defaultHwInfo);
|
2021-03-30 18:11:00 +00:00
|
|
|
EXPECT_EQ(WaitUtils::defaultWaitCount, WaitUtils::waitCount);
|
|
|
|
|
|
|
|
|
|
uint32_t oldCount = CpuIntrinsicsTests::pauseCounter.load();
|
2025-03-21 08:27:46 +00:00
|
|
|
bool ret = WaitUtils::waitFunction(nullptr, 0u, 0);
|
2021-03-30 18:11:00 +00:00
|
|
|
EXPECT_FALSE(ret);
|
|
|
|
|
EXPECT_EQ(oldCount + WaitUtils::waitCount, CpuIntrinsicsTests::pauseCounter);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-18 11:39:39 +00:00
|
|
|
TEST_F(WaitPredicateOnlyTest, givenDebugFlagOverridesWhenNoPollAddressProvidedThenPauseDefaultTimeAndReturnFalse) {
|
2021-03-30 18:11:00 +00:00
|
|
|
uint32_t count = 10u;
|
2023-11-30 08:32:25 +00:00
|
|
|
debugManager.flags.WaitLoopCount.set(count);
|
2021-03-30 18:11:00 +00:00
|
|
|
|
2025-03-26 12:53:38 +00:00
|
|
|
WaitUtils::init(WaitUtils::WaitpkgUse::noUse, *defaultHwInfo);
|
2021-03-30 18:11:00 +00:00
|
|
|
EXPECT_EQ(count, WaitUtils::waitCount);
|
|
|
|
|
|
|
|
|
|
uint32_t oldCount = CpuIntrinsicsTests::pauseCounter.load();
|
2025-03-21 08:27:46 +00:00
|
|
|
bool ret = WaitUtils::waitFunction(nullptr, 0u, 0);
|
2021-03-30 18:11:00 +00:00
|
|
|
EXPECT_FALSE(ret);
|
|
|
|
|
EXPECT_EQ(oldCount + count, CpuIntrinsicsTests::pauseCounter);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-18 11:39:39 +00:00
|
|
|
TEST_F(WaitPredicateOnlyTest, givenDefaultSettingsWhenPollAddressProvidedDoesNotMeetCriteriaThenPauseDefaultTimeAndReturnFalse) {
|
2025-03-26 12:53:38 +00:00
|
|
|
WaitUtils::init(WaitUtils::WaitpkgUse::noUse, *defaultHwInfo);
|
2021-03-30 18:11:00 +00:00
|
|
|
EXPECT_EQ(WaitUtils::defaultWaitCount, WaitUtils::waitCount);
|
|
|
|
|
|
2022-11-22 13:53:59 +00:00
|
|
|
volatile TagAddressType pollValue = 1u;
|
|
|
|
|
TaskCountType expectedValue = 3;
|
2021-03-30 18:11:00 +00:00
|
|
|
|
|
|
|
|
uint32_t oldCount = CpuIntrinsicsTests::pauseCounter.load();
|
2025-03-21 08:27:46 +00:00
|
|
|
bool ret = WaitUtils::waitFunction(&pollValue, expectedValue, 0);
|
2021-03-30 18:11:00 +00:00
|
|
|
EXPECT_FALSE(ret);
|
|
|
|
|
EXPECT_EQ(oldCount + WaitUtils::waitCount, CpuIntrinsicsTests::pauseCounter);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-18 11:39:39 +00:00
|
|
|
TEST_F(WaitPredicateOnlyTest, givenDefaultSettingsWhenPollAddressProvidedMeetsCriteriaThenPauseDefaultTimeAndReturnTrue) {
|
2025-03-26 12:53:38 +00:00
|
|
|
WaitUtils::init(WaitUtils::WaitpkgUse::noUse, *defaultHwInfo);
|
2021-03-30 18:11:00 +00:00
|
|
|
EXPECT_EQ(WaitUtils::defaultWaitCount, WaitUtils::waitCount);
|
|
|
|
|
|
2022-11-22 13:53:59 +00:00
|
|
|
volatile TagAddressType pollValue = 3u;
|
|
|
|
|
TaskCountType expectedValue = 1;
|
2021-03-30 18:11:00 +00:00
|
|
|
|
|
|
|
|
uint32_t oldCount = CpuIntrinsicsTests::pauseCounter.load();
|
2025-03-21 08:27:46 +00:00
|
|
|
bool ret = WaitUtils::waitFunction(&pollValue, expectedValue, 0);
|
2021-03-30 18:11:00 +00:00
|
|
|
EXPECT_TRUE(ret);
|
|
|
|
|
EXPECT_EQ(oldCount + WaitUtils::waitCount, CpuIntrinsicsTests::pauseCounter);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-18 11:39:39 +00:00
|
|
|
TEST_F(WaitPredicateOnlyTest, givenDebugFlagSetZeroWhenPollAddressProvidedMeetsCriteriaThenPauseZeroTimesAndReturnTrue) {
|
2021-03-30 18:11:00 +00:00
|
|
|
uint32_t count = 0u;
|
2023-11-30 08:32:25 +00:00
|
|
|
debugManager.flags.WaitLoopCount.set(count);
|
2021-03-30 18:11:00 +00:00
|
|
|
|
2025-03-26 12:53:38 +00:00
|
|
|
WaitUtils::init(WaitUtils::WaitpkgUse::noUse, *defaultHwInfo);
|
2021-03-30 18:11:00 +00:00
|
|
|
EXPECT_EQ(count, WaitUtils::waitCount);
|
|
|
|
|
|
2022-11-22 13:53:59 +00:00
|
|
|
volatile TagAddressType pollValue = 3u;
|
|
|
|
|
TaskCountType expectedValue = 1;
|
2021-03-30 18:11:00 +00:00
|
|
|
|
|
|
|
|
uint32_t oldCount = CpuIntrinsicsTests::pauseCounter.load();
|
2025-03-21 08:27:46 +00:00
|
|
|
bool ret = WaitUtils::waitFunction(&pollValue, expectedValue, 0);
|
2021-03-30 18:11:00 +00:00
|
|
|
EXPECT_TRUE(ret);
|
|
|
|
|
EXPECT_EQ(oldCount + WaitUtils::waitCount, CpuIntrinsicsTests::pauseCounter);
|
|
|
|
|
}
|