Skip to content

Commit edcd505

Browse files
authored
fix: unbreak osl-unittest.h for OptiX (#1926)
Ugh, I broke the testsuite under OptiX a while back and it took me a while to notice. When I added new unit tests for color[24] and vector[24], I used the format() call, and that's not supported in OptiX mode. But printf is, so in this patch, I fix it all up and now the tests pass in OptiX. Signed-off-by: Larry Gritz <[email protected]>
1 parent 4176a6f commit edcd505

File tree

3 files changed

+45
-20
lines changed

3 files changed

+45
-20
lines changed

testsuite/color4/test.osl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ test (color4 param1 = color4 ({0.5, 1.5, 2.5}, 3.5),
4242
color4 param2 = color4 ({10.0, 20.0, 30.0}, 40.0)
4343
)
4444
{
45-
printf("parameter initialization: param1 = %s\n", tostring(param1));
46-
printf("parameter initialization: param2 = %s\n", tostring(param2));
45+
printf("parameter initialization: param1 = %g %g\n", param1.rgb, param1.a);
46+
printf("parameter initialization: param2 = %g %g\n", param2.rgb, param2.a);
4747
printf("\n");
4848

4949
OSL_CHECK_EQUAL(param1, mkcolor4(0.5, 1.5, 2.5, 3.5));

testsuite/common/shaders/osl-unittest.h

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,61 @@
2323
#endif
2424

2525

26-
string tostring(int x) { return format("%d", x); }
27-
string tostring(float x) { return format("%g", x); }
28-
string tostring(color x) { return format("%g", x); }
29-
string tostring(point x) { return format("%g", x); }
30-
string tostring(vector x) { return format("%g", x); }
31-
string tostring(normal x) { return format("%g", x); }
32-
string tostring(string x) { return x; }
26+
27+
void failmsg(string file, int line, string xs, int x, string ys, int y)
28+
{
29+
printf("\nFAIL: %s:%d: %s (%d) == %s (%d)\n\n", file, line, xs, x, ys, y);
30+
}
31+
32+
void failmsg(string file, int line, string xs, float x, string ys, float y)
33+
{
34+
printf("\nFAIL: %s:%d: %s (%g) == %s (%g)\n\n", file, line, xs, x, ys, y);
35+
}
36+
37+
void failmsg(string file, int line, string xs, color x, string ys, color y)
38+
{
39+
printf("\nFAIL: %s:%d: %s (%g) == %s (%g)\n\n", file, line, xs, x, ys, y);
40+
}
41+
42+
void failmsg(string file, int line, string xs, vector x, string ys, vector y)
43+
{
44+
printf("\nFAIL: %s:%d: %s (%g) == %s (%g)\n\n", file, line, xs, x, ys, y);
45+
}
3346

3447
#ifdef COLOR2_H
35-
string tostring(color2 x) { return format("%g %g", x.r, x.a); }
48+
void failmsg(string file, int line, string xs, color2 x, string ys, color2 y)
49+
{
50+
printf("\nFAIL: %s:%d: %s (%g %g) == %s (%g %g)\n\n",
51+
file, line, xs, x.r, x.a, ys, y.r, y.a);
52+
}
3653
#endif
3754

3855
#ifdef COLOR4_H
39-
string tostring(color4 x)
56+
void failmsg(string file, int line, string xs, color4 x, string ys, color4 y)
4057
{
41-
return format("%g %g %g %g", x.rgb.r, x.rgb.g, x.rgb.b, x.a);
58+
printf("\nFAIL: %s:%d: %s (%g %g) == %s (%g %g)\n\n",
59+
file, line, xs, x.rgb, x.a, ys, y.rgb, y.a);
4260
}
4361
#endif
4462

4563
#ifdef VECTOR2_H
46-
string tostring(vector2 x) { return format("%g %g", x.x, x.y); }
64+
void failmsg(string file, int line, string xs, vector2 x, string ys, vector2 y)
65+
{
66+
printf("\nFAIL: %s:%d: %s (%g %g) == %s (%g %g)\n\n",
67+
file, line, xs, x.x, x.y, ys, y.x, y.y);
68+
}
4769
#endif
4870

4971
#ifdef VECTOR4_H
50-
string tostring(vector4 x)
72+
void failmsg(string file, int line, string xs, vector4 x, string ys, vector4 y)
5173
{
52-
return format("%g %g %g %g", x.x, x.y, x.z, x.w);
74+
printf("\nFAIL: %s:%d: %s (%g %g %g %g) == %s (%g %g %g %g)\n\n",
75+
file, line, xs, x.x, x.y, x.z, x.w, ys, y.x, y.y, y.z, y.w);
5376
}
5477
#endif
5578

5679

80+
5781
// Macros to test conditions in shaders.
5882
//
5983
// A success by default will just silently move on, but if the symbol
@@ -80,15 +104,14 @@ string tostring(vector4 x)
80104

81105

82106
// Check that two expressions are equal. For non-built-in types, this
83-
// requires that a tostring() function is defined for that type.
107+
// requires that a failmsg() function is defined for that type.
84108
#define OSL_CHECK_EQUAL(x,y) \
85109
do { \
86110
if ((x) == (y)) { \
87111
if (OSL_UNITTEST_VERBOSE) \
88112
printf("PASS: %s == %s\n", #x, #y); \
89113
} else { \
90-
printf("\nFAIL: %s:%d: %s (%s) == %s (%s)\n\n", \
91-
__FILE__, __LINE__, #x, tostring(x), #y, tostring(y)); \
114+
failmsg(__FILE__, __LINE__, #x, x, #y, y); \
92115
if (OSL_UNITTEST_EXIT_ON_FAILURE) \
93116
exit(); \
94117
} \

testsuite/vector4/test.osl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ test (vector4 param1 = vector4 (0.5, 1.5, 2.5, 3.5),
3737
vector4 param2 = vector4 (10.0, 20.0, 30.0, 40.0)
3838
)
3939
{
40-
printf("parameter initialization: param1 = %s\n", tostring(param1));
41-
printf("parameter initialization: param2 = %s\n", tostring(param2));
40+
printf("parameter initialization: param1 = %g %g %g %g\n",
41+
param1.x, param1.y, param1.z, param1.w);
42+
printf("parameter initialization: param2 = %g %g %g %g\n",
43+
param2.x, param2.y, param2.z, param2.w);
4244
printf("\n");
4345

4446
OSL_CHECK_EQUAL(param1, vector4(0.5, 1.5, 2.5, 3.5));

0 commit comments

Comments
 (0)