From 486d5176749922bf0eb1ffc7d99a4b1b62740be3 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 24 Mar 2008 07:17:05 +0000 Subject: setup a bit of a test framework --- mk/scripts.mk | 1 + sh/Makefile | 3 ++ sh/runtests.sh | 25 +++++++++++++++++ src/test/Makefile | 2 +- src/test/runtests.sh | 69 +++++++++++++++++++++++++++++++++++++++++++++ src/test/symbols.sh | 78 --------------------------------------------------- test/setup_env.sh | 22 +++++++++++++++ test/skel.runtests.sh | 5 ++++ 8 files changed, 126 insertions(+), 79 deletions(-) create mode 100755 sh/runtests.sh create mode 100755 src/test/runtests.sh delete mode 100755 src/test/symbols.sh create mode 100755 test/setup_env.sh create mode 100755 test/skel.runtests.sh diff --git a/mk/scripts.mk b/mk/scripts.mk index 3021c92c..146b56a5 100644 --- a/mk/scripts.mk +++ b/mk/scripts.mk @@ -43,6 +43,7 @@ realinstall: ${BIN} ${CONF} ${CONF_APPEND} install: all realinstall ${INSTALLAFTER} check test:: + @if test -e runtests.sh ; then ./runtests.sh || exit $$? ; fi # A lot of scripts don't have anything to clean # Also, some rm implentation require a file argument regardless of error diff --git a/sh/Makefile b/sh/Makefile index bd55cbda..2f10ef53 100644 --- a/sh/Makefile +++ b/sh/Makefile @@ -18,3 +18,6 @@ _installafter: @# Put functions.sh into the init.d dir so 3rd party apps don't have to @# be multilib aware ln -snf ${PREFIX}/${RC_LIB}/sh/functions.sh ${DESTDIR}/${PREFIX}/${INITDIR} || exit $$? + +check test:: + ./runtests.sh diff --git a/sh/runtests.sh b/sh/runtests.sh new file mode 100755 index 00000000..d0d6a17d --- /dev/null +++ b/sh/runtests.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +top_srcdir=${top_srcdir:-..} +. ${top_srcdir}/test/setup_env.sh + +ret=0 + +tret=0 +ebegin "Testing yesno()" +for f in yes YES Yes true TRUE True 1 ; do + if ! yesno ${f} ; then + ((tret+=1)) + echo "!${f}!" + fi +done +for f in no NO No false FALSE False 0 ; do + if yesno ${f} ; then + ((tret+=1)) + echo "!${f}!" + fi +done +eend ${tret} +((ret+=tret)) + +exit ${ret} diff --git a/src/test/Makefile b/src/test/Makefile index c3e879ea..d7fde60f 100644 --- a/src/test/Makefile +++ b/src/test/Makefile @@ -3,7 +3,7 @@ all: install: check test:: - ./symbols.sh + ./runtests.sh clean: rm -f *.out diff --git a/src/test/runtests.sh b/src/test/runtests.sh new file mode 100755 index 00000000..47bac3b1 --- /dev/null +++ b/src/test/runtests.sh @@ -0,0 +1,69 @@ +#!/bin/sh + +top_srcdir=${top_srcdir:-../..} +. ${top_srcdir}/test/setup_env.sh + +libeinfo_srcdir="${srcdir}/../libeinfo" +libeinfo_builddir="${builddir}/../libeinfo" +librc_srcdir="${srcdir}/../librc" +librc_builddir="${builddir}/../librc" +rc_srcdir="${srcdir}/../rc" +rc_builddir="${builddir}/../rc" + +checkit() { + local base=$1; shift + echo "$@" | tr ' ' '\n' > ${base}.out + diff -u ${base}.list ${base}.out + eend $? + ret=$(($ret + $?)) +} + +ret=0 + +ebegin "Checking exported symbols in libeinfo.so (data)" +checkit einfo.data $( +readelf -Ws ${libeinfo_builddir}/libeinfo.so \ + | awk '$4 == "OBJECT" && $5 == "GLOBAL" && $7 != "UND" {print $NF}' \ + | sort -u +) + +ebegin "Checking exported symbols in libeinfo.so (functions)" +checkit einfo.funcs $( +readelf -Ws ${libeinfo_builddir}/libeinfo.so \ + | awk '$4 == "FUNC" && $5 == "GLOBAL" && $7 != "UND" {print $NF}' \ + | sort -u \ + | egrep -v \ + -e '^_(init|fini)$' +) + +ebegin "Checking exported symbols in librc.so (data)" +checkit rc.data $( +readelf -Ws ${librc_builddir}/librc.so \ + | awk '$4 == "OBJECT" && $5 == "GLOBAL" && $7 != "UND" {print $NF}' \ + | sort -u +) + +ebegin "Checking exported symbols in librc.so (functions)" +checkit rc.funcs $( +readelf -Ws ${librc_builddir}/librc.so \ + | awk '$4 == "FUNC" && $5 == "GLOBAL" && $7 != "UND" {print $NF}' \ + | sort -u \ + | egrep -v \ + -e '^_(init|fini)$' +) + +ebegin "Checking hidden functions in librc.so" +sed -n '/^librc_hidden_proto/s:.*(\(.*\))$:\1:p' ${librc_srcdir}/librc.h \ + | sort -u \ + > librc.funcs.hidden.list +readelf -Wr $(grep -l '#include[[:space:]]"librc\.h"' ${librc_srcdir}/*.c | sed 's:\.c$:.o:') \ + | awk '$5 ~ /^rc_/ {print $5}' \ + | sort -u \ + | egrep -v '^rc_environ_fd$' \ + > librc.funcs.hidden.out +syms=$(diff -u librc.funcs.hidden.list librc.funcs.hidden.out | sed -n '/^+[^+]/s:^+::p') +[ -z "${syms}" ] +eend $? "Missing hidden defs:"$'\n'"${syms}" +ret=$(($ret + $?)) + +exit ${ret} diff --git a/src/test/symbols.sh b/src/test/symbols.sh deleted file mode 100755 index 56fe0489..00000000 --- a/src/test/symbols.sh +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/sh - -top_srcdir=${top_srcdir:-../..} -srcdir=${builddir:-.} -top_builddir=${top_srcdir:-../..} -builddir=${builddir:-.} - -. ${top_srcdir}/sh/functions.sh - -libeinfo_srcdir="${srcdir}/../libeinfo" -libeinfo_builddir="${builddir}/../libeinfo" -librc_srcdir="${srcdir}/../librc" -librc_builddir="${builddir}/../librc" -rc_srcdir="${srcdir}/../rc" -rc_builddir="${builddir}/../rc" - -make -s -C ${rc_builddir} links - -export LD_LIBRARY_PATH=${libeinfo_builddir}:${librc_builddir}:${LD_LIBRARY_PATH} -export PATH=${rc_builddir}:${PATH} - -checkit() { - local base=$1; shift - echo "$@" | tr ' ' '\n' > ${base}.out - diff -u ${base}.list ${base}.out - eend $? - ret=$(($ret + $?)) -} - -ret=0 - -ebegin "Checking exported symbols in libeinfo.so (data)" -checkit einfo.data $( -readelf -Ws ${libeinfo_builddir}/libeinfo.so \ - | awk '$4 == "OBJECT" && $5 == "GLOBAL" && $7 != "UND" {print $NF}' \ - | sort -u -) - -ebegin "Checking exported symbols in libeinfo.so (functions)" -checkit einfo.funcs $( -readelf -Ws ${libeinfo_builddir}/libeinfo.so \ - | awk '$4 == "FUNC" && $5 == "GLOBAL" && $7 != "UND" {print $NF}' \ - | sort -u \ - | egrep -v \ - -e '^_(init|fini)$' -) - -ebegin "Checking exported symbols in librc.so (data)" -checkit rc.data $( -readelf -Ws ${librc_builddir}/librc.so \ - | awk '$4 == "OBJECT" && $5 == "GLOBAL" && $7 != "UND" {print $NF}' \ - | sort -u -) - -ebegin "Checking exported symbols in librc.so (functions)" -checkit rc.funcs $( -readelf -Ws ${librc_builddir}/librc.so \ - | awk '$4 == "FUNC" && $5 == "GLOBAL" && $7 != "UND" {print $NF}' \ - | sort -u \ - | egrep -v \ - -e '^_(init|fini)$' -) - -ebegin "Checking hidden functions in librc.so" -sed -n '/^librc_hidden_proto/s:.*(\(.*\))$:\1:p' ${librc_srcdir}/librc.h \ - | sort -u \ - > librc.funcs.hidden.list -readelf -Wr $(grep -l '#include[[:space:]]"librc\.h"' ${librc_srcdir}/*.c | sed 's:\.c$:.o:') \ - | awk '$5 ~ /^rc_/ {print $5}' \ - | sort -u \ - | egrep -v '^rc_environ_fd$' \ - > librc.funcs.hidden.out -syms=$(diff -u librc.funcs.hidden.list librc.funcs.hidden.out | sed -n '/^+[^+]/s:^+::p') -[ -z "${syms}" ] -eend $? "Missing hidden defs:"$'\n'"${syms}" -ret=$(($ret + $?)) - -exit ${ret} diff --git a/test/setup_env.sh b/test/setup_env.sh new file mode 100755 index 00000000..96fdf9d2 --- /dev/null +++ b/test/setup_env.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +if [ -z "${top_srcdir}" ] ; then + echo "You must set top_srcdir before sourcing this file" 1>&2 + exit 1 +fi + +srcdir=${srcdir:-.} +top_builddir=${top_builddir:-${top_srcdir}} +builddir=${builddir:-${srcdir}} + +export LD_LIBRARY_PATH=${top_builddir}/src/libeinfo:${top_builddir}/src/librc:${LD_LIBRARY_PATH} +export PATH=${top_builddir}/src/rc:${PATH} + +${MAKE:-make} -s -C ${top_srcdir}/src/rc links + +. ${top_srcdir}/sh/functions.sh + +if [ $? -ne 0 ] ; then + echo "Sourcing functions.sh failed !?" 1>&2 + exit 1 +fi diff --git a/test/skel.runtests.sh b/test/skel.runtests.sh new file mode 100755 index 00000000..cda20027 --- /dev/null +++ b/test/skel.runtests.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +# top_srcdir=${top_srcdir:-SET/THIS/PATH/OK!?} +. ${top_srcdir}/test/setup_env.sh + -- cgit v1.2.3