[Quiz] Cleanup

This commit is contained in:
Romain Goyet
2015-09-03 23:15:09 +02:00
parent 3e29ff1236
commit 2bb2a2af28
9 changed files with 44 additions and 49 deletions

View File

@@ -0,0 +1,6 @@
#include <quiz.h>
#include <kandinsky.h>
TEST(setpixel) {
2+2;
}

View File

@@ -1,5 +1,6 @@
SFLAGS += -Ipoincare/include
objs += $(addprefix poincare/src/, expression.o number.o fraction.o power.o expression_lexer.o expression_parser.o)
objs += $(addprefix poincare/src/, expression.o integer.o number.o fraction.o power.o expression_lexer.o expression_parser.o)
tests += $(addprefix poincare/test/, integer.cpp)
# Even though flex and bison will generate both implementation and headers at
# once, we don't declare it in the Makefile. If we did, "make -jN" with N>1 may

View File

@@ -0,0 +1,6 @@
#include <quiz.h>
#include <poincare.h>
TEST(integer) {
1+1;
}

View File

@@ -1,3 +1,5 @@
SFLAGS += -Iquiz/include
symbols_file = $(addprefix quiz/src/, symbols.c)
products += $(symbols_file)
@@ -7,4 +9,4 @@ $(symbols_file): $(tests)
test_objs = $(subst .c,.o, $(subst .cpp,.o,$(tests)))
test.elf: quiz/src/symbols.o $(test_objs)
test.elf: quiz/src/symbols.o quiz/src/runner.o $(test_objs)

View File

@@ -1 +1,6 @@
#ifndef QUIZ_H
#define QUIZ_H
#define TEST(foo) void test_##foo()
#endif

View File

@@ -1,46 +0,0 @@
#include <registers.h>
void assert(int condition);
void low_level_sleep(int iterations) {
for (int i=0;i<iterations;i++) {
}
}
void debugger() {
while(1) {
}
}
void halt(int success) {
RCC_AHB1ENR->GPIOGEN = 1;
if (success) {
GPIO_MODER(GPIOG)->MODER13 = GPIO_MODE_OUTPUT;
for (int i=0;i<5; i++) {
GPIO_ODR(GPIOG)->ODR13 = 0;
low_level_sleep(50000);
GPIO_ODR(GPIOG)->ODR13 = 1;
low_level_sleep(50000);
}
} else {
GPIO_MODER(GPIOG)->MODER14 = GPIO_MODE_OUTPUT;
for (int i=0;i<5; i++) {
GPIO_ODR(GPIOG)->ODR14 = 0;
low_level_sleep(50000);
GPIO_ODR(GPIOG)->ODR14 = 1;
low_level_sleep(50000);
}
}
debugger();
}
void assert(int condition) {
if (!condition) {
halt(0);
}
}
int main(int argc, char * argv[]) {
// Run assertions
halt(1);
}

11
quiz/src/runner.c Normal file
View File

@@ -0,0 +1,11 @@
#include "symbols.h"
#include <string.h>
void hello() {
int i = 0;
while (quiz_cases[i] != NULL) {
QuizCase c = quiz_cases[i];
c();
i++;
}
}

View File

@@ -1,3 +1,9 @@
BEGIN {
print "#include <string.h>"
print "#include \"symbols.h\""
print
}
#FIXME: Is there a way to capture subexpression in awk? The following gsub is
# kind of ugly
/TEST\(([a-z0-9_]+)\)/ { gsub(/(TEST\()|(\))/, "", $1); tests = tests "," $1 }
@@ -9,9 +15,10 @@ END {
sub(/\(\);\n/, "", a);
print a "();";
print "";
print "void * pointers[] = {";
print "QuizCase quiz_cases[] = {";
sub(/,/, "", b);
gsub(/,/, ",\n", b);
print b;
print ",NULL"
print "};"
}

3
quiz/src/symbols.h Normal file
View File

@@ -0,0 +1,3 @@
typedef void (*QuizCase)(void);
extern QuizCase quiz_cases[];