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 #pragma once
18
19 #include <signal.h>
20 #include <stdint.h>
21 #include <sys/types.h>
22 #include <sys/wait.h>
23
24 namespace unwindstack {
25
26 class TestScopedPidReaper {
27 public:
TestScopedPidReaper(pid_t pid)28 TestScopedPidReaper(pid_t pid) : pid_(pid) {}
~TestScopedPidReaper()29 ~TestScopedPidReaper() {
30 kill(pid_, SIGKILL);
31 waitpid(pid_, nullptr, 0);
32 }
33
34 private:
35 pid_t pid_;
36 };
37
38 void TestCheckForLeaks(void (*unwind_func)(void*), void* data);
39
40 void* GetTestLibHandle();
41
42 // TODO(b/148307629): Once we incorporate google benchmark library into
43 // GoogleTest, we can call benchmark::DoNotOptimize here instead.
44 template <class Tp>
DoNotOptimize(Tp const & value)45 static inline void DoNotOptimize(Tp const& value) {
46 asm volatile("" : : "r,m"(value) : "memory");
47 }
48
49 } // namespace unwindstack
50