#!/bin/sh TEXT_ERROR='\033[0;31mError: \033[0m' TEXT_INFO='\033[0;32mInfo: \033[0m' print_help() { echo "usage: $0 [-h] [-b [BUILT_TYPE]] [-i [PACKAGE]] [-t]\n" echo "Tool for easy building, installing and running tests of Universal Switch." echo "Requires getopt, gbs and sdb.\n" echo "Options:" echo "-h,--help print this message" echo "-bBUILT_TYPE,--build=BUILT_TYPE build repository using GBS, available types are: 'initial', 'fast', 'no-tests', default value is 'fast'" echo "-iPACKAGE,--install=PACKAGE install package on connected target, available packages are: 'base', 'tests', 'all', default value is 'all'" echo "-t,--run-tests run tests on connected target" echo "-j,--clean-journal vacuum systemd journal on target" } check_if_sdb_exist() { which sdb 1>/dev/null if [ "$?" -ne 0 ]; then echo $TEXT_ERROR"Command sdb cannot be found, check if it is installed and its directory is added to PATH" exit 1 fi } check_if_target_connected() { check_if_sdb_exist sdb devices | grep "device " 1>/dev/null if [ "$?" -ne 0 ]; then echo $TEXT_ERROR"Target not connected" exit 1 fi } rpm_install() { TMP=`mktemp -d` check_if_target_connected sdb root on sdb -d shell mount -o remount,rw / cp "$@" "$TMP" 2>/dev/null sdb push "$TMP" "$TMP" sdb -d shell rpm -Uvh --force "$TMP"/* } exit_on_error() { if [ $? -eq 1 ]; then exit 1 fi } RUN_TESTS=0 CLEAN_JOURNAL=0 DEFAULT_BUILT_TYPE="fast" DEFAULT_INSTALL_TYPE="all" VERSION=`awk '/Version/ {print $2}' packaging/org.tizen.universal-switch.spec` RELEASE=`awk '/Release/ {print $2}' packaging/org.tizen.universal-switch.spec` ARGUMENTS=`getopt -o hb::i::tj -l help,build::,install::,run-tests,clean-journal -n "$0" -- "$@"` if [ $? -ne 0 ]; then print_help; fi eval set -- "$ARGUMENTS" while [ $# -gt 0 ]; do key="$1" case "$key" in --) shift break ;; '-h'|'--help') print_help exit 0 ;; '-b'|'--build') case "$2" in "") BUILD_DIR="$HOME/GBS-ROOT/local/BUILD-ROOTS/scratch.armv7l.0/home/abuild/rpmbuild/BUILD/org.tizen.universal-switch-$VERSION" if [ -d "$BUILD_DIR" ]; then BUILD_TYPE="fast" else BUILD_TYPE="initial" fi shift 2 ;; *) BUILD_TYPE="$2" shift 2 ;; esac ;; '-i'|'--install') case "$2" in "") INSTALL_PACKAGE="$DEFAULT_INSTALL_TYPE" shift 2 ;; *) INSTALL_PACKAGE="$2" shift 2 ;; esac ;; '-t'|'--run-tets') RUN_TESTS=1 shift ;; '-j'|'--clean-journal') CLEAN_JOURNAL=1 shift ;; *) echo "Invalid option, use '--help' for available options" exit 1 ;; esac done if [ "$BUILD_TYPE" != "" ]; then echo $TEXT_INFO"Build type: "$BUILD_TYPE" chosen" case "$BUILD_TYPE" in 'initial') gbs build -A armv7l --include-all --ccache --define "jobs 4" exit_on_error ;; 'fast') gbs build -A armv7l --include-all --noinit --ccache --keep-packs --define "jobs 4" exit_on_error ;; 'no-tests') gbs build -A armv7l --include-all --noinit --ccache --keep-packs --define "_without_tests 1" --define "jobs 4" exit_on_error ;; *) echo $TEXT_ERROR"Cannot build, valid options for building are: initial, fast, no-tests" exit 1 ;; esac fi if [ "$INSTALL_PACKAGE" != "" ]; then GBS_PATH="$HOME/GBS-ROOT/local/repos/public_mobile/armv7l/RPMS" BASE_PACKAGE_NAME="$GBS_PATH/org.tizen.universal-switch-$VERSION-$RELEASE.armv7l.rpm" TEST_PACKAGE_NAME="$GBS_PATH/org.tizen.universal-switch-tests-$VERSION-$RELEASE.armv7l.rpm" TEST_LIB_PACKAGE_NAME="$HOME/GBS-ROOT/local/cache/*/gtest-[0-9]*" case "$INSTALL_PACKAGE" in 'base') if [ -f "$BASE_PACKAGE_NAME" ]; then BASE_FILE="$BASE_PACKAGE_NAME" else echo $TEXT_ERROR"Base package not found, check if it was built." exit 1 fi ;; 'tests') if [ -f "$TEST_PACKAGE_NAME" ]; then TEST_FILE="$TEST_PACKAGE_NAME" LIB_FILE="$TEST_LIB_PACKAGE_NAME" else echo $TEXT_ERROR"Test package not found, check if it was built." exit 1 fi ;; 'all') if [ -f "$BASE_PACKAGE_NAME" -a -f "$TEST_PACKAGE_NAME" ]; then BASE_FILE="$BASE_PACKAGE_NAME" TEST_FILE="$TEST_PACKAGE_NAME" LIB_FILE="$TEST_LIB_PACKAGE_NAME" else echo $TEXT_ERROR"Not all packages exist, check if they were built." exit 1 fi ;; *) echo $TEXT_ERROR"Cannot install, valid options for installing are: base, tests, all" exit 1 ;; esac check_if_target_connected echo $TEXT_INFO"Following packages will be installed: $BASE_FILE $TEST_FILE $LIB_FILE" rpm_install "$BASE_FILE" "$TEST_FILE" $LIB_FILE fi if [ $CLEAN_JOURNAL -eq 1 ]; then check_if_target_connected sdb root on sdb shell 'journalctl --vacuum-size=1K' fi if [ $RUN_TESTS -eq 1 ]; then check_if_target_connected echo $TEXT_INFO"Setting vconf keys..." dir="$(dirname "$0")" "$dir"/utils/setVconfKeys.sh "accessibilityTests/" sdb root on sdb shell ' set -e DATE=`date "+%F %X"` for i in /usr/apps/org.tizen.universal-switch-tests/no-ui-scenarios/* do $i done echo "Tests with Graphical User Interface" UI_PID=`app_launcher -s org.tizen.universal-switch-tests | sed "s/^.*pid \= \([[:digit:]]*\).*$/\1/"` journalctl --since "$DATE" -f | grep universal-switch-tests & while kill -0 $UI_PID 2> /dev/null do sleep 1 done ' fi