| <html devsite><head> |
| <title>CTS 开发</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. |
| --> |
| |
| <h2 id="initializing-your-repo-client">初始化您的 Repo 客户端</h2> |
| <p>请按照<a href="/setup/downloading.html">相关说明</a>进行操作以获取并编译 Android 源代码,但在发出 <code>repo |
| init</code> 命令时,应指定一个特定的 CTS 分支名称,例如 <code>-b android-5.0_r2</code>。这可确保您的 CTS 更改将包含在下一个及后续 CTS 版本中。</p> |
| |
| <h2 id="building-and-running-cts">构建和运行 CTS</h2> |
| |
| <p>执行以下命令以构建 CTS 并启动交互式 CTS 控制台:</p> |
| <p class="note"><strong>注意</strong>:您可以为 <code>TARGET_PRODUCT</code> 提供其他值,以针对 <code>aosp_x86_64</code> 或 <code>aosp_mips</code> 这两种不同架构进行编译:</p> |
| <pre class="devsite-click-to-copy"> |
| <code class="devsite-terminal">cd <em>/path/to/android/root</em></code> |
| <code class="devsite-terminal">make cts -j32 TARGET_PRODUCT=aosp_arm64</code> |
| <code class="devsite-terminal">cts-tradefed</code> |
| </pre> |
| |
| <p>例如,在 cts-tf 控制台中,输入:</p> |
| <pre class="devsite-click-to-copy"> |
| tf> run cts --plan CTS |
| </pre> |
| |
| <h2 id="writing-cts-tests">编写 CTS 测试</h2> |
| |
| <p>CTS 测试使用 JUnit 和 Android 测试 API。请查看<a href="https://developer.android.com/tools/testing/testing_android.html">测试和插桩</a>教程,同时查看 <code>cts/tests</code> 目录下的现有测试。您会发现 CTS 测试大部分情况下都遵循其他 Android 测试中使用的相同规范。</p> |
| |
| <p>由于 CTS 会在多种正式版设备上运行,因此测试必须遵循以下规则:</p> |
| <ul> |
| <li>必须考虑到不同的屏幕尺寸、屏幕方向和键盘布局。</li> |
| <li>只能使用公共 API 方法。也就是说,避免使用用“隐藏”注释进行注释的所有类、方法和字段。</li> |
| <li>避免依赖于特定视图布局,或者依靠可能不在某些设备上提供的某些大小的资源。</li> |
| <li>请勿依赖根权限。</li> |
| </ul> |
| |
| <h3 id="test-naming-and-location">测试命名和位置</h3> |
| |
| <p> 大多数 CTS 测试用例都针对 Android API 中的特定类。这些测试具有以 <code>cts</code> 为后缀的 Java 软件包名称和以 <code>Test</code> 为后缀的类名称。每个测试用例包含多个测试,其中每个测试通常会对所测试的类采用特定方法。这些测试被安排在一个目录结构中且分为不同的类别,例如“微件”和“视图”。</p> |
| |
| <p> |
| 例如,用于 Java 软件包 <code>android.widget.TextView</code> 的 CTS 测试为 <code>android.widget.cts.TextViewTest</code>,其 Java 软件包名称为 <code>android.widget.cts</code>,其类名称为 <code>TextViewTest</code>。</p> |
| |
| <ul> |
| <li><strong>Java 软件包名称</strong><br />CTS 测试的 Java 软件包名称是所测试的类的软件包名称,后跟“.cts”。 |
| 对于我们的示例来说,软件包名称为 <code>android.widget.cts</code>。 |
| |
| </li><li><strong>类名称</strong><br />CTS 测试的类名称是所测试的类<strong></strong>名称加上“Test”(例如,如果测试以 <code>TextView</code> 为目标,则类名称应为 <code>TextViewTest</code>)。 |
| |
| </li><li><strong>模块名称(仅 CTS v2)</strong><br />CTS v2 按模块对测试进行整理。 |
| 模块名称通常是 Java 软件包名称的第二个字符串(在我们的示例中为 <code>widget</code>)(尽管并不一定非要这样)。</li> |
| </ul> |
| |
| <p>目录结构和示例代码取决于您使用的是 CTS v1 还是 CTS v2。 |
| </p> |
| <h4 id="cts-v1">CTS v1</h4> |
| <p>对于 Android 6.0 及更早版本,请使用 CTS v1。对于 CTS v1,示例代码位于 <code>cts/tests/tests/example</code> 下。 |
| </p> |
| <p>CTS v1 测试中的目录结构如下所示:</p> |
| <pre class="devsite-click-to-copy"> |
| cts/ |
| tests/ |
| tests/ |
| <em>package-name</em>/ |
| Android.mk |
| AndroidManifest.xml |
| src/ |
| android/ |
| <em>package-name</em>/ |
| SampleDeviceActivity.java |
| cts/ |
| SampleDeviceTest.java |
| </pre> |
| <h4 id="cts-v2">CTS v2</h4> |
| <p>对于 Android 7.0 及更高版本,请使用 CTS v2。有关详情,请参阅 <a href="https://android.googlesource.com/platform/cts/+/master/tests/sample/">AOSP 中的示例测试</a>。</p> |
| <p>CTS v2 目录结构如下所示:</p> |
| |
| <pre class="devsite-click-to-copy"> |
| cts/ |
| tests/ |
| <em>module-name</em>/ |
| Android.mk |
| AndroidManifest.xml |
| src/ |
| android/ |
| <em>package-name</em>/ |
| SampleDeviceActivity.java |
| cts/ |
| SampleDeviceTest.java |
| </pre> |
| |
| <h3 id="new-sample-packages">新建示例软件包</h3> |
| |
| <p>添加新测试时,可能没有现有目录用来放置测试。在这种情况下,您需要创建目录并复制相应的示例文件。</p> |
| |
| <h4 id="cts-v1">CTS v1</h4> |
| |
| <p> 如果您使用的是 CTS v1,请参阅 <code>cts/tests/tests/example</code> 下的示例并创建一个新目录。另外,请确保从其 <code>Android.mk</code> 中将新软件包的模块名称添加到 <code>cts/CtsTestCaseList.mk</code> 中的 <code>CTS_COVERAGE_TEST_CASE_LIST</code>。该 Makefile 由 <code>build/core/tasks/cts.mk</code> 用来将所有测试组合在一起,以创建最终 CTS 软件包。</p> |
| |
| <h4 id="cts-v2">CTS v2</h4> |
| <p> |
| 按照下列步骤使用示例测试 <code><a href="https://android.googlesource.com/platform/cts/+/master/tests/sample/">/cts/tests/sample/</a></code> 快速启动新的测试模块: |
| </p> |
| |
| <ol> |
| <li>运行以下命令来创建测试目录并将示例文件复制到该目录: |
| <pre class="devsite-terminal devsite-click-to-copy">mkdir cts/tests/<i>module-name</i> && cp -r cts/tests/sample/* cts/tests/<i>module-name</i></pre> |
| </li><li>转到 <code>cts/tests/<em>module-name</em></code>,然后按照上述建议的命名规范替换掉出现的所有“[Ss]ample”。 |
| </li><li>更新 <code>SampleDeviceActivity</code> 以运行您要测试的功能。 |
| </li><li>更新 <code>SampleDeviceTest</code> 以确保相关测试成功或记录错误日志。</li> |
| </ol> |
| |
| <h4>其他目录</h4> |
| |
| <p> 此外,您还可以添加其他 Android 目录,如 <code>assets</code>、<code>jni</code>、<code>libs</code> 和 <code>res</code>。要添加 JNI 代码,请在项目根目录下的 <code>src</code> 旁创建一个目录,并将原生代码和 <code>Android.mk</code> 包含在其中。</p> |
| |
| <p>Makefile 通常包含以下设置:</p> |
| <pre class="devsite-click-to-copy"> |
| LOCAL_PATH := $(call my-dir) |
| include $(CLEAR_VARS) |
| LOCAL_MODULE := libCtsSample_jni |
| |
| # don't include this package in any target |
| LOCAL_MODULE_TAGS := optional |
| LOCAL_SRC_FILES := <i>list of source code files</i> |
| LOCAL_C_INCLUDES := $(JNI_H_INCLUDE) |
| |
| # Tag this module as a cts test artifact |
| LOCAL_COMPATIBILITY_SUITE := cts |
| LOCAL_SHARED_LIBRARIES := libnativehelper |
| LOCAL_SDK_VERSION := current |
| include $(BUILD_SHARED_LIBRARY) |
| </pre> |
| |
| <h4>Android.mk 文件</h4> |
| |
| <p> 最后,需要修改项目根目录下的 <code>Android.mk</code> 文件,以编译原生代码并依赖于该代码,如下所示:</p> |
| |
| <pre class="devsite-click-to-copy"> |
| # All tests should include android.test.runner. |
| LOCAL_JAVA_LIBRARIES := android.test.runner |
| |
| # Includes the jni code as a shared library |
| LOCAL_JNI_SHARED_LIBRARIES := libCtsSample_jni |
| |
| # Include for InstrumentationCtsTestRunner |
| LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner... |
| LOCAL_SDK_VERSION := currentinclude $(BUILD_CTS_PACKAGE) |
| |
| #Tells make to look in subdirectories for more make files to include |
| include $(call all-makefiles-under,$(LOCAL_PATH)) |
| </pre> |
| |
| <h2 id="Fix-remove-tests">修复或移除测试</h2> |
| <p>除了添加新测试外,还可以通过其他方法为 CTS 做出贡献:修复或移除具有“BrokenTest”或“KnownFailure”注释的测试。</p> |
| |
| <h2 id="submitting-your-changes">提交您的更改</h2> |
| <p>按照<a href="/setup/submit-patches.html">提交补丁程序工作流程</a>向 CTS 贡献更改。系统会为您的更改分配审核者,您的更改很快即会得到审核!</p> |
| |
| <h2 id="release-schedule">版本发布时间表和分支信息</h2> |
| |
| <p>CTS 版本发布遵循以下时间表。</p> |
| |
| <p class="note"><strong>注意</strong>:该时间表是暂定的,可能会随着给定 Android 版本 CTS 的正式发布而不时更新。</p> |
| |
| <table> |
| <thead> |
| <tr> |
| <th>版本</th> |
| <th>分支</th> |
| <th>频率</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td>9</td> |
| <td>pie-cts-dev</td> |
| <td>每月</td> |
| </tr> |
| <tr> |
| <td>8.1</td> |
| <td>oreo-mr1-cts-dev</td> |
| <td>每月</td> |
| </tr> |
| <tr> |
| <td>8.0</td> |
| <td>oreo-cts-dev</td> |
| <td>每月</td> |
| </tr> |
| <tr> |
| <td>7.1</td> |
| <td>nougat-mr1-cts-dev</td> |
| <td>每月</td> |
| </tr> |
| <tr> |
| <td>7.0</td> |
| <td>nougat-cts-dev</td> |
| <td>每月</td> |
| </tr> |
| |
| <tr> |
| <td colspan="3">对于 6.0、5.1、5.0、4.4、4.3 和 4.2,尚无对应的版本发布计划。</td> |
| </tr> |
| </tbody></table> |
| |
| <h3 id="important-dates">版本发布当月的重要日期</h3> |
| |
| <ul> |
| <li><strong>第一周的周末</strong>:代码冻结。此时,不再接受与当前分支有关的提交内容,并且提交内容不会包含在下一版本的 CTS 中。我们选择了候选版本后,分支将再次开放并接受新的提交内容。 |
| |
| </li><li><strong>第二周或第三周</strong>:在 Android 开放源代码项目 (AOSP) 中发布 CTS。 |
| </li></ul> |
| |
| <h3 id="auto-merge">自动合并流程</h3> |
| |
| <p>CTS 开发分支已设置,因此提交到每个分支的更改将自动合并,如下所示:<br /> |
| nougat-cts-dev -> nougat-mr1-cts-dev -> oreo-cts-dev -> oreo-mr1-cts-dev -> pie-cts-dev -> <private-development-branch for Android Q></p> |
| |
| <p>如果变更列表 (CL) 未能正确合并,CL 的作者将收到一封电子邮件,其中包含有关如何解决冲突的说明。在大多数情况下,CL 作者可以通过这些说明来跳过存在冲突的 CL 的自动合并流程。</p> |
| |
| <p>此外,如果较旧的分支需要更改,则需要从较新的分支挑选 CL。</p> |
| |
| </body></html> |