qemu

FORK: QEMU emulator
git clone https://git.neptards.moe/neptards/qemu.git
Log | Files | Refs | Submodules | LICENSE

test_utils_32.h (2200B)


      1 /*
      2  *  Header file for test utilities
      3  *
      4  *  Copyright (C) 2019  Wave Computing, Inc.
      5  *  Copyright (C) 2019  Aleksandar Markovic <amarkovic@wavecomp.com>
      6  *
      7  *  This program is free software: you can redistribute it and/or modify
      8  *  it under the terms of the GNU General Public License as published by
      9  *  the Free Software Foundation, either version 2 of the License, or
     10  *  (at your option) any later version.
     11  *
     12  *  This program is distributed in the hope that it will be useful,
     13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15  *  GNU General Public License for more details.
     16  *
     17  *  You should have received a copy of the GNU General Public License
     18  *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
     19  *
     20  */
     21 
     22 #ifndef TEST_UTILS_32_H
     23 #define TEST_UTILS_32_H
     24 
     25 #include <stdio.h>
     26 #include <stdint.h>
     27 #include <inttypes.h>
     28 #include <string.h>
     29 
     30 #define PRINT_RESULTS 0
     31 
     32 
     33 static inline int32_t check_results_32(const char *instruction_name,
     34                                        const uint32_t test_count,
     35                                        const double elapsed_time,
     36                                        const uint32_t *b32_result,
     37                                        const uint32_t *b32_expect)
     38 {
     39 #if PRINT_RESULTS
     40     uint32_t ii;
     41     printf("\n");
     42     for (ii = 0; ii < test_count; ii++) {
     43         uint64_t a;
     44         memcpy(&a, (b32_result + ii), 8);
     45         if (ii % 8 != 0) {
     46             printf("        0x%08lxULL,\n", a);
     47         } else {
     48             printf("        0x%08lxULL,                   /* %3d  */\n",
     49                    a, ii);
     50         }
     51     }
     52     printf("\n");
     53 #endif
     54     uint32_t i;
     55     uint32_t pass_count = 0;
     56     uint32_t fail_count = 0;
     57 
     58     printf("%s:   ", instruction_name);
     59     for (i = 0; i < test_count; i++) {
     60         if (b32_result[i] == b32_expect[i]) {
     61             pass_count++;
     62         } else {
     63             fail_count++;
     64         }
     65     }
     66 
     67     printf("PASS: %3d   FAIL: %3d   elapsed time: %5.2f ms\n",
     68            pass_count, fail_count, elapsed_time);
     69 
     70     if (fail_count > 0) {
     71         return -1;
     72     } else {
     73         return 0;
     74     }
     75 }
     76 
     77 
     78 #endif