blob: fb5ceb9e473ae69eabd88f7a1735007201313675 [file] [log] [blame]
Zhi An Ng7d45d902022-01-12 09:18:24 -08001// 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
11TEST(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
20TEST(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}
Zhi An Ng15dd6112022-01-28 09:23:15 -080030
31TEST(JitMemory, AllocateAndReleaseCodeBufferWithNoCapacity) {
32 xnn_code_buffer b;
33 b.capacity = 0;
34 ASSERT_EQ(xnn_status_success, xnn_release_code_memory(&b));
35}