Пример #1
0
def runtest():
    """check cross-generated output against native reference files"""

    # object code
    for infile, opts, reffile in (["gaops.gpl", [], "GAOPS-Q"
                                   ], ["gainst.gpl", [], "GAINST-Q"], [
                                       "gabranch.gpl",
                                       [],
                                       "GABRANCH-Q",
                                   ], ["gamove.gpl", [], "GAMOVE-Q"
                                       ], ["gafmt.gpl", [], "GAFMT-Q"],
                                  ["gadirs.gpl", [],
                                   "GADIRS-Q"], ["gacopy.gpl", [], "GACOPY-Q"],
                                  ["gaexts.gpl", [],
                                   "GAEXTS-Q"], ["gapass.gpl", [],
                                                 "GAPASS-Q"]):
        source = os.path.join(Dirs.gplsources, infile)
        xdm(Disks.gplsrcs, "-e", reffile, "-o", Files.reference)
        xga(*[source] + opts + ["-w", "-o", Files.output])
        check_gbc_files_eq(infile, Files.output, Files.reference)

    # cart generation
    for name in ["gacart", "gahello"]:
        source = os.path.join(Dirs.gplsources, name + ".gpl")
        ref = os.path.join(Dirs.refs, name + ".rpk")
        xga(source, "-c", "-o", Files.output)
        check_files_eq("GPL cart",
                       Files.output,
                       ref,
                       "P",
                       mask=((0x8, 0x1e), (0x188, 0xfff)))

    # cleanup
    os.remove(Files.output)
    os.remove(Files.reference)
Пример #2
0
def runtest():
    """check cross-generated output against native reference files"""

    # object code
    for infile, opts, reffile in (['gaops.gpl', [], 'GAOPS-Q'], [
            'gainst.gpl', [], 'GAINST-Q'
    ], ['gabranch.gpl', [],
            'GABRANCH-Q'], ['gamove.gpl', [],
                            'GAMOVE-Q'], ['gafmt.gpl', [], 'GAFMT-Q'],
                                  ['gadirs.gpl', [],
                                   'GADIRS-Q'], ['gacopy.gpl', [], 'GACOPY-Q'],
                                  ['gaexts.gpl', [],
                                   'GAEXTS-Q'], ['gapass.gpl', [],
                                                 'GAPASS-Q']):
        source = os.path.join(Dirs.gplsources, infile)
        xdm(Disks.gplsrcs, '-e', reffile, '-o', Files.reference)
        xga(*[source] + opts + ['-q', '-o', Files.output])
        check_gbc_files_eq(infile, Files.output, Files.reference)

    # cart generation
    source = os.path.join(Dirs.gplsources, 'gahello.gpl')
    ref = os.path.join(Dirs.refs, 'gahello.rpk')
    xga(source, '-c', '-o', Files.output)
    with ZipFile(Files.output, 'r') as zout, ZipFile(ref, 'r') as zref:
        outdata = zout.read('GAHELLO.bin')
        refdata = zref.read('GAHELLO.bin')
        if outdata != refdata:
            error('GPL cart', 'Main file mismatch')
        if 'layout.xml' not in zout.namelist(
        ) or 'meta-inf.xml' not in zout.namelist():
            error('GPL cart', 'Missing layout or meta-inf files in RPK')

    # cleanup
    os.remove(Files.output)
    os.remove(Files.reference)
Пример #3
0
def runtest():
    """run regression tests"""

    # check for errors
    source = os.path.join(Dirs.gplsources, 'gaerrs.gpl')
    with open(Files.error, 'w') as ferr:
        xga(source, '-o', Files.output, stderr=ferr, rc=1)
    act_errors = read_stderr(Files.error, include_warnings=False)
    exp_errors = get_source_markers(source, tag=r';ERROR')
    check_errors(exp_errors, act_errors)

    # error messages in pass 0 and 1
    for s in ['gaerrs0.gpl', 'gaerrs1.gpl']:
        source = os.path.join(Dirs.gplsources, s)
        with open(Files.error, 'w') as ferr:
            xga(source, '-o', Files.output, stderr=ferr, rc=1)
        act_errors = read_stderr(Files.error, include_warnings=False)
        exp_errors = get_source_markers(source, tag=r'\* ERROR')
        check_errors(exp_errors, act_errors)

    # open .if-.endif or .defm-.endm
    source = os.path.join(Dirs.gplsources, 'gaopenif.gpl')
    with open(Files.error, 'w') as ferr:
        xga(source, '-o', Files.output, stderr=ferr, rc=1)
    with open(Files.error, 'r') as fin:
        msgs = ' '.join(fin.readlines())
    if 'Missing .endif' not in msgs:
        error('open', 'Missing error for open .if/.endif')

    source = os.path.join(Dirs.gplsources, 'gaopenmac.gpl')
    with open(Files.error, 'w') as ferr:
        xga(source, '-o', Files.output, stderr=ferr, rc=1)
    with open(Files.error, 'r') as fin:
        msgs = ' '.join(fin.readlines())
    if 'Missing .endm' not in msgs:
        error('open', 'Missing error for open .defm/.endm')

    # warnings
    source = os.path.join(Dirs.gplsources, 'gawarn.gpl')
    with open(Files.error, 'w') as ferr:
        xga(source, '-o', Files.output, stderr=ferr, rc=0)
    act_errors = read_stderr(Files.error, include_warnings=True)
    exp_errors = get_source_markers(source, tag=r';WARN')
    check_errors(exp_errors, act_errors)

    # cleanup
    os.remove(Files.output)
    os.remove(Files.error)
Пример #4
0
def runtest():
    """run regression tests"""

    # check for errors
    source = os.path.join(Dirs.gplsources, "gaerrs.gpl")
    with open(Files.error, "w") as ferr:
        xga(source, "-o", Files.output, stderr=ferr, rc=1)
    act_errors = read_stderr(Files.error, include_warnings=False)
    exp_errors = get_source_markers(source, tag=r";ERROR")
    check_errors(exp_errors, act_errors)

    # error messages in pass 0 and 1
    for s in ["gaerrs0.gpl", "gaerrs1.gpl"]:
        source = os.path.join(Dirs.gplsources, s)
        with open(Files.error, "w") as ferr:
            xga(source, "-o", Files.output, stderr=ferr, rc=1)
        act_errors = read_stderr(Files.error, include_warnings=False)
        exp_errors = get_source_markers(source, tag=r"\* ERROR")
        check_errors(exp_errors, act_errors)

    # open .if-.endif or .defm-.endm
    source = os.path.join(Dirs.gplsources, "gaopenif.gpl")
    with open(Files.error, "w") as ferr:
        xga(source, "-o", Files.output, stderr=ferr, rc=1)
    with open(Files.error, "r") as fin:
        msgs = " ".join(fin.readlines())
    if "Missing .endif" not in msgs:
        error("open", "Missing error for open .if/.endif")

    source = os.path.join(Dirs.gplsources, "gaopenmac.gpl")
    with open(Files.error, "w") as ferr:
        xga(source, "-o", Files.output, stderr=ferr, rc=1)
    with open(Files.error, "r") as fin:
        msgs = " ".join(fin.readlines())
    if "Missing .endm" not in msgs:
        error("open", "Missing error for open .defm/.endm")

    # warnings
    source = os.path.join(Dirs.gplsources, "gawarn.gpl")
    with open(Files.error, "w") as ferr:
        xga(source, "-o", Files.output, stderr=ferr, rc=0)
    act_errors = read_stderr(Files.error, include_warnings=True)
    exp_errors = get_source_markers(source, tag=r";WARN")
    check_errors(exp_errors, act_errors)

    # cleanup
    os.remove(Files.output)
    os.remove(Files.error)
Пример #5
0
def runtest():
    """check cross-generated output against native reference files"""

    # object code
    for infile, opts, reffile in [
            ("gaops.gpl", [], "GAOPS-Q"),
            ("gainst.gpl", [], "GAINST-Q"),
            ("gabranch.gpl", [], "GABRANCH-Q", ),
            ("gamove.gpl", [], "GAMOVE-Q"),
            ("gafmt.gpl", ["-s", "rag"], "GAFMT-Q"),
            ("gadirs.gpl", [], "GADIRS-Q"),
            ("gacopy.gpl", [], "GACOPY-Q"),
            ("gaexts.gpl", [], "GAEXTS-Q"),
            ("gapass.gpl", [], "GAPASS-Q")
            ]:
        source = os.path.join(Dirs.gplsources, infile)
        xdm(Disks.gplsrcs, "-e", reffile, "-o", Files.reference)
        xga(*[source] + opts + ["-o", Files.output])
        checkGbcFilesEq(infile, Files.output, Files.reference)

    # cart generation
    for name in ["gacart", "gahello"]:
        source = os.path.join(Dirs.gplsources, name + ".gpl")
        ref = os.path.join(Dirs.refs, name + ".rpk")
        xga(source, "-c", "-o", Files.output)
        checkFilesEq("GPL cart", Files.output, ref, "P",
                     mask=((0x8, 0x1e), (0x188, 0xfff)))

    # extensions
    source = os.path.join(Dirs.gplsources, "gaxprep.gpl")
    xga(source, "-D", "isdef=2", "-o", Files.output)
    xdm(Disks.gplsrcs, "-e", "GAXPREP-Q", "-o", Files.reference)
    checkGbcFilesEq(source, Files.output, Files.reference)

    # error messages
    for s in ["gaerrs0.gpl", "gaerrs1.gpl"]:
        source = os.path.join(Dirs.gplsources, s)
        with open(source, "r") as fin:
            expect = [lino + 1 for lino, line in enumerate(fin)
                      if "* ERROR" in line]
        with open(Files.error, "w") as ferr:
            xga(source, "-o", Files.output, stderr=ferr, rc=1)
        with open(Files.error, "r") as fin:
            try:
                found = [int(line[:4]) for line in fin if line[0] != "*"]
            except ValueError:
                error("Error messages", "Unexpected error message")
        if found != expect:
            error("Error messages",
                  "Error mismatch, extra: " +
                  str([x for x in found if x not in expect]) +
                  " missing: " +
                  str([x for x in expect if x not in found]))

    # cleanup
    os.remove(Files.output)
    os.remove(Files.reference)
    os.remove(Files.error)
Пример #6
0
def runtest():
    """check disassembly"""

    # source with sym file
    source = os.path.join(Dirs.gplsources, "dgsource.gpl")
    xga(source, "-o", Files.reference, "-E", Files.input)
    xdg(Files.reference, "-a", "2000", "-f", ">2000", "-p", "-S", Files.input,
        "-o", Files.output)
    check_source(Files.output, source)

    # from/to
    source = os.path.join(Dirs.gplsources, "dgexclude.gpl")
    xga(source, "-o", Files.reference)
    xdg(Files.reference, "-a", "0", "-f", "0x3", "-t", "0xa", "-p", "-o",
        Files.output)
    byte_count = count_bytes(Files.output)
    if byte_count != 13:
        error("from/to", "BYTE count mismatch: %d" % byte_count)

    # exclude
    source = os.path.join(Dirs.gplsources, "dgexclude.gpl")
    xga(source, "-o", Files.reference)
    xdg(Files.reference, "-a", "0", "-r", "0x0", "-e", "2-4", "10-14", "-p",
        "-o", Files.output)
    byte_count = count_bytes(Files.output)
    if byte_count != 6:
        error("exclude", "BYTE count mismatch: %d" % byte_count)

    # syntax
    source = os.path.join(Dirs.gplsources, "dgsyntax.gpl")
    xga(source, "-o", Files.reference)
    for syntax in "rag", "ryte", "mizapf":
        xdg(Files.reference, "-a", "0", "-f", "0", "-y", syntax, "-o",
            Files.output)
        check_syntax(Files.output, syntax)

    # syntax MOVE
    source = os.path.join(Dirs.gplsources, "dgsynmove.gpl")
    xga(*[source] + ["-o", Files.reference])
    for syntax in "xdt99", "rag", "ryte", "mizapf":
        xdg(Files.reference, "-a", "0", "-f", "0", "-y", syntax, "-o",
            Files.output)
        check_move(Files.output, syntax)

    # "start"
    source = os.path.join(Dirs.gplsources, "dgstart.gpl")
    xga(source, "-o", Files.reference)
    xdg(Files.reference, "-a", "6000", "-f", "start", "-o", Files.output)
    memn_count_1 = sum(count_mnemonics(Files.output, offset=9).values())
    if memn_count_1 != 6:
        error("start", "mnemonic count mismatch: %d/6" % memn_count_1)
    xdg(Files.reference, "-a", "6000", "-r", "start", "-o", Files.output)
    mnem_count_2 = sum(count_mnemonics(Files.output, offset=9).values())
    if mnem_count_2 != 6:
        error("start", "mnemonic count mismatch: %d/6" % mnem_count_2)

    # origins
    source = os.path.join(Dirs.gplsources, "dgjumps.gpl")
    xga(source, "-o", Files.reference)
    xdg(Files.reference, "-a", "0", "-r", "0", "-o", Files.output)
    check_origins(Files.output, {
        0x0: [0x12, 0x25],
        0x1a: [0xd, 0x20],
        0x28: [0x8, 0x22]
    })

    # strings
    source = os.path.join(Dirs.gplsources, "dgtext.gpl")
    xga(source, "-o", Files.reference)
    xdg(Files.reference, "-a", "8000", "-r", "8000", "-n", "-p", "-o",
        Files.output)
    mnems = count_mnemonics(Files.output)
    if mnems.get("byte") != 8:
        error("strings", "BYTE count mismatch: %d" % bytes)
    if mnems.get("text") != 2:
        error("strings", "TEXT count mismatch: %d" % bytes)

    # force
    source = os.path.join(Dirs.gplsources, "dgforce.gpl")
    xga(source, "-o", Files.reference)
    xdg(Files.reference, "-a", "a000", "-r", "a000", "-o", Files.output)
    n = sum(count_mnemonics(Files.output, offset=9).values())
    if n != 7:
        error("force", "Mnemonics count mismatch: %d != 7" % n)
    xdg(Files.reference, "-a", "a000", "-r", "a000", "-F", "-o", Files.output)
    nf = sum(count_mnemonics(Files.output, offset=9).values())
    if nf != 8:
        error("force", "Mnemonics count mismatch: %d != 8" % nf)

    # skip -k
    source = os.path.join(Dirs.gplsources, "dgsource.gpl")
    xga(source, "-o", Files.output, "-E", Files.input)
    with open(Files.output, "rb") as fin, open(Files.reference, "wb") as fout:
        data = fin.read()
        fout.write("\x99" * 0x999)
        fout.write(data)
    xdg(Files.reference, "-a", "2000", "-f", ">2000", "-k", "999", "-p", "-S",
        Files.input, "-o", Files.output)
    check_source(Files.output, source)

    # strict -s
    source = os.path.join(Dirs.gplsources, "dgsource.gpl")
    xga(source, "-o", Files.reference, "-E", Files.input)
    xdg(Files.reference, "-a", "2000", "-f", ">2000", "-p", "-S", Files.input,
        "-o", Files.output)
    with open(Files.output, "r") as fin:
        for line in fin.readlines():
            line = re.sub(r"'[^']*'", "", line)  # escape literal
            if line != line.lower():
                error("strict",
                      "Source file not entirely lower case: %s" % line)

    xdg(Files.reference, "-a", "2000", "-f", ">2000", "-p", "-s", "-S",
        Files.input, "-o", Files.output)
    with open(Files.output, "r") as fin:
        for line in fin.readlines():
            if line != line.upper():
                error("strict",
                      "Source file not entirely upper case: %s" % line)

    # concise -c
    source = os.path.join(Dirs.gplsources, "dgconcis.gpl")
    xga(source, "-o", Files.reference)
    xdg(Files.reference, "-a", "4000", "-r", "4000", "-s", "-c", "-o",
        Files.output)
    check_ellipsis(Files.output, skip=2)
    # no condensed output when disassembling as program (-p)

    # layout
    source = os.path.join(Dirs.gplsources, "dgstart.gpl")
    xga(source, "-o", Files.reference)
    xdg(Files.reference, "-a", "6000", "-f", "start", "-o", Files.output)
    check_indent(Files.output, 2)
    xdg(Files.reference, "-a", "6000", "-f", "start", "-p", "-o", Files.output)
    check_indent(Files.output, 1)

    # cleanup
    os.remove(Files.input)
    os.remove(Files.output)
    os.remove(Files.reference)
Пример #7
0
def runtest():
    """check cross-generated output against native reference files"""

    # input and output files
    source = os.path.join(Dirs.gplsources, "gacart.gpl")
    with open(Files.output, "wb") as f:
        xga(source, "-o", "-", stdout=f)
    xga(source, "-o", Files.reference)
    check_files_eq("stdout", Files.output, Files.reference, "P")

    with open(Files.output, "wb") as f:
        xga(source, "-i", "-G", ">6000", "-A", ">0030", "-o", "-", stdout=f)
    xga(source, "-i", "-G", ">6000", "-A", ">0030", "-o", Files.reference)
    check_files_eq("stdout", Files.output, Files.reference, "P")

    with open(Files.output, "w") as f:
        xga(source, "-o", Files.input, "-L", "-", stdout=f)
    xga(source, "-o", Files.input, "-L", Files.reference)
    check_text_eq(Files.output, Files.reference)

    source = os.path.join(Dirs.gplsources, "nonexisting")
    with open(Files.error, "w") as ferr:
        xga(source, "-o", Files.output, stderr=ferr, rc=1)
    with open(Files.error, "r") as ferr:
        errs = ferr.readlines()
    if len(errs) != 1 or errs[0].strip() != "Error: File not found":
        error("File error", "Incorrect file error message")

    # text -t
    source = os.path.join(Dirs.gplsources, "gacart.gpl")
    xga(source, "-o", Files.reference)
    xga(source, "-t", "c4r", "-o", Files.output)
    check_bin_text_equal_c(Files.output, Files.reference)

    xga(source, "-t", "b4", "-o", Files.output)
    check_bin_text_equal_basic(Files.output, Files.reference)

    # list and symbols -L
    source = os.path.join(Dirs.gplsources, "gahello.gpl")
    xga(source, "-o", Files.error, "-L", Files.input)
    xga(source, "-o", Files.reference)
    with open(Files.input, "r") as flist, open(Files.error, "w") as fout:
        listfile = [
            line[16:] for line in flist.readlines() if line[0:4] != "****"
        ][1:]
        fout.writelines(listfile)
    xga(Files.error, "-o", Files.output)
    check_binary_files_eq("list", Files.output, Files.reference)  # checks code
    check_list_addr_data(Files.input, Files.reference,
                         0x0000)  # checks addr and data

    # cleanup
    os.remove(Files.input)
    os.remove(Files.output)
    os.remove(Files.reference)
    os.remove(Files.error)
Пример #8
0
def runtest():
    """check disassembly"""

    # source with sym file
    source = os.path.join(Dirs.gplsources, 'dgsource.gpl')
    xga(source, '-o', Files.reference, '-E', Files.input)
    xdg(Files.reference, '-a', '2000', '-f', '>2000', '-p', '-S', Files.input,
        '-o', Files.output)
    check_source(Files.output, source)

    # from/to
    source = os.path.join(Dirs.gplsources, 'dgexclude.gpl')
    xga(source, '-o', Files.reference)
    xdg(Files.reference, '-a', '0', '-f', '0x3', '-t', '0xa', '-p', '-o',
        Files.output)
    byte_count = count_bytes(Files.output)
    if byte_count != 13:
        error('from/to', 'BYTE count mismatch: %d' % byte_count)

    # exclude
    source = os.path.join(Dirs.gplsources, 'dgexclude.gpl')
    xga(source, '-o', Files.reference)
    xdg(Files.reference, '-a', '0', '-r', '0x0', '-e', '2-4', '10-14', '-p',
        '-o', Files.output)
    byte_count = count_bytes(Files.output)
    if byte_count != 6:
        error('exclude', 'BYTE count mismatch: %d' % byte_count)

    # syntax
    source = os.path.join(Dirs.gplsources, 'dgsyntax.gpl')
    xga(source, '-o', Files.reference)
    for syntax in 'rag', 'ryte', 'mizapf':
        xdg(Files.reference, '-a', '0', '-f', '0', '-y', syntax, '-o',
            Files.output)
        check_syntax(Files.output, syntax)

    # syntax MOVE
    source = os.path.join(Dirs.gplsources, 'dgsynmove.gpl')
    xga(*[source] + ['-o', Files.reference])
    for syntax in 'xdt99', 'rag', 'ryte', 'mizapf':
        xdg(Files.reference, '-a', '0', '-f', '0', '-y', syntax, '-o',
            Files.output)
        check_move(Files.output, syntax)

    # 'start'
    source = os.path.join(Dirs.gplsources, 'dgstart.gpl')
    xga(source, '-o', Files.reference)
    xdg(Files.reference, '-a', '6000', '-f', 'start', '-o', Files.output)
    memn_count_1 = sum(count_mnemonics(Files.output, offset=9).values())
    if memn_count_1 != 6:
        error('start', 'mnemonic count mismatch: %d/6' % memn_count_1)
    xdg(Files.reference, '-a', '6000', '-r', 'start', '-o', Files.output)
    mnem_count_2 = sum(count_mnemonics(Files.output, offset=9).values())
    if mnem_count_2 != 6:
        error('start', 'mnemonic count mismatch: %d/6' % mnem_count_2)

    # origins
    source = os.path.join(Dirs.gplsources, 'dgjumps.gpl')
    xga(source, '-o', Files.reference)
    xdg(Files.reference, '-a', '0', '-r', '0', '-o', Files.output)
    check_origins(Files.output, {
        0x0: [0x12, 0x25],
        0x1a: [0xd, 0x20],
        0x28: [0x8, 0x22]
    })

    # strings
    source = os.path.join(Dirs.gplsources, 'dgtext.gpl')
    xga(source, '-o', Files.reference)
    xdg(Files.reference, '-a', '8000', '-r', '8000', '-n', '-p', '-o',
        Files.output)
    mnems = count_mnemonics(Files.output)
    if mnems.get('byte') != 8:
        error('strings', 'BYTE count mismatch: %d' % bytes)
    if mnems.get('text') != 2:
        error('strings', 'TEXT count mismatch: %d' % bytes)

    # force
    source = os.path.join(Dirs.gplsources, 'dgforce.gpl')
    xga(source, '-o', Files.reference)
    xdg(Files.reference, '-a', 'a000', '-r', 'a000', '-o', Files.output)
    n = sum(count_mnemonics(Files.output, offset=9).values())
    if n != 7:
        error('force', 'Mnemonics count mismatch: %d != 7' % n)
    xdg(Files.reference, '-a', 'a000', '-r', 'a000', '-F', '-o', Files.output)
    nf = sum(count_mnemonics(Files.output, offset=9).values())
    if nf != 8:
        error('force', 'Mnemonics count mismatch: %d != 8' % nf)

    # skip -k
    source = os.path.join(Dirs.gplsources, 'dgsource.gpl')
    xga(source, '-o', Files.output, '-E', Files.input)
    with open(Files.output, 'rb') as fin, open(Files.reference, 'wb') as fout:
        data = fin.read()
        fout.write(b'\x99' * 0x999)
        fout.write(data)
    xdg(Files.reference, '-a', '2000', '-f', '>2000', '-k', '999', '-p', '-S',
        Files.input, '-o', Files.output)
    check_source(Files.output, source)

    # strict -s
    source = os.path.join(Dirs.gplsources, 'dgsource.gpl')
    xga(source, '-o', Files.reference, '-E', Files.input)
    xdg(Files.reference, '-a', '2000', '-f', '>2000', '-p', '-S', Files.input,
        '-o', Files.output)
    with open(Files.output, 'r') as fin:
        for line in fin.readlines():
            line = re.sub(r"'[^']*'", '', line)  # escape literal
            if line != line.lower():
                error('strict',
                      'Source file not entirely lower case: %s' % line)

    xdg(Files.reference, '-a', '2000', '-f', '>2000', '-p', '-s', '-S',
        Files.input, '-o', Files.output)
    with open(Files.output, 'r') as fin:
        for line in fin.readlines():
            if line != line.upper():
                error('strict',
                      'Source file not entirely upper case: %s' % line)

    # concise -c
    source = os.path.join(Dirs.gplsources, 'dgconcis.gpl')
    xga(source, '-o', Files.reference)
    xdg(Files.reference, '-a', '4000', '-r', '4000', '-s', '-c', '-o',
        Files.output)
    check_ellipsis(Files.output, skip=2)
    # no condensed output when disassembling as program (-p)

    # layout
    source = os.path.join(Dirs.gplsources, 'dgstart.gpl')
    xga(source, '-o', Files.reference)
    xdg(Files.reference, '-a', '6000', '-f', 'start', '-o', Files.output)
    check_indent(Files.output, 2)
    xdg(Files.reference, '-a', '6000', '-f', 'start', '-p', '-o', Files.output)
    check_indent(Files.output, 1)

    # cleanup
    os.remove(Files.input)
    os.remove(Files.output)
    os.remove(Files.reference)
Пример #9
0
def runtest():
    """check cross-generated output against native reference files"""

    # run disassembler
    for srcfile, dopts, aopts in [
        ('gaops.gpl', ['-a', '0', '-r', '6', '17a'], []),
        ('gainst.gpl',
         ['-a', '0', '-r', '6', 'a2', 'a3', 'aa', 'ab', 'ac', 'b2', 'b4'], []),
        ('gabranch.gpl', ['-a', '0', '-f', '5'], []),
        ('gamove.gpl', ['-a', '0', '-f', '6'], []),
        ('gafmt.gpl', ['-a', '0', '-f', '5', '-y', 'rag'], []),
        ('gacopy.gpl', ['-a', '>2000', '-r', '2000'], []),
        ('gaexts.gpl', ['-a', '0', '-r', '0x1e'], []),
        ('gapass.gpl', ['-a', '0x6030', '-r', '6030'], [])
    ]:
        source = os.path.join(Dirs.gplsources, srcfile)
        xga(*[source] + aopts + ['-o', Files.reference])
        xdg(*[Files.reference] + dopts + ['-p', '-o', Files.input])
        xga(*[Files.input] + aopts + ['-o', Files.output])
        check_files_eq(srcfile, Files.output, Files.reference, 'PROGRAM')
        check_bytes(Files.input, source)

    # top-down disassembler
    for srcfile, dopts, aopts in [
        ('gaops.gpl', ['-a', '0', '-f', '6'], []),
        ('gainst.gpl', ['-a', '0', '-f', '6'], []),
        ('gabranch.gpl', ['-a', '0', '-f', '5'], []),
        ('gamove.gpl', ['-a', '0', '-f', '6'], []),
        ('gafmt.gpl', ['-a', '0', '-f', '5', '-y', 'rag'], []),
        ('gadirs.gpl', ['-a', '0', '-f', '0'], []),
        ('gacopy.gpl', ['-a', '>2000', '-f', '>2000'], []),
        ('gaexts.gpl', ['-a', '0', '-f', '0x1e'], []),
        ('gapass.gpl', ['-a', '0x6030', '-f', '>6030'], [])
    ]:
        source = os.path.join(Dirs.gplsources, srcfile)
        xga(*[source] + aopts + ['-o', Files.reference])
        xdg(*[Files.reference] + dopts + ['-p', '-o', Files.input])
        xga(*[Files.input] + aopts + ['-o', Files.output])
        check_files_eq(srcfile, Files.output, Files.reference, 'PROGRAM')
        xdg(*[Files.reference] + dopts +
            ['-o', Files.output
             ])  # -p would introduce BYTEs where not disassembled
        if count_bytes(Files.output) > 0:
            error('BYTE', 'Unwanted BYTE directives in result')

    # disassembler run
    for srcfile in ['dgruns.gpl']:
        source = os.path.join(Dirs.gplsources, srcfile)
        xga(*[source] + ['-o', Files.reference])
        xdg(*[Files.reference] +
            ['-a', '0', '-r', '0x0', '-p', '-o', Files.input])
        xga(*[Files.input] + ['-o', Files.output])
        check_files_eq(srcfile, Files.output, Files.reference, 'PROGRAM')
        check_bytes(Files.input, source)

    # disassemble blob
    binary = os.path.join(Dirs.refs, 'blobg.bin')
    #TODO: universal character escape \x..
    #xdg(binary, '-a', '0', '-f', 'start', '-p', '-o', Files.input)
    #xga(Files.input, '-o', Files.output)
    #check_files_eq('blobg', Files.output, binary, 'PROGRAM')
    #xdg(binary, '-a', '0', '-r', 'start', '-p', '-o', Files.input)
    #xga(Files.input, '-o', Files.output)
    #check_files_eq('blobg-run', Files.output, binary, 'PROGRAM')

    # disassemble random
    randrange = [n for n in range(256) if n != 0x08 and n != 0xfb]
    for r in range(16):
        random.seed(r)
        binary = bytes([random.choice(randrange) for i in range(2048)])
        with open(Files.reference, 'wb') as fref:
            fref.write(binary)
        xdg(Files.reference, '-a', '1000', '-f', '1000', '-p', '-o',
            Files.input)
        xga(Files.input, '-o', Files.output)
        check_files_eq('random' + str(r), Files.reference, Files.output,
                       'PROGRAM')

    # cleanup
    os.remove(Files.input)
    os.remove(Files.output)
    os.remove(Files.reference)
Пример #10
0
def runtest():
    """check cross-generated output against native reference files"""

    # run disassembler
    for srcfile, dopts, aopts in [
            ("gaops.gpl", ["-a", "0", "-r", "6", "17a"], []),
            ("gainst.gpl", ["-a", "0", "-r", "6", "a2", "a3", "aa", "ab", "ac", "b2", "b4"], []),
            ("gabranch.gpl", ["-a", "0", "-f", "5"], []),
            ("gamove.gpl", ["-a", "0", "-f", "6"], []),
            ("gafmt.gpl", ["-a", "0", "-f", "5", "-y", "rag"], []),
            ("gacopy.gpl", ["-a", ">2000", "-r", "2000"], []),
            ("gaexts.gpl", ["-a", "0", "-r", "0x1e"], []),
            ("gapass.gpl", ["-a", "0x6030", "-r", "6030"], [])
            ]:
        source = os.path.join(Dirs.gplsources, srcfile)
        xga(*[source] + aopts + ["-o", Files.reference])
        xdg(*[Files.reference] + dopts + ["-p", "-o", Files.input])
        xga(*[Files.input] + aopts + ["-o", Files.output])
        check_files_eq(srcfile, Files.output, Files.reference, "PROGRAM")
        check_bytes(Files.input, source)

    # top-down disassembler
    for srcfile, dopts, aopts in [
            ("gaops.gpl", ["-a", "0", "-f", "6"], []),
            ("gainst.gpl", ["-a", "0", "-f", "6"], []),
            ("gabranch.gpl", ["-a", "0", "-f", "5"], []),
            ("gamove.gpl", ["-a", "0", "-f", "6"], []),
            ("gafmt.gpl", ["-a", "0", "-f", "5", "-y", "rag"], []),
            ("gadirs.gpl", ["-a", "0", "-f", "0"], []),
            ("gacopy.gpl", ["-a", ">2000", "-f", ">2000"], []),
            ("gaexts.gpl", ["-a", "0", "-f", "0x1e"], []),
            ("gapass.gpl", ["-a", "0x6030", "-f", ">6030"], [])
            ]:
        source = os.path.join(Dirs.gplsources, srcfile)
        xga(*[source] + aopts + ["-o", Files.reference])
        xdg(*[Files.reference] + dopts + ["-p", "-o", Files.input])
        xga(*[Files.input] + aopts + ["-o", Files.output])
        check_files_eq(srcfile, Files.output, Files.reference, "PROGRAM")
        if count_bytes(Files.output) > 0:
            error("BYTE", "Too many BYTE directives in result")

    # disassembler run
    for srcfile in ["dgruns.gpl"]:
        source = os.path.join(Dirs.gplsources, srcfile)
        xga(*[source] + ["-o", Files.reference])
        xdg(*[Files.reference] + ["-a", "0", "-r", "0x0", "-p", "-o", Files.input])
        xga(*[Files.input] + ["-o", Files.output])
        check_files_eq(srcfile, Files.output, Files.reference, "PROGRAM")
        check_bytes(Files.input, source)

    # disassemble blob
    binary = os.path.join(Dirs.refs, "blobg.bin")
    #TODO: universal character escape \x..
    #xdg(binary, "-a", "0", "-f", "start", "-p", "-o", Files.input)
    #xga(Files.input, "-o", Files.output)
    #check_files_eq("blobg", Files.output, binary, "PROGRAM")
    #xdg(binary, "-a", "0", "-r", "start", "-p", "-o", Files.input)
    #xga(Files.input, "-o", Files.output)
    #check_files_eq("blobg-run", Files.output, binary, "PROGRAM")

    # disassemble random
    randrange = [n for n in xrange(256) if n != 0x08 and n != 0xfb]
    for r in xrange(16):
        random.seed(r)
        binary = "".join([chr(random.choice(randrange)) for i in xrange(2048)])
        with open(Files.reference, "wb") as fref:
            fref.write(binary)
        xdg(Files.reference, "-a", "1000", "-f", "1000", "-p", "-o", Files.input)
        xga(Files.input, "-o", Files.output)
        check_files_eq("random" + str(r), Files.reference, Files.output, "PROGRAM")

    # cleanup
    os.remove(Files.input)
    os.remove(Files.output)
    os.remove(Files.reference)
Пример #11
0
def runtest():
    """run regression tests"""

    # preprocessor
    source = os.path.join(Dirs.gplsources, "gaxprep.gpl")
    xga(source, "-D", "isdef=2", "-o", Files.output)
    xdm(Disks.gplsrcs, "-e", "GAXPREP-Q", "-o", Files.reference)
    check_gbc_files_eq(source, Files.output, Files.reference)

    # directives
    source = os.path.join(Dirs.gplsources, "gaxbcopy.gpl")
    xga(source, "-I", "gpl", "-o", Files.output)
    source = os.path.join(Dirs.gplsources, "gaxbcopyn.gpl")
    xga(source, "-o", Files.reference)
    check_binary_files_eq("bcopy", Files.output, Files.reference)

    # local labels
    source = os.path.join(Dirs.gplsources, "gaxlocal.gpl")
    xga(source, "-o", Files.output)
    ref = os.path.join(Dirs.gplsources, "gaxlocaln.gpl")
    xga(ref, "-o", Files.reference)
    check_binary_files_eq("locals", Files.output, Files.reference)

    # floating-point numbers
    source = os.path.join(Dirs.gplsources, "gafloat.gpl")
    xga(source, "-o", Files.output)
    ref = os.path.join(Dirs.refs, "asfloat.ref")
    check_binary_files_eq("float", Files.output, ref)

    # GROM n or address
    for source in (" GROM >6000\n DATA $", " GROM 3\n DATA $"):
        with open(Files.input, "w") as fout:
            fout.writelines(source)
        xga(Files.input, "-o", Files.output)
        with open(Files.output, "rb") as fin:
            if fin.read()[:4] != "\x60\x00":
                error("GROM", "Incorrect address after GROM directive")

    # cleanup
    os.remove(Files.input)
    os.remove(Files.output)
    os.remove(Files.reference)
Пример #12
0
def runtest():
    '''check cross-generated output against native reference files'''

    # input and output files
    source = os.path.join(Dirs.gplsources, 'gacart.gpl')
    with open(Files.output, 'wb') as f:
        xga(source, '-o', '-', stdout=f)
    xga(source, '-o', Files.reference)
    check_files_eq('stdout', Files.output, Files.reference, 'P')

    xga(source, '-o', Dirs.tmp)
    if not os.path.isfile(os.path.join(Dirs.tmp, 'gacart.gbc')):
        error('output', '-o <dir> failed')

    with open(Files.output, 'wb') as f:
        xga(source, '-G', '>6000', '-A', '>0030', '-o', '-', stdout=f)
    xga(source, '-G', '>6000', '-A', '>0030', '-o', Files.reference)
    check_files_eq('stdout', Files.output, Files.reference, 'P')

    with open(Files.output, 'w') as f:
        xga(source, '-o', Files.input, '-L', '-', stdout=f)
    xga(source, '-o', Files.input, '-L', Files.reference)
    check_text_eq(Files.output, Files.reference)

    source = os.path.join(Dirs.gplsources, 'nonexisting')
    with open(Files.error, 'w') as ferr:
        xga(source, '-o', Files.output, stderr=ferr, rc=1)
    with open(Files.error, 'r') as ferr:
        errs = ferr.readlines()
    if len(errs) != 1 or errs[0].strip(
    ) != 'Error: File not found: nonexisting':
        error('File error', 'Incorrect file error message')

    # text -t
    source = os.path.join(Dirs.gplsources, 'gacart.gpl')
    xga(source, '-o', Files.reference)
    xga(source, '-t', 'c4r', '-o', Files.output)
    check_bin_text_equal_c(Files.output, Files.reference)

    xga(source, '-t', 'b4', '-o', Files.output)
    check_bin_text_equal_basic(Files.output, Files.reference)

    # listing and symbols -L
    source = os.path.join(Dirs.gplsources, 'gahello.gpl')
    xga(source, '-o', Files.error, '-L', Files.input)
    xga(source, '-o', Files.reference)
    with open(Files.input, 'r') as flist, open(Files.error, 'w') as fout:
        listfile = [
            line[14:] for line in flist.readlines() if line[0:4].isdigit()
        ]
        fout.writelines(listfile)
    xga(Files.error, '-o', Files.output)
    check_binary_files_eq('listing', Files.output,
                          Files.reference)  # checks code
    check_list_addr_data(Files.input, Files.reference,
                         0x0000)  # checks addr and data

    # cleanup
    os.remove(Files.input)
    os.remove(Files.reference)
    os.remove(Files.error)
    os.remove(Files.output)
Пример #13
0
def runtest():
    """run regression tests"""

    # other syntax
    source = os.path.join(Dirs.gplsources, 'gahello_timt.gpl')
    xga(source, '-y', 'mizapf', '-o', Files.output)
    ref = os.path.join(Dirs.gplsources, 'gahello.gpl')
    xga(ref, '-o', Files.reference)
    check_binary_files_eq('syntax', Files.output, Files.reference)

    # preprocessor
    source = os.path.join(Dirs.gplsources, 'gaxprep.gpl')
    xga(source, '-D', 'isdef=2', '-o', Files.output)
    xdm(Disks.gplsrcs, '-e', 'GAXPREP-Q', '-o', Files.reference)
    check_gbc_files_eq(source, Files.output, Files.reference)

    # directives
    source = os.path.join(Dirs.gplsources, 'gaxbcopy.gpl')
    xga(source, '-I', 'gpl', '-o', Files.output)
    source = os.path.join(Dirs.gplsources, 'gaxbcopyn.gpl')
    xga(source, '-o', Files.reference)
    check_binary_files_eq('bcopy', Files.output, Files.reference)

    # local labels
    source = os.path.join(Dirs.gplsources, 'gaxlocal.gpl')
    xga(source, '-o', Files.output)
    ref = os.path.join(Dirs.gplsources, 'gaxlocaln.gpl')
    xga(ref, '-o', Files.reference)
    check_binary_files_eq('locals', Files.output, Files.reference)

    # floating-point numbers
    source = os.path.join(Dirs.gplsources, 'gafloat.gpl')
    xga(source, '-o', Files.output)
    ref = os.path.join(Dirs.refs, 'asfloat.ref')
    check_binary_files_eq('float', Files.output, ref)

    # GROM n or address
    for source in (' GROM >6000\n DATA $', ' GROM 3\n DATA $'):
        with open(Files.input, 'w') as fout:
            fout.writelines(source)
        xga(Files.input, '-o', Files.output)
        with open(Files.output, 'rb') as fin:
            if fin.read()[:4] != b'\x60\x00':
                error('GROM', 'Incorrect address after GROM directive')

    # split GROMs
    source = os.path.join(Dirs.gplsources, 'gasplit.gpl')
    xga(source, '-g', '-o', Files.output)
    check_split_groms(3, 3)

    # cleanup
    os.remove(Files.input)
    os.remove(Files.output)
    os.remove(Files.reference)
Пример #14
0
def runtest():
    """check cross-generated output against native reference files"""

    # object code
    for infile, opts, reffile in [("gaops.gpl", [], "GAOPS-Q"),
                                  ("gainst.gpl", [], "GAINST-Q"),
                                  (
                                      "gabranch.gpl",
                                      [],
                                      "GABRANCH-Q",
                                  ), ("gamove.gpl", [], "GAMOVE-Q"),
                                  ("gafmt.gpl", ["-s", "rag"], "GAFMT-Q"),
                                  ("gadirs.gpl", [], "GADIRS-Q"),
                                  ("gacopy.gpl", [], "GACOPY-Q"),
                                  ("gaexts.gpl", [], "GAEXTS-Q"),
                                  ("gapass.gpl", [], "GAPASS-Q")]:
        source = os.path.join(Dirs.gplsources, infile)
        xdm(Disks.gplsrcs, "-e", reffile, "-o", Files.reference)
        xga(*[source] + opts + ["-o", Files.output])
        checkGbcFilesEq(infile, Files.output, Files.reference)

    # cart generation
    for name in ["gacart", "gahello"]:
        source = os.path.join(Dirs.gplsources, name + ".gpl")
        ref = os.path.join(Dirs.refs, name + ".rpk")
        xga(source, "-c", "-o", Files.output)
        checkFilesEq("GPL cart",
                     Files.output,
                     ref,
                     "P",
                     mask=((0x8, 0x1e), (0x188, 0xfff)))

    # extensions
    source = os.path.join(Dirs.gplsources, "gaxprep.gpl")
    xga(source, "-D", "isdef=2", "-o", Files.output)
    xdm(Disks.gplsrcs, "-e", "GAXPREP-Q", "-o", Files.reference)
    checkGbcFilesEq(source, Files.output, Files.reference)

    # error messages
    for s in ["gaerrs0.gpl", "gaerrs1.gpl"]:
        source = os.path.join(Dirs.gplsources, s)
        with open(source, "r") as fin:
            expect = [
                lino + 1 for lino, line in enumerate(fin) if "* ERROR" in line
            ]
        with open(Files.error, "w") as ferr:
            xga(source, "-o", Files.output, stderr=ferr, rc=1)
        with open(Files.error, "r") as fin:
            try:
                found = [int(line[:4]) for line in fin if line[0] != "*"]
            except ValueError:
                error("Error messages", "Unexpected error message")
        if found != expect:
            error(
                "Error messages", "Error mismatch, extra: " +
                str([x for x in found if x not in expect]) + " missing: " +
                str([x for x in expect if x not in found]))

    # cleanup
    os.remove(Files.output)
    os.remove(Files.reference)
    os.remove(Files.error)