/* * Copyright (c) 2017, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ #include "cl_api_tests.h" #include "runtime/helpers/ptr_math.h" using namespace OCLRT; typedef api_tests clCreateContextTests; namespace ULT { static int cbInvoked = 0; void CL_CALLBACK eventCallBack(const char *, const void *, size_t, void *) { cbInvoked++; } TEST_F(clCreateContextTests, returnsSuccess) { auto context = clCreateContext(nullptr, num_devices, devices, nullptr, nullptr, &retVal); ASSERT_EQ(CL_SUCCESS, retVal); ASSERT_NE(nullptr, context); EXPECT_NE(nullptr, context->dispatch.icdDispatch); EXPECT_NE(nullptr, context->dispatch.crtDispatch); retVal = clReleaseContext(context); EXPECT_EQ(CL_SUCCESS, retVal); } TEST_F(clCreateContextTests, noRet) { auto context = clCreateContext(nullptr, num_devices, devices, nullptr, nullptr, nullptr); ASSERT_NE(nullptr, context); EXPECT_NE(nullptr, context->dispatch.icdDispatch); EXPECT_NE(nullptr, context->dispatch.crtDispatch); retVal = clReleaseContext(context); EXPECT_EQ(CL_SUCCESS, retVal); } TEST_F(clCreateContextTests, returnsFail) { auto context = clCreateContext(nullptr, 0, devices, nullptr, nullptr, &retVal); ASSERT_EQ(nullptr, context); ASSERT_EQ(CL_INVALID_VALUE, retVal); cl_int someData = 25; context = clCreateContext(nullptr, num_devices, devices, nullptr, &someData, &retVal); ASSERT_EQ(nullptr, context); ASSERT_EQ(CL_INVALID_VALUE, retVal); } TEST_F(clCreateContextTests, invalidDevices) { cl_device_id devList[2]; devList[0] = devices[0]; devList[1] = (cl_device_id)ptrGarbage; auto context = clCreateContext(nullptr, 2, devList, nullptr, nullptr, &retVal); ASSERT_EQ(nullptr, context); ASSERT_EQ(CL_INVALID_DEVICE, retVal); } TEST_F(clCreateContextTests, nullDevices) { auto context = clCreateContext(nullptr, 2, nullptr, nullptr, nullptr, &retVal); ASSERT_EQ(nullptr, context); ASSERT_EQ(CL_INVALID_VALUE, retVal); } TEST_F(clCreateContextTests, nullUserData) { auto context = clCreateContext(nullptr, num_devices, devices, eventCallBack, nullptr, &retVal); ASSERT_NE(nullptr, context); retVal = clReleaseContext(context); EXPECT_EQ(CL_SUCCESS, retVal); } TEST_F(clCreateContextTests, givenInvalidContextCreationPropertiesThenContextCreationFails) { cl_context_properties invalidProperties[3] = {CL_CONTEXT_PLATFORM, (cl_context_properties) nullptr, 0}; auto context = clCreateContext(invalidProperties, num_devices, devices, nullptr, nullptr, &retVal); EXPECT_EQ(CL_INVALID_PLATFORM, retVal); EXPECT_EQ(nullptr, context); } } // namespace ULT