From 5a0a14504d99c681002b7efc90b131f5eb2c6a82 Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Mon, 6 Jun 2022 16:10:41 +0800 Subject: [PATCH 1/5] ci: split pytest requirements to requirements.json --- .gitlab-ci.yml | 13 ++----------- tools/requirements.json | 6 ++++++ tools/requirements/requirements.pytest.txt | 10 ++++++++++ 3 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 tools/requirements/requirements.pytest.txt diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0c9d5112ea..217fafb60a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -74,7 +74,6 @@ variables: TEST_ENV_CONFIG_REPO: "https://gitlab-ci-token:${BOT_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/qa/ci-test-runner-configs.git" CI_AUTO_TEST_SCRIPT_REPO_URL: "https://gitlab-ci-token:${BOT_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/qa/auto_test_script.git" CI_AUTO_TEST_SCRIPT_REPO_BRANCH: "ci/v4.1" - PYTEST_EMBEDDED_VERSION: "0.7.1" # cache python dependencies PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" @@ -209,20 +208,12 @@ before_script: - *setup_tools_unless_target_test - fetch_submodules - *download_test_python_contraint_file - - $IDF_PATH/tools/idf_tools.py install-python-env + - $IDF_PATH/tools/idf_tools.py install-python-env --features pytest # TODO: remove this, IDFCI-1207 - pip install esptool -c ~/.espressif/${CI_PYTHON_CONSTRAINT_FILE} - - pip install - "pytest-embedded-serial-esp~=$PYTEST_EMBEDDED_VERSION" - "pytest-embedded-idf~=$PYTEST_EMBEDDED_VERSION" - "pytest-embedded-qemu~=$PYTEST_EMBEDDED_VERSION" - pytest-rerunfailures - scapy - websocket-client - netifaces - -r tools/esp_prov/requirements.txt - export EXTRA_CFLAGS=${PEDANTIC_CFLAGS} - export EXTRA_CXXFLAGS=${PEDANTIC_CXXFLAGS} + - eval "$($IDF_PATH/tools/idf_tools.py export)" # use idf venv instead default: retry: diff --git a/tools/requirements.json b/tools/requirements.json index 8136e39488..df1993c7b3 100644 --- a/tools/requirements.json +++ b/tools/requirements.json @@ -12,6 +12,12 @@ "description": "Packages for supporting debugging from web browser", "optional": true, "requirement_path": "tools/requirements/requirements.gdbgui.txt" + }, + { + "name": "pytest", + "description": "Packages for CI with pytest", + "optional": true, + "requirement_path": "tools/requirements/requirements.pytest.txt" } ] } diff --git a/tools/requirements/requirements.pytest.txt b/tools/requirements/requirements.pytest.txt new file mode 100644 index 0000000000..4f58de5312 --- /dev/null +++ b/tools/requirements/requirements.pytest.txt @@ -0,0 +1,10 @@ +pytest-embedded-serial-esp +pytest-embedded-idf +pytest-embedded-qemu +pytest-rerunfailures +scapy +websocket-client +netifaces +rangehttpserver +dbus-python +protobuf From f20a747a2688ad87d437cc5c093c994582127aa1 Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Tue, 7 Jun 2022 09:05:15 +0800 Subject: [PATCH 2/5] ci: upload cache only when requirements txt changed --- .gitlab-ci.yml | 4 +++- .gitlab/ci/host-test.yml | 6 +++++- .gitlab/ci/pre_check.yml | 7 ------- .gitlab/ci/rules.yml | 9 +++++++++ .gitlab/ci/upload_cache.yml | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 .gitlab/ci/upload_cache.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 217fafb60a..2be13a169b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,5 @@ stages: + - upload_cache - pre_check - build - assign_test @@ -100,7 +101,7 @@ cache: paths: - .cache/pip # pull only for most of the use cases since it's cache dir. - # Only set "pull-push" policy for "scan_test" since it would **possibly** install all pypi packages + # Only set "push" policy for "upload_cache" stage jobs since it would install all pypi packages policy: pull .setup_tools_unless_target_test: &setup_tools_unless_target_test | @@ -226,6 +227,7 @@ default: include: - '.gitlab/ci/rules.yml' + - '.gitlab/ci/upload_cache.yml' - '.gitlab/ci/docs.yml' - '.gitlab/ci/static-code-analysis.yml' - '.gitlab/ci/pre_check.yml' diff --git a/.gitlab/ci/host-test.yml b/.gitlab/ci/host-test.yml index 29783e2201..9c0a764a4b 100644 --- a/.gitlab/ci/host-test.yml +++ b/.gitlab/ci/host-test.yml @@ -7,7 +7,11 @@ tags: - host_test dependencies: [] - needs: [] # run host_test jobs immediately + needs: + - job: upload-pip-cache-shiny + optional: true # run host_test jobs immediately, only after upload cache + - job: upload-pip-cache-brew + optional: true # run host_test jobs immediately, only after upload cache test_nvs_on_host: extends: .host_test_template diff --git a/.gitlab/ci/pre_check.yml b/.gitlab/ci/pre_check.yml index ac9ad2be7b..2c03670d12 100644 --- a/.gitlab/ci/pre_check.yml +++ b/.gitlab/ci/pre_check.yml @@ -160,13 +160,6 @@ scan_tests: - $TEST_APPS_OUTPUT_DIR - $COMPONENT_UT_OUTPUT_DIR expire_in: 1 week - cache: - key: pip-cache - paths: - - .cache/pip - # pull only for most of the use cases since it's cache dir. - # Only set "pull-push" policy for "scan_test" since it would **possibly** install all pypi packages - policy: pull-push variables: EXAMPLE_TEST_DIR: ${CI_PROJECT_DIR}/examples EXAMPLE_TEST_OUTPUT_DIR: ${CI_PROJECT_DIR}/examples/test_configs diff --git a/.gitlab/ci/rules.yml b/.gitlab/ci/rules.yml index f87b6c218d..f0f63001f4 100644 --- a/.gitlab/ci/rules.yml +++ b/.gitlab/ci/rules.yml @@ -12,6 +12,10 @@ - "components/**/Kconfig" - "components/**/CMakeList.txt" +.patterns-python-cache: &patterns-python-cache + - "tools/requirements.json" + - "tools/requirements/requirements.*.txt" + .patterns-python-files: &patterns-python-files - ".gitlab/ci/static-code-analysis.yml" - "**/*.py" @@ -232,6 +236,11 @@ rules: - <<: *if-protected-no_label +.rules:patterns:python-cache: + rules: + - <<: *if-dev-push + changes: *patterns-python-cache + .rules:dev: rules: - <<: *if-trigger diff --git a/.gitlab/ci/upload_cache.yml b/.gitlab/ci/upload_cache.yml new file mode 100644 index 0000000000..afbb0e0005 --- /dev/null +++ b/.gitlab/ci/upload_cache.yml @@ -0,0 +1,36 @@ +.upload_cache_template: + stage: upload_cache + image: $ESP_ENV_IMAGE + +.upload_pip_cache_template: + extends: + - .upload_cache_template + - .rules:patterns:python-cache + cache: + key: pip-cache + paths: + - .cache/pip + # pull only for most of the use cases since it's cache dir. + # Only set "push" policy for "upload_cache" stage jobs since it would install all pypi packages + policy: push + before_script: [] + script: + - source tools/ci/utils.sh + - is_based_on_commits $REQUIRED_ANCESTOR_COMMITS + - source tools/ci/setup_python.sh + - rm -rf .cache/pip # clear old packages + - $IDF_PATH/tools/idf_tools.py install-python-env --features pytest + # TODO: remove this, IDFCI-1207 + - pip install esptool -c ~/.espressif/${CI_PYTHON_CONSTRAINT_FILE} + +upload-pip-cache-shiny: + extends: .upload_pip_cache_template + tags: + - shiny + - build + +upload-pip-cache-brew: + extends: .upload_pip_cache_template + tags: + - brew + - build From a24f4dedcd87e33c9d76cfd43b9e423baaaeb5d0 Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Tue, 7 Jun 2022 09:31:47 +0800 Subject: [PATCH 3/5] ci(pytest): add missing tags --- pytest.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pytest.ini b/pytest.ini index dd9d240f29..32e659777e 100644 --- a/pytest.ini +++ b/pytest.ini @@ -43,7 +43,8 @@ markers = ethernet: ethernet runner ethernet_flash_8m: ethernet runner with 8mb flash wifi: wifi runner - wifi_bt + wifi_bt: wifi runner with bluetooth + deepsleep: deepsleep runners # multi-dut markers multi_dut_generic: tests should be run on generic runners, at least have two duts connected. From 566af729c59d0741090e774af599b8c38b9a41b7 Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Wed, 8 Jun 2022 08:19:21 +0800 Subject: [PATCH 4/5] docs: update pytest installation --- docs/en/contribute/esp-idf-tests-with-pytest.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/contribute/esp-idf-tests-with-pytest.rst b/docs/en/contribute/esp-idf-tests-with-pytest.rst index 621f4d878c..74d7c9d2d8 100644 --- a/docs/en/contribute/esp-idf-tests-with-pytest.rst +++ b/docs/en/contribute/esp-idf-tests-with-pytest.rst @@ -22,7 +22,7 @@ All the introduced concepts and usages are based on the default behavior in ESP- Installation ------------ -``$ pip install -U pytest-embedded-serial-esp~=0.7.0 pytest-embedded-idf~=0.7.0`` +All dependencies could be installed by running the install script with the ``--enable-pytest`` argument, e.g. ``$ install.sh --enable-pytest``. Basic Concepts -------------- From 34e04e39bb3d7c308960104c25ecd49a3b821542 Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Wed, 8 Jun 2022 10:11:43 +0800 Subject: [PATCH 5/5] fix: skip install dbus-python on windows --- tools/requirements/requirements.pytest.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/requirements/requirements.pytest.txt b/tools/requirements/requirements.pytest.txt index 4f58de5312..fbf994b1cb 100644 --- a/tools/requirements/requirements.pytest.txt +++ b/tools/requirements/requirements.pytest.txt @@ -6,5 +6,5 @@ scapy websocket-client netifaces rangehttpserver -dbus-python +dbus-python; sys_platform != 'win32' protobuf