• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_TEST_SHARED_MEMORY_H_
18 #define SRC_TRACING_TEST_TEST_SHARED_MEMORY_H_
19 
20 #include <stddef.h>
21 
22 #include <memory>
23 
24 #include "perfetto/ext/base/paged_memory.h"
25 #include "perfetto/ext/tracing/core/shared_memory.h"
26 
27 namespace perfetto {
28 
29 // A dummy implementation of shared memory for single process unittests
30 // (just a wrapper around malloc() that fits the SharedMemory API).
31 class TestSharedMemory : public SharedMemory {
32  public:
33   class Factory : public SharedMemory::Factory {
34    public:
35     ~Factory() override;
36     std::unique_ptr<SharedMemory> CreateSharedMemory(size_t size) override;
37   };
38 
39   explicit TestSharedMemory(size_t size);
40   ~TestSharedMemory() override;
41 
start()42   void* start() const override { return mem_.Get(); }
size()43   size_t size() const override { return size_; }
44 
45   base::PagedMemory mem_;
46   size_t size_;
47 };
48 
49 }  // namespace perfetto
50 
51 #endif  // SRC_TRACING_TEST_TEST_SHARED_MEMORY_H_
52