From 661a7b08ae846822aadca516f83d346c814854f0 Mon Sep 17 00:00:00 2001 From: Marcin Hajder Date: Tue, 24 Sep 2024 17:42:49 +0200 Subject: [PATCH] Added printf test for long type cases (#2037) according to work plan for issue https://github.com/KhronosGroup/OpenCL-CTS/issues/1058 --- test_conformance/printf/test_printf.cpp | 38 ++++++----- test_conformance/printf/test_printf.h | 2 + test_conformance/printf/util_printf.cpp | 87 +++++++++++++++++++++++-- 3 files changed, 104 insertions(+), 23 deletions(-) diff --git a/test_conformance/printf/test_printf.cpp b/test_conformance/printf/test_printf.cpp index d59e0682..73f0e205 100644 --- a/test_conformance/printf/test_printf.cpp +++ b/test_conformance/printf/test_printf.cpp @@ -698,6 +698,12 @@ int doTest(cl_command_queue queue, cl_context context, return TEST_SKIPPED_ITSELF; } + if ((allTestCase[testId]->_type == TYPE_LONG) && !isLongSupported(device)) + { + log_info("Skipping long because long is not supported.\n"); + return TEST_SKIPPED_ITSELF; + } + if ((allTestCase[testId]->_type == TYPE_DOUBLE || allTestCase[testId]->_type == TYPE_DOUBLE_LIMITS) && !is_extension_available(device, "cl_khr_fp64")) @@ -927,6 +933,12 @@ int test_int(cl_device_id deviceID, cl_context context, cl_command_queue queue, return doTest(gQueue, gContext, TYPE_INT, deviceID); } +int test_long(cl_device_id deviceID, cl_context context, cl_command_queue queue, + int num_elements) +{ + return doTest(gQueue, gContext, TYPE_LONG, deviceID); +} + int test_half(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements) { @@ -1043,23 +1055,15 @@ int test_buffer_size(cl_device_id deviceID, cl_context context, } test_definition test_list[] = { - ADD_TEST(int), - ADD_TEST(half), - ADD_TEST(half_limits), - ADD_TEST(float), - ADD_TEST(float_limits), - ADD_TEST(double), - ADD_TEST(double_limits), - ADD_TEST(octal), - ADD_TEST(unsigned), - ADD_TEST(hexadecimal), - ADD_TEST(char), - ADD_TEST(string), - ADD_TEST(format_string), - ADD_TEST(vector), - ADD_TEST(address_space), - ADD_TEST(buffer_size), - ADD_TEST(mixed_format_random), + ADD_TEST(int), ADD_TEST(long), + ADD_TEST(half), ADD_TEST(half_limits), + ADD_TEST(float), ADD_TEST(float_limits), + ADD_TEST(double), ADD_TEST(double_limits), + ADD_TEST(octal), ADD_TEST(unsigned), + ADD_TEST(hexadecimal), ADD_TEST(char), + ADD_TEST(string), ADD_TEST(format_string), + ADD_TEST(vector), ADD_TEST(address_space), + ADD_TEST(buffer_size), ADD_TEST(mixed_format_random), }; const int test_num = ARRAY_SIZE( test_list ); diff --git a/test_conformance/printf/test_printf.h b/test_conformance/printf/test_printf.h index 51f35117..7e5156a2 100644 --- a/test_conformance/printf/test_printf.h +++ b/test_conformance/printf/test_printf.h @@ -46,6 +46,7 @@ enum PrintfTestType { TYPE_INT, + TYPE_LONG, TYPE_HALF, TYPE_HALF_LIMITS, TYPE_FLOAT, @@ -80,6 +81,7 @@ struct printDataGenParameters // Reference results - filled out at run-time static std::vector correctBufferInt; +static std::vector correctBufferLong; static std::vector correctBufferHalf; static std::vector correctBufferFloat; static std::vector correctBufferDouble; diff --git a/test_conformance/printf/util_printf.cpp b/test_conformance/printf/util_printf.cpp index adf7b930..82183edb 100644 --- a/test_conformance/printf/util_printf.cpp +++ b/test_conformance/printf/util_printf.cpp @@ -23,6 +23,7 @@ // Helpers for generating runtime reference results static void intRefBuilder(printDataGenParameters&, char*, const size_t); +static void longRefBuilder(printDataGenParameters&, char*, const size_t); static void halfRefBuilder(printDataGenParameters&, char* rResult, const size_t); static void floatRefBuilder(printDataGenParameters&, char* rResult, const size_t); @@ -111,6 +112,73 @@ testCase testCaseInt = { }; +//================================== + +// long + +//================================== + +//------------------------------------------------------ + +// [string] format | [string] int-data representation | + +//------------------------------------------------------ + +std::vector printLongGenParameters = { + + //(Minimum) fifteen-wide,default(right)-justified + + { { "%5ld" }, "10000000000L" }, + + //(Minimum) fifteen-wide,left-justified + + { { "%-15ld" }, "-10000000000L" }, + + //(Minimum) fifteen-wide,default(right)-justified,zero-filled + + { { "%015ld" }, "10000000000L" }, + + //(Minimum) fifteen-wide,default(right)-justified,with sign + + { { "%+15ld" }, "-10000000000L" }, + + //(Minimum) fifteen-wide ,left-justified,with sign + + { { "%-+15ld" }, "10000000000L" }, + + //(Minimum) fifteen-digit(zero-filled in absent + // digits),default(right)-justified + + { { "%.15li" }, "10000000000L" }, + + //(Minimum)Sixteen-wide, fifteen-digit(zero-filled in absent + // digits),default(right)-justified + + { { "%-+16.15li" }, "-10000000000L" }, + +}; + +//----------------------------------------------- + +// test case for long | + +//----------------------------------------------- + +testCase testCaseLong = { + + TYPE_LONG, + + correctBufferLong, + + printLongGenParameters, + + longRefBuilder, + + klong + +}; + + //============================================== // half @@ -1404,12 +1472,12 @@ testCase testCaseMixedFormat = { TYPE_MIXED_FORMAT_RANDOM, //------------------------------------------------------------------------------- std::vector allTestCase = { - &testCaseInt, &testCaseHalf, &testCaseHalfLimits, - &testCaseFloat, &testCaseFloatLimits, &testCaseDouble, - &testCaseDoubleLimits, &testCaseOctal, &testCaseUnsigned, - &testCaseHexadecimal, &testCaseChar, &testCaseString, - &testCaseFormatString, &testCaseVector, &testCaseAddrSpace, - &testCaseMixedFormat + &testCaseInt, &testCaseLong, &testCaseHalf, + &testCaseHalfLimits, &testCaseFloat, &testCaseFloatLimits, + &testCaseDouble, &testCaseDoubleLimits, &testCaseOctal, + &testCaseUnsigned, &testCaseHexadecimal, &testCaseChar, + &testCaseString, &testCaseFormatString, &testCaseVector, + &testCaseAddrSpace, &testCaseMixedFormat }; //----------------------------------------- @@ -1526,6 +1594,13 @@ static void intRefBuilder(printDataGenParameters& params, char* refResult, const atoi(params.dataRepresentation)); } +static void longRefBuilder(printDataGenParameters& params, char* refResult, + const size_t refSize) +{ + snprintf(refResult, refSize, params.genericFormats.front().c_str(), + atoll(params.dataRepresentation)); +} + static void halfRefBuilder(printDataGenParameters& params, char* refResult, const size_t refSize) {