blob: bb845fd209972666b0d4d84df0be31983ca40d81 [file] [log] [blame]
<html devsite><head>
<title>验证和调试</title>
<meta name="project_path" value="/_project.yaml"/>
<meta name="book_path" value="/_book.yaml"/>
</head>
<body>
<!--
Copyright 2017 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.
-->
<p>要验证和调试蓝牙堆栈,请使用 AOSP 中提供的工具以及蓝牙技术联盟 (SIG) 的测试。</p>
<h2 id="testing-and-verifying">测试和验证</h2>
<p>为了测试蓝牙堆栈,AOSP 提供了一系列单元测试、CTS 测试,以及旨在辅助 Bluetooth Profile Tuning Suite 的工具。</p>
<h3 id="unit-tests-in-aosp">AOSP 中的单元测试</h3>
<p>AOSP 包括针对默认蓝牙堆栈的功能测试和单元测试。这些测试位于 <code><a href="https://android.googlesource.com/platform/system/bt/+/master/test/">
system/bt/test</a></code> 中。要运行 AOSP 测试,请执行以下操作:</p>
<ol>
<li>停止 Android 运行时:
<pre class="devsite-terminal devsite-click-to-copy">adb shell stop</pre></li>
<li>从测试目录中运行 shell 可执行文件,如果要运行特定测试或测试套件,请包含相应选项:
<pre class="devsite-terminal devsite-click-to-copy">./run_unit_tests.sh <var>TEST_GROUP_NAME</var> <var>TEST_NAME</var> <var>OPTIONS</var></pre></li>
<li>测试完成后,重新启用 Android 运行时:
<pre class="devsite-terminal devsite-click-to-copy">adb shell start</pre></li>
</ol>
<p>测试名称列表位于以下文件中:<code><a href="https://android.googlesource.com/platform/system/bt/+/master/test/run_unit_tests.sh">
system/bt/test/run_unit_tests.sh</a></code></p>
<h3 id="android-comms-test-suite">Android 通讯测试套件</h3>
<p>Android 通讯测试套件 (ACTS) 用于执行对连接堆栈(例如 WLAN、蓝牙和移动网络服务)的自动测试。该测试工具需要 adb 和 python,您可以在以下位置找到它:<code><a href="https://android.googlesource.com/platform/tools/test/connectivity/+/master/acts">
tools/test/connectivity/acts</a></code></p>
<p>针对蓝牙和蓝牙低功耗的 ACTS 测试分别位于以下位置:<code><a href="https://android.googlesource.com/platform/tools/test/connectivity/+/master/acts/tests/google/bt/">
tools/test/connectivity/acts/tests/google/bt</a></code><code><a href="https://android.googlesource.com/platform/tools/test/connectivity/+/master/acts/tests/google/ble">
tools/test/connectivity/acts/tests/google/ble</a></code></p>
<h3 id="profile-tuning-suite">Profile Tuning Suite</h3>
<p>Bluetooth SIG 提供了 Bluetooth Profile Tuning Suite (PTS),这是一种用于测试协议和配置文件互操作性的工具。如需更多信息,请访问 <a href="https://www.bluetooth.com/develop-with-bluetooth/test-tools/profile-tuning-suite">Bluetooth Profile Tuning Suite</a> 网站。</p>
<p>AOSP 提供了额外的工具来辅助 Bluetooth PTS。这些工具位于以下位置:<code><a href="https://android.googlesource.com/platform/tools/test/connectivity/+/master/acts/tests/google/bt/pts/">
tools/test/connectivity/acts/tests/google/bt/pts</a></code></p>
<h3 id="cts-tests">CTS 测试</h3>
<p>
<a href="/compatibility/cts/">兼容性测试套件</a> (CTS) 包括针对蓝牙堆栈的测试。这些测试位于以下位置:<code><a href="https://android.googlesource.com/platform/cts/+/master/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth/">
cts/apps/CtsVerifier/src/com/android/cts/verifier/bluetooth</a></code>
</p>
<h2 id="debugging-options">调试选项</h2>
<p>AOSP 提供了多种调试设备蓝牙堆栈的方法,其中包括日志和错误报告。这些方法可能不适用于无法再现的问题或可能受平台和设备的多个部分影响的音频问题。
</p>
<h3 id="debugging-with-bug-reports">使用错误报告进行调试</h3>
<p>要使用 <code>dumpsys</code> 检查蓝牙服务状态,请使用以下命令:</p>
<pre class="devsite-terminal devsite-click-to-copy">adb shell dumpsys bluetooth_manager</pre>
<p>默认情况下,所有日志消息的跟踪级别均为 2。要了解有关日志记录级别的更多信息,以及要更改不同配置文件的日志记录级别,请查看 <code><a href="https://android.googlesource.com/platform/system/bt/+/master/conf/bt_stack.conf">
system/bt/conf/bt_stack.conf</a></code></p>
<p>要从错误报告中提取信息收集日志,请使用 <code>btsnooz</code> 脚本。</p>
<ol>
<li>获取 <code><a href="https://android.googlesource.com/platform/system/bt/+/master/tools/scripts/btsnooz.py">
btsnooz.py</a></code></li>
<li>提取错误报告的文本版本。</li>
<li>对错误报告的文本版本运行 <code>btsnooz.py</code>
<pre class="devsite-terminal devsite-click-to-copy">btsnooz.py <em>BUG_REPORT</em>.txt &gt; <em>BTSNOOP</em>.log</pre>
</li>
</ol>
<h3 id="debugging-with-logs">使用日志进行调试</h3>
<p>在 Android 4.4 及更高版本中,您可以手动收集 BTSnoop 日志(类似于 RFC 1761 中的信息收集格式)。这些日志可捕获主机控制器接口 (HCI) 数据包。对于大多数 Android 设备,这些日志都存储在 <code>data/misc/bluetooth/logs</code> 中。</p>
<p>出于保护隐私方面的考虑,始终处于开启状态且位于“内存中”的 BTSnoop 仅会记录非个人信息和事件。要记录所有数据,用户需要通过执行以下操作来启用蓝牙 HCI 信息收集:</p>
<ol>
<li>启用设备上的<strong>开发者选项</strong></li>
<li><strong>开发者选项</strong>菜单中,打开<strong>启用蓝牙 HCI 信息收集日志</strong>开关。</li>
<li>重新启动蓝牙以使日志记录功能生效。</li>
</ol>
</body></html>