def run(self, env): # Save public test cases in `tests.exp' tests_exp = os.path.join(self.tests_dir(env), "tests.exp") test_cases = string.replace( encoding.get_unicode(self.test_case.read()), u"PROGRAM", env.program()) create_file(tests_exp, test_cases) testsuite = self.testsuite_dir(env) program_name = env.program() if " " in program_name: result = self.create_result(env) result.set_log( "<pre><b class=\"fail\">Error</b>: Path to the main() - source file contains spaces.\n\nFor Java .zip submittions, the directory hierarchy of the .zip file must excactly match the package structure.\nThe default package must correspond to the .zip root directory.</pre>" ) result.set_passed(False) return result cmd = [settings.DEJAGNU_RUNTEST, "--tool", program_name, "tests.exp"] environ = {} environ['JAVA'] = settings.JVM script_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'scripts') environ['POLICY'] = join(script_dir, "praktomat.policy") environ['USER'] = env.user().get_full_name().encode( sys.getdefaultencoding(), 'ignore') environ['HOME'] = testsuite environ['UPLOAD_ROOT'] = settings.UPLOAD_ROOT [output, error, exitcode, timed_out, oom_ed] = \ execute_arglist( cmd, testsuite, environment_variables=environ, timeout=settings.TEST_TIMEOUT, fileseeklimit=settings.TEST_MAXFILESIZE, extradirs=[env.tmpdir(), script_dir] ) output = encoding.get_unicode(output) try: summary = encoding.get_unicode( open(os.path.join(testsuite, program_name + ".sum")).read()) log = encoding.get_unicode( open(os.path.join(testsuite, program_name + ".log")).read()) except: summary = "" log = "" complete_output = self.htmlize_output(output + log) result = self.create_result(env) result.set_log(complete_output, timed_out=timed_out or oom_ed) result.set_passed(not exitcode and not timed_out and not oom_ed and self.output_ok(complete_output)) return result
def run(self, env): # Save public test cases in `tests.exp' tests_exp = os.path.join(self.tests_dir(env), "tests.exp") test_cases = string.replace(encoding.get_unicode(self.test_case.read()), u"PROGRAM", env.program()) create_file(tests_exp,test_cases) testsuite = self.testsuite_dir(env) program_name = env.program() if " " in program_name: result = self.create_result(env) result.set_log("<pre><b class=\"fail\">Error</b>: Path to the main() - source file contains spaces.\n\nFor Java .zip submittions, the directory hierarchy of the .zip file must excactly match the package structure.\nThe default package must correspond to the .zip root directory.</pre>") result.set_passed(False) return result cmd = [settings.DEJAGNU_RUNTEST, "--tool", program_name, "tests.exp"] environ = {} environ['JAVA'] = settings.JVM script_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)),'scripts') environ['POLICY'] = join(script_dir,"praktomat.policy") environ['USER'] = env.user().get_full_name().encode(sys.getdefaultencoding(), 'ignore') environ['HOME'] = testsuite environ['UPLOAD_ROOT'] = settings.UPLOAD_ROOT [output, error, exitcode, timed_out, oom_ed] = \ execute_arglist( cmd, testsuite, environment_variables=environ, timeout=settings.TEST_TIMEOUT, fileseeklimit=settings.TEST_MAXFILESIZE, extradirs=[env.tmpdir(), script_dir] ) output = encoding.get_unicode(output) try: summary = encoding.get_unicode(open(os.path.join(testsuite, program_name + ".sum")).read()) log = encoding.get_unicode(open(os.path.join(testsuite, program_name + ".log")).read()) except: summary = "" log = "" complete_output = self.htmlize_output(output + log) result = self.create_result(env) result.set_log(complete_output,timed_out=timed_out or oom_ed) result.set_passed(not exitcode and not timed_out and not oom_ed and self.output_ok(complete_output)) return result
def run(self, env): # Save public test cases in `tests.exp' tests_exp = os.path.join(self.tests_dir(env), "tests.exp") test_cases = string.replace(encoding.get_unicode(self.test_case.read()), u"PROGRAM", env.program()) create_file(tests_exp,test_cases) testsuite = self.testsuite_dir(env) program_name = env.program() if " " in program_name: result = self.result() result.set_log("<pre><b class=\"fail\">Error</b>: Path to the main() - source file contains spaces.\n\nFor Java .zip submittions, the directory hierarchy of the .zip file must excactly match the package structure.\nThe default package must correspond to the .zip root directory.</pre>") result.set_passed(False) return result cmd = [settings.DEJAGNU_RUNTEST, "--tool", program_name, "tests.exp"] environ = {} environ['JAVA'] = settings.JVM environ['POLICY'] = join(join(dirname(dirname(__file__)),"scripts"),"praktomat.policy") environ['USER'] = env.user().get_full_name().encode(sys.getdefaultencoding(), 'ignore') environ['HOME'] = testsuite environ['UPLOAD_ROOT'] = settings.UPLOAD_ROOT environ['USE_KILL_LOG'] = str(settings.USE_KILL_LOG) environ['ULIMIT_FILESIZE'] = '128' # Have the checker script set a filesize-ulimit of 128kb # Specifically, this limits the DejaGNU .log file size, # and thus deals with Programs that output lots of junk [output, error, exitcode] = execute_arglist(cmd, testsuite, environment_variables=environ) output = encoding.get_unicode(output) try: summary = encoding.get_unicode(open(os.path.join(testsuite, program_name + ".sum")).read()) log = encoding.get_unicode(open(os.path.join(testsuite, program_name + ".log")).read()) except: summary = "" log = "" complete_output = output + log if error: complete_output += "ERROR: Ein TimeOut ist aufgetreten!" # Or propably somsing else happend??????? result = self.result() result.set_log(self.htmlize_output(complete_output)) result.set_passed((not error) & self.output_ok(complete_output)) return result
def run(self, env): self.setup_dirs(env) create_file(os.path.join(self.lib_dir(env), env.program() + ".exp"), u"") defs = string.replace(encoding.get_unicode(self.test_defs.read()), "PROGRAM", env.program()) # defs = string.replace(defs, "JAVA", join(join(dirname(dirname(__file__)),"scripts"),"java")) defs = string.replace(defs, "JAVA", settings.JVM_SECURE) create_file(os.path.join(self.config_dir(env), "default.exp"), defs) return self.result()
def create_file(path, content, override=True, binary=False): """ """ dirname = os.path.dirname(path) if not os.path.exists(dirname): makedirs(dirname) else: if os.path.exists(path): if override: # delete file os.remove(path) else: # throw exception raise Exception('File already exists') with open(path, 'wb') as fd: if binary: fd.write(content) else: fd.write(encoding.get_utf8(encoding.get_unicode(content))) if (gid): # chown :praktomat <path> os.chown(path, -1, gid) # rwxrwx--- access for praktomattester:praktomat os.chmod(path, 0o770)
def run(self, env): filecopy_result = self.run_file(env) if not filecopy_result.passed: return filecopy_result if self.require_safe: safe_builder = IgnoringHaskellBuilder( _flags="-XSafe", _file_pattern=r"^.*\.[hH][sS]$", _main_required=False) safe_builder._ignore = self.ignore.split(" ") + [ self.path_relative_to_sandbox() ] safe_build_result = safe_builder.run(env) if not safe_build_result.passed: result = self.create_result(env) result.set_passed(False) result.set_log( '<pre>' + escape(self.test_description) + '\n\n======== Test Results (Safe) ======\n\n</pre><br/>\n' + safe_build_result.log) return result test_builder = TestOnlyBuildingBuilder( _flags="-main-is " + self.module_name(), _libs= "test-framework test-framework-quickcheck2 test-framework-hunit") test_builder._testsuite_filename = self.path_relative_to_sandbox() test_build_result = test_builder.run(env) if not test_build_result.passed: result = self.create_result(env) result.set_passed(False) result.set_log( '<pre>' + escape(self.test_description) + '\n\n======== Test Results (Building all) ======\n\n</pre><br/>\n' + test_build_result.log) return result environ = {} environ['UPLOAD_ROOT'] = settings.UPLOAD_ROOT cmd = [ "./" + self.module_binary_name(), "--maximum-generated-tests=1000" ] [output, error, exitcode, timed_out, oom_ed] = execute_arglist(cmd, env.tmpdir(), environment_variables=environ, timeout=settings.TEST_TIMEOUT, fileseeklimit=settings.TEST_MAXFILESIZE) result = self.create_result(env) (output, truncated) = truncated_log(output) output = '<pre>' + escape( self.test_description ) + '\n\n======== Test Results ======\n\n</pre><br/><pre>' + escape( output) + '</pre>' if self.include_testcase_in_report in ["FULL", "DL"]: testsuit_template = get_template( 'checker/checker/haskell_test_framework_report.html') output += testsuit_template.render({ 'showSource': (self.include_testcase_in_report == "FULL"), 'testfile': self.file, 'testfilename': self.path_relative_to_sandbox(), 'testfileContent': encoding.get_unicode(self.file.read()) }) result.set_log(output, timed_out=timed_out or oom_ed, truncated=truncated) result.set_passed(not exitcode and not timed_out and not oom_ed and self.output_ok(output) and not truncated) return result
def content(self): """docstring for content""" if self.isBinary(): return "Binary Data" else: return encoding.get_unicode(self.file.read())
def copy_file(from_file_path, to_file_path, replace=[], override=True): """ """ with open(from_file_path) as fd: content = encoding.get_unicode(fd.read()) create_file(to_file_path, content, replace=replace, override=override)
def run(self, env): filecopy_result = self.run_file(env) if not filecopy_result.passed: return filecopy_result if self.require_safe: safe_builder = IgnoringHaskellBuilder(_flags="-XSafe", _file_pattern = r"^.*\.[hH][sS]$", _main_required=False) safe_builder._ignore=self.ignore.split(" ") + [self.path_relative_to_sandbox()] safe_build_result = safe_builder.run(env) if not safe_build_result.passed: result = self.create_result(env) result.set_passed(False) result.set_log('<pre>' + escape(self.test_description) + '\n\n======== Test Results (Safe) ======\n\n</pre><br/>\n'+safe_build_result.log) return result test_builder = TestOnlyBuildingBuilder(_flags="-main-is "+self.module_name(), _libs="test-framework test-framework-quickcheck2 test-framework-hunit") test_builder._testsuite_filename=self.path_relative_to_sandbox() test_build_result = test_builder.run(env) if not test_build_result.passed: result = self.create_result(env) result.set_passed(False) result.set_log('<pre>' + escape(self.test_description) + '\n\n======== Test Results (Building all) ======\n\n</pre><br/>\n'+test_build_result.log) return result environ = {} environ['UPLOAD_ROOT'] = settings.UPLOAD_ROOT cmd = ["./"+self.module_binary_name(), "--maximum-generated-tests=5000"] [output, error, exitcode,timed_out, oom_ed] = execute_arglist(cmd, env.tmpdir(),environment_variables=environ,timeout=settings.TEST_TIMEOUT,fileseeklimit=settings.TEST_MAXFILESIZE) result = self.create_result(env) (output,truncated) = truncated_log(output) output = '<pre>' + escape(self.test_description) + '\n\n======== Test Results ======\n\n</pre><br/><pre>' + escape(output) + '</pre>' if self.include_testcase_in_report in ["FULL","DL"]: testsuit_template = get_template('checker/checker/haskell_test_framework_report.html') output += testsuit_template.render(Context({'showSource' : (self.include_testcase_in_report=="FULL"), 'testfile' : self.file, 'testfilename' : self.path_relative_to_sandbox(), 'testfileContent': encoding.get_unicode(self.file.read())})) result.set_log(output,timed_out=timed_out or oom_ed,truncated=truncated) result.set_passed(not exitcode and not timed_out and not oom_ed and self.output_ok(output) and not truncated) return result
def contains_NUL_char(bytestring): return encoding.get_unicode(bytestring).find("\x00") >= 0