---
 tests/cl/doc_program.cl           |  1 +
 tests/cl/doc_program.program_test |  1 +
 tests/cl/program/program-tester.c | 33 +++++++++++++++++++++++++++------
 tests/util/piglit-util-cl.c       | 26 +++++++++++++-------------
 tests/util/piglit-util-cl.h       |  8 ++++----
 5 files changed, 46 insertions(+), 23 deletions(-)

diff --git a/tests/cl/doc_program.cl b/tests/cl/doc_program.cl
index 84e92ee..3dee7e1 100644
--- a/tests/cl/doc_program.cl
+++ b/tests/cl/doc_program.cl
@@ -65,6 +65,7 @@ arg_in: 1 buffer float2[6] random      # Buffer argument with 
random data to ini
 arg_in: 2 float2 1 1                   # Int argument
 arg_out: 1 buffer float2[6] repeat 4.1 3.1 \ # Buffer argument with repeated 
expected data (4.1 3.1 4.1 3.1 4.1 3.1)
                             tolerance 0.1    # Tolerate result data with +-0.1 
offset
+                                             # Can also be expressed in terms 
of ulp: tolerance 5 ulp
 
 #???? Configuration end
 !*/
diff --git a/tests/cl/doc_program.program_test 
b/tests/cl/doc_program.program_test
index 3ff67a6..b6d50d1 100644
--- a/tests/cl/doc_program.program_test
+++ b/tests/cl/doc_program.program_test
@@ -65,6 +65,7 @@ arg_in: 1 buffer float2[6] random      # Buffer argument with 
random data to ini
 arg_in: 2 float2 1 1                   # Int argument
 arg_out: 1 buffer float2[6] repeat 4.1 3.1 \ # Buffer argument with repeated 
expected data (4.1 3.1 4.1 3.1 4.1 3.1)
                             tolerance 0.1    # Tolerate result data with +-0.1 
offset
+                                             # Can also be expressed in terms 
of ulp: tolerance 5 ulp
 
 
 # Program section #
diff --git a/tests/cl/program/program-tester.c 
b/tests/cl/program/program-tester.c
index a51f148..51a692b 100644
--- a/tests/cl/program/program-tester.c
+++ b/tests/cl/program/program-tester.c
@@ -127,10 +127,11 @@
 #define REGEX_DEFINE_ARG(type, value)  "([[:digit:]]+)[[:space:]]+" type \
                                        "[[:space:]]+(" value ")"
 #define REGEX_ARG_TOLERANCE            "tolerance[[:space:]]+(" REGEX_VALUE ")"
+#define REGEX_ARG_TOLERANCE_ULP        REGEX_ARG_TOLERANCE "[[:space:]]+ulp"
 #define REGEX_ARG_VALUE   REGEX_DEFINE_ARG( "(" REGEX_TYPE ")", REGEX_ARRAY )
 #define REGEX_ARG_BUFFER  REGEX_DEFINE_ARG( "buffer[[:space:]]+(" REGEX_TYPE 
")\\[([[:digit:]]+)\\]", \
                                             REGEX_ARRAY "|" REGEX_RANDOM "|" 
REGEX_REPEAT )           \
-                          "([[:space:]]+" REGEX_ARG_TOLERANCE ")?"
+                          "([[:space:]]+" "("REGEX_ARG_TOLERANCE "|" 
REGEX_ARG_TOLERANCE_ULP")" ")?"
 #define REGEX_ARG         "(" REGEX_ARG_VALUE "|" REGEX_ARG_BUFFER ")"
 
 /* Match whole line */
@@ -228,7 +229,7 @@ struct test_arg {
        /* tolerance */
        int64_t toli;
        uint64_t tolu;
-       double tolf;
+       uint64_t ulp;
 };
 
 struct test_arg create_test_arg()
@@ -247,7 +248,7 @@ struct test_arg create_test_arg()
 
                .toli = 0,
                .tolu = 0,
-               .tolf = 0,
+               .ulp = 0,
        };
 
        return ta;
@@ -902,6 +903,24 @@ get_test_arg_tolerance(struct test_arg* test_arg, const 
char* tolerance_str)
        regmatch_t pmatch[2];
        char* value_str = NULL;
 
+        fprintf(stderr, "tolerance = %s\n", tolerance_str);
+        if(regex_get_matches(tolerance_str,
+                            REGEX_ARG_TOLERANCE_ULP,
+                            pmatch,
+                            2,
+                            REG_NEWLINE)) {
+               regex_get_match_str(&value_str, tolerance_str, pmatch, 1);
+               switch(test_arg->cl_type) {
+               case TYPE_FLOAT:
+               case TYPE_DOUBLE:
+                       test_arg->ulp = get_uint(value_str);
+                       return;
+               default:
+                       fprintf(stderr, "ulp not value for integer types\n");
+                       exit_report_result(PIGLIT_WARN);
+                }
+       }
+
        if(regex_get_matches(tolerance_str,
                             REGEX_ARG_TOLERANCE,
                             pmatch,
@@ -923,9 +942,11 @@ get_test_arg_tolerance(struct test_arg* test_arg, const 
char* tolerance_str)
                        test_arg->tolu = get_uint(value_str);
                        break;
                case TYPE_FLOAT:
-               case TYPE_DOUBLE:
-                       test_arg->tolf = get_float(value_str);
+               case TYPE_DOUBLE: {
+                       float value = get_float(value_str);
+                       test_arg->ulp = *((uint64_t*)(&value));
                        break;
+                       }
                }
 
                free(value_str);
@@ -1662,7 +1683,7 @@ check_test_arg_value(struct test_arg test_arg,
                                rb = i*test_arg.cl_mem_size + c;                
             \
                                
if(!piglit_cl_probe_floating(((cl_type*)value)[rb],          \
                                                             
((cl_type*)test_arg.value)[rb], \
-                                                            test_arg.tolf)) {  
             \
+                                                            test_arg.ulp)) {   
            \
                                        ra = i*test_arg.cl_size + c;            
                 \
                                        printf("Error at %s[%zu]\n", type, ra); 
                 \
                                        return false;                           
                 \
diff --git a/tests/util/piglit-util-cl.c b/tests/util/piglit-util-cl.c
index 5b4267f..5ac20a8 100644
--- a/tests/util/piglit-util-cl.c
+++ b/tests/util/piglit-util-cl.c
@@ -62,27 +62,27 @@ piglit_cl_probe_uinteger(uint64_t value, uint64_t expect, 
uint64_t tolerance)
 
 /* TODO: Tolerance should be specified in terms of ULP. */
 bool
-piglit_cl_probe_floating(float value, float expect,  float tolerance)
+piglit_cl_probe_floating(float value, float expect,  uint32_t ulp)
 {
        float diff;
        union {
                float f;
-               unsigned u;
+               uint32_t u;
        } v, e, t;
 
        v.f = value;
        e.f = expect;
-       t.f = tolerance;
+       t.u = ulp;
        /* Treat infinity and nan seperately */
        if (probe_float_check_nan_inf(value, expect)) {
                return true;
        }
 
-       diff = value > expect ? value-expect : expect-value;
+       diff = fabsf(value - expect);
 
-       if(diff > tolerance || isnan(value)) {
-               printf("Expecting %f (0x%x) with tolerance %f, but got %f 
(0x%x)\n",
-                      e.f, e.u, t.f, v.f, v.u);
+       if(diff > ulp || isnan(value)) {
+               printf("Expecting %f (0x%x) with tolerance %f (%u ulps), but 
got %f (0x%x)\n",
+                      e.f, e.u, t.f, t.u, v.f, v.u);
                return false;
        }
 
@@ -90,7 +90,7 @@ piglit_cl_probe_floating(float value, float expect,  float 
tolerance)
 }
 
 bool
-piglit_cl_probe_double(double value, double expect, double tolerance)
+piglit_cl_probe_double(double value, double expect, uint64_t ulp)
 {
        double diff;
        union {
@@ -100,17 +100,17 @@ piglit_cl_probe_double(double value, double expect, 
double tolerance)
 
        v.f = value;
        e.f = expect;
-       t.f = tolerance;
+       t.u = ulp;
        /* Treat infinity and nan seperately */
        if (probe_float_check_nan_inf(value, expect)) {
                return true;
        }
 
-       diff = value > expect ? value-expect : expect-value;
+       diff = fabsl(value - expect);
 
-       if(diff > tolerance || isnan(value)) {
-               printf("Expecting %f (0x%lx) with tolerance %f, but got %f 
(0x%lx)\n",
-                      e.f, e.u, t.f, v.f, v.u);
+       if(diff > ulp || isnan(value)) {
+               printf("Expecting %f (0x%lx) with tolerance %f (%u ulps), but 
got %f (0x%lx)\n",
+                      e.f, e.u, t.f, t.u, v.f, v.u);
                return false;
        }
 
diff --git a/tests/util/piglit-util-cl.h b/tests/util/piglit-util-cl.h
index 90d0cd2..77d2545 100644
--- a/tests/util/piglit-util-cl.h
+++ b/tests/util/piglit-util-cl.h
@@ -63,15 +63,15 @@ bool piglit_cl_probe_uinteger(uint64_t value,
 
 /**
  * \brief Probe floating-point \c value if it compares equal to \c expect with
- *        tolerance \c tolerance.
+ *        tolerance \c ulp.
  */
-bool piglit_cl_probe_floating(float value, float expect, float tolerance);
+bool piglit_cl_probe_floating(float value, float expect, uint32_t ulp);
 
 /**
  * \brief Probe double \c value if it compares equal to \c expect with
- *        tolerance \c tolerance.
+ *        tolerance \c ulp.
  */
-bool piglit_cl_probe_double(double value, double expect, double tolerance);
+bool piglit_cl_probe_double(double value, double expect, uint64_t ulp);
 
 /**
  * \brief Check for unexpected GL error and report it.
-- 
1.8.1.4

_______________________________________________
Piglit mailing list
Piglit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to