File tree Expand file tree Collapse file tree 4 files changed +60
-0
lines changed
aarch64/static_cpu_templates
x86_64/static_cpu_templates Expand file tree Collapse file tree 4 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -40,3 +40,19 @@ impl std::fmt::Display for StaticCpuTemplate {
40
40
}
41
41
}
42
42
}
43
+
44
+ #[ cfg( test) ]
45
+ mod tests {
46
+ use super :: * ;
47
+ use crate :: cpu_config:: test_utils:: get_json_template;
48
+
49
+ #[ test]
50
+ fn verify_consistency_with_json_templates ( ) {
51
+ let static_templates = [ ( v1n1:: v1n1 ( ) , "aarch64_v1n1.json" ) ] ;
52
+
53
+ for ( hardcoded_template, filename) in static_templates {
54
+ let json_template = get_json_template ( filename) ;
55
+ assert_eq ! ( hardcoded_template, json_template) ;
56
+ }
57
+ }
58
+ }
Original file line number Diff line number Diff line change @@ -13,3 +13,6 @@ pub mod x86_64;
13
13
/// Module containing type implementations needed for aarch64 (ARM) CPU configuration
14
14
#[ cfg( target_arch = "aarch64" ) ]
15
15
pub mod aarch64;
16
+
17
+ #[ cfg( test) ]
18
+ pub mod test_utils;
Original file line number Diff line number Diff line change
1
+ // Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ use std:: path:: PathBuf ;
5
+
6
+ use crate :: cpu_config:: templates:: CustomCpuTemplate ;
7
+
8
+ // Get a static CPU template stored as a JSON file.
9
+ pub fn get_json_template ( filename : & str ) -> CustomCpuTemplate {
10
+ let json_path = [
11
+ env ! ( "CARGO_MANIFEST_DIR" ) ,
12
+ "../../resources/tests/static_cpu_templates" ,
13
+ filename,
14
+ ]
15
+ . iter ( )
16
+ . collect :: < PathBuf > ( ) ;
17
+
18
+ serde_json:: from_str ( & std:: fs:: read_to_string ( json_path) . unwrap ( ) ) . unwrap ( )
19
+ }
Original file line number Diff line number Diff line change @@ -50,3 +50,25 @@ impl StaticCpuTemplate {
50
50
self == & StaticCpuTemplate :: None
51
51
}
52
52
}
53
+
54
+ #[ cfg( test) ]
55
+ mod tests {
56
+ use super :: * ;
57
+ use crate :: cpu_config:: test_utils:: get_json_template;
58
+
59
+ #[ test]
60
+ fn verify_consistency_with_json_templates ( ) {
61
+ let static_templates = [
62
+ ( c3:: c3 ( ) , "c3.json" ) ,
63
+ ( t2:: t2 ( ) , "t2.json" ) ,
64
+ ( t2s:: t2s ( ) , "t2s.json" ) ,
65
+ ( t2cl:: t2cl ( ) , "t2cl.json" ) ,
66
+ ( t2a:: t2a ( ) , "t2a.json" ) ,
67
+ ] ;
68
+
69
+ for ( hardcoded_template, filename) in static_templates {
70
+ let json_template = get_json_template ( filename) ;
71
+ assert_eq ! ( hardcoded_template, json_template) ;
72
+ }
73
+ }
74
+ }
You can’t perform that action at this time.
0 commit comments