def _exec(self, com, parameters, cwd=None): cwd = self.mutants_dir if cwd is None else cwd classpath = generate_classpath([ '.', MUJAVA, COMMONSIO, OPENJAVA, self.jdk.tools, junit.JUNIT, junit.HAMCREST, self.classpath ]) command = [self.jdk.java, '-classpath', classpath, com] command += parameters try: env = os.environ.copy() env['CLASSPATH'] = classpath return subprocess.check_output(command, shell=False, cwd=cwd, stderr=subprocess.DEVNULL, env=env, timeout=(5 * 60)) except subprocess.TimeoutExpired: print('# ERROR: muJava timed out.') except subprocess.CalledProcessError as e: print('# ERROR: {0} returned non-zero exit status.\n{1}'.format( 'muJava', e.output.decode('unicode_escape')))
def run_soot(self, mid="ORIGINAL"): override_file_dir = os.path.abspath( os.path.join(self.options.mutants, self.target['directory'], mid)) with_override_file_classpath = generate_classpath( [override_file_dir, self.classes_dir]) soot = Soot(self.project_dir, with_override_file_classpath) soot.exec(self.target['class'], os.path.join(override_file_dir, 'opt'), jimple=False)
def _compile(self): os.mkdir(self.tests_classes) classpath = generate_classpath([self.classpath, self.tests_src, JUNIT, HAMCREST]) for java_test_file in sorted(get_java_files(self.tests_src)): self.jdk.run_javac(os.path.join(self.tests_src, java_test_file), 5 * 60, self.tests_src, '-classpath', classpath, '-d', self.tests_classes) return self._test_classes()
def exec(self, suite_dir, suite_classes_dir, sut_class, test_class, timeout=TIMEOUT): classpath = generate_classpath([ JMOCKIT, JUNIT, HAMCREST, EVOSUITE_RUNTIME, suite_classes_dir, self.classpath ]) return self._exec(suite_dir, sut_class, test_class, classpath, '.', timeout)
def _compile(self): self.suite_classes_dir = os.path.join(self.suite_dir, 'classes') self._create_dirs(self.suite_classes_dir) classpath = generate_classpath([ self.classpath, self.suite_dir, JUNIT, HAMCREST, self.suite_classes_dir ] + self._extra_classpath()) params = '-classpath', classpath, '-d', self.suite_classes_dir self.java.exec_java_all( [os.path.join(self.suite_dir, f) for f in self._get_java_files()], self._get_suite_dir(), self.java.get_env(), COMPILE_TIMEOUT * len(self._get_java_files()), *params)
def _run_test(self, test_suite, test_classes_dir, test_class, mutant_classpath='', timeout=(60 * 3)): classpath = generate_classpath([ JMOCKIT, JUNIT, HAMCREST, EVOSUITE, test_classes_dir, mutant_classpath, self.classpath, ]) coverage_source_dirs = self.source_dir if os.path.exists( os.path.join(mutant_classpath, self.sut_class.replace('.', os.sep) + '.java')): coverage_source_dirs = mutant_classpath command = [ self.jdk.java, '-classpath', classpath, '-Dcoverage-classes=' + self.sut_class, '-Dcoverage-output=html', '-Dcoverage-metrics=line', '-Dcoverage-srcDirs=' + coverage_source_dirs, 'org.junit.runner.JUnitCore', test_class ] start = time.time() try: output = subprocess.check_output(command, shell=False, cwd=test_suite, stderr=subprocess.DEVNULL, timeout=timeout) return (_extract_results_ok(output.decode('unicode_escape')), time.time() - start) except subprocess.CalledProcessError as e: return (_extract_results(e.output.decode('unicode_escape')), time.time() - start) except subprocess.TimeoutExpired: elapsed_time = time.time() - start print("# ERROR: Run JUnit tests timed out. {0} seconds".format( elapsed_time)) return (0, 0, set()), elapsed_time
def run_impactanalysis(self): classpath = generate_classpath([ #self.original, #self.mutant, SAFIRA, self.classpath, ]) #if os.path.exists( # os.path.join(mutant_classpath, # self.sut_class.replace('.', os.sep) + '.java')): # coverage_source_dirs = mutant_classpath # path_to_targets = self.original + " " + self.mutant command = [ self.jdk.java, '-classpath', classpath, 'saferefactor.safira.SafiraStart', self.original, self.mutant ] start = time.time() try: output = subprocess.check_output(command, shell=False, #cwd=test_suite, stderr=subprocess.STDOUT, timeout=60*3) list_methods, list_constructors = _extract_results_ok(output.decode('unicode_escape')) return list_methods, list_constructors, time.time() - start except subprocess.CalledProcessError as e: print("# ERROR: Run Safira Impact Analysis Call Process: {0} ".format( e.cmd )) print(e.output) return (_extract_results(e.output.decode('unicode_escape')), time.time() - start) except subprocess.TimeoutExpired: elapsed_time = time.time() - start print("# ERROR: Run Safira Impact Analysis timed out. {0} seconds".format( elapsed_time )) return (0, 0, set()), elapsed_time
def _exec(self, parameters, cwd=None): cwd = self.mutants_dir if cwd is None else cwd classpath = generate_classpath(['.', self.classpath, self.jdk.rt]) command = [MAJOR ] command += parameters print(classpath) try: env = {} return subprocess.check_output(command, shell=False, cwd=cwd, env=env, timeout=(5 * 60)) except subprocess.TimeoutExpired: print('# ERROR: Major time out.') except subprocess.CalledProcessError as e: print('# ERROR: {0} returned non-zero exit status.\n{1}'.format( 'major', e.output.decode('unicode_escape')))
def _exec_major(self, java_file, source_dir, classpath, operators='ALL'): export_dir = os.path.join(self.mutants_dir, '.tmp') dest_dir = os.path.join(export_dir, 'target', 'classes') if os.path.exists(export_dir): shutil.rmtree(export_dir) os.makedirs(dest_dir) print(self.jdk.rt) parameters = [ '-XMutator:' + operators, '-J-Dmajor.export.context=true', '-J-Dmajor.export.mutants=true', '-J-Dmajor.export.directory=' + export_dir, '-cp', generate_classpath([classpath, self.jdk.rt]), '-d', dest_dir, java_file ] self._exec(parameters, cwd=source_dir)