Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4c384ec8 authored by Chris Manton's avatar Chris Manton
Browse files

flatbuffers: Add dumpsys filter test

Bug: 216499488
Tag: #refactor
Test: gd/cert/run
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Change-Id: I63d0cfd99b447f2b7bef07111ebe0f4eb3585545
parent c9e3ca8e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -230,6 +230,7 @@ cc_test {
        ":TestMockLegacyHciInterface",
        ":TestMockMainShimEntry",
        ":TestMockStack",
        ":BluetoothOsSources_host",
        "shim/acl_api.cc",
        "shim/acl.cc",
        "shim/acl_legacy_interface.cc",
@@ -248,6 +249,7 @@ cc_test {
        "shim/shim.cc",
        "shim/stack.cc",
        "test/common_stack_test.cc",
        "test/main_shim_dumpsys_test.cc",
        "test/main_shim_test.cc",
    ],
    static_libs: [
+81 −0
Original line number Diff line number Diff line
/*
 *  Copyright 2022 The Android Open Source Project
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <unistd.h>

#include <future>

#include "common/init_flags.h"
#include "module.h"
#include "os/handler.h"
#include "os/system_properties.h"
#include "os/thread.h"
#include "shim/dumpsys.h"
#include "stack_manager.h"
#include "storage/storage_module.h"

using namespace bluetooth;
using namespace testing;

namespace {

constexpr char kTrue[] = "1";
constexpr char kFalse[] = "0";
constexpr char kReadOnlyDebuggableProperty[] = "ro.debuggable";

}  // namespace

class MainShimDumpsysTest : public testing::Test {
 public:
 protected:
  void SetUp() override {
    bluetooth::common::InitFlags::SetAllForTesting();

    ModuleList modules;
    modules.add<shim::Dumpsys>();
    modules.add<storage::StorageModule>();

    os::Thread* thread = new os::Thread("thread", os::Thread::Priority::NORMAL);
    stack_manager_.StartUp(&modules, thread);
  }
  void TearDown() override { stack_manager_.ShutDown(); }
  StackManager stack_manager_;

  os::Thread* thread_{nullptr};
  os::Handler* handler_{nullptr};
};

TEST_F(MainShimDumpsysTest, dumpsys_developer) {
  ASSERT_TRUE(os::SetSystemProperty(kReadOnlyDebuggableProperty, kTrue));

  std::promise<void> promise;
  auto future = promise.get_future();
  stack_manager_.GetInstance<shim::Dumpsys>()->Dump(STDOUT_FILENO, nullptr,
                                                    std::move(promise));
  future.get();
}

TEST_F(MainShimDumpsysTest, dumpsys_user) {
  ASSERT_TRUE(os::SetSystemProperty(kReadOnlyDebuggableProperty, kFalse));

  std::promise<void> promise;
  auto future = promise.get_future();
  stack_manager_.GetInstance<shim::Dumpsys>()->Dump(STDOUT_FILENO, nullptr,
                                                    std::move(promise));
  future.get();
}