From bb0ff460f41da09514e00d1f7825d5e5a9ed07a2 Mon Sep 17 00:00:00 2001 From: piotr-wozniak-mobica Date: Tue, 8 Aug 2023 12:19:56 +0200 Subject: [PATCH 1/3] UT for createKernels --- tests/test_openclhpp.cpp | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/test_openclhpp.cpp b/tests/test_openclhpp.cpp index 7748e664..023c2166 100644 --- a/tests/test_openclhpp.cpp +++ b/tests/test_openclhpp.cpp @@ -4516,5 +4516,46 @@ void testgetObjectInfo() { TEST_ASSERT_EQUAL(buffer.getObjectInfo(&type, &bufobj), CL_SUCCESS); TEST_ASSERT_EQUAL(type, CL_GL_OBJECT_BUFFER); TEST_ASSERT_EQUAL(bufobj, 0); + +static cl_int clCreateKernelsInProgram_testcreateKernels( + cl_program program, cl_uint num_kernels, cl_kernel *kernels, + cl_uint *num_kernels_ret, int num_calls) { + switch (num_calls) { + case 0: + case 1: + TEST_ASSERT_EQUAL(make_program(0), program); + if (num_kernels_ret != nullptr) { + *num_kernels_ret = 1; + } + return CL_SUCCESS; + case 2: + TEST_ASSERT_EQUAL(make_program(1), program); + if (num_kernels_ret != nullptr) { + *num_kernels_ret = 1; + } + return CL_SUCCESS; + case 3: + TEST_ASSERT_EQUAL(make_program(1), program); + return CL_DEVICE_NOT_FOUND; + case 4: + TEST_ASSERT_EQUAL(make_program(2), program); + return CL_DEVICE_NOT_AVAILABLE; + default: + return CL_SUCCESS; + } +} + +void testcreateKernels() { + cl_int ret = 0; + cl::vector kernels; + + clCreateKernelsInProgram_StubWithCallback( + clCreateKernelsInProgram_testcreateKernels); + ret = programPool[0].createKernels(&kernels); + TEST_ASSERT_EQUAL(CL_SUCCESS, ret); + ret = programPool[1].createKernels(&kernels); + TEST_ASSERT_EQUAL(CL_DEVICE_NOT_FOUND, ret); + ret = programPool[2].createKernels(&kernels); + TEST_ASSERT_EQUAL(CL_DEVICE_NOT_AVAILABLE, ret); } } // extern "C" From 413d85468a3fa0eb32b7b8565aae5392a384c465 Mon Sep 17 00:00:00 2001 From: Kamil Goras Date: Thu, 19 Oct 2023 11:56:22 +0200 Subject: [PATCH 2/3] Added corrections --- tests/test_openclhpp.cpp | 57 ++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/tests/test_openclhpp.cpp b/tests/test_openclhpp.cpp index 023c2166..57ca986a 100644 --- a/tests/test_openclhpp.cpp +++ b/tests/test_openclhpp.cpp @@ -4516,46 +4516,69 @@ void testgetObjectInfo() { TEST_ASSERT_EQUAL(buffer.getObjectInfo(&type, &bufobj), CL_SUCCESS); TEST_ASSERT_EQUAL(type, CL_GL_OBJECT_BUFFER); TEST_ASSERT_EQUAL(bufobj, 0); +} static cl_int clCreateKernelsInProgram_testcreateKernels( cl_program program, cl_uint num_kernels, cl_kernel *kernels, cl_uint *num_kernels_ret, int num_calls) { switch (num_calls) { case 0: - case 1: TEST_ASSERT_EQUAL(make_program(0), program); + TEST_ASSERT_EQUAL(0, num_kernels); if (num_kernels_ret != nullptr) { - *num_kernels_ret = 1; + *num_kernels_ret = 3; } return CL_SUCCESS; - case 2: - TEST_ASSERT_EQUAL(make_program(1), program); - if (num_kernels_ret != nullptr) { - *num_kernels_ret = 1; + case 1: + TEST_ASSERT_EQUAL(3, num_kernels); + TEST_ASSERT_EQUAL(nullptr, num_kernels_ret); + for (unsigned int i = 0; i < num_kernels; i++) + { + kernels[i] = make_kernel(i); } + return CL_SUCCESS; - case 3: + case 2: TEST_ASSERT_EQUAL(make_program(1), program); - return CL_DEVICE_NOT_FOUND; - case 4: - TEST_ASSERT_EQUAL(make_program(2), program); - return CL_DEVICE_NOT_AVAILABLE; + TEST_ASSERT_EQUAL(0, num_kernels); + TEST_ASSERT_NOT_NULL(num_kernels_ret); + *num_kernels_ret = 0; + + return CL_INVALID_PROGRAM_EXECUTABLE; + case 3: + TEST_ASSERT_EQUAL(nullptr, program); + TEST_ASSERT_EQUAL(0, num_kernels); + TEST_ASSERT_NOT_NULL(num_kernels_ret); + *num_kernels_ret = 0; + + return CL_INVALID_PROGRAM; default: return CL_SUCCESS; } } -void testcreateKernels() { +void testCreateKernels() { cl_int ret = 0; cl::vector kernels; - clCreateKernelsInProgram_StubWithCallback( - clCreateKernelsInProgram_testcreateKernels); + clCreateKernelsInProgram_StubWithCallback(clCreateKernelsInProgram_testcreateKernels); + ret = programPool[0].createKernels(&kernels); TEST_ASSERT_EQUAL(CL_SUCCESS, ret); + TEST_ASSERT_EQUAL(3, kernels.size()); + for (unsigned int i = 0; i < kernels.size(); i++) + { + kernels[i]() = nullptr; + } + kernels.clear(); + ret = programPool[1].createKernels(&kernels); - TEST_ASSERT_EQUAL(CL_DEVICE_NOT_FOUND, ret); - ret = programPool[2].createKernels(&kernels); - TEST_ASSERT_EQUAL(CL_DEVICE_NOT_AVAILABLE, ret); + TEST_ASSERT_EQUAL(CL_INVALID_PROGRAM_EXECUTABLE, ret); + TEST_ASSERT_EQUAL(true, kernels.empty()); + + cl::Program invalidProgram; + ret = invalidProgram.createKernels(&kernels); + TEST_ASSERT_EQUAL(CL_INVALID_PROGRAM, ret); + TEST_ASSERT_EQUAL(true, kernels.empty()); } } // extern "C" From 78cad8dd7bcc90c35ad8c86ac2134471d6c0b90c Mon Sep 17 00:00:00 2001 From: Kamil Goras Date: Mon, 20 Nov 2023 11:33:02 +0100 Subject: [PATCH 3/3] Code correction --- tests/test_openclhpp.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/test_openclhpp.cpp b/tests/test_openclhpp.cpp index ca3add39..5a726522 100644 --- a/tests/test_openclhpp.cpp +++ b/tests/test_openclhpp.cpp @@ -4579,7 +4579,8 @@ static cl_int clCreateKernelsInProgram_testcreateKernels( case 0: TEST_ASSERT_EQUAL(make_program(0), program); TEST_ASSERT_EQUAL(0, num_kernels); - if (num_kernels_ret != nullptr) { + if (num_kernels_ret != nullptr) + { *num_kernels_ret = 3; } return CL_SUCCESS; @@ -4596,14 +4597,20 @@ static cl_int clCreateKernelsInProgram_testcreateKernels( TEST_ASSERT_EQUAL(make_program(1), program); TEST_ASSERT_EQUAL(0, num_kernels); TEST_ASSERT_NOT_NULL(num_kernels_ret); - *num_kernels_ret = 0; + if (num_kernels_ret != nullptr) + { + *num_kernels_ret = 0; + } return CL_INVALID_PROGRAM_EXECUTABLE; case 3: TEST_ASSERT_EQUAL(nullptr, program); TEST_ASSERT_EQUAL(0, num_kernels); TEST_ASSERT_NOT_NULL(num_kernels_ret); - *num_kernels_ret = 0; + if (num_kernels_ret != nullptr) + { + *num_kernels_ret = 0; + } return CL_INVALID_PROGRAM; default: