Beispiel #1
0
def build_moduletest(test, arch):
	"""
	Given a path to the source files, build a unit test including the unity test harness targeting
	the given architecture.
	"""

	rawlog = '#' + test.get_path('rawlog', arch)
	outlog = '#' + test.get_path('log', arch)
	statusfile = '#' + test.get_path('status', arch)
	elffile = '#' + test.get_path('elf', arch)

	build_dirs = test.build_dirs(arch)
	objdir = build_dirs['objects']

	arch = arch.retarget(add=['test'])

	unit_env = Environment(tools=['xc16_compiler', 'xc16_assembler', 'xc16_linker'], ENV = os.environ)
	tester_env = Environment(tools=['xc16_compiler' ], ENV = os.environ)
	unit_env['ARCH'] = arch
	tester_env['ARCH'] = arch
	unit_env['OUTPUT'] = '%s.elf' % test.name

	objs = []
	for src in test.files + arch.extra_sources():
		name,ext = os.path.splitext(os.path.basename(src))
		target = os.path.join(objdir, name + '.o')

		if src == test.files[0]:
			objs.append(tester_env.xc16_gcc('#' + target, src))
		else:
			objs.append(unit_env.xc16_gcc('#' + target, src))

	#Generate main.c programmatically to run the test
	main_src = '#' + os.path.join(objdir, 'main.c')
	main_target = '#' + os.path.join(objdir, 'main.o')
	unit_env.Command(main_src, test.files[0], action=unit_env.Action(build_moduletest_main, "Creating test runner"))
	objs.append(unit_env.xc16_gcc(main_target, main_src))

	#Link the test, run it and build a status file
	unit_env.xc16_ld(elffile, objs)
	unit_env.Command(outlog, elffile, action=unit_env.Action(r"momo-picunit %s '%s' '%s'" % (arch.property('simulator_model'), elffile[1:], outlog[1:]), "Running unit test")) 
	unit_env.Command(statusfile, outlog, action=unit_env.Action(process_log, 'Processing log file'))

	return statusfile