From fa0662e54c393e618342914e3b442d58d02d113a Mon Sep 17 00:00:00 2001 From: Jacob Graves Date: Wed, 8 Jun 2022 11:26:28 -0600 Subject: [PATCH] Jenkins CI (#1102) * jenkins: initial commit * jenkins: add missing usb hub check script * jenkins: squish docker apt package install commands into a single command * jenkins: fix type in Dockerfile * jenkins: override interactive installations in Dockerfile (build-essentials fails due to tzdata) * jenkins: set executable flag on ci scripts * jenkins: remove sudo prefix from install scripts * jenkins: add python3 venv to Dockerfile and build scripts * jenkins: add missing python venv command to host install script * jenkins: remove python install and venv redundancies * jenkins: remove make install step, run hackrf tools directly from their build directory * jenkins: re-add python3 and pip installations to docker because usbhub depends on them * jenkins: add missing git install to docker * jenkins: add python-is-python3 to docker's installed dependencies * jenkins: use path string to specify the correct device for dfu-util * jenkins: specify usbhub id for dual hub setup * jenkins: turn unused usb hub ports off for testing * jenkins: remove custom job throttle property * use --disable-i2c usbhub option, install usbhub from latest, replace --privileged with cgroups option, remove redundancies from Dockerfile * update device usb path for dfu-util * remove apt/lists/* and fix typos * ci: remove redundant environment setup in Jenkins --- Dockerfile | 23 ++++++++++++++++ Jenkinsfile | 41 +++++++++++++++++++++++++++++ ci-scripts/configure-hubs.sh | 3 +++ ci-scripts/install-firmware.sh | 8 ++++++ ci-scripts/install-host.sh | 6 +++++ ci-scripts/test-firmware-flash.sh | 18 +++++++++++++ ci-scripts/test-firmware-program.sh | 21 +++++++++++++++ ci-scripts/test-host.sh | 21 +++++++++++++++ 8 files changed, 141 insertions(+) create mode 100644 Dockerfile create mode 100644 Jenkinsfile create mode 100755 ci-scripts/configure-hubs.sh create mode 100755 ci-scripts/install-firmware.sh create mode 100755 ci-scripts/install-host.sh create mode 100755 ci-scripts/test-firmware-flash.sh create mode 100755 ci-scripts/test-firmware-program.sh create mode 100755 ci-scripts/test-host.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..53e37d19 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +# Sandbox test environment for HackRF +FROM ubuntu:20.04 +CMD ["/bin/bash"] + +# Override interactive installations and install prerequisites +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update && apt-get install -y \ + build-essential \ + cmake \ + dfu-util \ + gcc-arm-none-eabi \ + git \ + libfftw3-dev \ + libusb-1.0-0-dev \ + pkg-config \ + python3 \ + python3-pip \ + python-is-python3 \ + && rm -rf /var/lib/apt/lists/* +RUN pip3 install git+https://github.com/CapableRobot/CapableRobot_USBHub_Driver --upgrade + +# Inform Docker that the container is listening on port 8080 at runtime +EXPOSE 8080 diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..3d5ea101 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,41 @@ +pipeline { + agent { + dockerfile { + args '--group-add=46 --device-cgroup-rule="c 189:* rmw" -v /dev/bus/usb:/dev/bus/usb' + } + } + stages { + stage('Build (Host)') { + steps { + sh './ci-scripts/install-host.sh' + } + } + stage('Build (Firmware)') { + steps { + sh './ci-scripts/install-firmware.sh' + } + } + stage('Test') { + steps { + sh './ci-scripts/configure-hubs.sh --off' + retry(3) { + sh './ci-scripts/test-host.sh' + } + retry(3) { + sh './ci-scripts/test-firmware-program.sh' + } + sh './ci-scripts/test-firmware-flash.sh' + } + } + } + post { + always { + sh './ci-scripts/configure-hubs.sh --reset' + sh 'rm -rf testing-venv/' + cleanWs(cleanWhenNotBuilt: false, + deleteDirs: true, + disableDeferredWipeout: true, + notFailBuild: true) + } + } +} diff --git a/ci-scripts/configure-hubs.sh b/ci-scripts/configure-hubs.sh new file mode 100755 index 00000000..47dcb44b --- /dev/null +++ b/ci-scripts/configure-hubs.sh @@ -0,0 +1,3 @@ +#!/bin/bash +usbhub --disable-i2c --hub D9D1 power state --port 1,2,3,4 $1 +usbhub --disable-i2c --hub 624C power state --port 1,2,3,4 $1 \ No newline at end of file diff --git a/ci-scripts/install-firmware.sh b/ci-scripts/install-firmware.sh new file mode 100755 index 00000000..8d83486c --- /dev/null +++ b/ci-scripts/install-firmware.sh @@ -0,0 +1,8 @@ +#!/bin/bash +git submodule init +git submodule update +mkdir firmware/hackrf_usb/build +cd firmware/hackrf_usb/build +cmake .. +make +cd ../../.. \ No newline at end of file diff --git a/ci-scripts/install-host.sh b/ci-scripts/install-host.sh new file mode 100755 index 00000000..a1260367 --- /dev/null +++ b/ci-scripts/install-host.sh @@ -0,0 +1,6 @@ +#!/bin/bash +mkdir host/build +cd host/build +cmake .. +make +cd ../.. \ No newline at end of file diff --git a/ci-scripts/test-firmware-flash.sh b/ci-scripts/test-firmware-flash.sh new file mode 100755 index 00000000..a56d8fa3 --- /dev/null +++ b/ci-scripts/test-firmware-flash.sh @@ -0,0 +1,18 @@ +#!/bin/bash +host/build/hackrf-tools/src/hackrf_spiflash -w firmware/hackrf_usb/build/hackrf_usb.bin +EXIT_CODE="$?" +if [ "$EXIT_CODE" == "1" ] +then + echo "No GreatFET found! Disconnected? Exiting.." + exit $EXIT_CODE +elif [ "$EXIT_CODE" == "0" ] +then + echo "Firmware successfully flashed!" +elif [ "$EXIT_CODE" == "127" ] +then + echo "Host tool installation failed! Exiting.." + exit $EXIT_CODE +else + echo "god have mercy on your soul" + exit $EXIT_CODE +fi \ No newline at end of file diff --git a/ci-scripts/test-firmware-program.sh b/ci-scripts/test-firmware-program.sh new file mode 100755 index 00000000..16a4fe2a --- /dev/null +++ b/ci-scripts/test-firmware-program.sh @@ -0,0 +1,21 @@ +#!/bin/bash +usbhub --disable-i2c --hub D9D1 power state --port 2 --reset +sleep 1s +dfu-util --path 1-2.2 --alt 0 --download firmware/hackrf_usb/build/hackrf_usb.dfu +EXIT_CODE="$?" +if [ "$EXIT_CODE" == "0" ] +then + echo "DFU installation success! Exiting.." + exit $EXIT_CODE +elif [ "$EXIT_CODE" == "74" ] +then + echo "No DFU capable USB device available! Disconnected? Exiting.." + exit 1 +elif [ "$EXIT_CODE" == "127" ] +then + echo "dfu-util installation failed! Exiting.." + exit $EXIT_CODE +else + echo "god have mercy on your soul" + exit $EXIT_CODE +fi \ No newline at end of file diff --git a/ci-scripts/test-host.sh b/ci-scripts/test-host.sh new file mode 100755 index 00000000..0a7ec7a3 --- /dev/null +++ b/ci-scripts/test-host.sh @@ -0,0 +1,21 @@ +#!/bin/bash +usbhub --disable-i2c --hub D9D1 power state --port 2 --reset +sleep 1s +host/build/hackrf-tools/src/hackrf_info +EXIT_CODE="$?" +if [ "$EXIT_CODE" == "1" ] +then + echo "Host tool installation success! Exiting.." + exit 0 +elif [ "$EXIT_CODE" == "0" ] +then + echo "Failed to boot HackRF into DFU mode! Check DFU pin jumper. Exiting.." + exit 1 +elif [ "$EXIT_CODE" == "127" ] +then + echo "Host tool installation failed! Exiting.." + exit $EXIT_CODE +else + echo "god have mercy on your soul" + exit $EXIT_CODE +fi \ No newline at end of file