コード例 #1
0
ファイル: test_engine.py プロジェクト: mrawde/cppbat
def compile_code(problem, code, files):
	errors = []
	warnings = []

	outfile = cppbat.core.settings.TEMP_DIR + '/test' # TODO make this random

	code = code.lower() 

	# parse code for compile errors/warnings
	lines = code.split('\n')
	for line in lines:
		error = utils.substr_rem(line, 'c error: ')
		if error:
			errors.append(error)
		else:
			warning = utils.substr_rem(line, 'c warning: ')
			if warning:
				warnings.append(warning)

	# copies the code into the outfile
	f = open(outfile, 'w')
	try:
		f.write(code)
	finally:
		f.close()

	return errors, warnings, outfile
コード例 #2
0
ファイル: test_engine.py プロジェクト: mrawde/cppbat
def run(prog, args):
	f = open(prog)
	lines = f.readlines()
	exec_tok = 'e: %s -> %s = '  % (','.join(args[:-1]), args[-1])
	for line in lines:
		rest = utils.substr_rem(line, exec_tok)
		if rest:
			# TODO remove the line ending at the end
			vals = rest.split(',') # TODO should be taking substr..
			return vals[0], vals[1], vals[2]
	return '', '', ''
コード例 #3
0
ファイル: engine.py プロジェクト: mrawde/cppbat
def run(prog, args):
	run = []
	if cppbat.core.settings.ENGINE == 'secure':
		run = ['pola-run', '-f', prog, '-B', '-e']
	run.append(prog)
	run.extend(args)

	print run 
	proc = popen2.Popen4(run) 

	# restrict the amount of time it gets
	# does this by sleeping and polling
	# TODO log how much it usually needs to sleep
	t = 0.0
	delta = 0.001
	while t < 0.1: # TODO parameterize this
		time.sleep(delta)
		t = t + delta
		status = proc.poll()
		if status != -1:
			break
		delta = delta * 2

	# parse output and generate return
	if status == -1: # timeout
		os.kill(proc.pid, signal.SIGTERM)
		ret_status = 'timeout'
	else: # completed
		if os.WIFEXITED(status):
			if os.WEXITSTATUS(status) == 0:
				ret_status = 'pass'
			else:
				ret_status = 'fail'
				
	# TODO probably better for output just to be a string instead of array
	# using this instead of readlines trims whitespace
	# unfortunately, it also adds an extra line so hence, the -2
	output = proc.fromchild.read().split('\n')
	try:
		result = utils.substr_rem(output[-2], 'CPPBAT value: ')
		output = output[:-2]
	except IndexError:
		result = None

	if not result:
		result = ''

	print output

	return ret_status, result, output