Example #1
0
def read_file_by_iozone(block_size=None,
                        file_size=None,
                        threads=None,
                        sequential=None):
    """
    Read file by iozone, will use params from test_conf generally
    """
    tc_logger.info('==>Start to read file by iozone')
    device_id = test_conf["device_id"]
    exe_file = test_conf['tool']['iozone']
    exe_dir = os.path.dirname(exe_file)
    if block_size is None:
        block_size = test_conf.get('block_size', '4k').lower()
    if file_size is None:
        file_size = test_conf.get('file_size', '128m').lower()
    if threads is None:
        threads = test_conf.get('threads', '8')
    if sequential is None:
        sequential = test_conf.get('sequential', True)
    sequential = '1' if unify_bool_value(sequential) else '2'
    command = 'shell "cd {0};{1} -w -r {2} -s {3} -i {4} -I -t {5}"'.format(
        exe_dir, exe_file, block_size, file_size, sequential, str(threads))

    adb = ADB(device_id)
    adb.execute_adb_command(command)
    tc_logger.info('==>Read file by iozone over')
Example #2
0
def keep_monitor():
    """
    Keep monitoring the test
    :return: None
    """
    if test_conf['monitor'] is True:
        tc_logger.info('==>Start monitoring execution')
        # config monitoring log
        tc_logger.removeHandler(ch)
        lh = logging.FileHandler(test_conf['monitor_dir'] + '/log.txt')
        lh.setLevel(logging.DEBUG)
        formatter = logging.Formatter(
            '%(asctime)s - %(levelname)s - %(message)s')
        lh.setFormatter(formatter)
        tc_logger.addHandler(lh)

        # start monitoring
        pool = Pool(1)
        m_module = import_module('android.monitor')
        m_func = getattr(m_module, 'monitor')
        pool.apply_async(func=m_func,
                         args=(test_conf['device_id'],
                               test_conf['monitor_target']))

        # revert monitoring log
        tc_logger.removeHandler(lh)
        tc_logger.addHandler(ch)
        tc_logger.info(
            'Monitoring system is starting adbd as root, waiting for {} seconds'
            .format(str(test_conf.get('monitor_root_sleep', 30))))
        time.sleep(test_conf.get('monitor_root_sleep', 30))
Example #3
0
def process_param(**kwargs):
    """
    Process parameters both from command line and IDE
    :param kwargs: key value pair
    :return: None
    """
    tc_logger.info('==>Start to process parameters')
    global test_conf
    if len(sys.argv) > 1:
        for arg in sys.argv[1:]:
            kv = arg.strip().split('=', 1)
            key = kv[0]
            value = kv[1]
            if ',' in value:
                value = value.lower().replace(' ', '').split(',')
            test_conf[key] = value
    else:
        for k, v in kwargs.items():
            if ',' in str(v):
                v = v.lower().replace(' ', '').split(',')
            test_conf[k] = v
    # make switch input standard
    switch = [
        'statistics', 'chart', 'monitor', 'watchdog', 'event_trace',
        'loop_health_report'
    ]
    for key in switch:
        if not isinstance(test_conf[key], bool):
            test_conf[key] = test_conf[key].lower() in ('1', 'true', 'yes',
                                                        't')

    if ("user_test_conf" in test_conf):
        tc_logger.info('==>Start to process user test conf yaml')
        with open(test_conf["user_test_conf"], 'r') as file:
            temp_conf = yaml.safe_load(file)
        for k, v in temp_conf.items():
            test_conf[k] = v
        tc_logger.info('==>Process user test conf yaml over')
    k1 = "default_suite_id"
    k2 = "default_test_id"
    v1 = test_conf[k1]
    v2 = test_conf[k2]
    for k, v in test_conf.items():
        if (type(v) == str):
            test_conf[k] = v.replace("@" + k1, v1).replace("@" + k2, v2)

    complete_config_path(
        test_conf['support_device'] + test_conf['support_tool'], test_conf)
    device = Device(test_conf['device_id'])
    device.root_device()
    if test_conf.get('device_type', None) is None:
        test_conf['device_type'] = device.get_host_manufacturer()[1][0]
    if test_conf.get('chip_manufacturer', None) is None:
        test_conf['chip_manufacturer'] = device.get_chip_manufacturer()[1][0]
    if test_conf.get('chip_capacity', None) is None:
        test_conf['chip_capacity'] = device.get_chip_capacity()[1][0]
    tc_logger.info('==>Process parameters over, valid parameters:')
    tc_logger.info(test_conf)
Example #4
0
    def main():
        initiate_device()
        initiate_file()
        keep_monitor()

        # config tc_logger to print in log.txt
        main_log = os.path.join(test_conf['log_home'], 'log.txt')
        fh = logging.FileHandler(main_log)
        fh.setLevel(logging.DEBUG)
        formatter = logging.Formatter(
            '%(asctime)s - %(levelname)s - %(message)s')
        fh.setFormatter(formatter)
        tc_logger.addHandler(fh)

        # import module and function
        set_up(level='case')
        module = import_module(test_conf['module'])
        func = getattr(module, test_conf['func'])
        try:
            func()
        except Exception as e:
            raise e
        finally:
            if test_conf['monitor'] is True:
                csv_files = [[
                    'monitor', test_conf['monitor_dir'] + '/monitor.csv'
                ]]
                convert_csv_files_to_json_file(csv_files)
            tear_down(level='case')
            if (test_conf.get("ddtf", None) is not None):
                tc_logger.removeHandler(fh)
Example #5
0
def run(**kwargs):
    process_param(**kwargs)

    def main():
        initiate_device()
        initiate_file()
        keep_monitor()

        # config tc_logger to print in log.txt
        main_log = os.path.join(test_conf['log_home'], 'log.txt')
        fh = logging.FileHandler(main_log)
        fh.setLevel(logging.DEBUG)
        formatter = logging.Formatter(
            '%(asctime)s - %(levelname)s - %(message)s')
        fh.setFormatter(formatter)
        tc_logger.addHandler(fh)

        # import module and function
        set_up(level='case')
        module = import_module(test_conf['module'])
        func = getattr(module, test_conf['func'])
        try:
            func()
        except Exception as e:
            raise e
        finally:
            if test_conf['monitor'] is True:
                csv_files = [[
                    'monitor', test_conf['monitor_dir'] + '/monitor.csv'
                ]]
                convert_csv_files_to_json_file(csv_files)
            tear_down(level='case')
            if (test_conf.get("ddtf", None) is not None):
                tc_logger.removeHandler(fh)

    if (test_conf.get("ddtf", None) is None):
        main()
    else:
        print("This is DDT workflow")
        ddtf = test_conf["ddtf"]
        if (ddtf.startswith("/")):
            ddtf = ddtf
        else:
            ddtf = os.path.join(test_conf["project_home"], "ddtf", ddtf)
        print("DDT file: " + ddtf)
        ddtd = read_csv_to_lls(ddtf)
        # temp_conf = copy.deepcopy(test_conf)
        for i in range(1, len(ddtd)):
            # test_conf = copy.deepcopy(temp_conf)
            print("Processing DDT Line " + str(i))
            for j in range(0, len(ddtd[i])):
                value = ddtd[i][j].replace(";", ",")
                if ("," in value):
                    value = value.lower().replace(' ', '').split(',')
                print(ddtd[0][j] + "=" + str(value))
                test_conf[ddtd[0][j]] = value
            main()
Example #6
0
def read_file_by_fio(block_size=None,
                     file_size=None,
                     rw=None,
                     rwmixread=None,
                     sub_jobs=None,
                     runtime=None):
    """
    Write file by fio, use params from test_conf generally
    """
    tc_logger.info('==>Write file by fio over')
    device_id = test_conf["device_id"]
    exe_file = test_conf['tool']['fio']
    iodepth = test_conf.get("iodepth", "32")

    if block_size is None:
        block_size = test_conf.get("block_size", "4k")
    if file_size is None:
        file_size = test_conf.get("file_size", "10G")
    if rw is None:
        rw = test_conf.get("rw", "read")
    if rwmixread is None:
        rwmixread = test_conf.get("rwmixread", "50")
    if runtime is None:
        runtime = test_conf.get("runtime", "600")
    if sub_jobs is None:
        sub_jobs = test_conf.get('sub_jobs', None)
    rewrite = unify_bool_value(test_conf.get('rewrite', True))
    filename = os.path.join(test_conf['tool']['dir'], 'fio_test_file')

    # testcase business workflow
    adb = ADB(device_id)
    if rw in ["randrw", "rw", "readwrite"]:
        rw = rw + " --rwmixread=" + rwmixread
    _sub_jobs = '--name=perf_std --filename={}'.format(filename)
    if sub_jobs:
        _sub_jobs_list = list()
        for i in range(1, int(sub_jobs) + 1):
            sub_name = 'job' + str(i)
            sub_filename = 'fio_test_' + str(file_size) + '_' + str(i)
            if not rewrite:
                rand_str = random.choice(range(10000))
                sub_filename = 'fio_test_' + str(file_size) + '_' + str(
                    i) + '_' + str(rand_str)
            sub_file_path = os.path.join(test_conf['tool']['dir'],
                                         sub_filename)
            _sub_job = '--name={0} --filename={1}'.format(
                sub_name, sub_file_path)
            _sub_jobs_list.append(_sub_job)
        _sub_jobs = ' '.join(_sub_jobs_list)
    fio_command = "shell {0} --direct=1 --norandommap=0 --numjobs=1 --ioengine=libaio --iodepth={1} --rw={2} --bs={3} --size={4} --runtime={5} --output-format=json,normal {6}" \
        .format(exe_file, iodepth, rw, block_size, file_size, runtime, _sub_jobs)
    adb.execute_adb_command(fio_command)
    tc_logger.info('==>Write file by fio over')
Example #7
0
def create_file_by_iozone(block_size=None, file_size=None, threads=None):
    """
    Create file by iozone, use params from test_conf generally, this method will write file 2 times
    """
    tc_logger.info('==>Start to create file by iozone')
    device_id = test_conf["device_id"]
    exe_file = test_conf['tool']['iozone']
    exe_dir = os.path.dirname(exe_file)
    if block_size is None:
        block_size = test_conf.get('block_size', '4k').lower()
    if file_size is None:
        file_size = test_conf.get('file_size', '128m').lower()
    if threads is None:
        threads = test_conf.get('threads', '8')
    command = 'shell "cd {0};{1} -w -r {2} -s {3} -i 0 -I -t {4}"'.format(
        exe_dir, exe_file, block_size, file_size, str(threads))

    adb = ADB(device_id)
    adb.execute_adb_command(command)
    tc_logger.info('==>Create file by iozone over')
Example #8
0
def _sleep(*args, **kwargs):
    """
    Sleep some time, default is 10 seconds, time as a param after sleep action has top priority
    """
    sleep_time = test_conf.get('loop_sleep', None)
    if sleep_time is None:
        sleep_time = 10
    if args:
        sleep_time = int(args[0])
    tc_logger.info('==>Sleeping {} seconds.'.format(sleep_time))
    sleep(int(sleep_time))
Example #9
0
def get_default_action(precondition=True, level='case'):
    """
    Get default action from input
    :param precondition: True means it's precondition, False means post condition
    :param level: case level or loop level
    :return: default action, list
    """
    default_action = list()
    if level == 'case':
        key = 'pre_case' if precondition else 'post_case'
    else:
        key = 'pre_loop' if precondition else 'post_loop'
    pre_key = test_conf.get(key, None)
    if pre_key:
        default_action = test_conf.get(pre_key, list())
        if default_action is None:
            default_action = list()
        else:
            if None in default_action:
                default_action.remove(None)
    if default_action:
        tc_logger.info('==>Default {} action: {}'.format(key, default_action))
    return default_action
Example #10
0
def tear_down(level, **kwargs):
    """
    A hook that will be executed after execution
    :return: None
    """
    post_actions = gather_action(precondition=False, level=level)
    for action in post_actions:
        _action, param, kw_param = handle_action(action)
        func = getattr(pipeline, _action)
        if 'loop' not in kwargs.keys():
            func(*param, **kw_param)
        else:
            kw_param['loop'] = kwargs['loop']
            if kwargs['loop'] % test_conf.get('loop_interval', 1) == 0:
                func(*param, **kw_param)
Example #11
0
def set_up(level, **kwargs):
    """
    A hook that will be executed before execution
    :param level: case level or loop level
    :return: None
    """
    pre_actions = gather_action(precondition=True, level=level)
    for action in pre_actions:
        _action, param, kw_param = handle_action(action)
        func = getattr(pipeline, _action)
        if 'loop' not in kwargs.keys():
            func(*param, **kw_param)
        else:
            kw_param['loop'] = kwargs['loop']
            if kwargs['loop'] % test_conf.get('loop_interval', 1) == 0:
                func(*param, **kw_param)
Example #12
0
def get_additional_action(precondition=True, level='case'):
    """
    Get additional action from input
    :param precondition: True means it's precondition, False means post condition
    :param level: case level or loop level
    :return: additional action, list
    """
    if level == 'case':
        key = 'add_pre_case' if precondition else 'add_post_case'
    else:
        key = 'add_pre_loop' if precondition else 'add_post_loop'
    additional_action = test_conf.get(key, list())
    if isinstance(additional_action, str):
        additional_action = [additional_action]
    if additional_action:
        tc_logger.info('==>Additional action: {}'.format(additional_action))
    return additional_action
Example #13
0
def get_exclusive_action(precondition=True, level='case'):
    """
    Get exclusive action from input
    :param precondition: True means it's precondition, False means post condition
    :param level: case level or loop level
    :return: exclusive action, list
    """
    if level == 'case':
        key = 'ud_pre_case' if precondition else 'ud_post_case'
    else:
        key = 'ud_pre_loop' if precondition else 'ud_post_loop'
    exclusive_action = test_conf.get(key, list())
    if isinstance(exclusive_action, str):
        exclusive_action = [exclusive_action]
    if exclusive_action:
        tc_logger.info('==>Exclusive action: {}'.format(exclusive_action))
    return exclusive_action
Example #14
0
def watchdog(timeout, func, *args, **kw):
    if test_conf["watchdog"] is not True:
        return func(*args, **kw)
    else:
        if timeout is None:
            timeout = int(test_conf.get("watchdog_timeout", 300))
        que = Queue.Queue(1)
        thread = threading.Thread(target=lambda q: q.put(func(*args, **kw)),
                                  args=(que, ))
        thread.setDaemon(True)
        thread.start()
        try:
            result = que.get(timeout=timeout)
        except Queue.Empty:
            tc_logger.error("Watchgod TimeOut - {} seconds".format(
                str(timeout)))
            raise
        return result