summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/avremu
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2014-10-14 22:25:31 +0000
committerKarl Berry <karl@freefriends.org>2014-10-14 22:25:31 +0000
commit0db489324b44568fc4fdd9d194ce6d17203fae88 (patch)
treed14c24184a6da8bdbbb2886ac268350ce77fe1e5 /Master/texmf-dist/source/latex/avremu
parent0f77752d377a5492ac8d36d73cb08ef7098dee64 (diff)
avremu (14oct14)
git-svn-id: svn://tug.org/texlive/trunk@35373 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/avremu')
-rw-r--r--Master/texmf-dist/source/latex/avremu/avremu.tex132
-rw-r--r--Master/texmf-dist/source/latex/avremu/imgs/mandelbrot-128x128.pngbin0 -> 2810 bytes
-rw-r--r--Master/texmf-dist/source/latex/avremu/imgs/mandelbrot-20x20.pngbin0 -> 2777 bytes
-rw-r--r--Master/texmf-dist/source/latex/avremu/imgs/mandelbrot-250x250.pngbin0 -> 8794 bytes
-rw-r--r--Master/texmf-dist/source/latex/avremu/simple-testsuite.tex511
-rw-r--r--Master/texmf-dist/source/latex/avremu/test-suite/FOOTER1
-rw-r--r--Master/texmf-dist/source/latex/avremu/test-suite/HEADER10
-rw-r--r--Master/texmf-dist/source/latex/avremu/test-suite/complex-memory.c22
-rw-r--r--Master/texmf-dist/source/latex/avremu/test-suite/empty-main.c10
-rw-r--r--Master/texmf-dist/source/latex/avremu/test-suite/fibonacci-rec.c20
-rw-r--r--Master/texmf-dist/source/latex/avremu/test-suite/float.c41
-rw-r--r--Master/texmf-dist/source/latex/avremu/test-suite/func-ptr.c22
-rw-r--r--Master/texmf-dist/source/latex/avremu/test-suite/mandelbrot.c116
-rw-r--r--Master/texmf-dist/source/latex/avremu/test-suite/mul.c52
-rw-r--r--Master/texmf-dist/source/latex/avremu/test-suite/printf.c69
-rw-r--r--Master/texmf-dist/source/latex/avremu/test-suite/shift.c26
-rw-r--r--Master/texmf-dist/source/latex/avremu/test-suite/string.c22
-rw-r--r--Master/texmf-dist/source/latex/avremu/test-suite/sum-rec.c23
-rwxr-xr-xMaster/texmf-dist/source/latex/avremu/test-suite/test-suite223
19 files changed, 1300 insertions, 0 deletions
diff --git a/Master/texmf-dist/source/latex/avremu/avremu.tex b/Master/texmf-dist/source/latex/avremu/avremu.tex
new file mode 100644
index 00000000000..3fe7b693e80
--- /dev/null
+++ b/Master/texmf-dist/source/latex/avremu/avremu.tex
@@ -0,0 +1,132 @@
+\documentclass{article}
+\usepackage{avremu}
+\usepackage{listings}
+\usepackage{hyperref}
+\usepackage{filecontents}
+\usepackage{tcolorbox}
+\usepackage{ydoc}
+
+\def\fileversion{v0.1}
+\def\filedate{2014/10/09}
+
+\makeatletter
+\def\cmd#1{\cs{\expandafter\cmd@to@cs\string#1}}
+\def\cmd@to@cs#1#2{\char\number`#2\relax}
+\DeclareRobustCommand\cs[1]{\texttt{\char`\\#1}}
+\makeatother
+
+\begin{filecontents*}{hello-world.c}
+#include <avr/io.h>
+
+int
+main(void)
+{
+ char *str = "Hello World!";
+ char *p = str;
+ while (*p) {
+ UDR = *p++;
+ }
+ asm volatile ("break;");
+}
+\end{filecontents*}
+
+\title{The \texttt{avremu} Package}
+\author{Christian Dietrich\\
+\url{stettberger@dokucode.de}\\
+\url{https://gitlab.brokenpipe.de/stettberger/avremu}}
+
+\begin{document}
+
+\maketitle
+
+\begin{tcolorbox}
+ \lstinputlisting[language=C]{hello-world.c}
+ \tcblower
+ \begin{lstlisting}[language=TeX]
+\avrloadc{hello-world.c}
+\avrrun
+UDR='\avrUDR' in \avrinstrcount\ instructions
+\end{lstlisting}
+\end{tcolorbox}
+\begin{tcolorbox}
+\avrloadc{hello-world.c}\avrrun
+UDR='\avrUDR' in \avrinstrcount\ instructions
+\end{tcolorbox}
+
+
+\LaTeX\ is known as a typesetting system. But the underlying \TeX\ system is a powerful macro
+processor. In fact, TeX is a Turing-complete programming language. \TeX\ can compute anything that
+is computable. Computeability is a concept from theoretical computer science. After visiting a
+theoretical computer-science course, you will know that there are things that cannot be solved by a
+machine. Never. Look out for the halting problem.
+
+This package does contain an \emph{CPU emulator} for the 8-bit microcontroller platform Atmel AVR, more
+precisely it implements the instruction-set architecture of the \texttt{ATmega8}.
+
+\begin{tcolorbox}
+\begin{lstlisting}[language=TeX]
+\avrloadc{mandelbrot.c}
+\avrrun
+
+\avrdrawppm{mandelbrot.ppm}
+\immediate\write18{convert mandelbrot.ppm mandelbrot.png}
+
+\includegraphics[width=\linewidth]{mandelbrot.png}
+\end{lstlisting}
+ \tcblower
+ This picture (250x250) took 44 hours to render. The source code can be found in the test-suite
+ directory under mandelbrot.c.\\
+
+ \includegraphics[width=\linewidth]{imgs/mandelbrot-250x250}
+\end{tcolorbox}
+
+\section{Provided Commands}
+
+\DescribeMacro{\avrloadihex}{\meta{filename}}
+Load an Intel HEX formatted image of the flash into the code memory of the AVR
+emulator. Additionally the state of the AVR emulator is set back to zero.
+
+\DescribeMacro{\avrloadc}[\meta{compiler options}]{\meta{filename}}
+Requires \verb|--shell-escape|. Compiles C source code file with \verb|avr-gcc| and the given
+compiler options. The default compiler option set is \verb|-mmcu=atmega8 -Os|. The resulting
+\texttt{.elf} file is transformed to an Intel HEX file and loaded into the code memory of the
+emulator.
+
+\DescribeMacro{\avrrun}
+Run the emulator until a \textbf{break} instruction occurs.
+
+\DescribeMacro{\avrstep}[\meta{steps}=1]
+Run the emulator for N instructions. The default is a single step. The stepping does automatically
+end, if a \textbf{break} instruction is executed.
+
+\DescribeMacro{\avrinstrcount}
+Expands to the number of executed instructions.
+
+\DescribeMacro{\avrsinglestep}
+Starts an interactive single-stepping mode, which was mainly used for implementing the emulator.
+
+\DescribeMacro{\usravremulibrary}{\meta{list of libraryies}}
+
+\subsection{Access to the Serial Console}
+If the program write to the \verb|UDR| IO register, the emulator catched those characters in an
+internal buffer.
+
+\DescribeMacro{\avrUDR}
+Expands to the internal UDR buffer.
+
+\DescribeMacro{\avrUDRclear}
+Clears the internal UDR buffer.
+
+\subsection{Draw Library}
+\DescribeMacro{\useavremulibrary}{avr.draw}
+
+See source/test-suite/mandelbrot.c for more details.
+
+\section{Implementation Details}
+Read the source.
+\end{document}
+
+%%% Local Variables:
+%%% mode: latex
+%%% TeX-master: t
+%%% End:
diff --git a/Master/texmf-dist/source/latex/avremu/imgs/mandelbrot-128x128.png b/Master/texmf-dist/source/latex/avremu/imgs/mandelbrot-128x128.png
new file mode 100644
index 00000000000..e71b02a3f3b
--- /dev/null
+++ b/Master/texmf-dist/source/latex/avremu/imgs/mandelbrot-128x128.png
Binary files differ
diff --git a/Master/texmf-dist/source/latex/avremu/imgs/mandelbrot-20x20.png b/Master/texmf-dist/source/latex/avremu/imgs/mandelbrot-20x20.png
new file mode 100644
index 00000000000..aa2fe4cdfc5
--- /dev/null
+++ b/Master/texmf-dist/source/latex/avremu/imgs/mandelbrot-20x20.png
Binary files differ
diff --git a/Master/texmf-dist/source/latex/avremu/imgs/mandelbrot-250x250.png b/Master/texmf-dist/source/latex/avremu/imgs/mandelbrot-250x250.png
new file mode 100644
index 00000000000..4f1ad50e1f8
--- /dev/null
+++ b/Master/texmf-dist/source/latex/avremu/imgs/mandelbrot-250x250.png
Binary files differ
diff --git a/Master/texmf-dist/source/latex/avremu/simple-testsuite.tex b/Master/texmf-dist/source/latex/avremu/simple-testsuite.tex
new file mode 100644
index 00000000000..23d851a5299
--- /dev/null
+++ b/Master/texmf-dist/source/latex/avremu/simple-testsuite.tex
@@ -0,0 +1,511 @@
+\documentclass{article}
+\usepackage[debug]{avremu}
+
+\begin{document}
+\makeatletter
+% Hook Macro for the tests
+\def\avr@test{}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\def\avr@test@ADD{%
+ \def\avr@test@helper##1##2{%
+ \avr@test@setup{ADD: ##1+##2}%
+ \avr@instr@LDI{0}{\csuse{avr@r31}}{##1}%
+ \avr@instr@LDI{1}{\csuse{avr@r17}}{##2}%
+ \avr@instr@ADD{2}{\csuse{avr@r17}}{\csuse{avr@r31}}%
+ \avr@instr@stepn{3}%
+ }%
+ \avr@test@helper{00000000}{00000001}%
+ \avr@test@SREG{00000000}%
+ \avr@test@REG{r17}{00000001}%
+ % Test Zero Flag
+ \avr@test@helper{00000000}{00000000}%
+ \avr@test@SREG{00000010}%
+ \avr@test@REG{r17}{00000000}%
+ % Test Carry and Half Carry
+ \avr@test@helper{11111111}{00000010}%
+ \avr@test@SREG{00100001}%
+ \avr@test@REG{r17}{00000001}%
+ % Test V
+ \avr@test@helper{10000000}{10000000}%
+ \avr@test@REG{r17}{00000000}%
+ \avr@test@SREG{00011011}%
+}
+\appto\avr@test{\avr@test@ADD}
+
+\def\avr@test@ADC{%
+ \def\avr@test@helper##1##2##3##4{%
+ \avr@test@setup{ADD: (##1:##2) + (##3:##4)}%
+ \avr@instr@LDI{0}{\csuse{avr@r30}}{##1}%
+ \avr@instr@LDI{1}{\csuse{avr@r31}}{##2}%
+ \avr@instr@LDI{2}{\csuse{avr@r17}}{##3}%
+ \avr@instr@LDI{3}{\csuse{avr@r18}}{##4}%
+ \avr@instr@ADD{4}{\csuse{avr@r18}}{\csuse{avr@r31}}%
+ \avr@instr@ADC{5}{\csuse{avr@r17}}{\csuse{avr@r30}}%
+ \avr@instr@stepn{6}%
+ }%
+ \avr@test@helper{00000000}{10000001}{00000000}{10000000}%
+ \avr@test@REG{r17}{00000001}%
+ \avr@test@SREG{00000000}%
+
+ \avr@test@helper{00000011}{10000001}{00001100}{10000000}%
+ \avr@test@REG{r17}{00010000}%
+ \avr@test@SREG{00100000}%
+
+}
+\appto\avr@test{\avr@test@ADC}
+
+\def\avr@test@SUB{%
+ \def\avr@test@helper##1##2{%
+ \avr@test@setup{SUB: ##1 - ##2}%
+ \avr@instr@LDI{0}{\csuse{avr@r17}}{##1}%
+ \avr@instr@LDI{1}{\csuse{avr@r31}}{##2}%
+ \avr@instr@SUB{2}{\csuse{avr@r17}}{\csuse{avr@r31}}%
+ \avr@instr@stepn{3}%
+ }%
+ \avr@test@helper{00001111}{00000010}%
+ \avr@test@REG{r17}{00001101}%
+ \avr@test@SREG{00000000}%
+
+ \avr@test@helper{00001111}{00010000}%
+ \avr@test@REG{r17}{11111111}%
+ \avr@test@SREG{00010101}%
+}
+\appto\avr@test{\avr@test@SUB}
+
+\def\avr@test@SBC{%
+ \def\avr@test@helper##1##2##3##4{%
+ \avr@test@setup{SBC: (##1:##2) - (##3:##4)}%
+ \avr@instr@LDI{0}{\csuse{avr@r30}}{##3}%
+ \avr@instr@LDI{1}{\csuse{avr@r31}}{##4}%
+ \avr@instr@LDI{2}{\csuse{avr@r17}}{##1}%
+ \avr@instr@LDI{3}{\csuse{avr@r18}}{##2}%
+ \avr@instr@SUB{4}{\csuse{avr@r18}}{\csuse{avr@r31}}%
+ \avr@instr@SBC{5}{\csuse{avr@r17}}{\csuse{avr@r30}}%
+ \avr@instr@stepn{6}%
+ }%
+ \avr@test@helper{00000000}{10000001}{00000000}{10000001}%
+ \avr@test@REG{r17}{00000000}%
+ \avr@test@REG{r18}{00000000}%
+ \avr@test@SREG{00000010}%
+
+ \avr@test@helper{00000000}{00000000}{00000000}{00000001}%
+ \avr@test@REG{r17}{11111111}%
+ \avr@test@REG{r18}{11111111}%
+ \avr@test@SREG{00110101}%
+
+ \avr@test@helper{00000000}{10000000}{00000000}{00000001}%
+ \avr@test@REG{r17}{00000000}%
+ \avr@test@REG{r18}{01111111}%
+ \avr@test@SREG{00000010}%
+}
+\appto\avr@test{\avr@test@SBC}
+
+\def\avr@test@BRB{%
+ \def\avr@test@helper##1##2##3{%
+ \avr@test@setup{BRB: ##1+##2 => PC+2}%
+ \avr@instr@LDI{0}{\csuse{avr@r30}}{##1}%
+ \avr@instr@LDI{1}{\csuse{avr@r31}}{##2}%
+ \avr@instr@ADD{2}{\csuse{avr@r30}}{\csuse{avr@r31}}%
+ \@@BRB{3}{##3}{1}%
+ \avr@instr@LDI{4}{\csuse{avr@r31}}{11001100}%
+ \avr@instr@LDI{5}{\csuse{avr@r20}}{00000000}%
+ \avr@instr@stepn{5}%
+ }%
+ % Check for cleared flag
+ \def\@@BRB{\avr@instr@BRBC}
+
+ \avr@test@helper{10000000}{10000000}{000}%
+ \avr@test@REG{r31}{11001100}%
+
+ \avr@test@helper{10000000}{00000001}{000}%
+ \avr@test@REG{r31}{00000001}%
+
+ % Check for SET flag
+ \def\@@BRB{\avr@instr@BRBS}
+
+ \avr@test@helper{10000000}{10000000}{000}%
+ \avr@test@REG{r31}{10000000}%
+
+ \avr@test@helper{10000000}{10000001}{100}%
+ \avr@test@REG{r31}{10000001}%
+}
+\preto\avr@test{\avr@test@BRB}
+
+\def\avr@test@fibonacci{%
+ \avr@test@setup{Fibonacci -- fib(8)=21}%
+ \avr@instr@LDI{0}{\csuse{avr@r30}}{00000001}%
+ \avr@instr@LDI{1}{\csuse{avr@r31}}{00000001}%
+ \avr@instr@LDI{2}{\csuse{avr@r20}}{00000101}%
+ \avr@instr@LDI{3}{\csuse{avr@r21}}{00000001}%
+ % tmp = x
+ \avr@instr@MOV{4}{\csuse{avr@r29}}{\csuse{avr@r30}}%
+ % x = x + y
+ \avr@instr@ADD{5}{\csuse{avr@r30}}{\csuse{avr@r31}}%
+ % y = tmp
+ \avr@instr@MOV{6}{\csuse{avr@r31}}{\csuse{avr@r29}}%
+ % i--
+ \avr@instr@SUB{7}{\csuse{avr@r20}}{\csuse{avr@r21}}%
+ \avr@instr@BRPL{8}{-5}
+ \avr@instr@BREAK{9}
+
+ \avr@instr@stepn{100}%
+ \avr@test@REG{r30}{00010101}
+}
+\preto\avr@test{\avr@test@fibonacci}
+
+\def\avr@test@BITOPS{%
+ \avr@test@setup{Bit Operations}%
+ \avr@instr@LDI{0}{\csuse{avr@r30}}{00111100}%
+ \avr@instr@LDI{1}{\csuse{avr@r31}}{00001111}%
+ \avr@instr@AND{2}{\csuse{avr@r30}}{\csuse{avr@r31}}%
+
+ \avr@instr@stepn{3}%
+ \avr@test@REG{r30}{00001100}
+
+ \avr@instr@ANDI{3}{\csuse{avr@r30}}{00001000}%
+ \avr@instr@stepn{1}%
+ \avr@test@REG{r30}{00001000}
+
+ \avr@instr@ORI{4}{\csuse{avr@r20}}{10101010}%
+ \avr@instr@stepn{1}%
+ \avr@test@REG{r20}{10101010}
+
+ \avr@instr@EOR{5}{\csuse{avr@r30}}{\csuse{avr@r20}}%
+ \avr@instr@TST{6}{\csuse{avr@r30}}%
+ \avr@instr@stepn{2}%
+ \avr@test@REG{r30}{10100010}
+}
+\preto\avr@test{\avr@test@BITOPS}
+
+\def\avr@test@SUBI{%
+ \avr@test@setup{SUBI}%
+ \avr@instr@LDI{0}{\csuse{avr@r30}}{00001111}%
+ \avr@instr@SUBI{1}{\csuse{avr@r30}}{00010000}%
+ \avr@instr@SBCI{2}{\csuse{avr@r30}}{00000001}%
+
+ \avr@instr@stepn{2}%
+ \avr@test@REG{r30}{11111111}
+ \avr@test@SREG{00010101}
+
+ \avr@instr@stepn{1}%
+ \avr@test@REG{r30}{11111101}
+ \avr@test@SREG{00010100}
+}
+\preto\avr@test{\avr@test@SUBI}
+
+\def\avr@test@CPI{%
+ \avr@test@setup{CPI}%
+ \avr@instr@LDI{0}{\csuse{avr@r30}}{00001111}%
+ \avr@instr@CPI{1}{\csuse{avr@r30}}{00001111}%
+
+ \avr@instr@stepn{2}%
+ \avr@test@REG{r30}{00001111}
+ \avr@test@SREG{00000010}
+}
+\preto\avr@test{\avr@test@CPI}
+
+\def\avr@test@MOVW{%
+ \avr@test@setup{MOVW}%
+ \avr@instr@LDI{0}{\csuse{avr@r30}}{00001111}%
+ \avr@instr@LDI{1}{\csuse{avr@r31}}{11110000}%
+ \avr@instr@MOVW{2}{\csuse{avr@r2}}{\csuse{avr@r30}}%
+
+ \avr@instr@stepn{3}%
+ \avr@test@REG{r2}{00001111}
+ \avr@test@REG{r3}{11110000}
+ \avr@test@SREG{00000000}
+}
+\preto\avr@test{\avr@test@MOVW}
+
+\def\avr@test@BSET{%
+ \avr@test@setup{BSET}%
+ \avr@instr@SEI{0}%
+ \avr@instr@SEC{1}%
+ \avr@instr@CLI{2}%
+
+ \avr@instr@stepn{2}%
+ \avr@test@SREG{10000001}
+ \avr@instr@stepn{1}%
+ \avr@test@SREG{00000001}
+
+}
+\preto\avr@test{\avr@test@BSET}
+
+\def\avr@test@BST{%
+ \avr@test@setup{BST}%
+ \avr@instr@LDI{0}{\csuse{avr@r31}}{00010000}%
+ \avr@instr@BST{1}{\csuse{avr@r31}}{100}%
+ \avr@instr@BLD{2}{\csuse{avr@r31}}{000}%
+ \avr@instr@CLT{3}
+ \avr@instr@BLD{4}{\csuse{avr@r31}}{100}%
+
+ \avr@instr@stepn{2}%
+ \avr@test@SREG{01000000}
+
+ \avr@instr@stepn{1}
+ \avr@test@REG{r31}{00010001}
+
+ \avr@instr@stepn{2}%
+ \avr@test@SREG{00000000}
+ \avr@test@REG{r31}{00000001}
+}
+\preto\avr@test{\avr@test@BST}
+
+\def\avr@test@NEG{%
+ \avr@test@setup{NEG}%
+ \avr@instr@LDI{0}{\csuse{avr@r20}}{00000001}%
+ \avr@instr@NEG{1}{\csuse{avr@r20}}%
+ \avr@instr@NEG{2}{\csuse{avr@r20}}%
+
+
+ \avr@instr@stepn{2}%
+ \avr@test@REG{r20}{11111111}
+ \avr@test@SREG{00110101}
+
+ \avr@instr@stepn{1}%
+ \avr@test@REG{r20}{00000001}
+ \avr@test@SREG{00100001}
+}
+\preto\avr@test{\avr@test@NEG}
+
+\def\avr@test@COM{%
+ \avr@test@setup{COM}%
+ \avr@instr@LDI{0}{\csuse{avr@r20}}{00000001}%
+ \avr@instr@COM{1}{\csuse{avr@r20}}%
+ \avr@instr@COM{2}{\csuse{avr@r20}}%
+
+
+ \avr@instr@stepn{2}%
+ \avr@test@REG{r20}{11111110}
+ \avr@test@SREG{00010101}
+
+ \avr@instr@stepn{1}%
+ \avr@test@REG{r20}{00000001}
+ \avr@test@SREG{00000001}
+}
+\preto\avr@test{\avr@test@COM}
+
+\def\avr@test@SBR{%
+ \avr@test@setup{SBR[CS]}%
+ \avr@instr@LDI{0}{\csuse{avr@r20}}{00001000}%
+ \avr@instr@SBRS{1}{\csuse{avr@r20}}{011}%
+ \avr@instr@LDI{2}{\csuse{avr@r20}}{00001111}%
+ \avr@instr@NOP{3}
+
+ \avr@instr@stepn{3}%
+ \avr@test@REG{r20}{00001000}
+
+ \avr@instr@SBRS{4}{\csuse{avr@r20}}{010}%
+ \avr@instr@LDI{5}{\csuse{avr@r20}}{00001111}%
+ \avr@instr@NOP{6}
+
+ \avr@instr@stepn{2}%
+ \avr@test@REG{r20}{00001111}
+}
+\preto\avr@test{\avr@test@SBR}
+
+\def\avr@test@ASR{%
+ \avr@test@setup{ASR}%
+ \avr@instr@LDI{0}{\csuse{avr@r20}}{00001001}%
+ \avr@instr@ASR{1}{\csuse{avr@r20}}%
+ \avr@instr@LDI{2}{\csuse{avr@r20}}{10001001}%
+ \avr@instr@ASR{3}{\csuse{avr@r20}}%
+
+ \avr@instr@stepn{2}%
+ \avr@test@REG{r20}{00000100}
+ \avr@test@SREG{00011001}
+
+ \avr@instr@stepn{2}%
+ \avr@test@REG{r20}{11000100}
+ \avr@test@SREG{00010101}
+}
+\preto\avr@test{\avr@test@ASR}
+
+\def\avr@test@LSR{%
+ \avr@test@setup{LSR}%
+ \avr@instr@LDI{0}{\csuse{avr@r20}}{00001001}%
+ \avr@instr@LSR{1}{\csuse{avr@r20}}%
+ \avr@instr@LDI{2}{\csuse{avr@r20}}{10001001}%
+ \avr@instr@LSR{3}{\csuse{avr@r20}}%
+
+
+ \avr@instr@stepn{2}%
+ \avr@test@REG{r20}{00000100}
+ \avr@test@SREG{00011001}
+
+ \avr@instr@stepn{2}%
+ \avr@test@REG{r20}{01000100}
+ \avr@test@SREG{00011001}
+}
+\preto\avr@test{\avr@test@LSR}
+
+\def\avr@test@ROR{%
+ \avr@test@setup{ROR}%
+ \avr@instr@LDI{0}{\csuse{avr@r20}}{00000001}%
+ \avr@instr@ROR{1}{\csuse{avr@r20}}%
+ \avr@instr@ROR{2}{\csuse{avr@r20}}%
+ \avr@instr@ROR{3}{\csuse{avr@r20}}%
+
+
+ \avr@instr@stepn{2}%
+ \avr@test@REG{r20}{00000000}
+ \avr@test@SREG{00011011}
+
+ \avr@instr@stepn{1}%
+ \avr@test@REG{r20}{10000000}
+ \avr@test@SREG{00001100}
+
+ \avr@instr@stepn{1}%
+ \avr@test@REG{r20}{01000000}
+ \avr@test@SREG{00000000}
+}
+\preto\avr@test{\avr@test@ROR}
+
+
+\def\avr@test@LDX{%
+ \avr@test@setup{LDX}%
+ \avr@mem@set{11110111}{257}%
+ \avr@mem@set{11110000}{258}%
+ \avr@mem@set{11110001}{259}%
+
+ \avr@instr@LDI{0}{\csuse{avr@r27}}{00000001}%
+ \avr@instr@LDI{1}{\csuse{avr@r26}}{00000010}%
+ \avr@instr@LDX{2}{\csuse{avr@r20}}%
+ \avr@instr@LDXp{3}{\csuse{avr@r21}}%
+ \avr@instr@LDmX{4}{\csuse{avr@r22}}%
+ \avr@instr@LDmX{5}{\csuse{avr@r23}}%
+ \avr@instr@LDmX{6}{\csuse{avr@r24}}%
+ \avr@instr@LDmX{7}{\csuse{avr@r24}}%
+
+ \avr@instr@stepn{8}%
+ \avr@test@REG{r20}{11110000}
+ \avr@test@REG{r21}{11110000}
+ \avr@test@REG{r22}{11110000}
+ \avr@test@REG{r23}{11110111}
+ \avr@test@REG{r24}{00000000}
+ \avr@test@REG{r26}{11111111}
+ \avr@test@REG{r27}{00000000}
+}
+\preto\avr@test{\avr@test@LDX}
+
+\def\avr@test@STZ{%
+ \avr@test@setup{STZ}%
+
+ \avr@instr@LDI{0}{\csuse{avr@r31}}{00000001}%
+ \avr@instr@LDI{1}{\csuse{avr@r30}}{00000010}%
+ \avr@instr@STZ{2}{\csuse{avr@r30}}%
+ \avr@instr@STmZ{3}{\csuse{avr@r30}}%
+ \avr@instr@STZp{4}{\csuse{avr@r0}}%
+ \avr@instr@STZp{5}{\csuse{avr@r0}}%
+
+ \avr@instr@stepn{4}%
+ \avr@test@MEM{258}{00000010}
+ \avr@test@MEM{257}{00000010}
+
+ \avr@instr@stepn{2}%
+ \avr@test@MEM{258}{00000000}
+ \avr@test@MEM{257}{00000000}
+}
+\preto\avr@test{\avr@test@STZ}
+
+\def\avr@test@SWAP{%
+ \avr@test@setup{SWAP}%
+ \avr@instr@LDI{0}{\csuse{avr@r20}}{00001001}%
+ \avr@instr@SWAP{1}{\csuse{avr@r20}}%
+
+ \avr@instr@stepn{2}%
+ \avr@test@REG{r20}{10010000}
+}
+\preto\avr@test{\avr@test@SWAP}
+
+\def\avr@test@LDSS{%
+ \avr@test@setup{LDS - STS (short)}%
+ \avr@instr@LDI{0}{\csuse{avr@r20}}{00001001}%
+ \avr@instr@STSS{1}{\csuse{avr@r20}}{1101001}%
+ \avr@instr@LDSS{2}{\csuse{avr@r21}}{1101001}%
+
+ \avr@instr@stepn{3}%
+ \avr@test@REG{r21}{00001001}
+}
+\preto\avr@test{\avr@test@LDSS}
+
+\def\avr@test@LDS{%
+ \avr@test@setup{LDS - STS (long)}%
+ \avr@instr@LDI{0}{\csuse{avr@r20}}{00001001}%
+ \avr@instr@STS{1}{\csuse{avr@r20}}{0000000011111111}%
+ \avr@instr@LDS{3}{\csuse{avr@r21}}{0000000011111111}%
+ \avr@instr@SBRC{5}{\csuse{avr@r0}}{011}% Skip always
+ \avr@instr@LDS{6}{\csuse{avr@r20}}{0000000011110000}%
+ \avr@instr@NOP{8}%
+
+ \avr@instr@stepn{5}%
+ \avr@test@REG{r21}{00001001}
+}
+\preto\avr@test{\avr@test@LDS}
+
+\def\avr@test@CPSE{%
+ \avr@test@setup{CPSE}%
+ \avr@instr@LDI{0}{\csuse{avr@r20}}{00001001}%
+ \avr@instr@LDI{1}{\csuse{avr@r21}}{00001001}%
+ \avr@instr@CPSE{2}{\csuse{avr@r20}}{\csuse{avr@r21}}% Skip always
+ \avr@instr@LDI{3}{\csuse{avr@r21}}{00001111}%
+ \avr@instr@NOP{4}%
+
+ \avr@instr@stepn{4}%
+ \avr@test@REG{r21}{00001001}
+}
+\preto\avr@test{\avr@test@CPSE}
+
+\def\avr@test@SBIC{%
+ \avr@test@setup{SBIC}%
+ \avr@instr@LDI{0}{\csuse{avr@r20}}{11110000}%
+ \avr@instr@OUT{1}{001111}{\csuse{avr@r20}}%
+ \avr@instr@SBIC{2}{01111}{111}% Skip never
+ \avr@instr@LDI{3}{\csuse{avr@r21}}{00001111}%
+ \avr@instr@NOP{4}%
+
+ \avr@instr@stepn{5}%
+ \avr@test@REG{r21}{00001111}
+}
+\preto\avr@test{\avr@test@SBIC}
+
+\def\avr@test@ADIW{%
+ \avr@test@setup{SBIC}%
+ \avr@instr@LDI{0}{\csuse{avr@r31}}{11111111}%
+ \avr@instr@LDI{1}{\csuse{avr@r30}}{11000000}%
+ \avr@instr@ADIW{2}{11}{111111}%
+ \avr@instr@ADIW{3}{11}{000001}%
+ \avr@instr@SBIW{4}{11}{000010}%
+
+
+
+ \avr@instr@stepn{3}%
+ \avr@test@REG{r30}{11111111}
+ \avr@test@REG{r31}{11111111}
+ \avr@test@SREG{00010100}
+
+ \avr@instr@stepn{1}%
+ \avr@test@REG{r30}{00000000}
+ \avr@test@REG{r31}{00000000}
+ \avr@test@SREG{00000011}
+
+ \avr@instr@stepn{1}%
+ \avr@test@REG{r30}{11111110}
+ \avr@test@REG{r31}{11111111}
+ \avr@test@SREG{00000101}
+
+}
+\preto\avr@test{\avr@test@ADIW}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Run the test-suite
+
+\avr@test
+
+\end{document}
+%%% Local Variables:
+%%% mode: latex
+%%% TeX-master: t
+%%% End:
+
diff --git a/Master/texmf-dist/source/latex/avremu/test-suite/FOOTER b/Master/texmf-dist/source/latex/avremu/test-suite/FOOTER
new file mode 100644
index 00000000000..815ab681a2f
--- /dev/null
+++ b/Master/texmf-dist/source/latex/avremu/test-suite/FOOTER
@@ -0,0 +1 @@
+\end{document} \ No newline at end of file
diff --git a/Master/texmf-dist/source/latex/avremu/test-suite/HEADER b/Master/texmf-dist/source/latex/avremu/test-suite/HEADER
new file mode 100644
index 00000000000..2df95b0ee7a
--- /dev/null
+++ b/Master/texmf-dist/source/latex/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/Master/texmf-dist/source/latex/avremu/test-suite/complex-memory.c b/Master/texmf-dist/source/latex/avremu/test-suite/complex-memory.c
new file mode 100644
index 00000000000..a05bfdf2adb
--- /dev/null
+++ b/Master/texmf-dist/source/latex/avremu/test-suite/complex-memory.c
@@ -0,0 +1,22 @@
+#include <avr/io.h>
+
+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/Master/texmf-dist/source/latex/avremu/test-suite/empty-main.c b/Master/texmf-dist/source/latex/avremu/test-suite/empty-main.c
new file mode 100644
index 00000000000..fa0d0dc57d5
--- /dev/null
+++ b/Master/texmf-dist/source/latex/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/Master/texmf-dist/source/latex/avremu/test-suite/fibonacci-rec.c b/Master/texmf-dist/source/latex/avremu/test-suite/fibonacci-rec.c
new file mode 100644
index 00000000000..a3f2f6edf33
--- /dev/null
+++ b/Master/texmf-dist/source/latex/avremu/test-suite/fibonacci-rec.c
@@ -0,0 +1,20 @@
+#include <avr/io.h>
+
+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/Master/texmf-dist/source/latex/avremu/test-suite/float.c b/Master/texmf-dist/source/latex/avremu/test-suite/float.c
new file mode 100644
index 00000000000..af6a8edebcf
--- /dev/null
+++ b/Master/texmf-dist/source/latex/avremu/test-suite/float.c
@@ -0,0 +1,41 @@
+#include <avr/io.h>
+#include <stdio.h>
+
+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/Master/texmf-dist/source/latex/avremu/test-suite/func-ptr.c b/Master/texmf-dist/source/latex/avremu/test-suite/func-ptr.c
new file mode 100644
index 00000000000..e42f26dbf66
--- /dev/null
+++ b/Master/texmf-dist/source/latex/avremu/test-suite/func-ptr.c
@@ -0,0 +1,22 @@
+#include <avr/io.h>
+
+// 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/Master/texmf-dist/source/latex/avremu/test-suite/mandelbrot.c b/Master/texmf-dist/source/latex/avremu/test-suite/mandelbrot.c
new file mode 100644
index 00000000000..e5be7e7e8d7
--- /dev/null
+++ b/Master/texmf-dist/source/latex/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 <avr/io.h>
+
+#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<itermax+1) {
+ setcolor(0,0,0);
+ } else {
+ setcolor(color_R[i],
+ color_G[i],
+ color_B[i]);
+ }
+ dot(hx-1, hy-1);
+ }
+ }
+
+ asm volatile ("break");
+}
+
+/*
+ check-name: Mandelbrot Set
+ compiler-opts: -O3
+ check-long: 1
+ check-start:
+ \def\avr@debug#1{}
+
+ \avr@instr@run
+
+ \avrdrawppm{mandelbrot.ppm}
+
+ \immediate\write18{convert mandelbrot.ppm mandelbrot.png}
+
+ \includegraphics[width=\linewidth]{mandelbrot.png}
+
+ check-end:
+*/
diff --git a/Master/texmf-dist/source/latex/avremu/test-suite/mul.c b/Master/texmf-dist/source/latex/avremu/test-suite/mul.c
new file mode 100644
index 00000000000..49f05550198
--- /dev/null
+++ b/Master/texmf-dist/source/latex/avremu/test-suite/mul.c
@@ -0,0 +1,52 @@
+#include <avr/io.h>
+
+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/Master/texmf-dist/source/latex/avremu/test-suite/printf.c b/Master/texmf-dist/source/latex/avremu/test-suite/printf.c
new file mode 100644
index 00000000000..e8d14fb0782
--- /dev/null
+++ b/Master/texmf-dist/source/latex/avremu/test-suite/printf.c
@@ -0,0 +1,69 @@
+#include <avr/io.h>
+#include <stdio.h>
+
+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/Master/texmf-dist/source/latex/avremu/test-suite/shift.c b/Master/texmf-dist/source/latex/avremu/test-suite/shift.c
new file mode 100644
index 00000000000..fe64b4ca208
--- /dev/null
+++ b/Master/texmf-dist/source/latex/avremu/test-suite/shift.c
@@ -0,0 +1,26 @@
+#include <avr/io.h>
+
+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/Master/texmf-dist/source/latex/avremu/test-suite/string.c b/Master/texmf-dist/source/latex/avremu/test-suite/string.c
new file mode 100644
index 00000000000..616598884ed
--- /dev/null
+++ b/Master/texmf-dist/source/latex/avremu/test-suite/string.c
@@ -0,0 +1,22 @@
+#include <avr/io.h>
+
+// 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/Master/texmf-dist/source/latex/avremu/test-suite/sum-rec.c b/Master/texmf-dist/source/latex/avremu/test-suite/sum-rec.c
new file mode 100644
index 00000000000..0fa00fc6bc2
--- /dev/null
+++ b/Master/texmf-dist/source/latex/avremu/test-suite/sum-rec.c
@@ -0,0 +1,23 @@
+#include <avr/io.h>
+
+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/Master/texmf-dist/source/latex/avremu/test-suite/test-suite b/Master/texmf-dist/source/latex/avremu/test-suite/test-suite
new file mode 100755
index 00000000000..e54a739f404
--- /dev/null
+++ b/Master/texmf-dist/source/latex/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
+