1 /*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <unistd.h>
18
19 #include <gtest/gtest.h>
20 #include <iostream>
21
22 #include <ion/ion.h>
23 #include "ion_test_fixture.h"
24
25 class SystemHeap : public IonTest {};
26
TEST_F(SystemHeap,Presence)27 TEST_F(SystemHeap, Presence) {
28 bool system_heap_found = false;
29 for (const auto& heap : ion_heaps) {
30 if (heap.type == ION_HEAP_TYPE_SYSTEM) {
31 system_heap_found = true;
32 EXPECT_TRUE((1 << heap.heap_id) & ION_HEAP_SYSTEM_MASK);
33 }
34 }
35 // We now expect the system heap to exist from Android
36 ASSERT_TRUE(system_heap_found);
37 }
38
TEST_F(SystemHeap,Allocate)39 TEST_F(SystemHeap, Allocate) {
40 int fd;
41 ASSERT_EQ(0, ion_alloc_fd(ionfd, getpagesize(), 0, ION_HEAP_SYSTEM_MASK, 0, &fd));
42 ASSERT_TRUE(fd != 0);
43 ASSERT_EQ(close(fd), 0); // free the buffer
44 }
45