Skip to content

Commit 2635863

Browse files
nnethercoteLegNeato
authored andcommitted
Use Vec literals when testing all_target_features.
Currently some `all_target_features` results are compared against a `Vec` literal, while some are only tested with a smattering of `contains`/`!contains` calls. This commit changes the latter one to use `Vec` literals. This is more thorough, easier to read, and demonstrates two existing bugs with `all_target_features`: - The values for the 'f' suffix ones are badly wrong. - The sort order is lexicographic, which puts `compute_100` before `compute_90`. The next commit will fix these bugs.
1 parent 3054d52 commit 2635863

File tree

1 file changed

+150
-60
lines changed

1 file changed

+150
-60
lines changed

crates/nvvm/src/lib.rs

Lines changed: 150 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -846,70 +846,160 @@ mod tests {
846846
]
847847
);
848848

849-
// Test 'a' variant - includes all available instructions for the architecture
850-
// This means: all base variants up to same version, all 'f' variants with same major and <= minor, plus itself
851-
let compute90a_features = NvvmArch::Compute90a.all_target_features();
852-
// Should include all base up to 90
853-
assert!(compute90a_features.contains(&"compute_35".to_string()));
854-
assert!(compute90a_features.contains(&"compute_90".to_string()));
855-
// Should include the 'a' variant itself
856-
assert!(compute90a_features.contains(&"compute_90a".to_string()));
857-
// Should NOT include any 'f' variants (90 has no 'f' variants)
858-
859-
// Test compute100a - should include base variants, and 100f
860-
let compute100a_features = NvvmArch::Compute100a.all_target_features();
861-
// Should include all base up to 100
862-
assert!(compute100a_features.contains(&"compute_90".to_string()));
863-
assert!(compute100a_features.contains(&"compute_100".to_string()));
864-
// Should include 100f (same major, <= minor)
865-
assert!(compute100a_features.contains(&"compute_100f".to_string()));
866-
// Should NOT include 101f or 103f (higher minor)
867-
assert!(!compute100a_features.contains(&"compute_101f".to_string()));
868-
assert!(!compute100a_features.contains(&"compute_103f".to_string()));
869-
// Should include itself
870-
assert!(compute100a_features.contains(&"compute_100a".to_string()));
849+
// Test 'a' variant - includes all available instructions for the architecture.
850+
// This means: all base variants up to same version, no 'f' variants (90 has none), and the
851+
// 'a' variant.
852+
assert_eq!(
853+
NvvmArch::Compute90a.all_target_features(),
854+
vec![
855+
"compute_35",
856+
"compute_37",
857+
"compute_50",
858+
"compute_52",
859+
"compute_53",
860+
"compute_60",
861+
"compute_61",
862+
"compute_62",
863+
"compute_70",
864+
"compute_72",
865+
"compute_75",
866+
"compute_80",
867+
"compute_86",
868+
"compute_87",
869+
"compute_89",
870+
"compute_90",
871+
"compute_90a",
872+
]
873+
);
874+
875+
// Test compute100a - should include base variants up to 100, and 100f, and itself,
876+
// but NOT 101f or 103f (higher minor).
877+
assert_eq!(
878+
NvvmArch::Compute100a.all_target_features(),
879+
vec![
880+
"compute_100",
881+
"compute_100a",
882+
"compute_100f",
883+
"compute_35",
884+
"compute_37",
885+
"compute_50",
886+
"compute_52",
887+
"compute_53",
888+
"compute_60",
889+
"compute_61",
890+
"compute_62",
891+
"compute_70",
892+
"compute_72",
893+
"compute_75",
894+
"compute_80",
895+
"compute_86",
896+
"compute_87",
897+
"compute_89",
898+
"compute_90",
899+
]
900+
);
871901

872902
// Test 'f' variant with 100f
873-
let compute100f_features = NvvmArch::Compute100f.all_target_features();
874-
assert!(compute100f_features.contains(&"compute_100".to_string())); // Same version base
875-
assert!(compute100f_features.contains(&"compute_101".to_string())); // Higher minor
876-
assert!(compute100f_features.contains(&"compute_103".to_string())); // Higher minor
877-
assert!(compute100f_features.contains(&"compute_100f".to_string())); // Self
878-
assert!(!compute100f_features.contains(&"compute_101f".to_string())); // No other 'f' variants
879-
assert!(!compute100f_features.contains(&"compute_90".to_string())); // Different major
903+
assert_eq!(
904+
NvvmArch::Compute100f.all_target_features(),
905+
// FIXME: this is wrong
906+
vec!["compute_100", "compute_100f", "compute_101", "compute_103"]
907+
);
908+
909+
// Test compute101a - should include base variants up to 101, and 100f and 101f, and
910+
// itself, but not 103f (higher minor)
911+
assert_eq!(
912+
NvvmArch::Compute101a.all_target_features(),
913+
vec![
914+
"compute_100",
915+
"compute_100f",
916+
"compute_101",
917+
"compute_101a",
918+
"compute_101f",
919+
"compute_35",
920+
"compute_37",
921+
"compute_50",
922+
"compute_52",
923+
"compute_53",
924+
"compute_60",
925+
"compute_61",
926+
"compute_62",
927+
"compute_70",
928+
"compute_72",
929+
"compute_75",
930+
"compute_80",
931+
"compute_86",
932+
"compute_87",
933+
"compute_89",
934+
"compute_90",
935+
]
936+
);
880937

881938
// Test 'f' variant with 101f
882-
let compute101f_features = NvvmArch::Compute101f.all_target_features();
883-
assert!(!compute101f_features.contains(&"compute_100".to_string())); // Lower minor NOT included
884-
assert!(compute101f_features.contains(&"compute_101".to_string())); // Same version base
885-
assert!(compute101f_features.contains(&"compute_103".to_string())); // Higher minor included
886-
assert!(compute101f_features.contains(&"compute_101f".to_string())); // Self
887-
assert!(!compute101f_features.contains(&"compute_101a".to_string())); // No 'a' variants
888-
889-
// Test compute101a
890-
let compute101a_features = NvvmArch::Compute101a.all_target_features();
891-
// Should include all base up to 101
892-
assert!(compute101a_features.contains(&"compute_100".to_string()));
893-
assert!(compute101a_features.contains(&"compute_101".to_string()));
894-
// Should include 100f and 101f (same major, <= minor)
895-
assert!(compute101a_features.contains(&"compute_100f".to_string()));
896-
assert!(compute101a_features.contains(&"compute_101f".to_string()));
897-
// Should NOT include 103f (higher minor)
898-
assert!(!compute101a_features.contains(&"compute_103f".to_string()));
899-
// Should include itself
900-
assert!(compute101a_features.contains(&"compute_101a".to_string()));
901-
902-
// Test 'f' variant - includes same major version with >= minor
903-
let compute120f_features = NvvmArch::Compute120f.all_target_features();
904-
assert!(compute120f_features.contains(&"compute_120".to_string()));
905-
assert!(compute120f_features.contains(&"compute_121".to_string())); // Higher minor included
906-
assert!(compute120f_features.contains(&"compute_120f".to_string())); // Self included
907-
assert!(!compute120f_features.contains(&"compute_120a".to_string())); // No 'a' variants
908-
assert!(!compute120f_features.contains(&"compute_121f".to_string())); // No other 'f' variants
909-
assert!(!compute120f_features.contains(&"compute_121a".to_string())); // No 'a' variants
910-
// Should NOT include different major versions
911-
assert!(!compute120f_features.contains(&"compute_100".to_string()));
912-
assert!(!compute120f_features.contains(&"compute_90".to_string()));
939+
assert_eq!(
940+
NvvmArch::Compute101f.all_target_features(),
941+
vec!["compute_101", "compute_101f", "compute_103"],
942+
);
943+
944+
assert_eq!(
945+
NvvmArch::Compute120.all_target_features(),
946+
vec![
947+
"compute_100",
948+
"compute_101",
949+
"compute_103",
950+
"compute_120",
951+
"compute_35",
952+
"compute_37",
953+
"compute_50",
954+
"compute_52",
955+
"compute_53",
956+
"compute_60",
957+
"compute_61",
958+
"compute_62",
959+
"compute_70",
960+
"compute_72",
961+
"compute_75",
962+
"compute_80",
963+
"compute_86",
964+
"compute_87",
965+
"compute_89",
966+
"compute_90",
967+
]
968+
);
969+
970+
assert_eq!(
971+
NvvmArch::Compute120f.all_target_features(),
972+
// FIXME: this is wrong
973+
vec!["compute_120", "compute_120f", "compute_121"]
974+
);
975+
976+
assert_eq!(
977+
NvvmArch::Compute120a.all_target_features(),
978+
vec![
979+
"compute_100",
980+
"compute_101",
981+
"compute_103",
982+
"compute_120",
983+
"compute_120a",
984+
"compute_120f",
985+
"compute_35",
986+
"compute_37",
987+
"compute_50",
988+
"compute_52",
989+
"compute_53",
990+
"compute_60",
991+
"compute_61",
992+
"compute_62",
993+
"compute_70",
994+
"compute_72",
995+
"compute_75",
996+
"compute_80",
997+
"compute_86",
998+
"compute_87",
999+
"compute_89",
1000+
"compute_90",
1001+
]
1002+
);
9131003
}
9141004

9151005
#[test]

0 commit comments

Comments
 (0)