Search in sources :

Example 16 with Bytes

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());
    }
}
Also used : Bytes(suite.primitive.Bytes) Amd64Interpret(suite.assembler.Amd64Interpret) List(java.util.List)

Example 17 with Bytes

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);
}
Also used : Bytes(suite.primitive.Bytes) Test(org.junit.Test)

Example 18 with Bytes

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);
}
Also used : Bytes(suite.primitive.Bytes) Test(org.junit.Test)

Example 19 with Bytes

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);
}
Also used : Bytes(suite.primitive.Bytes) Test(org.junit.Test)

Example 20 with 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);
}
Also used : Bytes(suite.primitive.Bytes) Amd64Interpret(suite.assembler.Amd64Interpret) List(java.util.List)

Aggregations

Bytes (suite.primitive.Bytes)56 Test (org.junit.Test)18 BytesBuilder (suite.primitive.Bytes.BytesBuilder)8 IOException (java.io.IOException)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Pair (suite.adt.pair.Pair)4 OutputStream (java.io.OutputStream)3 Path (java.nio.file.Path)3 To (suite.util.To)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Constants (suite.Constants)2 Amd64Interpret (suite.assembler.Amd64Interpret)2 Condition (suite.concurrent.Condition)2 Extent (suite.file.ExtentAllocator.Extent)2 JournalledPageFile (suite.file.JournalledPageFile)2 ImperativeCompiler (suite.ip.ImperativeCompiler)2 DataInput_ (suite.util.DataInput_)2