Beispiel #1
0
def test():

    properties = {}
    testcases = [] # each testcase in this list is a dictionary

    tss = api.testsuites()

    # Add a test testsuite
    properties['prop1'] = 'foo'
    properties['prop2'] = 'bar'

    ts = api.testsuite(name='My Test Name')
    props = api.propertiesType()

    for key, val in properties.items():
        tp = api.propertyType(key, val)
        props.add_property(tp)
    ts.set_properties(props)

    #ts.name = "My Test Name"
    ts.failures = 1
    ts.errors = 1
    #ts.timestamp = None
    #ts.hostname = None
    ts.tests = 2
    ts.time = 456

    # now add test cases
    tc = api.testcaseType()
    tc.name = 'my test case one'
    tc.classname = 'ltp' # Normally associated with java classes in JUnit
    tc.time = 23
    error = api.errorType(message='Error Message', type_ = 'A', valueOf_ = "This is the test output string ONE")
    tc.error = error
    ts.add_testcase(tc)

    # now add test cases
    tc = api.testcaseType()
    tc.name = 'my test case Two'
    tc.classname = 'ltp' # Normally associated with java classes in JUnit
    tc.time = 98
    error = api.failureType(message='Failure Message', type_ = 'B', valueOf_ = "This is the test output string TWO")
    # TODO WHAT IS type?
    tc.error = error
    ts.add_testcase(tc)

    ts.system_out = 'This is stdout'
    ts.system_err = 'This is stderr'

    tss.add_testsuite(ts)
    tss.export(sys.stdout, 0)
Beispiel #2
0
def main(basedir, resfiles):
    result_lists = []
    name_width = 40

    try:
        hn = open(os.path.join(basedir, "sysinfo/hostname")).read()
    except:
        hn = "localhost"

    testsuites = api.testsuites()
    ts = api.testsuite(name="Autotest tests")
    properties = api.propertiesType()
    ts.hostname = hn
    ts.timestamp = date.isoformat(date.today())

    # collect some existing report file contents as properties
    if False:  # Not sure, the properties don't seem to do anything for us right now.
        to_collect = [
            "cmdline", "cpuinfo", "df", "gcc_--version",
            "installed_packages", "interrupts",
            "ld_--version", "lspci_-vvn", "meminfo",
            "modules", "mount", "partitions",
            "proc_mounts", "slabinfo", "uname",
            "uptime", "version"
        ]

        for propitem in to_collect:
            try:
                rawcontents = open(os.path.join(basedir, "sysinfo", propitem)).read()
                # the xml processor can only handle ascii
                contents = ''.join([x for x in rawcontents if ord(x) < 128])
            except:
                contents = "Unable to open the file %s" % os.path.join(basedir, "sysinfo", propitem)
            tp = api.propertyType(propitem, contents)
            properties.add_property(tp)

    f = os.path.join(basedir, "status")
    raw_text = open(f).read()

    text = text_clean(raw_text)
    raw_text = None

    results = parse_results(text)
    name_width = max([name_width] + [len(r[0]) for r in results])

    testcases = []
    tests = 0
    failures = 0
    errors = 0
    time = 0
    if len(results):
        for r in results:

            # handle test case xml generation
            tname = r[0]
            # first, see if this is the overall test result
            if tname.strip() == '----':
                testsuite_result = r[1]
                testsuite_time = r[2]
                continue

            # otherwise, it's a test case
            tc = api.testcaseType()
            if '.' in tname:
                (suite, name) = tname.split('.', 1)
            else:
                suite = tname
                name = tname
            tc.name = name
            tc.classname = 'autotest.%s' % suite
            tc.time = int(r[2])
            tests = tests + 1
            fid = os.path.join(basedir, tname, 'debug', '%s.DEBUG' % tname)
            if not os.path.exists(fid):
                # tag also encoded with '.' delimeter, attempt with file
                # based on name.tag if suite/name parsing file doesn't exist
                fid = os.path.join(basedir, tname, 'debug',
                                   '%s.DEBUG' % os.path.basename(r[0]))
            debug_contents = file_load(fid)
            if not debug_contents:
                contents = 'Could not find debug file %s' % fid
            else:
                contents = text_clean(debug_contents)
            if r[1] == 'GOOD':
                # success, we append the testcase without an error or fail
                pass
            # Count NA as fails, disable them if you don't want them
            elif r[1] == 'TEST_NA':
                failures = failures + 1
                tcfailure = api.failureType(message='Test %s is Not Applicable: %s' % (tname, r[3]), type_='Failure', valueOf_="\n<![CDATA[\n%s\n]]>\n" % contents)
                tc.failure = tcfailure
            elif r[1] == 'ERROR':
                failures = failures + 1
                tcfailure = api.failureType(message='Test %s has failed' % tname, type_='Failure', valueOf_="\n<![CDATA[\n%s\n]]>\n" % contents)
                tc.failure = tcfailure
            else:
                # we don't know what this is
                errors = errors + 1
                tcerror = api.errorType(message='Unexpected value for result in test result for test %s' % tname, type_='Logparse', valueOf_="result=%s" % r[1])
                tc.error = tcerror
            testcases.append(tc)
    else:
        # no results to be found
        tc = api.testcaseType()
        tc.name = 'Logfilter'
        tc.classname = 'logfilter'
        tc.time = 0
        tcerror = api.errorType(message='LOGFILTER: No test cases found while parsing log', type_='Logparse', valueOf_='nothing to show')
        tc.error = tcerror
        testcases.append(tc)

    # if testsuite_result == "GOOD":
    #    if failures or error:
    #        raise RuntimeError("LOGFILTER internal error - Overall test results parsed as good, but test errors found")
    for tc in testcases:
        ts.add_testcase(tc)
    ts.failures = failures
    ts.errors = errors
    ts.time = testsuite_time
    ts.tests = tests
    ts.set_properties(properties)
    # TODO find and include stdout and stderr
    testsuites.add_testsuite(ts)
    testsuites.export(stdout, 0)