Esempio n. 1
0
def exec_util(main: str, args: str = "", timeout: Optional[int] = None):
    base_path = dirname(__file__)
    utils_jar_path = join(base_path, __UTILS_JAR_NAME)

    if exists(utils_jar_path) and not is_valid_file(utils_jar_path,
                                                    __UTILS_JAR_MD5):
        remove(utils_jar_path)

    if not exists(utils_jar_path):
        try:
            download_file(__UTILS_JAR_URL, utils_jar_path, __UTILS_JAR_MD5)
        except (URLError, ValueError, FileNotFoundError) as e:
            raise ValueError("utils unavailable: {}".format(e))

    return Shell.exec(
        "java -cp \"{}\" de.tu_darmstadt.stg.mubench.utils.{} {}".format(
            utils_jar_path, main, args),
        timeout=timeout)
Esempio n. 2
0
class Summarizer:
    """
    "
    """
    def __init__(self):
        self.shell = Shell()

    def summary(self, job_id, job_cnt):
        core_time = self.obtain_time("job{0}.sh.o{1}".format(job_cnt, job_id))

        # self.clean_up(job_type, job_id)
        self.clean_up(job_cnt, job_id)
        return core_time

    def obtain_time(self, filename):
        f_check = Path("{0}{1}".format(dir_path, filename))
        while not f_check.exists():
            time.sleep(5)
        f = open("{0}{1}".format(dir_path, filename))
        lines = f.readlines()
        f.close()
        for line in lines:
            m = time_exp.match(line)
            if m:
                calc_time = int(m.group("decimal")) +\
                    int(m.group("float")) * 10**(-len(m.group("float")))
                print(calc_time)
                return calc_time

    def clean_up(self, job_cnt, job_id):
        self.shell.execute(
            "cp", ["job{0}.sh.o{1} ../../tmp/".format(job_cnt, job_id)], [],
            dir_path)
        self.shell.execute(
            "cp", ["job{0}.sh.e{1} ../../tmp/".format(job_cnt, job_id)], [],
            dir_path)
        self.shell.execute("rm", [
            "job{0}.sh.o{1}".format(job_cnt, job_id),
            "job{0}.sh.e{1}".format(job_cnt, job_id),
        ], ["-f"], dir_path)
    logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
handler.setLevel(logging.DEBUG)
logger.addHandler(handler)

example_projects_by_API = {}
with open(INDEX_PATH) as index:
    for row in csv.reader(index, delimiter="\t"):
        # skip blank lines, e.g., on trailing newline
        if not row:
            continue

        target_type = row[6]
        try:
            if target_type not in example_projects_by_API:
                logger.info("Preparing examples for type: %s...", target_type)
                target_example_file = os.path.join(CHECKOUTS_PATH,
                                                   target_type + ".yml")
                example_projects = {}
                with open_yamls_if_exists(target_example_file) as projects:
                    for project in projects:
                        hash = Shell.exec(
                            "cd \"{}\"; git rev-parse HEAD".format(
                                join(MUBENCH_ROOT_PATH, project["path"])))
                        example_projects[project["url"]] = hash.strip()
                example_projects_by_API[target_type] = example_projects
        except Exception as error:
            logger.exception("failed", exc_info=error)

write_yaml(example_projects_by_API,
           join(CHECKOUTS_PATH, "example_projects_by_API.yml"))
Esempio n. 4
0
 def remove_ignore_lines(self, file):  
     Shell().execute("sed -i '/TargetBD/d' {}".format(file))      
    # new_user_view_video()
    #  login()
    test_new_user_view_live()
    # getSide()
    # swipeUp(500, 3)


if __name__ == '__main__':
     xml_report_path = "./allure-results"
     html_report_path = "./allure-results/html"
     # 开始测试
     args = ["test.py", '-s', '-q', '--alluredir', xml_report_path]
     pytest.main(args)
     args = ["test.py", '-s', '-q', '--alluredir', xml_report_path]
     pytest.main(args)
     # 生成html测试报告
     cmd1 = 'allure generate %s -o %s' % (xml_report_path, html_report_path)
     cmd2 = 'allure open ' + html_report_path
     try:
         Shell.invoke(cmd1)
         Shell.invoke(cmd2)
     except:
         L.e("Html测试报告生成失败,确保已经安装了Allure-Commandline")
     # try :
     #     Shell.invoke("allure serve --profile  ./")
     # except:
     #     L.e("Html测试报告生成失败,确保已经安装了Allure-Commandline")
     #

Esempio n. 6
0
 def _clone(self, url: str, revision: str, path: str):
     Shell.exec("git clone {} . --quiet".format(url), cwd=path, logger=self._logger)
Esempio n. 7
0
 def get_os_version(did):
     """获取手机系统版本"""
     return Shell.run(
         f"adb -s {did} shell getprop ro.build.version.release")
Esempio n. 8
0
 def test_command_try(self):
     assert Shell.try_exec("echo 'test'")
Esempio n. 9
0
 def test_timeout(self):
     with assert_raises(TimeoutError):
         Shell.exec("sleep 10", timeout=1)
Esempio n. 10
0
class DeployCommand():
    def __init__(self, neuron_path):
        self.env = Environment()
        self.shell = Shell()
        self.neuron_path = neuron_path
        job_name = 'job_{0}'.format(self.env.get_env())
        self.build_generator = BuildGenerator()
        self.job_generator = JobGenerator(job_name)

    def build(self, env, bench, params, use_tmp, build_neuron, neuron_use_tmp):
        self.build_generator.gen(params, use_tmp, neuron_use_tmp, env)
        commands = []
        tmp_str = ".tmp" if use_tmp else ""
        if env == "cluster":
            if build_neuron:
                commands.append({
                    "command":
                    "make",
                    "args": ["clean"],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
                commands.append({
                    "command":
                    "../../genie/simulator/tmp/build_config.sh",
                    "args": [],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
                commands.append({
                    "command":
                    "make",
                    "args": [],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
                commands.append({
                    "command":
                    "make",
                    "args": ["install"],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
            commands.append({
                "command":
                "./make_special.sh",
                "args": ["x86_64", bench, tmp_str],
                "options": [],
                "work_dir":
                "{0}/specials{1}".format(self.neuron_path, tmp_str)
            })
        if env == "k":
            if build_neuron:
                commands.append({
                    "command":
                    "../config/do_config_k1.sh",
                    "args": [],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
                commands.append({
                    "command":
                    "make",
                    "args": [],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
                commands.append({
                    "command":
                    "make",
                    "args": ["install"],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
                commands.append({
                    "command":
                    "../../genie/simulator/tmp/build_config.sh",
                    "args": [],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
                commands.append({
                    "command":
                    "export",
                    "args": ["LANG=C"],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
                commands.append({
                    "command":
                    "export",
                    "args": ["LC_ALL=C"],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
                commands.append({
                    "command":
                    "make",
                    "args": [],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
                commands.append({
                    "command":
                    "make",
                    "args": ["install"],
                    "options": [],
                    "work_dir":
                    "{0}/nrn-7.2{1}".format(self.neuron_path, tmp_str)
                })
                commands.append({
                    "command":
                    "cp",
                    "args": ["./x86_64/bin/*", "./sparc64/bin/"],
                    "options": [],
                    "work_dir":
                    "{0}/exec{1}".format(self.neuron_path, tmp_str)
                })
            commands.append({
                "command":
                "./make_special.sh",
                "args": [],
                "options": ["sparc64", bench, tmp_str],
                "work_dir":
                "{0}/specials{1}".format(self.neuron_path, tmp_str)
            })
        self.shell.run_cmds(commands)

    def run(self, env, params, cnt, use_tmp):
        self.job_generator.gen(params, cnt, use_tmp)
        if env == "cluster":
            res = self.shell.execute(
                "qsub", ["../../genie/simulator/tmp/job{0}.sh".format(cnt)],
                [], "{0}/hoc".format(self.neuron_path))[0]
            if type(res) is bytes:
                res = res.decode('utf-8')
            m = id_cluster_exp.match(res)
            return m.group("id")
        elif env == "k":
            res = self.shell.execute(
                "pjsub", ["../../genie/simulator/tmp/job{0}.sh".format(cnt)],
                [], "{0}/hoc".format(self.neuron_path))[0]
            if type(res) is bytes:
                res = res.decode('utf-8')
            m = id_k_exp.match(res)
            return m.group("id")
Esempio n. 11
0
 def test_output_contains_non_empty_stderr(self):
     out = Shell.exec("echo 'test' 1>&2")
     expected = "=== ERROR ===" + os.linesep + "test" + os.linesep
     assert_equals(expected, out)
Esempio n. 12
0
 def exists(self) -> bool:
     return exists(self.checkout_dir) and Shell.try_exec("svn info", cwd=self.checkout_dir)
Esempio n. 13
0
File: env.py Progetto: hashmup/genie
 def __init__(self):
     self.shell = Shell()
Esempio n. 14
0
 def create(self) -> None:
     self._logger.debug("Create chackout directory %s", self.checkout_dir)
     makedirs(self.checkout_dir, exist_ok=True)
     self._logger.debug("Checkout from %s", self.url)
     Shell.exec("svn checkout \"{}@{}\" .".format(self.url, self.revision), cwd=self.checkout_dir)
Esempio n. 15
0
 def _is_repo(self, path: str):
     return exists(path) and Shell.try_exec("git status", cwd=path, logger=self._logger)
Esempio n. 16
0
 def _update(self, url: str, revision: str, path: str):
     Shell.exec("git checkout {} --quiet".format(revision), cwd=path, logger=self._logger)
Esempio n. 17
0
 def test_output(self):
     out = Shell.exec("echo test")
     assert_equals("test" + os.linesep, out)
Esempio n. 18
0
 def test_output_contains_stdout_and_stderr(self):
     out = Shell.exec("echo '-stdout-' && echo '-stderr-' 1>&2")
     expected = "=== OUT ===" + os.linesep + \
                "-stdout-" + os.linesep + \
                "=== ERROR ===" + os.linesep + \
                "-stderr-" + os.linesep
Esempio n. 19
0
 def test_command_failure(self):
     with assert_raises(CommandFailedError):
         Shell.exec("unknown command")
Esempio n. 20
0
 def start_app(did, package):
     """启动APP"""
     activity = f"{package}.activity.StartActivity"
     Shell.run(f"adb -s {did} shell am start -n {package}/{activity}")
Esempio n. 21
0
 def test_command_try_failure(self):
     assert not Shell.try_exec("unknown command")
Esempio n. 22
0
 def cat_log(did, file_path):
     """打印Android日志"""
     Shell.exec_back(f"adb -s {did} logcat -v time > {file_path}")
Esempio n. 23
0
 def test_runs(self):
     Shell.exec("echo 'test'")
Esempio n. 24
0
 def extract_7zfiles(self):
     for file in self.all_7zfiles:
         Shell().execute("7za x {} -yo'{}'".format(file, "lteDo")) 
         self.logger.info("Extract {} done".format(file))    
Esempio n. 25
0
 def quit_app(did, package):
     """退出APP"""
     Shell.run(f"adb -s {did} shell am force-stop {package}")
Esempio n. 26
0
 def execute(self, version: ProjectVersion, detector_arguments: Dict[str,
                                                                     str],
             timeout: Optional[int], logger: Logger):
     detector_arguments = self._filter_args(detector_arguments, logger)
     command = self._get_command(detector_arguments)
     Shell.exec(command, logger=logger, timeout=timeout)
Esempio n. 27
0
 def get_brand(did):
     """获取手机品牌"""
     return Shell.run(f"adb -s {did} shell getprop ro.product.brand")
Esempio n. 28
0
 def export(self, file, option=""):
     file = self._check_repo(file)
     command = ["svn export", file, option, self.svn_option]
     result = Shell().execute(" ".join(command))
     return result
Esempio n. 29
0
run case with key word:
    python3 run.py -k <keyword>

"""

if __name__ == '__main__':
    env = Environment()
    xml_report_path = env.get_environment_info().xml_report
    html_report_path = env.get_environment_info().html_report
    # 开始测试
    args = [
        '-s', '-q', '--allure_features=My stdio1', '--alluredir',
        xml_report_path
    ]
    # args = ['-s', '-q'],'--allure_features=My stdio'
    self_args = sys.argv[1:]
    pytest.main(args)
    # 生成html测试报告
    cmd = 'allure generate %s -o %s' % (xml_report_path, html_report_path)
    #
    try:
        Shell.invoke(cmd)
    except:
        L.e("Html测试报告生成失败,确保已经安装了Allure-Commandline")
    # 查找html报告并发送
    # time.sleep(2)
    # from utils.mail import Mail
    # mail = Mail()
    # mail.sendMail()
Esempio n. 30
0
 def externals(self, file, option=""):
     file = self._check_repo(file)
     command = ["svn pg svn:externals", file, option, self.svn_option]
     result = Shell().execute(" ".join(command))
     return result