Blame tests/upstream-test-suite/runtests.py

Than Ngo b7bcaa
#!/usr/bin/python
Than Ngo b7bcaa
Than Ngo b7bcaa
from __future__ import print_function
Than Ngo b7bcaa
import argparse, glob, itertools, re, shutil, os, sys
Than Ngo b7bcaa
Than Ngo b7bcaa
config_reg = re.compile('.*\/\/\s*(?P<name>\S+):\s*(?P<value>.*)$')
Than Ngo b7bcaa
Than Ngo b7bcaa
class Tester:
Than Ngo b7bcaa
	def __init__(self,args,test):
Than Ngo b7bcaa
		self.args      = args
Than Ngo b7bcaa
		self.test      = test
Than Ngo b7bcaa
		self.update    = args.updateref
Than Ngo b7bcaa
		self.config    = self.get_config()
Than Ngo b7bcaa
		self.test_name = '[%s]: %s' % (self.test,self.config['objective'][0])
Than Ngo b7bcaa
		self.test_id   = self.test.split('_')[0]
Than Ngo b7bcaa
		if self.update:
Than Ngo b7bcaa
			self.test_out = self.args.inputdir+'/'+self.test_id
Than Ngo b7bcaa
		else:
Than Ngo b7bcaa
			self.test_out = self.args.outputdir+'/test_output_'+self.test_id
Than Ngo b7bcaa
		self.prepare_test()
Than Ngo b7bcaa
Than Ngo b7bcaa
	def compare_ok(self,got_file,expected_file,name):
Than Ngo b7bcaa
		if not os.path.isfile(got_file):
Than Ngo b7bcaa
			return (True,'%s absent' % got_file)
Than Ngo b7bcaa
		elif not os.path.isfile(expected_file):
Than Ngo b7bcaa
			return (True,'%s absent' % expected_file)
Than Ngo b7bcaa
		else:
Than Ngo b7bcaa
			diff = os.popen('diff -b -w -u %s %s' % (got_file,expected_file)).read()
Than Ngo b7bcaa
			if diff and not diff.startswith("No differences"):
Than Ngo b7bcaa
				return (True,'Difference between generated output and reference:\n%s' % diff)
Than Ngo b7bcaa
		return (False,'')
Than Ngo b7bcaa
Than Ngo b7bcaa
	def cleanup_xmllint(self,errmsg):
Than Ngo b7bcaa
		msg = errmsg.split('\n')
Than Ngo b7bcaa
		rtnmsg = ""
Than Ngo b7bcaa
		for o in msg:
Than Ngo b7bcaa
			if (o):
Than Ngo b7bcaa
				if (o.startswith("I/O error : Attempt")):
Than Ngo b7bcaa
					pass
Than Ngo b7bcaa
				else:
Than Ngo b7bcaa
					if (rtnmsg):
Than Ngo b7bcaa
						rtnmsg += '\n'
Than Ngo b7bcaa
					rtnmsg += o
Than Ngo b7bcaa
		return rtnmsg
Than Ngo b7bcaa
Than Ngo b7bcaa
	def cleanup_xmllint_docbook(self,errmsg):
Than Ngo b7bcaa
		# For future work, first get everything valid XML
Than Ngo b7bcaa
		msg = self.cleanup_xmllint(errmsg).split('\n')
Than Ngo b7bcaa
		rtnmsg = ""
Than Ngo b7bcaa
		cnt = 0
Than Ngo b7bcaa
		for o in msg:
Than Ngo b7bcaa
			if (o):
Than Ngo b7bcaa
				if (cnt):
Than Ngo b7bcaa
					cnt -= 1
Than Ngo b7bcaa
					pass
Than Ngo b7bcaa
				elif (o.endswith("does not validate")):
Than Ngo b7bcaa
					pass
Than Ngo b7bcaa
				elif (o.find("no DTD found!")!=-1):
Than Ngo b7bcaa
					pass
Than Ngo b7bcaa
				elif (o.find("is not an NCName")!=-1):
Than Ngo b7bcaa
					cnt = 2
Than Ngo b7bcaa
				else:
Than Ngo b7bcaa
					if (rtnmsg):
Than Ngo b7bcaa
						rtnmsg += '\n'
Than Ngo b7bcaa
					rtnmsg += o
Than Ngo b7bcaa
		return rtnmsg
Than Ngo b7bcaa
Than Ngo b7bcaa
	def get_config(self):
Than Ngo b7bcaa
		config = {}
Than Ngo b7bcaa
		with open(self.args.inputdir+'/'+self.test,'r') as f:
Than Ngo b7bcaa
			for line in f.readlines():
Than Ngo b7bcaa
				m = config_reg.match(line)
Than Ngo b7bcaa
				if m:
Than Ngo b7bcaa
					key   = m.group('name')
Than Ngo b7bcaa
					value = m.group('value')
Than Ngo b7bcaa
					if (key=='config'):
Than Ngo b7bcaa
						value = value.replace('$INPUTDIR',self.args.inputdir)
Than Ngo b7bcaa
					# print('key=%s value=%s' % (key,value))
Than Ngo b7bcaa
					config.setdefault(key, []).append(value)
Than Ngo b7bcaa
		return config
Than Ngo b7bcaa
Than Ngo b7bcaa
	def prepare_test(self):
Than Ngo b7bcaa
		# prepare test environment
Than Ngo b7bcaa
		shutil.rmtree(self.test_out,ignore_errors=True)
Than Ngo b7bcaa
		os.mkdir(self.test_out)
Than Ngo b7bcaa
		shutil.copy(self.args.inputdir+'/Doxyfile',self.test_out)
Than Ngo b7bcaa
		with open(self.test_out+'/Doxyfile','a') as f:
Than Ngo b7bcaa
			print('INPUT=%s/%s' % (self.args.inputdir,self.test), file=f)
Than Ngo b7bcaa
			print('STRIP_FROM_PATH=%s' % self.args.inputdir, file=f)
Than Ngo b7bcaa
			print('EXAMPLE_PATH=%s' % self.args.inputdir, file=f)
Than Ngo b7bcaa
			if 'config' in self.config:
Than Ngo b7bcaa
				for option in self.config['config']:
Than Ngo b7bcaa
					print(option, file=f)
Than Ngo b7bcaa
			if (self.args.xml):
Than Ngo b7bcaa
				print('GENERATE_XML=YES', file=f)
Than Ngo b7bcaa
				print('XML_OUTPUT=%s/out' % self.test_out, file=f)
Than Ngo b7bcaa
			else:
Than Ngo b7bcaa
				print('GENERATE_XML=NO', file=f)
Than Ngo b7bcaa
			if (self.args.rtf):
Than Ngo b7bcaa
				print('GENERATE_RTF=YES', file=f)
Than Ngo b7bcaa
				print('RTF_OUTPUT=%s/rtf' % self.test_out, file=f)
Than Ngo b7bcaa
			else:
Than Ngo b7bcaa
				print('GENERATE_RTF=NO', file=f)
Than Ngo b7bcaa
			if (self.args.docbook):
Than Ngo b7bcaa
				print('GENERATE_DOCBOOK=YES', file=f)
Than Ngo b7bcaa
				print('DOCBOOK_OUTPUT=%s/docbook' % self.test_out, file=f)
Than Ngo b7bcaa
			else:
Than Ngo b7bcaa
				print('GENERATE_DOCBOOK=NO', file=f)
Than Ngo b7bcaa
			if (self.args.xhtml):
Than Ngo b7bcaa
				print('GENERATE_HTML=YES', file=f)
Than Ngo b7bcaa
			# HTML_OUTPUT can also be set locally
Than Ngo b7bcaa
			print('HTML_OUTPUT=%s/html' % self.test_out, file=f)
Than Ngo b7bcaa
			print('HTML_FILE_EXTENSION=.xhtml', file=f)
Than Ngo b7bcaa
			if (self.args.pdf):
Than Ngo b7bcaa
				print('GENERATE_LATEX=YES', file=f)
Than Ngo b7bcaa
				print('LATEX_OUTPUT=%s/latex' % self.test_out, file=f)
Than Ngo b7bcaa
			if self.args.subdirs:
Than Ngo b7bcaa
				print('CREATE_SUBDIRS=YES', file=f)
Than Ngo b7bcaa
			if (self.args.cfgs):
Than Ngo b7bcaa
				for cfg in list(itertools.chain.from_iterable(self.args.cfgs)):
Than Ngo b7bcaa
					if cfg.find('=') == -1:
Than Ngo b7bcaa
						print("Not a doxygen configuration item, missing '=' sign: '%s'."%cfg)
Than Ngo b7bcaa
						sys.exit(1)
Than Ngo b7bcaa
					print(cfg, file=f)
Than Ngo b7bcaa
Than Ngo b7bcaa
		if 'check' not in self.config or not self.config['check']:
Than Ngo b7bcaa
			print('Test doesn\'t specify any files to check')
Than Ngo b7bcaa
			sys.exit(1)
Than Ngo b7bcaa
Than Ngo b7bcaa
		# run doxygen
Than Ngo b7bcaa
		if (sys.platform == 'win32'):
Than Ngo b7bcaa
			redir=' > nul:'
Than Ngo b7bcaa
		else:
Than Ngo b7bcaa
			redir=' 2> /dev/null > /dev/null'
Than Ngo b7bcaa
Than Ngo b7bcaa
		if (self.args.noredir):
Than Ngo b7bcaa
			redir=''
Than Ngo b7bcaa
Than Ngo b7bcaa
		if os.system('%s %s/Doxyfile %s' % (self.args.doxygen,self.test_out,redir))!=0:
Than Ngo b7bcaa
			print('Error: failed to run %s on %s/Doxyfile' % (self.args.doxygen,self.test_out))
Than Ngo b7bcaa
			sys.exit(1)
Than Ngo b7bcaa
Than Ngo b7bcaa
	# update the reference data for this test
Than Ngo b7bcaa
	def update_test(self,testmgr):
Than Ngo b7bcaa
		print('Updating reference for %s' % self.test_name)
Than Ngo b7bcaa
Than Ngo b7bcaa
		if 'check' in self.config:
Than Ngo b7bcaa
			for check in self.config['check']:
Than Ngo b7bcaa
				check_file='%s/out/%s' % (self.test_out,check)
Than Ngo b7bcaa
				# check if the file we need to check is actually generated
Than Ngo b7bcaa
				if not os.path.isfile(check_file):
Than Ngo b7bcaa
					print('Non-existing file %s after \'check:\' statement' % check_file)
Than Ngo b7bcaa
					return
Than Ngo b7bcaa
				# convert output to canonical form
Than Ngo b7bcaa
				data = os.popen('%s --format --noblanks --nowarning %s' % (self.args.xmllint,check_file)).read()
Than Ngo b7bcaa
				if data:
Than Ngo b7bcaa
					# strip version
Than Ngo b7bcaa
					data = re.sub(r'xsd" version="[0-9.-]+"','xsd" version=""',data).rstrip('\n')
Than Ngo b7bcaa
				else:
Than Ngo b7bcaa
					print('Failed to run %s on the doxygen output file %s' % (self.args.xmllint,self.test_out))
Than Ngo b7bcaa
					return
Than Ngo b7bcaa
				out_file='%s/%s' % (self.test_out,check)
Than Ngo b7bcaa
				with open(out_file,'w') as f:
Than Ngo b7bcaa
					print(data,file=f)
Than Ngo b7bcaa
		shutil.rmtree(self.test_out+'/out',ignore_errors=True)
Than Ngo b7bcaa
		os.remove(self.test_out+'/Doxyfile')
Than Ngo b7bcaa
Than Ngo b7bcaa
	# check the relevant files of a doxygen run with the reference material
Than Ngo b7bcaa
	def perform_test(self,testmgr):
Than Ngo b7bcaa
		if (sys.platform == 'win32'):
Than Ngo b7bcaa
			redir=' > nul:'
Than Ngo b7bcaa
			separ='&'
Than Ngo b7bcaa
		else:
Than Ngo b7bcaa
			redir=' 2> /dev/null'
Than Ngo b7bcaa
			separ=';'
Than Ngo b7bcaa
Than Ngo b7bcaa
		if (self.args.noredir):
Than Ngo b7bcaa
			redir=''
Than Ngo b7bcaa
Than Ngo b7bcaa
		failed_xml=False
Than Ngo b7bcaa
		failed_html=False
Than Ngo b7bcaa
		failed_latex=False
Than Ngo b7bcaa
		failed_docbook=False
Than Ngo b7bcaa
		failed_rtf=False
Than Ngo b7bcaa
		msg = ()
Than Ngo b7bcaa
		# look for files to check against the reference
Than Ngo b7bcaa
		if self.args.xml:
Than Ngo b7bcaa
			failed_xml=True
Than Ngo b7bcaa
			if 'check' in self.config:
Than Ngo b7bcaa
				for check in self.config['check']:
Than Ngo b7bcaa
					check_file='%s/out/%s' % (self.test_out,check)
Than Ngo b7bcaa
					# check if the file we need to check is actually generated
Than Ngo b7bcaa
					if not os.path.isfile(check_file):
Than Ngo b7bcaa
						# try with sub dirs
Than Ngo b7bcaa
						check_file = glob.glob('%s/out/*/*/%s' % (self.test_out,check))
Than Ngo b7bcaa
						if not check_file:
Than Ngo b7bcaa
							check_file='%s/out/%s' % (self.test_out,check)
Than Ngo b7bcaa
							msg += ('Non-existing file %s after \'check:\' statement' % check_file,)
Than Ngo b7bcaa
							break
Than Ngo b7bcaa
						else:
Than Ngo b7bcaa
							check_file = check_file[0]
Than Ngo b7bcaa
					# convert output to canonical form
Than Ngo b7bcaa
					data = os.popen('%s --format --noblanks --nowarning %s' % (self.args.xmllint,check_file)).read()
Than Ngo b7bcaa
					if data:
Than Ngo b7bcaa
						# strip version
Than Ngo b7bcaa
						data = re.sub(r'xsd" version="[0-9.-]+"','xsd" version=""',data).rstrip('\n')
Than Ngo b7bcaa
					else:
Than Ngo b7bcaa
						msg += ('Failed to run %s on the doxygen output file %s' % (self.args.xmllint,self.test_out),)
Than Ngo b7bcaa
						break
Than Ngo b7bcaa
					out_file='%s/%s' % (self.test_out,check)
Than Ngo b7bcaa
					with open(out_file,'w') as f:
Than Ngo b7bcaa
						print(data,file=f)
Than Ngo b7bcaa
					ref_file='%s/%s/%s' % (self.args.inputdir,self.test_id,check)
Than Ngo b7bcaa
					(failed_xml,xml_msg) = self.compare_ok(out_file,ref_file,self.test_name)
Than Ngo b7bcaa
					if failed_xml:
Than Ngo b7bcaa
						msg+= (xml_msg,)
Than Ngo b7bcaa
						break
Than Ngo b7bcaa
				if not failed_xml and not self.args.keep:
Than Ngo b7bcaa
					xml_output='%s/out' % self.test_out
Than Ngo b7bcaa
					shutil.rmtree(xml_output,ignore_errors=True)
Than Ngo b7bcaa
Than Ngo b7bcaa
		if (self.args.rtf):
Than Ngo b7bcaa
			# no tests defined yet
Than Ngo b7bcaa
			pass
Than Ngo b7bcaa
Than Ngo b7bcaa
		if (self.args.docbook):
Than Ngo b7bcaa
			docbook_output='%s/docbook' % self.test_out
Than Ngo b7bcaa
			if (sys.platform == 'win32'):
Than Ngo b7bcaa
				redirx=' 2> %s/temp >nul:'%docbook_output
Than Ngo b7bcaa
			else:
Than Ngo b7bcaa
				redirx='2>%s/temp >/dev/null'%docbook_output
Than Ngo b7bcaa
			# For future work, first get everything valid XML
Than Ngo b7bcaa
			# exe_string = '%s --relaxng db/docbook.rng --nonet --postvalid %s/*xml %s  % (self.args.xmllint,docbook_output,redirx)
Than Ngo b7bcaa
			tests = []
Than Ngo b7bcaa
			tests.append(glob.glob('%s/*.xml' % (docbook_output)))
Than Ngo b7bcaa
			tests.append(glob.glob('%s/*/*/*.xml' % (docbook_output)))
Than Ngo b7bcaa
			tests = ' '.join(list(itertools.chain.from_iterable(tests))).replace(self.args.outputdir +'/','').replace('\\','/')
Than Ngo b7bcaa
			exe_string = '%s --nonet --postvalid %s %s' % (self.args.xmllint,tests,redirx)
Than Ngo b7bcaa
			exe_string += ' %s more "%s/temp"' % (separ,docbook_output)
Than Ngo b7bcaa
Than Ngo b7bcaa
			failed_docbook=False
Than Ngo b7bcaa
			xmllint_out = os.popen(exe_string).read()
Than Ngo b7bcaa
			xmllint_out = self.cleanup_xmllint_docbook(xmllint_out)
Than Ngo b7bcaa
			if xmllint_out:
Than Ngo b7bcaa
				msg += (xmllint_out,)
Than Ngo b7bcaa
				failed_docbook=True
Than Ngo b7bcaa
			elif not self.args.keep:
Than Ngo b7bcaa
				shutil.rmtree(docbook_output,ignore_errors=True)
Than Ngo b7bcaa
Than Ngo b7bcaa
		if (self.args.xhtml):
Than Ngo b7bcaa
			html_output='%s/html' % self.test_out
Than Ngo b7bcaa
			if (sys.platform == 'win32'):
Than Ngo b7bcaa
				redirx=' 2> %s/temp >nul:'%html_output
Than Ngo b7bcaa
			else:
Than Ngo b7bcaa
				redirx='2>%s/temp >/dev/null'%html_output
Than Ngo b7bcaa
			exe_string = '%s --path dtd --nonet --postvalid %s/*xhtml %s %s ' % (self.args.xmllint,html_output,redirx,separ)
Than Ngo b7bcaa
			exe_string += 'more "%s/temp"' % (html_output)
Than Ngo b7bcaa
			failed_html=False
Than Ngo b7bcaa
			xmllint_out = os.popen(exe_string).read()
Than Ngo b7bcaa
			xmllint_out = self.cleanup_xmllint(xmllint_out)
Than Ngo b7bcaa
			if xmllint_out:
Than Ngo b7bcaa
				msg += (xmllint_out,)
Than Ngo b7bcaa
				failed_html=True
Than Ngo b7bcaa
			elif not self.args.keep:
Than Ngo b7bcaa
				shutil.rmtree(html_output,ignore_errors=True)
Than Ngo b7bcaa
		if (self.args.pdf):
Than Ngo b7bcaa
			failed_latex=False
Than Ngo b7bcaa
			latex_output='%s/latex' % self.test_out
Than Ngo b7bcaa
			if (sys.platform == 'win32'):
Than Ngo b7bcaa
				redirl='>nul: 2>temp'
Than Ngo b7bcaa
			else:
Than Ngo b7bcaa
				redirl='>/dev/null 2>temp'
Than Ngo b7bcaa
			exe_string = 'cd %s %s echo "q" | make %s %s' % (latex_output,separ,redirl,separ)
Than Ngo b7bcaa
			exe_string += 'more temp'
Than Ngo b7bcaa
			latex_out = os.popen(exe_string).read()
Than Ngo b7bcaa
			if latex_out.find("Error")!=-1:
Than Ngo b7bcaa
				msg += ("PDF generation failed\n  For a description of the problem see 'refman.log' in the latex directory of this test",)
Than Ngo b7bcaa
				failed_html=True
Than Ngo b7bcaa
			elif open(latex_output + "/refman.log",'r').read().find("Emergency stop")!= -1:
Than Ngo b7bcaa
				msg += ("PDF generation failed\n  For a description of the problem see 'refman.log' in the latex directory of this test",)
Than Ngo b7bcaa
				failed_html=True
Than Ngo b7bcaa
			elif not self.args.keep:
Than Ngo b7bcaa
				shutil.rmtree(latex_output,ignore_errors=True)
Than Ngo b7bcaa
Than Ngo b7bcaa
		if failed_xml or failed_html or failed_latex or failed_docbook or failed_rtf:
Than Ngo b7bcaa
			testmgr.ok(False,self.test_name,msg)
Than Ngo b7bcaa
			return
Than Ngo b7bcaa
Than Ngo b7bcaa
		testmgr.ok(True,self.test_name)
Than Ngo b7bcaa
		if not self.args.keep:
Than Ngo b7bcaa
			shutil.rmtree(self.test_out,ignore_errors=True)
Than Ngo b7bcaa
Than Ngo b7bcaa
	def run(self,testmgr):
Than Ngo b7bcaa
		if self.update:
Than Ngo b7bcaa
			self.update_test(testmgr)
Than Ngo b7bcaa
		else:
Than Ngo b7bcaa
			self.perform_test(testmgr)
Than Ngo b7bcaa
Than Ngo b7bcaa
class TestManager:
Than Ngo b7bcaa
	def __init__(self,args,tests):
Than Ngo b7bcaa
		self.args  = args
Than Ngo b7bcaa
		self.tests = tests
Than Ngo b7bcaa
		self.num_tests = len(tests)
Than Ngo b7bcaa
		self.count=1
Than Ngo b7bcaa
		self.passed=0
Than Ngo b7bcaa
		if self.args.xhtml:
Than Ngo b7bcaa
			self.prepare_dtd()
Than Ngo b7bcaa
		print('1..%d' % self.num_tests)
Than Ngo b7bcaa
Than Ngo b7bcaa
	def ok(self,result,test_name,msg='Ok'):
Than Ngo b7bcaa
		if result:
Than Ngo b7bcaa
			print('ok %s - %s' % (self.count,test_name))
Than Ngo b7bcaa
			self.passed = self.passed + 1
Than Ngo b7bcaa
		else:
Than Ngo b7bcaa
			print('not ok %s - %s' % (self.count,test_name))
Than Ngo b7bcaa
			print('-------------------------------------')
Than Ngo b7bcaa
			for o in msg:
Than Ngo b7bcaa
				print(o)
Than Ngo b7bcaa
				print('-------------------------------------')
Than Ngo b7bcaa
		self.count = self.count + 1
Than Ngo b7bcaa
Than Ngo b7bcaa
	def result(self):
Than Ngo b7bcaa
		if self.passed==self.num_tests:
Than Ngo b7bcaa
			print('All tests passed!')
Than Ngo b7bcaa
		else:
Than Ngo b7bcaa
			print('%d out of %s tests failed' % (self.num_tests-self.passed,self.num_tests))
Than Ngo b7bcaa
		return 0 if self.passed==self.num_tests else 1
Than Ngo b7bcaa
Than Ngo b7bcaa
	def perform_tests(self):
Than Ngo b7bcaa
		for test in self.tests:
Than Ngo b7bcaa
			tester = Tester(self.args,test)
Than Ngo b7bcaa
			tester.run(self)
Than Ngo b7bcaa
		res=self.result()
Than Ngo b7bcaa
		if self.args.xhtml and not res and not self.args.keep:
Than Ngo b7bcaa
			shutil.rmtree("dtd",ignore_errors=True)
Than Ngo b7bcaa
		return 0 if self.args.updateref else res
Than Ngo b7bcaa
Than Ngo b7bcaa
	def prepare_dtd(self):
Than Ngo b7bcaa
		shutil.rmtree("dtd",ignore_errors=True)
Than Ngo b7bcaa
		shutil.copytree(self.args.inputdir+"/dtd", "dtd")
Than Ngo b7bcaa
Than Ngo b7bcaa
def main():
Than Ngo b7bcaa
	# argument handling
Than Ngo b7bcaa
	parser = argparse.ArgumentParser(description='run doxygen tests')
Than Ngo b7bcaa
	parser.add_argument('--updateref',help=
Than Ngo b7bcaa
		'update the reference files. Should be used in combination with -id to '
Than Ngo b7bcaa
		'update the reference file(s) for the given test',action="store_true")
Than Ngo b7bcaa
	parser.add_argument('--doxygen',nargs='?',default='doxygen',help=
Than Ngo b7bcaa
		'path/name of the doxygen executable')
Than Ngo b7bcaa
	parser.add_argument('--xmllint',nargs='?',default='xmllint',help=
Than Ngo b7bcaa
		'path/name of the xmllint executable')
Than Ngo b7bcaa
	parser.add_argument('--id',nargs='+',dest='ids',action='append',type=int,help=
Than Ngo b7bcaa
		'run test with number n only (the option can be specified to run test with '
Than Ngo b7bcaa
		'number n only (the option can be specified multiple times')
Than Ngo b7bcaa
	parser.add_argument('--start_id',dest='start_id',type=int,help=
Than Ngo b7bcaa
		'run tests starting with number n')
Than Ngo b7bcaa
	parser.add_argument('--end_id',dest='end_id',type=int,help=
Than Ngo b7bcaa
		'run tests ending with number n')
Than Ngo b7bcaa
	parser.add_argument('--all',help=
Than Ngo b7bcaa
		'can be used in combination with -updateref to update the reference files '
Than Ngo b7bcaa
		'for all tests.',action="store_true")
Than Ngo b7bcaa
	parser.add_argument('--inputdir',nargs='?',default='.',help=
Than Ngo b7bcaa
		'input directory containing the tests')
Than Ngo b7bcaa
	parser.add_argument('--outputdir',nargs='?',default='.',help=
Than Ngo b7bcaa
		'output directory to write the doxygen output to')
Than Ngo b7bcaa
	parser.add_argument('--noredir',help=
Than Ngo b7bcaa
		'disable redirection of doxygen warnings',action="store_true")
Than Ngo b7bcaa
	parser.add_argument('--xml',help='create xml output and check',
Than Ngo b7bcaa
		action="store_true")
Than Ngo b7bcaa
	parser.add_argument('--rtf',help=
Than Ngo b7bcaa
		'create rtf output',action="store_true")
Than Ngo b7bcaa
	parser.add_argument('--docbook',help=
Than Ngo b7bcaa
		'create docbook output and check with xmllint',action="store_true")
Than Ngo b7bcaa
	parser.add_argument('--xhtml',help=
Than Ngo b7bcaa
		'create xhtml output and check with xmllint',action="store_true")
Than Ngo b7bcaa
	parser.add_argument('--pdf',help='create LaTeX output and create pdf from it',
Than Ngo b7bcaa
		action="store_true")
Than Ngo b7bcaa
	parser.add_argument('--subdirs',help='use the configuration parameter CREATE_SUBDIRS=YES',
Than Ngo b7bcaa
		action="store_true")
Than Ngo b7bcaa
	parser.add_argument('--keep',help='keep result directories',
Than Ngo b7bcaa
		action="store_true")
Than Ngo b7bcaa
	parser.add_argument('--cfg',nargs='+',dest='cfgs',action='append',help=
Than Ngo b7bcaa
		'run test with extra doxygen configuration settings '
Than Ngo b7bcaa
		'(the option may be specified multiple times')
Than Ngo b7bcaa
	test_flags = os.getenv('TEST_FLAGS', default='').split()
Than Ngo b7bcaa
	args = parser.parse_args(test_flags + sys.argv[1:])
Than Ngo b7bcaa
Than Ngo b7bcaa
	# sanity check
Than Ngo b7bcaa
	if (not args.xml) and (not args.pdf) and (not args.xhtml) and (not args.docbook and (not args.rtf)):
Than Ngo b7bcaa
		args.xml=True
Than Ngo b7bcaa
	if (not args.updateref is None) and (args.ids is None) and (args.all is None):
Than Ngo b7bcaa
		parser.error('--updateref requires either --id or --all')
Than Ngo b7bcaa
Than Ngo b7bcaa
	starting_directory = os.getcwd()
Than Ngo b7bcaa
	os.chdir(args.inputdir)
Than Ngo b7bcaa
	# find the tests to run
Than Ngo b7bcaa
	tests = []
Than Ngo b7bcaa
	if args.start_id:
Than Ngo b7bcaa
		if args.end_id:
Than Ngo b7bcaa
			for id in range(args.start_id, args.end_id + 1):
Than Ngo b7bcaa
				tests.append(glob.glob('%s_*'%id))
Than Ngo b7bcaa
				tests.append(glob.glob('0%s_*'%id))
Than Ngo b7bcaa
				tests.append(glob.glob('00%s_*'%id))
Than Ngo b7bcaa
		else:
Than Ngo b7bcaa
			parser.error('--start_id requires --end_id')
Than Ngo b7bcaa
	elif args.end_id:
Than Ngo b7bcaa
		parser.error('--end_id requires --start_id')
Than Ngo b7bcaa
	if args.ids:  # test ids are given by user
Than Ngo b7bcaa
		for id in list(itertools.chain.from_iterable(args.ids)):
Than Ngo b7bcaa
			tests.append(glob.glob('%s_*'%id))
Than Ngo b7bcaa
			tests.append(glob.glob('0%s_*'%id))
Than Ngo b7bcaa
			tests.append(glob.glob('00%s_*'%id))
Than Ngo b7bcaa
	if (not args.ids and not args.start_id):  # find all tests
Than Ngo b7bcaa
		tests = glob.glob('[0-9][0-9][0-9]_*')
Than Ngo b7bcaa
	else:
Than Ngo b7bcaa
		tests = list(itertools.chain.from_iterable(tests))
Than Ngo b7bcaa
	os.chdir(starting_directory)
Than Ngo b7bcaa
Than Ngo b7bcaa
	# create test manager to run the tests
Than Ngo b7bcaa
	testManager = TestManager(args,tests)
Than Ngo b7bcaa
	sys.exit(testManager.perform_tests())
Than Ngo b7bcaa
Than Ngo b7bcaa
if __name__ == '__main__':
Than Ngo b7bcaa
	main()