Skip to content

Commit

Permalink
Re-organize and document the test fixtures
Browse files Browse the repository at this point in the history
1) test input (fixtures) should be located under fixtures/, while tests/ should be used for test code
2) The source code of the debugdata_* files was added.
3) Added a readme giving brief descriptions of the test binaries, and how they were built.
  • Loading branch information
DanielT committed Dec 7, 2024
1 parent 2375bf6 commit ae35f93
Show file tree
Hide file tree
Showing 34 changed files with 149 additions and 69 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
65 changes: 65 additions & 0 deletions fixtures/bin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Binary fixtures for a2ltool tests

## debugdata

The source code for the various debugdata_* files is located inside the archive debugdata_src.zip.
This code is not intended to perform any sort of useful function, but only to produce interesting debug information when it is compiled.

### debugdata_gcc*.elf

Compiled with gcc 13.3 (as distributed by ARM) for bare-metal ARM; basic compile command:

`arm-none-eabi-gcc -mcpu=cortex-m7 -mthumb "-specs=nano.specs" "-specs=nosys.specs" -mfloat-abi=hard -nostdlib -g3 ...`

For the _dw3 variant, the command line option `-gdwarf3` is addded, to force gcc to generate DWARF3 output.

### debugdata_clang*.elf

Compiled with clang 19 for bare-metal ARM; basic compile command:

`clang --target=armv7m-none-eabi -mcpu=cortex-m7 -mfloat-abi=hard -nostdlib -g3 ...`

The _dw4 variant uses the additional command line option `-gdwarf-4` to force clang to generate DWARF4 instead of DWARF5.

### _dwz files

These files were run through DWZ (<https://sourceware.org/dwz/>).
The DWARF format is extremely inefficient and often contains many repetitions of essentially the same data.
DWZ aims to improve this, but it's not clear DWZ is doing much for these test files, since they are probably not complicated enough.
In any case, testing with these files has not revealed any new edge cases so far, so these files might be removed in the future.

### debugdata_cl.pdb

The debugdata example source was compiled with MSVC 2022. Compile command:

`cl ... /Qspectre- /Zi -o debugdata_cl.exe`

Only the resulting PDB file was added to git, since the exe file is not relevant for testing.

### debugdata_clang.pdb

This file was create by clang 19, using the clang-cl command:

`clang-cl.exe ... /Zi -o debugdata_clang.exe`

The exe file was discarded, since only the pdb is used for testing.

### debugdata_gcc.exe

This file was compiled with gcc 14.2 for windows created by the MSYS2 project.
MINGW / MSYS2 gcc produces .exe files that contain DWARF debug information.

Compile command:

`gcc -g3 -o debugdata_gcc.exe ...`

## update_test

The update_test files were built from the single source file update_test.c; they are used for various tests of the a2l update code.

update_test.elf
update_test.exe

## update_typedef_test

This is used for the test cases that are specific to the code creating and updating TYPEDEF_STRUCTUREs and INSTANCEs
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added fixtures/bin/debugdata_gcc.exe
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added fixtures/bin/debugdata_src.zip
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 25 additions & 10 deletions src/debuginfo/dwarf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,13 @@ mod test {
use super::*;

static ELF_FILE_NAMES: [&str; 7] = [
"tests/elffiles/debugdata_clang.elf",
"tests/elffiles/debugdata_clang_dw4.elf",
"tests/elffiles/debugdata_clang_dw4_dwz.elf",
"tests/elffiles/debugdata_gcc.elf",
"tests/elffiles/debugdata_gcc_dw3.elf",
"tests/elffiles/debugdata_gcc_dw3_dwz.elf",
"tests/elffiles/debugdata_gcc_dwz.elf",
"fixtures/bin/debugdata_clang.elf",
"fixtures/bin/debugdata_clang_dw4.elf",
"fixtures/bin/debugdata_clang_dw4_dwz.elf",
"fixtures/bin/debugdata_gcc.elf",
"fixtures/bin/debugdata_gcc_dw3.elf",
"fixtures/bin/debugdata_gcc_dw3_dwz.elf",
"fixtures/bin/debugdata_gcc_dwz.elf",
];

#[test]
Expand Down Expand Up @@ -637,14 +637,29 @@ mod test {

#[test]
fn test_load_mingw_exe() {
// The file tests/elffiles/update_test.c was compiled with mingw64 gcc
// The file fixtures/bin/update_test.c was compiled with mingw64 gcc
// (update_test.exe) as well as with gcc for arm (update_test.elf).
// Both file contain the same debug information, though the windows exe
// file has some additional items from the starup code.
let debugdata_exe =
DebugData::load_dwarf(OsStr::new("tests/elffiles/update_test.exe"), true).unwrap();
DebugData::load_dwarf(OsStr::new("fixtures/bin/update_test.exe"), true).unwrap();
let debugdata_elf =
DebugData::load_dwarf(OsStr::new("tests/elffiles/update_test.elf"), true).unwrap();
DebugData::load_dwarf(OsStr::new("fixtures/bin/update_test.elf"), true).unwrap();

// every variable in the elf file should also be in the exe file
for var in debugdata_elf.variables.keys() {
assert!(debugdata_exe.variables.contains_key(var));
}
}

#[test]
fn test_load_mingw_exe2() {
// Both file contain the same debug information, though the windows exe
// file has some additional items from the starup code.
let debugdata_exe =
DebugData::load_dwarf(OsStr::new("fixtures/bin/debugdata_gcc.exe"), true).unwrap();
let debugdata_elf =
DebugData::load_dwarf(OsStr::new("fixtures/bin/debugdata_gcc.elf"), true).unwrap();

// every variable in the elf file should also be in the exe file
for var in debugdata_elf.variables.keys() {
Expand Down
4 changes: 2 additions & 2 deletions src/debuginfo/pdb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ mod test {
use super::*;

static PDB_FILE_NAMES: [&str; 2] = [
"tests/elffiles/debugdata_cl.pdb",
"tests/elffiles/debugdata_clang.pdb",
"fixtures/bin/debugdata_cl.pdb",
"fixtures/bin/debugdata_clang.pdb",
];

#[test]
Expand Down
12 changes: 6 additions & 6 deletions src/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ mod test {
fn test_insert_items_normal() {
let mut a2l = a2lfile::new();
let debug_data = crate::debuginfo::DebugData::load_dwarf(
&OsString::from("tests/elffiles/update_test.elf"),
&OsString::from("fixtures/bin/update_test.elf"),
false,
)
.unwrap();
Expand Down Expand Up @@ -1057,7 +1057,7 @@ mod test {
fn test_insert_items_nonexistent() {
let mut a2l = a2lfile::new();
let debug_data = crate::debuginfo::DebugData::load_dwarf(
&OsString::from("tests/elffiles/update_test.elf"),
&OsString::from("fixtures/bin/update_test.elf"),
false,
)
.unwrap();
Expand Down Expand Up @@ -1103,7 +1103,7 @@ mod test {
fn test_insert_items_structures() {
let mut a2l = a2lfile::new();
let debug_data = crate::debuginfo::DebugData::load_dwarf(
&OsString::from("tests/elffiles/update_test.elf"),
&OsString::from("fixtures/bin/update_test.elf"),
false,
)
.unwrap();
Expand Down Expand Up @@ -1150,7 +1150,7 @@ mod test {
fn test_insert_multiple_normal() {
let mut a2l = a2lfile::new();
let debug_data = crate::debuginfo::DebugData::load_dwarf(
&OsString::from("tests/elffiles/update_test.elf"),
&OsString::from("fixtures/bin/update_test.elf"),
false,
)
.unwrap();
Expand Down Expand Up @@ -1216,7 +1216,7 @@ mod test {
fn test_insert_multiple_structures() {
let mut a2l = a2lfile::new();
let debug_data = crate::debuginfo::DebugData::load_dwarf(
&OsString::from("tests/elffiles/update_test.elf"),
&OsString::from("fixtures/bin/update_test.elf"),
false,
)
.unwrap();
Expand Down Expand Up @@ -1295,7 +1295,7 @@ mod test {
fn reject_unsuitable_types() {
let mut a2l = a2lfile::new();
let debug_data = crate::debuginfo::DebugData::load_dwarf(
&OsString::from("tests/elffiles/update_typedef_test.elf"),
&OsString::from("fixtures/bin/update_typedef_test.elf"),
false,
)
.unwrap();
Expand Down
Loading

0 comments on commit ae35f93

Please sign in to comment.