Skip to content

Commit

Permalink
add CI step to test executables (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 authored Aug 17, 2024
1 parent e4a0405 commit 28730d0
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 35 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/build.yml

This file was deleted.

12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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/
Expand Down
66 changes: 66 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
7 changes: 7 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down
36 changes: 32 additions & 4 deletions utils.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
Expand All @@ -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"

0 comments on commit 28730d0

Please sign in to comment.