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

Commit 263c5e8b authored by Chris Manton's avatar Chris Manton
Browse files

shim: Replace mock do_in_main_thread with a fake

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

Change-Id: Ibe9720b5934806bca2d62055fc50dc20ecac927d
parent 106ac870
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -233,6 +233,7 @@ cc_test {
        "shim/metrics_api.cc",
        "shim/shim.cc",
        "shim/stack.cc",
        "test/common/main_handler.cc",
        "test/common/mock_acl_ble.cc",
        "test/common/mock_acl_btm_pm.cc",
        "test/common/mock_bta_dm_act.cc",
@@ -243,7 +244,6 @@ cc_test {
        "test/common/mock_btm_inq.cc",
        "test/common/mock_btm_main.cc",
        "test/common/mock_btm_sec.cc",
        "test/common/mock_btu_task.cc",
        "test/common/mock_entry.cc",
        "test/common/mock_gatt_main.cc",
        "test/common/mock_hcic_hcicmds.cc",
+63 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 The Android Open Source Project
 * Copyright 2021 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.
@@ -14,57 +14,50 @@
 * limitations under the License.
 */

/*
 * Generated mock file from original source file
 *   Functions generated:7
 */

#include <map>
#include <string>

extern std::map<std::string, int> mock_function_count_map;

#include <base/bind.h>
#include <base/logging.h>
#include <base/run_loop.h>
#include <base/threading/thread.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bta/sys/bta_sys.h"
#include "btcore/include/module.h"
#include "bte.h"
#include "btif/include/btif_common.h"
#include "btm_iso_api.h"
#include <base/callback_forward.h>
#include <base/location.h>
#include <base/time/time.h>
#include <functional>

#include "common/message_loop_thread.h"
#include "include/hardware/bluetooth.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"
#include "stack/include/acl_hci_link_interface.h"
#include "stack/include/btu.h"

#ifndef UNUSED_ATTR
#define UNUSED_ATTR
#endif
using bluetooth::common::MessageLoopThread;
using BtMainClosure = std::function<void()>;

namespace {

MessageLoopThread main_thread("bt_fake_main_thread", true);
void do_post_on_bt_main(BtMainClosure closure) { closure(); }

}  // namespace

bluetooth::common::MessageLoopThread* get_main_thread() {
  mock_function_count_map[__func__]++;
  return nullptr;
}
bt_status_t do_in_main_thread(const base::Location& from_here,
                              base::OnceClosure task) {
  mock_function_count_map[__func__]++;
  ASSERT_LOG(main_thread.DoInThread(from_here, std::move(task)),
             "Unable to run on main thread");
  return BT_STATUS_SUCCESS;
}

bt_status_t do_in_main_thread_delayed(const base::Location& from_here,
                                      base::OnceClosure task,
                                      const base::TimeDelta& delay) {
  mock_function_count_map[__func__]++;
  ASSERT_LOG(!main_thread.DoInThreadDelayed(from_here, std::move(task), delay),
             "Unable to run on main thread delayed");
  return BT_STATUS_SUCCESS;
}
void btu_hci_msg_process(BT_HDR* p_msg) { mock_function_count_map[__func__]++; }
void main_thread_shut_down() { mock_function_count_map[__func__]++; }
void main_thread_start_up() { mock_function_count_map[__func__]++; }
void post_on_bt_main(std::function<void()> closure) {
  mock_function_count_map[__func__]++;

void post_on_bt_main(BtMainClosure closure) {
  ASSERT(do_in_main_thread(FROM_HERE,
                           base::Bind(do_post_on_bt_main, std::move(closure))));
}

void main_thread_start_up() {
  main_thread.StartUp();
  ASSERT_LOG(main_thread.IsRunning(),
             "Unable to start message loop on main thread");
}

void main_thread_shut_down() { main_thread.ShutDown(); }
+36 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 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.
 */

#pragma once

#include <base/callback_forward.h>
#include <base/location.h>
#include <base/time/time.h>
#include <functional>

#include "common/message_loop_thread.h"

using bluetooth::common::MessageLoopThread;
using BtMainClosure = std::function<void()>;

bt_status_t do_in_main_thread(const base::Location& from_here,
                              base::OnceClosure task);
bt_status_t do_in_main_thread_delayed(const base::Location& from_here,
                                      base::OnceClosure task,
                                      const base::TimeDelta& delay);
void post_on_bt_main(BtMainClosure closure);
void main_thread_start_up();
void main_thread_shut_down();