#1 Add CI tests using the standard test interface
Closed 2 years ago by svashisht. Opened 2 years ago by bgoncalv.
rpms/ bgoncalv/bash bash-tests  into  master

file added
+59

@@ -0,0 +1,59 @@ 

+ # Makefile

+ # Author: Jan Scotka <jscotka@redhat.com>

+ # Location:

+ 

+ # Copyright (c) 2008 Red Hat, Inc. All rights reserved. This copyrighted material

+ # is made available to anyone wishing to use, modify, copy, or

+ # redistribute it subject to the terms and conditions of the GNU General

+ # Public License v.2.

+ #

+ # This program is distributed in the hope that it will be useful, but WITHOUT ANY

+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A

+ # PARTICULAR PURPOSE. See the GNU General Public License for more details.

+ #

+ # You should have received a copy of the GNU General Public License

+ # along with this program; if not, write to the Free Software

+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

+ 

+ 

+ 

+ TOPLEVEL_NAMESPACE=/CoreOS

+ PACKAGE_NAME=bash

+ RELATIVE_PATH=sanity/func

+ 

+ export TEST=$(TOPLEVEL_NAMESPACE)/$(PACKAGE_NAME)/$(RELATIVE_PATH)

+ export TESTVERSION=1.0

+ 

+ BUILT_FILES=

+ 

+ FILES=$(METADATA) runtest.sh Makefile PURPOSE

+ 

+ .PHONY: all install download clean

+ 

+ run: $(FILES) build

+ 	./runtest.sh

+ 

+ build: $(BUILT_FILES)

+ 	chmod a+x ./runtest.sh

+ 

+ clean:

+ 	rm -f $(BUILT_FILES)

+ 

+ 

+ include /usr/share/rhts/lib/rhts-make.include

+ 

+ 

+ $(METADATA): Makefile

+ 	@touch $(METADATA)

+ 	@echo "Owner:        Jan Scotka <jscotka@redhat.com>" > $(METADATA)

+ 	@echo "Name:         $(TEST)" >> $(METADATA)

+ 	@echo "Path:         $(TEST_DIR)"       >> $(METADATA)

+ 	@echo "TestVersion:  $(TESTVERSION)"    >> $(METADATA)

+ 	@echo "Description:  Try shell basic functionality" >> $(METADATA)

+ 	@echo "Type:         Sanity" >> $(METADATA)

+ 	@echo "TestTime:     2h" >> $(METADATA)

+ 	@echo "RunFor:       $(PACKAGE_NAME)" >> $(METADATA)

+ 	@echo "Requires:     $(PACKAGE_NAME)" >> $(METADATA)

+ 	@echo "License:      GPLv2" >> $(METADATA)

+ 

+ 	rhts-lint $(METADATA)

file added
+1

@@ -0,0 +1,1 @@ 

+ Basic test of functions in Bourne-Again SHell, testing purpose for Test Container Project

@@ -0,0 +1,46 @@ 

+ #!/bin/bash

+ # Include rhts and rhtslib environment

+ . /usr/bin/rhts-environment.sh || exit 1

+ . /usr/share/beakerlib/beakerlib.sh || exit 1

+ 

+ PACKAGES=${PACKAGES:-bash}

+ SH_BIN=${SH_BIN:-bash}

+ 

+ rlJournalStart

+ 

+     rlPhaseStartSetup "Init phase"

+         rlAssertRpm --all

+         if [ $SH_BIN == "zsh" ]; then

+                 ZSH_OPT="-i"

+         else

+                 ZSH_OPT=""

+         fi

+     rlPhaseEnd

+ 

+ 

+     rlPhaseStartTest "Test of functions"

+         rlRun "${SH_BIN} -c pwd" 0 "Checking if ${SH_BIN} do pwd command"

+         rlRun "${SH_BIN} -c unexistcommand3241" 127 "Checking if ${SH_BIN} return 127 if command doesnt exist"

+         rm /tmp/unexistfile &>/dev/null

+         rlRun "${SH_BIN} -c 'ls /tmp/unexistfile'" 2 "Checking if ${SH_BIN} return 2 if none file"

+         rlRun "${SH_BIN} -c 'echo aba| sed s/a/b/g |grep -q bbb'" 0 "Checking pipes"

+         TT=`mktemp`

+         TEXT=sometihngverylong

+         rlRun "${SH_BIN} -c 'echo $TEXT > $TT; cat $TT |grep -q $TEXT'" 0 "Checking redirecting to file"

+         rlRun " ${SH_BIN} -c 'let a=1+1;echo \$a|grep -q 2'" 0 "Checking 'let' arithmetic operation 1+1"

+         rlRun "${SH_BIN} $ZSH_OPT -c 'sleep 100& WC=\$(jobs|wc -l) ; [[ \$WC -ge 1 ]]'" 0 "Checking process at background is running"

+ 

+         USER=${SH_BIN}user

+         rlRun "adduser -s /bin/${SH_BIN} $USER" 0,9 "Created user with ${SH_BIN} as default shell"

+         rlRun "su -l $USER -c 'echo \$PATH'" 0 "Logged as previous created user and run echo PATH"

+     rlPhaseEnd

+ 

+     # cleanup

+     rlPhaseStartCleanup "Cleaning up"

+         rlRun "true" 0 "True action"

+         rlRun "rm $TT" 0 "Checking delete of $TT"

+         sleep 10

+         rlRun "userdel $USER" 0 "Deleted user with ${SH_BIN} as default shell"

+     rlPhaseEnd

+ rlJournalPrintText

+ rlJournalEnd

@@ -0,0 +1,66 @@ 

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Makefile of /CoreOS/bash/Sanity/login-shell

+ #   Description: the test creates user with bash as login shell and verifies various functions related to user login

+ #   Author: Martin Kyral <mkyral@redhat.com>

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Copyright (c) 2016 Red Hat, Inc.

+ #

+ #   This program is free software: you can redistribute it and/or

+ #   modify it under the terms of the GNU General Public License as

+ #   published by the Free Software Foundation, either version 2 of

+ #   the License, or (at your option) any later version.

+ #

+ #   This program is distributed in the hope that it will be

+ #   useful, but WITHOUT ANY WARRANTY; without even the implied

+ #   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR

+ #   PURPOSE.  See the GNU General Public License for more details.

+ #

+ #   You should have received a copy of the GNU General Public License

+ #   along with this program. If not, see http://www.gnu.org/licenses/.

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ 

+ export TEST=/CoreOS/bash/Sanity/login-shell

+ export TESTVERSION=1.0

+ 

+ BUILT_FILES=

+ 

+ FILES=$(METADATA) runtest.sh Makefile PURPOSE script.exp ssh.exp tst.sh

+ 

+ .PHONY: all install download clean

+ 

+ run: $(FILES) build

+ 	./runtest.sh

+ 

+ build: $(BUILT_FILES)

+ 	test -x runtest.sh || chmod a+x runtest.sh

+ 

+ clean:

+ 	rm -f $(BUILT_FILES)

+ 

+ 

+ include /usr/share/rhts/lib/rhts-make.include

+ 

+ $(METADATA): Makefile

+ 	@echo "Owner:           Martin Kyral <mkyral@redhat.com>" > $(METADATA)

+ 	@echo "Name:            $(TEST)" >> $(METADATA)

+ 	@echo "TestVersion:     $(TESTVERSION)" >> $(METADATA)

+ 	@echo "Path:            $(TEST_DIR)" >> $(METADATA)

+ 	@echo "Description:     the test creates user with bash as login shell and verifies various functions related to user login" >> $(METADATA)

+ 	@echo "Type:            Sanity" >> $(METADATA)

+ 	@echo "TestTime:        5m" >> $(METADATA)

+ 	@echo "RunFor:          ksh zsh bash dash mksh pdksh" >> $(METADATA)

+ 	@echo "Requires:        bash" >> $(METADATA)

+ 	@echo "Requires:        expect" >> $(METADATA)

+ 	@echo "Requires:        procps-ng" >> $(METADATA)

+ 	@echo "Requires:        passwd" >> $(METADATA)

+ 	@echo "Requires:        openssh-clients openssh-server" >> $(METADATA)

+ 	@echo "Priority:        Normal" >> $(METADATA)

+ 	@echo "License:         GPLv2+" >> $(METADATA)

+ 	@echo "Confidential:    no" >> $(METADATA)

+ 	@echo "Destructive:     no" >> $(METADATA)

+ 

+ 	rhts-lint $(METADATA)

@@ -0,0 +1,3 @@ 

+ PURPOSE of /CoreOS/bash/Sanity/login-shell

+ Description: the test creates user with bash as login shell and verifies various functions related to user login

+ Author: Martin Kyral <mkyral@redhat.com>

@@ -0,0 +1,94 @@ 

+ #!/bin/bash

+ # vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   runtest.sh of /CoreOS/bash/Sanity/login-shell

+ #   Description: the test creates user with bash as login shell and verifies various functions related to user login

+ #   Author: Martin Kyral <mkyral@redhat.com>

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Copyright (c) 2016 Red Hat, Inc.

+ #

+ #   This program is free software: you can redistribute it and/or

+ #   modify it under the terms of the GNU General Public License as

+ #   published by the Free Software Foundation, either version 2 of

+ #   the License, or (at your option) any later version.

+ #

+ #   This program is distributed in the hope that it will be

+ #   useful, but WITHOUT ANY WARRANTY; without even the implied

+ #   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR

+ #   PURPOSE.  See the GNU General Public License for more details.

+ #

+ #   You should have received a copy of the GNU General Public License

+ #   along with this program. If not, see http://www.gnu.org/licenses/.

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ 

+ # Include Beaker environment

+ . /usr/bin/rhts-environment.sh || exit 1

+ . /usr/share/beakerlib/beakerlib.sh || exit 1

+ 

+ PACKAGES=${PACKAGES:-"bash"}

+ SH_BIN=${SH_BIN:-"bash"}

+ 

+ rlJournalStart

+     rlPhaseStartSetup

+         rlAssertRpm --all

+         rlAssertBinaryOrigin $SH_BIN

+         rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"

+         rlRun "cp script.exp ssh.exp tst.sh $TmpDir"

+         rlRun "pushd $TmpDir"

+         #USER=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1)

+         USER="user${RANDOM}"

+         rlRun "useradd -s /bin/${SH_BIN} -d /home/${USER} ${USER}"

+         rlRun "echo krava | passwd --stdin ${USER}"

+         rlRun "sed -i 's/shelluser/${USER}/g' script.exp"

+         rlRun "sed -i 's/shelluser/${USER}/g' ssh.exp"

+         rlRun "sed -i 's/shelluser/${USER}/g' tst.sh"

+         rlRun "sed -i 's/shellbin/${SH_BIN}/g' script.exp"

+         rlRun "sed -i 's/shellbin/${SH_BIN}/g' ssh.exp"

+         rlRun "sed -i 's/shellbin/${SH_BIN}/g' tst.sh"

+         rlRun "cp tst.sh /home/${USER}/"

+         rlRun "chown ${USER} /home/${USER}/tst.sh"

+         rlRun "mv /etc/profile.d/tps-cd.sh /root/tps-cd.sh" 0,1 "Backing tps-cd.sh up"

+     rlPhaseEnd

+ 

+     rlPhaseStartTest

+         rlLog "::::: 'su -c' test :::::"

+         rlRun "su ${USER} -c 'echo something' | tee test1.log" 0 "echo something test"

+         rlLog "test1.log: $(cat test1.log)"

+         rlAssertGrep "something" "test1.log"

+         rlRun "su ${USER} -c 'echo \$0 | tee /home/${USER}/ps1.log'" 0 "shell detection test"

+         rlLog "ps1.log: $(cat /home/${USER}/ps1.log)"

+         rlAssertGrep "$SH_BIN" "/home/${USER}/ps1.log"

+         # the following does not work with pdksh for some reason

+         # not a big deal, ssh test can substitute this

+         [ "$SH_BIN" != "pdksh" ] && {

+         rlLog "::::: 'su -l' test :::::"

+         expect script.exp &

+         sleep 20

+         pgrep expect && pkill expect

+         rlLog "test2.log: $(cat /home/${USER}/test2.log)"

+         rlAssertGrep "something" "/home/${USER}/test2.log"

+         rlLog "ps2.log: $(cat /home/${USER}/ps2.log)"

+         rlAssertGrep "$SH_BIN" "/home/${USER}/ps2.log"

+         }

+         rlLog "::::: ssh login test :::::"

+         expect ssh.exp &

+         sleep 20

+         pgrep expect && pkill expect

+         rlLog "ps3.log: $(cat /home/${USER}/ps3.log)"

+         rlAssertGrep "$SH_BIN" "/home/${USER}/ps3.log"

+         rlAssertExists "/home/${USER}/tst.dat"

+     rlPhaseEnd

+ 

+     rlPhaseStartCleanup

+         rlRun "mv /root/tps-cd.sh /etc/profile.d/tps-cd.sh" 0,1 "Restoring tps-cd.sh"

+         rlRun "su -c 'kill -9 -1' ${USER}" 0 "Killing all processes of ${USER}"

+         rlRun "userdel -r ${USER}"

+         rlRun "popd"

+         rlRun "rm -r $TmpDir" 0 "Removing tmp directory"

+     rlPhaseEnd

+ rlJournalPrintText

+ rlJournalEnd

@@ -0,0 +1,57 @@ 

+ #!/usr/bin/expect -f

+ #

+ # This Expect script was generated by autoexpect on Wed Jan 13 12:41:15 2016

+ # Expect and autoexpect were both written by Don Libes, NIST.

+ #

+ # Note that autoexpect does not guarantee a working script.  It

+ # necessarily has to guess about certain things.  Two reasons a script

+ # might fail are:

+ #

+ # 1) timing - A surprising number of programs (rn, ksh, zsh, telnet,

+ # etc.) and devices discard or ignore keystrokes that arrive "too

+ # quickly" after prompts.  If you find your new script hanging up at

+ # one spot, try adding a short sleep just before the previous send.

+ # Setting "force_conservative" to 1 (see below) makes Expect do this

+ # automatically - pausing briefly before sending each character.  This

+ # pacifies every program I know of.  The -c flag makes the script do

+ # this in the first place.  The -C flag allows you to define a

+ # character to toggle this mode off and on.

+ 

+ set force_conservative 0  ;# set to 1 to force conservative mode even if

+ 			  ;# script wasn't run conservatively originally

+ if {$force_conservative} {

+ 	set send_slow {1 .1}

+ 	proc send {ignore arg} {

+ 		sleep .1

+ 		exp_send -s -- $arg

+ 	}

+ }

+ 

+ #

+ # 2) differing output - Some programs produce different output each time

+ # they run.  The "date" command is an obvious example.  Another is

+ # ftp, if it produces throughput statistics at the end of a file

+ # transfer.  If this causes a problem, delete these patterns or replace

+ # them with wildcards.  An alternative is to use the -p flag (for

+ # "prompt") which makes Expect only look for the last line of output

+ # (i.e., the prompt).  The -P flag allows you to define a character to

+ # toggle this mode off and on.

+ #

+ # Read the man page for more info.

+ #

+ # -Don

+ 

+ 

+ set timeout -1

+ spawn "/bin/shellbin"

+ match_max 100000

+ send -- "su -l shelluser\r"

+ sleep 3

+ send -- "cd\r"

+ send -- "echo something\r"

+ send -- "echo something > test2.log\r"

+ send -- "pwd\r"

+ send -- "echo \$0 | tee ps2.log\r"

+ send -- "exit\r"

+ send -- "exit\r"

+ expect eof

@@ -0,0 +1,67 @@ 

+ #!/usr/bin/expect -f

+ #

+ # This Expect script was generated by autoexpect on Mon Jan 18 05:25:00 2016

+ # Expect and autoexpect were both written by Don Libes, NIST.

+ #

+ # Note that autoexpect does not guarantee a working script.  It

+ # necessarily has to guess about certain things.  Two reasons a script

+ # might fail are:

+ #

+ # 1) timing - A surprising number of programs (rn, ksh, zsh, telnet,

+ # etc.) and devices discard or ignore keystrokes that arrive "too

+ # quickly" after prompts.  If you find your new script hanging up at

+ # one spot, try adding a short sleep just before the previous send.

+ # Setting "force_conservative" to 1 (see below) makes Expect do this

+ # automatically - pausing briefly before sending each character.  This

+ # pacifies every program I know of.  The -c flag makes the script do

+ # this in the first place.  The -C flag allows you to define a

+ # character to toggle this mode off and on.

+ 

+ set force_conservative 0  ;# set to 1 to force conservative mode even if

+             ;# script wasn't run conservatively originally

+ if {$force_conservative} {

+         set send_slow {1 .1}

+         proc send {ignore arg} {

+          sleep .1

+          exp_send -s -- $arg

+         }

+ }

+ 

+ #

+ # 2) differing output - Some programs produce different output each time

+ # they run.  The "date" command is an obvious example.  Another is

+ # ftp, if it produces throughput statistics at the end of a file

+ # transfer.  If this causes a problem, delete these patterns or replace

+ # them with wildcards.  An alternative is to use the -p flag (for

+ # "prompt") which makes Expect only look for the last line of output

+ # (i.e., the prompt).  The -P flag allows you to define a character to

+ # toggle this mode off and on.

+ #

+ # Read the man page for more info.

+ #

+ # -Don

+ 

+ set timeout -1

+ spawn "/bin/shellbin"

+ match_max 100000

+ expect "# "

+ send -- "ssh -o 'StrictHostKeyChecking no' shelluser@localhost\r"

+ expect "password: "

+ send -- "krava\r"

+ sleep 1

+ send -- "echo \$0 | tee ps3.log\r"

+ send -- "\r"

+ send -- "(bash /home/shelluser/tst.sh &)"

+ expect -exact "(bash /home/shelluser/tst.sh &)"

+ send -- "\r"

+ send -- "\r"

+ send -- "\r"

+ send -- "fg\r"

+ send -- "\r"

+ send -- "\r"

+ send -- "\r"

+ send -- "ls\r"

+ send -- "^D"

+ expect "# "

+ send -- "^D"

+ expect eof

@@ -0,0 +1,4 @@ 

+ #!/bin/shellbin

+ 

+ D=$(date)

+ echo $D > /home/shelluser//tst.dat

Extra '/' in path

What is the motive of this test ? Looking at the 'tests/login-shell/runtest.sh' shows that it just checks for existence of $HOME/tst.dat. Just doing 'touch /home/shelluser/tst.dat' should be sufficient here.

The test is spawned by this expect script: tests/login-shell/ssh.exp

It was originally written for ksh to cover: https://bugzilla.redhat.com/show_bug.cgi?id=1217236

file added
+63

@@ -0,0 +1,63 @@ 

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Makefile of /CoreOS/bash/Sanity/smoke

+ #   Description: Basic sanity smoke test

+ #   Author: Miroslav Hradilek <mhradile@redhat.com>

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Copyright (c) 2012 Red Hat, Inc. All rights reserved.

+ #

+ #   This copyrighted material is made available to anyone wishing

+ #   to use, modify, copy, or redistribute it subject to the terms

+ #   and conditions of the GNU General Public License version 2.

+ #

+ #   This program is distributed in the hope that it will be

+ #   useful, but WITHOUT ANY WARRANTY; without even the implied

+ #   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR

+ #   PURPOSE. See the GNU General Public License for more details.

+ #

+ #   You should have received a copy of the GNU General Public

+ #   License along with this program; if not, write to the Free

+ #   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,

+ #   Boston, MA 02110-1301, USA.

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ 

+ export TEST=/CoreOS/bash/Sanity/smoke

+ export TESTVERSION=1.0

+ 

+ BUILT_FILES=

+ 

+ FILES=$(METADATA) runtest.sh Makefile PURPOSE t_alias t_conditionals t_variables

+ 

+ .PHONY: all install download clean

+ 

+ run: $(FILES) build

+ 	./runtest.sh

+ 

+ build: $(BUILT_FILES)

+ 	test -x runtest.sh || chmod a+x runtest.sh

+ 

+ clean:

+ 	rm -f $(BUILT_FILES)

+ 

+ 

+ include /usr/share/rhts/lib/rhts-make.include

+ 

+ $(METADATA): Makefile

+ 	@echo "Owner:           Miroslav Hradilek <mhradile@redhat.com>" > $(METADATA)

+ 	@echo "Name:            $(TEST)" >> $(METADATA)

+ 	@echo "TestVersion:     $(TESTVERSION)" >> $(METADATA)

+ 	@echo "Path:            $(TEST_DIR)" >> $(METADATA)

+ 	@echo "Description:     Basic sanity smoke test" >> $(METADATA)

+ 	@echo "Type:            Sanity" >> $(METADATA)

+ 	@echo "TestTime:        5m" >> $(METADATA)

+ 	@echo "RunFor:          bash" >> $(METADATA)

+ 	@echo "Requires:        bash" >> $(METADATA)

+ 	@echo "Priority:        Normal" >> $(METADATA)

+ 	@echo "License:         GPLv2" >> $(METADATA)

+ 	@echo "Confidential:    no" >> $(METADATA)

+ 	@echo "Destructive:     no" >> $(METADATA)

+ 

+ 	rhts-lint $(METADATA)

file added
+5

@@ -0,0 +1,5 @@ 

+ PURPOSE of /CoreOS/bash/Sanity/smoke

+ Description: Basic sanity smoke test

+ Author: Miroslav Hradilek <mhradile@redhat.com>

+ 

+ Performs basic sanity smoke test. Tries to supply commands on a command line, variable assignment and substitution, file expansion, "test" builtin, redirection, pipeline and some control structures.

@@ -0,0 +1,82 @@ 

+ #!/bin/bash

+ # vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   runtest.sh of /CoreOS/bash/Sanity/smoke

+ #   Description: Basic sanity smoke test

+ #   Author: Miroslav Hradilek <mhradile@redhat.com>

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Copyright (c) 2012 Red Hat, Inc. All rights reserved.

+ #

+ #   This copyrighted material is made available to anyone wishing

+ #   to use, modify, copy, or redistribute it subject to the terms

+ #   and conditions of the GNU General Public License version 2.

+ #

+ #   This program is distributed in the hope that it will be

+ #   useful, but WITHOUT ANY WARRANTY; without even the implied

+ #   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR

+ #   PURPOSE. See the GNU General Public License for more details.

+ #

+ #   You should have received a copy of the GNU General Public

+ #   License along with this program; if not, write to the Free

+ #   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,

+ #   Boston, MA 02110-1301, USA.

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ 

+ # Include Beaker environment

+ . /usr/bin/rhts-environment.sh || exit 1

+ . /usr/share/beakerlib/beakerlib.sh || exit 1

+ 

+ PACKAGES=${PACKAGES:-"bash"}

+ SH_BIN=${SH_BIN:-"bash"}

+ 

+ rlJournalStart

+     rlPhaseStartSetup

+         rlAssertRpm --all

+         rlAssertBinaryOrigin $SH_BIN

+         rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"

+         rlRun "cp t_* $TmpDir/." 0 "Copying additional test files"

+         rlRun "pushd $TmpDir"

+     rlPhaseEnd

+ 

+     rlPhaseStartTest

+         rlLog "Commandline options"

+         rlRun "$SH_BIN -c 'echo OK' | grep OK" 0 "Testing -c option"

+ 

+         rlLog "Assorted tests"

+         rlRun "$SH_BIN -c 'echo \`echo OK\`' | grep OK" 0 "Testing command substitution"

+         [ "$SH_BIN" == "bash" ] && EXTRAPARAM="-i"

+         rlRun "$SH_BIN $EXTRAPARAM t_alias | grep OK" 0 "Testing alias"

+         rlRun "$SH_BIN -c 'echo \$((1+1))' | grep 2" 0 "Arithmetic expansion"

+         rlRun "$SH_BIN -c 'writedown(){ echo \$1; }; writedown OK' | grep OK" 0 "Testing function"

+ 

+         rlLog "Variables"

+         rlRun "$SH_BIN -c 'testvar1=\"OK\"; echo \"\$testvar1\"' | grep OK" 0 "Testing variable assignment"

+         rlRun "$SH_BIN t_variables | grep 'default,OK'" 0 "Testing variable substitution"

+         rlRun "$SH_BIN -c \"cat nonexistent; echo \$?\" | grep 1" 0 "Testing predefined variable \$?"

+ 

+         rlLog "File expansion"

+         rlRun "touch testfile" 0 "Creating test file"

+         rlRun "$SH_BIN -c 'echo test*' | grep testfile" 0 "Testing expansion to the test file name"

+ 

+         rlLog "Builtins"

+         rlRun "$SH_BIN -c 'test -e testfile'" 0 "Testing test builtin"

+ 

+         rlLog "Redirection and pipeline"

+         rlRun "$SH_BIN -c \"echo 'aBc' | grep B >redirection_out\"" 0 "Testing pipeline"

+         rlRun "grep 'aBc' redirection_out" 0 "Testing redirection"

+ 

+         rlLog "Control structures"

+         rlRun "$SH_BIN -c 'for i in 1 2 3; do echo -n \$i; done' | grep 123" 0 "Testing cycle for"

+         rlRun "$SH_BIN t_conditionals | grep 'operator,if,else,test'" 0 "Testing if and it's && operator shorthand"

+     rlPhaseEnd

+ 

+     rlPhaseStartCleanup

+         rlRun "popd"

+         rlRun "rm -r $TmpDir" 0 "Removing tmp directory"

+     rlPhaseEnd

+ rlJournalPrintText

+ rlJournalEnd

file added
+2

@@ -0,0 +1,2 @@ 

+ alias writedown='echo'

+ writedown OK

@@ -0,0 +1,6 @@ 

+ true && echo -n 'operator,'

+ if true; then echo -n 'if,'; fi

+ if ! true; then echo -n 'if,'; else echo -n 'else,'; fi

+ if [ 'notnul' ]; then echo -n 'test'; fi

+ 

+ 

@@ -0,0 +1,4 @@ 

+ testvar2=${testvar1:-default}

+ testvar3='OK'

+ testvar4=${testvar3:-default}

+ echo "$testvar2,$testvar4"

@@ -0,0 +1,63 @@ 

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Makefile of /CoreOS/bash/Regression/new-substitution-in-bash

+ #   Description: Test for substitution in bash

+ #   Author: Jan Kejda <jkejda@redhat.com>

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Copyright (c) 2013 Red Hat, Inc. All rights reserved.

+ #

+ #   This copyrighted material is made available to anyone wishing

+ #   to use, modify, copy, or redistribute it subject to the terms

+ #   and conditions of the GNU General Public License version 2.

+ #

+ #   This program is distributed in the hope that it will be

+ #   useful, but WITHOUT ANY WARRANTY; without even the implied

+ #   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR

+ #   PURPOSE. See the GNU General Public License for more details.

+ #

+ #   You should have received a copy of the GNU General Public

+ #   License along with this program; if not, write to the Free

+ #   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,

+ #   Boston, MA 02110-1301, USA.

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ 

+ export TEST=/CoreOS/bash/Regression/new-substitution-in-bash

+ export TESTVERSION=1.0

+ 

+ BUILT_FILES=

+ 

+ FILES=$(METADATA) runtest.sh Makefile PURPOSE test.sh

+ 

+ .PHONY: all install download clean

+ 

+ run: $(FILES) build

+ 	./runtest.sh

+ 

+ build: $(BUILT_FILES)

+ 	test -x runtest.sh || chmod a+x runtest.sh

+ 

+ clean:

+ 	rm -f $(BUILT_FILES)

+ 

+ 

+ include /usr/share/rhts/lib/rhts-make.include

+ 

+ $(METADATA): Makefile

+ 	@echo "Owner:           Jan Kejda <jkejda@redhat.com>" > $(METADATA)

+ 	@echo "Name:            $(TEST)" >> $(METADATA)

+ 	@echo "TestVersion:     $(TESTVERSION)" >> $(METADATA)

+ 	@echo "Path:            $(TEST_DIR)" >> $(METADATA)

+ 	@echo "Description:     Test for substitution in bash" >> $(METADATA)

+ 	@echo "Type:            Regression" >> $(METADATA)

+ 	@echo "TestTime:        5m" >> $(METADATA)

+ 	@echo "RunFor:          bash" >> $(METADATA)

+ 	@echo "Requires:        bash" >> $(METADATA)

+ 	@echo "Priority:        Normal" >> $(METADATA)

+ 	@echo "License:         GPLv2" >> $(METADATA)

+ 	@echo "Confidential:    no" >> $(METADATA)

+ 	@echo "Destructive:     no" >> $(METADATA)

+ 

+ 	rhts-lint $(METADATA)

@@ -0,0 +1,5 @@ 

+ PURPOSE of /CoreOS/bash/Regression/new-substitution-in-bash

+ Description: the test creates user with bash as login shell and verifies various functions related to user login

+ Author: Jan Kejda <jkejda@redhat.com>

+ 

+ Test checks right functionality of feature ${NAME:OFFSET:LENGTH}.

@@ -0,0 +1,56 @@ 

+ #!/bin/bash

+ # vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   runtest.sh of /CoreOS/bash/Regression/new-substitution-in-bash

+ #   Description: Test for substitution in bash

+ #   Author: Jan Kejda <jkejda@redhat.com>

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Copyright (c) 2013 Red Hat, Inc. All rights reserved.

+ #

+ #   This copyrighted material is made available to anyone wishing

+ #   to use, modify, copy, or redistribute it subject to the terms

+ #   and conditions of the GNU General Public License version 2.

+ #

+ #   This program is distributed in the hope that it will be

+ #   useful, but WITHOUT ANY WARRANTY; without even the implied

+ #   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR

+ #   PURPOSE. See the GNU General Public License for more details.

+ #

+ #   You should have received a copy of the GNU General Public

+ #   License along with this program; if not, write to the Free

+ #   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,

+ #   Boston, MA 02110-1301, USA.

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ 

+ # Include Beaker environment

+ . /usr/bin/rhts-environment.sh || exit 1

+ . /usr/share/beakerlib/beakerlib.sh || exit 1

+ 

+ PACKAGES=${PACKAGES:-"bash"}

+ SH_BIN=${SH_BIN:-"bash"}

+ 

+ rlJournalStart

+     rlPhaseStartSetup

+         rlAssertRpm --all

+         rlRun "sed -i 's/shellbin/${SH_BIN}/g' test.sh"

+         rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"

+         rlRun "cp test.sh $TmpDir"

+         rlRun "pushd $TmpDir"

+         rlRun "touch test.log"

+     rlPhaseEnd

+ 

+     rlPhaseStartTest

+         rlRun "$SH_BIN test.sh"

+         rlAssertGrep "erty" "test.log"

+     rlPhaseEnd

+ 

+     rlPhaseStartCleanup

+         rlRun "popd"

+         rlRun "rm -r $TmpDir" 0 "Removing tmp directory"

+     rlPhaseEnd

+ rlJournalPrintText

+ rlJournalEnd

@@ -0,0 +1,5 @@ 

+ #!/bin/shellbin

+ 

+ TEST="qwerty"

+ echo ${TEST:2:4}

Why is this line required ?

It's there just to have the result of the substitution in the main test log so in case of fail you have first-look information of how it failed. Can be removed, though.

+ echo ${TEST:2:4} > test.log 2>&1

file added
+32

@@ -0,0 +1,32 @@ 

+ ---

+ # Tests that run in classic context

+ - hosts: localhost

+   roles:

+   - role: standard-test-beakerlib

+     tags:

+     - classic

+     tests:

+     - func

+     - login-shell

+     - smoke

+     - substitution-in-bash

+     required_packages:

+     - expect            # login-shell requires expect command

+     - findutils         # beakerlib needs find command

+     - which             # smoke requires which command

+ 

+ # Tests that run in container and atomic contexts

+ - hosts: localhost

+   roles:

+   - role: standard-test-beakerlib

+     tags:

+     - container

+     - atomic

+     tests:

+     - func

+     - smoke

+     - substitution-in-bash

+     required_packages:

+     - findutils         # beakerlib needs find command

+     - which             # smoke requires which command

+ 

Adds tests according to the CI wiki [0] specifically the standard test interface in the spec [1].

The playbook includes Tier1 level test cases that have been tested in the following contexts and is passing reliably: Atomic Host, Docker, and Classic.
Test logs are stored in the Artifacts directory.

The following steps are used to execute the tests using the standard test interface:

  • Atomic
    sudo ANSIBLE_INVENTORY=$(test -e inventory && echo inventory || echo /usr/share/ansible/inventory) TEST_SUBJECTS=../atomic.qcow2 TEST_ARTIFACTS=$PWD/artifacts ansible-playbook --tags atomic tests.yml

  • Docker
    sudo ANSIBLE_INVENTORY=$(test -e inventory && echo inventory || echo /usr/share/ansible/inventory) TEST_SUBJECTS=docker:docker.io/library/fedora:26 TEST_ARTIFACTS=$PWD/artifacts ansible-playbook --tags container tests.yml

  • Classic
    sudo ANSIBLE_INVENTORY=$(test -e inventory && echo inventory || echo /usr/share/ansible/inventory) TEST_SUBJECTS="" TEST_ARTIFACTS=$PWD/artifacts ansible-playbook --tags classic tests.yml

[0] https://fedoraproject.org/wiki/CI
[1] https://fedoraproject.org/wiki/Changes/InvokingTests

rebased onto 897ae91

2 years ago

Where this variable is used ?

ZSH_OPT is used here, but this is only set if the test is configured to use "zsh" and not "bash" as shell. This test is generic to support different shells.

What is the motive of this test ? Looking at the 'tests/login-shell/runtest.sh' shows that it just checks for existence of $HOME/tst.dat. Just doing 'touch /home/shelluser/tst.dat' should be sufficient here.

Other tests exit if sourcing fails :

. /usr/bin/rhts-environment.sh || exit 1

It would be good to have a consistent sourcing style.

Thanks for the review, I will check it the test author to get this fixed properly.

*~ does not expand to anything in bash. Please remove it.

*~ does not expand to anything in bash. Please remove it from here and rest of the Makefiles.

Ok, but if this test gets copied over to this repo. It would be hard to keep it in sync with rest of the shells.

Yes, we understand that and it is expected they will not be in syc with other shell tests anymore. As it will not be in syc with the internal version in the future either, but this was a decision we made when starting the porting test upstream.
Sure we can update the test to be bash specific if you prefer.

I think we shall decide how to handle the scenario of sharing tests between components. As of now, the attitude seems to be copying the tests over to every component's git which would eventually lead to diverging of the tests and worsened maintainability. Better approach would IMO be to have the test itself in only one of the components and in the other put just a wrapper to download and run the test itself. But, this needs to be decided. ATM I propose letting the variables there with a comment and remove them eventually once the approach is decided.

The test is spawned by this expect script: tests/login-shell/ssh.exp

It was originally written for ksh to cover: https://bugzilla.redhat.com/show_bug.cgi?id=1217236

rebased onto 1216a10

2 years ago

rebased onto 4e28949

2 years ago

rebased onto c4f4691

2 years ago

fixed issues:
exit with 1 in case test can't import libraries
removed usage of "*~"
updated truncated test descriptions.

rebased onto 6c32f13

2 years ago

It's there just to have the result of the substitution in the main test log so in case of fail you have first-look information of how it failed. Can be removed, though.

Is there a way to share the tests for different components in Fedora ? I think it would be best to decide approach early, otherwise we will end up copying same tests in different repos.

I already written a wrapper allowing to run cross-component tests:


!/bin/bash

COMPONENT=component
TEST=test_of_a_feature

pushd /tmp

git clone https://upstreamfirst.fedorainfracloud.org/$COMPONENT.git

pushd $COMPONENT/$TEST

. runtest.sh

popd
rm -rf $COMPONENT
popd


The idea is that in the other component's repo, there will be a dummy test directory containing this runtest.sh with the COMPONENT and TEST (and other if needed) variables properly defined.

Is there a way to share the tests for different components in Fedora ? I think it would be best to decide approach early, otherwise we will end up copying same tests in different repos.

Yes! Other packages make use of this. Obviously you have to trust the source, but you could pull the tests from any available repo, e.g. for upstream tests.
Since the upstreamfirst repos will go away eventually, I wouldn't recommend that as a good practice place. I would probably either create a project such as shell-tests on https://pagure.io/ or use one of the shells as the "master".

Plus one for sharing the test coverage across compatible shells. Martin Kyral has a good experience with sharing tests among bash, ksh, mksh, zsh a dash. So it makes a perfect sense to me to have a single source for these tests. At the first sight I would probably prefer a separate shell-tests repo which sounds to me like a bit more clear solution.

From the email discussion with developers it seems the best place for storing shared shell tests would be the "shell" repository under the "tests" namespace, like this:

https://src.fedoraproject.org/tests/shell/

Here's Fedora Infrastructure ticket requesting the new repository:

https://pagure.io/fedora-infrastructure/issue/6478

Share Test Code proposal sent to fedora ci list.

Closing this pull request as the tests need to be stored in other repository.

Pull-Request has been closed by svashisht

2 years ago