Skip to content

Commit 8e1aed5

Browse files
committed
Add test that parses JRuby's boot files
This is not all of the boot files but is sufficient to demonstrate a memory fault in the AOT WASM parser.
1 parent 1cbe798 commit 8e1aed5

2 files changed

Lines changed: 79 additions & 1 deletion

File tree

java-wasm/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
</dependency>
6262
<dependency>
6363
<groupId>org.jruby</groupId>
64-
<artifactId>jruby-base</artifactId>
64+
<artifactId>jruby-complete</artifactId>
6565
<version>10.0.2.0</version>
6666
</dependency>
6767
</dependencies>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,82 @@
11
package org.prism;
22

3+
import org.jruby.Ruby;
4+
import org.junit.jupiter.api.Test;
5+
6+
import java.io.DataInputStream;
7+
import java.io.InputStream;
8+
import java.nio.charset.StandardCharsets;
9+
import java.util.EnumSet;
10+
311
public class JRubyTest {
12+
final static String[] JRUBY_BOOT_FILES = {
13+
"jruby/java.rb",
14+
"jruby/java/core_ext.rb",
15+
"jruby/java/core_ext/object.rb",
16+
"jruby/java/java_ext.rb",
17+
"jruby/kernel.rb",
18+
"jruby/kernel/signal.rb",
19+
"jruby/kernel/kernel.rb",
20+
"jruby/kernel/proc.rb",
21+
"jruby/kernel/process.rb",
22+
"jruby/kernel/enumerator.rb",
23+
"jruby/kernel/enumerable.rb",
24+
"jruby/kernel/io.rb",
25+
"jruby/kernel/gc.rb",
26+
"jruby/kernel/range.rb",
27+
"jruby/kernel/file.rb",
28+
"jruby/kernel/method.rb",
29+
"jruby/kernel/thread.rb",
30+
"jruby/kernel/integer.rb",
31+
"jruby/kernel/time.rb",
32+
"jruby/preludes.rb",
33+
"jruby/kernel/prelude.rb",
34+
"jruby/kernel/enc_prelude.rb",
35+
"META-INF/jruby.home/lib/ruby/stdlib/unicode_normalize.rb",
36+
"jruby/kernel/gem_prelude.rb",
37+
"META-INF/jruby.home/lib/ruby/stdlib/rubygems.rb",
38+
"META-INF/jruby.home/lib/ruby/stdlib/rbconfig.rb",
39+
"jruby/kernel/rbconfig.rb",
40+
"META-INF/jruby.home/lib/ruby/stdlib/rubygems/compatibility.rb",
41+
"META-INF/jruby.home/lib/ruby/stdlib/rubygems/defaults.rb",
42+
"META-INF/jruby.home/lib/ruby/stdlib/rubygems/deprecate.rb",
43+
"META-INF/jruby.home/lib/ruby/stdlib/rubygems/errors.rb",
44+
"META-INF/jruby.home/lib/ruby/stdlib/rubygems/target_rbconfig.rb",
45+
"META-INF/jruby.home/lib/ruby/stdlib/rubygems/exceptions.rb",
46+
"META-INF/jruby.home/lib/ruby/stdlib/rubygems/unknown_command_spell_checker.rb",
47+
"META-INF/jruby.home/lib/ruby/stdlib/rubygems/specification.rb",
48+
"META-INF/jruby.home/lib/ruby/stdlib/rubygems/basic_specification.rb",
49+
"META-INF/jruby.home/lib/ruby/stdlib/rubygems/stub_specification.rb",
50+
"META-INF/jruby.home/lib/ruby/stdlib/rubygems/platform.rb",
51+
"META-INF/jruby.home/lib/ruby/stdlib/rubygems/specification_record.rb",
52+
"META-INF/jruby.home/lib/ruby/stdlib/rubygems/util/list.rb",
53+
"META-INF/jruby.home/lib/ruby/stdlib/rubygems/requirement.rb",
54+
"META-INF/jruby.home/lib/ruby/stdlib/rubygems/version.rb",
55+
};
56+
57+
@Test
58+
public void basicJRubyTest() throws Throwable{
59+
Prism prism = new PrismWASM();
60+
byte[] src = new byte[1024*1024];
61+
62+
for (var file : JRUBY_BOOT_FILES) {
63+
byte[] options = ParsingOptions.serialize(
64+
file.getBytes(StandardCharsets.UTF_8),
65+
1,
66+
"UTF-8".getBytes(StandardCharsets.UTF_8),
67+
false,
68+
EnumSet.noneOf(ParsingOptions.CommandLine.class),
69+
ParsingOptions.SyntaxVersion.LATEST,
70+
false,
71+
false,
72+
false,
73+
new byte[][][]{}
74+
);
75+
try (InputStream fileIn = Ruby.getClassLoader().getResourceAsStream(file)) {
76+
DataInputStream dis = new DataInputStream(fileIn);
77+
int read = dis.read(src);
78+
prism.serialize(options, src, read);
79+
}
80+
}
81+
}
482
}

0 commit comments

Comments
 (0)