Colin Cross | 363441b | 2013-11-07 23:06:58 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 <gtest/gtest.h> |
| 18 | |
| 19 | #include <ion/ion.h> |
| 20 | |
| 21 | #include "ion_test_fixture.h" |
| 22 | |
| 23 | IonTest::IonTest() : m_ionFd(-1) |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | void IonTest::SetUp() { |
| 28 | m_ionFd = ion_open(); |
| 29 | ASSERT_GE(m_ionFd, 0); |
| 30 | } |
| 31 | |
| 32 | void IonTest::TearDown() { |
| 33 | ion_close(m_ionFd); |
| 34 | } |
| 35 | |
| 36 | IonAllHeapsTest::IonAllHeapsTest() : |
| 37 | m_firstHeap(0), |
| 38 | m_lastHeap(0), |
| 39 | m_allHeaps() |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | void IonAllHeapsTest::SetUp() { |
| 44 | int fd = ion_open(); |
| 45 | ASSERT_GE(fd, 0); |
| 46 | |
| 47 | for (int i = 1; i != 0; i <<= 1) { |
| 48 | ion_user_handle_t handle = 0; |
| 49 | int ret; |
| 50 | ret = ion_alloc(fd, 4096, 0, i, 0, &handle); |
| 51 | if (ret == 0 && handle != 0) { |
| 52 | ion_free(fd, handle); |
| 53 | if (!m_firstHeap) { |
| 54 | m_firstHeap = i; |
| 55 | } |
| 56 | m_lastHeap = i; |
| 57 | m_allHeaps.push_back(i); |
| 58 | } else { |
| 59 | ASSERT_EQ(-ENODEV, ret); |
| 60 | } |
| 61 | } |
| 62 | ion_close(fd); |
| 63 | |
| 64 | EXPECT_NE(0U, m_firstHeap); |
| 65 | EXPECT_NE(0U, m_lastHeap); |
| 66 | |
| 67 | RecordProperty("Heaps", m_allHeaps.size()); |
| 68 | IonTest::SetUp(); |
| 69 | } |
| 70 | |
| 71 | void IonAllHeapsTest::TearDown() { |
| 72 | IonTest::TearDown(); |
| 73 | } |