From e0c6872cf40896c7be36b11dcc744620f10adf1d Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 2 Sep 2019 13:46:59 +0900 Subject: Initial commit --- macros/latex/contrib/avremu/test-suite/FOOTER | 1 + macros/latex/contrib/avremu/test-suite/HEADER | 10 + .../contrib/avremu/test-suite/complex-memory.c | 22 ++ .../latex/contrib/avremu/test-suite/empty-main.c | 10 + .../contrib/avremu/test-suite/fibonacci-rec.c | 20 ++ macros/latex/contrib/avremu/test-suite/float.c | 41 ++++ macros/latex/contrib/avremu/test-suite/func-ptr.c | 22 ++ .../latex/contrib/avremu/test-suite/mandelbrot.c | 116 +++++++++++ macros/latex/contrib/avremu/test-suite/mul.c | 52 +++++ macros/latex/contrib/avremu/test-suite/printf.c | 69 +++++++ macros/latex/contrib/avremu/test-suite/shift.c | 26 +++ macros/latex/contrib/avremu/test-suite/string.c | 22 ++ macros/latex/contrib/avremu/test-suite/sum-rec.c | 23 +++ macros/latex/contrib/avremu/test-suite/test-suite | 223 +++++++++++++++++++++ 14 files changed, 657 insertions(+) create mode 100644 macros/latex/contrib/avremu/test-suite/FOOTER create mode 100644 macros/latex/contrib/avremu/test-suite/HEADER create mode 100644 macros/latex/contrib/avremu/test-suite/complex-memory.c create mode 100644 macros/latex/contrib/avremu/test-suite/empty-main.c create mode 100644 macros/latex/contrib/avremu/test-suite/fibonacci-rec.c create mode 100644 macros/latex/contrib/avremu/test-suite/float.c create mode 100644 macros/latex/contrib/avremu/test-suite/func-ptr.c create mode 100644 macros/latex/contrib/avremu/test-suite/mandelbrot.c create mode 100644 macros/latex/contrib/avremu/test-suite/mul.c create mode 100644 macros/latex/contrib/avremu/test-suite/printf.c create mode 100644 macros/latex/contrib/avremu/test-suite/shift.c create mode 100644 macros/latex/contrib/avremu/test-suite/string.c create mode 100644 macros/latex/contrib/avremu/test-suite/sum-rec.c create mode 100755 macros/latex/contrib/avremu/test-suite/test-suite (limited to 'macros/latex/contrib/avremu/test-suite') diff --git a/macros/latex/contrib/avremu/test-suite/FOOTER b/macros/latex/contrib/avremu/test-suite/FOOTER new file mode 100644 index 0000000000..815ab681a2 --- /dev/null +++ b/macros/latex/contrib/avremu/test-suite/FOOTER @@ -0,0 +1 @@ +\end{document} \ No newline at end of file diff --git a/macros/latex/contrib/avremu/test-suite/HEADER b/macros/latex/contrib/avremu/test-suite/HEADER new file mode 100644 index 0000000000..2df95b0ee7 --- /dev/null +++ b/macros/latex/contrib/avremu/test-suite/HEADER @@ -0,0 +1,10 @@ +\documentclass{article} +\usepackage{graphicx} + +\usepackage[debug]{avremu} +\useavremulibrary{avr.draw} + +\errorcontextlines=23 + +\begin{document} +\makeatletter diff --git a/macros/latex/contrib/avremu/test-suite/complex-memory.c b/macros/latex/contrib/avremu/test-suite/complex-memory.c new file mode 100644 index 0000000000..a05bfdf2ad --- /dev/null +++ b/macros/latex/contrib/avremu/test-suite/complex-memory.c @@ -0,0 +1,22 @@ +#include + +volatile char foo[30]; + +int main() { + foo[0] = 23; + foo[1] = 42; + foo[2] = foo[0] + foo[1]; + + asm volatile ("break"); +} + +/* + check-name: Complex Memory Operations + check-start: + \avr@instr@stepn{1000} + + \avr@test@MEM{96}{00010111} % 23 + \avr@test@MEM{97}{00101010} % 42 + \avr@test@MEM{98}{01000001} % 65 + check-end: +*/ diff --git a/macros/latex/contrib/avremu/test-suite/empty-main.c b/macros/latex/contrib/avremu/test-suite/empty-main.c new file mode 100644 index 0000000000..fa0d0dc57d --- /dev/null +++ b/macros/latex/contrib/avremu/test-suite/empty-main.c @@ -0,0 +1,10 @@ +int main() { + asm volatile ("break"); +} + +/** + check-name: Run simple main Function + check-start: +\avr@instr@stepn{5000} + check-end: +**/ diff --git a/macros/latex/contrib/avremu/test-suite/fibonacci-rec.c b/macros/latex/contrib/avremu/test-suite/fibonacci-rec.c new file mode 100644 index 0000000000..a3f2f6edf3 --- /dev/null +++ b/macros/latex/contrib/avremu/test-suite/fibonacci-rec.c @@ -0,0 +1,20 @@ +#include + +char fib(char n) { + if (n <= 1) { + return 1; + } + return fib(n-1) + fib(n-2); +} + +int main() { + UDR = fib(5); + asm volatile ("break"); +} +/* + check-name: Fibonacci (Recursive) + check-start: + \avr@instr@stepn{1000} + \avr@test@REG{r24}{00001000} + check-end: +*/ diff --git a/macros/latex/contrib/avremu/test-suite/float.c b/macros/latex/contrib/avremu/test-suite/float.c new file mode 100644 index 0000000000..af6a8edebc --- /dev/null +++ b/macros/latex/contrib/avremu/test-suite/float.c @@ -0,0 +1,41 @@ +#include +#include + +static int uart_putchar(char c, FILE *stream); +static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, + _FDEV_SETUP_WRITE); +static int +uart_putchar(char c, FILE *stream) +{ + UDR = c; + return 0; +} + +volatile uint16_t xxx = 65; + +int +main(void) +{ + stdout = &mystdout; + + volatile float a = 0.23; + volatile float b = 0.43; + + printf("%.2f", 1/ (a * b * 3)); + asm volatile("break;"); + + return 0; +} + + +/** + check-name: Calculate with floats + compiler-opts: -Wl,-u,vfprintf -lm -lprintf_flt + + check-start: + + \avr@instr@stepn{100000} + \avr@test@UDR{3.37} + + check-end: +**/ diff --git a/macros/latex/contrib/avremu/test-suite/func-ptr.c b/macros/latex/contrib/avremu/test-suite/func-ptr.c new file mode 100644 index 0000000000..e42f26dbf6 --- /dev/null +++ b/macros/latex/contrib/avremu/test-suite/func-ptr.c @@ -0,0 +1,22 @@ +#include + +// Produces LPM operations +__attribute__((noinline)) void bar() { + UDR='X'; +} +void (*foo)() = bar; + +int main() { + bar(); + foo(); + asm volatile ("break"); +} + +/* + check-name: Function Pointers + check-start: + \avr@instr@stepn{1000000} + + \avr@test@UDR{XX} + check-end: +*/ diff --git a/macros/latex/contrib/avremu/test-suite/mandelbrot.c b/macros/latex/contrib/avremu/test-suite/mandelbrot.c new file mode 100644 index 0000000000..e5be7e7e8d --- /dev/null +++ b/macros/latex/contrib/avremu/test-suite/mandelbrot.c @@ -0,0 +1,116 @@ +/** mandel.c by Eric R. Weeks written 9-28-96 + ** weeks@physics.emory.edu + ** http://www.physics.emory.edu/~weeks/ + ** + ** This program is public domain, but this header must be left intact + ** and unchanged. + ** + **/ + +#include + +#define CMD_COLOR 1 +#define CMD_DOT 2 + + + +static +void setcolor(uint8_t r, uint8_t g, uint8_t b) { + TWDR = r; + TWDR = g; + TWDR = b; + TWAR = CMD_COLOR; +} + +static +void dot(uint8_t x, uint8_t y) { + TWDR = x, TWDR = y; + TWAR = CMD_DOT; +} + + +/* Colors +import colorsys +def color(i): + h = i/float(100) + s = 1.0 + v = h + print h, s, v + x = colorsys.hsv_to_rgb(h, s, v) + return (str(int(x[0] * 255)), + str(int(x[1] * 255)), + str(int(x[2] * 255))) + +colors = [color (i) for i in range(0, 100)] + +print "char color_R[] = {%s};" % (",".join([x[0] for x in colors])) +print "char color_G[] = {%s};" % (",".join([x[1] for x in colors])) +print "char color_B[] = {%s};" % (",".join([x[2] for x in colors])) + */ + +char color_R[] = {0,2,5,7,10,12,15,17,20,22,25,28,30,33,35,38,40,42,42,41,40,39,38,36,34,31,29,26,22,19,15,11,6,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,13,24,35,47,58,70,83,95,108,121,135,149,163,177,192,207,214,216,219,221,224,226,229,232,234,237,239,242,244,247,249,252}; +char color_G[] = {0,0,0,1,2,3,5,7,9,12,15,18,22,25,29,34,39,43,45,48,51,53,56,58,61,63,66,68,71,73,76,79,81,84,86,89,91,94,96,99,102,104,107,109,112,114,117,119,122,124,127,122,116,110,104,98,91,84,76,69,61,52,44,35,26,16,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +char color_B[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,8,14,20,27,33,40,48,55,63,71,80,89,98,107,117,127,130,132,135,137,140,142,145,147,150,153,155,158,160,163,165,168,170,173,175,178,181,183,186,188,191,193,196,198,201,204,206,209,211,205,195,184,173,161,149,137,125,112,99,86,72,58,44,29,15}; + + +int main() { + + float x,xx,y,cx,cy; + uint8_t iteration; + uint8_t hx,hy; +#define itermax 100 /* how many iterations to do */ +#define magnify 4.0 /* no magnification */ +#define hxres 250 /* horizonal resolution */ +#define hyres 250 /* vertical resolution */ +#define ydelta 0 +#define xdelta -0.75 + + uint8_t i; + for (hy=1;hy<=hyres;hy++) { + for (hx=1;hx<=hxres;hx++) { + cx = (((float)hx)/((float)hxres)-0.5)/magnify*3.0-0.7; + cy = (((float)hy)/((float)hyres)-0.5)/magnify*3.0; + cx += xdelta; + cy += ydelta; + x = 0.0; y = 0.0; + for (iteration=1; iteration < itermax; iteration++) { + xx = x*x-y*y+cx; + y = 2.0*x*y+cy; + x = xx; + if (x*x+y*y>128.0){ + i = iteration; + iteration = itermax + 1; + } + } + // Print a dot + if (iteration + +volatile char foo[30]; + +int main() { + foo[0] = 23; + foo[1] = 42; + // Should produce a mul + foo[2] = foo[0] * foo[1]; + + // Contains a decrement (8 Bit Dividend) + foo[3] = (unsigned char)((unsigned char )foo[1] / (unsigned char)foo[0]); + + foo[4] = foo[1] % foo[0]; + + volatile uint16_t x = 1000; + volatile uint16_t y = 55; + + foo[5] = x * y; + foo[20] = 165; + + itoa((unsigned char)foo[20], &foo[6], 10); + itoa((signed char)foo[20], &foo[9], 10); + + + asm volatile ("break"); +} + +/* + check-name: Complex Memory Operations + check-start: + \avr@instr@stepn{100000} + + \avr@test@MEM{96}{00010111} % 23 + \avr@test@MEM{97}{00101010} % 42 + \avr@test@MEM{98}{11000110} % 198 + + \avr@test@MEM{99}{00000001} % 1 + \avr@test@MEM{100}{00010011} % 19 + + \avr@test@MEM{101}{11011000} % 216 + + \avr@test@MEM{102}{00110001} % '1' + \avr@test@MEM{103}{00110110} % '6' + \avr@test@MEM{104}{00110101} % '5' + + \avr@test@MEM{105}{00101101} % '-' + \avr@test@MEM{106}{00111001} % '9' + \avr@test@MEM{107}{00110001} % '1' + + check-end: +*/ diff --git a/macros/latex/contrib/avremu/test-suite/printf.c b/macros/latex/contrib/avremu/test-suite/printf.c new file mode 100644 index 0000000000..e8d14fb078 --- /dev/null +++ b/macros/latex/contrib/avremu/test-suite/printf.c @@ -0,0 +1,69 @@ +#include +#include + +char buffer[30]; + +volatile char buf[3]; + +static int uart_putchar(char c, FILE *stream); +static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, + _FDEV_SETUP_WRITE); +static int +uart_putchar(char c, FILE *stream) +{ + UDR = c; + return 0; +} + + +int +main(void) +{ + stdout = &mystdout; + + buf[0] = 'x'; + buf[1] = 'y'; + buf[2] = '\0'; + + puts(buf); + + + asm volatile("break;"); + + printf(":%c", buf[0]); + + asm volatile("break;"); + + printf(":%d:", buf[1]); + + asm volatile("break;"); + + volatile float x=0.23; + printf(":%.2f:", x); + + asm volatile("break;"); + + return 0; +} + + +/** + check-name: Print to Stdout + compiler-opts: -Wl,-u,vfprintf -lm -lprintf_flt + check-start: + + \avr@instr@stepn{100000} + \avr@test@UDR{xy^10} % ^10 == \n + \def\avr@UDR{} + + \avr@instr@stepn{100000} + \avr@test@UDR{:x} + + \avr@instr@stepn{100000} + \avr@test@UDR{:121:} + + \avr@instr@stepn{100000} + \avr@test@UDR{:0.23:} + + check-end: +**/ diff --git a/macros/latex/contrib/avremu/test-suite/shift.c b/macros/latex/contrib/avremu/test-suite/shift.c new file mode 100644 index 0000000000..fe64b4ca20 --- /dev/null +++ b/macros/latex/contrib/avremu/test-suite/shift.c @@ -0,0 +1,26 @@ +#include + +volatile char foo[30]; + +int main() { + foo[0] = 5; + foo[1] = 42; + foo[2] = foo[1] >> foo[0]; + foo[3] = foo[1] << (foo[0]>>2); + + + asm volatile ("break"); +} + +/* + check-name: Shift Operations + check-start: + \avr@instr@stepn{1000} + + \avr@test@MEM{96}{00000101} % 5 + \avr@test@MEM{97}{00101010} % 42 + \avr@test@MEM{98}{00000001} % 0 + \avr@test@MEM{99}{01010100} % 42 + + check-end: +*/ diff --git a/macros/latex/contrib/avremu/test-suite/string.c b/macros/latex/contrib/avremu/test-suite/string.c new file mode 100644 index 0000000000..616598884e --- /dev/null +++ b/macros/latex/contrib/avremu/test-suite/string.c @@ -0,0 +1,22 @@ +#include + +// Produces LPM operations +const char *foo = "abc"; + +int main() { + char* p = foo; + while (*p) { + UDR = *p++; + } + + asm volatile ("break"); +} + +/* + check-name: String Operations + check-start: + \avr@instr@stepn{1000000} + + \avr@test@UDR{abc} + check-end: +*/ diff --git a/macros/latex/contrib/avremu/test-suite/sum-rec.c b/macros/latex/contrib/avremu/test-suite/sum-rec.c new file mode 100644 index 0000000000..0fa00fc6bc --- /dev/null +++ b/macros/latex/contrib/avremu/test-suite/sum-rec.c @@ -0,0 +1,23 @@ +#include + +char sum(char n) { + if (n <= 1) { + return n; + } + return n + sum(n-1); +} + +int main() { + UDR = sum(4); + asm volatile ("break"); +} + +/* + check-name: Complex Memory Operations + check-start: + + \avr@instr@stepn{1000} + \avr@test@REG{r24}{00001010} + + check-end: +*/ diff --git a/macros/latex/contrib/avremu/test-suite/test-suite b/macros/latex/contrib/avremu/test-suite/test-suite new file mode 100755 index 0000000000..e54a739f40 --- /dev/null +++ b/macros/latex/contrib/avremu/test-suite/test-suite @@ -0,0 +1,223 @@ +#!/bin/bash + +#set -x + +default_path=".." +tests_list=`find . -name '*.c' | sed -e 's#^\./\(.*\)#\1#' | sort` +prog_name=`basename $0` + +export TEXINPUTS=$PWD/..//:$TEXINPUTS + +# counts: +# - tests that have not been converted to test-suite format +# - tests that passed +# - tests that failed +# - tests that failed but are known to fail +unhandled_tests=0 +ok_tests=0 +ko_tests=0 +known_ko_tests=0 + + +# defaults to not verbose +[ -z "$V" ] && V=0 + +## +# get_value(key, file) - gets the value of a (key, value) pair in file. +# +# returns 0 on success, 1 if the file does not have the key +get_value() +{ + last_result=`grep $1: $2 | sed -e "s/^.*$1:\(.*\)$/\1/"` + [ -z "$last_result" ] && return 1 + return 0 +} + +## +# get_tag(key, file) - does file has the tag key in it ? +# +# returns 0 if present, 1 otherwise +get_tag() +{ + last_result=`grep $1 $2` + return $? +} + +## +# verbose(string) - prints string if we are in verbose mode +verbose() +{ + [ "$V" -eq "1" ] && echo " $1" + return 0 +} + +## +# error(string[, die]) - prints an error and exits with value die if given +error() +{ + echo " error: $1" + [ -n "$2" ] && exit $2 + return 0 +} + +do_usage() +{ +echo "$prog_name - a tiny automatic testing script" +echo "Usage: $prog_name [command] [command arguments]" +echo +echo "commands:" +echo " none runs the whole test suite" +echo " single file runs the test in 'file'" +echo +echo " help prints usage" +} + +## +# do_test(file) - tries to validate a test case +# +# it "parses" file, looking for check-* tags and tries to validate +# the test against an expected result +# returns: +# - 0 if the test passed, +# - 1 if it failed, +# - 2 if it is not a "test-suite" test. +do_test() +{ + test_failed=0 + file="$1" + + # can this test be handled by test-suite ? + # (it has to have a check-name key in it) + get_value "check-name" $file + if [ "$?" -eq 1 ]; then + echo "warning: test '$file' unhandled" + unhandled_tests=`expr $unhandled_tests + 1` + return 2 + fi + test_name=$last_result + + echo -n "TEST $test_name ($file)" + + cp HEADER "$file".tex + get_value compiler-opts "$file" + echo "\avrloadc[-Os -mmcu=atmega8 $last_result]{$file}" >> "$file".tex + + awk '/check-start/,/check-end/ {print}' $file \ + | egrep -v 'check-(start|end)' >> "$file".tex + cat FOOTER >> "$file".tex + + + # grab the actual output & exit value + pdflatex -halt-on-error -shell-escape "$file".tex 1> $file.output 2> $file.error + actual_exit_value=$? + rm -f *.log *.aux + + if [ "$actual_exit_value" -ne 0 ]; then + echo + error " Actual exit value does not match the expected one." + error " expected 0, got $actual_exit_value" + if [ x"$V" = x"1" ]; then + cat $file.output | sed 's/^/ /' + else + tail -n 10 $file.output | sed 's/^/ /' + fi + test_failed=1 + else + get_value BREAK "$file".output + echo " ($last_result)" | sed 's/ instructions//' | tr -d "\n" + echo + fi + + if [ "$test_failed" -eq "1" ]; then + ko_tests=`expr $ko_tests + 1` + get_tag "check-known-to-fail" $file + if [ "$?" -eq "0" ]; then + echo "info: test '$file' is known to fail" + known_ko_tests=`expr $known_ko_tests + 1` + fi + return 1 + else + ok_tests=`expr $ok_tests + 1` + return 0 + fi +} + +pwait() { + # This functions blocks until less than $1 subprocesses are running + jobs="$1" + [ -z "$jobs" ] && jobs=5 + + while [ $(jobs -r | wc -l) -gt "$jobs" ]; do + sleep 0.5 + done +} + +do_test_suite() +{ + for i in $tests_list; do + if get_value "check-long" "$i" > /dev/null; then + echo "IGNORED $i (long running)" + continue + fi + do_test "$i" + done + + # prints some numbers + tests_nr=`expr $ok_tests + $ko_tests` + echo -n "Out of $tests_nr tests, $ok_tests passed, $ko_tests failed" + echo " ($known_ko_tests of them are known to fail)" + if [ "$unhandled_tests" -ne "0" ]; then + echo "$unhandled_tests tests could not be handled by $prog_name" + fi +} + +## +# arg_file(filename) - checks if filename exists +arg_file() +{ + [ -z "$1" ] && { + do_usage + exit 1 + } + [ -e "$1" ] || { + error "Can't open file $1" + exit 1 + } + return 0 +} + +case "$1" in + '') + do_test_suite + if test `expr $ko_tests - $known_ko_tests` -gt 0; then + for f in *.error.diff *.output.diff; do + if test -s "$f"; then + echo "Contents of $f:" + cat "$f" + echo "===" + fi + done + exit 1 + fi + ;; + single) + arg_file "$2" + do_test "$2" + case "$?" in + 0) echo "$2 passed !";; + 1) echo "$2 failed !";; + 2) echo "$2 can't be handled by $prog_name";; + esac + ;; + format) + arg_file "$2" + do_format "$2" "$3" "$4" + ;; + help | *) + do_usage + exit 1 + ;; +esac + +exit 0 + -- cgit v1.2.3