Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 1 | /* crosstest.py --test=mem_intrin.cpp --driver=mem_intrin_main.cpp \ |
| 2 | --prefix=Subzero_ --output=mem_intrin */ |
| 3 | |
| 4 | #include <stdint.h> /* cstdint requires -std=c++0x or higher */ |
| 5 | #include <cstdio> |
| 6 | |
| 7 | #include "mem_intrin.h" |
| 8 | namespace Subzero_ { |
| 9 | #include "mem_intrin.h" |
| 10 | } |
| 11 | |
| 12 | #define XSTR(s) STR(s) |
| 13 | #define STR(s) #s |
| 14 | |
| 15 | void testFixedLen(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
Jim Stichnoth | dd842db | 2015-01-27 12:53:53 -0800 | [diff] [blame^] | 16 | #define do_test_fixed(test_func) \ |
| 17 | for (uint8_t init_val = 0; init_val < 100; ++init_val) { \ |
| 18 | ++TotalTests; \ |
| 19 | int llc_result = test_func(init_val); \ |
| 20 | int sz_result = Subzero_::test_func(init_val); \ |
| 21 | if (llc_result == sz_result) { \ |
| 22 | ++Passes; \ |
| 23 | } else { \ |
| 24 | ++Failures; \ |
| 25 | printf("Failure (%s): init_val=%d, llc=%d, sz=%d\n", STR(test_func), \ |
| 26 | init_val, llc_result, sz_result); \ |
| 27 | } \ |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Jim Stichnoth | dd842db | 2015-01-27 12:53:53 -0800 | [diff] [blame^] | 30 | do_test_fixed(memcpy_test_fixed_len); |
| 31 | do_test_fixed(memmove_test_fixed_len); |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 32 | do_test_fixed(memset_test_fixed_len) |
| 33 | #undef do_test_fixed |
| 34 | } |
| 35 | |
| 36 | void testVariableLen(size_t &TotalTests, size_t &Passes, size_t &Failures) { |
| 37 | uint8_t buf[256]; |
| 38 | uint8_t buf2[256]; |
Jim Stichnoth | dd842db | 2015-01-27 12:53:53 -0800 | [diff] [blame^] | 39 | #define do_test_variable(test_func) \ |
| 40 | for (size_t len = 4; len < 128; ++len) { \ |
| 41 | for (uint8_t init_val = 0; init_val < 100; ++init_val) { \ |
| 42 | ++TotalTests; \ |
| 43 | int llc_result = test_func(buf, buf2, init_val, len); \ |
| 44 | int sz_result = Subzero_::test_func(buf, buf2, init_val, len); \ |
| 45 | if (llc_result == sz_result) { \ |
| 46 | ++Passes; \ |
| 47 | } else { \ |
| 48 | ++Failures; \ |
| 49 | printf("Failure (%s): init_val=%d, len=%d, llc=%d, sz=%d\n", \ |
| 50 | STR(test_func), init_val, len, llc_result, sz_result); \ |
| 51 | } \ |
| 52 | } \ |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Jim Stichnoth | dd842db | 2015-01-27 12:53:53 -0800 | [diff] [blame^] | 55 | do_test_variable(memcpy_test); |
| 56 | do_test_variable(memmove_test); |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 57 | do_test_variable(memset_test) |
| 58 | #undef do_test_variable |
| 59 | } |
| 60 | |
| 61 | int main(int argc, char **argv) { |
| 62 | unsigned TotalTests = 0; |
| 63 | unsigned Passes = 0; |
| 64 | unsigned Failures = 0; |
| 65 | testFixedLen(TotalTests, Passes, Failures); |
| 66 | testVariableLen(TotalTests, Passes, Failures); |
| 67 | printf("TotalTests=%u Passes=%u Failures=%u\n", TotalTests, Passes, Failures); |
| 68 | return Failures; |
| 69 | } |