Skip to content

Commit 9ee3590

Browse files
xuejun-xjstudychao
authored andcommitted
dbs-boot: fdt: add a switch of creating dtb files
Add a switch of creating dtb files for fdt unit tests. It will read environment variable "FDT_CREATE_DTB" to decide whether to create new dtb file for this "cargo test". Usage: ```shell $ FDT_CREATE_DTB=1 cargo test ``` Fixes: openanolis#276 Opensource: y Signed-off-by: xuejun-xj <[email protected]>
1 parent 04fa7f4 commit 9ee3590

File tree

1 file changed

+10
-4
lines changed
  • crates/dbs-boot/src/aarch64

1 file changed

+10
-4
lines changed

crates/dbs-boot/src/aarch64/fdt.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ fn create_pmu_node(fdt: &mut FdtWriter, vpmu_feature: &VpmuFeatureLevel) -> Resu
391391
mod tests {
392392
use std::cmp::min;
393393
use std::collections::HashMap;
394+
use std::env;
394395
use std::fs::OpenOptions;
395396
use std::io::Write;
396397
use std::path::PathBuf;
@@ -454,8 +455,13 @@ mod tests {
454455
}
455456

456457
// Create fdt dtb file
457-
#[allow(dead_code)]
458458
fn create_dtb_file(name: &str, dtb: &[u8]) {
459+
// Control whether to create new dtb files for unit test.
460+
// Usage: FDT_CREATE_DTB=1 cargo test
461+
if env::var("FDT_CREATE_DTB").is_err() {
462+
return;
463+
}
464+
459465
// Use this code when wanting to generate a new DTB sample.
460466
// Do manually check dtb files with dtc
461467
// See https://git.kernel.org/pub/scm/utils/dtc/dtc.git/plain/Documentation/manual.txt
@@ -531,7 +537,7 @@ mod tests {
531537
)
532538
.unwrap();
533539

534-
// create_dtb_file("output.dtb", &dtb);
540+
create_dtb_file("output.dtb", &dtb);
535541

536542
let bytes = include_bytes!("test/output.dtb");
537543
let pos = 4;
@@ -568,7 +574,7 @@ mod tests {
568574
)
569575
.unwrap();
570576

571-
// create_dtb_file("output_with_initrd.dtb", &dtb);
577+
create_dtb_file("output_with_initrd.dtb", &dtb);
572578

573579
let bytes = include_bytes!("test/output_with_initrd.dtb");
574580
let pos = 4;
@@ -605,7 +611,7 @@ mod tests {
605611
)
606612
.unwrap();
607613

608-
// create_dtb_file("output_with_pmu.dtb", &dtb);
614+
create_dtb_file("output_with_pmu.dtb", &dtb);
609615

610616
let bytes = include_bytes!("test/output_with_pmu.dtb");
611617
let pos = 4;

0 commit comments

Comments
 (0)