From 4a2301b3820e976a892705e03ff19701898b5224 Mon Sep 17 00:00:00 2001 From: Kaiyeung Luk Date: Tue, 26 Nov 2024 08:26:01 -0800 Subject: [PATCH] i#7046: Validate the contents of the Linux memory dump file. (#7092) Set postcmd to use "readelf -a" to dump the contents of Linux memory dump file. Replace suite/tests/client-interface/memory_dump_test.expect with suite/tests/client-interface/memory_dump_test.templatex which validates the contents of the output of "readelf -a". Issue: #7046 --- suite/tests/CMakeLists.txt | 6 +++ .../client-interface/memory_dump_test.dll.c | 1 - .../client-interface/memory_dump_test.expect | 4 -- .../memory_dump_test.templatex | 41 +++++++++++++++++++ 4 files changed, 47 insertions(+), 5 deletions(-) delete mode 100644 suite/tests/client-interface/memory_dump_test.expect create mode 100644 suite/tests/client-interface/memory_dump_test.templatex diff --git a/suite/tests/CMakeLists.txt b/suite/tests/CMakeLists.txt index a35ba5aa182..22f64e5d528 100644 --- a/suite/tests/CMakeLists.txt +++ b/suite/tests/CMakeLists.txt @@ -2647,6 +2647,12 @@ if (NOT ANDROID) # TODO i#38: Port test to Android. client-interface/attach_blocking.runall "" "" "") endif () if (X64 AND (LINUX OR WIN32)) + if (LINUX) + set(client.memory_dump_test_runcmp "${CMAKE_CURRENT_SOURCE_DIR}/runmulti.cmake") + set(client.memory_dump_test_precmd "rm@${PROJECT_BINARY_DIR}/logs/simple_app.*.elf") + set(client.memory_dump_test_postcmd "${READELF_EXECUTABLE}@-a@${PROJECT_BINARY_DIR}/logs/simple_app.*.elf") + set(client.memory_dump_test_expectbase "memory_dump_test") + endif () tobuild_ci(client.memory_dump_test client-interface/memory_dump_test.c "" "" "") endif () endif () diff --git a/suite/tests/client-interface/memory_dump_test.dll.c b/suite/tests/client-interface/memory_dump_test.dll.c index 0113dc4ad42..f379728f61d 100644 --- a/suite/tests/client-interface/memory_dump_test.dll.c +++ b/suite/tests/client-interface/memory_dump_test.dll.c @@ -56,7 +56,6 @@ event_nudge(void *drcontext, uint64 arg) #endif if (!dr_create_memory_dump(&spec)) dr_fprintf(STDERR, "Error: failed to create memory dump.\n"); - // TODO i#7046: Verify the content of the output file. return; } dr_fprintf(STDERR, "Error: unexpected nudge event!\n"); diff --git a/suite/tests/client-interface/memory_dump_test.expect b/suite/tests/client-interface/memory_dump_test.expect deleted file mode 100644 index 903cc0a1840..00000000000 --- a/suite/tests/client-interface/memory_dump_test.expect +++ /dev/null @@ -1,4 +0,0 @@ -thank you for testing memory dump -thread init -nudge delivered 1 -Hello, world! diff --git a/suite/tests/client-interface/memory_dump_test.templatex b/suite/tests/client-interface/memory_dump_test.templatex new file mode 100644 index 00000000000..3171bf9510b --- /dev/null +++ b/suite/tests/client-interface/memory_dump_test.templatex @@ -0,0 +1,41 @@ +thank you for testing memory dump +thread init +nudge delivered 1 +Hello, world! +#ifdef LINUX +#undef UNIX +ELF Header: + Magic: 7f 45 4c 46 02 01 01 03 00 00 00 00 00 00 00 00.* + Class: ELF64 + Data: 2's complement, little endian + Version: 1 \(current\) + OS/ABI: UNIX - GNU + ABI Version: 0 + Type: CORE \(Core file\) + Machine: .* + Version: 0x1 + Entry point address: 0x0 + Start of program headers: 64 \(bytes into file\) + Start of section headers: [0-9]+ \(bytes into file\) + Flags: 0x0 + Size of this header: 64 \(bytes\) + Size of program headers: 56 \(bytes\) + Number of program headers: 1 + Size of section headers: 64 \(bytes\) + Number of section headers: [0-9]+ + Section header string table index: [0-9]+ +.* +Section Headers: +.*\[Nr\] Name Type Address Offset + Size EntSize Flags Link Info Align +.* shstrtab STRTAB.* +Program Headers: + Type Offset VirtAddr PhysAddr + FileSiz MemSiz Flags Align + NOTE.* +.* +Displaying notes found at file offset 0x[0-9a-f]+ with length 0x[0-9a-f]+: + Owner.*Data size.*Description + CORE.*NT_PRSTATUS.*\(prstatus structure\) + CORE.*NT_FPREGSET.*\(floating point registers\) +#endif