aot_emit_parametric_test.cc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. class aot_emit_parametric_test_suite : public testing::Test
  14. {
  15. protected:
  16. // You should make the members protected s.t. they can be
  17. // accessed from sub-classes.
  18. // virtual void SetUp() will be called before each test is run. You
  19. // should define it if you need to initialize the variables.
  20. // Otherwise, this can be skipped.
  21. virtual void SetUp() {}
  22. static void SetUpTestCase()
  23. {
  24. CWD = get_test_binary_dir();
  25. WASM_FILE = strdup((CWD + MAIN_WASM).c_str());
  26. }
  27. // virtual void TearDown() will be called after each test is run.
  28. // You should define it if there is cleanup work to do. Otherwise,
  29. // you don't have to provide it.
  30. //
  31. virtual void TearDown() {}
  32. static void TearDownTestCase() { free(WASM_FILE); }
  33. WAMRRuntimeRAII<512 * 1024> runtime;
  34. };
  35. TEST_F(aot_emit_parametric_test_suite, aot_compile_op_select)
  36. {
  37. const char *wasm_file = WASM_FILE;
  38. unsigned int wasm_file_size = 0;
  39. unsigned char *wasm_file_buf = nullptr;
  40. char error_buf[128] = { 0 };
  41. wasm_module_t wasm_module = nullptr;
  42. struct AOTCompData *comp_data = nullptr;
  43. struct AOTCompContext *comp_ctx = nullptr;
  44. AOTFuncContext *func_ctx = nullptr;
  45. AOTCompOption option = { 0 };
  46. option.opt_level = 3;
  47. option.size_level = 3;
  48. option.output_format = AOT_FORMAT_FILE;
  49. /* default value, enable or disable depends on the platform */
  50. option.bounds_checks = 2;
  51. option.enable_simd = true;
  52. option.enable_aux_stack_check = true;
  53. option.enable_bulk_memory = true;
  54. option.enable_ref_types = true;
  55. wasm_file_buf =
  56. (unsigned char *)bh_read_file_to_buffer(wasm_file, &wasm_file_size);
  57. EXPECT_NE(wasm_file_buf, nullptr);
  58. wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size, error_buf,
  59. sizeof(error_buf));
  60. EXPECT_NE(wasm_module, nullptr);
  61. comp_data = aot_create_comp_data((WASMModule *)wasm_module, NULL, false);
  62. EXPECT_NE(nullptr, comp_data);
  63. comp_ctx = aot_create_comp_context(comp_data, &option);
  64. EXPECT_NE(comp_ctx, nullptr);
  65. EXPECT_TRUE(aot_compile_wasm(comp_ctx));
  66. func_ctx = comp_ctx->func_ctxes[1];
  67. EXPECT_FALSE(aot_compile_op_select(comp_ctx, func_ctx, true));
  68. EXPECT_FALSE(aot_compile_op_select(comp_ctx, func_ctx, false));
  69. }
  70. TEST_F(aot_emit_parametric_test_suite, aot_compile_op_drop)
  71. {
  72. const char *wasm_file = WASM_FILE;
  73. unsigned int wasm_file_size = 0;
  74. unsigned char *wasm_file_buf = nullptr;
  75. char error_buf[128] = { 0 };
  76. wasm_module_t wasm_module = nullptr;
  77. struct AOTCompData *comp_data = nullptr;
  78. struct AOTCompContext *comp_ctx = nullptr;
  79. AOTFuncContext *func_ctx = nullptr;
  80. AOTCompOption option = { 0 };
  81. option.opt_level = 3;
  82. option.size_level = 3;
  83. option.output_format = AOT_FORMAT_FILE;
  84. /* default value, enable or disable depends on the platform */
  85. option.bounds_checks = 2;
  86. option.enable_simd = true;
  87. option.enable_aux_stack_check = true;
  88. option.enable_bulk_memory = true;
  89. option.enable_ref_types = true;
  90. wasm_file_buf =
  91. (unsigned char *)bh_read_file_to_buffer(wasm_file, &wasm_file_size);
  92. EXPECT_NE(wasm_file_buf, nullptr);
  93. wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size, error_buf,
  94. sizeof(error_buf));
  95. EXPECT_NE(wasm_module, nullptr);
  96. comp_data = aot_create_comp_data((WASMModule *)wasm_module, NULL, false);
  97. EXPECT_NE(nullptr, comp_data);
  98. comp_ctx = aot_create_comp_context(comp_data, &option);
  99. EXPECT_NE(comp_ctx, nullptr);
  100. EXPECT_TRUE(aot_compile_wasm(comp_ctx));
  101. func_ctx = comp_ctx->func_ctxes[1];
  102. func_ctx->block_stack.block_list_end = nullptr;
  103. EXPECT_FALSE(aot_compile_op_drop(comp_ctx, func_ctx, true));
  104. EXPECT_FALSE(aot_compile_op_drop(comp_ctx, func_ctx, false));
  105. }