cl22: Use single array for function list (#148)

Signed-off-by: Radek Szymanski <radek.szymanski@arm.com>
This commit is contained in:
Radek Szymanski
2019-04-10 12:30:38 +01:00
committed by Kévin Petit
parent 394dece0d7
commit 07196c351a
139 changed files with 2380 additions and 4142 deletions

View File

@@ -17,19 +17,6 @@
#define TEST_COMMON_AUTOTEST_AUTOTEST_HPP
#include "test_suite.hpp"
#include "test_case.hpp"
namespace autotest {
inline std::vector<const char*> get_strings_ptrs(const std::vector<std::string>& list)
{
std::vector<const char*> v;
for(auto& s : list)
{
v.push_back(s.c_str());
}
return v;
}
}
#define STR_JOIN( X, Y ) STR_DO_JOIN( X, Y )
#define STR_DO_JOIN( X, Y ) STR_DO_JOIN_2(X,Y)
@@ -43,13 +30,6 @@ namespace autotest {
// (test case code...)
// }
//
// It automatically registers created test case to global test_suite object. Test functions
// names and pointers to those functions can be later retrieved this way:
// - std::vector<basefn> test_functions_list = autotest::test_suite::get_test_functions();
// - std::vector<std::string> test_functions_names = autotest::test_suite::get_test_names();
//
// Helper function which constructs vector of const char pointers to test functions names:
// - std::vector<const char *> test_functions_names_c_str = autotest::get_strings_ptrs(test_functions_names);
#define AUTO_TEST_CASE(name) \
struct name { static int run_test(cl_device_id, cl_context, cl_command_queue, int); }; \
static autotest::detail::test_case_registration STR_JOIN(name, STR_JOIN(_registration, __LINE__)) (#name, name::run_test); \

View File

@@ -1,41 +0,0 @@
//
// Copyright (c) 2017 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.
//
#ifndef TEST_COMMON_AUTOTEST_TEST_CASE_HPP
#define TEST_COMMON_AUTOTEST_TEST_CASE_HPP
#include <string>
#include "../../test_common/harness/threadTesting.h"
namespace autotest
{
struct test_case {
// Test case name
const std::string name;
// Pointer to test function.
const basefn function_pointer;
test_case(const std::string& name, const basefn function_ptr)
: name(name), function_pointer(function_ptr)
{
}
};
} // end namespace autotest
#endif // TEST_COMMON_AUTOTEST_TEST_CASE_HPP

View File

@@ -19,8 +19,6 @@
#include <vector>
#include <string>
#include "test_case.hpp"
namespace autotest {
struct test_suite {
@@ -30,33 +28,13 @@ struct test_suite {
}
void add(const test_case& tc)
void add(const test_definition& td)
{
test_cases.push_back(tc);
test_defs.push_back(td);
}
static std::vector<basefn> get_test_functions()
{
std::vector<basefn> v;
for(auto& tc: global_test_suite().test_cases)
{
v.push_back(tc.function_pointer);
}
return v;
}
static std::vector<std::string> get_test_names()
{
std::vector<std::string> v;
for(auto& tc : global_test_suite().test_cases)
{
v.push_back(tc.name);
}
return v;
}
// List of test cases
std::vector<test_case> test_cases;
// List of test definitions
std::vector<test_definition> test_defs;
// Test suite name
const std::string name;
@@ -73,7 +51,7 @@ struct test_case_registration
{
test_case_registration(const std::string& name, const basefn ptr)
{
::autotest::test_suite::global_test_suite().add(test_case(name, ptr));
::autotest::test_suite::global_test_suite().add(test_definition({ptr, name.c_str()}));
}
};

View File

@@ -48,22 +48,20 @@ int gHasLong = 1;
#define DEFAULT_NUM_ELEMENTS 0x4000
int runTestHarness( int argc, const char *argv[], unsigned int num_fns,
basefn fnList[], const char *fnNames[],
int imageSupportRequired, int forceNoContextCreation, cl_command_queue_properties queueProps )
int runTestHarness( int argc, const char *argv[], int testNum, test_definition testList[],
int imageSupportRequired, int forceNoContextCreation, cl_command_queue_properties queueProps )
{
return runTestHarnessWithCheck( argc, argv, num_fns, fnList, fnNames, imageSupportRequired, forceNoContextCreation, queueProps,
return runTestHarnessWithCheck( argc, argv, testNum, testList, imageSupportRequired, forceNoContextCreation, queueProps,
( imageSupportRequired ) ? verifyImageSupport : NULL );
}
int runTestHarnessWithCheck( int argc, const char *argv[], unsigned int num_fns,
basefn fnList[], const char *fnNames[],
int imageSupportRequired, int forceNoContextCreation, cl_command_queue_properties queueProps,
DeviceCheckFn deviceCheckFn )
int runTestHarnessWithCheck( int argc, const char *argv[], int testNum, test_definition testList[],
int imageSupportRequired, int forceNoContextCreation, cl_command_queue_properties queueProps,
DeviceCheckFn deviceCheckFn )
{
test_start();
cl_device_type device_type = CL_DEVICE_TYPE_DEFAULT;
cl_device_type device_type = CL_DEVICE_TYPE_DEFAULT;
cl_uint num_platforms = 0;
cl_platform_id *platforms;
cl_device_id device;
@@ -75,7 +73,6 @@ int runTestHarnessWithCheck( int argc, const char *argv[], unsigned int num_fns,
int err, ret;
char *endPtr;
unsigned int i;
int based_on_env_var = 0;
@@ -137,15 +134,15 @@ int runTestHarnessWithCheck( int argc, const char *argv[], unsigned int num_fns,
/* Special case: just list the tests */
if( ( argc > 1 ) && (!strcmp( argv[ 1 ], "-list" ) || !strcmp( argv[ 1 ], "-h" ) || !strcmp( argv[ 1 ], "--help" )))
{
log_info( "Usage: %s [<function name>*] [pid<num>] [id<num>] [<device type>]\n", argv[0] );
log_info( "Usage: %s [<test name>*] [pid<num>] [id<num>] [<device type>]\n", argv[0] );
log_info( "\t<function name>\tOne or more of: (wildcard character '*') (default *)\n");
log_info( "\tpid<num>\t\tIndicates platform at index <num> should be used (default 0).\n" );
log_info( "\tid<num>\t\tIndicates device at index <num> should be used (default 0).\n" );
log_info( "\t<device_type>\tcpu|gpu|accelerator|<CL_DEVICE_TYPE_*> (default CL_DEVICE_TYPE_DEFAULT)\n" );
for( i = 0; i < num_fns; i++ )
for( int i = 0; i < testNum; i++ )
{
log_info( "\t\t%s\n", fnNames[ i ] );
log_info( "\t\t%s\n", testList[i].name );
}
test_finish();
return 0;
@@ -468,7 +465,7 @@ int runTestHarnessWithCheck( int argc, const char *argv[], unsigned int num_fns,
DisableFTZ( &oldMode );
#endif
int error = parseAndCallCommandLineTests( argc, argv, device, num_fns, fnList, fnNames, forceNoContextCreation, queueProps, num_elements );
int error = parseAndCallCommandLineTests( argc, argv, device, testNum, testList, forceNoContextCreation, queueProps, num_elements );
#if defined(__APPLE__) && defined(__arm__)
// Restore the old FP mode before leaving.
@@ -478,23 +475,23 @@ int runTestHarnessWithCheck( int argc, const char *argv[], unsigned int num_fns,
return error;
}
static int find_wildcard_matching_functions( const char *fnNames[], unsigned char fnsToCall[], unsigned int num_fns,
static int find_wildcard_matching_functions( test_definition testList[], unsigned char selectedTestList[], int testNum,
const char *wildcard )
{
int found_tests = 0;
size_t wildcard_length = strlen( wildcard ) - 1; /* -1 for the asterisk */
for( unsigned int fnIndex = 0; fnIndex < num_fns; fnIndex++ )
for( int fnIndex = 0; fnIndex < testNum; fnIndex++ )
{
if( strncmp( fnNames[ fnIndex ], wildcard, wildcard_length ) == 0 )
if( strncmp( testList[ fnIndex ].name, wildcard, wildcard_length ) == 0 )
{
if( fnsToCall[ fnIndex ] )
if( selectedTestList[ fnIndex ] )
{
log_error( "ERROR: Test '%s' has already been selected.\n", fnNames[ fnIndex ] );
log_error( "ERROR: Test '%s' has already been selected.\n", testList[ fnIndex ].name );
return EXIT_FAILURE;
}
fnsToCall[ fnIndex ] = 1;
selectedTestList[ fnIndex ] = 1;
found_tests = 1;
}
}
@@ -508,29 +505,29 @@ static int find_wildcard_matching_functions( const char *fnNames[], unsigned cha
return EXIT_SUCCESS;
}
static int find_argument_matching_function( const char *fnNames[], unsigned char *fnsToCall, unsigned int num_fns,
static int find_argument_matching_function( test_definition testList[], unsigned char selectedTestList[], int testNum,
const char *argument )
{
unsigned int fnIndex;
int fnIndex;
for( fnIndex = 0; fnIndex < num_fns; fnIndex++ )
for( fnIndex = 0; fnIndex < testNum; fnIndex++ )
{
if( strcmp( argument, fnNames[ fnIndex ] ) == 0 )
if( strcmp( argument, testList[fnIndex].name ) == 0 )
{
if( fnsToCall[ fnIndex ] )
if( selectedTestList[ fnIndex ] )
{
log_error( "ERROR: Test '%s' has already been selected.\n", fnNames[ fnIndex ] );
log_error( "ERROR: Test '%s' has already been selected.\n", testList[fnIndex].name );
return EXIT_FAILURE;
}
else
{
fnsToCall[ fnIndex ] = 1;
selectedTestList[ fnIndex ] = 1;
break;
}
}
}
if( fnIndex == num_fns )
if( fnIndex == testNum )
{
log_error( "ERROR: The argument '%s' did not match any test names.\n", argument );
return EXIT_FAILURE;
@@ -539,18 +536,18 @@ static int find_argument_matching_function( const char *fnNames[], unsigned char
return EXIT_SUCCESS;
}
int parseAndCallCommandLineTests( int argc, const char *argv[], cl_device_id device, unsigned int num_fns,
basefn fnList[], const char *fnNames[], int forceNoContextCreation,
int parseAndCallCommandLineTests( int argc, const char *argv[], cl_device_id device, int testNum,
test_definition testList[], int forceNoContextCreation,
cl_command_queue_properties queueProps, int num_elements )
{
int ret = EXIT_SUCCESS;
unsigned char *fnsToCall = ( unsigned char* ) calloc( num_fns, 1 );
unsigned char *selectedTestList = ( unsigned char* ) calloc( testNum, 1 );
if( argc == 1 )
{
/* No actual arguments, all tests will be run. */
memset( fnsToCall, 1, num_fns );
memset( selectedTestList, 1, testNum );
}
else
{
@@ -558,18 +555,18 @@ int parseAndCallCommandLineTests( int argc, const char *argv[], cl_device_id dev
{
if( strchr( argv[ argIndex ], '*' ) != NULL )
{
ret = find_wildcard_matching_functions( fnNames, fnsToCall, num_fns, argv[ argIndex ] );
ret = find_wildcard_matching_functions( testList, selectedTestList, testNum, argv[ argIndex ] );
}
else
{
if( strcmp( argv[ argIndex ], "all" ) == 0 )
{
memset( fnsToCall, 1, num_fns );
memset( selectedTestList, 1, testNum );
break;
}
else
{
ret = find_argument_matching_function( fnNames, fnsToCall, num_fns, argv[ argIndex ] );
ret = find_argument_matching_function( testList, selectedTestList, testNum, argv[ argIndex ] );
}
}
@@ -582,7 +579,7 @@ int parseAndCallCommandLineTests( int argc, const char *argv[], cl_device_id dev
if( ret == EXIT_SUCCESS )
{
ret = callTestFunctions( fnList, fnNames, fnsToCall, num_fns, device, forceNoContextCreation, num_elements, queueProps );
ret = callTestFunctions( testList, selectedTestList, testNum, device, forceNoContextCreation, num_elements, queueProps );
if( gTestsFailed == 0 )
{
@@ -610,30 +607,30 @@ int parseAndCallCommandLineTests( int argc, const char *argv[], cl_device_id dev
test_finish();
free( fnsToCall );
free( selectedTestList );
return ret;
}
int callTestFunctions( basefn functionList[], const char *functionNames[], unsigned char functionsToCall[],
int numFunctions, cl_device_id deviceToUse, int forceNoContextCreation,
int callTestFunctions( test_definition testList[], unsigned char selectedTestList[],
int testNum, cl_device_id deviceToUse, int forceNoContextCreation,
int numElementsToUse, cl_command_queue_properties queueProps )
{
int numErrors = 0;
for( int i = 0; i < numFunctions; ++i )
for( int i = 0; i < testNum; ++i )
{
if( functionsToCall[ i ] )
if( selectedTestList[i] )
{
/* Skip any unimplemented tests. */
if( functionList[ i ] != NULL )
if( testList[i].func != NULL )
{
numErrors += callSingleTestFunction( functionList[ i ], functionNames[ i ], deviceToUse,
forceNoContextCreation, numElementsToUse, queueProps );
numErrors += callSingleTestFunction( testList[i], deviceToUse, forceNoContextCreation,
numElementsToUse, queueProps );
}
else
{
log_info( "%s test currently not implemented\n", functionNames[ i ] );
log_info( "%s test currently not implemented\n", testList[i].name );
}
}
}
@@ -647,9 +644,8 @@ void CL_CALLBACK notify_callback(const char *errinfo, const void *private_info,
}
// Actual function execution
int callSingleTestFunction( basefn functionToCall, const char *functionName,
cl_device_id deviceToUse, int forceNoContextCreation,
int numElementsToUse, const cl_queue_properties queueProps )
int callSingleTestFunction( test_definition test, cl_device_id deviceToUse, int forceNoContextCreation,
int numElementsToUse, const cl_queue_properties queueProps )
{
int numErrors = 0, ret;
cl_int error;
@@ -677,32 +673,32 @@ int callSingleTestFunction( basefn functionToCall, const char *functionName,
}
/* Run the test and print the result */
log_info( "%s...\n", functionName );
log_info( "%s...\n", test.name );
fflush( stdout );
error = check_opencl_version_with_testname(functionName, deviceToUse);
test_missing_feature(error, functionName);
error = check_opencl_version_with_testname(test.name, deviceToUse);
test_missing_feature(error, test.name);
error = check_functions_for_offline_compiler(functionName, deviceToUse);
test_missing_support_offline_cmpiler(error, functionName);
error = check_functions_for_offline_compiler(test.name, deviceToUse);
test_missing_support_offline_cmpiler(error, test.name);
ret = functionToCall( deviceToUse, context, queue, numElementsToUse); //test_threaded_function( ptr_basefn_list[i], group, context, num_elements);
ret = test.func(deviceToUse, context, queue, numElementsToUse); //test_threaded_function( ptr_basefn_list[i], group, context, num_elements);
if( ret == TEST_NOT_IMPLEMENTED )
{
/* Tests can also let us know they're not implemented yet */
log_info("%s test currently not implemented\n\n", functionName);
log_info("%s test currently not implemented\n\n", test.name);
}
else
{
/* Print result */
if( ret == 0 ) {
log_info( "%s PASSED\n", functionName );
log_info( "%s passed\n", test.name );
gTestsPassed++;
}
else
{
numErrors++;
log_error( "%s FAILED\n", functionName );
log_error( "%s FAILED\n", test.name );
gTestsFailed++;
}
}

View File

@@ -25,6 +25,18 @@
extern "C" {
#endif
#define ADD_TEST(fn) {test_##fn, #fn}
#define NOT_IMPLEMENTED_TEST(fn) {NULL, #fn}
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
typedef struct test_definition
{
basefn func;
const char* name;
} test_definition;
typedef enum test_status
{
TEST_PASS = 0,
@@ -37,39 +49,36 @@ extern cl_uint gRandomSeed;
// Supply a list of functions to test here. This will allocate a CL device, create a context, all that
// setup work, and then call each function in turn as dictatated by the passed arguments.
extern int runTestHarness( int argc, const char *argv[], unsigned int num_fns,
basefn fnList[], const char *fnNames[],
int imageSupportRequired, int forceNoContextCreation, cl_command_queue_properties queueProps );
extern int runTestHarness( int argc, const char *argv[], int testNum, test_definition testList[],
int imageSupportRequired, int forceNoContextCreation, cl_command_queue_properties queueProps );
// Device checking function. See runTestHarnessWithCheck. If this function returns anything other than TEST_PASS, the harness exits.
typedef test_status (*DeviceCheckFn)( cl_device_id device );
// Same as runTestHarness, but also supplies a function that checks the created device for required functionality.
extern int runTestHarnessWithCheck( int argc, const char *argv[], unsigned int num_fns,
basefn fnList[], const char *fnNames[],
int imageSupportRequired, int forceNoContextCreation, cl_command_queue_properties queueProps, DeviceCheckFn deviceCheckFn );
extern int runTestHarnessWithCheck( int argc, const char *argv[], int testNum, test_definition testList[],
int imageSupportRequired, int forceNoContextCreation,
cl_command_queue_properties queueProps, DeviceCheckFn deviceCheckFn );
// The command line parser used by runTestHarness to break up parameters into calls to callTestFunctions
extern int parseAndCallCommandLineTests( int argc, const char *argv[], cl_device_id device, unsigned int num_fns,
basefn *fnList, const char *fnNames[],
int forceNoContextCreation, cl_command_queue_properties queueProps, int num_elements );
extern int parseAndCallCommandLineTests( int argc, const char *argv[], cl_device_id device, int testNum,
test_definition testList[], int forceNoContextCreation,
cl_command_queue_properties queueProps, int num_elements );
// Call this function if you need to do all the setup work yourself, and just need the function list called/
// managed.
// functionList is the actual array of functions
// functionNames is an array of strings representing the name of each function
// functionsToCall is an array of integers (treated as bools) which tell which function is to be called,
// each element at index i, corresponds to the element in functionList at index i
// numFunctions is the number of elements in the arrays
// testList is the data structure that contains test functions and its names
// selectedTestList is an array of integers (treated as bools) which tell which function is to be called,
// each element at index i, corresponds to the element in testList at index i
// testNum is the number of tests in testList and selectedTestList
// contextProps are used to create a testing context for each test
// deviceToUse and numElementsToUse are all just passed to each test function
extern int callTestFunctions( basefn functionList[], const char *functionNames[], unsigned char functionsToCall[],
int numFunctions, cl_device_id deviceToUse, int forceNoContextCreation,
extern int callTestFunctions( test_definition testList[], unsigned char selectedTestList[],
int testNum, cl_device_id deviceToUse, int forceNoContextCreation,
int numElementsToUse, cl_command_queue_properties queueProps );
// This function is called by callTestFunctions, once per function, to do setup, call, logging and cleanup
extern int callSingleTestFunction( basefn functionToCall, const char *functionName,
cl_device_id deviceToUse, int forceNoContextCreation,
extern int callSingleTestFunction( test_definition test, cl_device_id deviceToUse, int forceNoContextCreation,
int numElementsToUse, cl_command_queue_properties queueProps );
///// Miscellaneous steps