Пример #1
0
import json

from protos_gen.config_pb2 import RunnerConfig, TestcaseConfig
from protos_gen.record_pb2 import TestExecutionRecord
from utils.base import generate_id, base64_encode, LogChunkCache
from utils.ios import config_plist, xctest_cmd, spawn_xcrun_log, parse_sim_log

if __name__ == '__main__':
    runner_conf = RunnerConfig()
    runner_conf.jobID = 'TJ-1'
    runner_conf.runnerID = generate_id('RUN-A')

    runner_conf.sdkConfig.appKeyIOS = 'VVW0Fno7BEZt1a/y6KLM36uj9qcjw7CAHDwWZKDlWDs='
    runner_conf.sdkConfig.appKeyAndroid = 'J6IPlk5AEU+2/Yi59rfYnsFQtdtOgAo9GAzysx8ciOM='

    # runner_conf.sdkConfig.serverSites["shl2"].CopyFrom(Site(ips=["http://114.80.155.50:22016"]))

    runner_conf.sdkConfig.marketPerm.Level = "2"
    # runner_conf.sdkConfig.marketPerm.CffLevel = "2"
    # runner_conf.sdkConfig.marketPerm.DceLevel = "2"
    # runner_conf.sdkConfig.marketPerm.CzceLevel = "2"
    # runner_conf.sdkConfig.marketPerm.FeLevel = "2"
    # runner_conf.sdkConfig.marketPerm.GILevel = "2"
    # runner_conf.sdkConfig.marketPerm.ShfeLevel = "2"
    # runner_conf.sdkConfig.marketPerm.HKPerms.extend(["hk10", "hka1"])

    case_conf = TestcaseConfig()
    case_conf.testcaseID = 'TESTCASE_1'
    case_conf.continueWhenFailed = False
    case_conf.roundIntervalSec = 3
    case_conf.paramStrs.extend([json.dumps({'QUOTE_NUMBERS': '600000.sh'})])
Пример #2
0
def testAndroidCases(case_conf, market_level, hk_perms, server_sites):
    """
    测试安卓样例
    :param case_conf:       case_conf
    :param market_level:    runner_conf.sdkConfig.marketPerm.Level
    :param hk_perms:        runner_conf.sdkConfig.marketPerm.HKPerms.extend([ @param ])
    :param server_sites:    runner_conf.sdkConfig.serverSites[ @key ].CopyFrom(Site(ips=[ @value ]))
    """
    runner_conf = RunnerConfig()
    runner_conf.jobID = 'TJ-1'
    runner_conf.runnerID = generate_id('RUN-A')
    runner_conf.sdkConfig.appKeyIOS = 'VVW0Fno7BEZt1a/y6KLM36uj9qcjw7CAHDwWZKDlWDs='
    runner_conf.sdkConfig.appKeyAndroid = 'J6IPlk5AEU+2/Yi59rfYnsFQtdtOgAo9GAzysx8ciOM='
    runner_conf.sdkConfig.marketPerm.Level = market_level
    runner_conf.casesConfig.extend(case_conf)

    if hk_perms.__len__() != 0:
        runner_conf.sdkConfig.marketPerm.HKPerms.extend(hk_perms)

    if server_sites.__len__() != 0:
        for k, v in server_sites.items():
            runner_conf.sdkConfig.serverSites[k].CopyFrom(Site(ips=[v]))

    print(base64_encode(runner_conf.SerializeToString()))

    chunk_cache = LogChunkCache()

    def read_record(record_str):
        record = TestExecutionRecord()
        ''''''
        recordFromAndroid.append(record_str)
        chunk_cacheFromAndroid.append(chunk_cache)
        data = parse_logcat(chunk_cache, record_str)
        if data:
            record.ParseFromString(data)
        if len(record.ListFields()) > 0:
            print("*********Record Start****************")
            # print(record)
            test_db.append(record)
            test_out.append(data)
            print("*********Record End****************\n")

    spawn_logcat(serial=serial_str, logger=read_record)

    test_status_code = []

    def check_test_result(line):
        global test_result
        if 'INSTRUMENTATION_STATUS_CODE' in line:
            # find number in string, https://stackoverflow.com/a/29581287/9797889
            codes = re.findall(
                "[-+]?[.]?[\d]+(?:,\d\d\d)*[\.]?\d*(?:[eE][-+]?\d+)?", line)
            # check whether code ONLY contains '0' or '1'
            test_status_code.extend(codes)

    # 生成含有ADB测试命令的shell脚本
    # TODO(Ouyang): 将Shell脚本的存储位置作为参数
    command_to_script(args=[
        'am', 'instrument', '-w', '-r', '-e', 'debug', 'false', '-e', 'filter',
        'com.chi.ssetest.TestcaseFilter', '-e', 'listener',
        'com.chi.ssetest.TestcaseExecutionListener', '-e', 'collector_file',
        'test.log', '-e', 'runner_config',
        base64_encode(runner_conf.SerializeToString()),
        'com.chi.ssetest.test/android.support.test.runner.AndroidJUnitRunner'
    ],
                      script_path='/tmp/test.sh')
    # 将测试脚本push进设备并执行(因为binder传输1MB的限制)
    cmd_code_push = exec_adb_cmd(
        args="adb push E://adb//test.sh /data/local/tmp/", serial=serial_str)
    cmd_code_exec = exec_adb_cmd(args="adb shell sh /data/local/tmp/test.sh",
                                 serial=serial_str,
                                 logger=check_test_result)

    #
    print("status: ", (cmd_code_exec == 0) and \
          len(test_status_code) > 0 and \
          (test_status_code.count('0') + test_status_code.count('1') == len(test_status_code)))
Пример #3
0
def gen2confict_2():
    runner_conf_list = []
    for i in range(2):
        runner_conf = RunnerConfig()
        runner_conf.jobID = 'TJ-1'
        runner_conf.runnerID = generate_id('RUN-A')
        runner_conf.sdkConfig.appKeyIOS = 'VVW0Fno7BEZt1a/y6KLM36uj9qcjw7CAHDwWZKDlWDs='
        runner_conf.sdkConfig.appKeyAndroid = 'J6IPlk5AEU+2/Yi59rfYnsFQtdtOgAo9GAzysx8ciOM='
        runner_conf.sdkConfig.marketPerm.Level = "2"
        runner_conf.sdkConfig.marketPerm.HKPerms.extend(["hk10"])

        if i == 0:
            runner_conf.sdkConfig.serverSites["sh"].CopyFrom(
                Site(ips=["http://114.80.155.134:22016"]))
            runner_conf.sdkConfig.serverSites["sz"].CopyFrom(
                Site(ips=["http://114.80.155.134:22016"]))
            runner_conf.sdkConfig.serverSites["bj"].CopyFrom(
                Site(ips=["http://114.80.155.134:22016"]))
            runner_conf.sdkConfig.serverSites["cf"].CopyFrom(
                Site(ips=["http://114.80.155.134:22016"]))
            runner_conf.sdkConfig.serverSites["nf"].CopyFrom(
                Site(ips=["http://114.80.155.134:22013"]))
            runner_conf.sdkConfig.serverSites["gf"].CopyFrom(
                Site(ips=["http://114.80.155.134:22013"]))
            runner_conf.sdkConfig.serverSites["pb"].CopyFrom(
                Site(ips=["http://114.80.155.134:22016"]))
            runner_conf.sdkConfig.serverSites["hk1"].CopyFrom(
                Site(ips=["http://114.80.155.133:22016"]))
            runner_conf.sdkConfig.serverSites["hk5"].CopyFrom(
                Site(ips=["http://114.80.155.133:22016"]))
            runner_conf.sdkConfig.serverSites["hk10"].CopyFrom(
                Site(ips=["http://114.80.155.133:22016"]))
            runner_conf.sdkConfig.serverSites["hka1"].CopyFrom(
                Site(ips=["http://114.80.155.133:22016"]))
            runner_conf.sdkConfig.serverSites["hkd1"].CopyFrom(
                Site(ips=["http://114.80.155.133:22016"]))
            runner_conf.sdkConfig.serverSites["hkaz"].CopyFrom(
                Site(ips=["http://114.80.155.133:22016"]))
            runner_conf.sdkConfig.serverSites["hkdz"].CopyFrom(
                Site(ips=["http://114.80.155.133:22016"]))
        else:
            runner_conf.sdkConfig.serverSites["sh"].CopyFrom(
                Site(ips=["http://114.80.155.61:22016"]))
            runner_conf.sdkConfig.serverSites["sz"].CopyFrom(
                Site(ips=["http://114.80.155.61:22016"]))
            runner_conf.sdkConfig.serverSites["bj"].CopyFrom(
                Site(ips=["http://114.80.155.61:22016"]))
            runner_conf.sdkConfig.serverSites["cf"].CopyFrom(
                Site(ips=["http://114.80.155.61:22016"]))
            runner_conf.sdkConfig.serverSites["nf"].CopyFrom(
                Site(ips=["http://114.80.155.61:22013"]))
            runner_conf.sdkConfig.serverSites["gf"].CopyFrom(
                Site(ips=["http://114.80.155.61:22013"]))
            runner_conf.sdkConfig.serverSites["pb"].CopyFrom(
                Site(ips=["http://114.80.155.61:22016"]))
            runner_conf.sdkConfig.serverSites["hk1"].CopyFrom(
                Site(ips=["http://114.80.155.133:22016"]))
            runner_conf.sdkConfig.serverSites["hk5"].CopyFrom(
                Site(ips=["http://114.80.155.133:22016"]))
            runner_conf.sdkConfig.serverSites["hk10"].CopyFrom(
                Site(ips=["http://114.80.155.133:22016"]))
            runner_conf.sdkConfig.serverSites["hka1"].CopyFrom(
                Site(ips=["http://114.80.155.133:22016"]))
            runner_conf.sdkConfig.serverSites["hkd1"].CopyFrom(
                Site(ips=["http://114.80.155.133:22016"]))
            runner_conf.sdkConfig.serverSites["hkaz"].CopyFrom(
                Site(ips=["http://114.80.155.133:22016"]))
            runner_conf.sdkConfig.serverSites["hkdz"].CopyFrom(
                Site(ips=["http://114.80.155.133:22016"]))

        case_conf = TestcaseConfig()
        case_conf.testcaseID = 'CHARTSUB_2'
        case_conf.roundIntervalSec = 3
        case_conf.continueWhenFailed = False
        case_conf.paramStrs.extend([
            json.dumps({
                'quoteitem': '600000.sh',
                'type': 'ChartTypeOneDay',
                'begin': '0',
                'end': '100',
                'select': 'time,ddx,ddy,ddz'
            })
        ])

        runner_conf.casesConfig.extend([case_conf])
        runner_conf_list.append(runner_conf)
    return runner_conf_list
Пример #4
0
def gen2confict_1():
    runner_conf_list = []
    for i in range(2):
        runner_conf = RunnerConfig()
        runner_conf.jobID = 'TJ-1'
        runner_conf.runnerID = generate_id('RUN-A')
        runner_conf.sdkConfig.appKeyIOS = 'VVW0Fno7BEZt1a/y6KLM36uj9qcjw7CAHDwWZKDlWDs='
        runner_conf.sdkConfig.appKeyAndroid = 'J6IPlk5AEU+2/Yi59rfYnsFQtdtOgAo9GAzysx8ciOM='
        runner_conf.sdkConfig.marketPerm.Level = "1"
        runner_conf.sdkConfig.marketPerm.HKPerms.extend(["hk10"])

        if i == 0:
            runner_conf.sdkConfig.serverSites["sh"].CopyFrom(
                Site(ips=["http://114.80.155.134:22016"]))
            runner_conf.sdkConfig.serverSites["sz"].CopyFrom(
                Site(ips=["http://114.80.155.134:22016"]))
            runner_conf.sdkConfig.serverSites["bj"].CopyFrom(
                Site(ips=["http://114.80.155.134:22016"]))
            runner_conf.sdkConfig.serverSites["cf"].CopyFrom(
                Site(ips=["http://114.80.155.134:22016"]))
            runner_conf.sdkConfig.serverSites["nf"].CopyFrom(
                Site(ips=["http://114.80.155.134:22013"]))
            runner_conf.sdkConfig.serverSites["gf"].CopyFrom(
                Site(ips=["http://114.80.155.134:22013"]))
            runner_conf.sdkConfig.serverSites["pb"].CopyFrom(
                Site(ips=["http://114.80.155.134:22016"]))
            runner_conf.sdkConfig.serverSites["hk1"].CopyFrom(
                Site(ips=["http://114.80.155.133:22016"]))
            runner_conf.sdkConfig.serverSites["hk5"].CopyFrom(
                Site(ips=["http://114.80.155.133:22016"]))
            runner_conf.sdkConfig.serverSites["hk10"].CopyFrom(
                Site(ips=["http://114.80.155.133:22016"]))
            runner_conf.sdkConfig.serverSites["hka1"].CopyFrom(
                Site(ips=["http://114.80.155.133:22016"]))
            runner_conf.sdkConfig.serverSites["hkd1"].CopyFrom(
                Site(ips=["http://114.80.155.133:22016"]))
            runner_conf.sdkConfig.serverSites["hkaz"].CopyFrom(
                Site(ips=["http://114.80.155.133:22016"]))
            runner_conf.sdkConfig.serverSites["hkdz"].CopyFrom(
                Site(ips=["http://114.80.155.133:22016"]))
        else:
            runner_conf.sdkConfig.serverSites["sh"].CopyFrom(
                Site(ips=["http://114.80.155.134:22016"]))
            runner_conf.sdkConfig.serverSites["sz"].CopyFrom(
                Site(ips=["http://114.80.155.134:22016"]))
            runner_conf.sdkConfig.serverSites["bj"].CopyFrom(
                Site(ips=["http://114.80.155.134:22016"]))
            runner_conf.sdkConfig.serverSites["cf"].CopyFrom(
                Site(ips=["http://114.80.155.134:22016"]))
            runner_conf.sdkConfig.serverSites["nf"].CopyFrom(
                Site(ips=["http://114.80.155.134:22013"]))
            runner_conf.sdkConfig.serverSites["gf"].CopyFrom(
                Site(ips=["http://114.80.155.134:22013"]))
            runner_conf.sdkConfig.serverSites["pb"].CopyFrom(
                Site(ips=["http://114.80.155.134:22016"]))
            runner_conf.sdkConfig.serverSites["hk1"].CopyFrom(
                Site(ips=["http://114.80.155.58:8601"]))
            runner_conf.sdkConfig.serverSites["hk5"].CopyFrom(
                Site(ips=["http://114.80.155.58:8601"]))
            runner_conf.sdkConfig.serverSites["hk10"].CopyFrom(
                Site(ips=["http://114.80.155.58:8601"]))
            runner_conf.sdkConfig.serverSites["hka1"].CopyFrom(
                Site(ips=["http://114.80.155.58:8601"]))
            runner_conf.sdkConfig.serverSites["hkd1"].CopyFrom(
                Site(ips=["http://114.80.155.58:8601"]))
            runner_conf.sdkConfig.serverSites["hkaz"].CopyFrom(
                Site(ips=["http://114.80.155.58:8601"]))
            runner_conf.sdkConfig.serverSites["hkdz"].CopyFrom(
                Site(ips=["http://114.80.155.58:8601"]))

        case_conf = TestcaseConfig()
        case_conf.testcaseID = 'OHLCTEST_1'
        case_conf.roundIntervalSec = 3
        case_conf.continueWhenFailed = False
        case_conf.paramStrs.extend(
            [json.dumps({
                'stk': '00700.hk',
                'type': 'dayk'
            })])
        runner_conf.casesConfig.extend([case_conf])
        runner_conf_list.append(runner_conf)
    return runner_conf_list