2020-01-14 20:52:06 +08:00
|
|
|
/*
|
2022-04-01 19:47:24 +08:00
|
|
|
* Copyright (C) 2020-2022 Intel Corporation
|
2020-01-14 20:52:06 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/utilities/cpuintrinsics.h"
|
2020-01-14 20:52:06 +08:00
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
#include <cstdint>
|
|
|
|
|
2021-03-31 02:11:00 +08:00
|
|
|
namespace CpuIntrinsicsTests {
|
2020-01-14 20:52:06 +08:00
|
|
|
extern std::atomic<uintptr_t> lastClFlushedPtr;
|
|
|
|
extern std::atomic<uint32_t> pauseCounter;
|
2022-04-01 19:47:24 +08:00
|
|
|
extern std::atomic<uint32_t> sfenceCounter;
|
2021-03-31 02:11:00 +08:00
|
|
|
} // namespace CpuIntrinsicsTests
|
2020-01-14 20:52:06 +08:00
|
|
|
|
|
|
|
TEST(CpuIntrinsicsTest, whenClFlushIsCalledThenExpectToPassPtrToSystemCall) {
|
|
|
|
uintptr_t flushAddr = 0x1234;
|
|
|
|
void const *ptr = reinterpret_cast<void const *>(flushAddr);
|
|
|
|
NEO::CpuIntrinsics::clFlush(ptr);
|
2021-03-31 02:11:00 +08:00
|
|
|
EXPECT_EQ(flushAddr, CpuIntrinsicsTests::lastClFlushedPtr);
|
2020-01-14 20:52:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CpuIntrinsicsTest, whenPauseCalledThenExpectToIncreaseCounter) {
|
2021-03-31 02:11:00 +08:00
|
|
|
uint32_t oldCount = CpuIntrinsicsTests::pauseCounter.load();
|
2020-01-14 20:52:06 +08:00
|
|
|
NEO::CpuIntrinsics::pause();
|
2021-03-31 02:11:00 +08:00
|
|
|
EXPECT_EQ(oldCount + 1, CpuIntrinsicsTests::pauseCounter);
|
2020-01-14 20:52:06 +08:00
|
|
|
}
|
2022-04-01 19:47:24 +08:00
|
|
|
|
|
|
|
TEST(CpuIntrinsicsTest, whenSfenceCalledThenExpectToIncreaseCounter) {
|
|
|
|
uint32_t oldCount = CpuIntrinsicsTests::sfenceCounter.load();
|
|
|
|
NEO::CpuIntrinsics::sfence();
|
|
|
|
EXPECT_EQ(oldCount + 1, CpuIntrinsicsTests::sfenceCounter);
|
|
|
|
}
|