Skip to content

Commit 3ebc200

Browse files
committed
add more tests
1 parent 6854f63 commit 3ebc200

1 file changed

Lines changed: 178 additions & 1 deletion

File tree

tests/test_openclhpp.cpp

Lines changed: 178 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,42 @@ void testMoveConstructContextNonNull(void);
535535
void testMoveConstructContextNull(void);
536536
MAKE_MOVE_TESTS(Context, make_context, clReleaseContext, contextPool)
537537

538+
static cl_context clCreateContext_EmptyDevices(
539+
const cl_context_properties* properties,
540+
cl_uint num_devices,
541+
const cl_device_id* devices,
542+
void (CL_CALLBACK* pfn_notify)(const char* errinfo, const void* private_info, size_t cb, void* user_data),
543+
void* user_data,
544+
cl_int* errcode_ret,
545+
int num_calls)
546+
{
547+
(void) num_calls;
548+
549+
TEST_ASSERT_EQUAL(properties, nullptr);
550+
TEST_ASSERT_EQUAL(num_devices, 0);
551+
TEST_ASSERT_EQUAL(devices, nullptr);
552+
TEST_ASSERT_EQUAL(pfn_notify, nullptr);
553+
TEST_ASSERT_EQUAL(user_data, nullptr);
554+
555+
if (errcode_ret) {
556+
errcode_ret[0] = CL_INVALID_VALUE;
557+
}
558+
559+
return nullptr;
560+
}
561+
562+
void testContextCreateEmptyDevices(void)
563+
{
564+
#ifndef CL_HPP_ENABLE_EXCEPTIONS
565+
clCreateContext_StubWithCallback(clCreateContext_EmptyDevices);
566+
567+
cl::vector<cl::Device> vec;
568+
cl::Context context(vec);
569+
570+
TEST_ASSERT_EQUAL(nullptr, context());
571+
#endif
572+
}
573+
538574
/// Stub for querying CL_CONTEXT_DEVICES that returns two devices
539575
static cl_int clGetContextInfo_testContextGetDevices(
540576
cl_context context,
@@ -1967,6 +2003,15 @@ void testKernelSetArgBySetKernelArgSVMPointerWithVectorType(void)
19672003
#endif
19682004
}
19692005

2006+
void testKernelSetArgBySetKernelArgSVMPointerWithEmptyVectorType(void)
2007+
{
2008+
#if CL_HPP_TARGET_OPENCL_VERSION >= 200
2009+
VECTOR_CLASS<int> vec;
2010+
clSetKernelArgSVMPointer_ExpectAndReturn(make_kernel(1), 2, nullptr, CL_SUCCESS);
2011+
TEST_ASSERT_EQUAL(kernelPool[1].setArg(2, vec), CL_SUCCESS);
2012+
#endif
2013+
}
2014+
19702015
void testKernelSetArgBySetKernelArgSVMPointerWithPointerType(void)
19712016
{
19722017
#if CL_HPP_TARGET_OPENCL_VERSION >= 200
@@ -2027,7 +2072,7 @@ void testKernelSetSVMPointers(void)
20272072
#endif
20282073
}
20292074

2030-
void testKernelSetSVMPointersEmpty(void)
2075+
void testKernelSetSVMPointersEmptyVec(void)
20312076
{
20322077
#if CL_HPP_TARGET_OPENCL_VERSION >= 200
20332078
clSetKernelExecInfo_ExpectAndReturn(make_kernel(0),
@@ -2041,6 +2086,20 @@ void testKernelSetSVMPointersEmpty(void)
20412086
#endif
20422087
}
20432088

2089+
void testKernelSetSVMPointersEmptyArray(void)
2090+
{
2091+
#if CL_HPP_TARGET_OPENCL_VERSION >= 200
2092+
clSetKernelExecInfo_ExpectAndReturn(make_kernel(0),
2093+
CL_KERNEL_EXEC_INFO_SVM_PTRS,
2094+
0, nullptr, CL_SUCCESS);
2095+
2096+
std::array<void*, 0> arr;
2097+
cl_int ret = kernelPool[0].setSVMPointers<0>(arr);
2098+
2099+
TEST_ASSERT_EQUAL_HEX(CL_SUCCESS, ret);
2100+
#endif
2101+
}
2102+
20442103
cl_int clSetKernelExecInfo_EnableFineGrainedSystemSVM(cl_kernel kernel,
20452104
cl_kernel_exec_info param_name,
20462105
size_t param_value_size,
@@ -2193,6 +2252,124 @@ void testCopyHostToBuffer(void)
21932252
* Tests for building Programs
21942253
****************************************************************************/
21952254

2255+
static cl_program clCreateProgramWithSource_EmptySource(
2256+
cl_context context,
2257+
cl_uint count,
2258+
const char** strings,
2259+
const size_t* lengths,
2260+
cl_int* errcode_ret,
2261+
int num_calls)
2262+
{
2263+
(void) num_calls;
2264+
2265+
TEST_ASSERT_EQUAL(context, make_context(1));
2266+
TEST_ASSERT_EQUAL(count, 0);
2267+
TEST_ASSERT_EQUAL(strings, nullptr);
2268+
TEST_ASSERT_EQUAL(lengths, nullptr);
2269+
2270+
if (errcode_ret) {
2271+
errcode_ret[0] = CL_INVALID_VALUE;
2272+
}
2273+
2274+
return nullptr;
2275+
}
2276+
2277+
void testProgramCreateEmptySources(void)
2278+
{
2279+
#ifndef CL_HPP_ENABLE_EXCEPTIONS
2280+
clCreateProgramWithSource_StubWithCallback(clCreateProgramWithSource_EmptySource);
2281+
clReleaseContext_ExpectAndReturn(make_context(1), CL_SUCCESS);
2282+
2283+
cl::Context context(make_context(1));
2284+
2285+
cl::Program::Sources sources;
2286+
cl::Program program(context, sources);
2287+
2288+
TEST_ASSERT_EQUAL(nullptr, program());
2289+
#endif
2290+
}
2291+
2292+
static cl_program clCreateProgramWithBinary_EmptyBinaries(
2293+
cl_context context,
2294+
cl_uint num_devices,
2295+
const cl_device_id* device_list,
2296+
const size_t* lengths,
2297+
const unsigned char** binaries,
2298+
cl_int* binary_status,
2299+
cl_int* errcode_ret,
2300+
int num_calls)
2301+
{
2302+
(void) num_calls;
2303+
2304+
TEST_ASSERT_EQUAL(context, make_context(1));
2305+
TEST_ASSERT_EQUAL(num_devices, 0);
2306+
TEST_ASSERT_EQUAL(device_list, nullptr);
2307+
TEST_ASSERT_EQUAL(lengths, nullptr);
2308+
TEST_ASSERT_EQUAL(binaries, nullptr);
2309+
TEST_ASSERT_EQUAL(binary_status, nullptr);
2310+
2311+
if (errcode_ret) {
2312+
errcode_ret[0] = CL_INVALID_VALUE;
2313+
}
2314+
2315+
return nullptr;
2316+
}
2317+
2318+
void testProgramCreateEmptyBinaries(void)
2319+
{
2320+
#ifndef CL_HPP_ENABLE_EXCEPTIONS
2321+
clCreateProgramWithBinary_StubWithCallback(clCreateProgramWithBinary_EmptyBinaries);
2322+
clReleaseContext_ExpectAndReturn(make_context(1), CL_SUCCESS);
2323+
2324+
cl::Context context(make_context(1));
2325+
2326+
cl::vector<cl::Device> devices;
2327+
cl::Program::Binaries binaries;
2328+
cl::Program program(context, devices, binaries);
2329+
2330+
TEST_ASSERT_EQUAL(nullptr, program());
2331+
#endif
2332+
}
2333+
2334+
static cl_program clCreateProgramWithBuiltInKernels_EmptyDevices(
2335+
cl_context context,
2336+
cl_uint num_devices,
2337+
const cl_device_id* device_list,
2338+
const char* kernel_names,
2339+
cl_int* errcode_ret,
2340+
int num_calls)
2341+
{
2342+
(void) num_calls;
2343+
2344+
TEST_ASSERT_EQUAL(context, make_context(1));
2345+
TEST_ASSERT_EQUAL(num_devices, 0);
2346+
TEST_ASSERT_EQUAL(device_list, nullptr);
2347+
TEST_ASSERT_EQUAL_STRING(kernel_names, "foo");
2348+
2349+
if (errcode_ret) {
2350+
errcode_ret[0] = CL_INVALID_VALUE;
2351+
}
2352+
2353+
return nullptr;
2354+
}
2355+
2356+
void testProgramCreateBuiltinKernelsEmptyDevices(void)
2357+
{
2358+
#if CL_HPP_TARGET_OPENCL_VERSION >= 120
2359+
#ifndef CL_HPP_ENABLE_EXCEPTIONS
2360+
clCreateProgramWithBuiltInKernels_StubWithCallback(clCreateProgramWithBuiltInKernels_EmptyDevices);
2361+
clReleaseContext_ExpectAndReturn(make_context(1), CL_SUCCESS);
2362+
2363+
cl::Context context(make_context(1));
2364+
2365+
cl::vector<cl::Device> devices;
2366+
cl::Program program(context, devices, "foo");
2367+
2368+
TEST_ASSERT_EQUAL(nullptr, program());
2369+
#endif
2370+
#endif
2371+
}
2372+
21962373
static cl_int clGetDeviceInfo_testGetBuildInfo(
21972374
cl_device_id device,
21982375
cl_device_info param_name,

0 commit comments

Comments
 (0)