diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.yml index 7e4fa948..cfdd2818 100644 --- a/.github/workflows/packages.yml +++ b/.github/workflows/packages.yml @@ -44,10 +44,38 @@ jobs: build_all_kmods: true build_all_modules: true build_full: true + upload_images: true ccache_type: packages upload_ccache_cache: ${{ github.repository_owner == 'openwrt' }} check_packages_list: ${{ needs.determine_changed_packages.outputs.changed_packages }} + test: + name: Test with QEMU + needs: build + strategy: + fail-fast: False + matrix: + include: + - target: malta + subtarget: be + image: openwrt-malta-be-vmlinux-initramfs.elf + use_qemu: true + qemu_target: mips + - target: x86 + subtarget: 64 + image: openwrt-x86-64-generic-squashfs-combined.img + use_qemu: true + qemu_target: x86 + qemu_bin: x86_64 + uses: ./.github/workflows/reusable_test-image.yml + with: + target: ${{ matrix.target }} + subtarget: ${{ matrix.subtarget }} + image: ${{ matrix.image }} + use_qemu: ${{ matrix.use_qemu }} + qemu_target: ${{ matrix.qemu_target }} + qemu_bin: ${{ matrix.qemu_bin || '' }} + upload-ccache-cache-in-s3: if: github.event_name == 'push' && github.repository_owner == 'openwrt' name: Upload ccache cache to s3 diff --git a/.github/workflows/reusable_build.yml b/.github/workflows/reusable_build.yml index d22542d1..463ba0fb 100644 --- a/.github/workflows/reusable_build.yml +++ b/.github/workflows/reusable_build.yml @@ -59,6 +59,8 @@ on: type: boolean upload_external_toolchain: type: boolean + upload_images: + type: boolean use_ccache_cache: type: boolean default: true @@ -739,3 +741,12 @@ jobs: name: ${{ inputs.target }}-${{ inputs.subtarget }}-external-toolchain path: openwrt/bin/targets/${{ inputs.target }}/${{ inputs.subtarget }}/${{ steps.get-toolchain-name.outputs.toolchain-name }} retention-days: 1 + + - name: Upload compiled images + if: inputs.build_full == true && inputs.upload_images == true + uses: actions/upload-artifact@v4 + with: + name: ${{ inputs.target }}-${{ inputs.subtarget }}${{ inputs.testing == true && '-testing' || '' }}-images + path: | + openwrt/bin/targets/${{ inputs.target }}/${{ inputs.subtarget }}/openwrt-${{ inputs.target }}-${{ inputs.subtarget }}-* + retention-days: 1 diff --git a/.github/workflows/reusable_test-image.yml b/.github/workflows/reusable_test-image.yml new file mode 100644 index 00000000..9c27c4e0 --- /dev/null +++ b/.github/workflows/reusable_test-image.yml @@ -0,0 +1,70 @@ +name: Test Image + +on: + workflow_call: + inputs: + target: + required: true + type: string + subtarget: + required: true + type: string + testing: + type: boolean + image: + required: true + type: string + use_qemu: + type: boolean + qemu_target: + type: string + qemu_bin: + type: string + +jobs: + test: + name: Test image ${{ inputs.target }}/${{ inputs.subtarget }} + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + repository: aparcar/openwrt-tests + + - name: Install dependencies + run: | + sudo apt install python3-pip + + - name: Install QEMU dependency + if: inputs.use_qemu == true + run: | + sudo apt install qemu-system-${{ inputs.qemu_target }} + + - name: Install test project dependencies + run: | + pip3 install poetry + poetry install + + - name: Download compiled images from build job + uses: actions/download-artifact@v4 + with: + name: ${{ inputs.target }}-${{ inputs.subtarget }}${{ inputs.testing == true && '-testing' || '' }}-images + + - name: Extract image if needed + run: | + # gunzip return 2 for warning hence we need to reset + if [ -f "${{ inputs.image }}.gz" ]; then + gunzip -q ${{ inputs.image }}.gz || true + fi + + - name: Run test with QEMU + if: inputs.use_qemu == true + run: | + export LG_QEMU_BIN=qemu-system-${{ inputs.qemu_bin || inputs.qemu_target }} + + poetry run pytest \ + --lg-env tests/qemu.yaml \ + --target ${{ inputs.target }}-${{ inputs.subtarget }} \ + --firmware "$(pwd)"/${{ inputs.image }} +