Corrections for printf test with floating point limits arguments (#1940)

According to work plan from issue #1058
This commit is contained in:
Marcin Hajder
2024-05-21 17:38:04 +02:00
committed by GitHub
parent e6fec7417f
commit 88a707dd13
3 changed files with 477 additions and 306 deletions

View File

@@ -14,6 +14,7 @@
// limitations under the License. // limitations under the License.
// //
#include "harness/os_helpers.h" #include "harness/os_helpers.h"
#include "harness/typeWrappers.h"
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
@@ -78,10 +79,16 @@ static int isKernelPFormat(testCase* pTestCase,size_t testId);
// Static functions declarations // Static functions declarations
//----------------------------------------- //-----------------------------------------
// Make a program that uses printf for the given type/format, // Make a program that uses printf for the given type/format,
static cl_program makePrintfProgram(cl_kernel *kernel_ptr, const cl_context context,const unsigned int testId,const unsigned int testNum,bool isLongSupport = true,bool is64bAddrSpace = false); static cl_program
makePrintfProgram(cl_kernel* kernel_ptr, const cl_context context,
const unsigned int testId, const unsigned int testNum,
const unsigned int formatNum, bool isLongSupport = true,
bool is64bAddrSpace = false);
// Creates and execute the printf test for the given device, context, type/format // Creates and execute the printf test for the given device, context, type/format
static int doTest(cl_command_queue queue, cl_context context, const unsigned int testId, const unsigned int testNum, cl_device_id device); static int doTest(cl_command_queue queue, cl_context context,
const unsigned int testId, const unsigned int testNum,
cl_device_id device);
// Check if device supports long // Check if device supports long
static bool isLongSupported(cl_device_id device_id); static bool isLongSupported(cl_device_id device_id);
@@ -206,7 +213,12 @@ int waitForEvent(cl_event* event)
//----------------------------------------- //-----------------------------------------
// makePrintfProgram // makePrintfProgram
//----------------------------------------- //-----------------------------------------
static cl_program makePrintfProgram(cl_kernel *kernel_ptr, const cl_context context,const unsigned int testId,const unsigned int testNum,bool isLongSupport,bool is64bAddrSpace) static cl_program makePrintfProgram(cl_kernel* kernel_ptr,
const cl_context context,
const unsigned int testId,
const unsigned int testNum,
const unsigned int formatNum,
bool isLongSupport, bool is64bAddrSpace)
{ {
int err; int err;
cl_program program; cl_program program;
@@ -223,7 +235,10 @@ static cl_program makePrintfProgram(cl_kernel *kernel_ptr, const cl_context cont
"(void)\n", "(void)\n",
"{\n" "{\n"
" printf(\"", " printf(\"",
allTestCase[testId]->_genParameters[testNum].genericFormat, allTestCase[testId]
->_genParameters[testNum]
.genericFormats[formatNum]
.c_str(),
"\\n\",", "\\n\",",
allTestCase[testId]->_genParameters[testNum].dataRepresentation, allTestCase[testId]->_genParameters[testNum].dataRepresentation,
");", ");",
@@ -255,11 +270,19 @@ static cl_program makePrintfProgram(cl_kernel *kernel_ptr, const cl_context cont
}; };
//Program Source code for address space //Program Source code for address space
const char* sourceAddrSpace[] = { const char* sourceAddrSpace[] = {
"__kernel void ", testname,"(",addrSpaceArgument, "__kernel void ",
testname,
"(",
addrSpaceArgument,
")\n{\n", ")\n{\n",
allTestCase[testId]->_genParameters[testNum].addrSpaceVariableTypeQualifier, allTestCase[testId]
->_genParameters[testNum]
.addrSpaceVariableTypeQualifier,
"printf(", "printf(",
allTestCase[testId]->_genParameters[testNum].genericFormat, allTestCase[testId]
->_genParameters[testNum]
.genericFormats[formatNum]
.c_str(),
",", ",",
allTestCase[testId]->_genParameters[testNum].addrSpaceParameter, allTestCase[testId]->_genParameters[testNum].addrSpaceParameter,
"); ", "); ",
@@ -399,14 +422,21 @@ static bool is64bAddressSpace(cl_device_id device_id)
//----------------------------------------- //-----------------------------------------
// doTest // doTest
//----------------------------------------- //-----------------------------------------
static int doTest(cl_command_queue queue, cl_context context, const unsigned int testId, const unsigned int testNum, cl_device_id device) static int doTest(cl_command_queue queue, cl_context context,
const unsigned int testId, const unsigned int testNum,
cl_device_id device)
{
int err = TEST_FAIL;
for (unsigned formatNum = 0; formatNum
< allTestCase[testId]->_genParameters[testNum].genericFormats.size();
formatNum++)
{ {
if ((allTestCase[testId]->_type == TYPE_HALF if ((allTestCase[testId]->_type == TYPE_HALF
|| allTestCase[testId]->_type == TYPE_HALF_LIMITS) || allTestCase[testId]->_type == TYPE_HALF_LIMITS)
&& !is_extension_available(device, "cl_khr_fp16")) && !is_extension_available(device, "cl_khr_fp16"))
{ {
log_info( log_info("Skipping half because cl_khr_fp16 extension is not "
"Skipping half because cl_khr_fp16 extension is not supported.\n"); "supported.\n");
return TEST_SKIPPED_ITSELF; return TEST_SKIPPED_ITSELF;
} }
@@ -422,29 +452,67 @@ static int doTest(cl_command_queue queue, cl_context context, const unsigned int
return TEST_SKIPPED_ITSELF; return TEST_SKIPPED_ITSELF;
} }
log_info("%d)testing printf(\"%sv%s%s\",%s)\n",testNum,allTestCase[testId]->_genParameters[testNum].vectorFormatFlag,allTestCase[testId]->_genParameters[testNum].vectorSize, log_info(
allTestCase[testId]->_genParameters[testNum].vectorFormatSpecifier,allTestCase[testId]->_genParameters[testNum].dataRepresentation); "%d)testing printf(\"%sv%s%s\",%s)\n", testNum,
allTestCase[testId]->_genParameters[testNum].vectorFormatFlag,
allTestCase[testId]->_genParameters[testNum].vectorSize,
allTestCase[testId]
->_genParameters[testNum]
.vectorFormatSpecifier,
allTestCase[testId]
->_genParameters[testNum]
.dataRepresentation);
} }
else if (allTestCase[testId]->_type == TYPE_ADDRESS_SPACE) else if (allTestCase[testId]->_type == TYPE_ADDRESS_SPACE)
{ {
if (isKernelArgument(allTestCase[testId], testNum)) if (isKernelArgument(allTestCase[testId], testNum))
{ {
log_info("%d)testing kernel //argument %s \n printf(%s,%s)\n",testNum,allTestCase[testId]->_genParameters[testNum].addrSpaceArgumentTypeQualifier, log_info("%d)testing kernel //argument %s \n printf(%s,%s)\n",
allTestCase[testId]->_genParameters[testNum].genericFormat,allTestCase[testId]->_genParameters[testNum].addrSpaceParameter); testNum,
allTestCase[testId]
->_genParameters[testNum]
.addrSpaceArgumentTypeQualifier,
allTestCase[testId]
->_genParameters[testNum]
.genericFormats[formatNum]
.c_str(),
allTestCase[testId]
->_genParameters[testNum]
.addrSpaceParameter);
} }
else else
{ {
log_info("%d)testing kernel //variable %s \n printf(%s,%s)\n",testNum,allTestCase[testId]->_genParameters[testNum].addrSpaceVariableTypeQualifier, log_info("%d)testing kernel //variable %s \n printf(%s,%s)\n",
allTestCase[testId]->_genParameters[testNum].genericFormat,allTestCase[testId]->_genParameters[testNum].addrSpaceParameter); testNum,
allTestCase[testId]
->_genParameters[testNum]
.addrSpaceVariableTypeQualifier,
allTestCase[testId]
->_genParameters[testNum]
.genericFormats[formatNum]
.c_str(),
allTestCase[testId]
->_genParameters[testNum]
.addrSpaceParameter);
} }
} }
else else
{ {
log_info("%d)testing printf(\"%s\",%s)\n",testNum,allTestCase[testId]->_genParameters[testNum].genericFormat,allTestCase[testId]->_genParameters[testNum].dataRepresentation); log_info("%d)testing printf(\"%s\",%s)\n", testNum,
allTestCase[testId]
->_genParameters[testNum]
.genericFormats[formatNum]
.c_str(),
allTestCase[testId]
->_genParameters[testNum]
.dataRepresentation);
} }
// Long support for varible type // Long support for varible type
if(allTestCase[testId]->_type == TYPE_VECTOR && !strcmp(allTestCase[testId]->_genParameters[testNum].dataType,"long") && !isLongSupported(device)) if (allTestCase[testId]->_type == TYPE_VECTOR
&& !strcmp(allTestCase[testId]->_genParameters[testNum].dataType,
"long")
&& !isLongSupported(device))
{ {
log_info("Long is not supported, test not run.\n"); log_info("Long is not supported, test not run.\n");
return 0; return 0;
@@ -452,16 +520,17 @@ static int doTest(cl_command_queue queue, cl_context context, const unsigned int
// Long support for address in FULL_PROFILE/EMBEDDED_PROFILE // Long support for address in FULL_PROFILE/EMBEDDED_PROFILE
bool isLongSupport = true; bool isLongSupport = true;
if(allTestCase[testId]->_type == TYPE_ADDRESS_SPACE && isKernelPFormat(allTestCase[testId],testNum) && !isLongSupported(device)) if (allTestCase[testId]->_type == TYPE_ADDRESS_SPACE
&& isKernelPFormat(allTestCase[testId], testNum)
&& !isLongSupported(device))
{ {
isLongSupport = false; isLongSupport = false;
} }
int err; clProgramWrapper program;
cl_program program; clKernelWrapper kernel;
cl_kernel kernel; clMemWrapper d_out;
cl_mem d_out = NULL; clMemWrapper d_a;
cl_mem d_a = NULL;
char _analysisBuffer[ANALYSIS_BUFFER_SIZE]; char _analysisBuffer[ANALYSIS_BUFFER_SIZE];
cl_uint out32 = 0; cl_uint out32 = 0;
cl_ulong out64 = 0; cl_ulong out64 = 0;
@@ -470,8 +539,11 @@ static int doTest(cl_command_queue queue, cl_context context, const unsigned int
// Define an index space (global work size) of threads for execution. // Define an index space (global work size) of threads for execution.
size_t globalWorkSize[1]; size_t globalWorkSize[1];
program = makePrintfProgram(&kernel, context,testId,testNum,isLongSupport,is64bAddressSpace(device)); program =
if (!program || !kernel) { makePrintfProgram(&kernel, context, testId, testNum, formatNum,
isLongSupport, is64bAddressSpace(device));
if (!program || !kernel)
{
++s_test_fail; ++s_test_fail;
++s_test_cnt; ++s_test_cnt;
return -1; return -1;
@@ -483,16 +555,19 @@ static int doTest(cl_command_queue queue, cl_context context, const unsigned int
if (isKernelArgument(allTestCase[testId], testNum)) if (isKernelArgument(allTestCase[testId], testNum))
{ {
int a = 2; int a = 2;
d_a = clCreateBuffer(context, CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR, d_a = clCreateBuffer(context,
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
sizeof(int), &a, &err); sizeof(int), &a, &err);
if(err!= CL_SUCCESS || d_a == NULL) { if (err != CL_SUCCESS || d_a == NULL)
{
log_error("clCreateBuffer failed\n"); log_error("clCreateBuffer failed\n");
goto exit; continue;
} }
err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &d_a); err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &d_a);
if(err!= CL_SUCCESS) { if (err != CL_SUCCESS)
{
log_error("clSetKernelArg failed\n"); log_error("clSetKernelArg failed\n");
goto exit; continue;
} }
} }
// For address space test if %p is tested // For address space test if %p is tested
@@ -500,14 +575,16 @@ static int doTest(cl_command_queue queue, cl_context context, const unsigned int
{ {
d_out = clCreateBuffer(context, CL_MEM_READ_WRITE, d_out = clCreateBuffer(context, CL_MEM_READ_WRITE,
sizeof(cl_ulong), NULL, &err); sizeof(cl_ulong), NULL, &err);
if(err!= CL_SUCCESS || d_out == NULL) { if (err != CL_SUCCESS || d_out == NULL)
{
log_error("clCreateBuffer failed\n"); log_error("clCreateBuffer failed\n");
goto exit; continue;
} }
err = clSetKernelArg(kernel, 1, sizeof(cl_mem), &d_out); err = clSetKernelArg(kernel, 1, sizeof(cl_mem), &d_out);
if(err!= CL_SUCCESS) { if (err != CL_SUCCESS)
{
log_error("clSetKernelArg failed\n"); log_error("clSetKernelArg failed\n");
goto exit; continue;
} }
} }
} }
@@ -516,16 +593,18 @@ static int doTest(cl_command_queue queue, cl_context context, const unsigned int
if (err != 0) if (err != 0)
{ {
log_error("Error while redirection stdout to file"); log_error("Error while redirection stdout to file");
goto exit; continue;
} }
globalWorkSize[0] = 1; globalWorkSize[0] = 1;
cl_event ndrEvt; cl_event ndrEvt;
err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, globalWorkSize, NULL, 0, NULL,&ndrEvt); err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, globalWorkSize,
if (err != CL_SUCCESS) { NULL, 0, NULL, &ndrEvt);
if (err != CL_SUCCESS)
{
releaseOutputStream(fd); releaseOutputStream(fd);
log_error("\n clEnqueueNDRangeKernel failed errcode:%d\n", err); log_error("\n clEnqueueNDRangeKernel failed errcode:%d\n", err);
++s_test_fail; ++s_test_fail;
goto exit; continue;
} }
fflush(stdout); fflush(stdout);
@@ -534,10 +613,10 @@ static int doTest(cl_command_queue queue, cl_context context, const unsigned int
{ {
releaseOutputStream(fd); releaseOutputStream(fd);
log_error("clFlush failed\n"); log_error("clFlush failed\n");
goto exit; continue;
} }
//Wait until kernel finishes its execution and (thus) the output printed from the kernel // Wait until kernel finishes its execution and (thus) the output
//is immediately printed // printed from the kernel is immediately printed
err = waitForEvent(&ndrEvt); err = waitForEvent(&ndrEvt);
releaseOutputStream(fd); releaseOutputStream(fd);
@@ -545,22 +624,24 @@ static int doTest(cl_command_queue queue, cl_context context, const unsigned int
if (err != CL_SUCCESS) if (err != CL_SUCCESS)
{ {
log_error("waitforEvent failed\n"); log_error("waitforEvent failed\n");
goto exit; continue;
} }
fflush(stdout); fflush(stdout);
if(allTestCase[testId]->_type == TYPE_ADDRESS_SPACE && isKernelPFormat(allTestCase[testId],testNum)) if (allTestCase[testId]->_type == TYPE_ADDRESS_SPACE
&& isKernelPFormat(allTestCase[testId], testNum))
{ {
// Read the OpenCL output buffer (d_out) to the host output array (out) // Read the OpenCL output buffer (d_out) to the host output array
// (out)
if (!is64bAddressSpace(device)) // 32-bit address space if (!is64bAddressSpace(device)) // 32-bit address space
{ {
clEnqueueReadBuffer(queue, d_out, CL_TRUE, 0, sizeof(cl_int),&out32, clEnqueueReadBuffer(queue, d_out, CL_TRUE, 0, sizeof(cl_int),
0, NULL, NULL); &out32, 0, NULL, NULL);
} }
else // 64-bit address space else // 64-bit address space
{ {
clEnqueueReadBuffer(queue, d_out, CL_TRUE, 0, sizeof(cl_ulong),&out64, clEnqueueReadBuffer(queue, d_out, CL_TRUE, 0, sizeof(cl_ulong),
0, NULL, NULL); &out64, 0, NULL, NULL);
} }
} }
@@ -570,23 +651,20 @@ static int doTest(cl_command_queue queue, cl_context context, const unsigned int
getAnalysisBuffer(_analysisBuffer); getAnalysisBuffer(_analysisBuffer);
if (!is64bAddressSpace(device)) // 32-bit address space if (!is64bAddressSpace(device)) // 32-bit address space
{ {
if(0 != verifyOutputBuffer(_analysisBuffer,allTestCase[testId],testNum,(cl_ulong) out32)) if (0
!= verifyOutputBuffer(_analysisBuffer, allTestCase[testId],
testNum, (cl_ulong)out32))
err = ++s_test_fail; err = ++s_test_fail;
} }
else //64-bit address space else //64-bit address space
{ {
if(0 != verifyOutputBuffer(_analysisBuffer,allTestCase[testId],testNum,out64)) if (0
!= verifyOutputBuffer(_analysisBuffer, allTestCase[testId],
testNum, out64))
err = ++s_test_fail; err = ++s_test_fail;
} }
exit: }
if(clReleaseKernel(kernel) != CL_SUCCESS)
log_error("clReleaseKernel failed\n");
if(clReleaseProgram(program) != CL_SUCCESS)
log_error("clReleaseProgram failed\n");
if(d_out)
clReleaseMemObject(d_out);
if(d_a)
clReleaseMemObject(d_a);
++s_test_cnt; ++s_test_cnt;
return err; return err;
} }

View File

@@ -62,7 +62,7 @@ enum PrintfTestType
struct printDataGenParameters struct printDataGenParameters
{ {
const char* genericFormat; std::vector<std::string> genericFormats;
const char* dataRepresentation; const char* dataRepresentation;
const char* vectorFormatFlag; const char* vectorFormatFlag;
const char* vectorFormatSpecifier; const char* vectorFormatSpecifier;

View File

@@ -46,39 +46,41 @@ std::vector<printDataGenParameters> printIntGenParameters = {
//(Minimum)Five-wide,default(right)-justified //(Minimum)Five-wide,default(right)-justified
{"%5d","10"}, { { "%5d" }, "10" },
//(Minimum)Five-wide,left-justified //(Minimum)Five-wide,left-justified
{"%-5d","10"}, { { "%-5d" }, "10" },
//(Minimum)Five-wide,default(right)-justified,zero-filled //(Minimum)Five-wide,default(right)-justified,zero-filled
{"%05d","10"}, { { "%05d" }, "10" },
//(Minimum)Five-wide,default(right)-justified,with sign //(Minimum)Five-wide,default(right)-justified,with sign
{"%+5d","10"}, { { "%+5d" }, "10" },
//(Minimum)Five-wide ,left-justified,with sign //(Minimum)Five-wide ,left-justified,with sign
{"%-+5d","10"}, { { "%-+5d" }, "10" },
//(Minimum)Five-digit(zero-filled in absent digits),default(right)-justified //(Minimum)Five-digit(zero-filled in absent digits),default(right)-justified
{"%.5i","100"}, { { "%.5i" }, "100" },
//(Minimum)Six-wide,Five-digit(zero-filled in absent digits),default(right)-justified //(Minimum)Six-wide,Five-digit(zero-filled in absent
// digits),default(right)-justified
{"%6.5i","100"}, { { "%6.5i" }, "100" },
// 0 and - flag both apper ==>0 is ignored,left-justified,capital I // 0 and - flag both apper ==>0 is ignored,left-justified,capital I
{"%-06i","100"}, { { "%-06i" }, "100" },
//(Minimum)Six-wide,Five-digit(zero-filled in absent digits),default(right)-justified //(Minimum)Six-wide,Five-digit(zero-filled in absent
// digits),default(right)-justified
{"%06.5i","100"} { { "%06.5i" }, "100" }
}; };
@@ -119,50 +121,50 @@ std::vector<printDataGenParameters> printHalfGenParameters = {
// Default(right)-justified // Default(right)-justified
{ "%f", "1.234h" }, { { "%f" }, "1.234h" },
// One position after the decimal,default(right)-justified // One position after the decimal,default(right)-justified
{ "%4.2f", "1.2345h" }, { { "%4.2f" }, "1.2345h" },
// Zero positions after the // Zero positions after the
// decimal([floor]rounding),default(right)-justified // decimal([floor]rounding),default(right)-justified
{ "%.0f", "0.1h" }, { { "%.0f" }, "0.1h" },
// Zero positions after the decimal([ceil]rounding),default(right)-justified // Zero positions after the decimal([ceil]rounding),default(right)-justified
{ "%.0f", "0.6h" }, { { "%.0f" }, "0.6h" },
// Zero-filled,default positions number after the // Zero-filled,default positions number after the
// decimal,default(right)-justified // decimal,default(right)-justified
{ "%0f", "0.6h" }, { { "%0f" }, "0.6h" },
// Double argument representing floating-point,used by f // Double argument representing floating-point,used by f
// style,default(right)-justified // style,default(right)-justified
{ "%4g", "5.678h" }, { { "%4g" }, "5.678h" },
// Double argument representing floating-point,used by e // Double argument representing floating-point,used by e
// style,default(right)-justified // style,default(right)-justified
{ "%4.2g", "5.678h" }, { { "%4.2g" }, "5.678h" },
// Double argument representing floating-point,used by e // Double argument representing floating-point,used by e
// style,default(right)-justified // style,default(right)-justified
{ "%4G", "0.000062h" }, { { "%4G" }, "0.000062h" },
// Double argument representing floating-point,with // Double argument representing floating-point,with
// exponent,left-justified,default(right)-justified // exponent,left-justified,default(right)-justified
{ "%-#20.15e", "65504.0h" }, { { "%-#20.15e" }, "65504.0h" },
// Double argument representing floating-point,with // Double argument representing floating-point,with
// exponent,left-justified,with sign,capital E,default(right)-justified // exponent,left-justified,with sign,capital E,default(right)-justified
{ "%+#21.15E", "-65504.0h" }, { { "%+#21.15E" }, "-65504.0h" },
}; };
//--------------------------------------------------------- //---------------------------------------------------------
@@ -203,16 +205,22 @@ testCase testCaseHalf = {
std::vector<printDataGenParameters> printHalfLimitsGenParameters = { std::vector<printDataGenParameters> printHalfLimitsGenParameters = {
// Infinity (1.0/0.0) // Infinity (1.0/0.0)
{ { "%f", "%e", "%g", "%a" }, "1.0h/0.0h" },
{ "%f", "1.0h/0.0h" },
// NaN // NaN
{ { "%f", "%e", "%g", "%a" }, "nan((ushort)0)" },
{ "%f", "sqrt(-1.0h)" },
// NaN // NaN
{ "%f", "acospi(2.0h)" } { { "%f", "%e", "%g", "%a" }, "acospi(2.0h)" },
// Infinity (1.0/0.0)
{ { "%F", "%E", "%G", "%A" }, "1.0h/0.0h" },
// NaN
{ { "%F", "%E", "%G", "%A" }, "nan((ushort)0)" },
// NaN
{ { "%F", "%E", "%G", "%A" }, "acospi(2.0h)" }
}; };
//-------------------------------------------------------- //--------------------------------------------------------
@@ -224,9 +232,15 @@ std::vector<std::string> correctBufferHalfLimits = {
"inf", "inf",
"-nan", "nan",
"nan" "nan",
"INF",
"NAN",
"NAN"
}; };
@@ -267,75 +281,87 @@ std::vector<printDataGenParameters> printFloatGenParameters = {
// Default(right)-justified // Default(right)-justified
{"%f","10.3456"}, { { "%f" }, "10.3456" },
// One position after the decimal,default(right)-justified // One position after the decimal,default(right)-justified
{"%.1f","10.3456"}, { { "%.1f" }, "10.3456" },
// Two positions after the decimal,default(right)-justified // Two positions after the decimal,default(right)-justified
{"%.2f","10.3456"}, { { "%.2f" }, "10.3456" },
//(Minimum)Eight-wide,three positions after the decimal,default(right)-justified //(Minimum)Eight-wide,three positions after the
// decimal,default(right)-justified
{"%8.3f","10.3456"}, { { "%8.3f" }, "10.3456" },
//(Minimum)Eight-wide,two positions after the decimal,zero-filled,default(right)-justified //(Minimum)Eight-wide,two positions after the
// decimal,zero-filled,default(right)-justified
{"%08.2f","10.3456"}, { { "%08.2f" }, "10.3456" },
//(Minimum)Eight-wide,two positions after the decimal,left-justified //(Minimum)Eight-wide,two positions after the decimal,left-justified
{"%-8.2f","10.3456"}, { { "%-8.2f" }, "10.3456" },
//(Minimum)Eight-wide,two positions after the decimal,with sign,default(right)-justified //(Minimum)Eight-wide,two positions after the decimal,with
// sign,default(right)-justified
{"%+8.2f","-10.3456"}, { { "%+8.2f" }, "-10.3456" },
//Zero positions after the decimal([floor]rounding),default(right)-justified // Zero positions after the
// decimal([floor]rounding),default(right)-justified
{"%.0f","0.1"}, { { "%.0f" }, "0.1" },
// Zero positions after the decimal([ceil]rounding),default(right)-justified // Zero positions after the decimal([ceil]rounding),default(right)-justified
{"%.0f","0.6"}, { { "%.0f" }, "0.6" },
//Zero-filled,default positions number after the decimal,default(right)-justified // Zero-filled,default positions number after the
// decimal,default(right)-justified
{"%0f","0.6"}, { { "%0f" }, "0.6" },
//Double argument representing floating-point,used by f style,default(right)-justified // Double argument representing floating-point,used by f
// style,default(right)-justified
{"%4g","12345.6789"}, { { "%4g" }, "12345.6789" },
//Double argument representing floating-point,used by e style,default(right)-justified // Double argument representing floating-point,used by e
// style,default(right)-justified
{"%4.2g","12345.6789"}, { { "%4.2g" }, "12345.6789" },
//Double argument representing floating-point,used by f style,default(right)-justified // Double argument representing floating-point,used by f
// style,default(right)-justified
{"%4G","0.0000023"}, { { "%4G" }, "0.0000023" },
//Double argument representing floating-point,used by e style,default(right)-justified // Double argument representing floating-point,used by e
// style,default(right)-justified
{"%4G","0.023"}, { { "%4G" }, "0.023" },
//Double argument representing floating-point,with exponent,left-justified,default(right)-justified // Double argument representing floating-point,with
// exponent,left-justified,default(right)-justified
{"%-#20.15e","789456123.0"}, { { "%-#20.15e" }, "789456123.0" },
//Double argument representing floating-point,with exponent,left-justified,with sign,capital E,default(right)-justified // Double argument representing floating-point,with
// exponent,left-justified,with sign,capital E,default(right)-justified
{"%+#21.15E","789456123.0"}, { { "%+#21.15E" }, "789456123.0" },
// Double argument representing floating-point,in [-]xh.hhhhpAd style // Double argument representing floating-point,in [-]xh.hhhhpAd style
{"%.6a","0.1"}, { { "%.6a" }, "0.1" },
//(Minimum)Ten-wide,Double argument representing floating-point,in xh.hhhhpAd style,default(right)-justified //(Minimum)Ten-wide,Double argument representing floating-point,in
// xh.hhhhpAd style,default(right)-justified
{"%10.2a","9990.235"}, { { "%10.2a" }, "9990.235" },
}; };
//--------------------------------------------------------- //---------------------------------------------------------
@@ -376,16 +402,22 @@ testCase testCaseFloat = {
std::vector<printDataGenParameters> printFloatLimitsGenParameters = { std::vector<printDataGenParameters> printFloatLimitsGenParameters = {
// Infinity (1.0/0.0) // Infinity (1.0/0.0)
{ { "%f", "%e", "%g", "%a" }, "1.0f/0.0f" },
{ "%f", "1.0f/0.0f" },
// NaN // NaN
{ { "%f", "%e", "%g", "%a" }, "nan(0U)" },
{ "%f", "sqrt(-1.0f)" },
// NaN // NaN
{ "%f", "acospi(2.0f)" } { { "%f", "%e", "%g", "%a" }, "acospi(2.0f)" },
// Infinity (1.0/0.0)
{ { "%F", "%E", "%G", "%A" }, "1.0f/0.0f" },
// NaN
{ { "%F", "%E", "%G", "%A" }, "nan(0U)" },
// NaN
{ { "%F", "%E", "%G", "%A" }, "acospi(2.0f)" }
}; };
//-------------------------------------------------------- //--------------------------------------------------------
@@ -397,9 +429,15 @@ std::vector<std::string> correctBufferFloatLimits = {
"inf", "inf",
"-nan", "nan",
"nan" "nan",
"INF",
"NAN",
"NAN"
}; };
@@ -439,19 +477,20 @@ std::vector<printDataGenParameters> printOctalGenParameters = {
// Default(right)-justified // Default(right)-justified
{"%o","10"}, { { "%o" }, "10" },
// Five-digit,default(right)-justified // Five-digit,default(right)-justified
{"%.5o","10"}, { { "%.5o" }, "10" },
// Default(right)-justified,increase precision // Default(right)-justified,increase precision
{"%#o","100000000"}, { { "%#o" }, "100000000" },
//(Minimum)Four-wide,Five-digit,0-flag ignored(because of precision),default(right)-justified //(Minimum)Four-wide,Five-digit,0-flag ignored(because of
// precision),default(right)-justified
{"%04.5o","10"} { { "%04.5o" }, "10" }
}; };
@@ -495,17 +534,17 @@ std::vector<printDataGenParameters> printUnsignedGenParameters = {
// Default(right)-justified // Default(right)-justified
{"%u","10"}, { { "%u" }, "10" },
// Zero precision for zero,default(right)-justified // Zero precision for zero,default(right)-justified
{"%.0u","0"}, { { "%.0u" }, "0" },
}; };
//------------------------------------------------------- //-------------------------------------------------------
//Test case for octal | // Test case for unsigned |
//------------------------------------------------------- //-------------------------------------------------------
@@ -543,23 +582,23 @@ std::vector<printDataGenParameters> printHexadecimalGenParameters = {
// Add 0x,low x,default(right)-justified // Add 0x,low x,default(right)-justified
{"%#x","0xABCDEF"}, { { "%#x" }, "0xABCDEF" },
// Add 0x,capital X,default(right)-justified // Add 0x,capital X,default(right)-justified
{"%#X","0xABCDEF"}, { { "%#X" }, "0xABCDEF" },
// Not add 0x,if zero,default(right)-justified // Not add 0x,if zero,default(right)-justified
{"%#X","0"}, { { "%#X" }, "0" },
//(Minimum)Eight-wide,default(right)-justified //(Minimum)Eight-wide,default(right)-justified
{"%8x","399"}, { { "%8x" }, "399" },
//(Minimum)Four-wide,zero-filled,default(right)-justified //(Minimum)Four-wide,zero-filled,default(right)-justified
{"%04x","399"} { { "%04x" }, "399" }
}; };
@@ -603,15 +642,15 @@ std::vector<printDataGenParameters> printCharGenParameters = {
// Four-wide,zero-filled,default(right)-justified // Four-wide,zero-filled,default(right)-justified
{"%4c","\'1\'"}, { { "%4c" }, "\'1\'" },
// Four-wide,left-justified // Four-wide,left-justified
{"%-4c","\'1\'"}, { { "%-4c" }, "\'1\'" },
//(unsigned) int argument,default(right)-justified //(unsigned) int argument,default(right)-justified
{"%c","66"} { { "%c" }, "66" }
}; };
@@ -674,15 +713,15 @@ std::vector<printDataGenParameters> printStringGenParameters = {
//(Minimum)Four-wide,zero-filled,default(right)-justified //(Minimum)Four-wide,zero-filled,default(right)-justified
{"%4s","\"foo\""}, { { "%4s" }, "\"foo\"" },
// One-digit(precision ignored),left-justified // One-digit(precision ignored),left-justified
{"%.1s","\"foo\""}, { { "%.1s" }, "\"foo\"" },
//%% specification //%% specification
{"%s","\"%%\""}, { { "%s" }, "\"%%\"" },
}; };
//--------------------------------------------------------- //---------------------------------------------------------
@@ -741,27 +780,27 @@ std::vector<printDataGenParameters> printVectorGenParameters = {
//(Minimum)Two-wide,two positions after decimal //(Minimum)Two-wide,two positions after decimal
{ NULL, "(1.0f,2.0f,3.0f,4.0f)", "%2.2", "hlf", "float", "4" }, { { "" }, "(1.0f,2.0f,3.0f,4.0f)", "%2.2", "hlf", "float", "4" },
// Alternative form,uchar argument // Alternative form,uchar argument
{ NULL, "(0xFA,0xFB)", "%#", "hhx", "uchar", "2" }, { { "" }, "(0xFA,0xFB)", "%#", "hhx", "uchar", "2" },
// Alternative form,ushort argument // Alternative form,ushort argument
{ NULL, "(0x1234,0x8765)", "%#", "hx", "ushort", "2" }, { { "" }, "(0x1234,0x8765)", "%#", "hx", "ushort", "2" },
// Alternative form,uint argument // Alternative form,uint argument
{ NULL, "(0x12345678,0x87654321)", "%#", "hlx", "uint", "2" }, { { "" }, "(0x12345678,0x87654321)", "%#", "hlx", "uint", "2" },
// Alternative form,long argument // Alternative form,long argument
{ NULL, "(12345678,98765432)", "%", "ld", "long", "2" }, { { "" }, "(12345678,98765432)", "%", "ld", "long", "2" },
//(Minimum)Two-wide,two positions after decimal //(Minimum)Two-wide,two positions after decimal
{ NULL, "(1.0h,2.0h,3.0h,4.0h)", "%2.2", "hf", "half", "4" } { { "" }, "(1.0h,2.0h,3.0h,4.0h)", "%2.2", "hf", "half", "4" }
}; };
//------------------------------------------------------------ //------------------------------------------------------------
@@ -821,28 +860,72 @@ testCase testCaseVector = {
//------------------------------------------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------------------------------------------
std::vector<printDataGenParameters> printAddrSpaceGenParameters = { std::vector<printDataGenParameters> printAddrSpaceGenParameters = {
// Global memory region // Global memory region
{"\"%d\\n\"",NULL,NULL,NULL,NULL,NULL,"__global int* x","","*x",""}, { { "\"%d\\n\"" },
NULL,
NULL,
NULL,
NULL,
NULL,
"__global int* x",
"",
"*x",
"" },
// Global,constant, memory region // Global,constant, memory region
{"\"%d\\n\"",NULL,NULL,NULL,NULL,NULL,"constant int* x","","*x",""}, { { "\"%d\\n\"" },
NULL,
NULL,
NULL,
NULL,
NULL,
"constant int* x",
"",
"*x",
"" },
// Local memory region // Local memory region
{"\"%+d\\n\"",NULL,NULL,NULL,NULL,NULL,"","local int x;\n x= (int)3;\n","x",""}, { { "\"%+d\\n\"" },
NULL,
NULL,
NULL,
NULL,
NULL,
"",
"local int x;\n x= (int)3;\n",
"x",
"" },
// Private memory region // Private memory region
{"\"%i\\n\"",NULL,NULL,NULL,NULL,NULL,"","private int x;\n x = (int)-1;\n","x",""}, { { "\"%i\\n\"" },
NULL,
NULL,
NULL,
NULL,
NULL,
"",
"private int x;\n x = (int)-1;\n",
"x",
"" },
// Address of void * from global memory region // Address of void * from global memory region
{"\"%p\\n\"",NULL,NULL,NULL,NULL,NULL,"__global void* x,__global intptr_t* xAddr","","x","*xAddr = (intptr_t)x;\n"} { { "\"%p\\n\"" },
NULL,
NULL,
NULL,
NULL,
NULL,
"__global void* x,__global intptr_t* xAddr",
"",
"x",
"*xAddr = (intptr_t)x;\n" }
}; };
@@ -955,17 +1038,25 @@ size_t verifyOutputBuffer(char *analysisBuffer,testCase* pTestCase,size_t testId
++eCorrectBuffer; ++eCorrectBuffer;
return strcmp(eCorrectBuffer,exp); return strcmp(eCorrectBuffer,exp);
} }
if(!strcmp(pTestCase->_correctBuffer[testId].c_str(),"inf"))
return strcmp(analysisBuffer,"inf")&&strcmp(analysisBuffer,"infinity")&&strcmp(analysisBuffer,"1.#INF00")&&strcmp(analysisBuffer,"Inf"); if (pTestCase->_correctBuffer[testId] == "inf")
if(!strcmp(pTestCase->_correctBuffer[testId].c_str(),"nan") || !strcmp(pTestCase->_correctBuffer[testId].c_str(),"-nan")) { return strcmp(analysisBuffer, "inf")
return strcmp(analysisBuffer,"nan")&&strcmp(analysisBuffer,"-nan")&&strcmp(analysisBuffer,"1.#IND00")&&strcmp(analysisBuffer,"-1.#IND00")&&strcmp(analysisBuffer,"NaN")&&strcmp(analysisBuffer,"nan(ind)")&&strcmp(analysisBuffer,"nan(snan)")&&strcmp(analysisBuffer,"-nan(ind)"); && strcmp(analysisBuffer, "infinity");
} else if (pTestCase->_correctBuffer[testId] == "INF")
return strcmp(analysisBuffer, "INF")
&& strcmp(analysisBuffer, "INFINITY");
else if (pTestCase->_correctBuffer[testId] == "nan")
return strcmp(analysisBuffer, "nan") && strcmp(analysisBuffer, "-nan");
else if (pTestCase->_correctBuffer[testId] == "NAN")
return strcmp(analysisBuffer, "NAN") && strcmp(analysisBuffer, "-NAN");
return strcmp(analysisBuffer, pTestCase->_correctBuffer[testId].c_str()); return strcmp(analysisBuffer, pTestCase->_correctBuffer[testId].c_str());
} }
static void intRefBuilder(printDataGenParameters& params, char* refResult, const size_t refSize) static void intRefBuilder(printDataGenParameters& params, char* refResult, const size_t refSize)
{ {
snprintf(refResult, refSize, params.genericFormat, atoi(params.dataRepresentation)); snprintf(refResult, refSize, params.genericFormats.front().c_str(),
atoi(params.dataRepresentation));
} }
static void halfRefBuilder(printDataGenParameters& params, char* refResult, static void halfRefBuilder(printDataGenParameters& params, char* refResult,
@@ -973,30 +1064,32 @@ static void halfRefBuilder(printDataGenParameters& params, char* refResult,
{ {
cl_half val = cl_half_from_float(strtof(params.dataRepresentation, NULL), cl_half val = cl_half_from_float(strtof(params.dataRepresentation, NULL),
half_rounding_mode); half_rounding_mode);
snprintf(refResult, refSize, params.genericFormat, cl_half_to_float(val)); snprintf(refResult, refSize, params.genericFormats.front().c_str(),
cl_half_to_float(val));
} }
static void floatRefBuilder(printDataGenParameters& params, char* refResult, const size_t refSize) static void floatRefBuilder(printDataGenParameters& params, char* refResult, const size_t refSize)
{ {
snprintf(refResult, refSize, params.genericFormat, strtof(params.dataRepresentation, NULL)); snprintf(refResult, refSize, params.genericFormats.front().c_str(),
strtof(params.dataRepresentation, NULL));
} }
static void octalRefBuilder(printDataGenParameters& params, char* refResult, const size_t refSize) static void octalRefBuilder(printDataGenParameters& params, char* refResult, const size_t refSize)
{ {
const unsigned long int data = strtoul(params.dataRepresentation, NULL, 10); const unsigned long int data = strtoul(params.dataRepresentation, NULL, 10);
snprintf(refResult, refSize, params.genericFormat, data); snprintf(refResult, refSize, params.genericFormats.front().c_str(), data);
} }
static void unsignedRefBuilder(printDataGenParameters& params, char* refResult, const size_t refSize) static void unsignedRefBuilder(printDataGenParameters& params, char* refResult, const size_t refSize)
{ {
const unsigned long int data = strtoul(params.dataRepresentation, NULL, 10); const unsigned long int data = strtoul(params.dataRepresentation, NULL, 10);
snprintf(refResult, refSize, params.genericFormat, data); snprintf(refResult, refSize, params.genericFormats.front().c_str(), data);
} }
static void hexRefBuilder(printDataGenParameters& params, char* refResult, const size_t refSize) static void hexRefBuilder(printDataGenParameters& params, char* refResult, const size_t refSize)
{ {
const unsigned long int data = strtoul(params.dataRepresentation, NULL, 0); const unsigned long int data = strtoul(params.dataRepresentation, NULL, 0);
snprintf(refResult, refSize, params.genericFormat, data); snprintf(refResult, refSize, params.genericFormats.front().c_str(), data);
} }
/* /*