Verified Commit 5bf0498b authored by Karel Koci's avatar Karel Koci 🤘
Browse files

Rework build system and test execution

This updates C tests to run only as one binary.

The important change is that tests are enabled explicitly and thus in
default disabled. The same now also applies to linters.
parent 91248c97
Pipeline #83589 passed with stages
in 3 minutes and 46 seconds
# The desired results
*.html
*.so
*.o
*.a
*.la
*.lo
/libupdater.la
/pkgtransaction
# Outputs
/pkgupdate
/pkgtransaction
/libupdater.la
/updater-*.tar.gz
/updater-*.tar.xz
/updater-*.zip
# Build
.libs
# Some stuff for debugging
/.coverage.info
/coverage/
# Stuff dump core all over the place.
core
vgcore.*
massif.out.*
# Test stuff
*.o
*.pc
*.lo
/src/lib/lua/*.lua.h
/tests/lua/*.lua.h
# Test outputs
/tests/c/unittests-lib
/tests/lua/lunit-launch
test-suite*.log
tests/check-compiled
tests/luacheck-compiled
tests/arguments
testdir
# Gitlab pages
pages
tests/**/*.log
tests/**/*.trs
# Coverage output
*.gcno
*.gcda
/updater-*-coverage*
## Autotools
/.m4
/.aux
# http://www.gnu.org/software/automake
Makefile
Makefile.in
/ar-lib
/test-driver
.deps
.dirstamp
# http://www.gnu.org/software/autoconf
......@@ -37,36 +39,13 @@ autom4te.cache
/autoscan.log
/autoscan-*.log
/aclocal.m4
/compile
/config.guess
/config.h.in
/config.log
/config.status
/config.sub
/configure
/configure.scan
/depcomp
/install-sh
/missing
/stamp-h1
/aminclude_static.am
# https://www.gnu.org/software/libtool/
/ltmain.sh
/libtool
# http://www.gnu.org/software/texinfo
/texinfo.tex
# http://www.gnu.org/software/m4/
m4/libtool.m4
m4/ltoptions.m4
m4/ltsugar.m4
m4/ltversion.m4
m4/lt~obsolete.m4
# Generated Makefile
Makefile
## Development
tags
.tags
.ycm_*.py
.ycm_*.pyc
compile_commands.json
......@@ -4,14 +4,14 @@ variables:
stages:
- build
- test
- pages
- coverage
## Build stage ###################################################################
.build:
stage: build
script:
- ./bootstrap
- ./configure --disable-tests --disable-docs
- ./configure
- make
artifacts:
when: on_failure
......@@ -37,7 +37,7 @@ build-alpine:
image: registry.labs.nic.cz/turris/updater/updater:tests
before_script:
- ./bootstrap
- ./configure
- ./configure --enable-tests --enable-linters
.test-check:
extends: .test
......@@ -59,14 +59,31 @@ valgrind-memcheck:
script:
- make check-valgrind-memcheck
# TODO possibly run sgcheck?
lint-c:
allow_failure: true
extends: .test
script:
- make lint-c
lint-lua:
allow_failure: true
extends: .test
script:
- make lint-lua
## Code Coverage stage ###########################################################
coverage:
stage: coverage
needs: [check]
image: registry.labs.nic.cz/turris/updater/updater:tests
script:
- ./bootstrap
- ./configure --enable-tests --enable-code-coverage
- make check-code-coverage V=1
- mv updater-*-coverage updater-coverage
coverage: '/lines\.\.\.\.\.\.: (\d+.\d+%)/'
artifacts:
expire_in: 1 month
expose_as: 'Code Coverage'
paths:
- 'updater-coverage/'
ACLOCAL_AMFLAGS = -I m4
include $(srcdir)/utils/helpers.mk
ACLOCAL_AMFLAGS = -I .m4
bin_PROGRAMS =
lib_LTLIBRARIES =
EXTRA_DIST =
CLEANFILES =
linted_sources =
include $(srcdir)/src/Makefile.am
include $(srcdir)/utils/helpers.mk
if ENABLE_DOCS
dist_doc_DATA = README.md
endif
if ENABLE_LINTERS
include $(srcdir)/utils/lint.am
endif
include $(srcdir)/tests/Makefile.am
#!/bin/sh
# Directory used for m4 macros of autoconf
mkdir -p m4
mkdir -p .m4 .aux
# On old versions of autoconf-archive this file is not present so fake it
[ -f aminclude_static.am ] || echo "# dummy" > aminclude_static.am
......
AC_INIT([updater-ng], [69.1.2], [tech.support@turris.cz])
AC_CONFIG_MACRO_DIRS([m4])
AC_CONFIG_MACRO_DIRS([.m4])
AC_CONFIG_AUX_DIR([.aux])
AM_INIT_AUTOMAKE([foreign silent-rules subdir-objects -Wall -Wno-portability])
AM_INIT_AUTOMAKE([
foreign silent-rules subdir-objects
-Wall -Wno-portability
dist-zip dist-xz
])
AM_SILENT_RULES([yes])
AC_PROG_CC
......@@ -9,10 +14,10 @@ AC_GNU_SOURCE
AM_PROG_AR
LT_INIT
AX_CHECK_COMPILE_FLAG([-std=c11], , AC_MSG_ERROR([Compiler with C11 standard support is required]))
AX_APPEND_FLAG([-std=c11])
AC_ARG_WITH([embed-busybox], [AC_HELP_STRING([--with-embed-busybox=BUSYBOX], [Embed given busybox binary])])
AM_CONDITIONAL([BUSYBOX_EMBED], [test -n "$with_embed_busybox"])
AC_SUBST([BUSYBOX_EMBED], [$with_embed_busybox])
......@@ -23,13 +28,13 @@ AS_IF([test -n "$with_embed_busybox"],
AC_DEFINE_UNQUOTED([BUSYBOX_EMBED], [$with_embed_busybox], [Embded Busybox])
])
PKG_CHECK_MODULES([LUA], [lua >= 5.1 lua < 5.2],,
[PKG_CHECK_MODULES([LUA], [lua5.1])])
PKG_CHECK_MODULES([LIBEVENT], [libevent >= 2.0])
PKG_CHECK_MODULES([LIBARCHIVE], [libarchive])
PKG_CHECK_MODULES([LIBCURL], [libcurl])
PKG_CHECK_MODULES([LIBCRYPTO], [libcrypto])
PKG_CHECK_MODULES([LIBURIPARSER], [liburiparser >= 0.9])
PKG_CHECK_MODULES([lua], [lua >= 5.1 lua < 5.2],,
[PKG_CHECK_MODULES([lua], [lua5.1])])
PKG_CHECK_MODULES([libevent], [libevent >= 2.0])
PKG_CHECK_MODULES([libarchive], [libarchive])
PKG_CHECK_MODULES([libcurl], [libcurl])
PKG_CHECK_MODULES([libcrypto], [libcrypto])
PKG_CHECK_MODULES([liburiparser], [liburiparser >= 0.9])
AC_CHECK_HEADERS([uthash.h], , AC_MSG_ERROR([uthash is required]))
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([#include <argp.h>],[argp_parse(0,1,NULL,0,0,0);])],,
......@@ -41,25 +46,29 @@ AS_IF([test -z "$PERL"], [AC_MSG_ERROR([Missing perl interpreter])])
AC_PATH_PROG([XXDI], [xxdi.pl],, [$ac_abs_confdir/utils])
AS_IF([test -z "$XXDI"], [AC_MSG_ERROR([Not able to locate xxdi.pl])])
dnl Documentation
AC_ARG_ENABLE([docs], AC_HELP_STRING([--disable-docs], [Disable documentation]))
AM_CONDITIONAL([ENABLE_DOCS], [test "x$enable_docs" != "xno"])
dnl Tests
AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests], [Disable tests]))
AM_CONDITIONAL([ENABLE_TESTS], [test "x$enable_tests" != "xno"])
AS_IF([test "x$enable_tests" != "xno"], [
AC_ARG_ENABLE([tests], AC_HELP_STRING([--enable-tests], [Whether to enable unit tests]))
AM_CONDITIONAL([ENABLE_TESTS], [test "x$enable_tests" = "xyes"])
AS_IF([test "x$enable_tests" = "xyes"], [
PKG_CHECK_MODULES([CHECK], [check >= 0.11])
AX_PROG_PERL_MODULES([common::sense], , AC_MSG_WARN(Perl modules File::Slurp is required))
AC_REQUIRE_AUX_FILE([tap-driver.sh])
])
AX_VALGRIND_CHECK
dnl Linters
AC_ARG_ENABLE([linters], AC_HELP_STRING([--disable-linters], [Disable linters (cppcheck and luacheck)]))
AM_CONDITIONAL([ENABLE_TESTS], [test "x$enable_linters" != "xno"])
AS_IF([test "x$enable_linters" != "xno"], [
AC_PATH_PROG([LUACHECK], [luacheck])
AC_ARG_ENABLE([linters], AC_HELP_STRING([--enable-linters], [Whether to enable code linting support (cppcheck)]))
AM_CONDITIONAL([ENABLE_LINTERS], [test "x$enable_linters" = "xyes"])
AS_IF([test "x$enable_linters" = "xyes"], [
AC_PATH_PROG([CPPCHECK], [cppcheck])
AS_IF([test -z "$CPPCHECK" ], AC_MSG_ERROR([Missing linter cppcheck]))
AC_PATH_PROG([LUACHECK], [luacheck])
AS_IF([test -z "$LUACHECK" ], AC_MSG_ERROR([Missing linter luacheck]))
])
dnl Coverage
......
bin_PROGRAMS =
lib_LTLIBRARIES =
lint_sources =
include $(srcdir)/%reldir%/lib/Makefile.am
include $(srcdir)/%reldir%/pkgtransaction/Makefile.am
include $(srcdir)/%reldir%/pkgupdate/Makefile.am
##################################################################################
lint_V = $(lint_V_@AM_V@)
lint_V_ = $(lint_V_@AM_DEFAULT_V@)
lint_V_0 = @echo LINT $@;
lint:
$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -k lint-c lint-lua
lint-c: $(filter %.c %.h, $(lint_sources))
$(lint_V)$(CPPCHECK) --error-exitcode=1 \
--enable=warning \
--std=c11 \
--suppress=allocaCalled \
--suppress=obsoleteFunctionsalloca \
--template='{file}:{line},{severity},{id},{message}' \
--inline-suppr \
$^
lint-lua: $(filter %.lua, $(lint_sources))
$(lint_V)$(LUACHECK) --config "%reldir%/luacheck.config" $^
......@@ -42,20 +42,20 @@ LIBUPDATER_LUA_FILES = \
libupdater_la_CFLAGS = \
-iquote "$(builddir)/%reldir%" \
$(LUA_CFLAGS) \
$(LIBEVENT_CFLAGS) \
$(LIBARCHIVE_CFLAGS) \
$(LIBCURL_CLAGS) \
$(LIBCRYPTO_CFLAGS) \
$(LIBURIPARSER_CFLAGS) \
$(lua_CFLAGS) \
$(libevent_CFLAGS) \
$(libarchive_CFLAGS) \
$(libcurl_CLAGS) \
$(libcrypto_CFLAGS) \
$(liburiparser_CFLAGS) \
$(CODE_COVERAGE_CFLAGS)
libupdater_la_LDFLAGS = \
$(LUA_LIBS) \
$(LIBEVENT_LIBS) \
$(LIBARCHIVE_LIBS) \
$(LIBCURL_LIBS) \
$(LIBCRYPTO_LIBS) \
$(LIBURIPARSER_LIBS) \
$(lua_LIBS) \
$(libevent_LIBS) \
$(libarchive_LIBS) \
$(libcurl_LIBS) \
$(libcrypto_LIBS) \
$(liburiparser_LIBS) \
$(CODE_COVERAGE_LIBS) \
-ldl \
-release ${VERSION}
......@@ -85,6 +85,6 @@ $(builddir)/%reldir%/busybox_exec.h: $(BUSYBOX_EMBED)
endif
lint_sources += \
linted_sources += \
$(filter-out %/picosat.c,$(libupdater_la_SOURCES)) \
$(filter-out %/dumper.lua %/stacktraceplus.lua,$(LIBUPDATER_LUA_FILES))
......@@ -303,10 +303,8 @@ static int lua_decompress(lua_State *L) {
size_t size = 0, len = 0;
char *data = NULL;
while (!feof(f)) {
if (size <= (len + 1)) {
size += BUFSIZ;
data = realloc(data, size * sizeof *data);
}
if (size <= (len + 1))
data = realloc(data, (size += BUFSIZ) * sizeof *data);
len += fread(data + len, 1, size - len - 1, f);
}
data[len] = '\0';
......
......@@ -9,4 +9,4 @@ pkgtransaction_CFLAGS = \
pkgtransaction_LDADD = libupdater.la
lint_sources += $(pkgtransaction_SOURCES)
linted_sources += $(pkgtransaction_SOURCES)
......@@ -9,4 +9,4 @@ pkgupdate_CFLAGS = \
pkgupdate_LDADD = libupdater.la
lint_sources += $(pkgupdate_SOURCES)
linted_sources += $(pkgupdate_SOURCES)
# General test logging and output
*.log
*.trs
TESTS =
check_PROGRAMS =
check_LTLIBRARIES =
TEST_EXTENSIONS = .lua .sys_trans .sys_update
if ENABLE_TESTS
DISTCHECK_CONFIGURE_FLAGS = --enable-tests
include $(srcdir)/%reldir%/c/Makefile.am
include $(srcdir)/%reldir%/lua/Makefile.am
include $(srcdir)/%reldir%/system/Makefile.am
# TODO TMPDIR?
AM_TESTS_ENVIRONMENT = \
export TOP_SRCDIR="$(srcdir)"; \
export DATADIR="$(srcdir)/tests/data"; \
export DATA_DIR="$(abs_srcdir)/tests/data"; \
export BUILD_DIR="$(abs_builddir)";
LOG_DRIVER = \
env AM_TAP_AWK='$(AWK)' TEST_OUTPUT_TAP="/dev/stdout" \
'$(SHELL)' '$(srcdir)/.aux/tap-driver.sh'
# Valgrind #######################################################################
## Valgrind
VALGRIND_memcheck_FLAGS = \
--leak-check=full \
--show-leak-kinds=definite,indirect,possible \
......@@ -19,25 +40,14 @@ check-valgrind-$(1): check-valgrind-$(1)-am
endef
$(foreach tool,$(valgrind_tools),$(eval $(call check_valgrind_rule,$(tool))))
# Coverage #######################################################################
## Coverage
CODE_COVERAGE_LCOV_OPTIONS := --no-external
CODE_COVERAGE_GENHTML_OPTIONS := --prefix $(dir $(abs_top_builddir))
include $(srcdir)/aminclude_static.am
clean-local: code-coverage-clean
distclean-local: code-coverage-dist-clean
##################################################################################
# TODO TMPDIR?
AM_TESTS_ENVIRONMENT = \
export TOP_SRCDIR="$(srcdir)"; \
export DATADIR="$(srcdir)/tests/data"; \
export DATA_DIR="$(abs_srcdir)/tests/data"; \
export BUILD_DIR="$(abs_builddir)";
TEST_EXTENSIONS = .lua .sys_trans .sys_update
if ENABLE_TESTS
include $(srcdir)/%reldir%/c/Makefile.am
include $(srcdir)/%reldir%/lua/Makefile.am
include $(srcdir)/%reldir%/system/Makefile.am
endif
# Test binaries
archive
base64
changelog
util
syscnf
path_utils
signature
subprocess
download
uri
interpreter
TESTS += \
%reldir%/archive \
%reldir%/base64 \
%reldir%/changelog \
%reldir%/util \
%reldir%/syscnf \
%reldir%/path_utils \
%reldir%/signature \
%reldir%/subprocess \
%reldir%/download \
%reldir%/uri \
%reldir%/interpreter
TESTS += %reldir%/unittests-lib
check_PROGRAMS += \
%reldir%/archive \
%reldir%/base64 \
%reldir%/changelog \
%reldir%/util \
%reldir%/syscnf \
%reldir%/path_utils \
%reldir%/signature \
%reldir%/subprocess \
%reldir%/download \
%reldir%/uri \
%reldir%/interpreter
%canon_reldir%_archive_LDADD = %reldir%/libctest.la
%canon_reldir%_base64_LDADD = %reldir%/libctest.la
%canon_reldir%_changelog_LDADD = %reldir%/libctest.la
%canon_reldir%_util_LDADD = %reldir%/libctest.la
%canon_reldir%_syscnf_LDADD = %reldir%/libctest.la
%canon_reldir%_path_utils_LDADD = %reldir%/libctest.la
%canon_reldir%_signature_LDADD = %reldir%/libctest.la
%canon_reldir%_subprocess_LDADD = %reldir%/libctest.la
%canon_reldir%_download_LDADD = %reldir%/libctest.la
%canon_reldir%_uri_LDADD = %reldir%/libctest.la
%canon_reldir%_interpreter_LDADD = %reldir%/libctest.la
%canon_reldir%_archive_CFLAGS = -I $(srcdir)/src/lib $(libupdater_la_CFLAGS)
%canon_reldir%_base64_CFLAGS = -I $(srcdir)/src/lib $(libupdater_la_CFLAGS)
%canon_reldir%_changelog_CFLAGS = -I $(srcdir)/src/lib $(libupdater_la_CFLAGS)
%canon_reldir%_util_CFLAGS = -I $(srcdir)/src/lib $(libupdater_la_CFLAGS)
%canon_reldir%_syscnf_CFLAGS = -I $(srcdir)/src/lib $(libupdater_la_CFLAGS)
%canon_reldir%_path_utils_CFLAGS = -I $(srcdir)/src/lib $(libupdater_la_CFLAGS)
%canon_reldir%_signature_CFLAGS = -I $(srcdir)/src/lib $(libupdater_la_CFLAGS)
%canon_reldir%_subprocess_CFLAGS = -I $(srcdir)/src/lib $(libupdater_la_CFLAGS)
%canon_reldir%_download_CFLAGS = -I $(srcdir)/src/lib $(libupdater_la_CFLAGS)
%canon_reldir%_uri_CFLAGS = -I $(srcdir)/src/lib $(libupdater_la_CFLAGS)
%canon_reldir%_interpreter_CFLAGS = -I $(srcdir)/src/lib $(libupdater_la_CFLAGS)
# TODO possibly integrate all tests to single binary or solve this LDADD somehow
check_LTLIBRARIES += %reldir%/libctest.la
%canon_reldir%_libctest_la_SOURCES = \
%reldir%/ctest.c \
%reldir%/test_data.c
%canon_reldir%_libctest_la_CFLAGS = \
-I $(srcdir)/src/lib \
$(CHECK_FLAGS)
%canon_reldir%_libctest_la_LIBADD = \
check_PROGRAMS += %reldir%/unittests-lib
%canon_reldir%_unittests_lib_SOURCES = \
%reldir%/unittests.c \
%reldir%/test_data.h %reldir%/test_data.c \
%reldir%/archive.c \
%reldir%/base64c. \
%reldir%/changelog.c \
%reldir%/download.c \
%reldir%/interpreter.c \
%reldir%/path_utils.c \
%reldir%/signature.c \
%reldir%/subprocess.c \
%reldir%/syscnf.c \
%reldir%/uri.c \
%reldir%/util.c
%canon_reldir%_unittests_lib_CFLAGS = \
-isystem '$(srcdir)/src/lib' \
$(libupdater_la_CFLAGS) \
$(CHECK_CFLAGS) \
${CODE_COVERAGE_CFLAGS}
%canon_reldir%_unittests_lib_LDADD = \
libupdater.la \
$(CHECK_LIBS)
$(CHECK_LIBS) \
${CODE_COVERAGE_LIBS}
# TODO locks test in locks.c
linted_sources += $(%canon_reldir%_unittests_lib_SOURCES)
......@@ -16,8 +16,8 @@
* You should have received a copy of the GNU General Public License
* along with Updater. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ctest.h"
#include "test_data.h"
#include <check.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
......@@ -30,6 +30,9 @@
#include <util.h>
#include <path_utils.h>
void unittests_add_suite(Suite*);
START_TEST(decompress_buffer) {
// This was generated using shell command
// echo -n "42" | gzip - | xxd -i
......@@ -183,19 +186,23 @@ START_TEST(unpack_package_valid) {
END_TEST
Suite *gen_test_suite(void) {
Suite *result = suite_create("Unpack");
TCase *tcases = tcase_create("tcase");
tcase_add_test(tcases, decompress_buffer);
tcase_add_test(tcases, decompress_lorem_ipsum_short_plain);
tcase_add_test(tcases, decompress_lorem_ipsum_short_gz);
tcase_add_test(tcases, decompress_lorem_ipsum_short_xz);
tcase_add_test(tcases, decompress_lorem_ipsum);
suite_add_tcase(result, tcases);
TCase *tunpack_package = tcase_create("unpack_package");
tcase_add_checked_fixture(tunpack_package, unpack_package_setup,
__attribute__((constructor))
static void suite() {
Suite *suite = suite_create("archive");
TCase *decompress_case = tcase_create("decompress");
tcase_add_test(decompress_case, decompress_buffer);
tcase_add_test(decompress_case, decompress_lorem_ipsum_short_plain);
tcase_add_test(decompress_case, decompress_lorem_ipsum_short_gz);
tcase_add_test(decompress_case, decompress_lorem_ipsum_short_xz);
tcase_add_test(decompress_case, decompress_lorem_ipsum);
suite_add_tcase(suite, decompress_case);
TCase *unpack_case = tcase_create("unpack");
tcase_add_checked_fixture(unpack_case, unpack_package_setup,
unpack_package_teardown);
tcase_add_test(tunpack_package, unpack_package_valid);
suite_add_tcase(result, tunpack_package);
return result;
tcase_add_test(unpack_case, unpack_package_valid);
suite_add_tcase(suite, unpack_case);
unittests_add_suite(suite);
}
......@@ -16,10 +16,12 @@
* You should have received a copy of the GNU General Public License
* along with Updater. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ctest.h"
#include <check.h>
#include <base64.h>
#include <stdlib.h>
void unittests_add_suite(Suite*);
#define BASE64_PLAIN "Hello\n"
#define BASE64_ENCOD "SGVsbG8K"
#define BASE64_INVALID "SGvs$bG8L"
......@@ -42,11 +44,15 @@ START_TEST(base64) {
END_TEST
Suite *gen_test_suite(void) {
Suite *result = suite_create("base64");
TCase *cs = tcase_create("base64");
tcase_add_test(cs, base64_is_valid);
tcase_add_test(cs, base64);
suite_add_tcase(result, cs);
return result;
__attribute__((constructor))
static void suite() {
Suite *suite = suite_create("base64");
TCase *base64_case = tcase_create("base64");
tcase_add_test(base64_case, base64_is_valid);
tcase_add_test(base64_case, base64);
suite_add_tcase(suite, base64_case);
unittests_add_suite(suite);
}
......@@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with Updater. If not, see <http://www.gnu.org/licenses/>.
*/