/tests/t0004-module-loading.sh
Shell | 122 lines | 108 code | 13 blank | 1 comment | 16 complexity | 3cda7df3dad2cf7a46662ae91d620466 MD5 | raw file
1#!/bin/sh 2 3test_description='pdsh dynamic module support' 4 5TEST_MODULE_PATH="$(pwd)/test-modules" 6 7. ${srcdir:-.}/test-lib.sh 8 9if ! test_have_prereq DYNAMIC_MODULES; then 10 skip_all='skipping dynamic module tests, pdsh built with static modules' 11 test_done 12fi 13 14 15if ! test -f $TEST_MODULE_PATH/a.la -a -f $TEST_MODULE_PATH/b.la; then 16 echo "$0: Test modules A & B not built, please run \"make check.\"" >&2 17 exit 1 18fi 19 20 21module_list () { 22 pdsh -L "$EXTRA_PDSH_ARGS" 2>&1 | \ 23 perl -n -e '\ 24 chomp; ($k,$v) = split(/: */); 25 $m = $v if ($k eq "Module"); 26 print "$m $v\n" if ($k eq "Active");' 27} 28 29loaded_modules() { 30 module_list | awk '$2 == "yes" {print $1}' 31} 32 33conflicting_modules() { 34 module_list | awk '$2 == "no" {print $1}' 35} 36 37module_is_active() { 38 loaded_modules | while read m; do 39 if [ "$m" = "$1" ]; then 40 return 0 41 fi 42 done 43} 44 45module_is_inactive() { 46 conflicting_modules | while read m; do 47 if [ "$m" = "$1" ]; then 48 return 0 49 fi 50 done 51} 52 53test_output_matches() { 54 OUTPUT="$1" 55 PATTERN="$2" 56 if ! echo "$OUTPUT" | grep -q "$PATTERN" ; then 57 say_color error "Error: Didn't find pattern \"$PATTERN\"" 58 say_color info "OUTPUT=$OUTPUT" 59 false 60 fi 61} 62 63unset EXTRA_PDSH_ARGS 64 65test_expect_success NOTROOT 'PDSH_MODULE_DIR functionality' ' 66 PDSH_MODULE_DIR=$TEST_DIRECTORY/test-modules 67 module_is_active A && module_is_active B 68' 69 70export PDSH_MODULE_DIR="$TEST_DIRECTORY/test-modules" 71 72test_expect_success NOTROOT 'module A takes precedence over B' ' 73 module_is_active misc/A && module_is_inactive misc/B 74' 75 76test_expect_success NOTROOT 'pdsh -M B ativates module B' ' 77 EXTRA_PDSH_ARGS="-M B" 78 module_is_active misc/B && module_is_inactive misc/A 79' 80test_expect_success NOTROOT 'PDSH_MISC_MODULES option works' ' 81 PDSH_MISC_MODULES=B 82 module_is_active misc/B && module_is_inactive misc/A 83' 84test_expect_success NOTROOT '-M option overrides PDSH_MISC_MODULES environment var' ' 85 OUTPUT=$(PDSH_MISC_MODULES=B pdsh -MA -L 2>&1) 86 say_color error "$OUTPUT" 87' 88test_expect_success NOTROOT 'pdsh help string correctly displays options of loaded modules' ' 89 OUTPUT=$(pdsh -h 2>&1 | grep ^-a) && 90 test_output_matches "$OUTPUT" "Module A" && 91 OUTPUT=$(pdsh -M B -h 2>&1 | grep ^-a) && 92 test_output_matches "$OUTPUT" "Module B" 93' 94test_expect_success NOTROOT 'Loading conflicting module with -M causes error' ' 95 OUTPUT=$(pdsh -MA,B 2>&1 | grep Warning) 96 test_output_matches "$OUTPUT" \ 97 "Failed to initialize requested module \"misc/B\"" 98' 99 100test_expect_success NOTROOT 'Conflicting modules dont run init()' ' 101 PDSH_MODULE_DIR=$TEST_DIRECTORY/test-modules 102 if pdsh -q 2>&1 | grep "B: in init"; then 103 say_color error "Error: init routine for module B run unexpectedly" 104 false 105 fi 106' 107test_expect_success NOTROOT 'Force loaded module runs init()' ' 108 PDSH_MODULE_DIR=$TEST_DIRECTORY/test-modules 109 if ! pdsh -q -MB 2>&1 | grep "B: in init"; then 110 say_color error "Error: init routine for module B not run with -M B" 111 false 112 fi 113' 114test_expect_success NOTROOT 'New conflicting module does not run init() with -M' ' 115 PDSH_MODULE_DIR=$TEST_DIRECTORY/test-modules 116 if pdsh -q -MB 2>&1 | grep "A: in init"; then 117 say_color error "Error: A init routine run with -M B" 118 false 119 fi 120' 121 122test_done