Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

Commit

Permalink
Add tests for error behaviour in internal dev. container functions
Browse files Browse the repository at this point in the history
Issue #33
  • Loading branch information
nunofachada committed Jun 11, 2019
1 parent f33580e commit cd35d4a
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ set(TESTS_STUBONLY test_profiler_op)
# implementation
set(TESTS_OPT test_profiler test_platforms test_buffer test_devquery
test_context test_event test_program test_image test_sampler
test_kernel test_queue test_device test_devsel)
test_kernel test_queue test_device test_devsel test_errors)

# Complete set of tests
set(TESTS ${TESTS_STUBONLY} ${TESTS_OPT})
Expand Down
91 changes: 91 additions & 0 deletions tests/lib/test_errors.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* This file is part of cf4ocl (C Framework for OpenCL).
*
* cf4ocl is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* cf4ocl is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with cf4ocl. If not, see <http://www.gnu.org/licenses/>.
* */

/**
* @internal
*
* @file
* Tests if errors occur when they should when using cf4ocl.
*
* @author Nuno Fachada
* @date 2019
* @copyright [GNU General Public License version 3 (GPLv3)](http://www.gnu.org/licenses/gpl.html)
* */

#include <cf4ocl2.h>
#include "test.h"
#include "_ccl_abstract_dev_container_wrapper.h"

/**
* @internal
*
* @brief Used as a mock function for getting devices in a device container
* wrapper.
*/
static CCLWrapperInfo * mock_get_devices(
CCLDevContainer * devcon, CCLErr ** err) {

CCL_UNUSED(devcon);
g_set_error(err, CCL_ERROR, CL_INVALID_VALUE, "Mock error");
return NULL;
}

/**
* @internal
*
* @brief Tests errors in device container functions.
* */
static void device_container_test() {

/* Test variables. */
CCLDevContainer mock_devcon = { { 0, NULL, NULL, 0 }, 0, NULL };
CCLDevice * dev;
CCLErr * err = NULL;

/* Try and get device from mock device container. */
dev = ccl_dev_container_get_device(
&mock_devcon, mock_get_devices, 0, &err);

/* Check that dev is NULL */
g_assert(dev == NULL);

/* Check the error domain and code, and clear the error. */
g_assert_error(err, CCL_ERROR, CL_INVALID_VALUE);
g_clear_error(&err);

/* Confirm that no memory was allocated for wrappers. */
g_assert(ccl_wrapper_memcheck());
}

/**
* @internal
*
* @brief Main function.
* @param[in] argc Number of command line arguments.
* @param[in] argv Command line arguments.
* @return Result of test run.
* */
int main(int argc, char ** argv) {

g_test_init(&argc, &argv, NULL);

g_test_add_func(
"/wrappers/errors/device-container",
device_container_test);

return g_test_run();
}

0 comments on commit cd35d4a

Please sign in to comment.