mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
cl21: Use single array for function list (#147)
Signed-off-by: Radek Szymanski <radek.szymanski@arm.com>
This commit is contained in:
committed by
Kévin Petit
parent
c0b9a74583
commit
50ba83e754
@@ -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_functions_for_offline_compiler(functionName, deviceToUse);
|
||||
test_missing_support_offline_cmpiler(error, functionName);
|
||||
error = check_opencl_version_with_testname(test.name, deviceToUse);
|
||||
test_missing_feature(error, test.name);
|
||||
|
||||
ret = functionToCall( deviceToUse, context, queue, numElementsToUse); //test_threaded_function( ptr_basefn_list[i], group, context, num_elements);
|
||||
error = check_functions_for_offline_compiler(test.name, deviceToUse);
|
||||
test_missing_support_offline_cmpiler(error, test.name);
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user