AWS IoT Device SDK C:
Main
|
Return to main page ↑ |
Guide to this SDK's automated testing setup.
The SDK's GitHub repo relies on the following tools to provide automated testing of commits and pull requests.
The following files on the GitHub repo control the automated tests:
.travis.yml
scripts/
directory sh
) that run on Travis CI servers.ci_test_mqtt.sh
tests the MQTT library.ci_test_doc.sh
tests the documentation build. Runs for pull requests only.ci_test_coverage.sh
generates and submits coverage results to Codecov. Runs for commits only.How to set up the automated testing services.
All of the automated testing services have web interfaces that can be connected to a GitHub account.
How to set up Travis CI.
Link to Travis CI: https://travis-ci.org/
How to set up Codecov.
Link to Codecov: https://codecov.io/
CODECOV_TOKEN
to the Repository Upload Token. Travis CI will automatically submit coverage data on commit check builds.The automated tests distinguish between GitHub commits and pull requests. Different sets of tests run on commits and pull requests.
Because pull requests come from other repos and contain unknown code, Travis CI will not provide encrypted environment variables for pull requests. Therefore, pull requests are tested against unsecured servers. The following tests are run for pull requests.
ci_test_common.sh
): this script tests common components like the task pool, atomics, etc. These tests do not use the network.ci_test_mqtt.sh
): the MQTT tests run on an unsecured connection against a locally-installed Mosquitto broker on the Travis CI VM.ci_test_shadow.sh
): only the Shadow unit tests are run for a pull request build. These tests do not use the network.ci_test_doc.sh
): checks that the documentation builds against the code in the pull request.For commits, the credentials necessary for connecting to AWS IoT are provided by Travis CI. The following tests are run for commits.
ci_test_common.sh
): runs the same tests as the common pull request tests.ci_test_mqtt.sh
): runs the same MQTT tests as the MQTT pull request tests, but against the AWS IoT MQTT broker instead of a Mosquitto broker.ci_test_shadow.sh
): runs both the Shadow unit tests and the Shadow system tests. Requires connection to AWS IoT.ci_test_coverage.sh
): Gathers code coverage data and submits it to Codecov.429 TOO MANY REQUESTS
error. If this happens, restart the Shadow tests. The main C SDK GitHub repo has an increased limit for Shadow requests, so it should not encounter this error.Because different sets of tests are run for commits and pull requests, both commit and pull request checks should be used to validate code changes. The commit checks can be set up to run on a GitHub fork, where they will run whenever a new commit is pushed to the fork. When a pull request is made from the fork to the main repo, the pull request checks will run.
How to set up AWS IoT credentials for commit checks.
Forking the main GitHub repo copies the Travis CI scripts, but does not copy any credentials, which are provided by Travis CI's encrypted environment variable feature. AWS IoT credentials are required to run the commit checks. No credentials are required to run pull request checks.
The AWS IoT client certificate and private key must be formatted to be acceptable for use in a CI script.
The credentials are written from Travis encrypted environment variables using the following command:
Therefore, all given credentials must be formatted for echo -e
. As an example, consider the following certificate:
It should be formatted as follows for Travis CI:
Note the spaces have an escape character \
before them, as in -----BEGIN\ CERTIFICATE-----
. Line breaks have been removed and replaced with \\n
.
Similar formatting should be applied to the matching private key.
The AWS IoT endpoint, client certificate, and client certificate private key are set on Travis CI's "Settings" page.
To edit the credentials, go to the "Settings" page on Travis CI. This is usually <repo URL>/settings
; for example, https://travis-ci.org/aws/aws-iot-device-sdk-embedded-C/settings
for the main repo. Under "Environment Variables", set the following variables:
Name | Value | Notes |
---|---|---|
AWS_IOT_CLIENT_CERT | Formatted client certificate | The AWS IoT client certificate. This value does not need to be hidden in the build log. |
AWS_IOT_ENDPOINT | ABCDEFG1234567.iot.<region>.amazonaws.com | The AWS IoT endpoint. This value does not need to be hidden in the build log. |
AWS_IOT_PRIVATE_KEY | Formatted private key | The private key matching the AWS IoT client certificate.
|
IOT_IDENTIFIER_PREFIX | CSDKCI | This string is prepended to all MQTT client identifiers used by the CI. It may be anything, but must match the client identifier in the AWS IoT policy. The example policy below uses CSDKCI . This value does not need to be hidden in the build log. |
The certificates used with Travis CI must have an appropriate policy attached.
AWS recommends using the most restrictive policy possible. The following policy should be used for the CI.
This policy only allows the CI to interact with topics that contain a matching client identifier (which is prefixed with the Travis CI variable IOT_IDENTIFIER_PREFIX
). A few special topics used by the MQTT tests are also present. The policy will need to be updated if any new topics are used by the tests in the future.
Additional CI settings for running the Jobs system tests and Provisioning system tests.
The Jobs system tests use AWS CLI to create and delete Jobs. Therefore, additional setup is needed in Travis CI.
Under the "Environment Variables" section of the Travis CI "Settings" page, set the following additional environment variables.
Name | Value | Notes |
---|---|---|
AWS_ACCESS_KEY_ID | The AWS access key for the Jobs tests IAM user |
|
AWS_DEFAULT_REGION | The AWS region to use with the Jobs tests | Should be the region where the Jobs test Thing is registered. This value does not need to be hidden in the build log. |
AWS_SECRET_ACCESS_KEY | The AWS secret access key for the Jobs tests IAM user |
|