First stab at autogen.sh
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
build/
|
build/
|
||||||
libs/
|
libs/
|
||||||
|
tests/
|
||||||
mgos_i2c
|
mgos_i2c
|
||||||
|
5
Makefile
5
Makefile
@ -14,10 +14,11 @@ SRCDIR = src
|
|||||||
INCDIR = include
|
INCDIR = include
|
||||||
OBJDIR = build
|
OBJDIR = build
|
||||||
LIBDIR = libs
|
LIBDIR = libs
|
||||||
|
TESTDIR = tests
|
||||||
BINDIR = .
|
BINDIR = .
|
||||||
|
|
||||||
SRCS := $(shell find -L $(SRCDIR) $(LIBDIR) -type f -name '*.c' | egrep -v 'deps/|build/' )
|
SRCS := $(shell find -L $(SRCDIR) $(LIBDIR) $(TESTDIR) -type f -name '*.c' | egrep -v 'deps/|build/' )
|
||||||
INCS := $(shell find -L $(SRCDIR) $(LIBDIR) $(INCDIR) -type d -name 'include'| egrep -v 'deps/|build/' )
|
INCS := $(shell find -L $(SRCDIR) $(LIBDIR) $(TESTDIR) $(INCDIR) -type d -name 'include'| egrep -v 'deps/|build/' )
|
||||||
INCFLAGS := $(patsubst %,-I %, $(INCS))
|
INCFLAGS := $(patsubst %,-I %, $(INCS))
|
||||||
OBJS := $(patsubst %.c, build/%.o, $(SRCS))
|
OBJS := $(patsubst %.c, build/%.o, $(SRCS))
|
||||||
RM = rm -f
|
RM = rm -f
|
||||||
|
97
autogen.sh
Executable file
97
autogen.sh
Executable file
@ -0,0 +1,97 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
OUT_SRC=src/tests_autogen.c
|
||||||
|
OUT_INC=include/tests_autogen.h
|
||||||
|
DATE=$(date)
|
||||||
|
|
||||||
|
# ---
|
||||||
|
|
||||||
|
gen_src_head() {
|
||||||
|
cat > $OUT_SRC << EOF
|
||||||
|
// Generated on $DATE by $USER
|
||||||
|
//
|
||||||
|
#include "mgos.h"
|
||||||
|
#include "$(basename $OUT_INC)"
|
||||||
|
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_src_body() {
|
||||||
|
echo "GEN $OUT_SRC"
|
||||||
|
(
|
||||||
|
for func in create run destroy; do
|
||||||
|
echo "bool tests_${func}(void) {"
|
||||||
|
echo " uint32_t total=0, success=0;"
|
||||||
|
for n in $*; do
|
||||||
|
cat << EOF
|
||||||
|
if (!test_${n}_${func}()) {
|
||||||
|
LOG(LL_ERROR, ("Could not $func test $n"));
|
||||||
|
} else {
|
||||||
|
success++;
|
||||||
|
}
|
||||||
|
total++;
|
||||||
|
|
||||||
|
EOF
|
||||||
|
done
|
||||||
|
cat << EOF
|
||||||
|
return (total == success);
|
||||||
|
}
|
||||||
|
|
||||||
|
EOF
|
||||||
|
done
|
||||||
|
) >> $OUT_SRC
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_src_tail() {
|
||||||
|
cat >> $OUT_SRC << EOF
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_inc_head() {
|
||||||
|
cat > $OUT_INC << EOF
|
||||||
|
// Generated on $DATE by $USER
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
#include "mgos.h"
|
||||||
|
|
||||||
|
// Master test prototypes (called from main.c)
|
||||||
|
bool tests_create(void);
|
||||||
|
bool tests_run(void);
|
||||||
|
bool tests_destroy(void);
|
||||||
|
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_inc_body() {
|
||||||
|
echo "GEN $OUT_INC"
|
||||||
|
for n in $*; do
|
||||||
|
cat >> $OUT_INC << EOF
|
||||||
|
// Test suite "$n"
|
||||||
|
bool test_${n}_create(void);
|
||||||
|
bool test_${n}_run(void);
|
||||||
|
bool test_${n}_destroy(void);
|
||||||
|
|
||||||
|
EOF
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_inc_tail() {
|
||||||
|
cat >> $OUT_INC << EOF
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
gen_inc_head
|
||||||
|
gen_src_head
|
||||||
|
|
||||||
|
for f in tests/*.c; do
|
||||||
|
base=$(basename $f | cut -f1 -d'.')
|
||||||
|
echo "CHK $base in $f"
|
||||||
|
base_list="$base_list $base"
|
||||||
|
done
|
||||||
|
|
||||||
|
gen_inc_body $base_list
|
||||||
|
gen_src_body $base_list
|
||||||
|
|
||||||
|
gen_inc_tail
|
||||||
|
gen_src_tail
|
||||||
|
|
1
include/.gitignore
vendored
Normal file
1
include/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
tests_autogen.h
|
1
src/.gitignore
vendored
Normal file
1
src/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
tests_autogen.c
|
@ -1,4 +1,5 @@
|
|||||||
#include "mgos.h"
|
#include "mgos.h"
|
||||||
|
#include "tests_autogen.h"
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
@ -59,6 +60,10 @@ int main(int argc, char **argv, char **environ) {
|
|||||||
|
|
||||||
i2c_scanner(i2c, true);
|
i2c_scanner(i2c, true);
|
||||||
|
|
||||||
|
tests_create();
|
||||||
|
tests_run();
|
||||||
|
tests_destroy();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
|
Reference in New Issue
Block a user