This adds some basic interface tests.  It makes use of the --dry-run
option to determine which variables have been set and to which values.
We also check for the various warnings generated.

Signed-off-by: Andy Whitcroft <[EMAIL PROTECTED]>
---
 tests/Makefile     |   10 +++-
 tests/hugectl-test |  185 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/run_tests.sh |   55 ++++++++++++---
 3 files changed, 238 insertions(+), 12 deletions(-)
 create mode 100644 tests/hugectl-test

diff --git a/tests/Makefile b/tests/Makefile
index 009f75f..fbe9700 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,5 +1,6 @@
 PREFIX = /usr/local
 
+HOST_TESTS = hugectl-test
 LIB_TESTS = gethugepagesize test_root find_path unlinked_fd misalign \
        readback truncate shared private fork-cow empty_mounts large_mounts \
        meminfo_nohuge ptrace-write-hugepage icache-hygiene slbpacaflush \
@@ -66,6 +67,7 @@ ALLHELPERLIBS = $(foreach 
DIR,$(OBJDIRS),$(HELPER_LIBS:%=$(DIR)/%))
 ifdef CC64
 ALLTESTS += $(TESTS_64:%=obj64/%)
 endif
+ALLHOST = $(HOST_TESTS:%=obj/%)
 
 objs_needing_wrappers = \
        $(foreach W,$(WRAPPERS:%.sh=%),$(filter $(1)/$(W),$(ALLTESTS)))
@@ -73,7 +75,7 @@ WRAPPERS32 = $(addsuffix .sh,$(call 
objs_needing_wrappers,obj32))
 WRAPPERS64 = $(addsuffix .sh,$(call objs_needing_wrappers,obj64))
 ALLWRAPPERS = $(WRAPPERS32) $(WRAPPERS64)
 
-all:   $(ALLTESTS) $(ALLHELPERS) $(ALLHELPERLIBS) $(ALLWRAPPERS)
+all:   $(ALLTESTS) $(ALLHELPERS) $(ALLHELPERLIBS) $(ALLWRAPPERS) $(ALLHOST)
 
 shmoverride_linked.c: shmoverride_unlinked.c
        ln -s shmoverride_unlinked.c shmoverride_linked.c
@@ -108,6 +110,12 @@ obj64/libheapshrink.so: obj64/heapshrink-helper-pic.o
        @mkdir -p obj64
        $(CC64) -Wl,-soname,$(notdir $@) -shared -o $@ $^
 
+$(HOST_TESTS:%=obj/%): obj/%: %
+       @$(VECHO) BUILD "(host test)" $@
+       @mkdir -p obj
+       cp -p $< $@
+       chmod +x $@
+
 $(LIB_TESTS:%=obj32/%): %: %.o obj32/testutils.o obj32/libtestutils.o
        @$(VECHO) LD32 "(lib test)" $@
        $(CC32) $(LDFLAGS) $(LDFLAGS32) -o $@ $^ $(LDLIBS) -lhugetlbfs
diff --git a/tests/hugectl-test b/tests/hugectl-test
new file mode 100644
index 0000000..99426b5
--- /dev/null
+++ b/tests/hugectl-test
@@ -0,0 +1,185 @@
+#!/bin/bash
+
+RC_PASS=0
+RC_FAIL=1
+
+function run() {
+       RET=`"$@" --dry-run 2>&1`
+       if [ "$QUIET_TEST" = '' ]; then
+               echo "$@: "
+               echo "$RET" | sed -e 's/^/ >/'
+       fi
+}
+
+nl="
+"
+function check_for() {
+       typeset result="$1"
+       typeset pattern="$2"
+
+       match=1
+       eval "
+               case \"\$nl\$result\$nl\" in
+               *\${nl}\$pattern\${nl}*)        match=0 ;;
+               esac
+       "
+
+       return $match
+}
+
+function good() {
+       typeset test="$1"
+       typeset result="$2"
+       typeset pattern="$3"
+
+       if ! check_for "$result" "$pattern"; then
+               echo "FAIL: hugectl $test: $pattern not present" 1>&2
+               echo "$result"
+               exit $RC_FAIL
+       fi
+}
+function bad() {
+       typeset test="$1"
+       typeset result="$2"
+       typeset pattern="$3"
+
+       if check_for "$result" "$pattern"; then
+               echo "FAIL: hugectl $test: $pattern was present" 1>&2
+               echo "$result"
+               exit $RC_FAIL
+       fi
+}
+
+# Check base settings
+test="hugectl"
+run $test
+good "$test" "$RET" "HUGETLB_VERBOSE='1'"
+good "$test" "$RET" "LD_PRELOAD='libhugetlbfs.so'"
+good "$test" "$RET" "LD_LIBRARY_PATH='*:'"
+
+# Check verbose flag
+test="hugectl -v"
+run $test
+good "$test" "$RET" "HUGETLB_VERBOSE='2'"
+
+test="hugectl -v -v"
+run $test
+good "$test" "$RET" "HUGETLB_VERBOSE='3'"
+
+test="hugectl --verbose=10"
+run $test
+good "$test" "$RET" "HUGETLB_VERBOSE='10'"
+
+test="hugectl --verbose=99"
+run $test
+good "$test" "$RET" "HUGETLB_VERBOSE='99'"
+
+test="hugectl --verbose=99 -v"
+run $test
+good "$test" "$RET" "HUGETLB_VERBOSE='99'"
+
+# Check the library path flags
+test="hugectl"
+run $test
+good "$test" "$RET" "LD_LIBRARY_PATH='*:'"
+
+test="hugectl --library-use-path"
+run $test
+bad "$test" "$RET" "LD_LIBRARY_PATH='*'"
+
+test="hugectl --library-path /somewhere"
+run $test
+good "$test" "$RET" "LD_LIBRARY_PATH='/somewhere/*'"
+
+# Check the --no-preload flag
+test="hugectl"
+run $test
+good "$test" "$RET" "LD_PRELOAD='libhugetlbfs.so'"
+
+test="hugectl --no-preload"
+run $test
+bad "$test" "$RET" "LD_PRELOAD='*'"
+
+# Check --text
+test="hugectl --text"
+run $test
+good "$test" "$RET" "HUGETLB_ELFMAP='R'"
+
+test="hugectl --text=FOO"
+run $test
+good "$test" "$RET" "HUGETLB_ELFMAP='R=FOO'"
+
+# Check --data
+test="hugectl --data"
+run $test
+good "$test" "$RET" "HUGETLB_ELFMAP='W'"
+
+test="hugectl --data=FOO"
+run $test
+good "$test" "$RET" "HUGETLB_ELFMAP='W=FOO'"
+
+# Check --bss
+test="hugectl --bss"
+run $test
+good "$test" "$RET" "HUGETLB_ELFMAP='W'"
+
+test="hugectl --bss=FOO"
+run $test
+good "$test" "$RET" "HUGETLB_ELFMAP='W=FOO'"
+
+# Check for --bss/--data warnings
+warn="* WARNING: data and bss remapped together *"
+
+test="hugectl -v --data"
+run $test
+good "$test" "$RET" "$warn"
+
+test="hugectl -v --bss"
+run $test
+good "$test" "$RET" "$warn"
+
+test="hugectl -v --data --bss"
+run $test
+bad "$test" "$RET" "$warn"
+
+# Check --disable & warnings
+warn="* WARNING: --disable masks requested remap*"
+
+test="hugectl -v --disable"
+run $test
+good "$test" "$RET" "HUGETLB_ELFMAP='no'"
+bad  "$test" "$RET" "$warn"
+
+test="hugectl -v --disable --text"
+run $test
+good "$test" "$RET" "HUGETLB_ELFMAP='no'"
+good  "$test" "$RET" "$warn"
+
+test="hugectl -v --disable --data"
+run $test
+good "$test" "$RET" "HUGETLB_ELFMAP='no'"
+good  "$test" "$RET" "$warn"
+
+# Check --heap
+test="hugectl --heap"
+run $test
+good "$test" "$RET" "HUGETLB_MORECORE='yes'"
+
+test="hugectl --heap=FOO"
+run $test
+good "$test" "$RET" "HUGETLB_MORECORE='FOO'"
+
+# Check --shm & warnings
+warn="* WARNING: shm segments may only be mapped in the default hugepage size"
+
+test="hugectl -v --shm"
+run $test
+good "$test" "$RET" "HUGETLB_SHM='yes'"
+bad  "$test" "$RET" "$warn"
+
+test="hugectl -v --shm=FOO"
+run $test
+good "$test" "$RET" "HUGETLB_SHM='yes'"
+good "$test" "$RET" "$warn"
+
+exit 0
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 9064451..2d36d5f 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -12,7 +12,7 @@ export HUGETLB_VERBOSE
 
 ENV=/usr/bin/env
 
-for BITS in 32 64; do
+for BITS in 0 32 64; do
     tot_tests[$BITS]=0
     tot_pass[$BITS]=0
     tot_fail[$BITS]=0
@@ -97,6 +97,36 @@ function check_linkhuge_tests() {
     done
 }
 
+RC_PASS=0
+RC_CONFIG=1
+RC_FAIL=2
+RC_XFAIL=3
+RC_XPASS=4
+
+run_test_host () {
+    RC_PASS=$RC_PASS RC_CONFIG=$RC_CONFIG RC_FAIL=$RC_FAIL \
+       RC_XFAIL=$RC_XFAIL RC_XPASS=$RC_XPASS \
+       PATH="../obj:$PATH"
+       "obj/$1"
+    rc="$?"
+    BITS=0
+    if [ "$rc" == "$RC_PASS" ]; then
+       tot_pass[$BITS]=$[tot_pass[$BITS] + 1]
+    elif [ "$rc" == "$RC_CONFIG" ]; then
+       tot_config[$BITS]=$[tot_config[$BITS] + 1]
+    elif [ "$rc" == "$RC_FAIL" ]; then
+       tot_fail[$BITS]=$[tot_fail[$BITS] + 1]
+    elif [ "$rc" == "$RC_XFAIL" ]; then
+       tot_xfail[$BITS]=$[tot_xfail[$BITS] + 1]
+    elif [ "$rc" == "$RC_XPASS" ]; then
+       tot_xpass[$BITS]=$[tot_xpass[$BITS] + 1]
+    elif [ "$rc" -gt 127 ]; then
+       tot_signal[$BITS]=$[tot_signal[$BITS] + 1]
+    else
+       tot_strange[$BITS]=$[tot_strange[$BITS] + 1]
+    fi
+}
+
 run_test_bits () {
     BITS=$1
     shift
@@ -262,6 +292,9 @@ restore_shm_sysctl() {
 }
 
 functional_tests () {
+# host tool tests
+    run_test_host hugectl-test
+
 # Kernel background tests not requiring hugepage support
     run_test zero_filesize_segment
 
@@ -420,14 +453,14 @@ for set in $TESTSETS; do
 done
 
 echo -e "********** TEST SUMMARY"
-echo -e "*                      32-bit\t64-bit"
-echo -e "*     Total testcases:        ${tot_tests[32]}\t${tot_tests[64]}"
-echo -e "*             Skipped:        ${tot_skip[32]}\t${tot_skip[64]}"
-echo -e "*                PASS:        ${tot_pass[32]}\t${tot_pass[64]}"
-echo -e "*                FAIL:        ${tot_fail[32]}\t${tot_fail[64]}"
-echo -e "*    Killed by signal:        ${tot_signal[32]}\t${tot_signal[64]}"
-echo -e "*   Bad configuration:        ${tot_config[32]}\t${tot_config[64]}"
-echo -e "*       Expected FAIL:        ${tot_xfail[32]}\t${tot_xfail[64]}"
-echo -e "*     Unexpected PASS:        ${tot_xpass[32]}\t${tot_xpass[64]}"
-echo -e "* Strange test result:        ${tot_strange[32]}\t${tot_strange[64]}"
+echo -e "*                      32-bit\t64-bit\tHOST"
+echo -e "*     Total testcases:        
${tot_tests[32]}\t${tot_tests[64]}\t${tot_tests[0]}"
+echo -e "*             Skipped:        
${tot_skip[32]}\t${tot_skip[64]}\t${tot_skip[0]}"
+echo -e "*                PASS:        
${tot_pass[32]}\t${tot_pass[64]}\t${tot_pass[0]}"
+echo -e "*                FAIL:        
${tot_fail[32]}\t${tot_fail[64]}\t${tot_fail[0]}"
+echo -e "*    Killed by signal:        
${tot_signal[32]}\t${tot_signal[64]}\t${tot_signal[0]}"
+echo -e "*   Bad configuration:        
${tot_config[32]}\t${tot_config[64]}\t${tot_config[0]}"
+echo -e "*       Expected FAIL:        
${tot_xfail[32]}\t${tot_xfail[64]}\t${tot_xfail[0]}"
+echo -e "*     Unexpected PASS:        
${tot_xpass[32]}\t${tot_xpass[64]}\t${tot_xpass[0]}"
+echo -e "* Strange test result:        
${tot_strange[32]}\t${tot_strange[64]}\t${tot_strange[0]}"
 echo -e "**********"
-- 
1.6.0.2.711.gf1ba4


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Libhugetlbfs-devel mailing list
Libhugetlbfs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to