Skip to content

Commit

Permalink
test: merge integration tests sharing the same program
Browse files Browse the repository at this point in the history
  • Loading branch information
boricj committed Aug 25, 2024
1 parent aaf6db6 commit 21bf8da
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import ghidra.program.model.address.AddressFactory;
import ghidra.program.model.address.AddressSetView;

public class COFF_I386_ascii_table_main_o_Test extends DelinkerIntegrationTest {
public class COFF_I386_ascii_table_Test extends DelinkerIntegrationTest {
private static final File mainFile =
new File("src/test/resources/ascii-table/reference/coff_windows/i386/main.obj");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@
import ghidra.program.model.address.AddressFactory;
import ghidra.program.model.address.AddressSetView;

public class ELF_I386_ascii_table_main_o_Test extends DelinkerIntegrationTest {
public class ELF_I386_ascii_table_Test extends DelinkerIntegrationTest {
private static final File mainFile =
new File("src/test/resources/ascii-table/reference/elf_linux_freestanding/i386/main.o");

private static final File ctypeFile =
new File("src/test/resources/ascii-table/reference/elf_linux_freestanding/i386/ctype.o");

@Override
protected String getProgramName() {
return "src/test/resources/ascii-table/reference/elf_linux_freestanding/i386/ascii-table.elf.gzf";
Expand Down Expand Up @@ -123,4 +126,55 @@ public void testExport_main_o() throws Exception {
exported.hasRelocationAtAddress(".rel.rodata", 0x00000048,
X86_32_ElfRelocationType.R_386_32.typeId(), "islower", 0);
}

@Test
public void testExport_ctype_o() throws Exception {
AddressFactory af = getProgram().getAddressFactory();
AddressSetView set = af.getAddressSet(af.getAddress("0804924e"), af.getAddress("0804938e")) // .text
.union(af.getAddressSet(af.getAddress("0804a060"), af.getAddress("0804a160"))); // .rodata
File exportedFile = exportObjectFile(set, new ElfRelocatableObjectExporter(), null);

ObjectFile ctypeObjectFile = new ElfObjectFile(ctypeFile);
ElfObjectFile exported = new ElfObjectFile(exportedFile);

ctypeObjectFile.compareSectionBytes(".text", exported, ".text");
ctypeObjectFile.compareSectionSizes(".rel.text", exported, ".rel.text");
ctypeObjectFile.compareSectionBytes(".rodata", exported, ".rodata");

exported.hasSymbolAtAddress(".symtab", "isalnum", ".text", 0x00000000);
exported.hasSymbolAtAddress(".symtab", "isalpha", ".text", 0x0000001d);
exported.hasSymbolAtAddress(".symtab", "iscntrl", ".text", 0x0000003a);
exported.hasSymbolAtAddress(".symtab", "isdigit", ".text", 0x00000057);
exported.hasSymbolAtAddress(".symtab", "isgraph", ".text", 0x00000074);
exported.hasSymbolAtAddress(".symtab", "islower", ".text", 0x00000091);
exported.hasSymbolAtAddress(".symtab", "isprint", ".text", 0x000000ae);
exported.hasSymbolAtAddress(".symtab", "ispunct", ".text", 0x000000cd);
exported.hasSymbolAtAddress(".symtab", "isspace", ".text", 0x000000ea);
exported.hasSymbolAtAddress(".symtab", "isupper", ".text", 0x00000107);
exported.hasSymbolAtAddress(".symtab", "isxdigit", ".text", 0x00000124);
exported.hasSymbolAtAddress(".symtab", "_ctype_", ".rodata", 0x00000000);

exported.hasRelocationAtAddress(".rel.text", 0x0000000f,
X86_32_ElfRelocationType.R_386_32.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x0000002c,
X86_32_ElfRelocationType.R_386_32.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x00000049,
X86_32_ElfRelocationType.R_386_32.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x00000066,
X86_32_ElfRelocationType.R_386_32.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x00000083,
X86_32_ElfRelocationType.R_386_32.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x000000a0,
X86_32_ElfRelocationType.R_386_32.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x000000bd,
X86_32_ElfRelocationType.R_386_32.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x000000dc,
X86_32_ElfRelocationType.R_386_32.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x000000f9,
X86_32_ElfRelocationType.R_386_32.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x00000116,
X86_32_ElfRelocationType.R_386_32.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x00000133,
X86_32_ElfRelocationType.R_386_32.typeId(), "_ctype_", 0);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@
import ghidra.program.model.address.AddressFactory;
import ghidra.program.model.address.AddressSetView;

public class ELF_Mipsel_ascii_table_main_o_Test extends DelinkerIntegrationTest {
public class ELF_Mipsel_ascii_table_Test extends DelinkerIntegrationTest {
private static final File mainFile =
new File("src/test/resources/ascii-table/reference/elf_linux_freestanding/mipsel/main.o");

private static final File ctypeFile =
new File("src/test/resources/ascii-table/reference/elf_linux_freestanding/mipsel/ctype.o");

@Override
protected String getProgramName() {
return "src/test/resources/ascii-table/reference/elf_linux_freestanding/mipsel/ascii-table.elf.gzf";
Expand Down Expand Up @@ -218,4 +221,77 @@ public void testExport_main_o() throws Exception {
exported.hasRelocationAtAddress(".rel.rodata", 0x00000048,
MIPS_ElfRelocationType.R_MIPS_32.typeId(), "islower", 0);
}

@Test
public void testExport_ctype_o() throws Exception {
AddressFactory af = getProgram().getAddressFactory();
AddressSetView set = af.getAddressSet(af.getAddress("00400600"), af.getAddress("0040086f")) // .text
.union(af.getAddressSet(af.getAddress("00400a00"), af.getAddress("00400b0f"))); // .rodata
File exportedFile = exportObjectFile(set, new ElfRelocatableObjectExporter(), null);

ObjectFile ctypeObjectFile = new ElfObjectFile(ctypeFile);
ElfObjectFile exported = new ElfObjectFile(exportedFile);

ctypeObjectFile.compareSectionBytes(".text", exported, ".text");
ctypeObjectFile.compareSectionSizes(".rel.text", exported, ".rel.text");
ctypeObjectFile.compareSectionBytes(".rodata", exported, ".rodata");

exported.hasSymbolAtAddress(".symtab", "isalnum", ".text", 0x00000000);
exported.hasSymbolAtAddress(".symtab", "isalpha", ".text", 0x00000038);
exported.hasSymbolAtAddress(".symtab", "iscntrl", ".text", 0x00000070);
exported.hasSymbolAtAddress(".symtab", "isdigit", ".text", 0x000000a8);
exported.hasSymbolAtAddress(".symtab", "isgraph", ".text", 0x000000e0);
exported.hasSymbolAtAddress(".symtab", "islower", ".text", 0x00000118);
exported.hasSymbolAtAddress(".symtab", "isprint", ".text", 0x00000150);
exported.hasSymbolAtAddress(".symtab", "ispunct", ".text", 0x00000188);
exported.hasSymbolAtAddress(".symtab", "isspace", ".text", 0x000001c0);
exported.hasSymbolAtAddress(".symtab", "isupper", ".text", 0x000001f8);
exported.hasSymbolAtAddress(".symtab", "isxdigit", ".text", 0x00000230);
exported.hasSymbolAtAddress(".symtab", "_ctype_", ".rodata", 0x00000000);

exported.hasRelocationAtAddress(".rel.text", 0x00000010,
MIPS_ElfRelocationType.R_MIPS_HI16.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x00000014,
MIPS_ElfRelocationType.R_MIPS_LO16.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x00000048,
MIPS_ElfRelocationType.R_MIPS_HI16.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x0000004c,
MIPS_ElfRelocationType.R_MIPS_LO16.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x00000080,
MIPS_ElfRelocationType.R_MIPS_HI16.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x00000084,
MIPS_ElfRelocationType.R_MIPS_LO16.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x000000b8,
MIPS_ElfRelocationType.R_MIPS_HI16.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x000000bc,
MIPS_ElfRelocationType.R_MIPS_LO16.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x000000f0,
MIPS_ElfRelocationType.R_MIPS_HI16.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x000000f4,
MIPS_ElfRelocationType.R_MIPS_LO16.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x00000128,
MIPS_ElfRelocationType.R_MIPS_HI16.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x0000012c,
MIPS_ElfRelocationType.R_MIPS_LO16.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x00000160,
MIPS_ElfRelocationType.R_MIPS_HI16.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x00000164,
MIPS_ElfRelocationType.R_MIPS_LO16.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x00000198,
MIPS_ElfRelocationType.R_MIPS_HI16.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x0000019c,
MIPS_ElfRelocationType.R_MIPS_LO16.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x000001d0,
MIPS_ElfRelocationType.R_MIPS_HI16.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x000001d4,
MIPS_ElfRelocationType.R_MIPS_LO16.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x00000208,
MIPS_ElfRelocationType.R_MIPS_HI16.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x0000020c,
MIPS_ElfRelocationType.R_MIPS_LO16.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x00000240,
MIPS_ElfRelocationType.R_MIPS_HI16.typeId(), "_ctype_", 0);
exported.hasRelocationAtAddress(".rel.text", 0x00000244,
MIPS_ElfRelocationType.R_MIPS_LO16.typeId(), "_ctype_", 0);
}
}

This file was deleted.

0 comments on commit 21bf8da

Please sign in to comment.