[PATCH 5/6] tests: test alternatives pre-run hooks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Keegan McAllister <keegan@xxxxxxxxxxx>
---
 tests/test-depmod/18alternatives-syntax.sh |   14 ++++
 tests/test-depmod/19alternatives-hooks.sh  |  112 ++++++++++++++++++++++++++++
 2 files changed, 126 insertions(+), 0 deletions(-)
 create mode 100755 tests/test-depmod/19alternatives-hooks.sh

diff --git a/tests/test-depmod/18alternatives-syntax.sh b/tests/test-depmod/18alternatives-syntax.sh
index afd3c26..a9f7333 100755
--- a/tests/test-depmod/18alternatives-syntax.sh
+++ b/tests/test-depmod/18alternatives-syntax.sh
@@ -83,6 +83,20 @@ config
 EOF
 [ "`depmod 2>&1 || echo $?`" = "WARNING: /etc/depmod.alternatives/01alt.conf line 2: malformed alternatives file" ]
 
+# Empty pre-run
+cat > $ALT_CONF <<EOF
+moduledir /other_lib/modules
+pre-run
+EOF
+[ "`depmod 2>&1 || echo $?`" = "WARNING: /etc/depmod.alternatives/01alt.conf line 2: malformed alternatives file" ]
+
+# Empty pre-run (trailing spaces)
+cat > $ALT_CONF <<EOF
+moduledir /other_lib/modules
+pre-run   
+EOF
+[ "`depmod 2>&1 || echo $?`" = "WARNING: /etc/depmod.alternatives/01alt.conf line 2: malformed alternatives file" ]
+
 # Unreadable file
 echo > $ALT_CONF
 chmod 000 $ALT_CONF
diff --git a/tests/test-depmod/19alternatives-hooks.sh b/tests/test-depmod/19alternatives-hooks.sh
new file mode 100755
index 0000000..e6fc499
--- /dev/null
+++ b/tests/test-depmod/19alternatives-hooks.sh
@@ -0,0 +1,112 @@
+#! /bin/sh
+# Test alternatives hooks
+
+rm -rf tests/tmp/*
+
+MODULE_DIR=tests/tmp/lib/modules/$MODTEST_UNAME
+mkdir -p $MODULE_DIR
+ALT_MODULE_DIR=tests/tmp/other_lib/modules/$MODTEST_UNAME
+mkdir -p $ALT_MODULE_DIR
+
+ALTS_DIR=tests/tmp/etc/depmod.alternatives
+mkdir -p $ALTS_DIR
+
+ALT_CONF=$ALTS_DIR/01alt.conf
+
+# Run system() commands for real
+export MODTEST_DO_SYSTEM=1
+
+MOD_DEP=tests/tmp/other_lib/modules/$MODTEST_UNAME/modules.dep
+
+# No hook
+rm -f $MOD_DEP
+cat > $ALT_CONF <<EOF
+moduledir /other_lib/modules
+EOF
+[ "`depmod 2>&1 || echo $?`" = "" ]
+[ -f $MOD_DEP ]
+
+# Basic hook
+rm -f $MOD_DEP
+cat > $ALT_CONF <<EOF
+moduledir /other_lib/modules
+pre-run /bin/echo "Hello from the depmod test suite!"
+EOF
+[ "`depmod 2>&1 || echo $?`" = "Hello from the depmod test suite!" ]
+[ -f $MOD_DEP ]
+
+# Basic hook
+rm -f $MOD_DEP
+cat > $ALT_CONF <<EOF
+moduledir /other_lib/modules
+pre-run expr 2 + 2
+EOF
+[ "`depmod 2>&1 || echo $?`" = "4" ]
+[ -f $MOD_DEP ]
+
+# Custom hook
+HOOK_SH=`pwd`/tests/tmp/etc/myhook.sh
+HOOK_TEST_FILE=tests/tmp/etc/hook-ran
+cat > $HOOK_SH <<EOF
+echo "Hello from the custom hook"
+pwd
+[ -f $MOD_DEP ]  # should not exist
+echo \$?
+touch $HOOK_TEST_FILE
+echo "Hook finished."
+EOF
+chmod +x $HOOK_SH
+
+rm -f $MOD_DEP $HOOK_TEST_FILE
+cat > $ALT_CONF <<EOF
+moduledir /other_lib/modules
+pre-run $HOOK_SH
+EOF
+[ "`depmod 2>&1 || echo $?`" = "Hello from the custom hook
+`pwd`
+1
+Hook finished." ]
+[ -f $MOD_DEP ]
+[ -f $HOOK_TEST_FILE ]
+
+# Failing hook; alternative is skipped
+rm -f $MOD_DEP
+cat > $ALT_CONF <<EOF
+moduledir /other_lib/modules
+pre-run false
+EOF
+[ "`depmod 2>&1 || echo $?`" = "WARNING: skipping alternative due to failed pre-run command: false" ]
+[ ! -f $MOD_DEP ]
+
+# Hook does not exist
+rm -f $MOD_DEP
+cat > $ALT_CONF <<EOF
+moduledir /other_lib/modules
+pre-run depmod_test_this_executable_does_not_exist
+EOF
+[ "`depmod 2>&1 || echo $?`" = "sh: depmod_test_this_executable_does_not_exist: not found
+WARNING: skipping alternative due to failed pre-run command: depmod_test_this_executable_does_not_exist" ]
+[ ! -f $MOD_DEP ]
+
+# Hooks aren't run on dryrun
+rm -f $MOD_DEP $HOOK_TEST_FILE
+cat > $ALT_CONF <<EOF
+moduledir /other_lib/modules
+pre-run touch $HOOK_TEST_FILE
+EOF
+[ "`depmod --dry-run 2>&1 >/dev/null || echo $?`" = "WARNING: doing dry run, skipping pre-run command: touch tests/tmp/etc/hook-ran" ]
+[ ! -f $MOD_DEP ]
+[ ! -f $HOOK_TEST_FILE ]
+[ "`depmod 2>&1 || echo $?`" = "" ]
+[ -f $MOD_DEP ]
+[ -f $HOOK_TEST_FILE ]
+
+# Empty pre-run line => alternative skipped
+rm -f $MOD_DEP
+cat > $ALT_CONF <<EOF
+moduledir /other_lib/modules
+# some trailing spaces on next line
+pre-run   
+EOF
+[ "`depmod 2>&1 || echo $?`" = "WARNING: /etc/depmod.alternatives/01alt.conf line 3: malformed alternatives file" ]
+[ ! -f $MOD_DEP ]
-- 
1.7.2.3

--
To unsubscribe from this list: send the line "unsubscribe linux-modules" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux