Exemplo n.º 1
0
def t18():
    pretty = '%s t18' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t18')

    src = 'git://review.sonyericsson.net/semctools/ave/vcsjob.git'
    dst = w.make_tempdir()

    # fetch the source into the destination
    try:
        vcsjob.fetch(src, dst, 'master', depth='2')
        cmd = [
            'git',
            '--git-dir=%s/.git' % dst, '--work-tree=' + dst, 'rev-list',
            'HEAD', '--count'
        ]
        (s, o, e) = ave.cmd.run(cmd, timeout=100, debug=False)
        if int(o) != 2:
            print(
                'FAIL %s: git clone parameter --depth is ignored in clones.' %
                pretty)
    except Exception, e:
        print('FAIL %s: fetch failed: %s' % (pretty, str(e)))
        return False
Exemplo n.º 2
0
Arquivo: cli.py Projeto: yiu31802/ave
def t17(executable, sources):
    pretty = '%s t17' % __file__
    print(pretty)

    if sources:
        sources = ' -s ' + ','.join(sources)
    else:
        sources = ''

    w = Workspace(uid='vcsjob-cli-t17')

    # pull the tree into a temporary directory
    valid  = 'git://review.sonyericsson.net/semctools/ave/vcsjob'
    target = w.make_tempdir()
    for i in range(5):
        cmd = '%s %s fetch -s %s -d %s -r master' % (
            executable, sources, valid, target
        )
        (s, o, e) = ave.cmd.run(cmd)
        if s != 0:
            print(o)
            print(e)
            print('FAIL %s: wrong return code: %s' % (pretty, s))
            return

    w.delete()
Exemplo n.º 3
0
Arquivo: cli.py Projeto: yiu31802/ave
def t18(executable, sources):
    pretty = '%s t18' % __file__
    print(pretty)

    if sources:
        sources = ' -s ' + ','.join(sources)
    else:
        sources = ''

    w = Workspace(uid='vcsjob-cli-t4')

    sys.path.insert(0, os.getcwd())

    # pull the tree into a temporary directory, check that all remotes are
    # also locals afterwards
    valid  = 'git://review.sonyericsson.net/semctools/ave/vcsjob'
    target = w.make_tempdir()
    cmd = '%s %s fetch -s %s -d %s -r master' % (
        executable, sources, valid, target
    )
    (s, o, e) = ave.cmd.run(cmd)
    if s != 0:
        print('FAIL %s: could not fetch master:\n%s\n%s' % (pretty, o, e))
        return
    (local, remote) = ave.git.list_branches(target)
    if local != remote:
        print(
            'FAIL %s: list of remote and local branches not equal: %s != %s'
            % (pretty, local, remote)
        )

    w.delete()
Exemplo n.º 4
0
Arquivo: cli.py Projeto: yiu31802/ave
def t15(executable, sources):
    pretty = '%s t15' % __file__
    print(pretty)

    if sources:
        sources = ' -s ' + ','.join(sources)
    else:
        sources = ''

    w = Workspace(uid='vcsjob-cli-t15')

    dst = w.make_tempdir()
    (s, o, e) = ave.cmd.run(
        '%s %s fetch --source=git://no.such.host/tree -d %s -r y'
        % (executable, sources, dst)
    )
    if s == 0:
        print('FAIL %s: wrong return code: %s' % (pretty, s))
        return
    if 'failed to clone from git://no.such.host/tree' not in o:
        print('FAIL %s: error not shown:\n%s' % (pretty, o))
        return
    if e:
        print('FAIL %s: stderr set:\n%s' % (pretty, e))
        return
    if os.path.exists(dst):
        print(
            'FAIL %s: failing a clone to an empty dir should cause the dir to '
            'be deleted.'
        )
        return

    w.delete()
Exemplo n.º 5
0
Arquivo: cli.py Projeto: yiu31802/ave
def t7(executable, sources):
    pretty = '%s t7' % __file__
    print(pretty)

    if sources:
        sources = ' -s ' + ','.join(sources)
    else:
        sources = ''

    w = Workspace(uid='vcsjob-cli-t7')

    # create a broken .vcsjob file
    target = w.make_tempdir()
    f = open(os.path.join(target, '.vcsjob'), 'w')
    f.write('{ "executables": [ { "path": "does_not_exist" } ] }')
    f.close()

    # put in a tags filter that doesn't include any tests
    cmd = '%s %s execute --jobs=%s --tags=NONSENSE' % (
        executable, sources, target
    )
    (s, o, e) = ave.cmd.run(cmd)
    if s == 0:
        print('FAIL %s: wrong return code: %s' % (pretty, s))
        return
    if not o.splitlines()[0].startswith('ERROR: no such file: '):
        print('FAIL %s: help not shown:\n%s' % (pretty, o))
        return
    if e:
        print('FAIL %s: stderr set:\n%s' % (pretty, e))
        return

    w.delete()
Exemplo n.º 6
0
def generate_report(pretty, json_file):
    '''
    Generates a report from a static JSON result file
    '''
    # setup workspace
    ws = Workspace('test-files-marionette')
    ws_json_file = os.path.join(ws.make_tempdir(), json_file)
    # copy static json result file to workspace
    shutil.copyfile(os.path.join(TEST_DATA_PATH, json_file), ws_json_file)
    # create a random test name for decibel
    buff = []
    for i in range(10):
        buff.append(random.randint(0, 9))
    name = ''.join(['%d' % i for i in buff])
    # create time stamp for report
    time = datetime.now()
    start_time = time.strftime("%Y-%m-%d %H:%M:%S")
    end_time = (time + timedelta(seconds=1)).strftime("%Y-%m-%d %H:%M:%S")
    # try to generate report.

    # delete workspace.
    ws.delete()
    # check if decibel reported 200 (ok) in response.

    return name, start_time, end_time
Exemplo n.º 7
0
def t3():
    pretty = '%s t3' % __file__
    print(pretty)

    w = Workspace('spool-t3')

    try:
        s = Spool(w.make_tempdir())
    except Exception, e:
        print('FAIL %s: could not create spool: %s' % (pretty, str(e)))
        return
Exemplo n.º 8
0
def t7():
    pretty = '%s t7' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t7')

    # set up source and destination in temporary directories
    src = make_vcsjob_tree(w)
    dst = w.make_tempdir()

    # fetch the source into the destination
    try:
        vcsjob.fetch(src, dst, 'master')
    except Exception, e:
        print('FAIL %s: fetch failed: %s' % (pretty, str(e)))
        return
Exemplo n.º 9
0
def t20():
    pretty = '%s t20' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t20')

    src = 'git://review.sonyericsson.net/platform/prebuilts/misc.git'
    dst = w.make_tempdir()

    # fetch the source into the destination
    try:
        vcsjob.fetch(src, dst, 'oss/tools_r22.2')
    except Exception, e:
        print('FAIL %s: fetch failed: %s' % (pretty, str(e)))
        w.delete()
        return False
Exemplo n.º 10
0
def t9():
    pretty = '%s t9' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t9')

    src = make_vcsjob_tree(w)
    dst = w.make_tempdir()

    # pull the tree into a temporary directory, check that the current branch
    # is "master".
    try:
        result = vcsjob.fetch(src, dst, 'master')
    except Exception, e:
        print('FAIL %s: fetch failed: %s' % (pretty, str(e)))
        return
Exemplo n.º 11
0
def t16():
    pretty = '%s t16' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t16')

    # set up source and destination in temporary directories
    src = make_vcsjob_tree(w)
    dst = w.make_tempdir()

    # fetch the source into the destination
    exc = None
    try:
        result = vcsjob.fetch(src, dst, 'no_such_branch')
    except Exception, e:
        exc = e
Exemplo n.º 12
0
def t14():
    pretty = '%s t14' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t14')

    src = make_vcsjob_tree(w)

    # pull "master"
    dst = w.make_tempdir()

    try:
        result = vcsjob.fetch(src, dst, 'master')
    except Exception, e:
        print('FAIL %s: first fetch failed: %s' % (pretty, str(e)))
        return
Exemplo n.º 13
0
def t15():
    pretty = '%s t15' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t15')

    src = make_vcsjob_tree(w)
    ids = ave.git.rev_list(src)

    # pull "master"
    dst = w.make_tempdir()

    try:
        result = vcsjob.fetch(src, dst, ids[1])
    except Exception, e:
        print('FAIL %s: first fetch failed: %s' % (pretty, str(e)))
        return
Exemplo n.º 14
0
def t13():
    pretty = '%s t13' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t13')

    src = make_vcsjob_tree(w)

    # pull the tree into a temporary directory, check that the current branch
    # is "master".
    dst = w.make_tempdir()

    try:
        vcsjob.fetch(src, dst, 'master')
    except Exception, e:
        print('FAIL %s: could not fetch master: %s' % (pretty, str(e)))
        return
Exemplo n.º 15
0
Arquivo: cli.py Projeto: yiu31802/ave
def t9(executable, sources):
    pretty = '%s t9' % __file__
    print(pretty)

    if sources:
        sources = ' -s ' + ','.join(sources)
    else:
        sources = ''

    w = Workspace(uid='vcsjob-cli-t9')

    # fetch something valid
    valid  = 'git://review.sonyericsson.net/semctools/ave/vcsjob'
    target = w.make_tempdir()
    cmd = '%s %s fetch -s %s -d %s -r master' % (
        executable, sources, valid, target
    )
    (s, o, e) = ave.cmd.run(cmd)
    if s != 0:
        print('FAIL %s: could not fetch:\n%s\n%s' % (pretty, o, e))
        return

    # set some environment variables
    os.environ['FOO'] = 'BAR'
    os.environ['COW'] = 'MOO'

    # filter in the FOO environment variable, but not COW
    cmd = '%s %s execute --jobs=%s -t DEMO -e FOO' % (executable,sources,target)
    (s, o, e) = ave.cmd.run(cmd)

    found_foo = False
    found_cow = False
    for line in o.splitlines():
        if   line == 'FOO=BAR':
            found_foo = True
        elif line == 'COW=MOO':
            found_cow = True
    if not found_foo:
       print('FAIL %s: FOO was not set: %s' % (pretty, o))
       return
    if found_cow:
        print('FAIL %s: COW was set: %s' % (pretty, o))
        return

    w.delete()
Exemplo n.º 16
0
def t8():
    pretty = '%s t8' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t8')

    # set up source and destination in temporary directories
    src = make_vcsjob_tree(w)
    dst = w.make_tempdir()

    # repeatedly fetch the source into the destination
    result = vcsjob.OK
    for i in range(5):
        try:
            result += vcsjob.fetch(src, dst, 'master')
        except Exception, e:
            print('FAIL %s: fetch failed: %s' % (pretty, str(e)))
            return
Exemplo n.º 17
0
def t12():
    pretty = '%s t12' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t12')

    src = make_vcsjob_tree(w)

    # set up destination in a temporary directory that contains some dirt
    dst = w.make_tempdir()
    f = open(os.path.join(dst, 'dirt.txt'), 'w')
    f.write('bar')
    f.close()

    exc = None
    try:
        vcsjob.fetch(src, dst, 'master')
    except Exception, e:
        exc = e
Exemplo n.º 18
0
def t10():
    pretty = '%s t10' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t10')

    # set up source and destination in temporary directories
    src = make_vcsjob_tree(w)

    # "create" a non-existant destination directory by removing a temporary dir
    dst = w.make_tempdir()
    shutil.rmtree(dst)

    # fetch the source into the destination
    try:
        result = vcsjob.fetch(src, dst, 'master')
    except Exception, e:
        print('FAIL %s: fetch failed: %s' % (pretty, str(e)))
        return
Exemplo n.º 19
0
def t11():
    pretty = '%s t11' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t11')

    src = make_vcsjob_tree(w)

    # create a non-directory destination
    dst = os.path.join(w.make_tempdir(), 'some_file')
    with open(dst, 'w') as f:
        f.write('anything')
        f.close()

    # fetch the source into the destination
    exc = None
    try:
        result = vcsjob.fetch(src, dst, 'master')
    except Exception, e:
        exc = e
Exemplo n.º 20
0
Arquivo: cli.py Projeto: yiu31802/ave
def t5(executable, sources):
    pretty = '%s t5' % __file__
    print(pretty)

    if sources:
        sources = ' -s ' + ','.join(sources)
    else:
        sources = ''

    w = Workspace(uid='vcsjob-cli-t5')

    # fetch something valid
    valid  = 'git://review.sonyericsson.net/semctools/ave/vcsjob'
    target = w.make_tempdir()
    cmd = '%s %s fetch -s %s -d %s -r master' % (
        executable, sources, valid, target
    )
    (s, o, e) = ave.cmd.run(cmd)
    if s != 0:
        print('FAIL %s: could not fetch:\n%s\n%s' % (pretty, o, e))
        return

    # break the .vcsjob file
    f = open(os.path.join(target, '.vcsjob'), 'a')
    f.write('not valid syntax in a .vcsjob file')
    f.close()

    # put in a tags filter that doesn't include any tests
    cmd = '%s %s execute --jobs=%s --tags=NONSENSE' %(executable,sources,target)
    (s, o, e) = ave.cmd.run(cmd)
    if s == 0:
        print('FAIL %s: wrong return code: %s' % (pretty, s))
        return
    if not o.split('\n')[0].startswith('ERROR: could not load'):
        print('FAIL %s: help not shown:\n%s' % (pretty, o))
        return
    if e:
        print('FAIL %s: stderr set:\n%s' % (pretty, e))
        return

    w.delete()
Exemplo n.º 21
0
def t4():
    pretty = '%s t4' % __file__
    print(pretty)

    w = Workspace('spool-t4')
    d = w.make_tempdir()
    s = Spool(d)

    # create a file in the temp dir, regiter its file descriptor with the spool
    # and then check that reading from the spool produces the same content as
    # was written to the file
    pr, pw = os.pipe()
    os.write(pw, 'blaha di bla bla')
    os.close(pw)

    try:
        s.register(pr)
    except Exception, e:
        print('FAIL %s: could not register file descriptor: %s' %
              (pretty, str(e)))
        return
Exemplo n.º 22
0
def t17():
    pretty = '%s t17' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t17')

    # set up the source
    src = make_vcsjob_tree(w)

    # set up an empty destination
    dst = w.make_tempdir()

    # first fetch
    vcsjob.fetch(src, dst, 'master')

    # check contents
    with open(os.path.join(dst, 'foo.txt'), 'r') as f:
        contents = f.read()
        if contents != 'bar':
            print('FAIL %s: wrong original content: %s' % (pretty, contents))
            return False

    # create new commit in source
    with open(os.path.join(src, 'foo.txt'), 'w') as f:
        f.write('barfly')
    ave.git.add(src, '.')
    ave.git.commit(src, 'Third commit')

    # second fetch
    vcsjob.fetch(src, dst, 'master')

    # check contents again
    with open(os.path.join(dst, 'foo.txt'), 'r') as f:
        contents = f.read()
        if contents != 'barfly':
            print('FAIL %s: wrong delta content: %s' % (pretty, contents))
            return False

    return True
Exemplo n.º 23
0
Arquivo: cli.py Projeto: yiu31802/ave
def t8(executable, sources):
    pretty = '%s t8' % __file__
    print(pretty)

    if sources:
        sources = ' -s ' + ','.join(sources)
    else:
        sources = ''

    w = Workspace(uid='vcsjob-cli-t8')

    # fetch something valid
    valid  = 'git://review.sonyericsson.net/semctools/ave/vcsjob'
    target = w.make_tempdir()
    cmd = '%s %s fetch -s %s -d %s -r master' % (
        executable, sources, valid, target
    )
    (s, o, e) = ave.cmd.run(cmd)
    if s != 0:
        print('FAIL %s: could not fetch:\n%s\n%s' % (pretty, o, e))
        return

    # remove the executable flag on a job
    os.chmod(os.path.join(target, 'jobs', 'demo_job.sh'), 0644)

    cmd = '%s %s execute --jobs=%s --tags=EXECUTE' % (executable, sources, target)
    (s, o, e) = ave.cmd.run(cmd)
    if s == 0:
        print('FAIL %s: wrong return code: %s' % (pretty, s))
        return
    if not o.splitlines()[0].startswith('ERROR: file is not executable: '):
        print('FAIL %s: help not shown:\n%s' % (pretty, o))
        return
    if e:
        print('FAIL %s: stderr set:\n%s' % (pretty, e))
        return

    w.delete()
Exemplo n.º 24
0
Arquivo: cli.py Projeto: yiu31802/ave
def t4(executable, sources):
    pretty = '%s t4' % __file__
    print(pretty)

    if sources:
        sources = ' -s ' + ','.join(sources)
    else:
        sources = ''

    w = Workspace(uid='vcsjob-cli-t4')

    # fetch something valid
    valid  = 'git://review.sonyericsson.net/semctools/ave/vcsjob'
    target = w.make_tempdir()
    cmd = '%s %s fetch -s %s -d %s -r master' % (
        executable, sources, valid, target
    )
    (s, o, e) = ave.cmd.run(cmd)
    if s != 0:
        print('FAIL %s: could not fetch:\n%s\n%s' % (pretty, o, e))
        return

    # put in a tags filter that doesn't include any tests
    cmd = '%s %s execute --jobs=%s --tags=NONSENSE' % (
        executable, sources, target
    )
    (s, o, e) = ave.cmd.run(cmd)
    if s == 0:
        print('FAIL %s: wrong return code: %s' % (pretty, s))
        return
    if o.splitlines()[0] != 'WARNING: no jobs were executed':
        print('FAIL %s: help not shown:\n%s' % (pretty, o))
        return
    if e:
        print('FAIL %s: stderr set:\n%s' % (pretty, e))
        return

    w.delete()
Exemplo n.º 25
0
def t19():
    pretty = '%s t19' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t19')

    src = 'git://review.sonyericsson.net/platform/prebuilts/misc.git'
    dst = w.make_tempdir()

    # fetch the source into the destination
    try:
        vcsjob.fetch(src, dst, 'oss/tools_r22.2', timeout=1)
        print('FAIL %s: it should be timeout') % pretty
        w.delete()
        return False
    except Exception, e:
        if 'command timed out' == str(e):
            w.delete()
            return True
        else:
            print('FAIL %s: fetch failed: %s' % (pretty, str(e)))
            w.delete()
            return False