1 /*
2 * Copyright 2022 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 <gmock/gmock.h>
18 #include <gtest/gtest.h>
19 #include <unistd.h>
20
21 #include <future>
22
23 #include "module.h"
24 #include "os/handler.h"
25 #include "os/system_properties.h"
26 #include "os/thread.h"
27 #include "shim/dumpsys.h"
28 #include "stack_manager.h"
29
30 using namespace bluetooth;
31 using namespace testing;
32
33 class MainShimDumpsysTest : public testing::Test {
34 public:
35 protected:
SetUp()36 void SetUp() override {
37 ModuleList modules;
38 modules.add<shim::Dumpsys>();
39
40 os::Thread* thread = new os::Thread("thread", os::Thread::Priority::NORMAL);
41 stack_manager_.StartUp(&modules, thread);
42 }
TearDown()43 void TearDown() override { stack_manager_.ShutDown(); }
44 StackManager stack_manager_;
45
46 os::Thread* thread_{nullptr};
47 os::Handler* handler_{nullptr};
48 };
49
TEST_F(MainShimDumpsysTest,dumpsys)50 TEST_F(MainShimDumpsysTest, dumpsys) {
51 std::promise<void> promise;
52 auto future = promise.get_future();
53 stack_manager_.GetInstance<shim::Dumpsys>()->Dump(STDOUT_FILENO, nullptr, std::move(promise));
54 future.get();
55 }
56