aot_emit_aot_file_test.cc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 "wasm_export.h"
  8. #include "aot_export.h"
  9. #include "bh_read_file.h"
  10. static std::string CWD;
  11. static std::string MAIN_WASM = "/main.wasm";
  12. static char *WASM_FILE;
  13. extern "C" {
  14. uint8 *
  15. aot_emit_aot_file_buf(AOTCompContext *comp_ctx, AOTCompData *comp_data,
  16. uint32 *p_aot_file_size);
  17. }
  18. class aot_emit_aot_file_test_suite : public testing::Test
  19. {
  20. protected:
  21. // You should make the members protected s.t. they can be
  22. // accessed from sub-classes.
  23. // virtual void SetUp() will be called before each test is run. You
  24. // should define it if you need to initialize the variables.
  25. // Otherwise, this can be skipped.
  26. virtual void SetUp() {}
  27. static void SetUpTestCase()
  28. {
  29. CWD = get_test_binary_dir();
  30. WASM_FILE = strdup((CWD + MAIN_WASM).c_str());
  31. }
  32. // virtual void TearDown() will be called after each test is run.
  33. // You should define it if there is cleanup work to do. Otherwise,
  34. // you don't have to provide it.
  35. //
  36. virtual void TearDown() {}
  37. static void TearDownTestCase() { free(WASM_FILE); }
  38. WAMRRuntimeRAII<512 * 1024> runtime;
  39. };
  40. TEST_F(aot_emit_aot_file_test_suite, aot_emit_aot_file)
  41. {
  42. const char *wasm_file = WASM_FILE;
  43. unsigned int wasm_file_size = 0;
  44. unsigned char *wasm_file_buf = nullptr;
  45. char error_buf[128] = { 0 };
  46. wasm_module_t wasm_module = nullptr;
  47. aot_comp_data_t comp_data = nullptr;
  48. aot_comp_context_t comp_ctx = nullptr;
  49. AOTCompOption option = { 0 };
  50. char out_file_name[] = "test.aot";
  51. option.opt_level = 3;
  52. option.size_level = 3;
  53. option.output_format = AOT_FORMAT_FILE;
  54. /* default value, enable or disable depends on the platform */
  55. option.bounds_checks = 2;
  56. option.enable_simd = false;
  57. option.enable_aux_stack_check = false;
  58. option.enable_bulk_memory = false;
  59. option.enable_ref_types = false;
  60. wasm_file_buf =
  61. (unsigned char *)bh_read_file_to_buffer(wasm_file, &wasm_file_size);
  62. EXPECT_NE(wasm_file_buf, nullptr);
  63. wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size, error_buf,
  64. sizeof(error_buf));
  65. EXPECT_NE(wasm_module, nullptr);
  66. comp_data = aot_create_comp_data(wasm_module, NULL, false);
  67. EXPECT_NE(nullptr, comp_data);
  68. comp_ctx = aot_create_comp_context(comp_data, &option);
  69. EXPECT_NE(comp_ctx, nullptr);
  70. EXPECT_TRUE(aot_compile_wasm(comp_ctx));
  71. EXPECT_EQ(false, aot_emit_aot_file(comp_ctx, comp_data, nullptr));
  72. }