aboutsummaryrefslogtreecommitdiff
path: root/test_conformance/printf/test_printf.h
blob: 038a7b9c04560be244de42f2e52d6d219a81398c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//
// Copyright (c) 2017 The Khronos Group Inc.
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef TESTPRINTF_INCLUDED_H
#define TESTPRINTF_INCLUDED_H

#include "harness/compat.h"
#include "harness/testHarness.h"
#include "harness/rounding_mode.h"

#include <stdio.h>
#include <string.h>
#include <vector>

#ifdef __APPLE__
#include <OpenCL/opencl.h>
#include <OpenCL/cl_platform.h>
#else
#include <CL/opencl.h>
#include <CL/cl_platform.h>
#endif

#define ANALYSIS_BUFFER_SIZE 256

//-----------------------------------------
// Definitions and initializations
//-----------------------------------------

//-----------------------------------------
// Types
//-----------------------------------------
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
};

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;
};

// Reference results - filled out at run-time
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;
// Reference results - Compile-time known
extern std::vector<std::string> correctBufferChar;
extern std::vector<std::string> correctBufferString;
extern std::vector<std::string> correctBufferFloatLimits;
extern std::vector<std::string> correctBufferVector;
extern std::vector<std::string> correctAddrSpace;

// Helper for generating reference results
void generateRef(const cl_device_id device);

//-----------------------------------------
//Test Case
//-----------------------------------------

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)
};

extern const char* strType[];
extern std::vector<testCase*> allTestCase;

size_t verifyOutputBuffer(char *analysisBuffer,testCase* pTestCase,size_t testId,cl_ulong pAddr = 0);

// Helpful macros

// The next three functions check on different return values.  Returns -1
// if the check failed
#define checkErr(err, msg)                \
    if (err != CL_SUCCESS) {                \
    log_error("%s failed errcode:%d\n", msg, err);    \
    return -1;                    \
    }

#define checkZero(val, msg)                \
    if (val == 0) {                    \
    log_error("%s failed errcode:%d\n", msg, err);    \
    return -1;                    \
    }

#define checkNull(ptr, msg)            \
    if (!ptr) {                    \
    log_error("%s failed\n", msg);        \
    return TEST_FAIL;                \
    }

// When a helper returns a negative one, we want to return from main
// with negative one. This helper prevents me from having to write
// this multiple time
#define checkHelperErr(err)            \
    if (err == -1) {                \
    return err;                \
    }

#endif // TESTSPRINTF_INCLUDED_H