Skip to content

Commit 16c6d7e

Browse files
Refactor ApiFixture
- setup number of root devices - define tested root device Related-To: NEO-4000 Change-Id: I785d07a7f54932f66fe57637c8d10775743a871c Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
1 parent 8ccadbb commit 16c6d7e

File tree

49 files changed

+267
-274
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+267
-274
lines changed

unit_tests/api/cl_add_comment_to_aub_tests.inl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ TEST_F(clAddCommentToAubTest, givenNullptrCommentWhenAddCommentToAubThenErrorIsR
2929
}
3030

3131
TEST_F(clAddCommentToAubTest, givenAubCenterAndProperCommentButNullptrAubManagerWhenAddCommentToAubThenErrorIsReturned) {
32-
pPlatform->peekExecutionEnvironment()->rootDeviceEnvironments[0]->aubCenter.reset(new MockAubCenter());
32+
pPlatform->peekExecutionEnvironment()->rootDeviceEnvironments[testedRootDeviceIndex]->aubCenter.reset(new MockAubCenter());
3333

3434
auto retVal = clAddCommentINTEL(pPlatform, "comment");
3535
EXPECT_EQ(CL_INVALID_VALUE, retVal);
@@ -47,7 +47,7 @@ TEST_F(clAddCommentToAubTest, givenProperCommentAubCenterAndAubManagerWhenAddCom
4747
auto mockAubCenter = new MockAubCenter();
4848
auto mockAubManager = new AubManagerCommentMock;
4949
mockAubCenter->aubManager.reset(mockAubManager);
50-
pPlatform->peekExecutionEnvironment()->rootDeviceEnvironments[0]->aubCenter.reset(mockAubCenter);
50+
pPlatform->peekExecutionEnvironment()->rootDeviceEnvironments[testedRootDeviceIndex]->aubCenter.reset(mockAubCenter);
5151

5252
EXPECT_FALSE(mockAubManager->addCommentCalled);
5353

unit_tests/api/cl_api_tests.cpp

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,31 @@
1515
#include "unit_tests/mocks/mock_memory_manager.h"
1616

1717
namespace NEO {
18-
19-
api_fixture::api_fixture()
20-
: retVal(CL_SUCCESS), retSize(0), pCommandQueue(nullptr),
21-
pContext(nullptr), pKernel(nullptr), pProgram(nullptr) {
22-
}
23-
24-
void api_fixture::SetUp() {
18+
constexpr size_t ApiFixture::numRootDevices;
19+
void ApiFixture::SetUp() {
20+
numDevicesBackup = numRootDevices;
2521
PlatformFixture::SetUp();
2622

27-
ASSERT_EQ(retVal, CL_SUCCESS);
28-
auto pDevice = pPlatform->getDevice(0);
23+
auto pDevice = pPlatform->getDevice(testedRootDeviceIndex);
2924
ASSERT_NE(nullptr, pDevice);
3025

31-
cl_device_id clDevice = pDevice;
32-
pContext = Context::create<MockContext>(nullptr, DeviceVector(&clDevice, 1), nullptr, nullptr, retVal);
26+
testedClDevice = pDevice;
27+
pContext = Context::create<MockContext>(nullptr, DeviceVector(&testedClDevice, 1), nullptr, nullptr, retVal);
28+
EXPECT_EQ(retVal, CL_SUCCESS);
3329

34-
pCommandQueue = new CommandQueue(pContext, pDevice, 0);
30+
pCommandQueue = new CommandQueue(pContext, pDevice, nullptr);
3531

3632
pProgram = new MockProgram(*pDevice->getExecutionEnvironment(), pContext, false);
3733

3834
pKernel = new MockKernel(pProgram, pProgram->mockKernelInfo, *pDevice);
3935
ASSERT_NE(nullptr, pKernel);
4036
}
4137

42-
void api_fixture::TearDown() {
43-
delete pKernel;
44-
delete pCommandQueue;
45-
if (pContext) {
46-
pContext->release();
47-
}
48-
if (pProgram) {
49-
pProgram->release();
50-
}
38+
void ApiFixture::TearDown() {
39+
pKernel->release();
40+
pCommandQueue->release();
41+
pContext->release();
42+
pProgram->release();
5143

5244
PlatformFixture::TearDown();
5345
}

unit_tests/api/cl_api_tests.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "runtime/tracing/tracing_api.h"
1111
#include "test.h"
1212
#include "unit_tests/fixtures/platform_fixture.h"
13+
#include "unit_tests/helpers/variable_backup.h"
1314

1415
#include "gtest/gtest.h"
1516

@@ -22,33 +23,33 @@ class Context;
2223
class MockKernel;
2324
class MockProgram;
2425
class MockAlignedMallocManagerDevice;
26+
struct RootDeviceEnvironment;
27+
extern size_t numPlatformDevices;
2528

26-
struct api_fixture : public PlatformFixture {
27-
using PlatformFixture::SetUp;
28-
29-
public:
30-
api_fixture();
31-
32-
protected:
29+
struct ApiFixture : public PlatformFixture {
3330
virtual void SetUp();
3431
virtual void TearDown();
3532

36-
cl_int retVal;
37-
size_t retSize;
38-
39-
CommandQueue *pCommandQueue;
40-
Context *pContext;
41-
MockKernel *pKernel;
42-
MockProgram *pProgram;
33+
cl_int retVal = CL_SUCCESS;
34+
size_t retSize = 0;
35+
36+
CommandQueue *pCommandQueue = nullptr;
37+
Context *pContext = nullptr;
38+
MockKernel *pKernel = nullptr;
39+
MockProgram *pProgram = nullptr;
40+
constexpr static size_t numRootDevices = 1u;
41+
VariableBackup<size_t> numDevicesBackup{&numPlatformDevices};
42+
const uint32_t testedRootDeviceIndex = 0u;
43+
cl_device_id testedClDevice = nullptr;
4344
};
4445

45-
struct api_tests : public api_fixture,
46+
struct api_tests : public ApiFixture,
4647
public ::testing::Test {
4748
virtual void SetUp() override {
48-
api_fixture::SetUp();
49+
ApiFixture::SetUp();
4950
}
5051
virtual void TearDown() override {
51-
api_fixture::TearDown();
52+
ApiFixture::TearDown();
5253
}
5354
};
5455

unit_tests/api/cl_create_buffer_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ typedef api_tests clCreateBufferTests;
2121

2222
namespace ClCreateBufferTests {
2323

24-
class clCreateBufferTemplateTests : public api_fixture,
24+
class clCreateBufferTemplateTests : public ApiFixture,
2525
public testing::TestWithParam<uint64_t> {
2626
void SetUp() override {
27-
api_fixture::SetUp();
27+
ApiFixture::SetUp();
2828
}
2929

3030
void TearDown() override {
31-
api_fixture::TearDown();
31+
ApiFixture::TearDown();
3232
}
3333
};
3434

unit_tests/api/cl_create_command_queue_tests.inl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TEST_F(clCreateCommandQueueTest, GivenCorrectParametersWhenCreatingCommandQueueT
2323
cl_command_queue cmdQ = nullptr;
2424
cl_queue_properties properties = 0;
2525

26-
cmdQ = clCreateCommandQueue(pContext, devices[0], properties, &retVal);
26+
cmdQ = clCreateCommandQueue(pContext, devices[testedRootDeviceIndex], properties, &retVal);
2727

2828
ASSERT_NE(nullptr, cmdQ);
2929
ASSERT_EQ(CL_SUCCESS, retVal);
@@ -33,7 +33,7 @@ TEST_F(clCreateCommandQueueTest, GivenCorrectParametersWhenCreatingCommandQueueT
3333
}
3434

3535
TEST_F(clCreateCommandQueueTest, GivenNullContextWhenCreatingCommandQueueThenInvalidContextErrorIsReturned) {
36-
clCreateCommandQueue(nullptr, devices[0], 0, &retVal);
36+
clCreateCommandQueue(nullptr, devices[testedRootDeviceIndex], 0, &retVal);
3737
ASSERT_EQ(CL_INVALID_CONTEXT, retVal);
3838
}
3939

@@ -46,7 +46,7 @@ TEST_F(clCreateCommandQueueTest, GivenInvalidPropertiesWhenCreatingCommandQueueT
4646
cl_command_queue cmdQ = nullptr;
4747
cl_queue_properties properties = 0xf0000;
4848

49-
cmdQ = clCreateCommandQueue(pContext, devices[0], properties, &retVal);
49+
cmdQ = clCreateCommandQueue(pContext, devices[testedRootDeviceIndex], properties, &retVal);
5050

5151
ASSERT_EQ(nullptr, cmdQ);
5252
ASSERT_EQ(CL_INVALID_VALUE, retVal);
@@ -55,7 +55,7 @@ TEST_F(clCreateCommandQueueTest, GivenInvalidPropertiesWhenCreatingCommandQueueT
5555
TEST_F(clCreateCommandQueueTest, GivenOoqParametersWhenQueueIsCreatedThenQueueIsSucesfullyCreated) {
5656
cl_int retVal = CL_SUCCESS;
5757
cl_queue_properties ooq = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE;
58-
auto cmdq = clCreateCommandQueue(pContext, devices[0], ooq, &retVal);
58+
auto cmdq = clCreateCommandQueue(pContext, devices[testedRootDeviceIndex], ooq, &retVal);
5959
EXPECT_NE(nullptr, cmdq);
6060
EXPECT_EQ(retVal, CL_SUCCESS);
6161
retVal = clReleaseCommandQueue(cmdq);
@@ -64,23 +64,23 @@ TEST_F(clCreateCommandQueueTest, GivenOoqParametersWhenQueueIsCreatedThenQueueIs
6464
HWTEST_F(clCreateCommandQueueTest, GivenOoqParametersWhenQueueIsCreatedThenCommandStreamReceiverSwitchesToBatchingMode) {
6565
cl_int retVal = CL_SUCCESS;
6666
cl_queue_properties ooq = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE;
67-
auto mockDevice = castToObject<MockDevice>(devices[0]);
67+
auto mockDevice = castToObject<MockDevice>(devices[testedRootDeviceIndex]);
6868
auto &csr = mockDevice->getUltCommandStreamReceiver<FamilyType>();
6969
EXPECT_EQ(DispatchMode::ImmediateDispatch, csr.dispatchMode);
7070

71-
auto cmdq = clCreateCommandQueue(pContext, devices[0], ooq, &retVal);
71+
auto cmdq = clCreateCommandQueue(pContext, devices[testedRootDeviceIndex], ooq, &retVal);
7272
EXPECT_EQ(DispatchMode::BatchedDispatch, csr.dispatchMode);
7373
retVal = clReleaseCommandQueue(cmdq);
7474
}
7575

7676
HWTEST_F(clCreateCommandQueueTest, GivenOoqParametersWhenQueueIsCreatedThenCommandStreamReceiverSwitchesToNTo1SubmissionModel) {
7777
cl_int retVal = CL_SUCCESS;
7878
cl_queue_properties ooq = CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE;
79-
auto mockDevice = castToObject<MockDevice>(devices[0]);
79+
auto mockDevice = castToObject<MockDevice>(devices[testedRootDeviceIndex]);
8080
auto &csr = mockDevice->getUltCommandStreamReceiver<FamilyType>();
8181
EXPECT_FALSE(csr.isNTo1SubmissionModelEnabled());
8282

83-
auto cmdq = clCreateCommandQueue(pContext, devices[0], ooq, &retVal);
83+
auto cmdq = clCreateCommandQueue(pContext, devices[testedRootDeviceIndex], ooq, &retVal);
8484
EXPECT_TRUE(csr.isNTo1SubmissionModelEnabled());
8585
retVal = clReleaseCommandQueue(cmdq);
8686
}

0 commit comments

Comments
 (0)