• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 Google LLC
2 //
3 // This source code is licensed under the BSD-style license found in the
4 // LICENSE file in the root directory of this source tree.
5 
6 #include <xnnpack/allocator.h>
7 #include <xnnpack/common.h>
8 
9 #include <gtest/gtest.h>
10 
TEST(JitMemory,AllocateAndReleaseEmptyCode)11 TEST(JitMemory, AllocateAndReleaseEmptyCode) {
12   xnn_code_buffer b;
13   ASSERT_EQ(xnn_status_success, xnn_allocate_code_memory(&b, XNN_DEFAULT_CODE_BUFFER_SIZE));
14 #if XNN_PLATFORM_JIT
15   ASSERT_EQ(xnn_status_success, xnn_finalize_code_memory(&b));
16 #endif  // XNN_PLATFORM_JIT
17   ASSERT_EQ(xnn_status_success, xnn_release_code_memory(&b));
18 }
19 
TEST(JitMemory,AllocateAndReleaseJunkCode)20 TEST(JitMemory, AllocateAndReleaseJunkCode) {
21   xnn_code_buffer b;
22   ASSERT_EQ(xnn_status_success, xnn_allocate_code_memory(&b, XNN_DEFAULT_CODE_BUFFER_SIZE));
23   std::string junk = "1234";
24   memcpy(b.code, junk.data(), junk.length());
25 #if XNN_PLATFORM_JIT
26   ASSERT_EQ(xnn_status_success, xnn_finalize_code_memory(&b));
27 #endif  // XNN_PLATFORM_JIT
28   ASSERT_EQ(xnn_status_success, xnn_release_code_memory(&b));
29 }
30 
TEST(JitMemory,AllocateAndReleaseCodeBufferWithNoCapacity)31 TEST(JitMemory, AllocateAndReleaseCodeBufferWithNoCapacity) {
32   xnn_code_buffer b;
33   b.capacity = 0;
34   ASSERT_EQ(xnn_status_success, xnn_release_code_memory(&b));
35 }
36