summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.h.in3
-rwxr-xr-xconfigure5
-rw-r--r--configure.ac5
-rw-r--r--src/lib/memory.c46
-rw-r--r--src/lib/module.c1
-rw-r--r--src/lib/syntax.c1
-rw-r--r--src/tools/genboot.c8
-rwxr-xr-xtools/check24
-rwxr-xr-xtools/checkcov13
9 files changed, 72 insertions, 34 deletions
diff --git a/config.h.in b/config.h.in
index cd458a5..bf2893d 100644
--- a/config.h.in
+++ b/config.h.in
@@ -18,6 +18,9 @@
MSVC and with C++ compilers. */
#undef FLEXIBLE_ARRAY_MEMBER
+/* Defined if the build mode is "coverage", to disable asserts */
+#undef NDEBUG
+
/* Name of package */
#undef PACKAGE
diff --git a/configure b/configure
index 9ea8331..043519c 100755
--- a/configure
+++ b/configure
@@ -4863,7 +4863,12 @@ printf "%s\n" "#define APLWC_BUILD_TYPE_RELEASE 1" >>confdefs.h
;; #(
coverage) :
+
printf "%s\n" "#define APLWC_BUILD_TYPE_COVERAGE 1" >>confdefs.h
+,
+
+printf "%s\n" "#define NDEBUG 1" >>confdefs.h
+
;; #(
*) :
diff --git a/configure.ac b/configure.ac
index db987c6..9b3e9d4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,7 +25,10 @@ AC_MSG_RESULT([$build_mode])
AS_CASE([$build_mode],
[debug], [AC_DEFINE([APLWC_BUILD_TYPE_DEBUG], [1], [Defined if the build mode is "debug"])],
[release], [AC_DEFINE([APLWC_BUILD_TYPE_RELEASE], [1], [Defined if the build mode is "release"])],
- [coverage], [AC_DEFINE([APLWC_BUILD_TYPE_COVERAGE], [1], [Defined if the build mode is "coverage"])]
+ [coverage], [
+ AC_DEFINE([APLWC_BUILD_TYPE_COVERAGE], [1], [Defined if the build mode is "coverage"]),
+ AC_DEFINE([NDEBUG], [1], [Defined if the build mode is "coverage", to disable asserts])
+ ]
)
AC_CONFIG_FILES([
diff --git a/src/lib/memory.c b/src/lib/memory.c
index 051acba..a8317c7 100644
--- a/src/lib/memory.c
+++ b/src/lib/memory.c
@@ -41,7 +41,9 @@ struct chunk {
unsigned int last:1;
};
+#if APLWC_BUILD_TYPE_DEBUG
static void debug_check_mem(struct aplwc *);
+#endif /* APLWC_BUILD_TYPE_DEBUG */
void
memory_init(struct aplwc *aplwc)
@@ -436,27 +438,6 @@ compact(struct aplwc *aplwc)
}
}
-static void
-debug_check_mem(struct aplwc *aplwc)
-{
- uint64_t size;
- struct chunk *c, *prev;
-
- size = 0;
- prev = NULL;
- for(c = (struct chunk *)aplwc->data; c; prev = c, c = next(c)){
- assert(((uint8_t*)c) < (aplwc->data+aplwc->size));
- assert((c->size % ALIGNMENT) == 0);
- assert(c->stack == NULL);
- size += c->size;
- assert((c->last == 0) != (size == aplwc->size));
- if(c->tag == CHUNK_TAG_FREE)
- assert((prev == NULL) || (prev->tag != CHUNK_TAG_FREE));
- }
-
- assert(size == aplwc->size);
-}
-
static void *
alloc(struct aplwc *aplwc, size_t size, enum chunk_tag tag)
{
@@ -653,3 +634,26 @@ valid_ref(struct aplwc_ref *ref)
{
return (ref->aplwc != NULL) && (ref->ptr != NULL);
}
+
+#if APLWC_BUILD_TYPE_DEBUG
+static void
+debug_check_mem(struct aplwc *aplwc)
+{
+ uint64_t size;
+ struct chunk *c, *prev;
+
+ size = 0;
+ prev = NULL;
+ for(c = (struct chunk *)aplwc->data; c; prev = c, c = next(c)){
+ assert(((uint8_t*)c) < (aplwc->data+aplwc->size));
+ assert((c->size % ALIGNMENT) == 0);
+ assert(c->stack == NULL);
+ size += c->size;
+ assert((c->last == 0) != (size == aplwc->size));
+ if(c->tag == CHUNK_TAG_FREE)
+ assert((prev == NULL) || (prev->tag != CHUNK_TAG_FREE));
+ }
+
+ assert(size == aplwc->size);
+}
+#endif /* APLWC_BUILD_TYPE_DEBUG */
diff --git a/src/lib/module.c b/src/lib/module.c
index 2ef5ba3..aaa9634 100644
--- a/src/lib/module.c
+++ b/src/lib/module.c
@@ -67,6 +67,7 @@ read_keyword_decl(struct aplwc *aplwc, struct aplwc_module *module, size_t offse
max = module->tokens->length - offset - 1;
+ len = -1;
assert(t(0).tag == TOKEN_TAG_KEYWORD);
switch(t(0).data.keyword){
case KW_MODULE:
diff --git a/src/lib/syntax.c b/src/lib/syntax.c
index 4850b1a..1740a4e 100644
--- a/src/lib/syntax.c
+++ b/src/lib/syntax.c
@@ -425,6 +425,7 @@ scan_string(struct aplwc *aplwc, struct string *text, int oneline)
MEMPTR(0, text);
tokens = NULL;
+ n = 0;
if((rc = check(aplwc, text, &n)) != APLWC_OK)
goto end;
diff --git a/src/tools/genboot.c b/src/tools/genboot.c
index 6f2e408..e89b3aa 100644
--- a/src/tools/genboot.c
+++ b/src/tools/genboot.c
@@ -4,14 +4,16 @@
int
main(int argc, char *argv[])
{
+ FILE *f;
+ int c, s;
+
assert(argc == 2);
- FILE *f = fopen(argv[1], "r");
+ f = fopen(argv[1], "r");
assert(f != NULL);
printf("unsigned char boot_src[] = { ");
- int c;
- int s = 0;
+ s = 0;
while((c = fgetc(f)) != EOF){
if(s++ > 0)
printf(", ");
diff --git a/tools/check b/tools/check
index 717746d..eee6490 100755
--- a/tools/check
+++ b/tools/check
@@ -2,7 +2,7 @@
set -e
-types="Debug Release Coverage"
+types="debug release coverage"
mkdir -p build
cd build
@@ -10,7 +10,27 @@ cd build
for type in $types
do
rm -rf $type
- cmake .. -G Ninja -B $type -DCMAKE_BUILD_TYPE=$type
+ mkdir -p $type
+ cd $type
+ case $type in
+ debug)
+ CFLAGS="-O0 -g3 -fsanitize=address,undefined"
+ ;;
+ coverage)
+ CFLAGS="-O0 -g3 --coverage -fcondition-coverage"
+ ;;
+ release)
+ CFLAGS="-O3"
+ ;;
+ *)
+ echo "Unsupported type"
+ exit 1
+ ;;
+ esac
+ ../../configure --enable-build-mode=$type CFLAGS="$CFLAGS -Wall -Wextra -Werror -std=c89 -pedantic"
+ make check
+ ../../configure --enable-build-mode=$type CFLAGS="$CFLAGS"
+ cd ..
done
cd ..
diff --git a/tools/checkcov b/tools/checkcov
index ac3cf91..412a58e 100755
--- a/tools/checkcov
+++ b/tools/checkcov
@@ -5,26 +5,25 @@ set -e
cd build/$1
case "$1" in
- Coverage)
- rm -rf CMakeFiles/aplwc.dir/src/lib/*
- rm -rf CMakeFiles/aplwc-repl.dir/src/bin/*
+ coverage)
+ rm -rf src/lib/*
+ rm -rf src/bin/*
;;
*)
;;
esac
-cmake --build .
-ctest
+make check
case "$1" in
- Coverage)
+ coverage)
;;
*)
exit 0
;;
esac
-gcov -tg CMakeFiles/aplwc.dir/src/lib/*.gcno CMakeFiles/aplwc-repl.dir/src/bin/*.gcno | awk '
+gcov -tg src/lib/*.gcno src/bin/*.gcno | awk '
BEGIN {
FS=":"
}