2025 年 3 月 27 日より、AOSP のビルドとコントリビューションには aosp-main
ではなく android-latest-release
を使用することをおすすめします。詳細については、AOSP の変更をご覧ください。
グローバル設定でプロトコルを読み込む
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
このセクションを理解するには、まず Tradefed @Option をご覧ください。
Tradefed の一般的なオプションでは、テストクラスは XML 設定やコマンドラインから追加情報を取得できます。この機能を使用すると、さらに進んで、必要に応じてこの追加情報を解決できるようになります。
ファイル オプションの例
ファイル @option の例
@Option(name = 'config-file')
private File mConfigFile;
上記は XML 構成を通じて設定できます。
<option name="config-file" value="/tmp/file" />
またはコマンドを使用することもできます。
--config-file /tmp/file
説明
この機能を使用すると、リモートのファイルタイプの @Option をローカル ファイルに解決して、ユーザー側からシームレスに使用できるようになります。
これを行うには、ファイルをリモート スタイル パスで指定する必要があります。次に例を示します。
--config-file gs://bucket/tmp/file
このパスは、保存先の Google Cloud Storage(GCS)バケット内のファイルを指します。Tradefed はリモートパスを参照して、ファイルのローカルへのダウンロードと @Option への割り当てを試行します。これで mConfigFile
変数がローカル バージョンのファイルを指定し、テストで使用できるようになります。
リモート ファイルがなんらかの理由でダウンロードできない場合、Tradefed は ConfigurationException
をスローし、テストの実行を回避します。ファイルが欠落すると、テストのアーティファクトも欠落することになるので、重大な失敗と見なされます。
クエリ パラメータを使用する
URL にクエリ パラメータを追加するには、?
を使用します。たとえば、gs://bucket/path?unzip=true
のように使用します。Key-Value の unzip=true
は IRemoteFileResolver インターフェースの実装で利用可能です。
組み込み動作には次の 2 つがあります。
- unzip:
true
に設定され、ダウンロードしたファイルが zip の場合、一時的な場所に自動的に解凍されます。例: ?unzip=true
- optional: デフォルトは
false
です。true
に設定しても解決しなかった場合、例外はスローされず、ファイルは置き換えられません。例: ?optional=true
--dynamic-download-args key=value
を使用してグローバル クエリ引数を渡すことができます。これは、呼び出しの際に試行されたすべての動的ダウンロードに Key-Value を渡します。
サポートされているプロトコル
正式にサポートされているプロトコルと、それに対応する形式は次のとおりです。
- Google Cloud Storage、プロトコル:
gs
、形式: gs://<bucket name>/path
- ローカル ファイル、プロトコル:
file
、形式: file:/local/path
- http リンク、プロトコル:
http
、形式: http://url
- https リンク、プロトコル:
https
、形式: https://url
制限事項
現在のところ、@Option の動的解決でサポートされるプロトコルとダウンロードの場所は限られています。@Option の解決は現在、メインの XML Tradefed 構成に対してのみ有効です。
スイートとして実行している場合、現在のモジュール(AndroidTest.xml
)はデフォルトではファイルを解決しません。これは、モジュールが未知の依存関係を生成しないようにするためです。スイートレベルで --enable-module-dynamic-download
を使用するとこの問題をエスケープできますが、互換性テストスイート(CTS)やベンダー テスト スイート(VTS)のようなメジャーなスイートでは有効になりません。
新しいプロトコルを実装する
サポートされているプロトコルは、IRemoteFileResolver インターフェースの Tradefed に実装できます。これにより、getSupportedProtocol
を使用して、ファイルパスで照合されるプロトコルの短いタグが定義されます。たとえば、gs
は Google Cloud Storage プロトコルで使用されます。実装するインターフェースとして推奨されるのは、長期的なメンテナンス インターフェースである #resolveRemoteFiles(RemoteFileResolverArgs)
です。
実装されたプロトコルをハーネス META-INF サービス ファイルに追加すると、サポートを正式に有効化できます。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-03-26 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-03-26 UTC。"],[],[],null,["# Load protocols with global config\n\nIn order to understand this section, first study the Tradefed\n[@Option](/docs/core/tests/tradefed/fundamentals/options).\n\nTypical options in Tradefed allow for test classes to receive additional\ninformation from the XML configuration or command line. This feature allows you\nto go one extra step and resolve some of this additional information if\nnecessary.\n\nFile option example\n-------------------\n\nExample File @option: \n\n @Option(name = 'config-file')\n private File mConfigFile;\n\nThe above can be set via XML configuration: \n\n \u003coption name=\"config-file\" value=\"/tmp/file\" /\u003e\n\nor via command: \n\n --config-file /tmp/file\n\nDescription\n-----------\n\nThe feature allows you to resolve File-typed @Options that are remote into a\nlocal file to be available seamlessly from a user standpoint.\n\nFor this to work, the file needs to be specified with a *remote style path*. For\nexample: \n\n --config-file gs://bucket/tmp/file\n\nThis path points to a file within a Google Cloud Storage (GCS) bucket where it's\nstored. Tradefed upon seeing that remote path, will attempt to download the file\nlocally and assign it to the @Option. This results in the `mConfigFile` variable\nto now point to the local version of the file, which can be used by the test.\n\nIf the remote file cannot be downloaded for any reason, Tradefed will throw a\n`ConfigurationException` that will prevent the test from running. We consider\nmissing those files a critical failure since some test artifacts will also be\nmissing.\n\nUse query parameters\n--------------------\n\nAdding query parameters to a URL is possible using `?`. For example,\n`gs://bucket/path?unzip=true`. The key/value `unzip=true` will be available in\nthe [IRemoteFileResolver\ninterface](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/src/com/android/tradefed/config/remote/IRemoteFileResolver.java)\nimplementation.\n\nTwo built-in behaviors are available:\n\n- unzip: If set to `true` and the downloaded file is a zip, it will be automatically unzipped to a temporary location. Example: `?unzip=true`\n- optional: Defaults to `false`. If set to `true` and the resolution fails, it won't throw an exception and will simply not replace the file. Example: `?optional=true`\n\nYou can also pass global query arguments via `--dynamic-download-args key=value`\nthat will pass the key/value to all the dynamic downloads attempted in the\ninvocation.\n\nSupported protocols\n-------------------\n\nThe officially supported protocols and their corresponding formats are:\n\n- Google Cloud Storage, protocol: `gs`, format: `gs://\u003cbucket name\u003e/path`\n- Local files, protocol: `file`, format: `file:/local/path`\n- http links, protocol: `http`, format: `http://url`\n- https links, protocol: `https`, format: `https://url`\n\nLimitations\n-----------\n\nThe dynamic resolution of @Option currently supports only a limited number of\nprotocols and locations to download from. The resolution of @Option is currently\nenabled only for the main XML Tradefed configuration.\n\nIf running as a suite, current modules (`AndroidTest.xml`) will not resolve the\nfiles by default.\n*This is meant to prevent modules from creating some unknown dependencies* . This\ncan be escaped by using `--enable-module-dynamic-download` at the suite level,\nbut major suites such as the [Compatibility Test Suite\n(CTS)](/docs/compatibility/cts) and [Vendor Test Suite\n(VTS)](/docs/compatibility/vts) will not enable it.\n\nImplement a new protocol\n------------------------\n\nThe protocols that are supported have an implementation in Tradefed of the\n[IRemoteFileResolver\ninterface](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/src/com/android/tradefed/config/remote/IRemoteFileResolver.java)\n,which defines the short tag of the protocol that will be matched in the\nfile path through `getSupportedProtocol`. For example, `gs` is used for the\nGoogle Cloud Storage protocol. The recommended interface to implement is\n`#resolveRemoteFiles(RemoteFileResolverArgs)` which will be the long-term\nmaintained interface.\n\nThe protocols implemented can be added to [the harness META-INF\nservices](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/res/META-INF/services/com.android.tradefed.config.remote.IRemoteFileResolver)\nfile to officially turn on the support."]]