From 1683b76a2df7c33503950a60452a66d6f293cea1 Mon Sep 17 00:00:00 2001 From: Nikki VonHollen Date: Wed, 21 Dec 2011 18:45:41 -0800 Subject: [PATCH] Updated to latest MockLibc, fixing build bug when srcdir != builddir --- noinst/mocklibc/.gitignore | 26 ------- noinst/mocklibc/bin/Makefile.am | 24 ++++++- noinst/mocklibc/bin/mocklibc | 33 -------- noinst/mocklibc/bin/mocklibc-test | 137 ---------------------------------- noinst/mocklibc/bin/mocklibc-test.in | 136 +++++++++++++++++++++++++++++++++ noinst/mocklibc/bin/mocklibc.in | 34 +++++++++ noinst/mocklibc/configure.ac | 6 ++ test/Makefile.am | 2 +- 8 files changed, 199 insertions(+), 199 deletions(-) delete mode 100644 noinst/mocklibc/.gitignore delete mode 100755 noinst/mocklibc/bin/mocklibc delete mode 100755 noinst/mocklibc/bin/mocklibc-test create mode 100644 noinst/mocklibc/bin/mocklibc-test.in create mode 100644 noinst/mocklibc/bin/mocklibc.in diff --git a/noinst/mocklibc/.gitignore b/noinst/mocklibc/.gitignore deleted file mode 100644 index 479141c..0000000 --- a/noinst/mocklibc/.gitignore +++ /dev/null @@ -1,26 +0,0 @@ -# Built by 'autogen --install' -Makefile -Makefile.in -configure -config.* -aclocal.m4 -autom4te.cache -depcomp -install-sh -libtool -ltmain.sh -missing -stamp-h1 - -# Built by 'make' -*.os -*.so -*.o -*.la -*.lo -.libs -.deps -src/mocklibc-debug-netgroup - -# Built by 'make dist' -mocklibc-*.tar.gz diff --git a/noinst/mocklibc/bin/Makefile.am b/noinst/mocklibc/bin/Makefile.am index 878bb9a..a2e65e0 100644 --- a/noinst/mocklibc/bin/Makefile.am +++ b/noinst/mocklibc/bin/Makefile.am @@ -1,5 +1,25 @@ -dist_bin_SCRIPTS = mocklibc +bin_SCRIPTS = mocklibc -dist_check_SCRIPTS = mocklibc-test +check_SCRIPTS = mocklibc-test TESTS = mocklibc-test + +EXTRA_DIST = mocklibc.in mocklibc-test.in +CLEANFILES = mocklibc mocklibc-test + + +# Substitute build variables in shell scripts +# See section "4.8.2 Installation Directory Variables" in autoconf manual + +edit = sed \ + -e 's|@libdir[@]|$(libdir)|g' \ + -e 's|@libname[@]|$(libname)|g' \ + -e 's|@top_srcdir[@]|$(top_srcdir)|g' \ + -e 's|@top_builddir[@]|$(top_builddir)|g' + +mocklibc mocklibc-test: Makefile + $(edit) $(srcdir)/$@.in > $@ + chmod a+x $@ + +mocklibc: $(srcdir)/mocklibc.in +mocklibc-test: $(srcdir)/mocklibc-test.in diff --git a/noinst/mocklibc/bin/mocklibc b/noinst/mocklibc/bin/mocklibc deleted file mode 100755 index 7bd081d..0000000 --- a/noinst/mocklibc/bin/mocklibc +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -# Copyright 2011 Google Inc. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Author: Nikki VonHollen - - -LIBNAME="libmocklibc.so" -BASEDIR=`dirname "$0"` - -LIBDIR="${BASEDIR}/../src/.libs" -LIBPATH="${LIBDIR}/${LIBNAME}" - -# Include Mocklibc's project dir if we can find it -if [[ -f "$LIBPATH" ]] -then - export LD_LIBRARY_PATH="${LIBDIR}:${LD_LIBRARY_PATH}" -fi - -# Exec the requested app, replacing this one -LD_PRELOAD="$LIBNAME" exec $@ diff --git a/noinst/mocklibc/bin/mocklibc-test b/noinst/mocklibc/bin/mocklibc-test deleted file mode 100755 index 658278d..0000000 --- a/noinst/mocklibc/bin/mocklibc-test +++ /dev/null @@ -1,137 +0,0 @@ -#!/bin/bash - -# Copyright 2011 Google Inc. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# Author: Nikki VonHollen - - -# Figure out where everything is - -BASEDIR=`dirname "$0"` -MOCKLIBC="${BASEDIR}/mocklibc" -ETCDIR="${BASEDIR}/../example" - - -# Setup the mock environment - -export MOCK_PASSWD="${ETCDIR}/passwd" -export MOCK_GROUP="${ETCDIR}/group" -export MOCK_NETGROUP="${ETCDIR}/netgroup" - - -# Test helper definitions - -TESTCOUNT=0 -FAILCOUNT=0 - -fail () { - echo "Test Failed:" - echo $@ >&2 - echo - FAILCOUNT=$((FAILCOUNT+1)) -} - -finish () { - if [[ $FAILCOUNT -gt 0 ]] - then - echo "Failed $FAILCOUNT of $TESTCOUNT tests." - exit 1 - else - echo "Passed $TESTCOUNT tests." - exit 0 - fi -} - -assert_true () { - $MOCKLIBC $@ || fail "assert true: $@" - TESTCOUNT=$((TESTCOUNT+1)) -} - -assert_false () { - $MOCKLIBC $@ && fail "assert false: $@" - TESTCOUNT=$((TESTCOUNT+1)) -} - -assert_grep () { - $MOCKLIBC ${@:2} | grep -q "^${1}\$" || fail "'$1' doesn't match output of: ${@:2}" - TESTCOUNT=$((TESTCOUNT+1)) -} - - -# Test implementations - -test_passwd () { - # Test user ids - assert_grep "0" id -u root - assert_grep "500" id -u john - assert_grep "501" id -u jane - - # Test primary groups - assert_grep "root" id -gn root - assert_grep "john" id -gn john - assert_grep "jane" id -gn jane -} - -test_group () { - # Test group lists for users - assert_grep "root" id -Gn root - assert_grep "john users" id -Gn john - assert_grep "jane users" id -Gn jane -} - -test_netgroup () { - # Test whether each user is each netgroup - assert_true innetgr foo -u john - assert_false innetgr foo -u jane - - assert_true innetgr bar -u jane - assert_false innetgr bar -u john - - assert_true innetgr baz -u john - assert_true innetgr baz -u jane - assert_false innetgr baz -u henry - - assert_true innetgr all -u john - assert_true innetgr all -u jane - assert_true innetgr all -u henry - - assert_false innetgr none -u john - assert_false innetgr none -u jane - assert_false innetgr none -u henry - - assert_false innetgr fake -u john -} - - -# Run the tests and print a report - -if (which id >/dev/null 2>&1) -then - test_passwd - test_group -else - echo "No 'id' command found, skipping passwd and group tests." >&2 -fi - -if (which innetgr >/dev/null 2>&1) -then - test_netgroup -else - echo "No 'innetgr' command found, skipping netgroup tests." >&2 -fi - - -finish - diff --git a/noinst/mocklibc/bin/mocklibc-test.in b/noinst/mocklibc/bin/mocklibc-test.in new file mode 100644 index 0000000..9f00a77 --- /dev/null +++ b/noinst/mocklibc/bin/mocklibc-test.in @@ -0,0 +1,136 @@ +#!/bin/bash + +# Copyright 2011 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Author: Nikki VonHollen + + +# Figure out where everything is + +MOCKLIBC="@top_builddir@/bin/mocklibc" +ETCDIR="@top_srcdir@/example" + + +# Setup the mock environment + +export MOCK_PASSWD="${ETCDIR}/passwd" +export MOCK_GROUP="${ETCDIR}/group" +export MOCK_NETGROUP="${ETCDIR}/netgroup" + + +# Test helper definitions + +TESTCOUNT=0 +FAILCOUNT=0 + +fail () { + echo "Test Failed:" + echo $@ >&2 + echo + FAILCOUNT=$((FAILCOUNT+1)) +} + +finish () { + if [[ $FAILCOUNT -gt 0 ]] + then + echo "Failed $FAILCOUNT of $TESTCOUNT tests." + exit 1 + else + echo "Passed $TESTCOUNT tests." + exit 0 + fi +} + +assert_true () { + $MOCKLIBC $@ || fail "assert true: $@" + TESTCOUNT=$((TESTCOUNT+1)) +} + +assert_false () { + $MOCKLIBC $@ && fail "assert false: $@" + TESTCOUNT=$((TESTCOUNT+1)) +} + +assert_grep () { + $MOCKLIBC ${@:2} | grep -q "^${1}\$" || fail "'$1' doesn't match output of: ${@:2}" + TESTCOUNT=$((TESTCOUNT+1)) +} + + +# Test implementations + +test_passwd () { + # Test user ids + assert_grep "0" id -u root + assert_grep "500" id -u john + assert_grep "501" id -u jane + + # Test primary groups + assert_grep "root" id -gn root + assert_grep "john" id -gn john + assert_grep "jane" id -gn jane +} + +test_group () { + # Test group lists for users + assert_grep "root" id -Gn root + assert_grep "john users" id -Gn john + assert_grep "jane users" id -Gn jane +} + +test_netgroup () { + # Test whether each user is each netgroup + assert_true innetgr foo -u john + assert_false innetgr foo -u jane + + assert_true innetgr bar -u jane + assert_false innetgr bar -u john + + assert_true innetgr baz -u john + assert_true innetgr baz -u jane + assert_false innetgr baz -u henry + + assert_true innetgr all -u john + assert_true innetgr all -u jane + assert_true innetgr all -u henry + + assert_false innetgr none -u john + assert_false innetgr none -u jane + assert_false innetgr none -u henry + + assert_false innetgr fake -u john +} + + +# Run the tests and print a report + +if (which id >/dev/null 2>&1) +then + test_passwd + test_group +else + echo "No 'id' command found, skipping passwd and group tests." >&2 +fi + +if (which innetgr >/dev/null 2>&1) +then + test_netgroup +else + echo "No 'innetgr' command found, skipping netgroup tests." >&2 +fi + + +finish + diff --git a/noinst/mocklibc/bin/mocklibc.in b/noinst/mocklibc/bin/mocklibc.in new file mode 100644 index 0000000..dc18855 --- /dev/null +++ b/noinst/mocklibc/bin/mocklibc.in @@ -0,0 +1,34 @@ +#!/bin/bash + +# Copyright 2011 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Author: Nikki VonHollen + + +BASEDIR=`dirname $0` +LIBDIR="${BASEDIR}/../src/.libs" +LIBPATH="${LIBDIR}/@libname@" + +if [[ -f "$LIBPATH" ]] +then + # Include Mocklibc's project build dir if we can find it + export LD_LIBRARY_PATH="${LIBDIR}:${LD_LIBRARY_PATH}" +else + # Use the system version instead, w/o requiring ldconfig + export LD_LIBRARY_PATH="@libdir@:${LD_LIBRARY_PATH}" +fi + +# Exec the requested app, replacing this one +LD_PRELOAD="@libname@" exec $@ diff --git a/noinst/mocklibc/configure.ac b/noinst/mocklibc/configure.ac index 676ca7e..70798ee 100644 --- a/noinst/mocklibc/configure.ac +++ b/noinst/mocklibc/configure.ac @@ -25,6 +25,12 @@ AC_TYPE_SSIZE_T AC_FUNC_MALLOC AC_CHECK_FUNCS([endgrent endpwent memset regcomp strdup]) +# Build wrapper scripts from templates +AC_SUBST([libname], [libmocklibc.so]) +#AC_CONFIG_FILES([bin/mocklibc], [chmod +x bin/mocklibc], [libname=${libname}]) +#AC_CONFIG_FILES([bin/mocklibc-test], [chmod +x bin/mocklibc-test], +# [libname=${libname}])) + AC_OUTPUT([ Makefile src/Makefile diff --git a/test/Makefile.am b/test/Makefile.am index 86a806c..d46fe6f 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -12,7 +12,7 @@ EXTRA_DIST = data export MOCK_PASSWD := $(abs_top_srcdir)/test/data/etc/passwd export MOCK_GROUP := $(abs_top_srcdir)/test/data/etc/group export MOCK_NETGROUP := $(abs_top_srcdir)/test/data/etc/netgroup -export TESTS_ENVIRONMENT := $(abs_top_srcdir)/noinst/mocklibc/bin/mocklibc +export TESTS_ENVIRONMENT := $(abs_top_builddir)/noinst/mocklibc/bin/mocklibc clean-local : rm -f *~ -- 1.7.5.4