/** * The package were third-party libraries are shaded into * @return */ public static String getShadedPackageForThirdPartyLibraries(){ return getEvoSuitePackage() + "." +SHADED; }
private static String[] getEvoSuitePackages() { return new String[] { PackageInfo.getEvoSuitePackage(), "org.exsyst", "de.unisb.cs.st.testcarver", "de.unisb.cs.st.evosuite", "testing.generation.evosuite", "de.unisl.cs.st.bugex" }; }
/** * The package name of the shaded EvoSutie. Used only for when testing EvoSuite * @return */ public static String getShadedEvoSuitePackage(){ String shaded = SHADED + "."; String evo = getEvoSuitePackage(); if(evo.startsWith(shaded)){ return evo; } else { return shaded + evo; } }
public static boolean isCurrentlyShaded(){ return getEvoSuitePackage().startsWith(SHADED); } }
public static String getEvoSuitePackageWithSlash(){ return getEvoSuitePackage().replace('.', '/'); }
public static boolean isEvoSuiteClass(Class<?> c) { return c.getName().startsWith(PackageInfo.getEvoSuitePackage()); //|| c.getName().equals("java.lang.String"); // This is now handled in addDependencyClass }
private static boolean isValidSource(String sourceClass) { return (!sourceClass.startsWith(PackageInfo.getEvoSuitePackage() + ".") || sourceClass.startsWith(PackageInfo.getEvoSuitePackage() + ".runtime.")) && !sourceClass.equals(URLClassLoader.class.getName()) && // Classloaders may differ, e.g. when running with ant !sourceClass.startsWith(RegExp.class.getPackage().getName()) && !sourceClass.startsWith("java.lang.System") && !sourceClass.startsWith("java.lang.String") && !sourceClass.startsWith("sun.") && !sourceClass.startsWith("com.sun.") && !sourceClass.startsWith("jdk.internal."); }
private boolean isValidSource(String sourceClass){ return (! sourceClass.startsWith(PackageInfo.getEvoSuitePackage()+".") || sourceClass.startsWith(PackageInfo.getEvoSuitePackage()+".runtime.")) && !sourceClass.equals(URLClassLoader.class.getName()) && // Classloaders may differ, e.g. when running with ant !sourceClass.startsWith(RegExp.class.getPackage().getName()) && !sourceClass.startsWith("java.lang.System") && !sourceClass.startsWith("java.lang.String") && !sourceClass.startsWith("java.lang.Class") && !sourceClass.startsWith("sun.") && !sourceClass.startsWith("com.sun.") && !sourceClass.startsWith("jdk.internal.") && !sourceClass.startsWith("<evosuite>"); }
public static String[] getPackagesShouldNotBeInstrumented() { //explicitly blocking client projects such as specmate is only a //temporary solution, TODO allow the user to specify //packages that should not be instrumented return new String[] { "java.", "javax.", "sun.", PackageInfo.getEvoSuitePackage(), "org.exsyst", "de.unisb.cs.st.testcarver", "de.unisb.cs.st.evosuite", "org.uispec4j", "de.unisb.cs.st.specmate", "org.xml", "org.w3c", "testing.generation.evosuite", "com.yourkit", "com.vladium.emma.", "daikon.", // Need to have these in here to avoid trouble with UnsatisfiedLinkErrors on Mac OS X and Java/Swing apps "apple.", "com.apple.", "com.sun", "org.junit", "junit.framework", "org.apache.xerces.dom3", "de.unisl.cs.st.bugex", "corina.cross.Single" // I really don't know what is wrong with this class, but we need to exclude it }; }
public static boolean isTargetProject(String className) { return (className.startsWith(Properties.PROJECT_PREFIX) || (!Properties.TARGET_CLASS_PREFIX .isEmpty() && className.startsWith(Properties.TARGET_CLASS_PREFIX))) && !className.startsWith("java.") && !className.startsWith("sun.") && !className.startsWith(PackageInfo.getEvoSuitePackage()) && !className.startsWith("org.exsyst") && !className.startsWith("de.unisb.cs.st.evosuite") && !className.startsWith("de.unisb.cs.st.specmate") && !className.startsWith("javax.") && !className.startsWith("org.xml") && !className.startsWith("org.w3c") && !className.startsWith("apple.") && !className.startsWith("com.apple.") && !className.startsWith("org.omg.") && !className.startsWith("sunw.") && !className.startsWith("org.jcp.") && !className.startsWith("org.ietf.") && !className.startsWith("daikon."); }
/** * If the application is using a SLF4 compliant logging framework, check * if it has been configured. If so, keep the logging as it is. * On the other hand, if no configuration/framework is used, then mute * the default logging (Logback) of the EvoSuite modules. * */ public static void setLoggingForJUnit(){ if(Properties.ENABLE_ASSERTS_FOR_EVOSUITE){ //if we are debugging, we don't want to switch off the logging return; } LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); if(isDefaultLoggingConfiguration(context)){ Logger root = LoggerFactory.getLogger(PackageInfo.getEvoSuitePackage()); if(root != null && root instanceof ch.qos.logback.classic.Logger){ ((ch.qos.logback.classic.Logger) root).setLevel(Level.OFF); } } }
private static void makeShadedCopy(){ String content = null; try { content = new Scanner(new File(resourceFolder + jdkFile)).useDelimiter("\\Z").next(); } catch (Exception e) { logger.error("Error when reading JDK file",e); return; } String shadedContent = content.replace(PackageInfo.getEvoSuitePackage(), PackageInfo.getShadedEvoSuitePackage()); File shadedFile = new File(resourceFolder+shadedJdkFile); if(shadedFile.exists()){ shadedFile.delete(); } try (PrintWriter out = new PrintWriter(shadedFile)) { out.write(shadedContent); } catch (Exception e){ logger.error("Error when making shaded copy"); } }
/** * <p> * getPackagesShouldNotBeInstrumented * </p> * * @return the names of class packages EvoSuite is not going to instrument */ public static String[] getPackagesShouldNotBeInstrumented() { //explicitly blocking client projects such as specmate is only a //temporary solution, TODO allow the user to specify //packages that should not be instrumented return new String[] { "java.", "javax.", "sun.", PackageInfo.getEvoSuitePackage(), "org.exsyst", "de.unisb.cs.st.testcarver", "de.unisb.cs.st.evosuite", "org.uispec4j", "de.unisb.cs.st.specmate", "org.xml", "org.w3c", "testing.generation.evosuite", "com.yourkit", "com.vladium.emma.", "daikon.", // Need to have these in here to avoid trouble with UnsatisfiedLinkErrors on Mac OS X and Java/Swing apps "apple.", "com.apple.", "com.sun", "org.junit", "junit.framework", "org.apache.xerces.dom3", "de.unisl.cs.st.bugex", "corina.cross.Single" // I really don't know what is wrong with this class, but we need to exclude it }; }
/** * Get project's dependencies * * @param project * @return */ public static List<String> getDependencyPathElements(MavenProject project) { List<String> dependencyArtifacts = new ArrayList<String>(); project.getDependencyArtifacts() .stream() .filter(element -> !element.isOptional()) // FIXME do we really need to check the 'scope'? //.filter(element -> element.getScope().equals(scope)) .filter(element -> element.getFile().exists()) .filter(element -> !element.getGroupId().equals(PackageInfo.getEvoSuitePackage())) .filter(element -> !element.getGroupId().equals("junit")) .forEach(element -> dependencyArtifacts.add(element.getFile().getAbsolutePath())); return dependencyArtifacts; }
private void registerObjectsClassName(final Object receiver) { if (receiver instanceof Class) //this can only happen, if there is a static method call { final Class<?> c = (Class<?>) receiver; this.oidClassNames.add(c.getName().replace(PackageInfo.getEvoSuitePackage()+".testcarver.wrapper.", "")); //.replaceFirst("\\$\\d+$", "")); } else if (this.isPlain(receiver)) { // we don't need fully qualified name for plain types // TODO: I don't understand why we would want to shorten the name if it's a primitive. // It makes it more difficult later to identify the classes contained in the log. this.oidClassNames.add(receiver.getClass().getName());//.replaceFirst("\\$\\d+$", "")); // this.oidClassNames.add(receiver.getClass().getSimpleName());//.replaceFirst("\\$\\d+$", "")); } else if (isProxy(receiver) || isAnonymous(receiver)) { // TODO what if there is more than one interface? final Class<?> c = receiver.getClass(); final Class<?>[] interfaces = c.getInterfaces(); if(interfaces.length == 0) { // If there are no interfaces, try superclass? this.oidClassNames.add(c.getSuperclass().getName()); } else { this.oidClassNames.add(interfaces[0].getName()); } } else { String name = receiver.getClass().getName().replace(PackageInfo.getEvoSuitePackage()+".testcarver.wrapper.", ""); this.oidClassNames.add(name);//.replaceFirst("\\$\\d+$", "")); } }
public static boolean shouldSkip(ExecutionResult result, int exceptionPosition){ if (exceptionPosition >= result.test.size()) { // Timeouts are put after the last statement if the process was forcefully killed return true; } //not interested in security exceptions when Sandbox is active Throwable t = result.getExceptionThrownAtPosition(exceptionPosition); if (t instanceof SecurityException && Properties.SANDBOX){ return true; } /* Ignore exceptions thrown in the test code itself. Eg, due to mutation we can end up with tests like: Foo foo = null: foo.bar(); */ if (t instanceof CodeUnderTestException){ return true; } if (t.getStackTrace() != null && t.getStackTrace().length > 0 && t.getStackTrace()[0] != null) { // This is to cover cases not handled by CodeUnderTestException, or if bug in EvoSuite itself if(t.getStackTrace()[0].getClassName().startsWith(PackageInfo.getEvoSuitePackage()+".testcase")) return true; // Enum valueOf exceptions are not interesting, they just result from invalid strings if(t.getStackTrace()[0].getClassName().startsWith(Enum.class.getCanonicalName()) && t.getStackTrace()[0].getMethodName().startsWith("valueOf")) return true; } return false; }
@Override public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { String classWithDots = className.replace('/', '.'); if(!active || !RuntimeInstrumentation.checkIfCanInstrument(classWithDots) || classWithDots.startsWith(PackageInfo.getEvoSuitePackage())){ return classfileBuffer; } else { //ClassResetter.getInstance().setClassLoader(loader); ClassReader reader = new ClassReader(classfileBuffer); synchronized(instrumentedClasses){ instrumentedClasses.add(classWithDots); } logger.debug("Going to instrument: "+classWithDots); if(instrumenter.isAlreadyInstrumented(new ClassReader(classfileBuffer))) { logger.debug("Skipping transformation of {} as it is already instrumented", classWithDots); return classfileBuffer; } return instrumenter.transformBytes(loader, className, reader, false); // TODO: Need to set skip instrumentation for test class } }
if (e.toString().contains( PackageInfo.getEvoSuitePackage()+".regression.ObjectFields")) { statistics.permissionAllowed(perm); return;
if (element.getClassName().startsWith(PackageInfo.getEvoSuitePackage()+".testcase")) { return null;
@Test public void testGetEvoSuitePackage() throws Exception { assertEquals("org.evosuite",PackageInfo.getEvoSuitePackage()); }