|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
Coverage seems wrong (Cobertura 1.9.3, Tomcat 6.0.18, Java 1.6)Hi! I am using Cobertura to measure the test coverage of a large web project (more than 10000 classes). Environment: Cobertura 1.9.3 Tomcat 6.0.18 on Windows Sun JDK 1.6.0_16-b01 I observe the following: (cobertura.ser copied to Tomcat base dir.) On Tomcat Tomcat start (catalina.bat), there is nothing special When I access the application, I get two messages: - loading coverage data for xxx classes - writing coverage data for xxx classes The second step looked odd for me, but I found a note on the mailing list (and a piece of code) which explains this is necessary to load some classes on startup, not in the shutdown hook. Next I played a bit with the application to create some coverage data. When I shut down Tomcat (via catalina.bat), the file cobertura.ser is written the second time (verified by file time stamp, and you can see the file growing while it is written). But: The coverage data looks wrong. Some lines are reported as covered, but most of the lines are reported as uncovered, even lines which are executed during initializaiton of the application. Does anybody have an idea what could be wrong? Regards, Roger ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Cobertura-devel mailing list Cobertura-devel@... https://lists.sourceforge.net/lists/listinfo/cobertura-devel |
|
|
Re: Coverage seems wrong (Cobertura 1.9.3, Tomcat 6.0.18, Java 1.6)It is not apparent what may be wrong. Is there any error in the log? If you can, show the script you are using to instrument the war. -----Original Message----- From: Roger Butenuth [mailto:RButenuth@...] Sent: Wednesday, October 14, 2009 1:18 PM To: cobertura-devel@... Subject: [Cobertura-devel] Coverage seems wrong (Cobertura 1.9.3, Tomcat 6.0.18, Java 1.6) Hi! I am using Cobertura to measure the test coverage of a large web project (more than 10000 classes). Environment: Cobertura 1.9.3 Tomcat 6.0.18 on Windows Sun JDK 1.6.0_16-b01 I observe the following: (cobertura.ser copied to Tomcat base dir.) On Tomcat Tomcat start (catalina.bat), there is nothing special When I access the application, I get two messages: - loading coverage data for xxx classes - writing coverage data for xxx classes The second step looked odd for me, but I found a note on the mailing list (and a piece of code) which explains this is necessary to load some classes on startup, not in the shutdown hook. Next I played a bit with the application to create some coverage data. When I shut down Tomcat (via catalina.bat), the file cobertura.ser is written the second time (verified by file time stamp, and you can see the file growing while it is written). But: The coverage data looks wrong. Some lines are reported as covered, but most of the lines are reported as uncovered, even lines which are executed during initializaiton of the application. Does anybody have an idea what could be wrong? Regards, Roger ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Cobertura-devel mailing list Cobertura-devel@... https://lists.sourceforge.net/lists/listinfo/cobertura-devel ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Cobertura-devel mailing list Cobertura-devel@... https://lists.sourceforge.net/lists/listinfo/cobertura-devel |
|
|
Antwort: RE: Coverage seems wrong (Cobertura 1.9.3, Tomcat 6.0.18, Java 1.6)Hi!
We are not working with a WAR-File. The project consists of several Eclipse-(sub)-projects. The sub projects are instrumented with ant: <cobertura-instrument datafile="${QS}/cobertura/cobertura.ser" maxmemory="1024M" todir= "${VERSION_LOKAL}/Basis/PackagesModel/classes_instr"> <fileset dir="${VERSION_LOKAL}/Basis/PackagesModel/classes"> <include name="**/*.class" /> </fileset> </cobertura-instrument> A second task copies all classes to WEB-INF/classes: <fastCopy sourceDirectory= "${VERSION_LOKAL}/Basis/PackagesModel/classes" destinationDirectory= "${VERSION_LOKAL}/Unversioned/deploy/web-root/WEB-INF/classes" /> <fastCopy sourceDirectory= "${VERSION_LOKAL}/Basis/PackagesModel/classes_instr" destinationDirectory= "${VERSION_LOKAL}/Unversioned/deploy/web-root/WEB-INF/classes" /> First the non instrumented classes, after that the instrumented classes. "fastCopy" is an ant task that copies about two times faster than the original ant task. It is necessary to copy the non instrumented classes first because otherwise the interfaces are missing in WEB-INF/classes (nothing to instrument in interfaces...). The fastCopy overwrites files, so this should work. I checked some classes in WEB-INF/classes, they have the same size as in classes_instr, so I assume I really have instrumented classes in WEB-INF/classes. (Instrumented size vs. non instrumented size is about factor 2.) After some more tests I have one error message on the console: >>>>>>>>>> INFO: Stopping Coyote HTTP/1.1 on http-2280 15.10.2009 10:42:40 org.apache.catalina.loader.WebappClassLoader loadClass INFO: Illegal access: this web application instance has been stopped already. Could not load net.abit.base.support.Processing. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact. java.lang.IllegalStateException at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1273) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) at net.abit.base.stack.PollingThread.startProcessingLoop(PollingThread.java:451) at net.abit.base.stack.PollingThread.run(PollingThread.java:293) 15.10.2009 10:42:41 org.apache.catalina.loader.WebappClassLoader findResourceInternal INFO: Illegal access: this web application instance has been stopped already. Could not load cobertura.properties. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact. 15.10.2009 10:42:41 org.apache.catalina.loader.WebappClassLoader findResourceInternal INFO: Illegal access: this web application instance has been stopped already. Could not load cobertura.properties. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact. <<<<<<<<<< I changed the application, now Processing is loaded on startup, not shutdown, but this solved only a part of the problem, new log: >>>>>>>>>> 15.10.2009 11:47:51 org.apache.coyote.http11.Http11Protocol destroy INFO: Stopping Coyote HTTP/1.1 on http-2280 15.10.2009 11:47:52 org.apache.catalina.loader.WebappClassLoader findResourceInternal INFO: Illegal access: this web application instance has been stopped already. Could not load cobertura.properties. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact. 15.10.2009 11:47:52 org.apache.catalina.loader.WebappClassLoader findResourceInternal INFO: Illegal access: this web application instance has been stopped already. Could not load cobertura.properties. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact. <<<<<<<<<< I placed a file cobertura.properties in the class path, this avoids the message in the log. :-) Unfortunately the coverage data is still wrong. :-( When I look into the coverage data, it looks like coverage runs for a really short time and than stops completely: Some code exetuted early in the initialization process of the aplication is covered, but all code executed later is not covered. Could be some thread or class loader problem, but I have no idea where to search next. Regards, Roger "John W. Lewis" <JohnW.Lewis@sas. com> An Roger Butenuth 15.10.2009 01:32 <RButenuth@...>, "cobertura-devel@... .net" <cobertura-devel@... .net> Kopie Thema RE: [Cobertura-devel] Coverage seems wrong (Cobertura 1.9.3, Tomcat 6.0.18, Java 1.6) It is not apparent what may be wrong. Is there any error in the log? If you can, show the script you are using to instrument the war. -----Original Message----- From: Roger Butenuth [mailto:RButenuth@...] Sent: Wednesday, October 14, 2009 1:18 PM To: cobertura-devel@... Subject: [Cobertura-devel] Coverage seems wrong (Cobertura 1.9.3, Tomcat 6.0.18, Java 1.6) Hi! I am using Cobertura to measure the test coverage of a large web project (more than 10000 classes). Environment: Cobertura 1.9.3 Tomcat 6.0.18 on Windows Sun JDK 1.6.0_16-b01 I observe the following: (cobertura.ser copied to Tomcat base dir.) On Tomcat Tomcat start (catalina.bat), there is nothing special When I access the application, I get two messages: - loading coverage data for xxx classes - writing coverage data for xxx classes The second step looked odd for me, but I found a note on the mailing list (and a piece of code) which explains this is necessary to load some classes on startup, not in the shutdown hook. Next I played a bit with the application to create some coverage data. When I shut down Tomcat (via catalina.bat), the file cobertura.ser is written the second time (verified by file time stamp, and you can see the file growing while it is written). But: The coverage data looks wrong. Some lines are reported as covered, but most of the lines are reported as uncovered, even lines which are executed during initializaiton of the application. Does anybody have an idea what could be wrong? Regards, Roger ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Cobertura-devel mailing list Cobertura-devel@... https://lists.sourceforge.net/lists/listinfo/cobertura-devel |
|
|
|
|
|
Re: Coverage seems wrong (Cobertura 1.9.3, Tomcat 6.0.18, Java 1.6)Is cobertura.jar in Tomcat’s lib directory? Or is it bundled
with the application. It should be in the lib directory. From: Roger Butenuth
[mailto:RButenuth@...]
------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Cobertura-devel mailing list Cobertura-devel@... https://lists.sourceforge.net/lists/listinfo/cobertura-devel |
|
|
Antwort: RE: Coverage seems wrong (Cobertura 1.9.3, Tomcat 6.0.18, Java 1.6)Hi!
cobertura.jar is in the WEB-INF/lib directory. I move it to apache-tomcat-6.0.18/lib and give it another try, this should change the classlaoder used, Roger "John W. Lewis" <JohnW.Lewis@sas. com> An Roger Butenuth 15.10.2009 22:06 <RButenuth@...>, "cobertura-devel@... .net" <cobertura-devel@... .net> Kopie Thema RE: [Cobertura-devel] Coverage seems wrong (Cobertura 1.9.3, Tomcat 6.0.18, Java 1.6) Is cobertura.jar in Tomcat’s lib directory? Or is it bundled with the application. It should be in the lib directory. From: Roger Butenuth [mailto:RButenuth@...] Sent: Thursday, October 15, 2009 4:04 PM To: cobertura-devel@... Cc: John W. Lewis Subject: RE: [Cobertura-devel] Coverage seems wrong (Cobertura 1.9.3, Tomcat 6.0.18, Java 1.6) Hi! I did some more research, first of all I added some debug code to ProjectData: ### Eclipse Workspace Patch 1.0 #P cobertura Index: src/net/sourceforge/cobertura/coveragedata/ProjectData.java =================================================================== --- src/net/sourceforge/cobertura/coveragedata/ProjectData.java (revision 689) +++ src/net/sourceforge/cobertura/coveragedata/ProjectData.java (working copy) @@ -53,6 +53,11 @@ /** This collection is used for quicker access to the list of classes. */ private Map classes = new HashMap(); + public ProjectData() { + System.out.println("=== thread=" + Thread.currentThread().getName()+ ", created new ProjectData=" + System.identityHashCode(this)); + new Exception("Just for stacktrace").printStackTrace(System.out); + } + public void addClassData(ClassData classData) { lock.lock(); @@ -348,6 +353,8 @@ synchronized (dataFile.getPath().intern() ) { FileLocker fileLocker = new FileLocker(dataFile); + System.out.println("===>>> save project data, thread=" + Thread.currentThread().getName() + + ", projectDataToSave=" + System.identityHashCode(projectDataToSave)); try { // Read the old data, merge our current data into it, then @@ -368,6 +375,8 @@ } finally { + System.out.println("===<<< save project data, thread=" + Thread.currentThread().getName() + + ", projectDataToSave=" + System.identityHashCode(projectDataToSave)); // Release the file lock fileLocker.release(); } Then I started Tomcat, started the application (just login and logout), terminated Tomcat. The resulting output (I started with a missing cobertura.ser to make things faster), comments bold. === thread=main, created new ProjectData=A 9031454 [added letters to hashCodes] <--- ProjectData A, as expected java.lang.Exception: Just for stacktrace at net.sourceforge.cobertura.coveragedata.ProjectData.<init>(ProjectData.java:58) at net.sourceforge.cobertura.coveragedata.ProjectData.getGlobalProjectData(ProjectData.java:256) at net.abit.viewbase.servlet.AbitContextListener.<init>(AbitContextListener.java:26) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at java.lang.Class.newInstance0(Class.java:355) at java.lang.Class.newInstance(Class.java:308) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3787) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342) === thread=main, created new ProjectData=B 24962279 <- ProjectData B, created as expected, but never written to disk! java.lang.Exception: Just for stacktrace at net.sourceforge.cobertura.coveragedata.ProjectData.<init>(ProjectData.java:58) at net.sourceforge.cobertura.coveragedata.ProjectData.saveGlobalProjectData(ProjectData.java:312) at net.sourceforge.cobertura.coveragedata.ProjectData.initialize(ProjectData.java:274) at net.sourceforge.cobertura.coveragedata.ProjectData.getGlobalProjectData(ProjectData.java:257) at net.abit.viewbase.servlet.AbitContextListener.<init>(AbitContextListener.java:26) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at java.lang.Class.newInstance0(Class.java:355) at java.lang.Class.newInstance(Class.java:308) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3787) ===>>> save project data, thread=main, projectDataToSave=A 9031454 Cobertura: Loaded information on 13 classes. Cobertura: Saved information on 13 classes. ===<<< save project data, thread=main, projectDataToSave=A 9031454 [application is running] AbitContextListener.contextDestroyed() - start AbitContextListener.contextDestroyed() - end === thread=main, created new ProjectData=C 20827989 <- Here seems to be the problem: new ProjectData C, but where is B gone? java.lang.Exception: Just for stacktrace at net.sourceforge.cobertura.coveragedata.ProjectData.<init>(ProjectData.java:58) at net.sourceforge.cobertura.coveragedata.ProjectData.getGlobalProjectData(ProjectData.java:256) at net.abit.base.stack.Job.<clinit>(Job.java:29) at sun.misc.Unsafe.ensureClassInitialized(Native Method) at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:25) at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:122) at java.lang.reflect.Field.acquireFieldAccessor(Field.java:918) at java.lang.reflect.Field.getFieldAccessor(Field.java:899) at java.lang.reflect.Field.set(Field.java:657) at org.apache.catalina.loader.WebappClassLoader.clearReferences(WebappClassLoader.java:1644) at org.apache.catalina.loader.WebappClassLoader.stop(WebappClassLoader.java:1524) at org.apache.catalina.loader.WebappLoader.stop(WebappLoader.java:707) at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4557) === thread=main, created new ProjectData=D 16179550 <- D as replacement for C, as expected java.lang.Exception: Just for stacktrace at net.sourceforge.cobertura.coveragedata.ProjectData.<init>(ProjectData.java:58) at net.sourceforge.cobertura.coveragedata.ProjectData.saveGlobalProjectData(ProjectData.java:312) at net.sourceforge.cobertura.coveragedata.ProjectData.initialize(ProjectData.java:274) at net.sourceforge.cobertura.coveragedata.ProjectData.getGlobalProjectData(ProjectData.java:257) at net.abit.base.stack.Job.<clinit>(Job.java:29) at sun.misc.Unsafe.ensureClassInitialized(Native Method) at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:25) at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:122) at java.lang.reflect.Field.acquireFieldAccessor(Field.java:918) at java.lang.reflect.Field.getFieldAccessor(Field.java:899) at java.lang.reflect.Field.set(Field.java:657) ===>>> save project data, thread=main, projectDataToSave=C 20827989 <- C is saved, but nearly nothing happened between creation and save Cobertura: Loaded information on 13 classes. Cobertura: Saved information on 13 classes. ===<<< save project data, thread=main, projectDataToSave=C 20827989 === thread=Thread-13, created new ProjectData=E 2862744 java.lang.Exception: Just for stacktrace at net.sourceforge.cobertura.coveragedata.ProjectData.<init>(ProjectData.java:58) at net.sourceforge.cobertura.coveragedata.ProjectData.saveGlobalProjectData(ProjectData.java:312) at net.sourceforge.cobertura.coveragedata.SaveTimer.run(SaveTimer.java:31) at java.lang.Thread.run(Thread.java:619) === thread=Thread-1, created new ProjectData=F 30649454 java.lang.Exception: Just for stacktrace at net.sourceforge.cobertura.coveragedata.ProjectData.<init>(ProjectData.java:58) at net.sourceforge.cobertura.coveragedata.ProjectData.saveGlobalProjectData(ProjectData.java:312) at net.sourceforge.cobertura.coveragedata.SaveTimer.run(SaveTimer.java:31) at java.lang.Thread.run(Thread.java:619) ===>>> save project data, thread=Thread-13, projectDataToSave=D 16179550 Cobertura: Loaded information on 13 classes. Cobertura: Saved information on 13 classes. ===<<< save project data, thread=Thread-13, projectDataToSave=D 16179550 ===>>> save project data, thread=Thread-1, projectDataToSave=E 2862744 Cobertura: Loaded information on 13 classes. Cobertura: Saved information on 13 classes. ===<<< save project data, thread=Thread-1, projectDataToSave=E 2862744 I have no idea why getGlobalProjectData create a new instance of ProjectData and does not write the old one: - when it is in the same class loader, the static variable should be not null - when it is in a different class loader, there should be a new shutdown hook and all would be o.k. I found a workaround: I added the code from your FAQ (at the bottom) and save the coverage data in the context listener on destroy. Regards, Roger ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Cobertura-devel mailing list Cobertura-devel@... https://lists.sourceforge.net/lists/listinfo/cobertura-devel |
|
|
Antwort: RE: Coverage seems wrong (Cobertura 1.9.3, Tomcat 6.0.18, Java 1.6)Hi!
When I move cobertura.jar to apache-tomcat-6.0.18/lib everything works fine. I found the reason why it fails when cobertura.jar is in WEB-INF/lib: Tomcat has a feature ENABLE_CLEAR_REFERENCES (see org.apache.catalina.loader.WebappClassLoader), this feature is enabled by default. It can be disabled by a system property: public static final boolean ENABLE_CLEAR_REFERENCES = Boolean.valueOf(System.getProperty("org.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES", "true")).booleanValue(); When the class loader for the application is stopped, it clears references in loaded classes. This clears the static variable globalProjectData and removes all gathered coverage data. The only coverage seen in the report is that of code executed after this event. I think this is neither a Tomcat bug nor a Cobertura bug, but it is worth a paragraph in the FAQ... Regards Roger "John W. Lewis" <JohnW.Lewis@sas. com> An Roger Butenuth 15.10.2009 22:06 <RButenuth@...>, "cobertura-devel@... .net" <cobertura-devel@... .net> Kopie Thema RE: [Cobertura-devel] Coverage seems wrong (Cobertura 1.9.3, Tomcat 6.0.18, Java 1.6) Is cobertura.jar in Tomcat’s lib directory? Or is it bundled with the application. It should be in the lib directory. ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Cobertura-devel mailing list Cobertura-devel@... https://lists.sourceforge.net/lists/listinfo/cobertura-devel |
| Free embeddable forum powered by Nabble | Forum Help |