aot_emit_parametric_test.cc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include "test_helper.h"
  6. #include "gtest/gtest.h"
  7. #include "bh_read_file.h"
  8. #include "aot_llvm.h"
  9. #include "aot_emit_parametric.h"
  10. static std::string CWD;
  11. static std::string MAIN_WASM = "/main.wasm";
  12. static char *WASM_FILE;
  13. static std::string
  14. get_binary_path()
  15. {
  16. char cwd[1024];
  17. memset(cwd, 0, 1024);
  18. if (readlink("/proc/self/exe", cwd, 1024) <= 0) {
  19. }
  20. char *path_end = strrchr(cwd, '/');
  21. if (path_end != NULL) {
  22. *path_end = '\0';
  23. }
  24. return std::string(cwd);
  25. }
  26. class aot_emit_parametric_test_suite : public testing::Test
  27. {
  28. protected:
  29. // You should make the members protected s.t. they can be
  30. // accessed from sub-classes.
  31. // virtual void SetUp() will be called before each test is run. You
  32. // should define it if you need to initialize the variables.
  33. // Otherwise, this can be skipped.
  34. virtual void SetUp() {}
  35. static void SetUpTestCase()
  36. {
  37. CWD = get_binary_path();
  38. WASM_FILE = strdup((CWD + MAIN_WASM).c_str());
  39. }
  40. // virtual void TearDown() will be called after each test is run.
  41. // You should define it if there is cleanup work to do. Otherwise,
  42. // you don't have to provide it.
  43. //
  44. virtual void TearDown() {}
  45. static void TearDownTestCase() { free(WASM_FILE); }
  46. WAMRRuntimeRAII<512 * 1024> runtime;
  47. };
  48. TEST_F(aot_emit_parametric_test_suite, aot_compile_op_select)
  49. {
  50. const char *wasm_file = WASM_FILE;
  51. unsigned int wasm_file_size = 0;
  52. unsigned char *wasm_file_buf = nullptr;
  53. char error_buf[128] = { 0 };
  54. wasm_module_t wasm_module = nullptr;
  55. struct AOTCompData *comp_data = nullptr;
  56. struct AOTCompContext *comp_ctx = nullptr;
  57. AOTFuncContext *func_ctx = nullptr;
  58. AOTCompOption option = { 0 };
  59. option.opt_level = 3;
  60. option.size_level = 3;
  61. option.output_format = AOT_FORMAT_FILE;
  62. /* default value, enable or disable depends on the platform */
  63. option.bounds_checks = 2;
  64. option.enable_simd = true;
  65. option.enable_aux_stack_check = true;
  66. option.enable_bulk_memory = true;
  67. option.enable_ref_types = true;
  68. wasm_file_buf =
  69. (unsigned char *)bh_read_file_to_buffer(wasm_file, &wasm_file_size);
  70. EXPECT_NE(wasm_file_buf, nullptr);
  71. wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size, error_buf,
  72. sizeof(error_buf));
  73. EXPECT_NE(wasm_module, nullptr);
  74. comp_data = aot_create_comp_data((WASMModule *)wasm_module, NULL, false);
  75. EXPECT_NE(nullptr, comp_data);
  76. comp_ctx = aot_create_comp_context(comp_data, &option);
  77. EXPECT_NE(comp_ctx, nullptr);
  78. EXPECT_TRUE(aot_compile_wasm(comp_ctx));
  79. func_ctx = comp_ctx->func_ctxes[1];
  80. EXPECT_FALSE(aot_compile_op_select(comp_ctx, func_ctx, true));
  81. EXPECT_FALSE(aot_compile_op_select(comp_ctx, func_ctx, false));
  82. }
  83. TEST_F(aot_emit_parametric_test_suite, aot_compile_op_drop)
  84. {
  85. const char *wasm_file = WASM_FILE;
  86. unsigned int wasm_file_size = 0;
  87. unsigned char *wasm_file_buf = nullptr;
  88. char error_buf[128] = { 0 };
  89. wasm_module_t wasm_module = nullptr;
  90. struct AOTCompData *comp_data = nullptr;
  91. struct AOTCompContext *comp_ctx = nullptr;
  92. AOTFuncContext *func_ctx = nullptr;
  93. AOTCompOption option = { 0 };
  94. option.opt_level = 3;
  95. option.size_level = 3;
  96. option.output_format = AOT_FORMAT_FILE;
  97. /* default value, enable or disable depends on the platform */
  98. option.bounds_checks = 2;
  99. option.enable_simd = true;
  100. option.enable_aux_stack_check = true;
  101. option.enable_bulk_memory = true;
  102. option.enable_ref_types = true;
  103. wasm_file_buf =
  104. (unsigned char *)bh_read_file_to_buffer(wasm_file, &wasm_file_size);
  105. EXPECT_NE(wasm_file_buf, nullptr);
  106. wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size, error_buf,
  107. sizeof(error_buf));
  108. EXPECT_NE(wasm_module, nullptr);
  109. comp_data = aot_create_comp_data((WASMModule *)wasm_module, NULL, false);
  110. EXPECT_NE(nullptr, comp_data);
  111. comp_ctx = aot_create_comp_context(comp_data, &option);
  112. EXPECT_NE(comp_ctx, nullptr);
  113. EXPECT_TRUE(aot_compile_wasm(comp_ctx));
  114. func_ctx = comp_ctx->func_ctxes[1];
  115. func_ctx->block_stack.block_list_end = nullptr;
  116. EXPECT_FALSE(aot_compile_op_drop(comp_ctx, func_ctx, true));
  117. EXPECT_FALSE(aot_compile_op_drop(comp_ctx, func_ctx, false));
  118. }