Add an http server to CI tests so that HTTP booting and loading can be tested.
Signed-off-by: Adriano Cordova <adriano.cord...@canonical.com> --- .azure-pipelines.yml | 14 +++++++++++++- .gitlab-ci.yml | 14 +++++++++++++- test/py/conftest.py | 5 +++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml index 5e1938b0526..ba31727aec1 100644 --- a/.azure-pipelines.yml +++ b/.azure-pipelines.yml @@ -316,9 +316,21 @@ stages: fi export PATH=/opt/qemu/bin:/tmp/uboot-test-hooks/bin:\${PATH} export PYTHONPATH=/tmp/uboot-test-hooks/py/travis-ci + python3 -m http.server 80 --directory "\${UBOOT_TRAVIS_BUILD_DIR}" > /dev/null 2>&1 & + HTTP_PID=\$! + sleep 1 # Give the server a moment to start + if ps -p \${HTTP_PID} > /dev/null; then + export HTTP_PID + export HTTP_SERVER="--httpserver localhost:80" + else + unset HTTP_PID + fi # "\${var:+"-k \$var"}" expands to "" if \$var is empty, "-k \$var" if not - ./test/py/test.py -ra -o cache_dir="\$UBOOT_TRAVIS_BUILD_DIR"/.pytest_cache --bd \${TEST_PY_BD} \${TEST_PY_ID} \${TEST_PY_EXTRA} \${TEST_PY_TEST_SPEC:+"-k \${TEST_PY_TEST_SPEC}"} --build-dir "\$UBOOT_TRAVIS_BUILD_DIR" --report-dir "\$UBOOT_TRAVIS_BUILD_DIR" --junitxml=\$(System.DefaultWorkingDirectory)/results.xml + ./test/py/test.py -ra -o cache_dir="\$UBOOT_TRAVIS_BUILD_DIR"/.pytest_cache --bd \${TEST_PY_BD} \${TEST_PY_ID} \${TEST_PY_EXTRA} \${HTTP_SERVER} \${TEST_PY_TEST_SPEC:+"-k \${TEST_PY_TEST_SPEC}"} --build-dir "\$UBOOT_TRAVIS_BUILD_DIR" --report-dir "\$UBOOT_TRAVIS_BUILD_DIR" --junitxml=\$(System.DefaultWorkingDirectory)/results.xml # the below corresponds to .gitlab-ci.yml "after_script" + if [[ -n "\${HTTP_PID}" ]]; then + kill \${HTTP_PID}; + fi rm -rf /tmp/uboot-test-hooks /tmp/venv EOF - task: CopyFiles@2 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6f11331514b..aeb54262883 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -106,10 +106,22 @@ stages: # "${var:+"-k $var"}" expands to "" if $var is empty, "-k $var" if not - export PATH=/opt/qemu/bin:/tmp/uboot-test-hooks/bin:${PATH}; export PYTHONPATH=/tmp/uboot-test-hooks/py/travis-ci; - ./test/py/test.py -ra --bd ${TEST_PY_BD} ${TEST_PY_ID} ${TEST_PY_EXTRA} + python3 -m http.server 80 --directory "${UBOOT_TRAVIS_BUILD_DIR}" > /dev/null 2>&1 & + HTTP_PID=$! + sleep 1 # Give the server a moment to start + if ps -p ${HTTP_PID} > /dev/null; then + export HTTP_PID + export HTTP_SERVER="--httpserver localhost:80" + else + unset HTTP_PID + fi + ./test/py/test.py -ra --bd ${TEST_PY_BD} ${TEST_PY_ID} ${TEST_PY_EXTRA} ${HTTP_SERVER} ${TEST_PY_TEST_SPEC:+"-k ${TEST_PY_TEST_SPEC}"} --build-dir "$UBOOT_TRAVIS_BUILD_DIR" --junitxml=/tmp/${TEST_PY_BD}/results.xml + if [[ -n "${HTTP_PID}" ]]; then + kill ${HTTP_PID}; + fi artifacts: when: always paths: diff --git a/test/py/conftest.py b/test/py/conftest.py index 5aea85647af..fbf67acecc3 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -89,6 +89,8 @@ def pytest_addoption(parser): parser.addoption('--gdbserver', default=None, help='Run sandbox under gdbserver. The argument is the channel '+ 'over which gdbserver should communicate, e.g. localhost:1234') + parser.addoption('--httpserver', default=None, + help='Address of http server, e.g. localhost:80') parser.addoption('--role', help='U-Boot board role (for Labgrid-sjg)') parser.addoption('--use-running-system', default=False, action='store_true', help="Assume that U-Boot is ready and don't wait for a prompt") @@ -267,6 +269,8 @@ def pytest_configure(config): persistent_data_dir = build_dir + '/persistent-data' mkdir_p(persistent_data_dir) + httpserver = config.getoption('httpserver') + gdbserver = config.getoption('gdbserver') if gdbserver and not board_type.startswith('sandbox'): raise Exception('--gdbserver only supported with sandbox targets') @@ -330,6 +334,7 @@ def pytest_configure(config): ubconfig.board_type_extra = board_type_extra ubconfig.board_identity = board_identity ubconfig.gdbserver = gdbserver + ubconfig.httpserver = httpserver ubconfig.use_running_system = config.getoption('use_running_system') ubconfig.dtb = build_dir + '/arch/sandbox/dts/test.dtb' ubconfig.connection_ok = True -- 2.48.1