1 /* 2 * Copyright (C) 2017 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 #ifndef SRC_TRACING_TEST_ALIGNED_BUFFER_TEST_H_ 18 #define SRC_TRACING_TEST_ALIGNED_BUFFER_TEST_H_ 19 20 #include <stdlib.h> 21 22 #include <memory> 23 #include <utility> 24 25 #include "perfetto/ext/base/utils.h" 26 #include "src/tracing/test/test_shared_memory.h" 27 #include "test/gtest_and_gmock.h" 28 29 namespace perfetto { 30 31 // Base parametrized test for unittests that require an aligned buffer. 32 class AlignedBufferTest : public ::testing::TestWithParam<size_t> { 33 public: 34 static constexpr size_t kNumPages = 14; 35 void SetUp() override; 36 void TearDown() override; 37 buf()38 uint8_t* buf() { return const_cast<uint8_t*>(std::as_const(*this).buf()); } buf()39 const uint8_t* buf() const { 40 return reinterpret_cast<const uint8_t*>(buf_->start()); 41 } buf_size()42 size_t buf_size() const { return buf_->size(); } page_size()43 size_t page_size() const { return page_size_; } 44 45 private: 46 size_t page_size_ = 0; 47 48 // This doesn't need any sharing. TestSharedMemory just happens to have the 49 // right harness to create a zeroed page-aligned buffer. 50 std::unique_ptr<TestSharedMemory> buf_; 51 }; 52 53 } // namespace perfetto 54 55 #endif // SRC_TRACING_TEST_ALIGNED_BUFFER_TEST_H_ 56