SWDEV-299127 - Merge 'develop' into 'amd-staging'
Change-Id: I7d3700cc417090f7327441ffd541750df69bcb49
This commit is contained in:
@@ -29,7 +29,37 @@
|
||||
"Unit_hipTextureMipmapObj2D_Check",
|
||||
"Unit_hipStreamPerThread_DeviceReset_1",
|
||||
"Unit_hipStreamPerThread_DeviceReset_2",
|
||||
"Unit_hipManagedKeyword_MultiGpu"
|
||||
"Unit_hipManagedKeyword_MultiGpu",
|
||||
"Unit_hipGraphAddDependencies_Functional",
|
||||
"Unit_hipGraph_BasicFunctional",
|
||||
"Unit_hipGraphClone_Functional",
|
||||
"Unit_hipGraphClone_MultiThreaded",
|
||||
"Unit_hipGraphAddHostNode_ClonedGraphwithHostNode",
|
||||
"Unit_hipGraphAddHostNode_VectorSquare",
|
||||
"Unit_hipGraphAddHostNode_BasicFunc",
|
||||
"Unit_hipGraphAddMemcpyNodeFromSymbol_GlobalMemory",
|
||||
"Unit_hipGraphAddMemcpyNodeFromSymbol_GlobalConstMemory",
|
||||
"Unit_hipGraphAddMemcpyNodeFromSymbol_GlobalMemoryWithKernel",
|
||||
"Unit_hipGraphExecHostNodeSetParams_Negative",
|
||||
"Unit_hipGraphExecHostNodeSetParams_ClonedGraphwithHostNode",
|
||||
"Unit_hipGraphExecHostNodeSetParams_BasicFunc",
|
||||
"Unit_hipGraphAddMemcpyNodeToSymbol_GlobalMemory",
|
||||
"Unit_hipGraphAddMemcpyNodeToSymbol_GlobalConstMemory",
|
||||
"Unit_hipGraphAddMemcpyNodeToSymbol_MemcpyToSymbolNodeWithKernel",
|
||||
"Unit_hipGraphDestroyNode_DestroyDependencyNode",
|
||||
"Unit_hipGraphGetNodes_Functional",
|
||||
"Unit_hipGraphGetRootNodes_Functional",
|
||||
"Unit_hipGraphHostNodeSetParams_ClonedGraphwithHostNode",
|
||||
"Unit_hipGraphAddChildGraphNode_OrgGraphAsChildGraph",
|
||||
"Unit_hipGraphAddChildGraphNode_SingleChildNode",
|
||||
"Unit_hipGraphExecMemcpyNodeSetParams1D_Functional",
|
||||
"Unit_hipGraphRemoveDependencies_ChangeComputeFunc",
|
||||
"Unit_hipGraphExecUpdate_Negative_CountDiffer",
|
||||
"Unit_hipGraphExecUpdate_Functional",
|
||||
"Unit_hipGraphExecEventRecordNodeSetEvent_Negative",
|
||||
"Unit_hipGraphExecMemcpyNodeSetParamsFromSymbol_Negative",
|
||||
"Unit_hipGraphExecMemcpyNodeSetParamsFromSymbol_Functional",
|
||||
"Unit_hipPtrGetAttribute_Simple"
|
||||
]
|
||||
|
||||
}
|
||||
|
||||
@@ -20,12 +20,11 @@
|
||||
|
||||
# build fails in windows
|
||||
if (UNIX)
|
||||
add_subdirectory(memory)
|
||||
add_subdirectory(graph)
|
||||
add_subdirectory(rtc)
|
||||
add_subdirectory(deviceLib)
|
||||
endif()
|
||||
|
||||
add_subdirectory(graph)
|
||||
add_subdirectory(memory)
|
||||
add_subdirectory(stream)
|
||||
add_subdirectory(event)
|
||||
add_subdirectory(occupancy)
|
||||
|
||||
@@ -57,7 +57,6 @@ set(TEST_SRC
|
||||
hipMemCoherencyTst.cc
|
||||
hipMallocManaged.cc
|
||||
hipMemRangeGetAttribute.cc
|
||||
hipHmmOvrSubscriptionTst.cc
|
||||
hipMemcpyFromSymbol.cc
|
||||
hipMemcpyFromSymbolAsync.cc
|
||||
hipMemcpyToSymbol.cc
|
||||
@@ -99,7 +98,6 @@ set(TEST_SRC
|
||||
hipMemAdviseMmap.cc
|
||||
hipMallocManaged.cc
|
||||
hipMemRangeGetAttribute.cc
|
||||
hipHmmOvrSubscriptionTst.cc
|
||||
hipMemcpyFromSymbol.cc
|
||||
hipMemcpyFromSymbolAsync.cc
|
||||
hipMemcpyToSymbol.cc
|
||||
@@ -124,7 +122,8 @@ if(UNIX)
|
||||
hipMemoryAllocateCoherent.cc
|
||||
hipHostMalloc.cc
|
||||
hipMemcpy.cc
|
||||
hipMemcpyAsync.cc)
|
||||
hipMemcpyAsync.cc
|
||||
hipHmmOvrSubscriptionTst.cc)
|
||||
endif()
|
||||
|
||||
hip_add_exe_to_target(NAME MemoryTest
|
||||
|
||||
@@ -242,7 +242,7 @@ static void seekAndSet3DArraySlice(bool bAsync) {
|
||||
|
||||
// select random slice for memset
|
||||
unsigned int seed = time(nullptr);
|
||||
int slice_index = rand_r(&seed) % ZSIZE_S;
|
||||
int slice_index = HipTest::RAND_R(&seed) % ZSIZE_S;
|
||||
|
||||
INFO("memset3d for sliceindex " << slice_index);
|
||||
|
||||
|
||||
@@ -0,0 +1,242 @@
|
||||
/*
|
||||
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "hipPrintfUtil.h"
|
||||
#include "../test_common.h"
|
||||
|
||||
__global__ void test_kernel_int(const char* format, int val) {
|
||||
printf(format, val);
|
||||
}
|
||||
|
||||
|
||||
__global__ void test_kernel_float(const char* format, float val) {
|
||||
printf(format, val);
|
||||
}
|
||||
|
||||
|
||||
__global__ void test_kernel_float_limits(int TestNum) {
|
||||
if (TestNum == 0) {
|
||||
printf("%f", 1.0f/0.0f);
|
||||
}
|
||||
if (TestNum == 1) {
|
||||
printf("%f", sqrt(-1.0f));
|
||||
}
|
||||
if (TestNum == 2) {
|
||||
printf("%f", acos(2.0f));
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void test_kernel_octal(const char* format, const unsigned long int val) {
|
||||
printf(format, val);
|
||||
}
|
||||
|
||||
__global__ void test_kernel_unsigned(const char* format, const unsigned long int val) {
|
||||
printf(format, val);
|
||||
}
|
||||
|
||||
__global__ void test_kernel_char(int TestNum) {
|
||||
if (TestNum == 0) {
|
||||
printf("%4c", '1');
|
||||
}
|
||||
if (TestNum == 1) {
|
||||
printf("%-4c", '1');
|
||||
}
|
||||
if (TestNum == 2) {
|
||||
printf("%c", 66);
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void test_kernel_string(int TestNum) {
|
||||
if (TestNum == 0) {
|
||||
printf("%4s", "foo");
|
||||
}
|
||||
if (TestNum == 1) {
|
||||
printf("%.1s", "foo");
|
||||
}
|
||||
if (TestNum == 2) {
|
||||
printf("%s","%%");
|
||||
}
|
||||
}
|
||||
|
||||
void BuildCorrectOutput(std::vector<std::string>* CorrectBuff, size_t TestId) {
|
||||
for (auto ¶ms:allTestCase[TestId]->_genParameters) {
|
||||
char refResult[256];
|
||||
if (allTestCase[TestId]->printFN == NULL)
|
||||
continue;
|
||||
allTestCase[TestId]->printFN(params, refResult, 256);
|
||||
CorrectBuff->push_back(refResult);
|
||||
}
|
||||
}
|
||||
|
||||
bool TestKernel(const unsigned int TestId, const unsigned int TestNum) {
|
||||
|
||||
CaptureStream capture(stdout);
|
||||
|
||||
capture.Begin();
|
||||
|
||||
switch (allTestCase[TestId]->_type) {
|
||||
case TYPE_INT: {
|
||||
const char* Format;
|
||||
size_t FormatLen = std::strlen(allTestCase[TestId]->_genParameters[TestNum].genericFormat);
|
||||
hipMalloc((void**)&Format, sizeof(char)*FormatLen);
|
||||
hipMemcpyHtoD((void*)Format, (void*)allTestCase[TestId]->_genParameters[TestNum].genericFormat , sizeof(char)*FormatLen);
|
||||
hipLaunchKernelGGL(test_kernel_int, dim3(1), dim3(1), 0, 0, Format,
|
||||
atoi(allTestCase[TestId]->_genParameters[TestNum].dataRepresentation));
|
||||
break;
|
||||
}
|
||||
case TYPE_FLOAT: {
|
||||
const char* Format;
|
||||
size_t FormatLen = std::strlen(allTestCase[TestId]->_genParameters[TestNum].genericFormat);
|
||||
hipMalloc((void**)&Format, sizeof(char)*FormatLen);
|
||||
hipMemcpyHtoD((void*)Format, (void*)allTestCase[TestId]->_genParameters[TestNum].genericFormat , sizeof(char)*FormatLen);
|
||||
float val = strtof(allTestCase[TestId]->_genParameters[TestNum].dataRepresentation, NULL);
|
||||
hipLaunchKernelGGL(test_kernel_float, dim3(1), dim3(1), 0, 0, Format, val);
|
||||
break;
|
||||
}
|
||||
case TYPE_FLOAT_LIMITS: {
|
||||
hipLaunchKernelGGL(test_kernel_float_limits, dim3(1), dim3(1), 0, 0, TestNum);
|
||||
break;
|
||||
}
|
||||
case TYPE_OCTAL: {
|
||||
const char* Format;
|
||||
size_t FormatLen = std::strlen(allTestCase[TestId]->_genParameters[TestNum].genericFormat);
|
||||
hipMalloc((void**)&Format, sizeof(char)*FormatLen);
|
||||
hipMemcpyHtoD((void*)Format, (void*)allTestCase[TestId]->_genParameters[TestNum].genericFormat , sizeof(char)*FormatLen);
|
||||
const unsigned long int data = strtoul(allTestCase[TestId]->_genParameters[TestNum].dataRepresentation, NULL, 10);
|
||||
hipLaunchKernelGGL(test_kernel_octal, dim3(1), dim3(1), 0, 0, Format, data);
|
||||
break;
|
||||
}
|
||||
case TYPE_UNSIGNED: {
|
||||
const char* Format;
|
||||
size_t FormatLen = std::strlen(allTestCase[TestId]->_genParameters[TestNum].genericFormat);
|
||||
hipMalloc((void**)&Format, sizeof(char)*FormatLen);
|
||||
hipMemcpyHtoD((void*)Format, (void*)allTestCase[TestId]->_genParameters[TestNum].genericFormat , sizeof(char)*FormatLen);
|
||||
const unsigned long int data = strtoul(allTestCase[TestId]->_genParameters[TestNum].dataRepresentation, NULL, 10);
|
||||
hipLaunchKernelGGL(test_kernel_unsigned, dim3(1), dim3(1), 0, 0, Format, data);
|
||||
break;
|
||||
}
|
||||
case TYPE_HEXADEC: {
|
||||
const char* Format;
|
||||
size_t FormatLen = std::strlen(allTestCase[TestId]->_genParameters[TestNum].genericFormat);
|
||||
hipMalloc((void**)&Format, sizeof(char)*FormatLen);
|
||||
hipMemcpyHtoD((void*)Format, (void*)allTestCase[TestId]->_genParameters[TestNum].genericFormat , sizeof(char)*FormatLen);
|
||||
const unsigned long int data = strtoul(allTestCase[TestId]->_genParameters[TestNum].dataRepresentation, NULL, 0);
|
||||
hipLaunchKernelGGL(test_kernel_unsigned, dim3(1), dim3(1), 0, 0, Format, data);
|
||||
break;
|
||||
}
|
||||
case TYPE_CHAR: {
|
||||
hipLaunchKernelGGL(test_kernel_char, dim3(1), dim3(1), 0, 0, TestNum);
|
||||
break;
|
||||
}
|
||||
case TYPE_STRING: {
|
||||
hipLaunchKernelGGL(test_kernel_string, dim3(1), dim3(1), 0, 0, TestNum);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
hipDeviceSynchronize();
|
||||
capture.End();
|
||||
std::string device_output = capture.getData();
|
||||
char* exp;
|
||||
//Exponenent representation
|
||||
if ((exp = std::strstr((char*)device_output.c_str(),"E+")) != NULL || (exp = std::strstr((char*)device_output.c_str(),"e+")) != NULL
|
||||
|| (exp = std::strstr((char*)device_output.c_str(),"E-")) != NULL || (exp = std::strstr((char*)device_output.c_str(),"e-")) != NULL) {
|
||||
|
||||
char correctExp[3]={0};
|
||||
std::strncpy(correctExp,exp,2);
|
||||
|
||||
char* eCorrectBuffer = strstr((char*)allTestCase[TestId]->_correctBuffer[TestNum].c_str(),correctExp);
|
||||
if (eCorrectBuffer == NULL) {
|
||||
return false;
|
||||
}
|
||||
eCorrectBuffer+=2;
|
||||
exp += 2;
|
||||
//Exponent always contains at least two digits
|
||||
if (strlen(exp) < 2) {
|
||||
return false;
|
||||
}
|
||||
//Skip leading zeros in the exponent
|
||||
while (*exp == '0') {
|
||||
++exp;
|
||||
}
|
||||
while (*eCorrectBuffer == '0') {
|
||||
++eCorrectBuffer;
|
||||
}
|
||||
if (std::strcmp(eCorrectBuffer,exp)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!std::strcmp(allTestCase[TestId]->_correctBuffer[TestNum].c_str(),"inf")) {
|
||||
if (!std::strcmp(device_output.c_str(),"inf")||!std::strcmp(device_output.c_str(),"infinity")
|
||||
|| !std::strcmp(device_output.c_str(),"1.#INF00")&&std::strcmp(device_output.c_str(),"Inf")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!std::strcmp(allTestCase[TestId]->_correctBuffer[TestNum].c_str(),"nan")
|
||||
|| !std::strcmp(allTestCase[TestId]->_correctBuffer[TestNum].c_str(),"-nan")) {
|
||||
if (!std::strcmp(device_output.c_str(),"nan")||!std::strcmp(device_output.c_str(),"-nan")
|
||||
|| !std::strcmp(device_output.c_str(),"1.#IND00")||!std::strcmp(device_output.c_str(),"-1.#IND00")
|
||||
|| !std::strcmp(device_output.c_str(),"NaN")||!std::strcmp(device_output.c_str(),"nan(ind)")
|
||||
|| !std::strcmp(device_output.c_str(),"nan(snan)")||!std::strcmp(device_output.c_str(),"-nan(ind)")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
std::cout<<device_output<<std::endl;
|
||||
std::cout<<allTestCase[TestId]->_correctBuffer[TestNum]<<std::endl;
|
||||
fflush(stdout);
|
||||
if (std::strcmp(device_output.c_str(), allTestCase[TestId]->_correctBuffer[TestNum].c_str())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#define MAX_TYPES 8
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
const char* arg = argv[1];
|
||||
bool TestpPass;
|
||||
if (!std::strcmp(arg,"--All") || !std::strcmp(arg," ")) {
|
||||
for (int i=0; i < TYPE_COUNT; i++) {
|
||||
BuildCorrectOutput(&allTestCase[i]->_correctBuffer, i);
|
||||
for (int j=0; j < allTestCase[i]->numOfTests; j++) {
|
||||
TestpPass = TestKernel(i,j);
|
||||
HIPASSERT(TestpPass == true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
char* input[] = {"--INT", "--FLOAT", "--FLOAT_LIMITS", "--OCTAL",
|
||||
"--UNSIGNED", "--HEXADEC", "--CHAR", "--STRING"};
|
||||
for (int i=0; i < MAX_TYPES; i++) {
|
||||
if (!std::strcmp(arg, input[i])) {
|
||||
BuildCorrectOutput(&allTestCase[i]->_correctBuffer, i);
|
||||
for (int j=0; j < allTestCase[i]->numOfTests; j++) {
|
||||
TestpPass = TestKernel(i,j);
|
||||
HIPASSERT(TestpPass == true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
passed();
|
||||
}
|
||||
@@ -0,0 +1,513 @@
|
||||
/*
|
||||
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _PRINTFUTIL_H_
|
||||
#define _PRINTFUTIL_H_
|
||||
|
||||
#include "printf_common.h"
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "hip/hip_runtime_api.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string> // std::string
|
||||
#include <iostream> // std::cout
|
||||
#include <sstream> // std::stringstream, std::stringbu
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
static std::vector<std::string> correctBufferInt;
|
||||
static std::vector<std::string> correctBufferFloat;
|
||||
static std::vector<std::string> correctBufferOctal;
|
||||
static std::vector<std::string> correctBufferUnsigned;
|
||||
static std::vector<std::string> correctBufferHexadecimal;
|
||||
|
||||
enum PrintfTestType {
|
||||
TYPE_INT,
|
||||
TYPE_FLOAT,
|
||||
TYPE_FLOAT_LIMITS,
|
||||
TYPE_OCTAL,
|
||||
TYPE_UNSIGNED,
|
||||
TYPE_HEXADEC,
|
||||
TYPE_CHAR,
|
||||
TYPE_STRING,
|
||||
TYPE_VECTOR,
|
||||
TYPE_ADDRESS_SPACE,
|
||||
TYPE_COUNT
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
kuchar = 0,
|
||||
kchar = 1,
|
||||
kushort = 2,
|
||||
kshort = 3,
|
||||
kuint = 4,
|
||||
kint = 5,
|
||||
kfloat = 6,
|
||||
kulong = 7,
|
||||
klong = 8,
|
||||
kdouble = 9,
|
||||
kvector = 10,
|
||||
kTypeCount // always goes last
|
||||
} Type;
|
||||
|
||||
struct printDataGenParameters {
|
||||
const char* genericFormat;
|
||||
const char* dataRepresentation;
|
||||
const char* vectorFormatFlag;
|
||||
const char* vectorFormatSpecifier;
|
||||
const char* dataType;
|
||||
const char* vectorSize;
|
||||
const char* addrSpaceArgumentTypeQualifier;
|
||||
const char* addrSpaceVariableTypeQualifier;
|
||||
const char* addrSpaceParameter;
|
||||
const char* addrSpacePAdd;
|
||||
};
|
||||
|
||||
struct testCase {
|
||||
enum PrintfTestType _type; //(data)type for test
|
||||
std::vector<std::string>& _correctBuffer; //look-up table for correct results for printf
|
||||
std::vector<printDataGenParameters>& _genParameters; //auxiliary data to build the code for kernel source
|
||||
void (*printFN)(printDataGenParameters&,
|
||||
char*,
|
||||
const size_t); //function pointer for generating reference results
|
||||
Type dataType; //the data type that will be printed during reference result generation (used for setting rounding mode)
|
||||
int numOfTests; // num of test performed based on genparam array elements
|
||||
};
|
||||
|
||||
static void intRefBuilder(printDataGenParameters& params, char* refResult, const size_t refSize) {
|
||||
snprintf(refResult, refSize, params.genericFormat, atoi(params.dataRepresentation));
|
||||
}
|
||||
|
||||
static void floatRefBuilder(printDataGenParameters& params, char* refResult, const size_t refSize) {
|
||||
snprintf(refResult, refSize, params.genericFormat, strtof(params.dataRepresentation, NULL));
|
||||
}
|
||||
|
||||
static void octalRefBuilder(printDataGenParameters& params, char* refResult, const size_t refSize) {
|
||||
const unsigned long int data = strtoul(params.dataRepresentation, NULL, 10);
|
||||
snprintf(refResult, refSize, params.genericFormat, data);
|
||||
}
|
||||
|
||||
static void unsignedRefBuilder(printDataGenParameters& params, char* refResult, const size_t refSize) {
|
||||
const unsigned long int data = strtoul(params.dataRepresentation, NULL, 10);
|
||||
snprintf(refResult, refSize, params.genericFormat, data);
|
||||
}
|
||||
|
||||
static void hexRefBuilder(printDataGenParameters& params, char* refResult, const size_t refSize) {
|
||||
const unsigned long int data = strtoul(params.dataRepresentation, NULL, 0);
|
||||
snprintf(refResult, refSize, params.genericFormat, data);
|
||||
}
|
||||
|
||||
//==================================
|
||||
|
||||
// int
|
||||
|
||||
//==================================
|
||||
|
||||
//------------------------------------------------------
|
||||
|
||||
// [string] format | [string] int-data representation |
|
||||
|
||||
//------------------------------------------------------
|
||||
|
||||
std::vector<printDataGenParameters> printIntGenParameters = {
|
||||
//(Minimum)Five-wide,default(right)-justified
|
||||
{"%5d","10"},
|
||||
//(Minimum)Five-wide,left-justified
|
||||
{"%-5d","10"},
|
||||
//(Minimum)Five-wide,default(right)-justified,zero-filled
|
||||
{"%05d","10"},
|
||||
//(Minimum)Five-wide,default(right)-justified,with sign
|
||||
{"%+5d","10"},
|
||||
//(Minimum)Five-wide ,left-justified,with sign
|
||||
{"%-+5d","10"},
|
||||
//(Minimum)Five-digit(zero-filled in absent digits),default(right)-justified
|
||||
{"%.5i","100"},
|
||||
//(Minimum)Six-wide,Five-digit(zero-filled in absent digits),default(right)-justified
|
||||
{"%6.5i","100"},
|
||||
//0 and - flag both apper ==>0 is ignored,left-justified,capital I
|
||||
{"%-06i","100"},
|
||||
//(Minimum)Six-wide,Five-digit(zero-filled in absent digits),default(right)-justified
|
||||
{"%06.5i","100"}
|
||||
};
|
||||
|
||||
testCase testCaseInt = {
|
||||
TYPE_INT,
|
||||
correctBufferInt,
|
||||
printIntGenParameters,
|
||||
intRefBuilder,
|
||||
kint,
|
||||
9
|
||||
};
|
||||
|
||||
|
||||
//==============================================
|
||||
|
||||
// float
|
||||
|
||||
//==============================================
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
// [string] format | [string] float-data representation |
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
std::vector<printDataGenParameters> printFloatGenParameters = {
|
||||
//Default(right)-justified
|
||||
{"%f","10.3456"},
|
||||
//One position after the decimal,default(right)-justified
|
||||
{"%.1f","10.3456"},
|
||||
//Two positions after the decimal,default(right)-justified
|
||||
{"%.2f","10.3456"},
|
||||
//(Minimum)Eight-wide,three positions after the decimal,default(right)-justified
|
||||
{"%8.3f","10.3456"},
|
||||
//(Minimum)Eight-wide,two positions after the decimal,zero-filled,default(right)-justified
|
||||
{"%08.2f","10.3456"},
|
||||
//(Minimum)Eight-wide,two positions after the decimal,left-justified
|
||||
{"%-8.2f","10.3456"},
|
||||
//(Minimum)Eight-wide,two positions after the decimal,with sign,default(right)-justified
|
||||
{"%+8.2f","-10.3456"},
|
||||
//Zero positions after the decimal([floor]rounding),default(right)-justified
|
||||
{"%.0f","0.1"},
|
||||
//Zero positions after the decimal([ceil]rounding),default(right)-justified
|
||||
{"%.0f","0.6"},
|
||||
//Zero-filled,default positions number after the decimal,default(right)-justified
|
||||
{"%0f","0.6"},
|
||||
//Double argument representing floating-point,used by f style,default(right)-justified
|
||||
{"%4g","12345.6789"},
|
||||
//Double argument representing floating-point,used by e style,default(right)-justified
|
||||
{"%4.2g","12345.6789"},
|
||||
//Double argument representing floating-point,used by f style,default(right)-justified
|
||||
{"%4G","0.0000023"},
|
||||
//Double argument representing floating-point,used by e style,default(right)-justified
|
||||
{"%4G","0.023"},
|
||||
//Double argument representing floating-point,with exponent,left-justified,default(right)-justified
|
||||
{"%-#20.15e","789456123.0"},
|
||||
//Double argument representing floating-point,with exponent,left-justified,with sign,capital E,default(right)-justified ????
|
||||
{"%+#21.15E","789456123.0"},
|
||||
//Double argument representing floating-point,in [-]xh.hhhhpAd style
|
||||
{"%.6a","0.1"},
|
||||
//(Minimum)Ten-wide,Double argument representing floating-point,in xh.hhhhpAd style,default(right)-justified
|
||||
{"%10.2a","9990.235"},
|
||||
};
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
||||
//Test case for float |
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
||||
testCase testCaseFloat = {
|
||||
TYPE_FLOAT,
|
||||
correctBufferFloat,
|
||||
printFloatGenParameters,
|
||||
floatRefBuilder,
|
||||
kfloat,
|
||||
18
|
||||
};
|
||||
|
||||
|
||||
//==============================================
|
||||
|
||||
// float limits
|
||||
|
||||
//==============================================
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
// [string] format | [string] float-data representation |
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
|
||||
std::vector<printDataGenParameters> printFloatLimitsGenParameters = {
|
||||
//Infinity (1.0/0.0)
|
||||
{"%f","1.0f/0.0f"},
|
||||
//NaN
|
||||
{"%f","sqrt(-1.0f)"},
|
||||
//NaN
|
||||
{"%f","acos(2.0f)"}
|
||||
};
|
||||
//--------------------------------------------------------
|
||||
|
||||
// Lookup table - [string]float-correct buffer |
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
std::vector<std::string> correctBufferFloatLimits = {
|
||||
"inf",
|
||||
"-nan",
|
||||
"nan"
|
||||
};
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
||||
//Test case for float |
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
||||
testCase testCaseFloatLimits = {
|
||||
TYPE_FLOAT_LIMITS,
|
||||
correctBufferFloatLimits,
|
||||
printFloatLimitsGenParameters,
|
||||
NULL,
|
||||
kfloat,
|
||||
3
|
||||
};
|
||||
|
||||
//=========================================================
|
||||
|
||||
// octal
|
||||
|
||||
//=========================================================
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
||||
// [string] format | [string] octal-data representation |
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
||||
std::vector<printDataGenParameters> printOctalGenParameters = {
|
||||
//Default(right)-justified
|
||||
{"%o","10"},
|
||||
//Five-digit,default(right)-justified
|
||||
{"%.5o","10"},
|
||||
//Default(right)-justified,increase precision
|
||||
{"%#o","100000000"},
|
||||
//(Minimum)Four-wide,Five-digit,0-flag ignored(because of precision),default(right)-justified
|
||||
{"%04.5o","10"}
|
||||
};
|
||||
|
||||
//-------------------------------------------------------
|
||||
|
||||
//Test case for octal |
|
||||
|
||||
//-------------------------------------------------------
|
||||
|
||||
testCase testCaseOctal = {
|
||||
TYPE_OCTAL,
|
||||
correctBufferOctal,
|
||||
printOctalGenParameters,
|
||||
octalRefBuilder,
|
||||
kulong,
|
||||
4
|
||||
};
|
||||
|
||||
|
||||
|
||||
//=========================================================
|
||||
|
||||
// unsigned
|
||||
|
||||
//=========================================================
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
||||
// [string] format | [string] unsined-data representation |
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
||||
std::vector<printDataGenParameters> printUnsignedGenParameters = {
|
||||
//Default(right)-justified
|
||||
{"%u","10"},
|
||||
};
|
||||
|
||||
//-------------------------------------------------------
|
||||
|
||||
//Test case for octal |
|
||||
|
||||
//-------------------------------------------------------
|
||||
|
||||
testCase testCaseUnsigned = {
|
||||
TYPE_UNSIGNED,
|
||||
correctBufferUnsigned,
|
||||
printUnsignedGenParameters,
|
||||
unsignedRefBuilder,
|
||||
kulong,
|
||||
1
|
||||
};
|
||||
|
||||
|
||||
|
||||
//=======================================================
|
||||
|
||||
// hexadecimal
|
||||
|
||||
//=======================================================
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
|
||||
// [string] format | [string] hexadecimal-data representation |
|
||||
|
||||
//--------------------------------------------------------------
|
||||
|
||||
std::vector<printDataGenParameters> printHexadecimalGenParameters = {
|
||||
//Add 0x,low x,default(right)-justified
|
||||
{"%#x","0xABCDEF"},
|
||||
//Add 0x,capital X,default(right)-justified
|
||||
{"%#X","0xABCDEF"},
|
||||
//Not add 0x,if zero,default(right)-justified
|
||||
{"%#X","0"},
|
||||
//(Minimum)Eight-wide,default(right)-justified
|
||||
{"%8x","399"},
|
||||
//(Minimum)Four-wide,zero-filled,default(right)-justified
|
||||
{"%04x","399"}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------
|
||||
|
||||
//Test case for hexadecimal |
|
||||
|
||||
//--------------------------------------------------------------
|
||||
|
||||
testCase testCaseHexadecimal = {
|
||||
TYPE_HEXADEC,
|
||||
correctBufferHexadecimal,
|
||||
printHexadecimalGenParameters,
|
||||
hexRefBuilder,
|
||||
kulong,
|
||||
5
|
||||
};
|
||||
|
||||
|
||||
|
||||
//=============================================================
|
||||
|
||||
// char
|
||||
|
||||
//=============================================================
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------
|
||||
|
||||
// [string] format | [string] string-data representation |
|
||||
|
||||
//-----------------------------------------------------------
|
||||
|
||||
std::vector<printDataGenParameters> printCharGenParameters = {
|
||||
//Four-wide,zero-filled,default(right)-justified
|
||||
{"%4c","'1'"},
|
||||
//Four-wide,left-justified
|
||||
{"%-4c","\'1\'"},
|
||||
//(unsigned) int argument,default(right)-justified
|
||||
{"%c","66"}
|
||||
};
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
||||
// Lookup table -[string] char-correct buffer |
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
||||
std::vector<std::string> correctBufferChar = {
|
||||
" 1",
|
||||
"1 ",
|
||||
"B",
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------
|
||||
|
||||
//Test case for char |
|
||||
|
||||
//----------------------------------------------------------
|
||||
|
||||
testCase testCaseChar = {
|
||||
TYPE_CHAR,
|
||||
correctBufferChar,
|
||||
printCharGenParameters,
|
||||
NULL,
|
||||
kchar,
|
||||
3
|
||||
};
|
||||
|
||||
//==========================================================
|
||||
|
||||
// string
|
||||
|
||||
//==========================================================
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
// [string]format | [string] string-data representation |
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
std::vector<printDataGenParameters> printStringGenParameters = {
|
||||
//(Minimum)Four-wide,zero-filled,default(right)-justified
|
||||
{"%4s","\"foo\""},
|
||||
//One-digit(precision ignored),left-justified
|
||||
{"%.1s","\"foo\""},
|
||||
//%% specification
|
||||
{"%s","\"%%\""},
|
||||
};
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
||||
// Lookup table -[string] string-correct buffer |
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
||||
std::vector<std::string> correctBufferString = {
|
||||
" foo",
|
||||
"f",
|
||||
"%%",
|
||||
};
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
||||
//Test case for string |
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
||||
testCase testCaseString = {
|
||||
TYPE_STRING,
|
||||
correctBufferString,
|
||||
printStringGenParameters,
|
||||
NULL,
|
||||
kchar,
|
||||
3
|
||||
};
|
||||
|
||||
std::vector<testCase*> allTestCase = {&testCaseInt, &testCaseFloat, &testCaseFloatLimits, &testCaseOctal, &testCaseUnsigned,
|
||||
&testCaseHexadecimal, &testCaseChar, &testCaseString};
|
||||
#endif
|
||||
Reference in New Issue
Block a user