Skip to content

Commit

Permalink
[TEST] Setup test infrastructure (#51)
Browse files Browse the repository at this point in the history
Setup test infrastructure
Document instructions to run the tests locally.
Implement CI for test execution triggered after build workflow.
Test results exported to github as PR comment.
Tests covers prerequisites check, bascic command line responses, IDF installation with default parameters, check IDF functionality building artifacts for a sample project.
  • Loading branch information
Fabricio-ESP authored Oct 30, 2024
1 parent e7b18d2 commit e2fe1f5
Show file tree
Hide file tree
Showing 15 changed files with 3,535 additions and 1 deletion.
136 changes: 136 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: Autotest

on:
workflow_run:
workflows: ["Rust"]
types:
- completed

jobs:
test:
name: Automated test scripts
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts

- name: Extract artifact (non-Windows)
if: runner.os != 'Windows'
run: |
mkdir -p test-bin
unzip ./artifacts/eim-${{ github.run_id }}-${{ matrix.os }}/eim.zip -d test-bin
# unzip ./test-bin/eim.zip -d test-bin
- name: Set executable permissions (non-Windows)
if: runner.os != 'Windows'
run: |
chmod +x ./test-bin/eim
- name: Run prerequisites test script (non-Windows)
if: runner.os != 'Windows'
run: |
export EIM_FILE_PATH="../test-bin/eim"
export EIM_VERSION="idf-im-cli 0.1.3"
export LOG_TO_FILE="true"
cd tests
npm ci
npx mocha --exit --reporter mocha-junit-reporter --reporter-options mochaFile=./results-pre-test.xml script/prerequisites.test.js
- name: Install dependencies (Ubuntu)
if: runner.os == 'Linux'
run: |
sudo apt-get install -y git cmake ninja-build wget flex bison gperf ccache libffi-dev libssl-dev dfu-util libusb-1.0-0-dev python3 python3-venv python3-pip
- name: Run IDF installation and post install test script (non-Windows)
if: runner.os != 'Windows'
run: |
export EIM_FILE_PATH="../test-bin/eim"
export EIM_VERSION="idf-im-cli 0.1.3"
export LOG_TO_FILE="true"
cd tests
npx mocha --exit --reporter mocha-junit-reporter --reporter-options mochaFile=./results.xml script/main.test.js
export IDF_SCRIPT=$HOME/.espressif/activate_idf_v5.3.1.sh
npx mocha --exit --reporter mocha-junit-reporter --reporter-options mochaFile=./results-post-test.xml script/postInstall.test.js
- name: Extract artifact (Windows)
if: runner.os == 'Windows'
run: |
mkdir -p test-bin
7z x ./artifacts/eim-${{ github.run_id }}-${{ matrix.os }}/eim.zip -otest-bin
# 7z x ./test-bin/eim.zip -otest-bin
- name: Print powershell and windows version (Windows)
if: runner.os == 'Windows'
run: |
$PSVersionTable
[System.Environment]::OSVersion.Version
- name: Run test script (Windows)
if: runner.os == 'Windows'
run: |
$env:EIM_FILE_PATH="..\test-bin\eim.exe"
$env:EIM_VERSION="idf-im-cli 0.1.3"
$env:LOG_TO_FILE="true"
7z x ./tests/node_modules.zip -otests/node_modules
Set-Location -Path "./tests"
npx mocha --exit --reporter mocha-junit-reporter --reporter-options mochaFile=./results-pre-test.xml script/prerequisites.test.js
- name: Install dependencies (Windows)
if: runner.os == 'windows'
run: |
choco install ninja -y
- name: Run test script (Windows)
if: runner.os == 'Windows'
run: |
$env:EIM_FILE_PATH = "..\test-bin\eim.exe"
$env:EIM_VERSION = "idf-im-cli 0.1.3"
$env:LOG_TO_FILE="true"
Set-Location -Path "./tests"
npx mocha --exit --reporter mocha-junit-reporter --reporter-options mochaFile=./results.xml script/main.test.js
$env:IDF_SCRIPT="C:\esp\v5.3.1\Microsoft.PowerShell_profile.ps1"
npx mocha --exit --reporter mocha-junit-reporter --reporter-options mochaFile=./results-post-test.xml script/postInstall.test.js
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results-${{ matrix.os }}.zip
path: |
./tests/results.xml
./tests/results-pre-test.xml
./tests/results-post-test.xml
./tests/test.log
publish-test-results:
name: Automated Test Results
needs: test
runs-on: ubuntu-latest
if: always()

steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts

- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
action_fail: true
files: "./artifacts/**/*.xml"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/docs/_build/
/docs/_build/
node_modules/
191 changes: 191 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
# Espressif Installation Manager automated tests

## Concepts

The EMI application should have a test structure that would allow validation or customer use cases on the final artifacts. At an initial stage
the tests will be executed manually and using an structure that will allow evolution to be triggered by github actions using local or remote windows and linux runners.

All tests are developed in Node.js using Chain and Mocha as test libraries in combination with Node-PTY for teminal emulation. It is required to install node on the test runner machine.

## Environment Setup

On the test machine, the first step is to copy the testing artifacts. The location of the artifacts can be set using environment variable, or the test will look for the `eim` file in the default location:

Windows: $USERPROFILE\espressif\
Linux/MacOS: $HOME/espressif

### Windows

Install chocolatey package manager:
https://docs.chocolatey.org/en-us/choco/setup/
Run this command with administrator priviledges.
`Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))`

Install Node.js:
https://nodejs.org/en/download/prebuilt-installer/current
`choco install nodejs --version="20.17.0" -y`

Install git:
https://git-scm.com/download/win
`choco install git.install -y`

Clone the test trunk from the public repository:

`git clone -b autotest https://github.com/espressif/idf-im-cli.git`

### Linux:

Install Git and curl and build-essential packages
`sudo apt install -y git curl build-essential`
`curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash`

Start a new terminal (to load nvm)
`nvm install 20`

Clone the test trunk from the public repository:
`git clone -b autotest https://github.com/espressif/idf-im-cli.git`

At his point test for prerequisits can be run, the remaining tests requires the pre-requisits to be installed.
The pre-requisites tests have been commented out of the test scripts.

`sudo apt install git cmake ninja-build wget flex bison gperf ccache libffi-dev libssl-dev dfu-util libusb-dev python3 python3-venv python3-pip`

### MacOS

## Commands summary

Navigate to the idf-im-cli folder, where the repository was cloned.
The scripts should be executed passing as arguments the path to the `eim` application and the version of the file being tested.

#### Windows

Open Powershell, and enable script execution:
`Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass`

To execute tests on windows, use the script
`.\tests\run_test.ps1 "<PATH TO EIM.EXE>" "<Version being tested>"`

Default arguments are:
`.\tests\run_test.ps1 "$env:USERPROFILE\espressif\eim.exe" "idf-im-cli 0.1.3"`

#### Linux

(if needed) Give execution permission to the test script
`chmod +x ./tests/run_test.sh`

To execute tests on linux, use the script:
`. ./tests/run_test.sh "<PATH TO EIM>" "<Version being tested>"`

Default arguments are:
`. ./tests/run_test.sh "$HOME/espressif/eim" "idf-im-cli 0.1.3"`

#### MacOS

To executing testins in MacOS, use the script:

<TODO>

# Installation Manager Usage

##Application arguments

```
Options:
-p, --path <PATH>
Base Path to which all the files and folder will be installed
-c, --config <FILE>
-t, --target <TARGET>
You can provide multiple targets separated by comma
-i, --idf-versions <IDF_VERSIONS>
you can provide multiple versions of ESP-IDF separated by comma
--tool-download-folder-name <TOOL_DOWNLOAD_FOLDER_NAME>
--tool-install-folder-name <TOOL_INSTALL_FOLDER_NAME>
--idf-tools-path <IDF_TOOLS_PATH>
Path to tools.json file relative from ESP-IDF installation folder
--tools-json-file <TOOLS_JSON_FILE>
Path to idf_tools.py file relative from ESP-IDF installation folder
-n, --non-interactive <NON_INTERACTIVE>
[possible values: true, false]
-m, --mirror <MIRROR>
url for download mirror to use instead of github.com
--idf-mirror <IDF_MIRROR>
url for download mirror to use instead of github.com for downloading esp-idf
-v, --verbose...
Increase verbosity level (can be used multiple times)
-l, --locale <LOCALE>
Set the language for the wizard (en, cn)
--log-file <LOG_FILE>
file in which logs will be stored (default: eim.log)
-r, --recurse-submodules <RECURSE_SUBMODULES>
Should the installer recurse into submodules of the ESP-IDF repository (derfault true)
[possible values: true, false]
-h, --help
Print help (see a summary with '-h')
-V, --version
Print version
```

## Example config file:

file config.toml (Linux)

```
path = "/home/virtual/.esp"
idf_path = "/home/virtual/.esp/v5.3.1/esp-idf"
tool_download_folder_name = "dist"
tool_install_folder_name = "tools"
target = ["all"]
idf_versions = ["v5.3.1"]
tools_json_file = "tools/tools.json"
idf_tools_path = "./tools/idf_tools.py"
mirror = "https://github.com"
idf_mirror = "https://github.com"
```

file config.toml (Windows)

```
path = 'C:\esp\'
idf_path = 'C:\esp\v5.3.1\esp-idf'
tool_download_folder_name = "dist"
tool_install_folder_name = "tools"
target = ["all"]
idf_versions = ["v5.3.1"]
tools_json_file = "tools/tools.json"
idf_tools_path = "./tools/idf_tools.py"
mirror = "https://github.com"
idf_mirror = "https://github.com"
```

## Full arguments

#### Windows:

`.\eim.exe -p c:\espressif -t all -i v5.3.1 --tool-download-folder-name dist --tool-install-folder-name tools --idf-tools-path ./tools/idf_tools.py --tools-json-file tools/tools.json -m https://github.com --idf-mirror https://github.com -r true`

`.\eim.exe -c config.toml`

`.\eim.exe --log-file InstManager.log`

#### Linux & MacOS

`./eim -p ~/.espressif -t all -i v5.3.1 --tool-download-folder-name dist --tool-install-folder-name tools --idf-tools-path ./tools/idf_tools.py --tools-json-file tools/tools.json -m https://github.com --idf-mirror https://github.com -r true`

`./eim -c config.toml`

`./eim --log-file InstManager.log`

## References

Packages required by EIM:

Windows: eim should be able to perform all requirements installation

Linux: sudo apt install git cmake ninja-build wget flex bison gperf ccache libffi-dev libssl-dev dfu-util libusb-dev python3 python3-venv python3-pip

MacOS:
Install homebrew and load the application to the terminal profile

`/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`

Then run: brew install dfu-util cmake ninja python3
Loading

0 comments on commit e2fe1f5

Please sign in to comment.