Untitled
unknown
plain_text
2 years ago
17 kB
4
Indexable
#!/bin/bash #··team·MN·RAN·L3·SW·1·WRO·7·SG #··e.g··run·script·like: #··testrunner /home/ute/robotws/testsuite/Wroclaw/RRM/5G_SW_WRO/CB008241/CB008241_A_B2.robot True #··testrunner /path_to_test_file #··testrunner /path_to_test_file /home/ute/robotws/testsuite/Wroclaw/RRM/5G_SW_WRO/CB008241/CB008241_A_B2.robot True #··testrunner·is·alias·for·script·path-/home/ute/robotws/testsuite/Wroclaw/RRM/5G_SW_WRO/resources/scripts/run_and_report_tests.sh #@Description This script is used to automatically run suite of tests. User can choose multiple test cases, run and after runs report # them all automatically. # After test run gnb would be reset to basic scf if there is no "Send Full Commissioning" in test case. # User have to provide test cases absolute path and choose whether tests have to be reported with True/False flag. # There is also possibility to provide for script txt file with test cases file paths and True/False flag for reporting. # Both cases of calling script can also be mixed - only last report flag will be taken into account. source /home/ute/test_repo/bin/activate; path_to_tests="/home/ute/robotws/testsuite/Wroclaw/RRM/5G_SW_WRO/" check_and_save_host_name() { name_of_host=${HOSTNAME//-/_} echo echo -e "Name of host is $name_of_host \n" } get_users_testline_topology() { topology=$(grep "SetExecutionParams ran" /home/ute/results/logs/DEBUG_log.txt | grep -o CLOUD..*D) echo "Your testline topology is "$topology echo } #Ask user for software version and wait for user input, check if software is correct with Regex ask_user_for_software_version() { if [[ $# -eq "0" ]]; then while true do read -r -p "Your software version [For example SBTS00_ENB_9999_220706_000008 or SBTS23R1_ENB_0000_000979_000008]: " software_version if [[ "$software_version" =~ ^SBTS[0-9]{2}[R]*[0-9]*_ENB_[0-9]{4}_[0-9]{6}_[0-9]{6}$ ]]; then echo "Your software version is "$software_version echo break else echo -e "Your software version is wrong. Correct it and write again \n" fi done else software_version=$(ssh -q toor4nsn@192.168.255.129 \ "cat /rom/TargetBD_SBT* | grep -oG 'swReleaseVersionPackageName=\"SBTS[0-9]\{2\}[R]*[0-9]*_ENB_[0-9]\{4\}_[0-9]\{6\}_[0-9]\{6\}' \ | grep -oG 'SBTS[0-9]\{2\}[R]*[0-9]*_ENB_[0-9]\{4\}_[0-9]\{6\}_[0-9]\{6\}'") echo "Your software version is "$software_version echo fi } #Ask user for tests paths, choosing "No" exits loop, "try_again" clears execution list. ask_user_for_tests_to_add() { tests_to_execute=() report_tests="" if [[ $# -eq "0" ]]; then while true do echo read -r -p "Do you want to add next test? [Y/N/Try_Again] " Input_question case $Input_question in [yY][eE][sS]|[yY]) echo -e "Your answer is: Yes \n" read -r -p "Complete full path to your test: " testpathfull echo "Selected testpath: "$testpathfull echo if [[ -f $testpathfull ]]; then echo "You added test "$testpathfull tests_to_execute+=($testpathfull) echo "List of tests that will be executed: "${tests_to_execute[@]} echo continue else echo -e "Invalid input. Check your test path. \n" fi ;; [nN][oO]|[nN]) echo -e "Your answer is: No \n" break ;; [tT][rR][yY][_][aA][gG][aA][iI][nN]) tests_to_execute=() echo -e "List of test to execute is cleared \n" continue ;; *) echo -e "Invalid input... \n" ;; esac done else check_user_arguments $@ fi ask_user_if_he_want_to_report_tests $report_tests } #If user gave arguments to script then this function checks if argument is file, test case path or information if user # wants to report tests(True/False). Function creates list of tests to execute and set report tests flag. check_user_arguments() { for test_case in $@; do if [[ -f "$PWD/$test_case" && "$PWD/$test_case" == *".txt" ]]; then declare -a arr echo echo "Loading tests from file: "$PWD/$test_case echo while read -r line; do arr+=$line" " done <$PWD/$test_case for test_in_file in $arr; do if [[ $test_in_file = "True" || $test_in_file = "False" ]]; then echo report_tests=$test_in_file elif [[ -f "$test_in_file" ]]; then echo "You added test "$test_in_file tests_to_execute+=($test_in_file) echo else echo "Invalid test. Check your test path for "$test_in_file echo fi done elif [[ -f $test_case && "$PWD/$test_case" == *".txt" ]]; then declare -a arr echo echo "Loading tests from file: "$test_case echo while read -r line; do arr+=$line" " done <$test_case for test_in_file in $arr; do if [[ $test_in_file = "True" || $test_in_file = "False" ]]; then echo report_tests=$test_in_file elif [[ -f "$test_in_file" ]]; then echo "You added test "$test_in_file tests_to_execute+=($test_in_file) echo else echo "Invalid test. Check your test path for "$test_in_file echo fi done elif [[ $test_case = "True" || $test_case = "False" ]]; then echo report_tests=$test_case elif [[ -f "$test_case" ]]; then echo "You added test "$test_case tests_to_execute+=($test_case) echo else echo "Invalid test. Check your test path for "$test_case echo fi done echo "List of tests that will be executed: "${tests_to_execute[@]/$path_to_tests} } #Function set report_tests variable or ask user for input and then sets report_tests variable. ask_user_if_he_want_to_report_tests() { True_or_false=$1 if [[ $True_or_false = "True" || $True_or_false = "False" ]]; then report_tests=$True_or_false echo echo "Tests will be reported after runs: "$report_tests echo else while true do echo echo "################################################################################################################" read -r -p "############################### Do you want to automatically report tests? [Y/n] ############################### " report_tests echo "################################################################################################################" case $report_tests in [yY][eE][sS]|[yY]) report_tests=True echo -e "Your answer is: Yes \n" echo "################################################################################################################" echo "##################### Your test runs will be automatically reported after running all tests ####################" echo -e "################################################################################################################ \n" break ;; [nN][oO]|[nN]) report_tests=False echo -e "Your answer is: No \n" echo "################################################################################################################" echo "#################### Your test runs will not be automatically reported after running tests #####################" echo -e "################################################################################################################ \n" break ;; *) echo "Invalid input..." ;; esac done fi } #Run test, check if test was executed successfully and append list for successfull and not successfull reports. After running tests reset testline. run_tests_and_report_them() { successfull_tests=() not_successfull_tests=() for test_case in "${tests_to_execute[@]}"; do echo "Running test "$test_case echo testpath=${test_case/$path_to_tests} robot -V /home/ute/testline_configuration/$name_of_host -L TRACE -b debug.log -d /home/ute/logs/$testpath $test_case if [[ $? -eq "0" ]]; then echo echo "################################################################################################################" echo "###########################################Test executed successfully###########################################" echo -e "################################################################################################################ \n" successfull_tests+=($test_case) else not_successfull_tests+=($test_case) echo echo "################################################################################################################" echo "#######################################Test wasn't executed successfully########################################" echo -e "################################################################################################################ \n" fi robot -o NONE -l NONE -r NONE -t check_radio_modules /home/ute/robotws/testsuite/Wroclaw/RRM/5G_SW_WRO/resources/scripts/script.robot echo "#################################################################################" if ! grep -oq "Send Full Commissioning" $test_case; then echo echo -e "Trigerring testline reset \n" reset_testline_and_check_radios_are_up fi echo "####################################### Successfully run tests: " ${successfull_tests[@]/$path_to_tests} echo "####################################### Not successfully run tests: " ${not_successfull_tests[@]/$path_to_tests} echo done report_tests_and_check_if_tests_were_reported } #Execute script for reseting testlines and check if reset was successfull reset_testline_and_check_radios_are_up() { robot -o NONE -l NONE -r NONE -t reset_testline_and_wait_for_radio_modules /home/ute/robotws/testsuite/Wroclaw/RRM/5G_SW_WRO/resources/scripts/script.robot if [[ $? -eq "0" ]]; then echo echo -e "#####################TESTLINE RESET - EXECUTED SUCCESSFULLY###################### \n" else echo echo "####################################### Successfully run tests: " ${successfull_tests[@]/$path_to_tests} echo "####################################### Not successfully run tests: " ${not_successfull_tests[@]/$path_to_tests} echo "########################################### TESTS WERE NOT REPORTED ############################################" echo "################################################################################################################" echo "###################################PROBLEM WITH TESTLINE RESET - EXIT SCRIPT####################################" echo "################################################################################################################" exit 1 fi } #Report test and check in report file if test was successfully reported. Delete directory after check. report_tests_and_check_if_tests_were_reported() { echo "Whether tests will be reported? " $report_tests echo echo "Test runs with pass status: " ${successfull_tests[@]/$path_to_tests} echo echo "Test runs with fail status: " ${not_successfull_tests[@]/$path_to_tests} if [[ $report_tests == True ]]; then Reported_tests=() Not_reported_tests=() Not_reported_tests+=($not_successfull_tests) for Test_run in "${successfull_tests[@]}"; do rm -r /home/ute/reporting_portal_report &>/dev/null ute_reporting_portal send -ro /home/ute/logs/${Test_run/$path_to_tests}/output.xml -tl $name_of_host --sw_version $software_version --info $topology -l $topology cat /home/ute/reporting_portal_report/collected/reporting_portal.json | grep -q "RAN_ET" if [[ $? -eq "0" ]]; then Reported_tests+=($Test_run) else Not_reported_tests+=($Test_run) fi done else echo echo "####################################### Successfully run tests: " ${successfull_tests[@]/$path_to_tests} echo "####################################### Not successfully run tests: " ${not_successfull_tests[@]/$path_to_tests} echo "################################################ END OF SCRIPT #################################################" exit 0 fi echo echo "####################################### Successfull test runs: " ${successfull_tests[@]/$path_to_tests} echo "####################################### Not successfull test runs: " ${not_successfull_tests[@]/$path_to_tests} echo echo "####################################### Successfully reported tests: " ${Reported_tests[@]/$path_to_tests} echo "####################################### Not reported tests: " ${Not_reported_tests[@]/$path_to_tests} echo "################################################ END OF SCRIPT #################################################" exit 0 } run_user_interface() { echo echo "################################################################################################################" echo "################################################################################################################" echo "################################################################################################################" echo "########################## Choose your option ################################" echo "################################################################################################################" echo "######### 1. Choose test cases to run - sw version will be taken from conf. files #########" echo "######### 2. Choose your software version and test cases #########" echo "######### 3. Choose file to run test cases #########" echo "################################################################################################################" echo "################################################################################################################" echo -e "################################################################################################################ \n" while true do read -r -p "What is your choice? " user_choice echo "You chose option number "$user_choice case $user_choice in 1) echo -e "Choose test cases to run - sw version will be taken from conf. files \n" get_users_testline_topology ask_user_for_software_version No ask_user_for_tests_to_add break ;; 2) echo -e "Choose your software version and test cases \n" get_users_testline_topology ask_user_for_software_version ask_user_for_tests_to_add break ;; 3) echo -e "Choose file to run test cases \n" read -r -p "Enter absolute path to file: " user_choice get_users_testline_topology ask_user_for_software_version $@ ask_user_for_tests_to_add $user_choice break ;; *) echo "Invalid input..." ;; esac done } cd /home/ute/ check_and_save_host_name if [[ $# -eq "0" ]]; then run_user_interface else get_users_testline_topology ask_user_for_software_version $@ ask_user_for_tests_to_add $@ fi run_tests_and_report_them
Editor is loading...