asmjit_test_assembler.cpp (3010B)
1 // This file is part of AsmJit project <https://asmjit.com> 2 // 3 // See <asmjit/core.h> or LICENSE.md for license and copyright information 4 // SPDX-License-Identifier: Zlib 5 6 #include <asmjit/core.h> 7 #include <stdio.h> 8 #include <stdlib.h> 9 #include <string.h> 10 11 #include "asmjit_test_assembler.h" 12 13 #include "../commons/asmjitutils.h" 14 #include "../commons/cmdline.h" 15 16 using namespace asmjit; 17 18 #if !defined(ASMJIT_NO_X86) 19 bool test_x86_assembler(const TestSettings& settings) noexcept; 20 bool test_x64_assembler(const TestSettings& settings) noexcept; 21 #endif 22 23 #if !defined(ASMJIT_NO_AARCH64) 24 bool test_aarch64_assembler(const TestSettings& settings) noexcept; 25 #endif 26 27 static void print_app_info() noexcept { 28 printf("AsmJit Assembler Test-Suite v%u.%u.%u [Arch=%s] [Mode=%s]\n\n", 29 unsigned((ASMJIT_LIBRARY_VERSION >> 16) ), 30 unsigned((ASMJIT_LIBRARY_VERSION >> 8) & 0xFF), 31 unsigned((ASMJIT_LIBRARY_VERSION ) & 0xFF), 32 asmjit_arch_as_string(Arch::kHost), 33 asmjit_build_type() 34 ); 35 } 36 37 static void print_app_usage(const TestSettings& settings) noexcept { 38 printf("Usage:\n"); 39 printf(" --help Show usage only\n"); 40 printf(" --verbose Show only assembling errors [%s]\n", settings.verbose ? "x" : " "); 41 printf(" --validate Use instruction validation [%s]\n", settings.validate ? "x" : " "); 42 printf(" --arch=<ARCH> Select architecture to run ('all' by default)\n"); 43 printf("\n"); 44 45 printf("Architectures:\n"); 46 #if !defined(ASMJIT_NO_X86) 47 printf(" --arch=x86 32-bit X86 architecture (X86)\n"); 48 printf(" --arch=x64 64-bit X86 architecture (X86_64)\n"); 49 #endif 50 #if !defined(ASMJIT_NO_AARCH64) 51 printf(" --arch=aarch64 64-bit ARM architecture (AArch64)\n"); 52 #endif 53 printf("\n"); 54 } 55 56 int main(int argc, char* argv[]) { 57 CmdLine cmd_line(argc, argv); 58 59 TestSettings settings {}; 60 settings.verbose = cmd_line.has_arg("--verbose"); 61 settings.validate = cmd_line.has_arg("--validate"); 62 63 print_app_info(); 64 print_app_usage(settings); 65 66 if (cmd_line.has_arg("--help")) { 67 return 0; 68 } 69 70 const char* arch = cmd_line.value_of("--arch", "all"); 71 bool x86_failed = false; 72 bool x64_failed = false; 73 bool aarch64_failed = false; 74 75 #if !defined(ASMJIT_NO_X86) 76 if ((strcmp(arch, "all") == 0 || strcmp(arch, "x86") == 0)) 77 x86_failed = !test_x86_assembler(settings); 78 79 if ((strcmp(arch, "all") == 0 || strcmp(arch, "x64") == 0)) 80 x64_failed = !test_x64_assembler(settings); 81 #endif 82 83 #if !defined(ASMJIT_NO_AARCH64) 84 if ((strcmp(arch, "all") == 0 || strcmp(arch, "aarch64") == 0)) 85 aarch64_failed = !test_aarch64_assembler(settings); 86 #endif 87 88 bool failed = x86_failed || x64_failed || aarch64_failed; 89 90 if (failed) { 91 if (x86_failed) 92 printf("** X86 test suite failed **\n"); 93 94 if (x64_failed) 95 printf("** X64 test suite failed **\n"); 96 97 if (aarch64_failed) 98 printf("** AArch64 test suite failed **\n"); 99 100 printf("** FAILURE **\n"); 101 } 102 else { 103 printf("** SUCCESS **\n"); 104 } 105 106 return failed ? 1 : 0; 107 }