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