use of suite.primitive.Bytes in project suite by stupidsing.
the class ElfTest method test.
private void test(String program, String input, int code) {
Bytes bytes = Bytes.of(input.getBytes(Constants.charset));
if (RunUtil.isUnix()) {
// not Windows => run ELF
Execute exec = elf.exec(bytes.toArray(), offset -> Funp_.main().compile(offset, program).t1);
assertEquals(code, exec.code);
assertEquals(input, exec.out);
} else {
// Windows => interpret assembly
Pair<List<Instruction>, Bytes> pair = Funp_.main().compile(code, program);
Amd64Interpret interpret = new Amd64Interpret();
assertEquals(code, interpret.interpret(pair.t0, pair.t1, bytes));
assertEquals(bytes, interpret.out.toBytes());
}
}
use of suite.primitive.Bytes in project suite by stupidsing.
the class RollingHashUtilTest method test1.
@Test
public void test1() {
Bytes bytes = To.bytes("0123456789abcdef");
int size = bytes.size();
int rollingHash = rollingHashUtil.hash(bytes);
for (int pos = 0; pos < size; pos++) rollingHash = rollingHashUtil.unroll(rollingHash, bytes.get(pos), size - pos);
assertEquals(rollingHashUtil.hash(Bytes.empty), rollingHash);
}
use of suite.primitive.Bytes in project suite by stupidsing.
the class AssemblerTest method testAssembleLongMode.
@Test
public void testAssembleLongMode() throws IOException {
Assembler assembler = new Assembler(32, true);
Bytes bytes = assembler.assemble(Suite.parse(".org = 0, .l MOV (R9D, DWORD 16),"));
assertEquals(bytes.size(), 7);
}
use of suite.primitive.Bytes in project suite by stupidsing.
the class AssemblerTest method testAssembler.
@Test
public void testAssembler() {
Bytes bytes = new Assembler(32).assemble(//
"" + //
".org = 0 \n" + //
" JMP (.end) \n" + //
" MOV (AX, 16) \n" + //
" MOV (EAX, 16) \n" + //
".end () \n" + //
" ADVANCE (16) \n");
assertEquals(16, bytes.size());
System.out.println(bytes);
}
use of suite.primitive.Bytes in project suite by stupidsing.
the class FunpTest method test.
private void test(int r, String p) {
LogUtil.info(p);
Pair<List<Instruction>, Bytes> pair = Funp_.main().compile(0, p);
Bytes bytes = pair.t1;
LogUtil.info("Hex" + bytes + "\n\n");
assertEquals(r, new Amd64Interpret().interpret(pair.t0, Bytes.of(), Bytes.of()));
assertTrue(bytes != null);
}
Aggregations