From 2092680faedcdc62366e8adced1d3bf73348b90c Mon Sep 17 00:00:00 2001 From: Angie Date: Fri, 26 Apr 2024 15:15:27 -0400 Subject: [PATCH] Add tests for dependency and symbol headers generation of partial scripts #20 --- slinky-cli/src/main.rs | 4 +- slinky/src/linker_writer.rs | 2 +- slinky/src/partial_linker_writer.rs | 22 +++- slinky/tests/integration_test.rs | 71 +++++++++++- tests/partial_linking/follow_segment.h | 113 +++++++++++++++++++ tests/partial_linking/follow_segment.yaml | 4 +- tests/partial_linking/follow_segment/boot.d | 6 + tests/partial_linking/follow_segment/kanji.d | 4 + tests/partial_linking/follow_segment/main.d | 8 ++ 9 files changed, 219 insertions(+), 15 deletions(-) create mode 100644 tests/partial_linking/follow_segment.h create mode 100644 tests/partial_linking/follow_segment/boot.d create mode 100644 tests/partial_linking/follow_segment/kanji.d create mode 100644 tests/partial_linking/follow_segment/main.d diff --git a/slinky-cli/src/main.rs b/slinky-cli/src/main.rs index 5c9c234..fdc3baa 100644 --- a/slinky-cli/src/main.rs +++ b/slinky-cli/src/main.rs @@ -43,7 +43,7 @@ fn main() { .save_linker_scripts(&output_path) .expect("Error writing the linker scripts"); writer - .write_other_files() + .save_other_files() .expect("Error writing other files listed on the document"); } else { let mut writer = slinky::LinkerWriter::new(&document.settings); @@ -59,7 +59,7 @@ fn main() { } writer - .write_other_files() + .save_other_files() .expect("Error writing other files listed on the document"); } diff --git a/slinky/src/linker_writer.rs b/slinky/src/linker_writer.rs index b3ce022..7f62dfe 100644 --- a/slinky/src/linker_writer.rs +++ b/slinky/src/linker_writer.rs @@ -437,7 +437,7 @@ impl<'a> LinkerWriter<'a> { } impl LinkerWriter<'_> { - pub fn write_other_files(&self) -> Result<(), SlinkyError> { + pub fn save_other_files(&self) -> Result<(), SlinkyError> { if let Some(d_path) = &self.settings.d_path { if let Some(target_path) = &self.settings.target_path { self.save_dependencies_file(d_path, target_path)?; diff --git a/slinky/src/partial_linker_writer.rs b/slinky/src/partial_linker_writer.rs index 97fdfa8..bec4294 100644 --- a/slinky/src/partial_linker_writer.rs +++ b/slinky/src/partial_linker_writer.rs @@ -77,12 +77,24 @@ impl<'a> PartialLinkerWriter<'a> { Ok(()) } - pub fn write_other_files(&self) -> Result<(), SlinkyError> { - self.main_writer.write_other_files()?; + pub fn save_other_files(&self) -> Result<(), SlinkyError> { + self.main_writer.save_other_files()?; - //for (partial, _name) in &self.partial_writers { - // partial.write_other_files()?; - //} + if self.settings.d_path.is_some() { + for (partial, name) in &self.partial_writers { + let mut target_path = PathBuf::new(); + + target_path.push(&self.settings.partial_build_segments_folder); + target_path.push(&format!("{}.o", name)); + + let mut d_path = PathBuf::new(); + + d_path.push(&self.settings.partial_scripts_folder); + d_path.push(&format!("{}.d", name)); + + partial.save_dependencies_file(&d_path, &target_path)?; + } + } Ok(()) } diff --git a/slinky/tests/integration_test.rs b/slinky/tests/integration_test.rs index 5fca665..4731c65 100644 --- a/slinky/tests/integration_test.rs +++ b/slinky/tests/integration_test.rs @@ -72,10 +72,11 @@ fn test_panic_invalid_yamls(#[files("../tests/panics/*.yaml")] path: PathBuf) { } #[rstest] -fn test_partial_linking_script_generation(#[files("../tests/partial_linking/*.ld")] ld_path: PathBuf) { +fn test_partial_linking_script_generation( + #[files("../tests/partial_linking/*.ld")] ld_path: PathBuf, +) { let yaml_path = ld_path.with_extension("yaml"); - //check_ld_generation(&yaml_path, &ld_path); let document = slinky::Document::read_file(&yaml_path).expect("unable to read original file"); let mut writer = slinky::PartialLinkerWriter::new(&document.settings); @@ -84,8 +85,10 @@ fn test_partial_linking_script_generation(#[files("../tests/partial_linking/*.ld let expected_ld_contents = fs::read_to_string(ld_path).expect("unable to read expected ld file"); - assert_eq!(expected_ld_contents, writer.get_main_writer().export_as_string()); - + assert_eq!( + expected_ld_contents, + writer.get_main_writer().export_as_string() + ); for (partial, name) in writer.get_partial_writers() { let mut p = PathBuf::new(); @@ -94,10 +97,66 @@ fn test_partial_linking_script_generation(#[files("../tests/partial_linking/*.ld p.push(&document.settings.partial_scripts_folder); p.push(&format!("{}.ld", name)); - //partial.save_linker_script(&p)?; let expected_partial_ld_contents = - fs::read_to_string(p).expect("unable to read expected ld file"); + fs::read_to_string(p).expect("unable to read expected ld file"); assert_eq!(expected_partial_ld_contents, partial.export_as_string()); } } + +#[rstest] +fn test_partial_linking_d_generation(#[files("../tests/partial_linking/*.d")] d_path: PathBuf) { + let yaml_path = d_path.with_extension("yaml"); + + let document = slinky::Document::read_file(&yaml_path).expect("unable to read original file"); + + let mut writer = slinky::PartialLinkerWriter::new(&document.settings); + writer.add_all_segments(&document.segments); + + let expected_d_contents = fs::read_to_string(d_path).expect("unable to read expected d file"); + + let target_path = document.settings.target_path.as_ref().unwrap(); + assert_eq!( + expected_d_contents, + writer + .get_main_writer() + .export_dependencies_as_string(target_path) + ); + + for (partial, name) in writer.get_partial_writers() { + let mut p = PathBuf::new(); + + p.push(".."); + p.push(&document.settings.partial_scripts_folder); + p.push(&format!("{}.d", name)); + + let expected_partial_ld_contents = + fs::read_to_string(p).expect("unable to read expected d file"); + + let mut partial_target = PathBuf::new(); + partial_target.push(&document.settings.partial_build_segments_folder); + partial_target.push(&format!("{}.o", name)); + assert_eq!( + expected_partial_ld_contents, + partial.export_dependencies_as_string(&partial_target) + ); + } +} + +#[rstest] +fn test_partial_linking_symbols_header_generation( + #[files("../tests/partial_linking/*.h")] h_path: PathBuf, +) { + let yaml_path = h_path.with_extension("yaml"); + let document = slinky::Document::read_file(&yaml_path).expect("unable to read original file"); + + let mut writer = slinky::PartialLinkerWriter::new(&document.settings); + writer.add_all_segments(&document.segments); + + let expected_h_contents = fs::read_to_string(h_path).expect("unable to read expected h file"); + + assert_eq!( + expected_h_contents, + writer.get_main_writer().export_symbol_header_as_string() + ); +} diff --git a/tests/partial_linking/follow_segment.h b/tests/partial_linking/follow_segment.h new file mode 100644 index 0000000..301dacd --- /dev/null +++ b/tests/partial_linking/follow_segment.h @@ -0,0 +1,113 @@ +#ifndef HEADER_SYMBOLS_H +#define HEADER_SYMBOLS_H + +extern char bootCOMMON_END[]; +extern char bootCOMMON_SIZE[]; +extern char bootCOMMON_START[]; +extern char boot_BSS_END[]; +extern char boot_BSS_SIZE[]; +extern char boot_BSS_START[]; +extern char boot_DATA_END[]; +extern char boot_DATA_SIZE[]; +extern char boot_DATA_START[]; +extern char boot_RODATA_END[]; +extern char boot_RODATA_SIZE[]; +extern char boot_RODATA_START[]; +extern char boot_ROM_END[]; +extern char boot_ROM_SIZE[]; +extern char boot_ROM_START[]; +extern char boot_SBSS_END[]; +extern char boot_SBSS_SIZE[]; +extern char boot_SBSS_START[]; +extern char boot_SCOMMON_END[]; +extern char boot_SCOMMON_SIZE[]; +extern char boot_SCOMMON_START[]; +extern char boot_SDATA_END[]; +extern char boot_SDATA_SIZE[]; +extern char boot_SDATA_START[]; +extern char boot_TEXT_END[]; +extern char boot_TEXT_SIZE[]; +extern char boot_TEXT_START[]; +extern char boot_VRAM[]; +extern char boot_VRAM_END[]; +extern char boot_VRAM_SIZE[]; +extern char boot_alloc_VRAM[]; +extern char boot_alloc_VRAM_END[]; +extern char boot_alloc_VRAM_SIZE[]; +extern char boot_noload_VRAM[]; +extern char boot_noload_VRAM_END[]; +extern char boot_noload_VRAM_SIZE[]; +extern char kanjiCOMMON_END[]; +extern char kanjiCOMMON_SIZE[]; +extern char kanjiCOMMON_START[]; +extern char kanji_BSS_END[]; +extern char kanji_BSS_SIZE[]; +extern char kanji_BSS_START[]; +extern char kanji_DATA_END[]; +extern char kanji_DATA_SIZE[]; +extern char kanji_DATA_START[]; +extern char kanji_RODATA_END[]; +extern char kanji_RODATA_SIZE[]; +extern char kanji_RODATA_START[]; +extern char kanji_ROM_END[]; +extern char kanji_ROM_SIZE[]; +extern char kanji_ROM_START[]; +extern char kanji_SBSS_END[]; +extern char kanji_SBSS_SIZE[]; +extern char kanji_SBSS_START[]; +extern char kanji_SCOMMON_END[]; +extern char kanji_SCOMMON_SIZE[]; +extern char kanji_SCOMMON_START[]; +extern char kanji_SDATA_END[]; +extern char kanji_SDATA_SIZE[]; +extern char kanji_SDATA_START[]; +extern char kanji_TEXT_END[]; +extern char kanji_TEXT_SIZE[]; +extern char kanji_TEXT_START[]; +extern char kanji_VRAM[]; +extern char kanji_VRAM_END[]; +extern char kanji_VRAM_SIZE[]; +extern char kanji_alloc_VRAM[]; +extern char kanji_alloc_VRAM_END[]; +extern char kanji_alloc_VRAM_SIZE[]; +extern char kanji_noload_VRAM[]; +extern char kanji_noload_VRAM_END[]; +extern char kanji_noload_VRAM_SIZE[]; +extern char mainCOMMON_END[]; +extern char mainCOMMON_SIZE[]; +extern char mainCOMMON_START[]; +extern char main_BSS_END[]; +extern char main_BSS_SIZE[]; +extern char main_BSS_START[]; +extern char main_DATA_END[]; +extern char main_DATA_SIZE[]; +extern char main_DATA_START[]; +extern char main_RODATA_END[]; +extern char main_RODATA_SIZE[]; +extern char main_RODATA_START[]; +extern char main_ROM_END[]; +extern char main_ROM_SIZE[]; +extern char main_ROM_START[]; +extern char main_SBSS_END[]; +extern char main_SBSS_SIZE[]; +extern char main_SBSS_START[]; +extern char main_SCOMMON_END[]; +extern char main_SCOMMON_SIZE[]; +extern char main_SCOMMON_START[]; +extern char main_SDATA_END[]; +extern char main_SDATA_SIZE[]; +extern char main_SDATA_START[]; +extern char main_TEXT_END[]; +extern char main_TEXT_SIZE[]; +extern char main_TEXT_START[]; +extern char main_VRAM[]; +extern char main_VRAM_END[]; +extern char main_VRAM_SIZE[]; +extern char main_alloc_VRAM[]; +extern char main_alloc_VRAM_END[]; +extern char main_alloc_VRAM_SIZE[]; +extern char main_noload_VRAM[]; +extern char main_noload_VRAM_END[]; +extern char main_noload_VRAM_SIZE[]; + +#endif diff --git a/tests/partial_linking/follow_segment.yaml b/tests/partial_linking/follow_segment.yaml index 6f18b8e..c60f974 100644 --- a/tests/partial_linking/follow_segment.yaml +++ b/tests/partial_linking/follow_segment.yaml @@ -2,8 +2,10 @@ settings: base_path: build section_end_align: null - d_path: tests/partial_linking/follow_segment.d target_path: build/rom.elf + d_path: tests/partial_linking/follow_segment.d + + symbols_header_path: tests/partial_linking/follow_segment.h partial_scripts_folder: tests/partial_linking/follow_segment partial_build_segments_folder: segments diff --git a/tests/partial_linking/follow_segment/boot.d b/tests/partial_linking/follow_segment/boot.d new file mode 100644 index 0000000..ffd4407 --- /dev/null +++ b/tests/partial_linking/follow_segment/boot.d @@ -0,0 +1,6 @@ +segments/boot.o: \ + build/src/main/boot_main.o \ + build/src/libultra.o + +build/src/main/boot_main.o: +build/src/libultra.o: diff --git a/tests/partial_linking/follow_segment/kanji.d b/tests/partial_linking/follow_segment/kanji.d new file mode 100644 index 0000000..b7600d0 --- /dev/null +++ b/tests/partial_linking/follow_segment/kanji.d @@ -0,0 +1,4 @@ +segments/kanji.o: \ + build/src/kanji/kanji.o + +build/src/kanji/kanji.o: diff --git a/tests/partial_linking/follow_segment/main.d b/tests/partial_linking/follow_segment/main.d new file mode 100644 index 0000000..d362002 --- /dev/null +++ b/tests/partial_linking/follow_segment/main.d @@ -0,0 +1,8 @@ +segments/main.o: \ + build/src/main/main.o \ + build/src/main/dmadata.o \ + build/asm/main/util.o + +build/src/main/main.o: +build/src/main/dmadata.o: +build/asm/main/util.o: