IoT Edge is written in C# and Rust. The C# development setup is described below. The Rust development setup is described here.
If you want to run tests outside of the pipelines, you will need to be running linux.
Make sure the following dependencies are installed in your environment before you build IoT Edge code:
Dependency | Notes |
---|---|
.NET 6.0 | Installation instructions here. |
Java | Not needed if building in VS IDE (Windows). Otherwise, a JRE is required to compile the Antlr4 grammar files into C# classes, and java must be on your path. |
Besides using Visual Studio in Windows, you can build by running the build script:
scripts/linux/buildBranch.sh
Binaries are published to target/publish/
.
Besides using Test Explorer in Visual Studio, you can run the unit tests with:
scripts/linux/runTests.sh
To run integration tests and/or BVTs, make sure the following dependencies are installed in your environment:
Dependency | Notes |
---|---|
Azure CLI | Installation instructions here. |
Powershell | Installation instructions here. |
Jq | Installation instructions here. |
Docker | Installation instructions here. In Linux environments, be sure to follow the post-installation steps so the tests can run without sudo . |
The integration tests and BVTs expect to find certain values in an Azure KeyVault (see edge-util/test/Microsoft.Azure.Devices.Edge.Util.Test.Common/settings/base.json
). For the tests to access the KeyVault at runtime, a certificate must first be installed in the environment where the tests will run. Install the KeyVault certificate with:
az login # Login and select default subscription, if necessary
scripts/linux/downloadAndInstallCert.sh -v <VaultName> -c <CertName>
Argument | Description |
---|---|
VaultName | KeyVault name. See az keyvault secret show help. |
CertName | Certificate name. See --secret in az keyvault secret show help. |
Then run the tests either with Test Explorer in Visual Studio IDE, or with:
scripts/linux/runTests.sh "Category=Integration"
The syntax of the "filter" argument is described here. All IoT Edge tests are categorized as one of Unit
, Integration
, or Bvt
.
The end-to-end tests are documented here.
Currently, Code Coverage Local Checks are supported only in a Windows Environment due to dependency on Microsoft Code Coverage Tools
dotnet test /p:CollectCoverage=true --filter "Category=Unit" -s CodeCoverage.runsettings --logger:trx --results-directory TestResults
dotnet tool install --global dotnet-coverageconverter
dotnet-coverageconverter --CoverageFilesFolder TestResults
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator "-reports:TestResults\*\*.coveragexml" "-targetdir:report"
Sometimes it is useful to build the Edge Hub container locally. If you want to do so you can run the below script:
./scripts/linux/buildLocalEdgeHub.sh --registry-address "$(registry.address)" --version "$(version)"
There is a script in the repo to setup a docker container with the Visual Studio Debugger (vsdbg). After running the script in a container, you can connect the VSCode debugger to a process running in the container. The following example shows how to run the setup script on a Linux IoT Edge device to setup the debugger in the Edge Agent container:
$ scripts/linux/setupContainerDebugger.sh -c edgeAgent -u edgeagentuser
After running the debugger setup script, create a launch.json file in the edgeAgent/.vscode directory. The launch.json file should have the following contents (Note: replace the value in sourceFileMap
before running):
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Remote Debug IoT Edge Module (.NET Core)",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickRemoteProcess}",
"pipeTransport": {
"pipeProgram": "docker",
"pipeArgs": [
"exec",
"-i",
"-u",
"edgeagentuser"
"edgeAgent",
"sh",
"-c"
],
"debuggerPath": "/root/vsdbg/vsdbg",
"pipeCwd": "${workspaceFolder}",
"quoteArgs": true
},
"sourceFileMap": {
"<replace-with-compile-time-path-to-edge-agent-source>": "${workspaceRoot}"
},
"symbolOptions": {
"searchPaths": ["/app"],
"searchMicrosoftSymbolServer": false,
"searchNuGetOrgSymbolServer": false
},
"justMyCode": true,
"requireExactSource": true
}
]
}
Start debugging by selecting the configuration defined above from the 'Run and Debug' tab (Ctrl+Shift+D) and selecting the 'Start Debugging' button (F5).
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。