@@ -2,7 +2,7 @@ use crate::gpu;
22use crate :: gpu:: mockgpu;
33use crate :: jobsapi;
44use crate :: json_tags;
5- use crate :: linux:: procfs;
5+ use crate :: linux:: { procfs, system } ;
66use crate :: systemapi;
77use crate :: time;
88
@@ -15,6 +15,7 @@ use std::path;
1515#[ derive( Default ) ]
1616pub struct Builder {
1717 proc_files : Option < HashMap < String , String > > ,
18+ node_files : Option < HashMap < String , String > > ,
1819 pids : Option < Vec < ( usize , u32 ) > > ,
1920 threads : Option < HashMap < usize , Vec < ( usize , u32 ) > > > ,
2021 users : Option < HashMap < u32 , String > > ,
@@ -39,13 +40,22 @@ impl Builder {
3940 }
4041 }
4142
43+ // Files below /proc
4244 pub fn with_proc_files ( self , files : HashMap < String , String > ) -> Builder {
4345 Builder {
4446 proc_files : Some ( files) ,
4547 ..self
4648 }
4749 }
4850
51+ // Files below /sys/devices/system/node
52+ pub fn with_node_files ( self , files : HashMap < String , String > ) -> Builder {
53+ Builder {
54+ node_files : Some ( files) ,
55+ ..self
56+ }
57+ }
58+
4959 pub fn with_pids ( self , pids : Vec < ( usize , u32 ) > ) -> Builder {
5060 Builder {
5161 pids : Some ( pids) ,
@@ -188,6 +198,7 @@ impl Builder {
188198 threads,
189199 }
190200 } ,
201+ node_files : self . node_files . unwrap_or_default ( ) ,
191202 now : if let Some ( x) = self . now {
192203 x
193204 } else {
@@ -216,6 +227,7 @@ pub struct MockSystem {
216227 os_release : String ,
217228 architecture : String ,
218229 fs : MockFS ,
230+ node_files : HashMap < String , String > ,
219231 gpus : mockgpu:: MockGpuAPI ,
220232 users : HashMap < u32 , String > ,
221233 pid : u32 ,
@@ -298,7 +310,7 @@ impl systemapi::SystemAPI for MockSystem {
298310 }
299311
300312 fn get_numa_distances ( & self ) -> Result < Vec < Vec < u32 > > , String > {
301- Ok ( vec ! [ vec! [ 10u32 ] ] )
313+ system :: get_numa_distances ( self )
302314 }
303315
304316 fn compute_node_information ( & self ) -> Result < ( u64 , Vec < u64 > ) , String > {
@@ -337,6 +349,13 @@ impl systemapi::SystemAPI for MockSystem {
337349 panic ! ( "Not in use yet" ) ;
338350 }
339351
352+ fn read_node_file_to_string ( & self , filename : & str ) -> io:: Result < String > {
353+ match self . node_files . get ( filename) {
354+ Some ( contents) => Ok ( contents. clone ( ) ) ,
355+ None => Err ( io:: Error :: from ( io:: ErrorKind :: NotFound ) ) ,
356+ }
357+ }
358+
340359 fn run_sacct (
341360 & self ,
342361 _job_states : & [ & str ] ,
0 commit comments