gooptest
2020-09-25
A microcontroller testing framework.
1Gooptest
1.1Motivating Example
Adapted from examples/blink.lisp: (defsuite blink
:core (make-arduino-uno (find-sketch "blink")))
(in-suite blink)
(runtest "Light starts in the off state."
(cycles 1000) ; Sleep for 1000 CPU cycles
(assert-pin :low 13)) ; Assert than pin 13 is low
(runtest "Light turns from off to on at the right time"
(cycles 499 :ms) ; Sleep for 499 milliseconds
(assert-pin :low 13)
(cycles 2 :ms)
(assert-pin :high 13))
(runtest "Light blinks on and off many times."
;; The loop below expects to be started with 400 ms (nominal) until the
;; next blink.
(cycles 100 :ms)
;; Test 10 blinks on and off
(dotimes (i 10)
(assert
(cycles-between (:start '(390 :ms) ; Start checking 390ms from now
:stop '(410 :ms) ; Stop checking 410ms from now
:finally '(500 :ms) ; Return after 500ms from now, to
; exit in a consistent state.
:skip '(1 :ms)) ; Poll the pin every millisecond
(eq :high (pin 13)))) ; Ensure that this condition passes
; some time during the interval.
;; Realistically, you could test a blinker pretty well just using
;; (cycles), without the fancy (cycles-between).
(assert
(cycles-between (:start '(390 :ms)
:stop '(410 :ms)
:finally '(500 :ms)
:skip '(1 :ms))
(eq :low (pin 13)))))))
1.2Setup
1.2.1Dependencies
To emulate AVR cores, you need to install simavr. On Debian and derivatives(that's you, Ubuntu!), simavr is packaged, so run ~sudo apt installlibsimavr~ (you do not need development headers). Elsewhere, download,compile, and install simavr from the link above.To compile Arduino sketches, you'll needarduino-cli.Installation is pretty easy. Put it in your$PATH
if you want gooptest tobe able to automatically compile your sketches. TODO: set a custom path toarduino-cli in a variable.1.2.2Gooptest itself
If you're familiar with Lisp and have a working development environment: Putthis repository into your ASDF load path, then ~(asdf:load-system:gooptest)~. Examples are in the packagegooptest/examples
. You might needto install dependencies via quicklisp.1.3Documentation
Most public functions in gooptest have meaningful documentation strings. Seepackage.lisp for a list of exported symbols, then useyour editor's documentation features for more details.The examples are a more digestible overview of gooptest.
Running the examples should be as simple as (asdf:load-system
:gooptest/examples)
followed by, for example, (gooptest/examples:blink)
to
run the blink example.