libelf: add test

This commit is contained in:
FX Coudert 2018-03-11 11:41:23 +01:00
parent 0beba1d2aa
commit 39c04f94f8

View file

@ -24,4 +24,32 @@ class Libelf < Formula
system "make"
system "make", "install"
end
test do
elf_content = "7F454C460101010000000000000000000200030001000000548004083400000000000000000000003400200001000000000000000100000000000000008004080080040874000000740000000500000000100000B00431DB43B96980040831D2B20CCD8031C040CD8048656C6C6F20776F726C640A"
File.open(testpath/"elf", "w+b") do |file|
file.write([elf_content].pack('H*'))
end
(testpath/"test.c").write <<~EOS
#include <gelf.h>
#include <fcntl.h>
#include <stdio.h>
int main(void) {
GElf_Ehdr ehdr;
int fd = open("elf", O_RDONLY, 0);
if (elf_version(EV_CURRENT) == EV_NONE) return 1;
Elf *e = elf_begin(fd, ELF_C_READ, NULL);
if (elf_kind(e) != ELF_K_ELF) return 1;
if (gelf_getehdr(e, &ehdr) == NULL) return 1;
printf("%d-bit ELF\\n", gelf_getclass(e) == ELFCLASS32 ? 32 : 64);
return 0;
}
EOS
system ENV.cc, "test.c", "-L#{lib}", "-I#{include}/libelf",
"-lelf", "-o", "test"
assert_match "32-bit ELF", shell_output("./test")
end
end