mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[Quiz] Logging on screen
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
SFLAGS += -Iquiz/include
|
||||
objs += $(addprefix quiz/src/, runner.o symbols.o)
|
||||
|
||||
symbols_file = $(addprefix quiz/src/, symbols.c)
|
||||
products += $(symbols_file)
|
||||
@@ -8,8 +7,9 @@ $(symbols_file): $(tests)
|
||||
@echo "AWK $@"
|
||||
@awk -f quiz/src/symbols.awk $(tests) > $@
|
||||
|
||||
runner_objs += $(addprefix quiz/src/, runner.o symbols.o)
|
||||
test_objs = $(subst .c,.o, $(subst .cpp,.o,$(tests)))
|
||||
|
||||
test.elf: $(objs) $(test_objs)
|
||||
test.elf: $(objs) $(runner_objs) $(test_objs)
|
||||
@echo "LD $@"
|
||||
@$(LD) $(LDFLAGS) $(objs) $(test_objs) -o $@
|
||||
|
||||
@@ -1,10 +1,22 @@
|
||||
#ifndef QUIZ_H
|
||||
#define QUIZ_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define QUIZ_CASE(name) extern "C" { void quiz_case_##name();}; void quiz_case_##name()
|
||||
#else
|
||||
#define QUIZ_CASE(name) void quiz_case_##name()
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void quiz_assert_true(bool condition);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
7
quiz/src/assertions.c
Normal file
7
quiz/src/assertions.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <ion.h>
|
||||
#include <quiz.h>
|
||||
|
||||
void quiz_assert_true(bool condition) {
|
||||
if (!condition) {
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,29 @@
|
||||
#include "symbols.h"
|
||||
#include <string.h>
|
||||
#include <kandinsky.h>
|
||||
|
||||
void print(char * message) {
|
||||
static int line_y = 0;
|
||||
int line_height = KDStringSize("M").height;
|
||||
KDDrawString(message, (KDPoint){.x = 0, .y = line_y});
|
||||
line_y += line_height;
|
||||
if (line_y > ION_FRAMEBUFFER_HEIGHT) {
|
||||
line_y = 0;
|
||||
ion_getchar();
|
||||
// Clear screen maybe?
|
||||
}
|
||||
}
|
||||
|
||||
void hello() {
|
||||
int i = 0;
|
||||
while (quiz_cases[i] != NULL) {
|
||||
QuizCase c = quiz_cases[i];
|
||||
c();
|
||||
print(quiz_case_names[i]);
|
||||
i++;
|
||||
}
|
||||
print("ALL TESTS FINISHED");
|
||||
while (1) {
|
||||
ion_sleep();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,19 +6,28 @@ BEGIN {
|
||||
|
||||
#FIXME: Is there a way to capture subexpression in awk? The following gsub is
|
||||
# kind of ugly
|
||||
/QUIZ_CASE\(([a-z0-9_]+)\)/ { gsub(/(QUIZ_CASE\()|(\))/, "", $1); tests = tests ",quiz_case_" $1 }
|
||||
/QUIZ_CASE\(([a-z0-9_]+)\)/ { gsub(/(QUIZ_CASE\()|(\))/, "", $1); tests = tests "quiz_case_" $1 "," }
|
||||
|
||||
END {
|
||||
a = tests;
|
||||
b = tests;
|
||||
gsub(/,/, "();\nvoid ", a);
|
||||
sub(/\(\);\n/, "", a);
|
||||
print a "();";
|
||||
print "";
|
||||
declarations = tests;
|
||||
gsub(/quiz_case/, "void quiz_case", declarations);
|
||||
gsub(/,/, "();\n", declarations);
|
||||
print declarations;
|
||||
|
||||
symbols = tests;
|
||||
print "QuizCase quiz_cases[] = {";
|
||||
sub(/,/, "", b);
|
||||
gsub(/,/, ",\n", b);
|
||||
print b;
|
||||
print ",NULL"
|
||||
gsub(/quiz_case/, " quiz_case", symbols);
|
||||
gsub(/,/, ",\n", symbols);
|
||||
symbols = symbols " NULL"
|
||||
print symbols;
|
||||
print "};"
|
||||
print ""
|
||||
|
||||
names = tests;
|
||||
print "char * quiz_case_names[] = {";
|
||||
gsub(/quiz_case_/, " \"", names);
|
||||
gsub(/,/, "\",\n", names);
|
||||
names = names " NULL"
|
||||
print names;
|
||||
print "};"
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
typedef void (*QuizCase)(void);
|
||||
|
||||
extern QuizCase quiz_cases[];
|
||||
extern char * quiz_case_names[];
|
||||
|
||||
Reference in New Issue
Block a user