java compatibility tests - mauven for j2s

4 views
Skip to first unread message

Sebastian Gurin

unread,
Aug 18, 2009, 5:52:39 PM8/18/09
to Java2Script
Hello all. I sucessfully integrated mauve (http://sources.redhat.com/mauve/) in java2script. Mauve is a free test suite for the Java class libraries. The current collaborators come from the Kaffe project, the GNU Classpath project, and the GCJ project. In sumarry it is a small, simple java test toolkit but has *a lot* of test for each class and subpackage of java.lang, java.util, etc.

What I have done is 1) import latest mauve sources into a java2script project 2) Remove/comment mauve test toolkit parts not supported by j2s (like java.io.*) 3) since this is a big project (j2s compiler takes 4 min to compile it in a fast machine) I removed all tests corresponding to those java packages/classes not supported by j2s.

I have uploaded the project to http://groups.google.com/group/java2script/web/j2sMauve.tar.bz2. It has its own j2slib since I had to correct a little bug (http://sourceforge.net/tracker/?func=detail&aid=2839956&group_id=155436&atid=795800).

I have runned some tests, mainly java.lang, and I see some tests failures and j2s errors :( My following steps will be generating a full report of all tests errors, failures and passes for java.lang and java.util.

I think mauve test suite is very exaustive and will really help j2s improving its quality but also will let us know more about j2s limitations, bugs, etc. Also, It will also help us to know how java compatibility is affected by an important change in j2s core or j2slib.

This only took me hours of work and it is only an initial proposal of how nauve can be used in j2s. I feel courious about how compatible is j2slib with java libraries, according to mauve. So, I will keep playing with this project. Nevertheless, I think it is a good idea to include these kind of java library compatibility toolkit sources toghether with j2s sources.

Well, let me know what you think. I will try to run as much tests as possible and publish my results and conclusions to the list.

--
Sebastian Gurin <sgu...@softpoint.org>

Zhou Renjian

unread,
Aug 18, 2009, 10:17:58 PM8/18/09
to java2...@googlegroups.com
Good job. Looking forward for more Java2Script bugs. :D

By the way, I made some JUnit tests for J2SLib using Apache Harmony's JUnit tests, long time ago. And Java2Script's Java core library (java.lang.*, java.util.*) is mainly from Apache Harmony.

Regards,
Zhou Renjian

--
http://webuzz.im/ Web IMs (G/A/M/Y)
http://j2s.sourceforge.net/ Java2Script

Sebastian Gurin

unread,
Aug 19, 2009, 1:18:36 PM8/19/09
to java2...@googlegroups.com

On Wed, 19 Aug 2009 10:17:58 +0800
Zhou Renjian <zhour...@gmail.com> wrote:

> Good job. Looking forward for more Java2Script bugs. :D
>
> By the way, I made some JUnit tests for J2SLib using Apache Harmony's JUnit
> tests, long time ago. And Java2Script's Java core library (java.lang.*,
> java.util.*) is mainly from Apache Harmony.

I can't find any reference to which apache-harmony's version was used for j2s.java.core. Do you remember it?

The thing is I'm finding bugs in apache-harmony, not related to j2s compiler. For example, consider java.util.AbstractCollection's addAll method:


/**
* Adds the objects in the specified Collection to this Collection.
*
* @param collection
* the Collection of objects
* @return true if this Collection is modified, false otherwise
*
* @throws UnsupportedOperationException
* when adding to this Collection is not supported
* @throws NullPointerException
* if null is used to invoke this method
*/
public boolean addAll(Collection<? extends E> collection) {
boolean result = false;
Iterator<? extends E> it = collection.iterator();
while (it.hasNext()) {
if (add(it.next())) {
result = true;
}
}
return result;
}

in a normal java program the following code will throw a NullPointerException, just as spected:

anAbstractCollection.addAll(null);

but not in java2script (because obj.somMethod() will raise a browser exception "obj is null" instead throwing a NullPointerException. (I have downloaded latest harmony sources and this remains the same)

The later method have to be fixed to the following so it behaves as spected in j2s:

public boolean addAll(Collection<? extends E> collection) {
if(collection==null) //cancerbero_sgx
throw new NullPointerException();
boolean result = false;
Iterator<? extends E> it = collection.iterator();
while (it.hasNext()) {
if (add(it.next())) {
result = true;
}
}
return result;
}

I had to fix this kind of errors so mauve test execute correctly. (interesting, sun jdk sources contain an if(collection==null){throw... in this kind of methods...)

In this stage I will focus only in make the test executable in j2s: I will only correct those bugs that make the test to raise a browser error. I will not focus on indentify or correct test bad asserts . If the the error is hard to correct, I will try to modify the test (and document this modification) so it can be runned correctly .

The idea is to have the larger amount of a java.lang and java.util mauve test running in j2s correctly. Then we can focus on identify and correct bad tests asserts, make a test suite and a better test result management.

--
Sebastian Gurin <sgu...@softpoint.org>

Sebastian Gurin

unread,
Aug 20, 2009, 9:47:42 AM8/20/09
to java2...@googlegroups.com
I have submited a bug report about this problem with native null pointer exceptions in https://sourceforge.net/tracker/?func=detail&aid=2841093&group_id=155436&atid=795800. Also have attached a small fix in the compiler. Following, I paste the bug text:


--- begin bug report ---

in java, the following code prints "OK" but fails in javascript with
browser error "o is null":

Object o = null;
boolean ok=false;
try {
o.toString(); //nullPointerException raised
} catch(NullPointerException e) {
ok=true;
} catch (Exception e) {
}
if(!ok) {System.out.println("error");}
else{System.out.println("ok");}


The error is due to the fact that the statement "o.toString()" throw a
native javascript error ("o is null") but not a java Exception, like
NullPointerException, as spected.

One way to solve this is to fix the compiler so it detects a native
javascriupt error inside the catch clause and build the corresponding
javascript exception. I fixed method
net.sf.j2s.core.astvisitors.ASTKeywordVisitor.visit(TryStatement). See
comment "cancerbero_sgx" in attached ASTKeywordVisitor.java file.

Without the fix, the last catch clause is translated to:

} catch (e) {
if (Clazz.instanceOf (e, NullPointerException)) {
ok = true;
} else {
throw e;
}
}

(bacause e is not a java.lang.Exception it is not catched). With the
proposed fix, the catch clause is translated to:

} catch (e) {
if (e.__CLASS_NAME__==null && e.name=='TypeError'){
e=new java.lang.NullPointerException();
}
if (Clazz.instanceOf (e, NullPointerException)) {
ok = true;
} else {
throw e;
}
}

(javascript native error detected and e reasigned to a
NullPointerException).

This java test works correctly with chrome, IE, firefox and opera.
Nevertheless, I'm not sure about ho will be affected other native
exceptions raisings besides "obj is null". This fixes the bug mentioned
with passing null parameters to some collection methods like addAll,
toArray(), etc

---end bug report---
--
Sebastian Gurin <sgu...@softpoint.org>

Sebastian Gurin

unread,
Aug 22, 2009, 12:01:42 PM8/22/09
to Java2Script
I had run almost all mauve tests of java.util. I upladed a document
with the results in this group files under the name "Testing j2s with
mauve.tar.gz"(http://java2script.googlegroups.com/web/Testing+j2s+with
+mauve.tar.gz?gda=vF9PRk8AAADmMaaDQEODIyuW4FwkFlrzYMD2afh5BoGrOxy66-
NgE1SXSAK9r_vF9YcQHcadgBl-
O2FC3fJCf-8YPVPNPJbJnHMhSp_qzSgvndaTPyHVdA&gsc=eVRP6gsAAAAjEdwS3ttGKMbTq98K2EGw).
In the case of errors, I documented them there and opened a bug report
on sourceforge. In general there are classes that succcessfully pass
most tests, and the bugs detected seems to be few (but in some case,
affecting several tests). I have noted that running java.lang tests
will be much more difficult than java.util and much more bugs will be
detected there.

I'm trying to implement an automatized way of reporting tests results
that let me know if a test 1) have browser errors due to native
exceptions, 2)have browser errors due to a java exception, 3) finalize
correctly and in this case collecting test failures, passes debug
messages. Nevertheless I think the attached document can show this
early results.

Regards,

Sebastian Gurin

On 18 ago, 23:17, Zhou Renjian <zhourenj...@gmail.com> wrote:
> Good job. Looking forward for more Java2Script bugs. :D
>
> By the way, I made some JUnit tests for J2SLib using Apache Harmony's JUnit
> tests, long time ago. And Java2Script's Java core library (java.lang.*,
> java.util.*) is mainly from Apache Harmony.
>
> Regards,
> Zhou Renjian
>
> --http://webuzz.im/Web IMs (G/A/M/Y)http://j2s.sourceforge.net/Java2Script
>
> On Wed, Aug 19, 2009 at 5:52 AM, Sebastian Gurin <sgu...@softpoint.org>wrote:
>
>
>
> > Hello all. I sucessfully integrated mauve (
> >http://sources.redhat.com/mauve/) in java2script. Mauve is a free test
> > suite for the Java class libraries. The current collaborators come from the
> > Kaffe project, the GNU Classpath project, and the GCJ project. In sumarry it
> > is a small, simple java test toolkit but has *a lot* of test for each class
> > and subpackage of java.lang, java.util, etc.
>
> > What I have done is 1) import latest mauve sources into a java2script
> > project 2)        Remove/comment mauve test toolkit parts not supported by
> > j2s (like java.io.*) 3) since this is a big project (j2s compiler takes 4
> > min to compile it in a fast machine) I removed all tests corresponding to
> > those java packages/classes not supported by j2s.
>
> > I have uploaded the project to
> >http://groups.google.com/group/java2script/web/j2sMauve.tar.bz2. It has
> > its own j2slib since I had to correct a little bug (
> >http://sourceforge.net/tracker/?func=detail&aid=2839956&group_id=1554...
> > ).
Reply all
Reply to author
Forward
0 new messages