mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-20 20:22:15 +00:00
test: strengthen ASM characterization gates
This commit is contained in:
1 parent
2e511a21e3
commit
a65207cc62
7 files changed
+383
-104
No files matched your search
+21
-2
@@ -1349,8 +1349,8 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec
|
||||
- Backfilled, on request, the characterization tests the six ports from `b45527e` to `8581d30` had skipped. Six new
|
||||
suites in `src/test/java/codechicken/multipart/asm/` add 32 plain-JVM tests, taking that suite from 276 to 308.
|
||||
`ByteCodeReader` and the signature parser are covered by behavior; `ScalaSigReader` by round trips, annotation
|
||||
lookup and its replaced-value result. `DebugPrinter`, `ASMMixinFactory` and `MultipartMixinFactory` initialize
|
||||
through Forge, so those tests pin public surfaces, fields and bytecode constants and calls, leaving generated
|
||||
lookup and its replaced-value result. Debug initialization and generator execution need Forge, so those tests
|
||||
pin public surfaces, fields and bytecode constants and calls, leaving generated
|
||||
tiles, pass-through delegation and Java-trait `copyFrom` to the Forge suite.
|
||||
- Ran the backfill against `src/main` restored from `1faf0dd`: it compiles against the untouched Scala and 45 of 46
|
||||
tests pass. The only failure is `MultipartMixinFactory`'s facade method set, which is the four additive static
|
||||
@@ -1359,3 +1359,22 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec
|
||||
- Two behaviors were pinned that inspection had not recorded. `ScalaSigReader.encode` drops the final 7-bit group, so
|
||||
a decode round trip is exact only when that group is empty; a payload ending in a high-bit byte does not survive
|
||||
it. `ScalaSignature.evalS` throws `MatchError` on an unknown tag while `eval` returns the table entry unchanged.
|
||||
|
||||
### 2026-09-03
|
||||
|
||||
- Addressed the three backfill review findings without changing production code. The lossy signature round trip now
|
||||
asserts the exact reference bytes `[0, 62]`, rather than accepting any result different from `[0, 0xfe]`.
|
||||
- Replaced the two presence-only `DebugPrinter` JVM checks with three Forge behavior tests for both config modes:
|
||||
directory creation, immediate-child-only startup cleanup, dump gating/naming/content and cumulative 16,000-byte
|
||||
logging boundaries (including an empty input and a single input crossing two boundaries). An isolated copy changes
|
||||
only the hard-coded output path to `@TempDir`; config and logger state are restored and live dev dumps are untouched.
|
||||
A temporary fault-injection run removing deletion and reversing dump/log guards failed all three new printer tests;
|
||||
those production edits were then restored.
|
||||
- Replaced the `copyFrom` call-presence check with three Forge tests invoking the actual completer. They assert
|
||||
byte-for-byte no-ops for empty/transient-only nodes and an existing method, then exact emitted super-call/guard/field
|
||||
order, transient exclusion and idempotence for mixed fields. Corrected the coverage claims: singleton construction
|
||||
is headless, but generation reaches Forge through `ObfMapping`; earlier dump comparisons were one-off checks.
|
||||
- Verification baseline is now 305 JVM / 122 Forge tests: three weak JVM checks moved to six focused Forge checks.
|
||||
Formatting/checkstyle/build and the Forge suite pass; all 39 generated dump hashes and the dev config are unchanged.
|
||||
No production ABI, source counts or next target changed. `multipart/asm/StackAnalyser.scala` remains next, using
|
||||
explicit migration-test authorization and separate characterization and refactor commits.
|
||||
@@ -12,8 +12,8 @@ what breaks, and what is left. The other documents hold the reasoning.
|
||||
| `JAVA_MIGRATION_MANUAL_CHECKS.md` | What no automated test can cover, and must be checked by hand in a client |
|
||||
| `JAVA_MIGRATION_PROFILE.md` | The focused baseline, first measured result, findings, and exact rerun command |
|
||||
|
||||
Branch: `algent/java`. Base: `master`. 164 commits including the API-cleanup plan, divergence-log cleanup and ports
|
||||
through the `ScalaSignature` parser extraction.
|
||||
Branch: `algent/java`. Base: `master`. 172 commits including the API-cleanup plan, divergence-log cleanup, ports
|
||||
through the `ScalaSignature` parser extraction, and its characterization backfill and review fixes.
|
||||
|
||||
## The one rule that matters
|
||||
|
||||
@@ -26,7 +26,9 @@ Followed for every port so far. It has caught three real ABI breaks that inspect
|
||||
|
||||
**Tests are added only when requested.** The six ASM ports from `b45527e` to `8581d30` were made under that
|
||||
instruction, verified with ABI, disassembly and dump comparisons instead; their characterization tests were
|
||||
backfilled afterwards on request. Ask before skipping step 1 again, and record which check replaced it.
|
||||
backfilled afterwards on request. If a fresh session lacks explicit authorization for migration tests, ask for it
|
||||
before starting the target; do not silently skip step 1. A request to add characterization tests for each migration
|
||||
target satisfies the general "do not write tests unless asked" instruction.
|
||||
|
||||
1. **Characterize first, commit separately.** Write tests against the untouched Scala and confirm they pass. Commit as
|
||||
`test: characterize X` before touching the implementation.
|
||||
@@ -72,7 +74,7 @@ awk -F'"' '/<testsuite /{t+=$4;f+=$8;e+=$10} END{print "tests="t" failures="f" e
|
||||
grep -o 'tests="[0-9]*" skipped="[0-9]*" failures="[0-9]*" errors="[0-9]*"' run/server/junit-out/TEST-*.xml
|
||||
```
|
||||
|
||||
Current baseline: **308 plain-JVM tests and 116 Java 8 Forge dedicated-server tests passing.** The ignored local server
|
||||
Current baseline: **305 plain-JVM tests and 122 Java 8 Forge dedicated-server tests passing.** The ignored local server
|
||||
EULA is accepted in this checkout. GitHub Actions runs the same self-validating Forge suite in a dependent job after
|
||||
the shared GTNH build; keep both jobs required.
|
||||
|
||||
@@ -612,12 +614,20 @@ The six ports above now have backfilled characterization tests in `src/test/java
|
||||
`ByteCodeReader` and the signature parser are covered by behavior: section-relative reads, `readNat`/`readLong`
|
||||
decoding and overflow, clamped string reads, the `advance` bounds failure, table decoding of the frozen
|
||||
`ReferenceScalaEdgePart` fixture, symbol and method-descriptor evaluation, `SigEntry.delete`, and a synthetic table
|
||||
for the literal and unknown-tag branches. `ScalaSigReader` is covered by round trips, the lossy trailing group,
|
||||
annotation lookup and `write`'s previous-value result. `DebugPrinter`, `ASMMixinFactory` and `MultipartMixinFactory`
|
||||
reach Forge from their initializers, so those tests assert public surfaces, fields, and bytecode constants and calls;
|
||||
generated tiles, pass-through delegation and Java-trait `copyFrom` stay covered by the Forge suite.
|
||||
for the literal and unknown-tag branches. `ScalaSigReader` is covered by round trips, the exact lossy `[0, 62]` result
|
||||
for `[0, 0xfe]`, annotation lookup and `write`'s previous-value result. Factory construction is headless; generation
|
||||
reaches Forge through `ObfMapping`. Public surfaces and pass-through bytecode smoke checks remain in the JVM suite.
|
||||
|
||||
Run against `src/main` restored from `1faf0dd`, the backfill compiles and passes 45 of its 46 tests. The one failure
|
||||
Six focused Forge tests replace three presence-only JVM checks. `DebugPrinterFunctionalTest` executes a fresh copy
|
||||
of the real printer with only its hard-coded directory redirected into `@TempDir`, leaving live dev dumps untouched.
|
||||
It covers enabled/disabled directory creation and dumping, immediate-child cleanup without recursion or repeated
|
||||
deletion, dump filenames/content and cumulative logging boundaries in both modes. Config and logger state are
|
||||
restored. `MultipartMixinFactoryFunctionalTest` calls the actual completer on synthetic nodes: empty/transient-only
|
||||
and existing-`copyFrom` inputs remain byte-for-byte unchanged; mixed fields emit the exact super-call, type guard and
|
||||
ordered non-transient copies, and a second completion is a no-op. Generated-tile and pass-through runtime behavior
|
||||
remain covered by the existing Forge tests.
|
||||
|
||||
The original backfill, run against `src/main` restored from `1faf0dd`, passed 45 of 46 ASM-package tests. The one failure
|
||||
is `MultipartMixinFactory`'s facade method set, which is the ledger's four additive static forwarders. Two assertions
|
||||
were relaxed to hold on both trees: the facade private constructors Scala never emitted, and `DebugPrinter$`'s
|
||||
directory cleanup, which Scala emitted as a separate closure class.
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
package codechicken.multipart.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.core.LogEvent;
|
||||
import org.apache.logging.log4j.core.Logger;
|
||||
import org.apache.logging.log4j.core.appender.AbstractAppender;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.LdcInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
import codechicken.lib.asm.ASMHelper;
|
||||
import codechicken.lib.config.ConfigTag;
|
||||
import codechicken.multipart.asm.DebugPrinter$;
|
||||
import codechicken.multipart.handler.MultipartProxy;
|
||||
|
||||
class DebugPrinterFunctionalTest {
|
||||
|
||||
@Test
|
||||
void createsMissingDirectoriesOnlyWhenEnabled(@TempDir Path root) throws Exception {
|
||||
for (boolean enabled : new boolean[] { false, true }) {
|
||||
Path directory = root.resolve(Boolean.toString(enabled)).resolve("nested");
|
||||
Object printer = printer(directory, enabled);
|
||||
assertEquals(enabled, Files.isDirectory(directory));
|
||||
|
||||
dump(printer, "fixture/Example");
|
||||
|
||||
assertEquals(enabled, Files.exists(directory.resolve("fixture#Example.txt")));
|
||||
assertEquals(enabled, Files.exists(directory));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void cleansOnlyImmediateChildrenAtStartupAndGatesDumps(@TempDir Path root) throws Exception {
|
||||
Path expected = root.resolve("expected.txt");
|
||||
ASMHelper.dump(classBytes(), expected.toFile(), false, false);
|
||||
for (boolean enabled : new boolean[] { false, true }) {
|
||||
Path directory = Files.createDirectory(root.resolve(Boolean.toString(enabled)));
|
||||
Path stale = Files.write(directory.resolve("stale.txt"), new byte[] { 1, 2, 3 });
|
||||
Path empty = Files.createDirectory(directory.resolve("empty"));
|
||||
Path nested = Files.createDirectory(directory.resolve("nested"));
|
||||
Path nestedFile = Files.write(nested.resolve("keep.txt"), new byte[] { 4, 5, 6 });
|
||||
|
||||
Object printer = printer(directory, enabled);
|
||||
|
||||
assertEquals(!enabled, Files.exists(stale));
|
||||
assertEquals(!enabled, Files.exists(empty));
|
||||
assertArrayEquals(new byte[] { 4, 5, 6 }, Files.readAllBytes(nestedFile), "Cleanup must not recurse");
|
||||
if (!enabled) assertArrayEquals(new byte[] { 1, 2, 3 }, Files.readAllBytes(stale));
|
||||
|
||||
Path later = Files.write(directory.resolve("created-after-startup.txt"), new byte[] { 7 });
|
||||
dump(printer, "fixture/Example");
|
||||
dump(printer, "fixture/Second");
|
||||
assertArrayEquals(new byte[] { 7 }, Files.readAllBytes(later), "Dumping must not repeat startup cleanup");
|
||||
for (String name : new String[] { "fixture#Example.txt", "fixture#Second.txt" }) {
|
||||
Path output = directory.resolve(name);
|
||||
if (enabled) assertArrayEquals(Files.readAllBytes(expected), Files.readAllBytes(output));
|
||||
else assertFalse(Files.exists(output));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void logsOnlyOnCumulativeThresholdCrossingsEvenWhenDumpingIsDisabled(@TempDir Path root) throws Exception {
|
||||
for (boolean enabled : new boolean[] { false, true }) {
|
||||
Object printer = printer(root.resolve(Boolean.toString(enabled)), enabled);
|
||||
Logger logger = (Logger) printer.getClass().getMethod("logger").invoke(printer);
|
||||
assertEquals("Multipart ASM", logger.getName());
|
||||
Level previousLevel = logger.getLevel();
|
||||
boolean previousAdditive = logger.isAdditive();
|
||||
RecordingAppender appender = new RecordingAppender();
|
||||
appender.start();
|
||||
logger.addAppender(appender);
|
||||
try {
|
||||
logger.setLevel(Level.DEBUG);
|
||||
logger.setAdditive(false);
|
||||
Method defined = printer.getClass().getMethod("defined", String.class, byte[].class);
|
||||
defined.invoke(printer, "first", new byte[15999]);
|
||||
assertTrue(appender.messages.isEmpty());
|
||||
defined.invoke(printer, "boundary", new byte[1]);
|
||||
assertEquals(Arrays.asList(message(16000)), appender.messages);
|
||||
defined.invoke(printer, "empty", new byte[0]);
|
||||
defined.invoke(printer, "below-next", new byte[15999]);
|
||||
assertEquals(Arrays.asList(message(16000)), appender.messages);
|
||||
defined.invoke(printer, "next-boundary", new byte[1]);
|
||||
defined.invoke(printer, "two-boundaries", new byte[32000]);
|
||||
defined.invoke(printer, "below-next", new byte[1]);
|
||||
assertEquals(Arrays.asList(message(16000), message(32000), message(64000)), appender.messages);
|
||||
} finally {
|
||||
logger.removeAppender(appender);
|
||||
logger.setLevel(previousLevel);
|
||||
logger.setAdditive(previousAdditive);
|
||||
appender.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String message(int bytes) {
|
||||
return bytes + " bytes of permGen has been used by ASMMixinCompiler";
|
||||
}
|
||||
|
||||
private static void dump(Object printer, String name) throws Exception {
|
||||
printer.getClass().getMethod("dump", String.class, byte[].class).invoke(printer, name, classBytes());
|
||||
}
|
||||
|
||||
private static byte[] classBytes() {
|
||||
ClassWriter writer = new ClassWriter(0);
|
||||
writer.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, "fixture/Example", null, "java/lang/Object", null);
|
||||
writer.visitEnd();
|
||||
return writer.toByteArray();
|
||||
}
|
||||
|
||||
private static Object printer(Path directory, boolean enabled) throws Exception {
|
||||
// Redirect only the hard-coded path; execute the real constructor and methods in an isolated loader.
|
||||
ClassNode node = new ClassNode();
|
||||
try (InputStream input = DebugPrinter$.class.getResourceAsStream("DebugPrinter$.class")) {
|
||||
assertNotNull(input);
|
||||
new ClassReader(input).accept(node, 0);
|
||||
}
|
||||
int paths = 0;
|
||||
for (MethodNode method : node.methods) {
|
||||
if (!method.name.equals("<init>")) continue;
|
||||
for (AbstractInsnNode instruction : method.instructions.toArray()) {
|
||||
if (instruction instanceof LdcInsnNode && "asm/multipart".equals(((LdcInsnNode) instruction).cst)) {
|
||||
((LdcInsnNode) instruction).cst = directory.toAbsolutePath().toString();
|
||||
paths++;
|
||||
}
|
||||
}
|
||||
}
|
||||
assertEquals(1, paths, "Never initialize a test copy with the live dev dump path");
|
||||
ClassWriter writer = new ClassWriter(0);
|
||||
node.accept(writer);
|
||||
Class<?> type = new FixtureClassLoader(DebugPrinter$.class.getClassLoader()).define(writer.toByteArray());
|
||||
ConfigTag tag = MultipartProxy.config().getTag("debug_asm");
|
||||
String previous = tag.value;
|
||||
try {
|
||||
// In-memory override only: do not save or rewrite the development config file.
|
||||
tag.value = Boolean.toString(enabled);
|
||||
Object printer = type.getField("MODULE$").get(null);
|
||||
assertEquals(enabled, type.getMethod("debug").invoke(printer));
|
||||
assertEquals(directory.toAbsolutePath().toFile(), type.getMethod("dir").invoke(printer));
|
||||
return printer;
|
||||
} finally {
|
||||
tag.value = previous;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class FixtureClassLoader extends ClassLoader {
|
||||
|
||||
private FixtureClassLoader(ClassLoader parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
private Class<?> define(byte[] bytecode) {
|
||||
return defineClass(null, bytecode, 0, bytecode.length);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RecordingAppender extends AbstractAppender {
|
||||
|
||||
private final List<String> messages = new ArrayList<>();
|
||||
|
||||
private RecordingAppender() {
|
||||
super("fmp-debug-printer-test", null, null, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void append(LogEvent event) {
|
||||
assertEquals(Level.DEBUG, event.getLevel());
|
||||
messages.add(event.getMessage().getFormattedMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
package codechicken.multipart.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
|
||||
import static org.objectweb.asm.Opcodes.ACC_TRANSIENT;
|
||||
import static org.objectweb.asm.Opcodes.ALOAD;
|
||||
import static org.objectweb.asm.Opcodes.GETFIELD;
|
||||
import static org.objectweb.asm.Opcodes.IFEQ;
|
||||
import static org.objectweb.asm.Opcodes.INSTANCEOF;
|
||||
import static org.objectweb.asm.Opcodes.INVOKESPECIAL;
|
||||
import static org.objectweb.asm.Opcodes.NOP;
|
||||
import static org.objectweb.asm.Opcodes.PUTFIELD;
|
||||
import static org.objectweb.asm.Opcodes.RETURN;
|
||||
import static org.objectweb.asm.Opcodes.V1_6;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.FieldInsnNode;
|
||||
import org.objectweb.asm.tree.JumpInsnNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.TypeInsnNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
|
||||
import codechicken.lib.asm.ASMHelper;
|
||||
import codechicken.multipart.asm.MultipartMixinFactory$;
|
||||
|
||||
class MultipartMixinFactoryFunctionalTest {
|
||||
|
||||
private static final String TILE = "codechicken/multipart/TileMultipart";
|
||||
private static final String COPY_DESC = "(L" + TILE + ";)V";
|
||||
|
||||
@Test
|
||||
void leavesEmptyAndTransientOnlyTraitsUntouched() {
|
||||
for (boolean transientField : new boolean[] { false, true }) {
|
||||
ClassNode node = trait();
|
||||
if (transientField) node.visitField(ACC_PUBLIC | ACC_TRANSIENT, "cache", "I", null, null);
|
||||
byte[] before = ASMHelper.createBytes(node, 0);
|
||||
|
||||
MultipartMixinFactory$.MODULE$.autoCompleteJavaTrait(node);
|
||||
|
||||
assertEquals(0, node.methods.size());
|
||||
assertArrayEquals(before, ASMHelper.createBytes(node, 0));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void preservesAnExistingCopyFromWithoutEmittingAnything() {
|
||||
ClassNode node = trait();
|
||||
node.visitField(ACC_PUBLIC, "saved", "I", null, null);
|
||||
MethodNode existing = new MethodNode(ACC_PUBLIC, "copyFrom", COPY_DESC, null, null);
|
||||
existing.visitInsn(NOP);
|
||||
existing.visitInsn(RETURN);
|
||||
existing.visitMaxs(0, 2);
|
||||
node.methods.add(existing);
|
||||
byte[] before = ASMHelper.createBytes(node, 0);
|
||||
|
||||
MultipartMixinFactory$.MODULE$.autoCompleteJavaTrait(node);
|
||||
|
||||
assertEquals(1, node.methods.size());
|
||||
assertSame(existing, node.methods.get(0));
|
||||
assertArrayEquals(before, ASMHelper.createBytes(node, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void emitsSuperCallThenTypeGuardAndOnlyNonTransientFieldCopies() {
|
||||
ClassNode node = trait();
|
||||
node.visitField(ACC_PUBLIC, "first", "I", null, null);
|
||||
node.visitField(ACC_PUBLIC | ACC_TRANSIENT, "cache", "I", null, null);
|
||||
node.visitField(ACC_PUBLIC, "second", "Ljava/lang/String;", null, null);
|
||||
|
||||
MultipartMixinFactory$.MODULE$.autoCompleteJavaTrait(node);
|
||||
|
||||
assertEquals(1, node.methods.size());
|
||||
MethodNode copy = node.methods.get(0);
|
||||
assertEquals("copyFrom", copy.name);
|
||||
assertEquals(COPY_DESC, copy.desc);
|
||||
assertEquals(ACC_PUBLIC, copy.access);
|
||||
assertEquals(2, copy.maxStack);
|
||||
assertEquals(2, copy.maxLocals);
|
||||
List<Integer> opcodes = new ArrayList<>();
|
||||
List<Integer> locals = new ArrayList<>();
|
||||
List<String> fields = new ArrayList<>();
|
||||
for (AbstractInsnNode instruction : copy.instructions.toArray()) {
|
||||
if (instruction.getOpcode() >= 0) opcodes.add(instruction.getOpcode());
|
||||
if (instruction instanceof VarInsnNode) locals.add(((VarInsnNode) instruction).var);
|
||||
if (instruction instanceof MethodInsnNode) {
|
||||
MethodInsnNode call = (MethodInsnNode) instruction;
|
||||
assertEquals(TILE, call.owner);
|
||||
assertEquals("copyFrom", call.name);
|
||||
assertEquals(COPY_DESC, call.desc);
|
||||
}
|
||||
if (instruction instanceof TypeInsnNode) {
|
||||
assertEquals(node.name, ((TypeInsnNode) instruction).desc);
|
||||
}
|
||||
if (instruction instanceof JumpInsnNode) {
|
||||
assertEquals(RETURN, ((JumpInsnNode) instruction).label.getNext().getOpcode());
|
||||
}
|
||||
if (instruction instanceof FieldInsnNode) {
|
||||
FieldInsnNode field = (FieldInsnNode) instruction;
|
||||
assertEquals(node.name, field.owner);
|
||||
fields.add(field.name + ':' + field.desc);
|
||||
}
|
||||
}
|
||||
assertEquals(
|
||||
Arrays.asList(
|
||||
ALOAD,
|
||||
ALOAD,
|
||||
INVOKESPECIAL,
|
||||
ALOAD,
|
||||
INSTANCEOF,
|
||||
IFEQ,
|
||||
ALOAD,
|
||||
ALOAD,
|
||||
GETFIELD,
|
||||
PUTFIELD,
|
||||
ALOAD,
|
||||
ALOAD,
|
||||
GETFIELD,
|
||||
PUTFIELD,
|
||||
RETURN),
|
||||
opcodes);
|
||||
assertEquals(Arrays.asList(0, 1, 1, 0, 1, 0, 1), locals);
|
||||
assertEquals(
|
||||
Arrays.asList("first:I", "first:I", "second:Ljava/lang/String;", "second:Ljava/lang/String;"),
|
||||
fields);
|
||||
|
||||
byte[] before = ASMHelper.createBytes(node, 0);
|
||||
MultipartMixinFactory$.MODULE$.autoCompleteJavaTrait(node);
|
||||
assertArrayEquals(before, ASMHelper.createBytes(node, 0), "A second completion must not duplicate copyFrom");
|
||||
}
|
||||
|
||||
private static ClassNode trait() {
|
||||
ClassNode node = new ClassNode();
|
||||
node.visit(V1_6, ACC_PUBLIC, "test/CopyFromFixture", null, TILE, null);
|
||||
return node;
|
||||
}
|
||||
}
|
||||
@@ -14,18 +14,11 @@ import java.util.TreeSet;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.IntInsnNode;
|
||||
import org.objectweb.asm.tree.LdcInsnNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
/**
|
||||
* Reflection and bytecode only: the companion's initializer reads the Forge config, so loading it in a plain JVM is not
|
||||
* possible. Dump content and the byte-count log are covered by the Forge suite.
|
||||
* Reflection only: initialization reads the Forge config. DebugPrinterFunctionalTest covers directory cleanup,
|
||||
* enabled/disabled dumping and byte-count logging under Forge.
|
||||
*/
|
||||
class DebugPrinterCharacterizationTest {
|
||||
|
||||
@@ -65,73 +58,6 @@ class DebugPrinterCharacterizationTest {
|
||||
assertEquals(5, DebugPrinter$.class.getDeclaredFields().length);
|
||||
}
|
||||
|
||||
@Test
|
||||
void gatesOnTheConfigTagAndClearsTheDumpDirectoryOnce() throws Exception {
|
||||
ClassNode node = companion();
|
||||
assertEquals(signatures("debug_asm", "Multipart ASM", "asm/multipart"), constants(node, "<init>"));
|
||||
assertCall(node, "<init>", "codechicken/multipart/handler/MultipartProxy", "config");
|
||||
assertCall(node, "<init>", "java/io/File", "mkdirs");
|
||||
// The per-file delete itself is covered by the Forge suite, which compares generated dump names.
|
||||
assertCall(node, "<init>", "java/io/File", "listFiles");
|
||||
assertCall(node, "<init>", "java/io/File", "exists");
|
||||
}
|
||||
|
||||
@Test
|
||||
void dumpsThroughASMHelperAndLogsEverySixteenThousandBytes() throws Exception {
|
||||
ClassNode node = companion();
|
||||
assertEquals(signatures(".txt"), constants(node, "dump"));
|
||||
assertCall(node, "dump", "codechicken/lib/asm/ASMHelper", "dump");
|
||||
|
||||
assertEquals(signatures(" bytes of permGen has been used by ASMMixinCompiler"), constants(node, "defined"));
|
||||
assertTrue(intOperands(node, "defined").contains(16000));
|
||||
assertCall(node, "defined", "org/apache/logging/log4j/Logger", "debug");
|
||||
}
|
||||
|
||||
private static ClassNode companion() throws Exception {
|
||||
ClassNode node = new ClassNode();
|
||||
new ClassReader(DebugPrinter$.class.getName()).accept(node, 0);
|
||||
return node;
|
||||
}
|
||||
|
||||
private static Set<String> constants(ClassNode node, String methodName) {
|
||||
Set<String> found = new TreeSet<>();
|
||||
for (AbstractInsnNode instruction : instructions(node, methodName)) {
|
||||
if (instruction instanceof LdcInsnNode && ((LdcInsnNode) instruction).cst instanceof String) {
|
||||
found.add((String) ((LdcInsnNode) instruction).cst);
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
private static Set<Integer> intOperands(ClassNode node, String methodName) {
|
||||
Set<Integer> found = new TreeSet<>();
|
||||
for (AbstractInsnNode instruction : instructions(node, methodName)) {
|
||||
if (instruction instanceof IntInsnNode) {
|
||||
found.add(((IntInsnNode) instruction).operand);
|
||||
} else if (instruction instanceof LdcInsnNode && ((LdcInsnNode) instruction).cst instanceof Integer) {
|
||||
found.add((Integer) ((LdcInsnNode) instruction).cst);
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
private static void assertCall(ClassNode node, String methodName, String owner, String name) {
|
||||
for (AbstractInsnNode instruction : instructions(node, methodName)) {
|
||||
if (instruction instanceof MethodInsnNode) {
|
||||
MethodInsnNode call = (MethodInsnNode) instruction;
|
||||
if (call.owner.equals(owner) && call.name.equals(name)) return;
|
||||
}
|
||||
}
|
||||
throw new AssertionError("Missing call " + owner + '.' + name + " in " + methodName);
|
||||
}
|
||||
|
||||
private static AbstractInsnNode[] instructions(ClassNode node, String methodName) {
|
||||
for (MethodNode method : node.methods) {
|
||||
if (method.name.equals(methodName)) return method.instructions.toArray();
|
||||
}
|
||||
throw new AssertionError("Missing method " + methodName);
|
||||
}
|
||||
|
||||
private static void assertField(String name, Class<?> type, int modifiers) throws Exception {
|
||||
Field field = DebugPrinter$.class.getDeclaredField(name);
|
||||
assertSame(type, field.getType());
|
||||
|
||||
+2
-15
@@ -21,9 +21,8 @@ import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
/**
|
||||
* The companion's initializer reaches Forge through TileMultipart, so generation is exercised by the Forge suite:
|
||||
* generated tiles, pass-through delegation and the copied fields of Java traits. Surface and emission order are checked
|
||||
* here.
|
||||
* Surface and bytecode smoke checks only. Generation reaches Forge through ObfMapping; the Forge suite checks copyFrom
|
||||
* guards and emitted instructions, generated tiles and pass-through delegation.
|
||||
*/
|
||||
class MultipartMixinFactoryCharacterizationTest {
|
||||
|
||||
@@ -83,18 +82,6 @@ class MultipartMixinFactoryCharacterizationTest {
|
||||
assertCall(node, "onCompiled", "codechicken/multipart/MultipartGenerator$", "registerTileClass");
|
||||
}
|
||||
|
||||
@Test
|
||||
void completesJavaTraitsWithAGuardedCopyFrom() throws Exception {
|
||||
ClassNode node = companion();
|
||||
Set<String> constants = constants(node, "autoCompleteJavaTrait");
|
||||
assertTrue(constants.contains("copyFrom"));
|
||||
assertTrue(constants.contains("(Lcodechicken/multipart/TileMultipart;)V"));
|
||||
assertTrue(constants.contains("codechicken/multipart/TileMultipart"));
|
||||
// The existing-method guard runs before anything is emitted.
|
||||
assertCall(node, "autoCompleteJavaTrait", "codechicken/lib/asm/ASMHelper", "findMethod");
|
||||
assertCall(node, "autoCompleteJavaTrait", "org/objectweb/asm/MethodVisitor", "visitMaxs");
|
||||
}
|
||||
|
||||
@Test
|
||||
void namesAndFillsThePassThroughTrait() throws Exception {
|
||||
ClassNode node = companion();
|
||||
|
||||
@@ -74,11 +74,11 @@ class ScalaSigReaderCharacterizationTest {
|
||||
assertEquals("", ScalaSigReader.encode(new byte[0]));
|
||||
assertArrayEquals(new byte[0], ScalaSigReader.decode(""));
|
||||
|
||||
// The dropped trailing group is empty for a short payload, but carries the high bits of a long one.
|
||||
// The dropped group is zero for 42, but carries high bits for [0, 0xfe].
|
||||
byte[] single = { 42 };
|
||||
assertArrayEquals(single, ScalaSigReader.decode(ScalaSigReader.encode(single)));
|
||||
byte[] highBit = { 0, (byte) 0xfe };
|
||||
assertFalse(Arrays.equals(highBit, ScalaSigReader.decode(ScalaSigReader.encode(highBit))));
|
||||
assertArrayEquals(new byte[] { 0, 62 }, ScalaSigReader.decode(ScalaSigReader.encode(highBit)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user