summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2016-03-24 09:54:54 +0100
committerKarel Zak <kzak@redhat.com>2016-03-24 09:54:54 +0100
commit64eca31f71290a17c21eb0760d2d1cd2acb25d3f (patch)
treee5c8620109c57e336530ca2bb4dca0cdb3b867a8
parent90a9b9910cb7800f1bd4981b19f34d220393ff2c (diff)
parent33bed90a7fd5567d15e6319fef9e2f3c69673f76 (diff)
downloadutil-linux-64eca31f71290a17c21eb0760d2d1cd2acb25d3f.tar.gz
Merge branch 'tests-setarch' of https://github.com/rudimeier/util-linux
* 'tests-setarch' of https://github.com/rudimeier/util-linux: tests: improve setarch tests, regarding --uname-2.6 issues setarch: add "exec" message to --verbose build-sys: ignore vim .swp files
-rw-r--r--.gitignore1
-rw-r--r--sys-utils/setarch.c7
-rw-r--r--tests/expected/misc/setarch-options (renamed from tests/expected/misc/setarch)13
-rw-r--r--tests/expected/misc/setarch-uname266
-rw-r--r--tests/expected/misc/setarch-uname26-version1
-rwxr-xr-xtests/ts/misc/setarch74
6 files changed, 91 insertions, 11 deletions
diff --git a/.gitignore b/.gitignore
index 841111e0b..064010b20 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,6 +11,7 @@
*.so
*.so.*
*.static
+*.swp
*.vim
*.[ao]
*~
diff --git a/sys-utils/setarch.c b/sys-utils/setarch.c
index b5e401c81..cf29cf770 100644
--- a/sys-utils/setarch.c
+++ b/sys-utils/setarch.c
@@ -391,8 +391,11 @@ int main(int argc, char *argv[])
if (set_arch(arch, options, 0))
err(EXIT_FAILURE, _("failed to set personality to %s"), arch);
- /* flush all output streams before exec */
- fflush(NULL);
+ if (verbose) {
+ printf(_("Execute command `%s'.\n"), argc ? argv[0] : "/bin/sh");
+ /* flush all output streams before exec */
+ fflush(NULL);
+ }
if (!argc) {
execl("/bin/sh", "-sh", NULL);
diff --git a/tests/expected/misc/setarch b/tests/expected/misc/setarch-options
index 54208acf6..698db5265 100644
--- a/tests/expected/misc/setarch
+++ b/tests/expected/misc/setarch-options
@@ -1,3 +1,14 @@
+###### unknown arch
+setarch: qubit: Unrecognized architecture
+exit: 1
+###### unknown command
+Execute command `/das/gibs/nicht'.
+setarch: /das/gibs/nicht: No such file or directory
+exit: 1
+###### noop uname -a
+Execute command `uname'.
+uname -a unchanged
+###### almost all options
Switching on ADDR_NO_RANDOMIZE.
Switching on FDPIC_FUNCPTRS.
Switching on MMAP_PAGE_ZERO.
@@ -8,5 +19,5 @@ Switching on SHORT_INODE.
Switching on WHOLE_SECONDS.
Switching on STICKY_TIMEOUTS.
Switching on ADDR_LIMIT_3GB.
-Switching on UNAME26.
+Execute command `echo'.
success
diff --git a/tests/expected/misc/setarch-uname26 b/tests/expected/misc/setarch-uname26
new file mode 100644
index 000000000..13667af75
--- /dev/null
+++ b/tests/expected/misc/setarch-uname26
@@ -0,0 +1,6 @@
+###### --uname-2.6 echo
+Switching on UNAME26.
+Execute command `echo'.
+2.6 works or kernel too old
+###### --uname-2.6 true, non-verbose
+2.6 works or kernel too old
diff --git a/tests/expected/misc/setarch-uname26-version b/tests/expected/misc/setarch-uname26-version
new file mode 100644
index 000000000..9c746e100
--- /dev/null
+++ b/tests/expected/misc/setarch-uname26-version
@@ -0,0 +1 @@
+kernel version changed to 2.6
diff --git a/tests/ts/misc/setarch b/tests/ts/misc/setarch
index 9b0e92eee..c8050e52a 100755
--- a/tests/ts/misc/setarch
+++ b/tests/ts/misc/setarch
@@ -21,13 +21,71 @@ ts_init "$*"
ts_check_test_command "$TS_CMD_SETARCH"
ARCH=$(uname -m)
-case $ARCH in
- # setarch --uname-2.6 fails on platforms without VDS
- *sparc* )
- ts_skip "unsupported arch"
- ;;
-esac
-
-$TS_CMD_SETARCH $(uname -m) -vRFZLXBIST3 --uname-2.6 echo "success" >$TS_OUTPUT 2>&1
+
+ts_init_subtest options
+echo "###### unknown arch" >>$TS_OUTPUT
+$TS_CMD_SETARCH qubit -v echo "success" >>$TS_OUTPUT 2>&1
+echo "exit: $?" >>$TS_OUTPUT
+
+echo "###### unknown command" >>$TS_OUTPUT
+$TS_CMD_SETARCH $ARCH -v /das/gibs/nicht >>$TS_OUTPUT 2>&1
+echo "exit: $?" >>$TS_OUTPUT
+
+echo "###### noop uname -a" >>$TS_OUTPUT
+uname_a=$(uname -srm)
+$TS_CMD_SETARCH $ARCH -v uname -srm >>$TS_OUTPUT 2>&1
+sed -i "$ s@${uname_a}@uname -a unchanged@" $TS_OUTPUT
+
+echo "###### almost all options" >>$TS_OUTPUT
+$TS_CMD_SETARCH $ARCH -vRFZLXBIST3 echo "success" >>$TS_OUTPUT 2>&1
+ts_finalize_subtest
+
+
+ts_init_subtest uname26
+finmsg="" # for debugging 2.6 issues
+
+echo "###### --uname-2.6 echo" >>$TS_OUTPUT
+$TS_CMD_SETARCH $ARCH -v --uname-2.6 echo "2.6 worked" >>$TS_OUTPUT 2>&1
+if [ $? -eq 0 ]; then
+ expected='^2.6 worked$'
+else
+ # this may happen after execvp
+ expected="^FATAL: kernel too old$"
+ finmsg+=" echo"
+fi
+sed -i "$ s/$expected/2.6 works or kernel too old/" $TS_OUTPUT
+
+echo "###### --uname-2.6 true, non-verbose" >>$TS_OUTPUT
+$TS_CMD_SETARCH $ARCH --uname-2.6 true >>$TS_OUTPUT 2>&1
+if [ $? -eq 0 ]; then
+ echo "2.6 works or kernel too old" >> $TS_OUTPUT
+else
+ # this may happen after execvp
+ expected="^FATAL: kernel too old$"
+ sed -i "$ s/$expected/2.6 works or kernel too old/" $TS_OUTPUT
+ finmsg+=" true"
+fi
+
+if [ -n "$finmsg" ]; then
+ finmsg=$(echo unsupported --uname-2.6: $finmsg)
+else
+ uname26_seems_supported=yes
+fi
+ts_finalize_subtest "$finmsg"
+
+
+# conditional subtest
+if [ "$uname26_seems_supported" = "yes" ]; then
+ts_init_subtest uname26-version
+ tmp=$($TS_CMD_SETARCH $ARCH --uname-2.6 uname -r)
+ if echo "$tmp" | grep -q "^2\.6\."; then
+ echo "kernel version changed to 2.6" >> $TS_OUTPUT
+ else
+ echo "uname26 failed" >> $TS_OUTPUT
+ echo "original kernel: $(uname -r)" >> $TS_OUTPUT
+ echo "uname26 kernel: $tmp" >> $TS_OUTPUT
+ fi
+ts_finalize_subtest
+fi # conditional subtest
ts_finalize