summaryrefslogtreecommitdiffhomepage
path: root/test-elf.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-03-29 16:14:55 +0200
committerRoland Reichwein <mail@reichwein.it>2020-03-29 16:14:55 +0200
commitb7e53bf9d091874d8028b37f6e4940b504cc9234 (patch)
tree44b223d52e889704b0205ac8fc6da728de27f29e /test-elf.cpp
parent9d3f2b289563cb7c845c8a35cb0e7553b21f85e2 (diff)
Code and data segment
Diffstat (limited to 'test-elf.cpp')
-rw-r--r--test-elf.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/test-elf.cpp b/test-elf.cpp
index d3fa9a9..46ef267 100644
--- a/test-elf.cpp
+++ b/test-elf.cpp
@@ -35,7 +35,7 @@ protected:
}
void TearDown(){
std::error_code ec;
- //fs::remove(TempFilename(), ec);
+ fs::remove(TempFilename(), ec);
}
};
@@ -44,13 +44,27 @@ TEST_F(ElfTest, read) {
}
#endif
-TEST_F(ElfTest, write) {
+TEST_F(ElfTest, write_code) {
Elf::Write(TempFilename(),
{
0x48, 0xc7, 0xc0, 0x3c, 0x00, 0x00, 0x00, // mov $0x3c,%rax # syscall 60
0x48, 0x31, 0xff, // xor %rdi,%rdi # exit code 0
0x0f, 0x05, // syscall
- });
+ }, {});
+
+ ASSERT_TRUE(fs::exists(TempFilename()));
+ ASSERT_GT(fs::file_size(TempFilename()), 0);
+}
+
+TEST_F(ElfTest, write_code_data) {
+ Elf::Write(TempFilename(),
+ {
+ 0x48, 0xc7, 0xc0, 0x3c, 0x00, 0x00, 0x00, // mov $0x3c,%rax # syscall 60
+ 0x48, 0x8b, 0x3c, 0x25, 0x00, 0x20, 0x40, // mov 0x402000,%rdi # use value from data segment as exit code
+ 0,
+ 0x0f, 0x05, // syscall
+ },
+ {1, 0, 0, 0, 0, 0, 0, 0});
ASSERT_TRUE(fs::exists(TempFilename()));
ASSERT_GT(fs::file_size(TempFilename()), 0);