mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-24 07:59:01 +00:00
Use unique tmp file to allow parallel printf tests (#213)
Parallel printf tests fail because they use the same file tmp to capture OpenCL kernel outputs. This patch solves this problem by using a unique file for each process.
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
|
#include "../../test_common/harness/compat.h"
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -34,6 +35,7 @@
|
|||||||
#define streamDup2(fd1,fd2) dup2(fd1,fd2)
|
#define streamDup2(fd1,fd2) dup2(fd1,fd2)
|
||||||
#endif
|
#endif
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <time.h>
|
||||||
#include "test_printf.h"
|
#include "test_printf.h"
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
@@ -55,10 +57,10 @@ typedef unsigned int uint32_t;
|
|||||||
|
|
||||||
//Stream helper functions
|
//Stream helper functions
|
||||||
|
|
||||||
//Associate stdout stream with the file(tmp):i.e redirect stdout stream to the specific files (tmp)
|
//Associate stdout stream with the file(gFileName):i.e redirect stdout stream to the specific files (gFileName)
|
||||||
static int acquireOutputStream();
|
static int acquireOutputStream();
|
||||||
|
|
||||||
//Close the file(tmp) associated with the stdout stream and disassociates it.
|
//Close the file(gFileName) associated with the stdout stream and disassociates it.
|
||||||
static void releaseOutputStream(int fd);
|
static void releaseOutputStream(int fd);
|
||||||
|
|
||||||
//Get analysis buffer to verify the correctess of printed data
|
//Get analysis buffer to verify the correctess of printed data
|
||||||
@@ -101,18 +103,42 @@ int waitForEvent(cl_event* event);
|
|||||||
int s_test_cnt = 0;
|
int s_test_cnt = 0;
|
||||||
int s_test_fail = 0;
|
int s_test_fail = 0;
|
||||||
|
|
||||||
|
static char gFileName[256];
|
||||||
|
|
||||||
//-----------------------------------------
|
//-----------------------------------------
|
||||||
// Static helper functions definition
|
// Static helper functions definition
|
||||||
//-----------------------------------------
|
//-----------------------------------------
|
||||||
|
|
||||||
|
//-----------------------------------------
|
||||||
|
// getTempFileName
|
||||||
|
//-----------------------------------------
|
||||||
|
static int getTempFileName()
|
||||||
|
{
|
||||||
|
// Create a unique temporary file to allow parallel executed tests.
|
||||||
|
#if (defined(__linux__) || defined(__APPLE__)) && (!defined( __ANDROID__ ))
|
||||||
|
sprintf(gFileName, "/tmp/tmpfile.XXXXXX");
|
||||||
|
int fd = mkstemp(gFileName);
|
||||||
|
if (fd == -1)
|
||||||
|
return -1;
|
||||||
|
close(fd);
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
UINT ret = GetTempFileName(".", "tmp", 0, gFileName);
|
||||||
|
if (ret == 0)
|
||||||
|
return -1;
|
||||||
|
#else
|
||||||
|
MTdata d = init_genrand((cl_uint)time(NULL));
|
||||||
|
sprintf(gFileName, "tmpfile.%u", genrand_int32(d));
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------
|
//-----------------------------------------
|
||||||
// acquireOutputStream
|
// acquireOutputStream
|
||||||
//-----------------------------------------
|
//-----------------------------------------
|
||||||
static int acquireOutputStream()
|
static int acquireOutputStream()
|
||||||
{
|
{
|
||||||
int fd = streamDup(fileno(stdout));
|
int fd = streamDup(fileno(stdout));
|
||||||
freopen("tmp","w",stdout);
|
freopen(gFileName,"w",stdout);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,7 +160,7 @@ static void getAnalysisBuffer(char* analysisBuffer)
|
|||||||
FILE *fp;
|
FILE *fp;
|
||||||
memset(analysisBuffer,0,ANALYSIS_BUFFER_SIZE);
|
memset(analysisBuffer,0,ANALYSIS_BUFFER_SIZE);
|
||||||
|
|
||||||
fp = fopen("tmp","r");
|
fp = fopen(gFileName,"r");
|
||||||
if(NULL == fp)
|
if(NULL == fp)
|
||||||
log_error("Failed to open analysis buffer\n");
|
log_error("Failed to open analysis buffer\n");
|
||||||
else
|
else
|
||||||
@@ -256,7 +282,7 @@ static cl_program makePrintfProgram(cl_kernel *kernel_ptr, const cl_context cont
|
|||||||
sprintf(testname,"%s%d","test",testId);
|
sprintf(testname,"%s%d","test",testId);
|
||||||
|
|
||||||
//Update addrSpaceArgument type,based on FULL_PROFILE/EMBEDDED_PROFILE
|
//Update addrSpaceArgument type,based on FULL_PROFILE/EMBEDDED_PROFILE
|
||||||
if(allTestCase[testId]->_type == ADDRESS_SPACE)
|
if(allTestCase[testId]->_type == TYPE_ADDRESS_SPACE)
|
||||||
{
|
{
|
||||||
sprintf(addrSpaceArgument,allTestCase[testId]->_genParameters[testNum].addrSpaceArgumentTypeQualifier);
|
sprintf(addrSpaceArgument,allTestCase[testId]->_genParameters[testNum].addrSpaceArgumentTypeQualifier);
|
||||||
if(isKernelPFormat(allTestCase[testId],testNum) && (!isLongSupport || !is64bAddrSpace))
|
if(isKernelPFormat(allTestCase[testId],testNum) && (!isLongSupport || !is64bAddrSpace))
|
||||||
@@ -272,11 +298,11 @@ static cl_program makePrintfProgram(cl_kernel *kernel_ptr, const cl_context cont
|
|||||||
|
|
||||||
// create program based on its type
|
// create program based on its type
|
||||||
|
|
||||||
if(allTestCase[testId]->_type == VECTOR)
|
if(allTestCase[testId]->_type == TYPE_VECTOR)
|
||||||
{
|
{
|
||||||
program = clCreateProgramWithSource( context,sizeof(sourceVec)/sizeof(sourceVec[0]),sourceVec, NULL, NULL);
|
program = clCreateProgramWithSource( context,sizeof(sourceVec)/sizeof(sourceVec[0]),sourceVec, NULL, NULL);
|
||||||
}
|
}
|
||||||
else if(allTestCase[testId]->_type == ADDRESS_SPACE)
|
else if(allTestCase[testId]->_type == TYPE_ADDRESS_SPACE)
|
||||||
{
|
{
|
||||||
program = clCreateProgramWithSource( context,sizeof(sourceAddrSpace)/sizeof(sourceAddrSpace[0]),sourceAddrSpace, NULL, NULL);
|
program = clCreateProgramWithSource( context,sizeof(sourceAddrSpace)/sizeof(sourceAddrSpace[0]),sourceAddrSpace, NULL, NULL);
|
||||||
}
|
}
|
||||||
@@ -309,12 +335,12 @@ static cl_program makePrintfProgram(cl_kernel *kernel_ptr, const cl_context cont
|
|||||||
size_t sourceLen;
|
size_t sourceLen;
|
||||||
const char** source;
|
const char** source;
|
||||||
|
|
||||||
if(allTestCase[testId]->_type == VECTOR)
|
if(allTestCase[testId]->_type == TYPE_VECTOR)
|
||||||
{
|
{
|
||||||
sourceLen = sizeof(sourceVec) / sizeof( sourceVec[0] );
|
sourceLen = sizeof(sourceVec) / sizeof( sourceVec[0] );
|
||||||
source = sourceVec;
|
source = sourceVec;
|
||||||
}
|
}
|
||||||
else if(allTestCase[testId]->_type == ADDRESS_SPACE)
|
else if(allTestCase[testId]->_type == TYPE_ADDRESS_SPACE)
|
||||||
{
|
{
|
||||||
sourceLen = sizeof(sourceAddrSpace) / sizeof( sourceAddrSpace[0] );
|
sourceLen = sizeof(sourceAddrSpace) / sizeof( sourceAddrSpace[0] );
|
||||||
source = sourceAddrSpace;
|
source = sourceAddrSpace;
|
||||||
@@ -467,7 +493,7 @@ static int doTest(cl_command_queue queue, cl_context context, const unsigned int
|
|||||||
}
|
}
|
||||||
|
|
||||||
//For address space test if there is kernel argument - set it
|
//For address space test if there is kernel argument - set it
|
||||||
if(allTestCase[testId]->_type == ADDRESS_SPACE )
|
if(allTestCase[testId]->_type == TYPE_ADDRESS_SPACE )
|
||||||
{
|
{
|
||||||
if(isKernelArgument(allTestCase[testId],testNum))
|
if(isKernelArgument(allTestCase[testId],testNum))
|
||||||
{
|
{
|
||||||
@@ -532,7 +558,7 @@ static int doTest(cl_command_queue queue, cl_context context, const unsigned int
|
|||||||
|
|
||||||
cl_uint out32;
|
cl_uint out32;
|
||||||
cl_ulong out64;
|
cl_ulong out64;
|
||||||
if(allTestCase[testId]->_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
|
||||||
@@ -713,6 +739,11 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (getTempFileName() == -1)
|
||||||
|
{
|
||||||
|
log_error("getTempFileName failed\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int err;
|
int err;
|
||||||
int fd = acquireOutputStream();
|
int fd = acquireOutputStream();
|
||||||
@@ -777,10 +808,10 @@ int main(int argc, char* argv[]) {
|
|||||||
//For all formats
|
//For all formats
|
||||||
for(unsigned int testNum = 0;testNum < allTestCase[testId]->_testNum;++testNum){
|
for(unsigned int testNum = 0;testNum < allTestCase[testId]->_testNum;++testNum){
|
||||||
releaseOutputStream(fd);
|
releaseOutputStream(fd);
|
||||||
if(allTestCase[testId]->_type == VECTOR)
|
if(allTestCase[testId]->_type == TYPE_VECTOR)
|
||||||
log_info("%d)testing printf(\"%sv%s%s\",%s)\n",testNum,allTestCase[testId]->_genParameters[testNum].vectorFormatFlag,allTestCase[testId]->_genParameters[testNum].vectorSize,
|
log_info("%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);
|
allTestCase[testId]->_genParameters[testNum].vectorFormatSpecifier,allTestCase[testId]->_genParameters[testNum].dataRepresentation);
|
||||||
else if(allTestCase[testId]->_type == ADDRESS_SPACE)
|
else if(allTestCase[testId]->_type == TYPE_ADDRESS_SPACE)
|
||||||
{
|
{
|
||||||
if(isKernelArgument)
|
if(isKernelArgument)
|
||||||
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",testNum,allTestCase[testId]->_genParameters[testNum].addrSpaceArgumentTypeQualifier,
|
||||||
@@ -794,12 +825,12 @@ int main(int argc, char* argv[]) {
|
|||||||
fd = acquireOutputStream();
|
fd = acquireOutputStream();
|
||||||
|
|
||||||
// Long support for varible type
|
// Long support for varible type
|
||||||
if(allTestCase[testId]->_type == VECTOR && !strcmp(allTestCase[testId]->_genParameters[testNum].dataType,"long") && !isLongSupported(device_id))
|
if(allTestCase[testId]->_type == TYPE_VECTOR && !strcmp(allTestCase[testId]->_genParameters[testNum].dataType,"long") && !isLongSupported(device_id))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// 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 == ADDRESS_SPACE && isKernelPFormat(allTestCase[testId],testNum) && !isLongSupported(device_id))
|
if(allTestCase[testId]->_type == TYPE_ADDRESS_SPACE && isKernelPFormat(allTestCase[testId],testNum) && !isLongSupported(device_id))
|
||||||
isLongSupport = false;
|
isLongSupport = false;
|
||||||
|
|
||||||
// Perform the test
|
// Perform the test
|
||||||
@@ -847,6 +878,7 @@ int main(int argc, char* argv[]) {
|
|||||||
log_error(" FAILED test.\n");
|
log_error(" FAILED test.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remove(gFileName);
|
||||||
test_finish();
|
test_finish();
|
||||||
return s_test_fail;
|
return s_test_fail;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,15 +60,15 @@
|
|||||||
//-----------------------------------------
|
//-----------------------------------------
|
||||||
enum Type
|
enum Type
|
||||||
{
|
{
|
||||||
INT,
|
TYPE_INT,
|
||||||
FLOAT,
|
TYPE_FLOAT,
|
||||||
OCTAL,
|
TYPE_OCTAL,
|
||||||
UNSIGNED,
|
TYPE_UNSIGNED,
|
||||||
HEXADEC,
|
TYPE_HEXADEC,
|
||||||
CHAR,
|
TYPE_CHAR,
|
||||||
STRING,
|
TYPE_STRING,
|
||||||
VECTOR,
|
TYPE_VECTOR,
|
||||||
ADDRESS_SPACE,
|
TYPE_ADDRESS_SPACE,
|
||||||
TYPE_COUNT
|
TYPE_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ testCase testCaseInt = {
|
|||||||
|
|
||||||
sizeof(correctBufferInt)/sizeof(char*),
|
sizeof(correctBufferInt)/sizeof(char*),
|
||||||
|
|
||||||
INT,
|
TYPE_INT,
|
||||||
|
|
||||||
correctBufferInt,
|
correctBufferInt,
|
||||||
|
|
||||||
@@ -297,7 +297,7 @@ testCase testCaseFloat = {
|
|||||||
|
|
||||||
sizeof(correctBufferFloat)/sizeof(char*),
|
sizeof(correctBufferFloat)/sizeof(char*),
|
||||||
|
|
||||||
FLOAT,
|
TYPE_FLOAT,
|
||||||
|
|
||||||
correctBufferFloat,
|
correctBufferFloat,
|
||||||
|
|
||||||
@@ -371,7 +371,7 @@ testCase testCaseOctal = {
|
|||||||
|
|
||||||
sizeof(correctBufferOctal)/sizeof(char*),
|
sizeof(correctBufferOctal)/sizeof(char*),
|
||||||
|
|
||||||
OCTAL,
|
TYPE_OCTAL,
|
||||||
|
|
||||||
correctBufferOctal,
|
correctBufferOctal,
|
||||||
|
|
||||||
@@ -433,7 +433,7 @@ testCase testCaseUnsigned = {
|
|||||||
|
|
||||||
sizeof(correctBufferUnsigned)/sizeof(char*),
|
sizeof(correctBufferUnsigned)/sizeof(char*),
|
||||||
|
|
||||||
UNSIGNED,
|
TYPE_UNSIGNED,
|
||||||
|
|
||||||
correctBufferUnsigned,
|
correctBufferUnsigned,
|
||||||
|
|
||||||
@@ -513,7 +513,7 @@ testCase testCaseHexadecimal = {
|
|||||||
|
|
||||||
sizeof(correctBufferHexadecimal)/sizeof(char*),
|
sizeof(correctBufferHexadecimal)/sizeof(char*),
|
||||||
|
|
||||||
HEXADEC,
|
TYPE_HEXADEC,
|
||||||
|
|
||||||
correctBufferHexadecimal,
|
correctBufferHexadecimal,
|
||||||
|
|
||||||
@@ -581,7 +581,7 @@ testCase testCaseChar = {
|
|||||||
|
|
||||||
sizeof(correctBufferChar)/sizeof(char*),
|
sizeof(correctBufferChar)/sizeof(char*),
|
||||||
|
|
||||||
CHAR,
|
TYPE_CHAR,
|
||||||
|
|
||||||
correctBufferChar,
|
correctBufferChar,
|
||||||
|
|
||||||
@@ -645,7 +645,7 @@ testCase testCaseString = {
|
|||||||
|
|
||||||
sizeof(correctBufferString)/sizeof(char*),
|
sizeof(correctBufferString)/sizeof(char*),
|
||||||
|
|
||||||
STRING,
|
TYPE_STRING,
|
||||||
|
|
||||||
correctBufferString,
|
correctBufferString,
|
||||||
|
|
||||||
@@ -723,7 +723,7 @@ testCase testCaseVector = {
|
|||||||
|
|
||||||
sizeof(correctBufferVector)/(sizeof(char *)),
|
sizeof(correctBufferVector)/(sizeof(char *)),
|
||||||
|
|
||||||
VECTOR,
|
TYPE_VECTOR,
|
||||||
|
|
||||||
correctBufferVector,
|
correctBufferVector,
|
||||||
|
|
||||||
@@ -795,7 +795,7 @@ testCase testCaseAddrSpace = {
|
|||||||
|
|
||||||
sizeof(correctAddrSpace)/(sizeof(char *)),
|
sizeof(correctAddrSpace)/(sizeof(char *)),
|
||||||
|
|
||||||
ADDRESS_SPACE,
|
TYPE_ADDRESS_SPACE,
|
||||||
|
|
||||||
correctAddrSpace,
|
correctAddrSpace,
|
||||||
|
|
||||||
@@ -825,7 +825,7 @@ size_t verifyOutputBuffer(char *analysisBuffer,testCase* pTestCase,size_t testId
|
|||||||
|
|
||||||
analysisBuffer[strlen(analysisBuffer)-1] = '\0';
|
analysisBuffer[strlen(analysisBuffer)-1] = '\0';
|
||||||
//Convert analysis buffer to long for address space
|
//Convert analysis buffer to long for address space
|
||||||
if(pTestCase->_type == ADDRESS_SPACE && strcmp(pTestCase->_genParameters[testId].addrSpacePAdd,""))
|
if(pTestCase->_type == TYPE_ADDRESS_SPACE && strcmp(pTestCase->_genParameters[testId].addrSpacePAdd,""))
|
||||||
|
|
||||||
{
|
{
|
||||||
char analysisBufferTmp[ANALYSIS_BUFFER_SIZE];
|
char analysisBufferTmp[ANALYSIS_BUFFER_SIZE];
|
||||||
|
|||||||
Reference in New Issue
Block a user