Skip to content

Commit

Permalink
Add tests for dependency and symbol headers generation of partial scr…
Browse files Browse the repository at this point in the history
…ipts

#20
  • Loading branch information
AngheloAlf committed Apr 26, 2024
1 parent 8edb699 commit 2092680
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 15 deletions.
4 changes: 2 additions & 2 deletions slinky-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -59,7 +59,7 @@ fn main() {
}

writer
.write_other_files()
.save_other_files()
.expect("Error writing other files listed on the document");
}

Expand Down
2 changes: 1 addition & 1 deletion slinky/src/linker_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
22 changes: 17 additions & 5 deletions slinky/src/partial_linker_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down
71 changes: 65 additions & 6 deletions slinky/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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()
);
}
113 changes: 113 additions & 0 deletions tests/partial_linking/follow_segment.h
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion tests/partial_linking/follow_segment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/partial_linking/follow_segment/boot.d
Original file line number Diff line number Diff line change
@@ -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:
4 changes: 4 additions & 0 deletions tests/partial_linking/follow_segment/kanji.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
segments/kanji.o: \
build/src/kanji/kanji.o

build/src/kanji/kanji.o:
8 changes: 8 additions & 0 deletions tests/partial_linking/follow_segment/main.d
Original file line number Diff line number Diff line change
@@ -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:

0 comments on commit 2092680

Please sign in to comment.