Loesung des Praktikums Systementwurf - Bjarne Hoesch - Bernhard Schoeffel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

device_test.c 1.5KB

1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "device_test.h"
  2. #include <stdio.h>
  3. #include <math.h>
  4. int device_test( test_function test, uint32_t binding, void * task, void * input_a, void * input_b, void * expected, float epsilon ) {
  5. int ret = test( binding, task, input_a, input_b, expected, epsilon );
  6. printf( TEST_DONE );
  7. return ret;
  8. }
  9. int assert_float_near( float expected, float value, float abs_err ) {
  10. float abs_diff = fabs( expected - value );
  11. int pass = abs_diff <= abs_err;
  12. if ( ! pass ) {
  13. printf( TEST_FAIL " assert_float_near |%e - %e| = %e < %e\n", expected, value, abs_diff, abs_err );
  14. }
  15. return pass;
  16. }
  17. int assert_eq( uint32_t expected, uint32_t value ) {
  18. int pass = expected == value;
  19. if ( ! pass ) {
  20. printf( TEST_FAIL " assert_eq %" PRIx32" = %" PRIx32, expected, value );
  21. }
  22. return pass;
  23. }
  24. void print_float_data_for_python( const float_word * data, uint32_t len ) {
  25. printf( "py_float_data=[%e", data[ 0 ].value );
  26. for ( uint32_t i = 1; i < len; ++i ) {
  27. printf( ",%e", data[ i ].value );
  28. }
  29. printf( "]\n" );
  30. }
  31. void print_hex_data_for_python( const float_word * data, uint32_t len ) {
  32. printf( "py_hex_data=[0x%"PRIx32, data[ 0 ].word );
  33. for ( uint32_t i = 1; i < len; ++i ) {
  34. printf( ",0x%"PRIx32, data[ i ].word );
  35. }
  36. printf( "]\n" );
  37. }
  38. void print_results_for_python( uint32_t cycle_count, const float_word * data, uint32_t len ) {
  39. printf( "py_cycle_count=%"PRIu32"\n", cycle_count );
  40. print_float_data_for_python( data, len );
  41. print_hex_data_for_python( data, len );
  42. }