Skip to content

Commit

Permalink
Added testing scenario for negative result of clCreateContext
Browse files Browse the repository at this point in the history
  • Loading branch information
shajder committed Aug 5, 2024
1 parent 284f757 commit 6d38ec8
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 0 deletions.
1 change: 1 addition & 0 deletions test_conformance/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ add_subdirectory( buffers )
add_subdirectory( commonfns )
add_subdirectory( compiler )
add_subdirectory( computeinfo )
add_subdirectory( context )
add_subdirectory( contractions )
add_subdirectory( conversions )
if(D3D10_IS_SUPPORTED)
Expand Down
8 changes: 8 additions & 0 deletions test_conformance/context/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
set(MODULE_NAME CONTEXT)

set(${MODULE_NAME}_SOURCES
main.cpp
test_context_negative_create.cpp
)

include(../CMakeCommon.txt)
37 changes: 37 additions & 0 deletions test_conformance/context/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Copyright (c) 2023 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "harness/compat.h"
#include <stdio.h>
#include <stdlib.h>

#include <string.h>
#include "procs.h"
#include "harness/testHarness.h"

#if !defined(_WIN32)
#include <unistd.h>
#endif

test_definition test_list[] = {
ADD_TEST_VERSION(context_negative_create, Version(1, 1)),
};

const int test_num = ARRAY_SIZE(test_list);

int main(int argc, const char *argv[])
{
return runTestHarness(argc, argv, test_num, test_list, false, 0);
}
25 changes: 25 additions & 0 deletions test_conformance/context/procs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Copyright (c) 2023 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "harness/errorHelpers.h"
#include "harness/kernelHelpers.h"
#include "harness/typeWrappers.h"
#include "harness/clImageHelper.h"
#include "harness/imageHelpers.h"

extern int test_context_negative_create(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
75 changes: 75 additions & 0 deletions test_conformance/context/test_context_negative_create.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// Copyright (c) 2024 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#include "harness/testHarness.h"
#include "harness/errorHelpers.h"
#include "harness/typeWrappers.h"
#include <chrono>
#include <system_error>
#include <thread>
#include <vector>
#include <algorithm>

int test_context_negative_create(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements)
{
cl_int err = CL_SUCCESS;

cl_uint num_platforms = 0;
err = clGetPlatformIDs(16, nullptr, &num_platforms);
test_error(err, "clGetPlatformIDs failed");


num_platforms = std::max(num_platforms, (cl_uint)2);
std::vector<cl_platform_id> platforms(num_platforms);

err = clGetPlatformIDs(num_platforms, platforms.data(), &num_platforms);
test_error(err, "clGetPlatformIDs failed");

std::vector<cl_device_id> platform_devices;

cl_uint num_devices = 0;
for (int p = 0; p < (int)num_platforms; p++)
{
err = clGetDeviceIDs(platforms[p], CL_DEVICE_TYPE_ALL, 0, nullptr,
&num_devices);
test_error(err, "clGetDeviceIDs failed");

std::vector<cl_device_id> devices(num_devices);
err = clGetDeviceIDs(platforms[p], CL_DEVICE_TYPE_ALL, num_devices,
devices.data(), nullptr);
test_error(err, "clGetDeviceIDs failed");

platform_devices.push_back(devices.front());
}

if (platform_devices.size() < 2)
{
log_info("Can't find needed resources. Skipping the test.\n");
return TEST_SKIPPED_ITSELF;
}

// Create secondary context
clContextWrapper multi_dev_context =
clCreateContext(0, platform_devices.size(), platform_devices.data(),
nullptr, nullptr, &err);
test_error(err, "Failed to create context");

test_failure_error(err, CL_INVALID_PROPERTY,
"Unexpected clCreateContext return");

return TEST_PASS;
}

0 comments on commit 6d38ec8

Please sign in to comment.