Beispiel #1
0
	def run(self, env):
		""" Build it. """
		result = CheckerResult(checker=self)

		filenames = [name for name in self.get_file_names(env)]
		args = [self.compiler()] + self.flags(env) + filenames + self.libs()
		[output,_,_,_]  = execute_arglist(args, env.tmpdir(),self.environment())

                has_main = re.search(r"^Linking ([^ ]*) ...$",output,re.MULTILINE)
                if has_main: self._detected_main = has_main.group(1)

		output = escape(output)
		output = self.enhance_output(env, output)
		
		# Allow server to delete created subfolders
		execute('chmod -R 0777 *', env.tmpdir())		

		# We mustn't have any warnings.
		passed = not self.has_warnings(output)	
		log  = self.build_log(output,args,set(filenames).intersection([solutionfile.path() for solutionfile in env.solution().solutionfile_set.all()]))

		# Now that submission was successfully built, try to find the main modules name again
		try:
			if passed : env.set_program(self.main_module(env))
		except self.NotFoundError as e:
			passed = not self._main_required
			log += "<pre>" + str(e) + "</pre>"

		result.set_passed(passed)
		result.set_log(log)
		return result        
Beispiel #2
0
    def run(self, env):
        """ Build it. """
        result = CheckerResult(checker=self)

        try:
            env.set_program(self.main_module(env))
        except self.NotFoundError as e:
            result.set_log(e)
            result.set_passed(False)
            return result

        filenames = [quote(name) for name in self.get_file_names(env)]
        args = [
            self.compiler()
        ] + self.output_flags(env) + self.flags(env) + filenames + self.libs()
        output = execute(args, env.tmpdir(), self.environment())[0]
        output = self.enhance_output(env, output)

        # Allow server to delete created subfolders
        execute('chmod -R 0777 *', env.tmpdir())

        # The executable has to exist and we mustn't have any warnings.
        passed = not self.has_warnings(output)
        result.set_log(
            self.build_log(
                output, args,
                set(filenames).intersection([
                    quote(solutionfile.path())
                    for solutionfile in env.solution().solutionfile_set.all()
                ])))
        result.set_passed(passed)
        return result
Beispiel #3
0
    def run(self, env):
        """ Runs tests in a special environment. Here's the actual work. 
		This runs the check in the environment ENV, returning a CheckerResult. """

        # Setup
        test_dir = env.tmpdir()
        replace = [(u"PROGRAM", env.program())] if env.program() else []
        copy_file_to_directory(self.shell_script.path, test_dir, replace=replace)

        # Run the tests -- execute dumped shell script 'script.sh'
        args = ["sh", os.path.basename(self.shell_script.name)]
        environ = {}
        environ["USER"] = env.user().get_full_name()
        environ["HOME"] = test_dir

        (output, error, exitcode) = execute(args, working_directory=test_dir, environment_variables=environ)

        result = CheckerResult(checker=self)
        if self.remove:
            output = re.sub(self.remove, "", output)
        if not self.returns_html:
            output = "<pre>" + output + "</pre>"
        result.set_log(output)
        result.set_passed(not error)

        return result
Beispiel #4
0
    def run(self, env):

        # Save save check configuration
        config_path = os.path.join(env.tmpdir(), "checks.xml")
        copy_file(self.configuration.path, config_path)

        # Run the tests
        args = [
            settings.JVM, "-cp", settings.CHECKSTYLEALLJAR, "-Dbasedir=.",
            "com.puppycrawl.tools.checkstyle.Main", "-c", "checks.xml"
        ] + [quote(name) for (name, content) in env.sources()]
        (output, error, exitcode) = execute(args, env.tmpdir())

        # Remove Praktomat-Path-Prefixes from result:
        output = re.sub(r"^" + re.escape(env.tmpdir()) + "/+",
                        "",
                        output,
                        flags=re.MULTILINE)

        result = CheckerResult(checker=self)
        result.set_log('<pre>' + escape(output) + '</pre>')

        result.set_passed(
            not error
            and not re.match('Starting audit...\nAudit done.', output) == None)

        return result
Beispiel #5
0
	def run(self, env):
		java_builder = JavaBuilder(_flags="", _libs=self.junit_version,_file_pattern=r"^.*\.[jJ][aA][vV][aA]$",_output_flags="")

		build_result = java_builder.run(env)

		if not build_result.passed:
			result = CheckerResult(checker=self)
			result.set_passed(False)
			result.set_log('<pre>' + escape(self.test_description) + '\n\n======== Test Results ======\n\n</pre><br/>\n'+build_result.log)
			return result

		environ = {}

		environ['UPLOAD_ROOT'] = settings.UPLOAD_ROOT
		environ['JAVA'] = settings.JVM
		environ['POLICY'] = os.path.join(os.path.join(os.path.dirname(os.path.dirname(__file__)),"scripts"),"junit.policy")
		environ['USE_KILL_LOG'] = "False" 
		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

		cmd = settings.JVM_SECURE  + " -cp " + settings.JAVA_LIBS[self.junit_version] + ":. " + self.runner() + " " + self.class_name
		[output, error, exitcode] = execute(cmd, env.tmpdir(),environment_variables=environ)

		result = CheckerResult(checker=self)
		
		result.set_log('<pre>' + escape(self.test_description) + '\n\n======== Test Results ======\n\n</pre><br/><pre>' + escape(output) + '</pre>')
		result.set_passed((not exitcode) and self.output_ok(output))
		return result
Beispiel #6
0
    def run(self, env):
        """ Runs tests in a special environment. Here's the actual work. 
		This runs the check in the environment ENV, returning a CheckerResult. """

        # Setup
        test_dir = env.tmpdir()
        replace = [(u'PROGRAM', env.program())] if env.program() else []
        copy_file_to_directory(self.shell_script.path,
                               test_dir,
                               replace=replace)

        # Run the tests -- execute dumped shell script 'script.sh'
        args = ["sh", os.path.basename(self.shell_script.name)]
        environ = {}
        environ['USER'] = env.user().get_full_name()
        environ['HOME'] = test_dir

        (output, error, exitcode) = execute(args,
                                            working_directory=test_dir,
                                            environment_variables=environ)

        result = CheckerResult(checker=self)
        if self.remove:
            output = re.sub(self.remove, "", output)
        if not self.returns_html:
            output = '<pre>' + output + '</pre>'
        result.set_log(output)
        result.set_passed(not error)

        return result
Beispiel #7
0
    def run(self, env):
        """ Runs tests in a special environment. Here's the actual work. 
		This runs the check in the environment ENV, returning a CheckerResult. """

        # Setup
        test_dir = env.tmpdir()
        if self.input_file: copy_file(self.input_file.path, test_dir)
        if self.output_file: copy_file(self.output_file.path, test_dir)
        replace = [(u'PROGRAM', env.program())] if env.program() else []
        copy_file_to_directory(self.shell_script.path,
                               test_dir,
                               replace=replace)
        args = ["sh", os.path.basename(self.shell_script.name)]
        environ = {}
        environ['USER'] = env.user().get_full_name()
        environ['HOME'] = test_dir

        (output, error, exitcode) = execute(args,
                                            working_directory=test_dir,
                                            environment_variables=environ)

        result = CheckerResult(checker=self)

        result.set_log(output)
        result.set_passed(not error)

        return result
Beispiel #8
0
    def run(self, env):
        """ Build it. """
        result = CheckerResult(checker=self)

        # Try to find out the main modules name with only the source files present
        try:
            env.set_program(self.main_module(env))
        except self.NotFoundError:
            pass

        filenames = [name for name in self.get_file_names(env)]
        args = [
            self.compiler()
        ] + self.output_flags(env) + self.flags(env) + filenames + self.libs()
        [output, _, _, _] = execute_arglist(args, env.tmpdir(),
                                            self.environment())

        output = escape(output)
        output = self.enhance_output(env, output)

        # Allow server to delete created subfolders
        execute('chmod -R 0777 *', env.tmpdir())

        # We mustn't have any warnings.
        passed = not self.has_warnings(output)
        log = self.build_log(
            output, args,
            set(filenames).intersection([
                solutionfile.path()
                for solutionfile in env.solution().solutionfile_set.all()
            ]))

        # Now that submission was successfully built, try to find the main modules name again
        try:
            if passed: env.set_program(self.main_module(env))
        except self.NotFoundError as e:
            # But only complain if the main method is required
            if self._main_required:
                log += "<pre>" + str(e) + "</pre>"
                passed = False

        result.set_passed(passed)
        result.set_log(log)
        return result
Beispiel #9
0
	def run(self, env):
		""" Do whatever this checker is suposed to do. """
		copy_file(self.test_case.path, env.tmpdir(), to_is_directory=True, binary=True)
		junit_class = os.path.basename(self.test_case.path).rsplit('.',1).pop(0)

		cmd = settings.JUNIT38 + " -text " + junit_class

		[output, error, exitcode] = execute(cmd, env.tmpdir())

		result = CheckerResult(checker=self)			
		result.set_log('<pre>' + escape(output) + '</pre>')
		result.set_passed(not exitcode)
		return result
Beispiel #10
0
    def run(self, env):
        """ Build it. """
        result = CheckerResult(checker=self)

        filenames = [name for name in self.get_file_names(env)]
        args = [self.compiler()] + self.flags(env) + filenames + self.libs()
        [output, _, _, _] = execute_arglist(args, env.tmpdir(),
                                            self.environment())

        has_main = re.search(r"^Linking ([^ ]*) ...$", output, re.MULTILINE)
        if has_main: self._detected_main = has_main.group(1)

        output = escape(output)
        output = self.enhance_output(env, output)

        # Allow server to delete created subfolders
        execute('chmod -R 0777 *', env.tmpdir())

        # We mustn't have any warnings.
        passed = not self.has_warnings(output)
        log = self.build_log(
            output, args,
            set(filenames).intersection([
                solutionfile.path()
                for solutionfile in env.solution().solutionfile_set.all()
            ]))

        # Now that submission was successfully built, try to find the main modules name again
        try:
            if passed: env.set_program(self.main_module(env))
        except self.NotFoundError as e:
            passed = not self._main_required
            log += "<pre>" + str(e) + "</pre>"

        result.set_passed(passed)
        result.set_log(log)
        return result
Beispiel #11
0
	def run(self, env):
		""" Build it. """
		result = CheckerResult(checker=self)

		# Try to find out the main modules name with only the source files present
		try:
			env.set_program(self.main_module(env))
		except self.NotFoundError:
			pass
		
		filenames = [name for name in self.get_file_names(env)]
		args = [self.compiler()] + self.output_flags(env) + self.flags(env) + filenames + self.libs()
		[output,_,_,_]  = execute_arglist(args, env.tmpdir(),self.environment())

		output = escape(output)
		output = self.enhance_output(env, output)
		
		# Allow server to delete created subfolders
		execute('chmod -R 0777 *', env.tmpdir())		

		# We mustn't have any warnings.
		passed = not self.has_warnings(output)	
		log  = self.build_log(output,args,set(filenames).intersection([solutionfile.path() for solutionfile in env.solution().solutionfile_set.all()]))

		# Now that submission was successfully built, try to find the main modules name again
		try:
			if passed : env.set_program(self.main_module(env))
		except self.NotFoundError as e:
			# But only complain if the main method is required
			if self._main_required:
				log += "<pre>" + str(e) + "</pre>"
				passed = False

		result.set_passed(passed)
		result.set_log(log)
		return result
Beispiel #12
0
	def run(self, env):
		""" Build it. """
		result = CheckerResult(checker=self)

		try:
			env.set_program(self.main_module(env))
		except self.NotFoundError as e:
			result.set_log(e)
			result.set_passed(False)
			return result
		
		filenames = [quote(name) for name in self.get_file_names(env)]
		args = [self.compiler()] + self.output_flags(env) + self.flags(env) + filenames + self.libs()
		output = execute(args, env.tmpdir(),self.environment())[0]
		output = self.enhance_output(env, output)
		
		# Allow server to delete created subfolders
		execute('chmod -R 0777 *', env.tmpdir())		

		# The executable has to exist and we mustn't have any warnings.
		passed = not self.has_warnings(output)	
		result.set_log(self.build_log(output,args,set(filenames).intersection([quote(solutionfile.path()) for solutionfile in env.solution().solutionfile_set.all()])))
		result.set_passed(passed)
		return result
Beispiel #13
0
    def run(self, env):
        java_builder = JavaBuilder(_flags="",
                                   _libs=self.junit_version,
                                   _file_pattern=r"^.*\.[jJ][aA][vV][aA]$",
                                   _output_flags="")

        build_result = java_builder.run(env)

        if not build_result.passed:
            result = CheckerResult(checker=self)
            result.set_passed(False)
            result.set_log(
                '<pre>' + escape(self.test_description) +
                '\n\n======== Test Results ======\n\n</pre><br/>\n' +
                build_result.log)
            return result

        environ = {}

        environ['UPLOAD_ROOT'] = settings.UPLOAD_ROOT
        environ['JAVA'] = settings.JVM
        environ['POLICY'] = os.path.join(
            os.path.join(os.path.dirname(os.path.dirname(__file__)),
                         "scripts"), "junit.policy")
        environ['USE_KILL_LOG'] = "False"
        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

        cmd = settings.JVM_SECURE + " -cp " + settings.JAVA_LIBS[
            self.junit_version] + ":. " + self.runner() + " " + self.class_name
        [output, error, exitcode] = execute(cmd,
                                            env.tmpdir(),
                                            environment_variables=environ)

        result = CheckerResult(checker=self)

        result.set_log('<pre>' + escape(self.test_description) +
                       '\n\n======== Test Results ======\n\n</pre><br/><pre>' +
                       escape(output) + '</pre>')
        result.set_passed((not exitcode) and self.output_ok(output))
        return result
Beispiel #14
0
	def run(self, env):

		# Save save check configuration
		config_path = os.path.join(env.tmpdir(), "checks.xml")
		copy_file(self.configuration.path, config_path)
		
		# Run the tests
		args = [settings.JVM, "-cp", settings.CHECKSTYLEALLJAR, "-Dbasedir=.", "com.puppycrawl.tools.checkstyle.Main", "-c", "checks.xml"] + [quote(name) for (name,content) in env.sources()]
		(output, error, exitcode) = execute(args, env.tmpdir())
		
		# Remove Praktomat-Path-Prefixes from result:
		output = re.sub(r"^"+re.escape(env.tmpdir())+"/+","",output,flags=re.MULTILINE)

		result = CheckerResult(checker=self)
		result.set_log('<pre>' + escape(output) + '</pre>')
		
		result.set_passed(not error and not re.match('Starting audit...\nAudit done.', output) == None)
		
		return result
Beispiel #15
0
	def run(self, env):
		""" Runs tests in a special environment. Here's the actual work. 
		This runs the check in the environment ENV, returning a CheckerResult. """

		# Setup
		test_dir	 = env.tmpdir()
		if self.input_file: copy_file(self.input_file.path, test_dir)
		if self.output_file: copy_file(self.output_file.path, test_dir)
		replace = [(u'PROGRAM',env.program())] if env.program() else []
		copy_file_to_directory(self.shell_script.path, test_dir, replace=replace)
		args = ["sh",  os.path.basename(self.shell_script.name)]
		environ = {}
		environ['USER'] = env.user().get_full_name()
		environ['HOME'] = test_dir
		
		(output, error, exitcode) = execute(args, working_directory=test_dir, environment_variables=environ)
		
		result = CheckerResult(checker=self)
	
		result.set_log(output)
		result.set_passed(not error)
		
		return result