aot_emit_function_test.cc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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_emit_control.h"
  9. #include "aot_emit_function.h"
  10. static std::string CWD;
  11. static std::string MAIN_WASM = "/main.wasm";
  12. static char *WASM_FILE;
  13. class aot_emit_function_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_function_test_suite, aot_compile_op_call)
  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. char out_file_name[] = "out_file_name_test";
  47. option.opt_level = 3;
  48. option.size_level = 3;
  49. option.output_format = AOT_FORMAT_FILE;
  50. /* default value, enable or disable depends on the platform */
  51. option.bounds_checks = 2;
  52. option.enable_simd = true;
  53. option.enable_aux_stack_check = true;
  54. option.enable_bulk_memory = true;
  55. option.enable_ref_types = true;
  56. wasm_file_buf =
  57. (unsigned char *)bh_read_file_to_buffer(wasm_file, &wasm_file_size);
  58. EXPECT_NE(wasm_file_buf, nullptr);
  59. wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size, error_buf,
  60. sizeof(error_buf));
  61. EXPECT_NE(wasm_module, nullptr);
  62. comp_data = aot_create_comp_data((WASMModule *)wasm_module, NULL, false);
  63. EXPECT_NE(nullptr, comp_data);
  64. comp_ctx = aot_create_comp_context(comp_data, &option);
  65. EXPECT_NE(comp_ctx, nullptr);
  66. EXPECT_TRUE(aot_compile_wasm(comp_ctx));
  67. func_ctx = comp_ctx->func_ctxes[1];
  68. EXPECT_EQ(false, aot_compile_op_call(comp_ctx, func_ctx, 9999, true));
  69. }