blob: f5bcffed853b295d9273229a7770aa73ccd2c126 [file] [log] [blame]
<html devsite><head>
<meta name="book_path" value="/_book.yaml"/>
<meta name="project_path" value="/_project.yaml"/>
</head>
<body>
<!--
Copyright 2018 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.
-->
<h1 id="native_tests" class="page-title">原生测试</h1>
<p>平台的原生测试通常会访问较低级别的 HAL,或针对各种系统服务执行原始 IPC。因此,测试方法通常与接受测试的服务密切相关。</p>
<p>请使用 <a href="https://github.com/google/googletest" class="external">gtest</a> 框架编译原生测试。这是与持续测试基础架构集成的先决条件。</p>
<h2 id="examples">示例</h2>
<p>以下是平台源代码中原生测试的一些示例:</p>
<ul>
<li><a href="https://android.googlesource.com/platform/frameworks/av/+/master/camera/tests/">frameworks/av/camera/tests</a></li>
<li><a href="https://android.googlesource.com/platform/frameworks/native/+/master/libs/gui/tests/">frameworks/native/libs/gui/tests</a></li>
</ul>
<h2 id="summary_of_steps">步骤总结</h2>
<ol>
<li>参阅示例原生测试模块设置,位于:<a href="https://android.googlesource.com/platform/frameworks/base/+/master/libs/hwui/tests/unit/">frameworks/base/libs/hwui/tests/unit/</a></li>
<li>测试模块配置应使用 <code>BUILD_NATIVE_TEST</code> 编译规则,以便自动包含 gtest 依赖项</li>
<li>编写测试配置。请参阅<a href="/compatibility/tests/development/blueprints">简单配置</a>选项和<a href="/compatibility/tests/development/test-config">复杂配置</a>选项。</li>
<li><p>使用 <code>mmm</code><code>mma</code>(取决于它是增量编译还是完整编译)编译测试模块,例如:</p>
<pre class="prettyprint lang-shell"><code>make hwui_unit_tests -j
</code></pre></li>
<li><p>使用 <a href="/compatibility/tests/development/atest">Atest</a> 在本地运行测试:</p>
<pre class="prettyprint"><code>atest hwui_unit_tests
</code></pre></li>
<li><p>使用 Trade Federation 自动化测试框架运行测试:</p>
<pre class="prettyprint"><code>make tradefed-all -j
tradefed.sh run template/local_min --template:map test=hwui_unit_tests
</code></pre></li>
<li><p>手动安装并运行:</p>
<ol>
<li><p>将生成的测试二进制文件推送到设备:</p>
<pre class="prettyprint lang-shell"><code>adb push ${OUT}/data/nativetest/hwui_unit_tests/hwui_unit_tests \
/data/nativetest/hwui_unit_tests/hwui_unit_tests
</code></pre></li>
<li><p>通过在设备上调用测试二进制文件执行测试:</p>
<pre class="prettyprint lang-shell"><code>adb shell /data/nativetest/hwui_unit_tests/hwui_unit_tests
</code></pre></li>
</ol>
<p>这样将启动原生测试。您还可以将 <code>--help</code> 参数添加到测试二进制文件,以详细了解自定义测试执行的不同方式。最后,请参阅 <a href="https://github.com/google/googletest/blob/master/googletest/docs/advanced.md">gtest 高级指南</a>,以了解更多参数及其用法。</p></li>
</ol>
</body></html>