diff --git a/.gitignore b/.gitignore index 2f90cba..d0f8570 100644 --- a/.gitignore +++ b/.gitignore @@ -21,10 +21,6 @@ bin *.tar.gz # logs *.log -# binaries generated in testing -cmd/server/server -cmd/reactor/reactor -cmd/tui/tui # task related .task diff --git a/.task/checksum/go-build b/.task/checksum/go-build index c7012f1..464558c 100644 --- a/.task/checksum/go-build +++ b/.task/checksum/go-build @@ -1 +1 @@ -b43ecff1fe53e18c4c9b756b32d38078 +fe0b33dbcc236558952eb8f9f91422c9 diff --git a/README.md b/README.md index d436af9..c818c63 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,8 @@ The project uses a make alternative called [task](https://github.com/go-task/tas After using `git clone git@github.com:fl-src/FRMS.git` to clone the repository, you can then build binaries of the two commands `server` and `reactor` for testing. The binaries will be put into the `bin/` folder and will be labeled with the platform and architecture they were built for. -**WARNING**: The reactor binary currently relies on a Linux cli application to interact with the i2c bus. -This may cause undefined behavior when run on a device without the tools installed. More information about this design choice can be found [here](wiki/reactor.md#i2c-issues) +**WARNING**: The reactor binary currently relies on the Linux [i2c-tools](https://archive.kernel.org/oldwiki/i2c.wiki.kernel.org/index.php/I2C_Tools.html) to interact with the i2c bus. +This may cause undefined behavior when run on a device without the tools installed. More information about this design choice can be found [here](wiki/reactor.md#i2c) ### Usage diff --git a/Taskfile.dist.yml b/Taskfile.dist.yml index e1956da..780f4be 100644 --- a/Taskfile.dist.yml +++ b/Taskfile.dist.yml @@ -4,14 +4,19 @@ tasks: clean: desc: "clean all of the old binaries" cmds: - - rm -v bin/* 2>/dev/null + - rm -vf bin/frms_* 2>/dev/null + + test: + desc: "Runs the full test suite" + cmds: + - bin/gotest.py all: - desc: "cleans and builds all" - deps: [clean, bb, server] + desc: "builds arm reactor binaries and arm/amd server binaries" + deps: [arm32-reactor, arm64-reactor, arm64-server, amd64-server] - bb: - desc: "Builds and sends to the beaglebone" + arm32-reactor: + desc: "Builds reactor binary for 32 bit arm linux device" cmds: - task: go-build vars: @@ -19,31 +24,45 @@ tasks: GOARCH: "arm" GOOS: "linux" BUILD_DIR: "reactor" - - scp bin/reactor_linux_arm debian:~/ - server: - desc: "Builds server binary" + arm64-reactor: + desc: "Builds reactor binary for 64 bit arm linux device" + cmds: + - task: go-build + vars: + GOARCH: "arm64" + GOOS: "linux" + BUILD_DIR: "reactor" + + arm64-server: + desc: "Builds server binary for 64 bit arm linux device" + cmds: + - task: go-build + vars: + GOARCH: "arm64" + GOOS: "linux" + BUILD_DIR: "server" + + amd64-server: + desc: "Builds server binary for amd linux machine" cmds: - task: go-build - vars: + vars: + GOARCH: "amd64" + GOOS: "linux" BUILD_DIR: "server" - GOOS: "{{OS}}" - GOARCH: "{{ARCH}}" go-build: internal: true cmds: - - go build -o bin/{{.BUILD_DIR}}_{{.GOOS}}_{{.GOARCH}} cmd/{{.BUILD_DIR}}/main.go + - go build -o bin/frms_{{.BUILD_DIR}}_{{.GOOS}}_{{.GOARCH}} cmd/{{.BUILD_DIR}}/main.go sources: - internal/pkg/**/*.go - cmd/{{.BUILD_DIR}}/main.go generates: - - bin/{{.BUILD_DIR}}_{{.GOOS}}_{{.GOARCH}} + - bin/frms_{{.BUILD_DIR}}_{{.GOOS}}_{{.GOARCH}} env: GOARM: "{{.GOARM}}" GOARCH: "{{.GOARCH}}" GOOS: "{{.GOOS}}" - test: - desc: "Runs the full test suite" - cmds: - - ./gotest.py + diff --git a/build.sh b/build.sh deleted file mode 100755 index 3dbe3fe..0000000 --- a/build.sh +++ /dev/null @@ -1,149 +0,0 @@ -#!/bin/bash - -# adding commands -usage() { - # how to use this build script - cat </dev/null - else - read -p "Clean old builds?(y/n) " -n 1 -r - if [[ $REPLY =~ ^[Yy]$ ]] ; then - rm -v bin/* 2>/dev/null - fi - fi - printf 'Clean!\n' -} - -create_build() { - # create build for $1 - case $1 in - 'rpi' ) - printf 'Building for Raspberry Pi!\n' - GARCH="arm64" - PLATFORM="reactor" - ;; - 'bb') - printf 'Building for BeagleBone!\n' - GARCH="arm" - GARM="GOARM=7" - PLATFORM="reactor" - ;; - 's') - printf 'Building for Server!\n' - GARCH="amd64" - PLATFORM="server" - ;; - 'd') - printf 'Building for Desktop!\n' - GARCH="amd64" - PLATFORM="server" - ;; - * ) - printf 'ERROR: %s type unrecognized!\n' "$1" - usage - exit 1 - ;; - esac - # setting up build - OUTFILE=$(printf '%s_linux_%s' "$PLATFORM" "$GARCH") - INFILE=$(printf '%s/main.go' "$PLATFORM") - # building - env GOOS=linux GOARCH="$GARCH" $GARM go build -o bin/"$OUTFILE" cmd/"$INFILE" - echo "Finished" - if [[ "$SCP"=true ]] ; then - printf 'Attempting to transfer to %s\n' "$2" - if [[ "$1" == "bb" ]] ; then - printf 'Copying to %s\n' "192.168.100.90" - scp "$HOME/FRMS/bin/$OUTFILE" debian:~/ - else - printf 'SCP Not available!\n' - fi - fi -} - -# handle long form -for arg in "$@"; do - shift - case "$arg" in - '--help') set -- "$@" "-h" ;; - '--list') set -- "$@" "-l" ;; - '--scp') set -- "$@" "-s" ;; - '--clean') set -- "$@" "-c" ;; - '--force') set -- "$@" "-f" ;; - *) set -- "$@" "$arg" ;; - esac -done - -# handle args -while getopts "lcsfh" opt ; do - case "$opt" in - 'h' ) - usage - exit 0 - ;; - 'c' ) - clean_builds - ;; - 'f' ) - FORCE=true - clean_builds - ;; - 's' ) - SCP=true - ;; - 'l') - list_systems - ;; - '?' ) - usage - exit 1 - ;; - esac -done - -shift $(($OPTIND - 1)) - -for dev in "$@"; do - case "$dev" in - 'RaspberryPi') dev='rpi' ;; - 'BeagleBone') dev='bb' ;; - 'Server') dev='s' ;; - 'Desktop') dev='d' ;; - esac - create_build "$dev" -done -printf 'Nothing else to do!\n' - -# echo "Compressing binaries for distrubution" -# tar -czf pireactor.tar.gz -C bin reactor_linux_arm64 -# tar -czf bbreactor.tar.gz -C bin reactor_linux_arm -# tar -czf server.tar.gz -C bin server_linux_amd64 -# tar -czf tui.tar.gz -C bin tui_linux_amd64 tui_linux_arm tui_linux_arm64 diff --git a/Dockerfile.reactor b/docker/Dockerfile.reactor similarity index 97% rename from Dockerfile.reactor rename to docker/Dockerfile.reactor index 371d40e..43d7023 100644 --- a/Dockerfile.reactor +++ b/docker/Dockerfile.reactor @@ -3,7 +3,7 @@ FROM --platform=$BUILDPLATFORM golang:1.18-alpine as builder WORKDIR /app -COPY . . +COPY ../ . RUN go mod download diff --git a/Dockerfile.server b/docker/Dockerfile.server similarity index 100% rename from Dockerfile.server rename to docker/Dockerfile.server diff --git a/docker-compose.yml b/docker/docker-compose.yml similarity index 100% rename from docker-compose.yml rename to docker/docker-compose.yml diff --git a/gotest.py b/gotest.py deleted file mode 100755 index 1fa03c9..0000000 --- a/gotest.py +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env python -import json -import subprocess - -class PackageTest: - def __init__(self): - self.status = "" - self.tests = [] - self.totaltime = 0 - -res = {} - -output = subprocess.run(["go","test","-count=1","-json","./..."], capture_output=True, text=True) - -output = str(output.stdout) -output = output.split('\n') - -for line in output[:-1]: - # parse the json - parsed = json.loads(line) - action = parsed["Action"] - - # skip - if action in ["start", "output", "run"]: - continue - - # create blank if doesn't exist - if parsed["Package"] not in res: - res[parsed["Package"]] = PackageTest() - - pkg = res[parsed["Package"]] - - if "Test" not in parsed: - # top level package result - pkg.status = action - if "Elapsed" in parsed: - pkg.totaltime = parsed["Elapsed"] - else: - # individual test - pkg.tests.append((parsed["Test"],parsed["Action"],parsed["Elapsed"])) - -totalRan = 0 -totalPassed = 0 -totalTime = 0 -# generating output from parsed json -for name, info in res.items(): - pkgname = name.split('/') - pkgname = '/'.join(name.split('/')[1:]) - if info.status == "skip": - print("Skipped %s" % (pkgname)) - continue - - print("\nTesting %s:" % (pkgname)) - - passed = 0 - total = 0 - - for test in info.tests: - total += 1 - out = [] - if test[1] == "pass": - passed += 1 - out = [" " + test[0] + ":",'\033[32mpass\033[0m ',str(test[2]) + 's'] - elif test[1] == "fail": - out = [" " + test[0] + ":",'\033[31mfail\033[0m ',str(test[2]) + 's'] - - print(f"{out[0] : <30}{out[1] : >5}{out[2] : >8}") - - result = "" - if info.status == "pass": - result = "\033[32mPASSED\033[0m" - else: - result = "\033[31mFAILED\033[0m" - - # keep track of grand totals - totalRan += total - totalPassed += passed - totalTime += info.totaltime - - print(" %s %d/%d in %.3fs/n" % (result, passed, total, info.totaltime)) - - -# output overall test statistics -if totalRan == totalPassed: - result = "\033[32mPASSED\033[0m" -else: - result = "\033[31mFAILED\033[0m" - -print("\nSUMMARY:\n\t%s %d/%d in %.3fs" % (result, totalPassed, totalRan, totalTime)) diff --git a/reactor_build.sh b/reactor_build.sh deleted file mode 100755 index 455f838..0000000 --- a/reactor_build.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -display_usage() { - echo "Usage: $0 reactor_type" -} - -# checking for help options -if [[ $@ == "--help" || $@ == "-h" ]] -then - display_usage - exit 0 -fi - -# checking that arguements are not empty -if [[ -z $1 ]] -then - echo "Type of reactor not specified!" - display_usage - exit 1 -fi - -# checking for valid reactor types -if [[ $1 == "pi" ]] -then - platform="linux/arm64" -elif [[ $1 == "bb" ]] -then - platform="linux/arm/v7" -else - echo "Reactor type $1 not supported!" - echo "Supported reactors include: pi, bb" - display_usage - exit 1 -fi - -# building reactor image - -echo "Building Reactor image for $1 platform=$platform" - -docker buildx build --rm --platform=$platform -f Dockerfile.reactor --tag localhost:5000/reactor . - -echo "Cleaning local images" - -docker image remove localhost:5000/reactor diff --git a/wc.sh b/wc.sh deleted file mode 100755 index 3777a06..0000000 --- a/wc.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -echo $(git ls-files | grep .go | awk '!/pb/' | xargs wc -l | tail -n 1) diff --git a/wiki/reactor.md b/wiki/reactor.md index 72f1bd0..1b4cfaf 100644 --- a/wiki/reactor.md +++ b/wiki/reactor.md @@ -8,8 +8,3 @@ This will describe the hardware used ## I2C - -### Issues - - -Should link here