gc_test.cc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_platform.h"
  8. #include "bh_read_file.h"
  9. #include "wasm_export.h"
  10. class WasmGCTest : public testing::Test
  11. {
  12. protected:
  13. void SetUp()
  14. {
  15. CWD = get_test_binary_dir();
  16. memset(&init_args, 0, sizeof(RuntimeInitArgs));
  17. init_args.mem_alloc_type = Alloc_With_Pool;
  18. init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
  19. init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
  20. ASSERT_EQ(wasm_runtime_full_init(&init_args), true);
  21. cleanup = true;
  22. }
  23. void TearDown()
  24. {
  25. if (cleanup) {
  26. wasm_runtime_destroy();
  27. }
  28. }
  29. public:
  30. bool load_wasm_file(const char *wasm_file)
  31. {
  32. char *file;
  33. unsigned char *wasm_file_buf;
  34. uint32 wasm_file_size;
  35. file = strdup((CWD + "/" + wasm_file).c_str());
  36. wasm_file_buf =
  37. (unsigned char *)bh_read_file_to_buffer(file, &wasm_file_size);
  38. free(file);
  39. if (!wasm_file_buf)
  40. return false;
  41. module = wasm_runtime_load(wasm_file_buf, wasm_file_size, error_buf,
  42. sizeof(error_buf));
  43. if (!module)
  44. return false;
  45. return true;
  46. }
  47. public:
  48. std::string CWD;
  49. RuntimeInitArgs init_args;
  50. wasm_module_t module = NULL;
  51. wasm_module_inst_t module_inst = NULL;
  52. wasm_function_inst_t func_inst = NULL;
  53. wasm_exec_env_t exec_env = NULL;
  54. char error_buf[128];
  55. char global_heap_buf[512 * 1024];
  56. bool cleanup = true;
  57. };
  58. TEST_F(WasmGCTest, Test_app1)
  59. {
  60. ASSERT_TRUE(load_wasm_file("test1.wasm"));
  61. ASSERT_TRUE(load_wasm_file("test2.wasm"));
  62. ASSERT_TRUE(load_wasm_file("test3.wasm"));
  63. ASSERT_TRUE(load_wasm_file("test4.wasm"));
  64. ASSERT_TRUE(load_wasm_file("test5.wasm"));
  65. ASSERT_TRUE(load_wasm_file("test6.wasm"));
  66. ASSERT_TRUE(load_wasm_file("struct1.wasm"));
  67. ASSERT_TRUE(load_wasm_file("struct2.wasm"));
  68. ASSERT_TRUE(load_wasm_file("struct3.wasm"));
  69. ASSERT_TRUE(load_wasm_file("func1.wasm"));
  70. ASSERT_TRUE(load_wasm_file("func2.wasm"));
  71. }
  72. TEST_F(WasmGCTest, Test_nested_struct)
  73. {
  74. //FIXME: Revert the change when anyref support is added
  75. ASSERT_FALSE(load_wasm_file("nested_struct_field_any.wasm"));
  76. ASSERT_FALSE(load_wasm_file("nested_array_elem_any.wasm"));
  77. }