diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index f61dfbf..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: build - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - build_32: - runs-on: ubuntu-22.04 - - steps: - - uses: actions/checkout@v3 - - - run: make -f utils.mk build32 - - build_64: - runs-on: ubuntu-22.04 - - steps: - - uses: actions/checkout@v3 - - - run: make -f utils.mk build64 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 988a42e..8d0f6d8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,11 +10,11 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - run: make -f utils.mk build32 - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: path: mtxrpicam_32 name: mtxrpicam_32 @@ -23,11 +23,11 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - run: make -f utils.mk build64 - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: path: mtxrpicam_64 name: mtxrpicam_64 @@ -39,12 +39,12 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: mtxrpicam_32 path: binaries/ - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: mtxrpicam_64 path: binaries/ diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..0d10e2f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,66 @@ +name: test + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build_32: + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v4 + + - run: make -f utils.mk build32 + + - uses: actions/upload-artifact@v4 + with: + path: mtxrpicam_32 + name: mtxrpicam_32 + + build_64: + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v4 + + - run: make -f utils.mk build64 + + - uses: actions/upload-artifact@v4 + with: + path: mtxrpicam_64 + name: mtxrpicam_64 + + test_32: + needs: build_32 + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v4 + + - uses: actions/download-artifact@v4 + with: + name: mtxrpicam_32 + path: . + + - run: chmod +x mtxrpicam_32 + + - run: make -f utils.mk test32 + + test_64: + needs: build_64 + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v4 + + - uses: actions/download-artifact@v4 + with: + name: mtxrpicam_64 + path: . + + - run: chmod +x mtxrpicam_64 + + - run: make -f utils.mk test64 diff --git a/README.md b/README.md index 76446a5..bca349a 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ This is embedded into all MediaMTX releases and shouldn't normally be downloaded 1. You must be on a Raspberry Pi, running Raspberry Pi OS Bullseye -2. Install the build dependencies: +2. Install build dependencies: ```sh sudo apt install -y \ diff --git a/main.c b/main.c index bb37921..19d4180 100644 --- a/main.c +++ b/main.c @@ -35,6 +35,13 @@ static void on_encoder_output(uint64_t ts, const uint8_t *buf, uint64_t size) { } int main() { + // this is meant to test that dependencies have been loaded correctly + // therefore a simple "return 0" is enough. + if (strlen(getenv("TEST")) != 0) { + printf("test passed\n"); + return 0; + } + int pipe_conf_fd = atoi(getenv("PIPE_CONF_FD")); pipe_video_fd = atoi(getenv("PIPE_VIDEO_FD")); diff --git a/utils.mk b/utils.mk index 8bfde15..4eaf7a5 100644 --- a/utils.mk +++ b/utils.mk @@ -10,6 +10,8 @@ help: @echo " build build binaries for all platforms" @echo " build32 build binaries for the 64-bit platform" @echo " build64 build binaries for the 32-bit platform" + @echo " test32 test binaries for the 32-bit platform" + @echo " test64 test binaries for the 64-bit platform" @echo "" build: build32 build64 @@ -33,6 +35,10 @@ COPY --from=build /s/mtxrpicam /s/mtxrpicam endef export DOCKERFILE_BUILD32 +build32: + echo "$$DOCKERFILE_BUILD32" | docker build . -f - -t build32 + docker run --rm -v $(PWD):/o build32 sh -c "mv /s/mtxrpicam /o/mtxrpicam_32" + define DOCKERFILE_BUILD64 FROM $(RPI64_IMAGE) AS build RUN ["cross-build-start"] @@ -52,10 +58,32 @@ COPY --from=build /s/mtxrpicam /s/mtxrpicam endef export DOCKERFILE_BUILD64 -build32: - echo "$$DOCKERFILE_BUILD32" | docker build . -f - -t build32 - docker run --rm -v $(PWD):/o build32 sh -c "mv /s/mtxrpicam /o/mtxrpicam_32" - build64: echo "$$DOCKERFILE_BUILD64" | docker build . -f - -t build64 docker run --rm -v $(PWD):/o build64 sh -c "mv /s/mtxrpicam /o/mtxrpicam_64" + +define DOCKERFILE_TEST32 +FROM multiarch/qemu-user-static:x86_64-arm AS qemu +FROM $(RPI32_IMAGE) AS build +COPY --from=qemu /usr/bin/qemu-arm-static /usr/bin/qemu-arm-static +RUN apt update && apt install -y --no-install-recommends libcamera0 libfreetype6 && rm -rf /var/lib/apt/lists/* +endef +export DOCKERFILE_TEST32 + +test32: + docker run --rm --privileged multiarch/qemu-user-static:register --reset --credential yes + echo "$$DOCKERFILE_TEST32" | docker build . -f - -t test32 + docker run --rm --platform=linux/arm/v6 -v $(PWD):/s -w /s test32 bash -c "TEST=1 ./mtxrpicam_32" + +define DOCKERFILE_TEST64 +FROM multiarch/qemu-user-static:x86_64-aarch64 AS qemu +FROM $(RPI64_IMAGE) AS build +COPY --from=qemu /usr/bin/qemu-aarch64-static /usr/bin/qemu-aarch64-static +RUN apt update && apt install -y --no-install-recommends libcamera0 libfreetype6 && rm -rf /var/lib/apt/lists/* +endef +export DOCKERFILE_TEST64 + +test64: + docker run --rm --privileged multiarch/qemu-user-static:register --reset --credential yes + echo "$$DOCKERFILE_TEST64" | docker build . -f - -t test64 + docker run --rm --platform=linux/arm64/v8 -v $(PWD):/s -w /s test64 bash -c "TEST=1 ./mtxrpicam_64"