示例#1
0
def libcore_profile_data_test():
  # from fd
  name = 'dos.library'
  fd = read_lib_fd(name)
  prof = LibProfileData(fd)
  # get func
  func_name = "Input"
  func = fd.get_func_by_name(func_name)
  idx = func.get_index()
  func_prof = prof.get_func_by_index(idx)
  assert func_prof
  assert func_prof.get_func_id() == idx
  assert prof.get_func_by_name(func_name) == func_prof
  # count
  func_prof.count(1.0)
  func_prof.count(2.0)
  func_prof.count(3.0)
  assert prof.get_total() == (3, 6.0, 2.0)
  assert prof.get_total_str() == \
      "LIB TOTAL                  3 calls    6000.000 ms" \
      "  avg    2000.000 ms"
  prof.remove_empty()
  assert [x for x in prof.get_all_funcs()] == [(func_name, func_prof)]
  # to/from dict
  data_dict = prof.get_data()
  prof2 = LibProfileData.from_dict(data_dict)
  assert prof == prof2
  # get func
  prof2.setup_func_table(fd)
  func_prof2 = prof2.get_func_by_index(idx)
  assert func_prof == func_prof2
示例#2
0
def libcore_profile_data_samples_test():
  # from fd
  name = 'dos.library'
  fd = read_lib_fd(name)
  prof = LibProfileData(fd, True)
  # get func
  func_name = "Input"
  func = fd.get_func_by_name(func_name)
  idx = func.get_index()
  func_prof = prof.get_func_by_index(idx)
  assert func_prof
  assert func_prof.get_func_id() == idx
  # count
  func_prof.count(1.0)
  func_prof.count(2.0)
  func_prof.count(3.0)
  assert prof.get_total() == (3, 6.0, 2.0)
  assert prof.get_total_str() == \
      "LIB TOTAL                  3 calls    6000.000 ms" \
      "  avg    2000.000 ms"
  prof.remove_empty()
  # to/from dict
  data_dict = prof.get_data()
  prof2 = LibProfileData.from_dict(data_dict)
  assert prof == prof2
  # get func
  prof2.setup_func_table(fd)
  func_prof2 = prof2.get_func_by_index(func.get_index())
  assert func_prof == func_prof2
示例#3
0
def libcore_stub_gen_profile_test():
    scan = _create_scan()
    ctx = _create_ctx()
    profile = LibProfileData(scan.get_fd())
    # create stub
    gen = LibStubGen()
    stub = gen.gen_stub(scan, ctx, profile)
    _check_stub(stub)
    # call func
    stub.PrintHello()
    stub.Dummy()
    stub.Swap()
    _check_profile(scan.get_fd(), profile)
示例#4
0
def libcore_stub_gen_fake_profile_test():
    name = 'vamostest.library'
    fd = read_lib_fd(name)
    ctx = _create_ctx()
    profile = LibProfileData(fd)
    # create stub
    gen = LibStubGen()
    stub = gen.gen_fake_stub(name, fd, ctx, profile)
    _check_stub(stub)
    # call func
    stub.PrintHello()
    stub.Dummy()
    stub.Swap()
    _check_profile(fd, profile)
示例#5
0
def libcore_stub_gen_multi_arg(caplog):
    caplog.set_level(logging.INFO)
    scan = _create_scan()
    ctx = _create_ctx()
    log_missing = logging.getLogger('missing')
    log_valid = logging.getLogger('valid')
    profile = LibProfileData(scan.get_fd())
    # create stub
    gen = LibStubGen(log_missing=log_missing, log_valid=log_valid)
    stub = gen.gen_stub(scan, ctx, profile)
    _check_stub(stub)
    # call func
    stub.PrintHello(1, 2, a=3)
    stub.Dummy(3, b='hello')
    stub.Swap('hugo', None, c=3)
    _check_log(caplog)
    _check_profile(scan.get_fd(), profile)
示例#6
0
def libcore_stub_gen_log_profile_test(caplog):
    caplog.set_level(logging.INFO)
    scan = _create_scan()
    ctx = _create_ctx()
    log_missing = logging.getLogger("missing")
    log_valid = logging.getLogger("valid")
    profile = LibProfileData(scan.get_fd())
    # create stub
    gen = LibStubGen(log_missing=log_missing, log_valid=log_valid)
    stub = gen.gen_stub(scan, ctx, profile)
    _check_stub(stub)
    # call func
    stub.PrintHello()
    stub.Dummy()
    stub.Swap()
    _check_log(caplog)
    _check_profile(scan.get_fd(), profile)
示例#7
0
def libcore_stub_gen_fake_log_profile_test(caplog):
    caplog.set_level(logging.INFO)
    name = 'vamostest.library'
    fd = read_lib_fd(name)
    ctx = _create_ctx()
    log_missing = logging.getLogger('missing')
    log_valid = logging.getLogger('valid')
    profile = LibProfileData(fd)
    # create stub
    gen = LibStubGen(log_missing=log_missing, log_valid=log_valid)
    stub = gen.gen_fake_stub(name, fd, ctx, profile)
    _check_stub(stub)
    # call func
    stub.PrintHello()
    stub.Dummy()
    stub.Swap()
    _check_log_fake(caplog)
    _check_profile(fd, profile)
示例#8
0
def libcore_stub_gen_multi_arg_test(caplog):
    caplog.set_level(logging.INFO)
    scan = _create_scan()
    ctx = _create_ctx()
    log_missing = logging.getLogger("missing")
    log_valid = logging.getLogger("valid")
    profile = LibProfileData(scan.get_fd())
    # create stub
    gen = LibStubGen(log_missing=log_missing, log_valid=log_valid)
    stub = gen.gen_stub(scan, ctx, profile)
    _check_stub(stub)
    # call func
    stub.PrintHello(1, 2, a=3)
    stub.Dummy(3, b="hello")
    stub.Swap("hugo", None, c=3)
    stub.PrintString("a", b=4, c=5)
    _check_log(caplog)
    _check_profile(scan.get_fd(), profile)
示例#9
0
def libcore_stub_gen_multi_arg(caplog):
    caplog.set_level(logging.INFO)
    name = 'vamostest.library'
    impl = VamosTestLibrary()
    fd = read_lib_fd(name)
    ctx = _create_ctx()
    log_missing = logging.getLogger('missing')
    log_valid = logging.getLogger('valid')
    profile = LibProfileData(fd)
    # create stub
    gen = LibStubGen(log_missing=log_missing, log_valid=log_valid)
    stub = gen.gen_stub(name, impl, fd, ctx, profile)
    _check_stub(stub)
    # call func
    stub.PrintHello(1, 2, a=3)
    stub.Dummy(3, b='hello')
    stub.Swap('hugo', None, c=3)
    _check_log(caplog)
    _check_profile(fd, profile)
示例#10
0
def _create_stub(do_profile=False, do_log=False):
    name = 'vamostest.library'
    impl = VamosTestLibrary()
    fd = read_lib_fd(name)
    ctx = _create_ctx()
    if do_profile:
        profile = LibProfileData(fd)
    else:
        profile = None
    if do_log:
        log_missing = logging.getLogger('missing')
        log_valid = logging.getLogger('valid')
    else:
        log_missing = None
        log_valid = None
    # create stub
    gen = LibStubGen(log_missing=log_missing, log_valid=log_valid)
    stub = gen.gen_stub(name, impl, fd, ctx, profile)
    return stub
示例#11
0
def _create_stub(do_profile=False, do_log=False):
    name = "vamostest.library"
    impl = VamosTestLibrary()
    fd = read_lib_fd(name)
    scanner = LibImplScanner()
    scan = scanner.scan(name, impl, fd)
    ctx = _create_ctx()
    if do_profile:
        profile = LibProfileData(fd)
    else:
        profile = None
    if do_log:
        log_missing = logging.getLogger("missing")
        log_valid = logging.getLogger("valid")
    else:
        log_missing = None
        log_valid = None
    # create stub
    gen = LibStubGen(log_missing=log_missing, log_valid=log_valid)
    stub = gen.gen_stub(scan, ctx, profile)
    return stub
示例#12
0
def libcore_profile_data_test():
    # from fd
    name = "dos.library"
    fd = read_lib_fd(name)
    prof = LibProfileData(fd)
    # get func
    func_name = "Input"
    func = fd.get_func_by_name(func_name)
    idx = func.get_index()
    func_prof = prof.get_func_by_index(idx)
    assert func_prof
    assert func_prof.get_func_id() == idx
    assert prof.get_func_by_name(func_name) == func_prof
    # count
    func_prof.count(1.0)
    func_prof.count(2.0)
    func_prof.count(3.0)
    assert prof.get_total() == (3, 6.0, 2.0)
    assert (
        prof.get_total_str() == "LIB TOTAL                  3 calls    6000.000 ms"
        "  avg    2000.000 ms"
    )
    prof.remove_empty()
    assert [x for x in prof.get_all_funcs()] == [(func_name, func_prof)]
    # to/from dict
    data_dict = prof.get_data()
    prof2 = LibProfileData.from_dict(data_dict)
    assert prof == prof2
    # get func
    prof2.setup_func_table(fd)
    func_prof2 = prof2.get_func_by_index(idx)
    assert func_prof == func_prof2