From 8a36ff81a49e70d53e56942ea7d5db4f49b185f0 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Thu, 18 Mar 2021 13:49:55 -0400 Subject: [PATCH] Add basic shell tests script framework Import a stripped down shell tests script framework from babeltrace2. This is part of an effort to standardise our autotools setup across project to simplify maintenance. Change-Id: I41ea4b186fe744fd6841d866daa87a802c96b692 Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- .gitignore | 1 - configure.ac | 2 -- tests/Makefile.am | 8 +++++--- tests/unit/ust-elf/Makefile.am | 2 ++ tests/unit/ust-elf/test_ust_elf | 13 ++++++++++++ tests/unit/ust-elf/test_ust_elf.in | 5 ----- tests/utils/Makefile.am | 3 ++- tests/utils/utils.sh | 33 ++++++++++++++++++++++++++++++ 8 files changed, 55 insertions(+), 12 deletions(-) create mode 100755 tests/unit/ust-elf/test_ust_elf delete mode 100644 tests/unit/ust-elf/test_ust_elf.in create mode 100755 tests/utils/utils.sh diff --git a/.gitignore b/.gitignore index 26cb98ff..76aa21b7 100644 --- a/.gitignore +++ b/.gitignore @@ -84,7 +84,6 @@ tests/unit/libmsgpack/test_msgpack tests/unit/libringbuffer/test_shm tests/unit/pthread_name/test_pthread_name tests/unit/snprintf/test_snprintf -tests/unit/ust-elf/test_ust_elf tests/unit/ust-elf/ust-elf # Java agent library diff --git a/configure.ac b/configure.ac index 414daf6b..bc119c38 100644 --- a/configure.ac +++ b/configure.ac @@ -554,8 +554,6 @@ AC_CONFIG_FILES([ lttng-ust-ctl.pc ]) -AC_CONFIG_FILES([tests/unit/ust-elf/test_ust_elf],[chmod +x tests/unit/ust-elf/test_ust_elf]) - AC_OUTPUT diff --git a/tests/Makefile.am b/tests/Makefile.am index 6ecd565f..7be53331 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,9 +2,11 @@ SUBDIRS = utils unit compile benchmark -LOG_DRIVER_FLAGS='--merge' -LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \ - $(srcdir)/utils/tap-driver.sh +LOG_DRIVER_FLAGS = --merge --comments +LOG_DRIVER = env AM_TAP_AWK='$(AWK)' \ + UST_TESTS_SRCDIR='$(abs_top_srcdir)/tests' \ + UST_TESTS_BUILDDIR='$(abs_top_builddir)/tests' \ + $(SHELL) $(srcdir)/utils/tap-driver.sh TESTS = \ unit/libringbuffer/test_shm \ diff --git a/tests/unit/ust-elf/Makefile.am b/tests/unit/ust-elf/Makefile.am index ff7fb7df..339feaf1 100644 --- a/tests/unit/ust-elf/Makefile.am +++ b/tests/unit/ust-elf/Makefile.am @@ -7,6 +7,8 @@ ust_elf_SOURCES = ust-elf.c ust_elf_LDADD = $(top_builddir)/liblttng-ust/liblttng-ust.la \ $(top_builddir)/tests/utils/libtap.a +dist_check_SCRIPTS = test_ust_elf + # Directories added to EXTRA_DIST will be recursively copied to the distribution. EXTRA_DIST = \ $(srcdir)/data \ diff --git a/tests/unit/ust-elf/test_ust_elf b/tests/unit/ust-elf/test_ust_elf new file mode 100755 index 00000000..afc6ecad --- /dev/null +++ b/tests/unit/ust-elf/test_ust_elf @@ -0,0 +1,13 @@ +#!/bin/bash +# SPDX-License-Identifier: LGPL-2.1-only + +if [ "x${UST_TESTS_SRCDIR:-}" != "x" ]; then + UTILSSH="$UST_TESTS_SRCDIR/utils/utils.sh" +else + UTILSSH="$(dirname "$0")/../../utils/utils.sh" +fi + +# shellcheck source=../utils/utils.sh +source "$UTILSSH" + +"${UST_TESTS_BUILDDIR}/unit/ust-elf/ust-elf" "${UST_TESTS_SRCDIR}/unit/ust-elf" diff --git a/tests/unit/ust-elf/test_ust_elf.in b/tests/unit/ust-elf/test_ust_elf.in deleted file mode 100644 index 99f345dd..00000000 --- a/tests/unit/ust-elf/test_ust_elf.in +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: LGPL-2.1-only - -TEST_DIR=$(dirname "$0") -"${TEST_DIR}/ust-elf" "@abs_top_srcdir@/tests/unit/ust-elf" diff --git a/tests/utils/Makefile.am b/tests/utils/Makefile.am index 402ba862..bfe52070 100644 --- a/tests/utils/Makefile.am +++ b/tests/utils/Makefile.am @@ -4,4 +4,5 @@ noinst_LIBRARIES = libtap.a libtap_a_SOURCES = tap.c tap.h dist_check_SCRIPTS = \ tap-driver.sh \ - tap.sh + tap.sh \ + utils.sh diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh new file mode 100755 index 00000000..cefb782c --- /dev/null +++ b/tests/utils/utils.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (c) 2019 Michael Jeanson +# Copyright (C) 2019 Philippe Proulx +# + +# This file is meant to be sourced at the start of shell script-based tests. + + +# Error out when encountering an undefined variable +set -u + +# If "readlink -f" is available, get a resolved absolute path to the +# tests source dir, otherwise make do with a relative path. +scriptdir="$(dirname "${BASH_SOURCE[0]}")" +if readlink -f "." >/dev/null 2>&1; then + testsdir=$(readlink -f "$scriptdir/..") +else + testsdir="$scriptdir/.." +fi + +# Allow overriding the source and build directories +if [ "x${UST_TESTS_SRCDIR:-}" = "x" ]; then + UST_TESTS_SRCDIR="$testsdir" +fi +export UST_TESTS_SRCDIR + +if [ "x${UST_TESTS_BUILDDIR:-}" = "x" ]; then + UST_TESTS_BUILDDIR="$testsdir" +fi +export UST_TESTS_BUILDDIR -- 2.34.1