aboutsummaryrefslogtreecommitdiffstats
path: root/travis
diff options
context:
space:
mode:
authorCyrill Gorcunov <gorcunov@gmail.com>2020-08-24 18:22:48 +0300
committerCyrill Gorcunov <gorcunov@gmail.com>2020-08-25 16:36:06 +0300
commit63ccbf4f5fed724037c48de1a767cfa7290fdf19 (patch)
tree434d83efc0eaa2306b875de4e787c78b25d8df29 /travis
parentd2e3bd850f59603b8402074fcd578312e308f1af (diff)
downloadnasm-63ccbf4f5fed724037c48de1a767cfa7290fdf19.tar.gz
nasm-63ccbf4f5fed724037c48de1a767cfa7290fdf19.tar.xz
nasm-63ccbf4f5fed724037c48de1a767cfa7290fdf19.zip
travis: nasm-t -- add ability to generate new tests
Just to not fill descriptor by hands every time. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Diffstat (limited to 'travis')
-rwxr-xr-xtravis/nasm-t.py118
1 files changed, 118 insertions, 0 deletions
diff --git a/travis/nasm-t.py b/travis/nasm-t.py
index 8a2ddb49..7a1e5506 100755
--- a/travis/nasm-t.py
+++ b/travis/nasm-t.py
@@ -34,6 +34,46 @@ for cmd in ['run']:
help = 'Run the selected test only',
required = False)
+for cmd in ['new']:
+ spp = sp.add_parser(cmd, help = 'Add a new test case')
+ spp.add_argument('--description',
+ dest = 'description', default = "Description of a test",
+ help = 'Description of a test',
+ required = False)
+ spp.add_argument('--id',
+ dest = 'id',
+ help = 'Test identifier/name',
+ required = True)
+ spp.add_argument('--format',
+ dest = 'format', default = 'bin',
+ help = 'Output format',
+ required = False)
+ spp.add_argument('--source',
+ dest = 'source',
+ help = 'Source file',
+ required = False)
+ spp.add_argument('--option',
+ dest = 'option',
+ default = '-Ox',
+ help = 'NASM options',
+ required = False)
+ spp.add_argument('--ref',
+ dest = 'ref',
+ help = 'Test reference',
+ required = False)
+ spp.add_argument('--output',
+ dest = 'output', default = 'y',
+ help = 'Output (compiled) file name (or "y")',
+ required = False)
+ spp.add_argument('--stdout',
+ dest = 'stdout', default = 'y',
+ help = 'Filename of stdout file (or "y")',
+ required = False)
+ spp.add_argument('--stderr',
+ dest = 'stderr', default = 'y',
+ help = 'Filename of stderr file (or "y")',
+ required = False)
+
for cmd in ['list']:
spp = sp.add_parser(cmd, help = 'List test cases')
@@ -44,6 +84,27 @@ for cmd in ['update']:
help = 'Update the selected test only',
required = False)
+map_fmt_ext = {
+ 'bin': '.bin',
+ 'elf': '.o',
+ 'elf64': '.o',
+ 'elf32': '.o',
+ 'elfx32': '.o',
+ 'ith': '.ith',
+ 'srec': '.srec',
+ 'obj': '.obj',
+ 'win32': '.obj',
+ 'win64': '.obj',
+ 'coff': '.obj',
+ 'macho': '.o',
+ 'macho32': '.o',
+ 'macho64': '.o',
+ 'aout': '.out',
+ 'aoutb': '.out',
+ 'as86': '.o',
+ 'rdf': '.rdf',
+}
+
args = parser.parse_args()
if args.cmd == None:
@@ -395,6 +456,63 @@ def test_update(desc):
return test_updated(desc['_test-name'])
+#
+# Create a new empty test case
+if args.cmd == 'new':
+ #
+ # If no source provided create one
+ # from (ID which is required)
+ if not args.source:
+ args.source = args.id + ".asm"
+
+ #
+ # Emulate "touch" on source file
+ path_asm = args.dir + os.sep + args.source
+ print("\tCreating %s" % (path_asm))
+ open(path_asm, 'a').close()
+
+ #
+ # Fill the test descriptor
+ #
+ # FIXME: We should probably use Jinja
+ path_json = args.dir + os.sep + args.id + ".json"
+ print("\tFilling descriptor %s" % (path_json))
+ with open(path_json, 'wb') as f:
+ f.write("[\n\t{\n".encode("utf-8"))
+ acc = []
+ if args.description:
+ acc.append("\t\t\"description\": \"{}\"".format(args.description))
+ acc.append("\t\t\"id\": \"{}\"".format(args.id))
+ if args.format:
+ acc.append("\t\t\"format\": \"{}\"".format(args.format))
+ acc.append("\t\t\"source\": \"{}\"".format(args.source))
+ if args.option:
+ acc.append("\t\t\"option\": \"{}\"".format(args.option))
+ if args.ref:
+ acc.append("\t\t\"ref\": \"{}\"".format(args.ref))
+ f.write(",\n".join(acc).encode("utf-8"))
+ if args.output or args.stdout or args.stderr:
+ acc = []
+ if args.output:
+ if args.output == 'y':
+ if args.format in map_fmt_ext:
+ args.output = args.id + map_fmt_ext[args.format]
+ acc.append("\t\t\t{{ \"output\": \"{}\" }}".format(args.output))
+ if args.stdout:
+ if args.stdout == 'y':
+ args.stdout = args.id + '.stdout'
+ acc.append("\t\t\t{{ \"stdout\": \"{}\" }}".format(args.stdout))
+ if args.stderr:
+ if args.stderr == 'y':
+ args.stderr = args.id + '.stderr'
+ acc.append("\t\t\t{{ \"stderr\": \"{}\" }}".format(args.stderr))
+ f.write(",\n".encode("utf-8"))
+ f.write("\t\t\"target\": [\n".encode("utf-8"))
+ f.write(",\n".join(acc).encode("utf-8"))
+ f.write("\n\t\t]".encode("utf-8"))
+ f.write("\n\t}\n]\n".encode("utf-8"))
+ f.close()
+
if args.cmd == 'run':
desc_array = []
if args.test == None: