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