Use EXPECT_THROW instead of handmade try-catch in tests

Signed-off-by: Patryk Wrobel <patryk.wrobel@intel.com>
This commit is contained in:
Patryk Wrobel
2022-09-05 23:00:09 +00:00
committed by Compute-Runtime-Automation
parent 301be3c21b
commit 4395e0c3a1
4 changed files with 7 additions and 30 deletions

View File

@@ -1262,13 +1262,9 @@ TEST_F(BuiltInTests, WhenGettingBuilderInfoTwiceThenPointerIsSame) {
}
TEST_F(BuiltInTests, GivenUnknownBuiltInOpWhenGettingBuilderInfoThenExceptionThrown) {
bool caughtException = false;
try {
BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(EBuiltInOps::COUNT, *pClDevice);
} catch (const std::runtime_error &) {
caughtException = true;
}
EXPECT_TRUE(caughtException);
EXPECT_THROW(
BuiltInDispatchBuilderOp::getBuiltinDispatchInfoBuilder(EBuiltInOps::COUNT, *pClDevice),
std::runtime_error);
}
TEST_F(BuiltInTests, GivenUnsupportedBuildTypeWhenBuildingDispatchInfoThenFalseIsReturned) {

View File

@@ -1868,19 +1868,12 @@ TEST_F(MemoryManagerWithCsrTest, GivenAllocationsInHostPtrManagerWhenBiggerOverl
GraphicsAllocation *graphicsAllocation3 = nullptr;
bool catchMe = false;
try {
graphicsAllocation3 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, MemoryConstants::pageSize * 10}, cpuPtr3);
} catch (...) {
catchMe = true;
}
EXPECT_ANY_THROW(graphicsAllocation3 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), false, MemoryConstants::pageSize * 10}, cpuPtr3));
EXPECT_NE(nullptr, graphicsAllocation1);
EXPECT_NE(nullptr, graphicsAllocation2);
EXPECT_EQ(nullptr, graphicsAllocation3);
EXPECT_TRUE(catchMe);
EXPECT_EQ((uintptr_t)cpuPtr1 & ~MemoryConstants::pageMask, (uintptr_t)graphicsAllocation1->fragmentsStorage.fragmentStorageData[0].cpuPtr);
EXPECT_EQ((uintptr_t)cpuPtr2 & ~MemoryConstants::pageMask, (uintptr_t)graphicsAllocation2->fragmentsStorage.fragmentStorageData[0].cpuPtr);
EXPECT_EQ(((uintptr_t)cpuPtr2 + MemoryConstants::pageSize) & ~MemoryConstants::pageMask, (uintptr_t)graphicsAllocation2->fragmentsStorage.fragmentStorageData[1].cpuPtr);

View File

@@ -574,14 +574,8 @@ TEST_F(HostPtrManagerTest, GivenFragmentSizeNonZeroWhenGettingFragmentThenCorrec
auto ptr3 = (void *)0x040000;
auto size3 = MemoryConstants::pageSize * 2;
requiredAllocations = hostPtrManager.getAllocationRequirements(rootDeviceIndex, ptr3, size3);
auto catchme = false;
try {
OsHandleStorage st = hostPtrManager.populateAlreadyAllocatedFragments(requiredAllocations);
EXPECT_EQ(st.fragmentCount, 0u);
} catch (...) {
catchme = true;
}
EXPECT_TRUE(catchme);
EXPECT_ANY_THROW(hostPtrManager.populateAlreadyAllocatedFragments(requiredAllocations));
}
TEST_F(HostPtrManagerTest, WhenCheckingForOverlapsThenCorrectStatusIsReturned) {

View File

@@ -953,14 +953,8 @@ void testIDListUnlockOnException() {
};
ListMock l;
bool caughtEx = false;
try {
l.throwExFromLock();
} catch (const ExType &) {
caughtEx = true;
}
EXPECT_THROW(l.throwExFromLock(), ExType);
EXPECT_TRUE(caughtEx);
EXPECT_FALSE(l.getLockedRef().test_and_set(std::memory_order_seq_cst));
}