133 logger.fine("@Result field = " + f);
134 Object myResult = getFieldFromObject(f, this);
135 Object otherResult = getFieldFromObject(f, base);
136 boolean same = compareObjects(myResult, otherResult);
137 logger.fine("comparing " + myResult + ", " + otherResult + ", match=" + same);
138 if (!same) {
139 logger.severe("mismatch comparing " + f + ", " + myResult + " vs. " + otherResult);
140 logSevere("FAILED!!! " + this.getClass());
141 return false;
142 }
143 }
144 }
145 }
146 clazz = clazz.getSuperclass();
147 }
148 logInfo("PASSED: " + this.getClass());
149 return true;
150 }
151
152 private boolean compareObjects(Object first, Object second) {
153 Class<?> clazz = first.getClass();
154 if (clazz != second.getClass()) {
155 return false;
156 }
157 if (!clazz.isArray()) {
158 // Non arrays.
159 if (clazz.equals(float.class) || clazz.equals(double.class)) {
160 return isEqualsFP((double) first, (double) second);
161 } else {
162 return first.equals(second);
163 }
164 } else {
165 // Handle the case where Objects are arrays.
166 ArrayComparer comparer;
167 if (clazz.equals(float[].class) || clazz.equals(double[].class)) {
168 comparer = new FPArrayComparer();
169 } else if (clazz.equals(long[].class) || clazz.equals(int[].class) || clazz.equals(byte[].class)) {
170 comparer = new IntArrayComparer();
171 } else if (clazz.equals(boolean[].class)) {
172 comparer = new BooleanArrayComparer();
248 @Override
249 Object getElement(Object ary, int index) {
250 return Array.getLong(ary, index);
251 }
252 }
253
254 class BooleanArrayComparer extends ArrayComparer {
255
256 @Override
257 Object getElement(Object ary, int index) {
258 return Array.getBoolean(ary, index);
259 }
260 }
261
262 class ObjArrayComparer extends ArrayComparer {
263
264 @Override
265 Object getElement(Object ary, int index) {
266 return Array.get(ary, index);
267 }
268 }
269
270 /**
271 * This isEqualsFP method allows subclass to override what FP equality means for this particular
272 * unit test.
273 */
274 public boolean isEqualsFP(double first, double second) {
275 return first == second;
276 }
277
278 public void setDispatchMode(DispatchMode dispatchMode) {
279 this.dispatchMode = dispatchMode;
280 }
281
282 public void setHsailMode(HsailMode hsailMode) {
283 this.hsailMode = hsailMode;
284 }
285
286 /**
287 * Return a clone of this instance unless overridden, we just call the null constructor.
479 return getHsailFromClassnameOclFile();
480 default:
481 fail("unknown hsailMode = " + hsailMode);
482 return null;
483 }
484 }
485
486 /**
487 * The getHSAILKernelName returns the name of the hsail kernel. By default we use 'run'. unless
488 * coming from opencl injection. Could be overridden by the junit test.
489 */
490 public String getHSAILKernelName() {
491 return (hsailMode != HsailMode.INJECT_OCL ? "&run" : "&__OpenCL_run_kernel");
492 }
493
494 private void createOkraKernel() {
495 // Call routines in the derived class to get the hsail code and kernel name.
496 String hsailSource = getHSAILSource(testMethod);
497 if (!okraLibExists) {
498 if (!gaveNoOkraWarning) {
499 logger.fine("No Okra library detected, skipping all KernelTester tests in " + this.getClass().getPackage().getName());
500 gaveNoOkraWarning = true;
501 }
502 }
503 // Ignore any kerneltester test if okra does not exist.
504 assumeTrue(okraLibExists);
505 // Control which okra instances can run the tests.
506 onSimulator = OkraContext.isSimulator();
507 okraContext = new OkraContext();
508 if (!okraContext.isValid()) {
509 fail("...unable to create context");
510 }
511 // Control verbosity in okra from our logLevel.
512 if (logLevel.intValue() <= Level.INFO.intValue()) {
513 okraContext.setVerbose(true);
514 }
515 okraKernel = new OkraKernel(okraContext, hsailSource, getHSAILKernelName());
516 if (!okraKernel.isValid()) {
517 fail("...unable to create kernel");
518 }
519 }
|
133 logger.fine("@Result field = " + f);
134 Object myResult = getFieldFromObject(f, this);
135 Object otherResult = getFieldFromObject(f, base);
136 boolean same = compareObjects(myResult, otherResult);
137 logger.fine("comparing " + myResult + ", " + otherResult + ", match=" + same);
138 if (!same) {
139 logger.severe("mismatch comparing " + f + ", " + myResult + " vs. " + otherResult);
140 logSevere("FAILED!!! " + this.getClass());
141 return false;
142 }
143 }
144 }
145 }
146 clazz = clazz.getSuperclass();
147 }
148 logInfo("PASSED: " + this.getClass());
149 return true;
150 }
151
152 private boolean compareObjects(Object first, Object second) {
153 if (first == null) {
154 return (second == null);
155 }
156 if (second == null) {
157 return (first == null);
158 }
159 Class<?> clazz = first.getClass();
160 if (clazz != second.getClass()) {
161 return false;
162 }
163 if (!clazz.isArray()) {
164 // Non arrays.
165 if (clazz.equals(float.class) || clazz.equals(double.class)) {
166 return isEqualsFP((double) first, (double) second);
167 } else {
168 return first.equals(second);
169 }
170 } else {
171 // Handle the case where Objects are arrays.
172 ArrayComparer comparer;
173 if (clazz.equals(float[].class) || clazz.equals(double[].class)) {
174 comparer = new FPArrayComparer();
175 } else if (clazz.equals(long[].class) || clazz.equals(int[].class) || clazz.equals(byte[].class)) {
176 comparer = new IntArrayComparer();
177 } else if (clazz.equals(boolean[].class)) {
178 comparer = new BooleanArrayComparer();
254 @Override
255 Object getElement(Object ary, int index) {
256 return Array.getLong(ary, index);
257 }
258 }
259
260 class BooleanArrayComparer extends ArrayComparer {
261
262 @Override
263 Object getElement(Object ary, int index) {
264 return Array.getBoolean(ary, index);
265 }
266 }
267
268 class ObjArrayComparer extends ArrayComparer {
269
270 @Override
271 Object getElement(Object ary, int index) {
272 return Array.get(ary, index);
273 }
274
275 @Override
276 boolean isEquals(Object firstElement, Object secondElement) {
277 return compareObjects(firstElement, secondElement);
278 }
279 }
280
281 /**
282 * This isEqualsFP method allows subclass to override what FP equality means for this particular
283 * unit test.
284 */
285 public boolean isEqualsFP(double first, double second) {
286 return first == second;
287 }
288
289 public void setDispatchMode(DispatchMode dispatchMode) {
290 this.dispatchMode = dispatchMode;
291 }
292
293 public void setHsailMode(HsailMode hsailMode) {
294 this.hsailMode = hsailMode;
295 }
296
297 /**
298 * Return a clone of this instance unless overridden, we just call the null constructor.
490 return getHsailFromClassnameOclFile();
491 default:
492 fail("unknown hsailMode = " + hsailMode);
493 return null;
494 }
495 }
496
497 /**
498 * The getHSAILKernelName returns the name of the hsail kernel. By default we use 'run'. unless
499 * coming from opencl injection. Could be overridden by the junit test.
500 */
501 public String getHSAILKernelName() {
502 return (hsailMode != HsailMode.INJECT_OCL ? "&run" : "&__OpenCL_run_kernel");
503 }
504
505 private void createOkraKernel() {
506 // Call routines in the derived class to get the hsail code and kernel name.
507 String hsailSource = getHSAILSource(testMethod);
508 if (!okraLibExists) {
509 if (!gaveNoOkraWarning) {
510 logger.severe("No Okra library detected, skipping all KernelTester tests in " + this.getClass().getPackage().getName());
511 gaveNoOkraWarning = true;
512 }
513 }
514 // Ignore any kerneltester test if okra does not exist.
515 assumeTrue(okraLibExists);
516 // Control which okra instances can run the tests.
517 onSimulator = OkraContext.isSimulator();
518 okraContext = new OkraContext();
519 if (!okraContext.isValid()) {
520 fail("...unable to create context");
521 }
522 // Control verbosity in okra from our logLevel.
523 if (logLevel.intValue() <= Level.INFO.intValue()) {
524 okraContext.setVerbose(true);
525 }
526 okraKernel = new OkraKernel(okraContext, hsailSource, getHSAILKernelName());
527 if (!okraKernel.isValid()) {
528 fail("...unable to create kernel");
529 }
530 }
|