

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 为测试设备配置设置
<a name="config-settings-device"></a>

构建、刷写和测试设置在 `configs/userdata.json` 文件中进行。我们通过在 `customPath` 中加载客户端和服务器证书和密钥来支持 Echo 服务器配置。有关更多信息，请参阅《FreeRTOS 移植指南》中的[设置 Echo 服务器](https://docs.amazonaws.cn/freertos/latest/portingguide/afr-echo-server.html)。**以下 JSON 示例显示如何配置适用于 FreeRTOS 的 IDT 来测试多个设备：

```
{
    "sourcePath": "{{/absolute-path-to/freertos}}",
    "vendorPath": "{{testData.sourcePath}}/vendors/{{vendor-name}}/boards/{{board-name}}",
    // ***********The sdkConfiguration block below is needed if you are not using the default, unmodified FreeRTOS repo. 
    // In other words, if you are using the default, unmodified FreeRTOS repo then remove this block***************
    "sdkConfiguration": {
        "name": "{{sdk-name}}",
        "version": "{{sdk-version}}",
        "path": "{{/absolute-path-to/sdk}}"
    },
    "buildTool": {
        "name": "{{your-build-tool-name}}",
        "version": "{{your-build-tool-version}}",
        "command": [
            "{{{{config.idtRootPath}}/relative-path-to/build-parallel.sh}} {{testData.sourcePath}} {{enableTests}}"
        ]
    },
    "flashTool": {
        "name": "{{your-flash-tool-name}}",
        "version": "{{your-flash-tool-version}}",
        "command": [
            "/{{{{config.idtRootPath}}/relative-path-to/flash-parallel.sh}} {{testData.sourcePath}} {{device.connectivity.serialPort}} {{buildImageName}}"
        ],
        "buildImageInfo" : {
            "testsImageName": "{{tests-image-name}}",
            "demosImageName": "{{demos-image-name}}"
        }
    },
    "testStartDelayms": 0,
    "clientWifiConfig": {
        "wifiSSID": "{{ssid}}",
        "wifiPassword": "{{password}}",
        "wifiSecurityType": "eWiFiSecurityOpen | eWiFiSecurityWEP | eWiFiSecurityWPA | eWiFiSecurityWPA2 | eWiFiSecurityWPA3"
    },
    "testWifiConfig": {
        "wifiSSID": "{{ssid}}",
        "wifiPassword": "{{password}}",
        "wifiSecurityType": "eWiFiSecurityOpen | eWiFiSecurityWEP | eWiFiSecurityWPA | eWiFiSecurityWPA2 | eWiFiSecurityWPA3"
    },
    //**********
    //This section is used to start echo server based on server certificate generation method,
    //When certificateGenerationMethod is set as Automatic specify the eccCurveFormat to generate certifcate and key based on curve format,
    //When certificateGenerationMethod is set as Custom specify the certificatePath and PrivateKeyPath to be used to start echo server
    //**********
    "echoServerCertificateConfiguration": {
      "certificateGenerationMethod": "Automatic | Custom",
      "customPath": {
          "clientCertificatePath":"{{/path/to/clientCertificate}}",
          "clientPrivateKeyPath": "{{/path/to/clientPrivateKey}}",
          "serverCertificatePath":"{{/path/to/serverCertificate}}",
          "serverPrivateKeyPath": "{{/path/to/serverPrivateKey}}"
      },
    "eccCurveFormat": "P224 | P256 | P384 | P521"
    },
    "echoServerConfiguration": {
        "securePortForSecureSocket": {{33333}}, // Secure tcp port used by SecureSocket test. Default value is 33333. Ensure that the port configured isn't blocked by the firewall or your corporate network
        "insecurePortForSecureSocket": {{33334}}, // Insecure tcp port used by SecureSocket test. Default value is 33334. Ensure that the port configured isn't blocked by the firewall or your corporate network
        "insecurePortForWiFi": {{33335}} // Insecure tcp port used by Wi-Fi test. Default value is 33335. Ensure that the port configured isn't blocked by the firewall or your corporate network
    },
    "otaConfiguration": {
        "otaFirmwareFilePath": "{{testData.sourcePath}}/{{relative-path-to/ota-image-generated-in-build-process}}",
        "deviceFirmwareFileName": "{{ota-image-name-on-device}}",
        "otaDemoConfigFilePath": "{{testData.sourcePath}}/{{relative-path-to/ota-demo-config-header-file}}",
        "codeSigningConfiguration": {
            "signingMethod": "Amazon | Custom",
            "signerHashingAlgorithm": "SHA1 | SHA256",
            "signerSigningAlgorithm": "RSA | ECDSA",
            "signerCertificate": "arn:{{partition}}:{{service}}:{{region}}:{{account-id}}:{{resource}}:{{qualifier}} | /{{absolute-path-to/signer-certificate-file}}",
            "signerCertificateFileName": "{{signerCertificate-file-name}}",
            "compileSignerCertificate": boolean,
            // ***********Use signerPlatform if you choose aws for signingMethod***************
            "signerPlatform": "AmazonFreeRTOS-Default | AmazonFreeRTOS-TI-CC3220SF",
            "untrustedSignerCertificate": "arn:{{partition}}:{{service}}:{{region}}:{{account-id}}:{{resourcetype}}:{{resource}}:{{qualifier}}",
            // ***********Use signCommand if you choose custom for signingMethod***************
            "signCommand": [
                "/{{absolute-path-to}}/sign.sh {{inputImageFilePath}} {{outputSignatureFilePath}}"
            ]
        }
    },
    // ***********Remove the section below if you're not configuring CMake***************
    "cmakeConfiguration": {
        "boardName": "{{board-name}}",
        "vendorName": "{{vendor-name}}",
        "compilerName": "{{compiler-name}}",
        "frToolchainPath": {{"/path/to/freertos/toolchain}}",
        "cmakeToolchainPath": "{{/path/to/cmake/toolchain}}"
    },
    "freertosFileConfiguration": {
        "required": [
            {
                "configName": "pkcs11Config",
                "filePath": "{{testData.sourcePath}}/vendors/{{vendor-name}}/boards/{{board-name}}/aws_tests/config_files/core_pkcs11_config.h"
            },
            {
                "configName": "pkcs11TestConfig",
                "filePath": "{{testData.sourcePath}}/vendors/{{vendor-name}}/boards/{{board-name}}/aws_tests/config_files/iot_test_pkcs11_config.h"
            }
        ],
        "optional": [
            {
                "configName": "otaAgentTestsConfig",
                "filePath": "{{testData.sourcePath}}/vendors/{{vendor-name}}/boards/{{board-name}}/aws_tests/config_files/ota_config.h"
            },
            {
                "configName": "otaAgentDemosConfig",
                "filePath": "{{testData.sourcePath}}/vendors/{{vendor-name}}/boards/{{board-name}}/aws_demos/config_files/ota_config.h"
            },
            {
                "configName": "otaDemosConfig",
                "filePath": "{{testData.sourcePath}}/vendors/{{vendor-name}}/boards/{{board-name}}/aws_demos/config_files/ota_demo_config.h"
            }
        ]
    }
}
```

下面列出了在 `userdata.json` 中使用的属性：

**`sourcePath`**  
移植的 FreeRTOS 源代码的根目录的路径。对于使用开发工具包的并行测试，可使用 `{{userData.sdkConfiguration.path}}` 占位符对 `sourcePath` 进行设置。例如：  

```
{ "sourcePath":"{{userData.sdkConfiguration.path}}/{{freertos}}" }
```

**`vendorPath`**  
供应商特定 FreeRTOS 代码的路径。对于串行测试，`vendorPath` 可以设置为绝对路径。例如：  

```
{ "vendorPath":"C:/{{path-to-freertos}}/vendors/espressif/boards/{{esp32}}" }
```
对于并行测试，`vendorPath` 可以使用 `{{testData.sourcePath}}` 占位符进行设置。例如：  

```
{ "vendorPath":"{{testData.sourcePath}}/vendors/espressif/boards/esp32" }
```
只有在不使用开发工具包的情况下运行时才需要 `vendorPath` 变量，否则可将其删除。  
在不使用开发工具包的情况下并行运行测试时，`vendorPath`、`buildTool`、`flashTool` 字段中必须使用 `{{testData.sourcePath}}` 占位符。使用单个设备运行测试时，`vendorPath`、`buildTool`、`flashTool` 字段中必须使用绝对路径。使用开发工具包运行时，必须在 `sourcePath`、`buildTool` 和 `flashTool` 命令中使用 `{{sdkPath}}` 占位符。

**`sdkConfiguration`**  
除了移植所需之外，如果您要对 FreeRTOS 的其他文件和文件夹结构的任何修改进行资格认证，则需要在此数据块中配置开发工具包信息。如果您不符合在开发工具包中使用移植的 FreeRTOS 的资格，则应完全省略该数据块。    
**`sdkConfiguration.name`**  
在 FreeRTOS 中使用的开发工具包的名称。如果您没有使用开发工具包，则应省略整个 `sdkConfiguration` 数据块。  
**`sdkConfiguration.version`**  
在 FreeRTOS 中使用的开发工具包的版本。如果您没有使用开发工具包，则应省略整个 `sdkConfiguration` 数据块。  
**`sdkConfiguration.path`**  
包含 FreeRTOS 代码的开发工具包目录的绝对路径。如果您没有使用开发工具包，则应省略整个 `sdkConfiguration` 数据块。

**`buildTool`**  
您的生成脚本（.bat 或 .sh）的完整路径，该脚本包含用于生成源代码的命令。构建命令中对源代码路径的所有引用都必须替换为 Amazon IoT Device Tester 变量`{{testdata.sourcePath}}`，对 SDK 路径的引用应替换为`{{sdkPath}}`。使用 `{{config.idtRootPath}}` 占位符引用绝对或相对 IDT 路径。

**`testStartDelayms`**  
指定 FreeRTOS 测试运行器在开始运行测试之前将等待多少毫秒。如果由于网络或其他延迟，待测试设备在 IDT 有机会连接并开始日志记录之前就开始输出重要的测试信息，这可能很有用。允许的最大值为 30000 毫秒（30 秒）。此值仅适用于 FreeRTOS 测试组，不适用于不使用 FreeRTOS 测试运行器的其他测试组，例如 OTA 测试。

**`flashTool`**  
您的刷入脚本（.sh 或 .bat）的完整路径，该脚本应该包含您设备的刷入命令。在刷写命令中，必须将对源代码路径的所有引用替换为适用于 FreeRTOS 的 IDT 的变量 `{{testdata.sourcePath}}`，并将对开发工具包路径的所有引用替换为适用于 FreeRTOS 的 IDT 变量 `{{sdkPath}}`。使用 `{{config.idtRootPath}}` 占位符引用绝对或相对 IDT路径。    
**`buildImageInfo`**    
**`testsImageName`**  
从 `{{freertos-source}}/tests` 文件夹构建测试时由构建命令生成的文件的名称。  
**`demosImageName`**  
从 `{{freertos-source}}/demos` 文件夹构建测试时由构建命令生成的文件的名称。

**`clientWifiConfig`**  
客户机 Wi-Fi 配置。 Wi-Fi 库测试需要一块 MCU 板来连接两个接入点。（两个接入点可以是相同的。） 此属性配置第一个接入点的 Wi-Fi 设置。一些 Wi-Fi 测试用例希望接入点具有一定的安全性，并且不会处于开放状态。确保两个接入点与运行 IDT 的主机位于同一个子网中。    
**`wifi_ssid`**  
 Wi-Fi SSID。  
**`wifi_password`**  
 Wi-Fi 密码。  
**`wifiSecurityType`**  
使用的 Wi-Fi 安全类型。以下值之一：  
+ `eWiFiSecurityOpen`
+ `eWiFiSecurityWEP`
+ `eWiFiSecurityWPA`
+ `eWiFiSecurityWPA2`
+ `eWiFiSecurityWPA3`
如果您的主板不支持 Wi-Fi，您仍必须在`device.json`文件中包含该`clientWifiConfig`部分，但可以省略这些属性的值。

**`testWifiConfig`**  
测试 Wi-Fi 配置。 Wi-Fi 库测试需要一块 MCU 板来连接两个接入点。（两个接入点可以是相同的。） 此属性配置第二个接入点的 Wi-Fi 设置。一些 Wi-Fi 测试用例希望接入点具有一定的安全性，并且不会处于开放状态。确保两个接入点与运行 IDT 的主机位于同一个子网中。    
**`wifiSSID`**  
 Wi-Fi SSID。  
**`wifiPassword`**  
 Wi-Fi 密码。  
**`wifiSecurityType`**  
使用的 Wi-Fi 安全类型。以下值之一：  
+ `eWiFiSecurityOpen`
+ `eWiFiSecurityWEP`
+ `eWiFiSecurityWPA`
+ `eWiFiSecurityWPA2`
+ `eWiFiSecurityWPA3`
如果您的主板不支持 Wi-Fi，您仍必须在`device.json`文件中包含该`testWifiConfig`部分，但可以省略这些属性的值。

**`echoServerCertificateConfiguration`**  
用于安全套接字测试的可配置 Echo 服务器证书生成占位符。该字段为必填。    
**`certificateGenerationMethod`**  
指定服务器证书是自动生成的，还是手动提供的。  
**`customPath`**  
如果 `certificateGenerationMethod` 为“自定义”，则 `certificatePath` 和 `privateKeyPath` 为必需项。    
**`certificatePath`**  
指定服务器证书的文件路径。  
**`privateKeyPath`**  
指定私有密钥的文件路径。  
**`eccCurveFormat`**  
指定主板支持的曲线格式。在 `device.json` 中将 `PKCS11` 设置为“ECC”时必需。有效值为“P224”、“P256”、“P384”或“P521”。

**`echoServerConfiguration`**  
用于 WiFi 和安全套接字测试的可配置回声服务器端口。该字段是可选的。    
**`securePortForSecureSocket`**  
用于设置使用 TLS 的 Echo 服务器以进行安全套接字测试的端口。默认值是 33333。确保配置的端口未被防火墙或公司网络阻止。  
**`insecurePortForSecureSocket`**  
用于设置不使用 TLS 的 Echo 服务器以进行安全套接字测试的端口。测试中使用的默认值为 33334。确保配置的端口未被防火墙或公司网络阻止。  
**`insecurePortForWiFi`**  
用于设置不带 TLS 的回声服务器进行 WiFi 测试的端口。测试中使用的默认值为 33335。确保配置的端口未被防火墙或公司网络阻止。

**`otaConfiguration`**  
OTA 配置。[可选]    
**`otaFirmwareFilePath`**  
在生成之后，所创建 OTA 映像的完整路径。例如 `{{testData.sourcePath}}/{{relative-path/to/ota/image/from/source/root}}`。  
**`deviceFirmwareFileName`**  
MCU 设备上 OTA 固件所在的完整文件路径。有些设备不使用此字段，但您仍必须提供一个值。  
**`otaDemoConfigFilePath`**  
位于 `{{afr-source}}/vendors/vendor/boards/board/aws_demos/config_files/` 中的 `aws_demo_config.h` 的完整路径。这些文件包含在 FreeRTOS 提供的移植代码模板中。  
**`codeSigningConfiguration`**  
代码签名配置。  
**`signingMethod`**  
代码签名方法。可能的值为 `AWS` 或 `Custom`。  
对于北京和宁夏区域，请使用 `Custom`。这些区域不支持 `AWS` 代码签名。  
**`signerHashingAlgorithm`**  
设备所支持的哈希算法。可能的值为 `SHA1` 或 `SHA256`。  
**`signerSigningAlgorithm`**  
设备所支持的签名算法。可能的值为 `RSA` 或 `ECDSA`。  
**`signerCertificate`**  
用于 OTA 的可信证书。  
对于 Amazon 代码签名方法，请使用上传到的可信证书的 Amazon 资源名称 (ARN)。 Amazon Certificate Manager  
对于自定义代码签名方法，请使用签署人证书文件的绝对路径。  
有关创建可信证书的更多信息，请参阅 [创建代码签名证书](ota-code-sign-cert.md)。  
**`signerCertificateFileName`**  
设备上代码签署证书的文件名。此值必须与您在运行 `aws acm import-certificate` 命令时提供的文件名相匹配。  
有关更多信息，请参阅 [创建代码签名证书](ota-code-sign-cert.md)。  
**`compileSignerCertificate`**  
`true`如果未配置或刷新代码签名者签名验证证书，则设置为，因此必须将其编译到项目中。 Amazon IoT Device Tester 获取可信证书并将其编译为。`aws_codesigner_certifiate.h`  
**`untrustedSignerCertificate`**  
在某些 OTA 测试中用作不可信证书的第二个证书的 ARN 或文件路径。有关创建证书的更多信息，请参阅[创建代码签名证书](https://docs.amazonaws.cn/freertos/latest/userguide/ota-code-sign-cert.html)。  
**`signerPlatform`**  
C Amazon ode Signer 在创建 OTA 更新任务时使用的签名和哈希算法。目前，此字段的可能值为 `AmazonFreeRTOS-TI-CC3220SF` 和 `AmazonFreeRTOS-Default`。  
+ 如果为 `SHA1` 和 `RSA`，则选择 `AmazonFreeRTOS-TI-CC3220SF`。
+ 如果为 `SHA256` 和 `ECDSA`，则选择 `AmazonFreeRTOS-Default`。
如果您的配置需要 `SHA256` \| `RSA` 或 `SHA1` \| `ECDSA`，请与我们联系以获取进一步的支持。  
如果您为 `signingMethod` 选择 `Custom`，则配置 `signCommand`。  
**`signCommand`**  
用于执行自定义代码签名的命令。您可以在 `/configs/script_templates` 目录中找到模板。  
命令中需要两个占位符 `{{inputImageFilePath}}` 和 `{{outputSignatureFilePath}}`。`{{inputImageFilePath}}` 是要签名的由 IDT 构建的映像的文件路径。`{{outputSignatureFilePath}}` 是将由脚本生成的签名的文件路径。

**`cmakeConfiguration`**  
CMake 配置 [可选]  
要执行 CMake 测试案例，您必须提供主板名称、供应商名称和 `frToolchainPath` 或 `compilerName`。如果您的 CMake 工具链使用自定义路径，则还需要提供 `cmakeToolchainPath`。  
**`boardName`**  
要测试的主板的名称。主板名称应该与 `{{path/to/afr/source/code}}/vendors/{{vendor}}/boards/{{board}}` 下的文件夹名称相同。  
**`vendorName`**  
所测试主板的供应商的名称。供应商名称应该与 `{{path/to/afr/source/code}}/vendors/{{vendor}}` 下的文件夹名称相同。  
**`compilerName`**  
编译器名称。  
**`frToolchainPath`**  
编译器工具链的全限定路径  
**`cmakeToolchainPath` **  
CMake 工具链的全限定路径。此字段为可选项

**`freertosFileConfiguration`**  
IDT 在运行测试之前修改的 FreeRTOS 文件的配置。    
**`required`**  
本节指定了您已移动其配置文件的必需测试，例如 PKCS11、TLS 等。    
**`configName`**  
正在配置的组件的名称。  
**`filePath`**  
`{{freertos}}` 存储库中配置文件的绝对路径。使用 `{{testData.sourcePath}}` 变量来定义路径。  
**`optional`**  
本节指定了您已移动其配置文件的可选测试 WiFi，例如 OTA 等。    
**`configName`**  
正在配置的组件的名称。  
**`filePath`**  
`{{freertos}}` 存储库中配置文件的绝对路径。使用 `{{testData.sourcePath}}` 变量来定义路径。

**注意**  
要执行 CMake 测试案例，您必须提供主板名称、供应商名称和 `afrToolchainPath` 或 `compilerName`。如果您的 CMake 工具链使用自定义路径，则还需要提供 `cmakeToolchainPath`。