--- /dev/null
+from logger import Logger
+from datetime import datetime
+import os
+import time
+import enum
+from util import util
+
+
+class UserInputReturnType(enum.Enum):
+ YES = 1,
+ NO = 2,
+ OTHER = 3,
+ ERROR = 4
+
+
+class executeRun:
+ """
+ This class runs TCs present in the rpm on the device.
+ It runs on 3 deviceS:-
+ TM1, TW2, RPI
+ """
+
+ rpm_path = '/local/repos/standard/armv7l/RPMS/'
+ rpm_name = '"efl-test-suite*.armv7l.rpm"'
+ device_path = "/opt/usr/"
+ download_path = "http://download.tizen.org/snapshots/tizen/unified/latest/repos/standard/packages/armv7l/"
+ results_dir_list = list()
+
+ def _waitforuserinput(self, query):
+ try:
+ user_input = input(query)
+ if user_input == 'Y' or user_input == 'y':
+ return UserInputReturnType.YES
+ elif user_input == 'N' or user_input == 'n':
+ return UserInputReturnType.NO
+ else:
+ return UserInputReturnType.OTHER
+ except ValueError:
+ return UserInputReturnType.ERROR
+
+ def _sdb_push(self):
+ while True:
+ gbs_root = input('Enter the path of your efl-test-suite RPMS directory: ')
+ gbs_root = util.expanduser(gbs_root)
+ Logger.info('Path entered: ' + gbs_root)
+ stream = os.popen("sudo find /" + gbs_root + " -name " + self.rpm_name)
+ efl_rpm = stream.read().strip()
+ if len(efl_rpm) == 0:
+ Logger.error("efl-test-suite RPM is not found. Check the entered path again.")
+ continue
+ else:
+ break
+ os.system("sudo cp " + efl_rpm + " /tmp/RPMS")
+ Logger.info("efl rpm can be found at path /tmp/RPMS/ on the system.")
+ os.system("sdb root on")
+ os.system("sdb push " + efl_rpm + " " + self.device_path)
+ efl_rpm = efl_rpm.split("/")[-1]
+ Logger.info(efl_rpm + " pushed successfully.")
+ check_rpm = ""
+ while True:
+ query = 'Enter Y/y to install latest check rpm, otherwise enter N/n: '
+ result = self._waitforuserinput(query)
+ if result == UserInputReturnType.ERROR:
+ Logger.error("Enter a valid input")
+ continue
+ elif result == UserInputReturnType.YES:
+ check_rpm = self.get_check_rpm()
+ os.system("sdb push " + check_rpm + " " + self.device_path)
+ check_rpm = check_rpm.split("/")[-1]
+ Logger.info(check_rpm + " is pushed successfully.")
+ break
+ elif result == UserInputReturnType.NO:
+ Logger.info("check rpm will neither be pushed nor installed on the target device.")
+ break
+ self._install_rpm(efl_rpm, check_rpm)
+
+ def get_check_rpm(self):
+ os.system('for i in $(wget -qO- '
+ + self.download_path
+ + ' | grep "check-0*.*armv7l.rpm<" | '
+ + "awk '{split($0,file,"
+ + r'"\""'
+ + "); print file[2]}'); do (cd /tmp/RPMS/ && curl -O "
+ + self.download_path
+ + "$i --silent);done"
+ )
+ os.system("rm -rf /tmp/RPMS/wget-* /tmp/RPMS/check-devel*")
+ Logger.info("check rpm is downloaded at path /tmp/RPMS/ on the system.")
+ stream = os.popen("find /tmp/RPMS/ -name " + "check-0*.armv7l.rpm")
+ check_rpm = stream.read().strip().split("\n")[0]
+ return check_rpm
+
+ def _install_rpm(self, efl_rpm, check_rpm):
+ os.system("sdb shell mount -o remount,rw /")
+ os.system('sdb shell su - -c "cd /opt/usr/; rpm -ivh --nodeps --force "'
+ + efl_rpm
+ + '"; exit"'
+ )
+ Logger.info(efl_rpm + " is installed successfully on the device.")
+ if len(check_rpm):
+ os.system('sdb shell su - -c "cd /opt/usr/; rpm -ivh --nodeps --force "'
+ + check_rpm
+ + '"; exit"'
+ )
+ Logger.info(check_rpm + " is installed successfully on the device.")
+
+ def _execute(self, device):
+ os.system("sdb shell su - -c 'cd /opt/usr/efl-test-suite/TC; ./execute.sh "
+ + device
+ + "; exit'"
+ )
+
+ def _sdb_pull(self, device):
+ result_path = input('Enter the path where you want to save results: ')
+ while True:
+ result_path = util.expanduser(result_path)
+ if not os.path.isdir(result_path):
+ result_path = input("Path not found!!.. Re-Enter the result path: ")
+ else:
+ Logger.warning('path entered: ' + result_path)
+ break
+ current_time = datetime.now().strftime("%d-%m-%Y_%H:%M:%S")
+ os.system("mkdir /" + result_path + "/result_" + device + "_" + current_time)
+ stream = os.popen("sdb shell su - -c 'cd "
+ + self.device_path
+ + "efl-test-suite/TC/results; ls -1rt; exit'")
+ self.results_dir_list = stream.read().splitlines()
+ exec_results = util.getExecutionResults(self.results_dir_list)
+
+ for tar_file in exec_results:
+ os.system("sdb pull "
+ + self.device_path
+ + "efl-test-suite/TC/results/"
+ + tar_file
+ + " "
+ + result_path
+ + "/result_"
+ + device
+ + "_"
+ + current_time
+ )
+ Logger.info("Results saved at " + result_path + "/result_" + device + "_" + current_time)
+
+ def run(self, device):
+ device_name = device
+ while True:
+ stream = os.popen("sdb get-state")
+ if stream.read().strip() == "device":
+ Logger.info("Device is connected to the system.")
+ break
+ else:
+ Logger.error("Device is either offline or not connected to the system.")
+ if self._waitforuserinput() == UserInputReturnType.NO:
+ return
+ continue
+ Logger.warning('Flash tizen image and push plugins into the device before starting execution.')
+ time.sleep(2)
+ if not os.path.isdir("/tmp/RPMS"):
+ os.system("mkdir /tmp/RPMS")
+ while True:
+ query = 'To cancel, Enter N/n; Enter Y/y, when the setup is ready to resume: '
+ result = self._waitforuserinput(query)
+ if result == UserInputReturnType.ERROR:
+ Logger.error("Enter a valid input")
+ continue
+ elif result == UserInputReturnType.YES:
+ self._sdb_push()
+ break
+ elif result == UserInputReturnType.NO:
+ return
+
+ if device_name == 'rpi':
+ device_name = 'mobile'
+ Logger.warning("Please setup wifi, lockscreen, screen timeout settings before starting execution.")
+ time.sleep(2)
+ while True:
+ query = 'To cancel, Enter N/n; Enter Y/y, when the setup is ready to resume: '
+ result = self._waitforuserinput(query)
+ if result == UserInputReturnType.ERROR:
+ Logger.error("Enter a valid input")
+ continue
+ elif result == UserInputReturnType.YES:
+ self._execute(device_name)
+ break
+ elif result == UserInputReturnType.NO:
+ return
+
+ self._sdb_pull(device)
+
+
+ExecuteRun = executeRun()
+
+if __name__ == '__main__':
+ ExecuteRun.run(device)