Пример #1
0
def build_for_target(test_node, target, g_option, f_option, clear, sections):
    #f_option is set if -f is used
    # Create the temperory build folders

    if f_option == 0:
        if os.path.exists(FOLDER.caliper_log_file):
            os.remove(FOLDER.caliper_log_file)
        if os.path.exists(FOLDER.summary_file):
            os.remove(FOLDER.summary_file)
    if not os.path.exists(FOLDER.build_dir):
        create_folder(FOLDER.build_dir)
    if not os.path.exists(FOLDER.exec_dir):
        create_folder(FOLDER.exec_dir)
    if not os.path.exists(FOLDER.results_dir):
        create_folder(FOLDER.results_dir)
    if not os.path.exists(FOLDER.yaml_dir):
        create_folder(FOLDER.yaml_dir)

    # This call assign target_arch with target architecture. Call
    # "get_host_arch" looks to be confusing :(
    target_arch = server_utils.get_host_arch(target)

    try:
        host_arch = server_utils.get_local_machine_arch()
    except Exception, e:
        logging.debug(" Error in get_local_machine_arch()")
        raise e
Пример #2
0
def build_for_local():
    arch = server_utils.get_local_machine_arch()
    logging.info("arch of the local host is %s" % arch)
    arch_dir = os.path.join(GEN_DIR, arch)
    if os.path.exists(arch_dir):
        shutil.rmtree(arch_dir)
    try:
        result = build_caliper(arch, 0)
    except Exception, e:
        raise Exception(e.args[0], e.args[1])
Пример #3
0
def build_for_local():
    arch = server_utils.get_local_machine_arch()
    logging.info("arch of the local host is %s" % arch)
    arch_dir = os.path.join(GEN_DIR, arch)
    if os.path.exists(arch_dir):
        shutil.rmtree(arch_dir)
    try:
        result = build_caliper(arch, flag=0, clear=0)
    except Exception, e:
        raise Exception(e.args[0], e.args[1])
Пример #4
0
def run_server_command(kind_bench, server_command, target):
    return_code = 0
    try:
        logging.debug("the server running command is %s" % server_command)
        local_arch = server_utils.get_local_machine_arch()
        local_exec_dir = os.path.join(caliper_path.GEN_DIR, local_arch)
        [output, return_code] = run_commands(local_exec_dir, kind_bench,
                                             server_command, target)
    except Exception, e:
        logging.debug("There is wrong with running the server command: %s" %
                      server_command)
        logging.info(e)
Пример #5
0
def run_server_command(kind_bench, server_command, target):
    return_code = 0
    try:
        logging.debug("the server running command is %s" % server_command)
        local_arch = server_utils.get_local_machine_arch()
        local_exec_dir = os.path.join(caliper_path.GEN_DIR, local_arch)
        [output, return_code] = run_commands(local_exec_dir, kind_bench,
                                                server_command, target)
    except Exception, e:
        logging.debug("There is wrong with running the server command: %s"
                        % server_command)
        logging.info(e)
Пример #6
0
def build_for_target(target,f_option,clear):
    #f_option is set if -f is used
    # Create the temperory build folders
    GEN_DIR = caliper_path.GEN_DIR
    WS_GEN_DIR = os.path.join(FOLDER.workspace, 'binary')

    benchs_dir = os.path.join(TMP_DIR, 'benchmarks')
    if not os.path.exists(benchs_dir):
        try:
            os.makedirs(benchs_dir, 0755)
        except Exception:
            os.mkdir(benchs_dir, 0755)

    # Improvement Point: Right now all the benchmarks are copied, we can only
    # copy the selected benchmarks to save the time.
    if os.path.exists(benchs_dir):
        shutil.rmtree(benchs_dir)
    shutil.copytree(caliper_path.BENCHS_DIR, benchs_dir)

    if not os.path.exists(caliper_path.FRONT_END_DIR):
        shutil.copytree(caliper_path.FRONT_TMP_DIR,
                caliper_path.FRONT_END_DIR)
    if f_option == 0:
        if os.path.exists(FOLDER.caliper_log_file):
            os.remove(FOLDER.caliper_log_file)

        if os.path.exists(FOLDER.summary_file):
            os.remove(FOLDER.summary_file)
    if not os.path.exists(FOLDER.build_dir):
        create_folder(FOLDER.build_dir)
    if not os.path.exists(FOLDER.exec_dir):
        create_folder(FOLDER.exec_dir)
    if not os.path.exists(FOLDER.results_dir):
        create_folder(FOLDER.results_dir)
    if not os.path.exists(FOLDER.yaml_dir):
        create_folder(FOLDER.yaml_dir)
    if not os.path.exists(FOLDER.html_dir):
        create_folder(FOLDER.html_dir)
    if not os.path.exists(caliper_path.HTML_DATA_DIR_INPUT):
        os.makedirs(caliper_path.HTML_DATA_DIR_INPUT)
    if not os.path.exists(caliper_path.HTML_DATA_DIR_OUTPUT):
        os.makedirs(caliper_path.HTML_DATA_DIR_OUTPUT)

    if server_utils.get_target_ip(target) in server_utils.get_local_ip():
        return build_for_local()

    try:
        host_arch = server_utils.get_local_machine_arch()
    except Exception, e:
        logging.debug(" Error in get_local_machine_arch()")
        raise e
Пример #7
0
def run_client_command(cmd_sec_name, tmp_logfile, kind_bench,
                        target, command):
    fp = open(tmp_logfile, "a+")
    start_log = "%%%%%%         %s test start       %%%%%% \n" % cmd_sec_name
    fp.write(start_log)
    fp.write("<<<BEGIN TEST>>>\n")
    tags = "[test: " + cmd_sec_name + "]\n"
    fp.write(tags)
    logs = "log: " + get_actual_commands(command, target) + "\n"
    fp.write(logs)
    start = time.time()
    flag = 0
    logging.debug("the client running command is %s" % command)

    # get the execution location in the remote host
    is_localhost = 0
    if server_utils.get_target_ip(target) in server_utils.get_local_ip():
        is_localhost = 1
    if (is_localhost == 1):
        arch = server_utils.get_local_machine_arch()
        host_exec_dir = os.path.join(caliper_path.GEN_DIR, arch)
    else:
        host_current_pwd = target.run("pwd").stdout.split("\n")[0]
        arch = server_utils.get_host_arch(target)
        host_exec_dir = os.path.join(host_current_pwd, 'caliper',
                                        "binary", arch)

    try:
        logging.debug("begining to execute the command of %s on remote host"
                        % command)
        if (is_localhost == 1):
            logging.debug("client command in localhost is: %s" % command)
            [out, returncode] = run_commands(host_exec_dir, kind_bench,
                                                command, fp, fp)
        else:
            logging.debug("client command in localhost is: %s" % command)
            [out, returncode] = run_remote_commands(host_exec_dir, kind_bench,
                                                    command, target, fp, fp)
    except error.ServRunError, e:
        fp.write("[status]: FAIL\n")
        sys.stdout.write(e)
        flag = -1
Пример #8
0
def build_each_tool(dirname, section_name, des_build_file, arch='x86_86'):
    """
    generate build.sh file for each benchmark tool and run the build.sh
    """

    os.chmod(des_build_file, stat.S_IRWXO + stat.S_IRWXU + stat.S_IRWXG)
    logging.info("=" * 55)
    logging.info("Building %s" % section_name)

    log_name = "%s.log" % section_name
    log_file = os.path.join(TMP_DIR, log_name)
    start_time = datetime.datetime.now()
    try:
        # Fixme : Using shell=True can be a security hazard.
        # See the warning under
        # https://docs.python.org/2/library/subprocess.html?highlight=subprocess.call#frequently-used-arguments.
        result = subprocess.call("echo '$$ %s BUILD START: %s' >> %s"
                                    % (section_name, str(start_time)[:19],
                                        FOLDER.caliper_log_file), shell=True)
        result = subprocess.call("%s %s %s %s >> %s 2>&1"
                                    % (des_build_file, arch,
                                        CALIPER_DIR, TMP_DIR, log_file),
                                        shell=True)
    except Exception:
        logging.info('There is exception when building the benchmarks')
        raise
    else:
        end_time = datetime.datetime.now()
        subprocess.call("echo '$$ %s BUILD STOP: %s' >> %s"
                         % (section_name, str(end_time)[:19],
                             FOLDER.caliper_log_file), shell=True)
        subprocess.call("echo '$$ %s BUILD DURATION: %s Seconds' >> %s"
                              % (section_name, (end_time - start_time).seconds,
                                  FOLDER.caliper_log_file), shell=True)
        if result:
            logging.info("Building Failed")
            logging.info("=" * 55)
            record_log(log_file, arch, 0)
        else:
            logging.info("Building Successful")
            logging.info("=" * 55)
            record_log(log_file, arch, 1)
    server_config = server_utils.get_server_cfg_path(
                                    os.path.join(dirname, section_name))
    # Not sure the server_config related section to be retained...
    if (server_config != ''):
        local_arch = server_utils.get_local_machine_arch()
        if (local_arch != arch):
            result = subprocess.call("%s %s %s %s> %s 2>&1"
                                    % (des_build_file, local_arch,
                                        CALIPER_DIR, TMP_DIR, log_file),
                                        shell=True)
            end_time = datetime.datetime.now()
            subprocess.call("echo '$$ %s BUILD STOP: %s' >> %s"
                            % (section_name, str(end_time)[:19],
                                FOLDER.caliper_log_file), shell=True)
            subprocess.call("echo '$$ %s BUILD DURATION %s Seconds' >> %s"
                            % (section_name, (end_time-start_time).seconds,
                                FOLDER.caliper_log_file), shell=True)
            if result:
                record_log(log_file, local_arch, 0)
            else:
                record_log(log_file, local_arch, 1)
            logging.debug("There is exception when building the benchmarks\
                        for localhost")
    return result
Пример #9
0
def build_each_tool(dirname, section_name, des_build_file, arch='x86_86'):
    """
    generate build.sh file for each benchmark tool and run the build.sh
    """

    os.chmod(des_build_file, stat.S_IRWXO + stat.S_IRWXU + stat.S_IRWXG)
    logging.info("=" * 55)
    logging.info("Building %s" % section_name)

    log_name = "%s.log" % section_name
    log_file = os.path.join(TMP_DIR, log_name)
    start_time = datetime.datetime.now()

    if os.path.exists(FOLDER.caliper_log_file):
        sections = section_name + " BUILD"
        fp = open(FOLDER.caliper_log_file,"r")
        f = fp.readlines()
        fp.close()
        op = open(FOLDER.caliper_log_file,"w")
        for line in f:
            if not(sections in line):
                op.write(line)
        op.close()
    try:
        # Fixme : Using shell=True can be a security hazard.
        # See the warning under
        # https://docs.python.org/2/library/subprocess.html?highlight=subprocess.call#frequently-used-arguments.
        result = subprocess.call("echo '$$ %s BUILD START: %s' >> %s"
                                    % (section_name, str(start_time)[:19],
                                        FOLDER.caliper_log_file), shell=True)
        result = subprocess.call("%s %s %s %s %s >> %s 2>&1"
                                    % (des_build_file, arch,
                                        CALIPER_DIR, TMP_DIR, "/".join(WS_GEN_DIR.split('/')[-2:]), log_file),
                                        shell=True)
    except Exception:
        logging.info('There is exception when building the benchmarks')
        raise
    else:
        end_time = datetime.datetime.now()
        subprocess.call("echo '$$ %s BUILD STOP: %s' >> %s"
                         % (section_name, str(end_time)[:19],
                             FOLDER.caliper_log_file), shell=True)
        subprocess.call("echo '$$ %s BUILD DURATION: %s Seconds' >> %s"
                              % (section_name, (end_time - start_time).seconds,
                                  FOLDER.caliper_log_file), shell=True)
        if result:
            logging.info("Building Failed")
            logging.info("=" * 55)
            record_log(log_file, arch, 0)
        else:
            logging.info("Building Successful")
            logging.info("=" * 55)
            record_log(log_file, arch, 1)
    server_config = server_utils.get_server_cfg_path(
                                    os.path.join(dirname, section_name))
    # Not sure the server_config related section to be retained...
    if (server_config != ''):
        local_arch = server_utils.get_local_machine_arch()
        if (local_arch != arch):
            result = subprocess.call("%s %s %s %s> %s 2>&1"
                                    % (des_build_file, local_arch,
                                        CALIPER_DIR, TMP_DIR, log_file),
                                        shell=True)
            end_time = datetime.datetime.now()
            subprocess.call("echo '$$ %s BUILD STOP: %s' >> %s"
                            % (section_name, str(end_time)[:19],
                                FOLDER.caliper_log_file), shell=True)
            subprocess.call("echo '$$ %s BUILD DURATION %s Seconds' >> %s"
                            % (section_name, (end_time-start_time).seconds,
                                FOLDER.caliper_log_file), shell=True)
            if result:
                record_log(log_file, local_arch, 0)
            else:
                record_log(log_file, local_arch, 1)
            logging.debug("There is exception when building the benchmarks\
                        for localhost")
    return result
Пример #10
0
def run_all_tests(caliper_dir, gen_dir, target):
    try:
        server_arch = server_utils.get_local_machine_arch()
    except error.ServUnsupportedError, e:
        raise error.ServRunError(e.args[0], e.args[1])
Пример #11
0
def caliper_run(target_exec_dir, target):
    # get the test cases defined files
    config_files = server_utils.get_cases_def_files(target_exec_dir)
    logging.debug("the selected configuration are %s" % config_files)

    for i in range(0, len(config_files)):
        # run benchmarks selected in each configuration file
        # config_file = os.path.join(caliper_path.CALIPER_PRE, config_files[i])
        config_file = os.path.join(config_files[i])
        config, sections = server_utils.read_config_file(config_file)
        logging.debug(sections)

        # get if it is the 'common' or 'arm' or 'android'
        classify = config_files[i].split("/")[-1].strip().split("_")[0]
        logging.debug(classify)

        for i in range(0, len(sections)):
            # run for each benchmark
            target_arch = server_utils.get_host_arch(target)
            build_name = sections[i] + '_' + target_arch + '.suc'
            build_suc = os.path.join(Folder.build_dir, build_name)
            if not os.path.exists(build_suc):
                continue
            build_host_name = sections[i] + '_' + \
                    server_utils.get_local_machine_arch() + '.fail'
            if os.path.exists(build_host_name):
                continue

            # try to resolve the configuration of the configuration file
            try:
                run_file = config.get(sections[i], 'run')
                parser = config.get(sections[i], 'parser')
            except Exception:
                raise AttributeError("The is no option value of parser")

            print_format()
            logging.info("Running %s" % sections[i])
            bench = os.path.join(classify, sections[i])
            try:
                result = run_all_cases(target_exec_dir, target, bench,
                                       sections[i], run_file)
            except Exception:
                logging.info("Running %s Exception" % sections[i])
                crash_handle.main()
                print_format()
                if sections[i] == "ltp":
                    try:
                        unmount = target.run(
                            "if  df -h |grep caliper_nfs  ; then umount /mnt/caliper_nfs/; fi"
                        )
                    except Exception:
                        unmount = target.run(
                            "if  df -h |grep caliper_nfs  ; then fuser -km /mnt/caliper_nfs ;fi"
                        )
                        unmount = target.run(
                            "if  df -h |grep caliper_nfs  ; then umount /mnt/caliper_nfs/ ;fi"
                        )
                run_flag = server_utils.get_fault_tolerance_config(
                    'fault_tolerance', 'run_error_continue')
                if run_flag == 1:
                    continue
                else:
                    return result
            else:
                logging.info("Running %s Finished" % sections[i])
                if sections[i] == "ltp":
                    try:
                        unmount = target.run(
                            "if  df -h |grep caliper_nfs  ; then umount /mnt/caliper_nfs/ ;fi"
                        )
                    except Exception:
                        unmount = target.run(
                            "if  df -h |grep caliper_nfs  ; then fuser -km /mnt/caliper_nfs/ ;fi"
                        )
                        unmount = target.run(
                            "if  df -h |grep caliper_nfs  ; then umount /mnt/caliper_nfs/ ;fi"
                        )
                print_format()

    return 0
Пример #12
0
def caliper_run(target_exec_dir, server, target):
    # get the test cases defined files
    config_files = server_utils.get_cases_def_files(target_exec_dir)
    logging.debug("the selected configuration are %s" % config_files)

    for i in range(0, len(config_files)):
        # run benchmarks selected in each configuration file
        # config_file = os.path.join(caliper_path.CALIPER_PRE, config_files[i])
        config_file = os.path.join(config_files[i])
        config, sections = server_utils.read_config_file(config_file)
        logging.debug(sections)

        # get if it is the 'common' or 'arm' or 'android'
        classify = config_files[i].split("/")[-1].strip().split("_")[0]
        logging.debug(classify)

        if classify == "server" and server:
            try:
                server_ip = settings.get_value("SERVER", "ip", type=str)
                server_port = settings.get_value("SERVER", "port", type=int)
                server_user = settings.get_value("SERVER", "user", type=str)
                logging.info(
                    "Please wait while caliper triggers the server.py script in the server"
                )
                server_pwd = server.run("pwd").stdout
                server_pwd = server_pwd.split("\n")[0]
                server_caliper_dir = os.path.join(server_pwd, "caliper_server")
                server_caliper_dir = os.path.join(server_caliper_dir,
                                                  "server.py")
                server_user = server_user + '@' + server_ip
                script = server_caliper_dir + ' ' + str(server_port)
                subprocess.Popen(
                    ['ssh', '%s' % server_user,
                     'python %s' % script])

            except Exception as e:
                logging.info(e)
                raise AttributeError(
                    "Error in establising connection with server")

        for i in range(0, len(sections)):
            # run for each benchmark
            target_arch = server_utils.get_host_arch(target)
            build_name = sections[i] + '_' + target_arch + '.suc'
            build_suc = os.path.join(Folder.build_dir, build_name)
            if not os.path.exists(build_suc):
                continue
            build_host_name = sections[i] + '_' + \
                    server_utils.get_local_machine_arch() + '.fail'
            if os.path.exists(build_host_name):
                continue

            # try to resolve the configuration of the configuration file
            try:
                run_file = config.get(sections[i], 'run')
                parser = config.get(sections[i], 'parser')
            except Exception:
                raise AttributeError("The is no option value of parser")

            print_format()

            logging.info("Running %s" % sections[i])
            bench = os.path.join(classify, sections[i])
            try:
                system_initialise(target)
                if classify == "server":
                    logging.info("Waiting for server to grant access")
                    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                    sock.connect((server_ip, server_port))
                    logging.info("%s" % str(sock.recv(1024)))

                result = run_all_cases(target_exec_dir, target, bench,
                                       sections[i], run_file)
                if classify == "server":
                    sock.send("1")
                    sock.close()
            except Exception:
                logging.info("Running %s Exception" % sections[i])
                crash_handle.main()
                print_format()
                if sections[i] == "ltp":
                    try:
                        unmount = target.run(
                            "if  df -h |grep caliper_nfs  ; then umount /mnt/caliper_nfs/; fi"
                        )
                    except Exception:
                        unmount = target.run(
                            "if  df -h |grep caliper_nfs  ; then fuser -km /mnt/caliper_nfs ;fi"
                        )
                        unmount = target.run(
                            "if  df -h |grep caliper_nfs  ; then umount /mnt/caliper_nfs/ ;fi"
                        )
                run_flag = server_utils.get_fault_tolerance_config(
                    'fault_tolerance', 'run_error_continue')
                if run_flag == 1:
                    continue
                else:
                    return result
            else:
                logging.info("Running %s Finished" % sections[i])
                if sections[i] == "ltp":
                    try:
                        unmount = target.run(
                            "if  df -h |grep caliper_nfs  ; then umount /mnt/caliper_nfs/ ;fi"
                        )
                    except Exception:
                        unmount = target.run(
                            "if  df -h |grep caliper_nfs  ; then fuser -km /mnt/caliper_nfs/ ;fi"
                        )
                        unmount = target.run(
                            "if  df -h |grep caliper_nfs  ; then umount /mnt/caliper_nfs/ ;fi"
                        )
                print_format()

    return 0
Пример #13
0
def caliper_run(target_exec_dir, target):
    # get the test cases defined files
    config_files = server_utils.get_cases_def_files(target_exec_dir)
    logging.debug("the selected configuration are %s" % config_files)

    for i in range(0, len(config_files)):
        # run benchmarks selected in each configuration file
        # config_file = os.path.join(caliper_path.CALIPER_PRE, config_files[i])
        config_file = os.path.join(config_files[i])
        config, sections = server_utils.read_config_file(config_file)
        logging.debug(sections)

        # get if it is the 'common' or 'arm' or 'android'
        classify = config_files[i].split("/")[-1].strip().split("_")[0]
        logging.debug(classify)

        for i in range(0, len(sections)):
            # run for each benchmark
            target_arch = server_utils.get_host_arch(target)
            build_name = sections[i]+'_'+target_arch+'.suc'
            build_suc = os.path.join(Folder.build_dir, build_name)
            if not os.path.exists(build_suc):
		      continue
            build_host_name = sections[i] + '_' + \
                    server_utils.get_local_machine_arch() + '.fail'
            if os.path.exists(build_host_name):
                continue


            # try to resolve the configuration of the configuration file
            try:
                run_file = config.get(sections[i], 'run')
                parser = config.get(sections[i], 'parser')
            except Exception:
                raise AttributeError("The is no option value of parser")

            print_format()
            logging.info("Running %s" % sections[i])
            bench = os.path.join(classify, sections[i])
            try:
                system_initialise(target)
                result = run_all_cases(target_exec_dir, target, bench,
                                        sections[i], run_file)
            except Exception:
                logging.info("Running %s Exception" % sections[i])
                crash_handle.main()
                print_format()
                if sections[i]== "ltp":
                    try:
                        unmount = target.run("if  df -h |grep caliper_nfs  ; then umount /mnt/caliper_nfs/; fi")
                    except Exception:
                        unmount = target.run("if  df -h |grep caliper_nfs  ; then fuser -km /mnt/caliper_nfs ;fi")
                        unmount = target.run("if  df -h |grep caliper_nfs  ; then umount /mnt/caliper_nfs/ ;fi")
                run_flag = server_utils.get_fault_tolerance_config(
                                'fault_tolerance', 'run_error_continue')
                if run_flag == 1:
                    continue
                else:
                    return result
            else:
                logging.info("Running %s Finished" % sections[i])
                if sections[i] == "ltp":
                    try:
                         unmount = target.run("if  df -h |grep caliper_nfs  ; then umount /mnt/caliper_nfs/ ;fi")
                    except Exception:
                         unmount = target.run("if  df -h |grep caliper_nfs  ; then fuser -km /mnt/caliper_nfs/ ;fi")
                         unmount = target.run("if  df -h |grep caliper_nfs  ; then umount /mnt/caliper_nfs/ ;fi")
                print_format()

    return 0