Skip to content

Commit 3054d52

Browse files
nnethercoteLegNeato
authored andcommitted
Minor NvvmArch test fixes.
- Improve a few comments. - Combine three `nvvm_arch_target_feature_format_*` tests into one. - Avoid some unnecessary local variables. - Rename `nvvm_arch_all_target_features_includes_lower_capabilities`, and order things more sensibly within it. - Remove `target_feature_synthesis_supports_conditional_compilation_patterns` and `target_feature_synthesis_enables_correct_cfg_patterns` and `nvvm_arch_a_suffix_includes_all_available_instructions`. They are all testing the same things as `nvvm_arch_all_target_features`. (A couple of things from them were moved into `nvvm_arch_all_target_features`, to preserve test coverage.) This all just makes things more streamlined and avoids repetition, to get ready for subsequent changes.
1 parent 8c9e53a commit 3054d52

File tree

1 file changed

+71
-162
lines changed

1 file changed

+71
-162
lines changed

crates/nvvm/src/lib.rs

Lines changed: 71 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -750,34 +750,24 @@ mod tests {
750750
}
751751

752752
#[test]
753-
fn nvvm_arch_target_feature_format_base_variants() {
753+
fn nvvm_arch_target_feature() {
754754
use crate::NvvmArch;
755755

756-
// Test base variants format
756+
// Test baseline features
757757
assert_eq!(NvvmArch::Compute35.target_feature(), "compute_35");
758758
assert_eq!(NvvmArch::Compute61.target_feature(), "compute_61");
759759
assert_eq!(NvvmArch::Compute90.target_feature(), "compute_90");
760760
assert_eq!(NvvmArch::Compute100.target_feature(), "compute_100");
761761
assert_eq!(NvvmArch::Compute120.target_feature(), "compute_120");
762-
}
763762

764-
#[test]
765-
fn nvvm_arch_target_feature_format_family_variants() {
766-
use crate::NvvmArch;
767-
768-
// Test family ('f') variants format
763+
// Test family-specfic ('f') features
769764
assert_eq!(NvvmArch::Compute100f.target_feature(), "compute_100f");
770765
assert_eq!(NvvmArch::Compute101f.target_feature(), "compute_101f");
771766
assert_eq!(NvvmArch::Compute103f.target_feature(), "compute_103f");
772767
assert_eq!(NvvmArch::Compute120f.target_feature(), "compute_120f");
773768
assert_eq!(NvvmArch::Compute121f.target_feature(), "compute_121f");
774-
}
775769

776-
#[test]
777-
fn nvvm_arch_target_feature_format_architecture_variants() {
778-
use crate::NvvmArch;
779-
780-
// Test architecture ('a') variants format
770+
// Test architecture-specific ('a') features
781771
assert_eq!(NvvmArch::Compute90a.target_feature(), "compute_90a");
782772
assert_eq!(NvvmArch::Compute100a.target_feature(), "compute_100a");
783773
assert_eq!(NvvmArch::Compute101a.target_feature(), "compute_101a");
@@ -787,32 +777,72 @@ mod tests {
787777
}
788778

789779
#[test]
790-
fn nvvm_arch_all_target_features_includes_lower_capabilities() {
780+
fn nvvm_arch_all_target_features() {
791781
use crate::NvvmArch;
792782

793783
// Compute35 only includes itself
794-
let compute35_features = NvvmArch::Compute35.all_target_features();
795-
assert_eq!(compute35_features, vec!["compute_35"]);
784+
assert_eq!(
785+
NvvmArch::Compute35.all_target_features(),
786+
vec!["compute_35"]
787+
);
796788

797789
// Compute50 includes all lower base capabilities
798-
let compute50_features = NvvmArch::Compute50.all_target_features();
799790
assert_eq!(
800-
compute50_features,
801-
vec!["compute_35", "compute_37", "compute_50"]
791+
NvvmArch::Compute50.all_target_features(),
792+
vec!["compute_35", "compute_37", "compute_50"],
802793
);
803794

804795
// Compute61 includes all lower base capabilities
805-
let compute61_features = NvvmArch::Compute61.all_target_features();
806796
assert_eq!(
807-
compute61_features,
797+
NvvmArch::Compute61.all_target_features(),
808798
vec![
809799
"compute_35",
810800
"compute_37",
811801
"compute_50",
812802
"compute_52",
813803
"compute_53",
814804
"compute_60",
815-
"compute_61"
805+
"compute_61",
806+
]
807+
);
808+
809+
// Compute70 includes all lower base capabilities
810+
assert_eq!(
811+
NvvmArch::Compute70.all_target_features(),
812+
vec![
813+
"compute_35",
814+
"compute_37",
815+
"compute_50",
816+
"compute_52",
817+
"compute_53",
818+
"compute_60",
819+
"compute_61",
820+
"compute_62",
821+
"compute_70",
822+
]
823+
);
824+
825+
// Compute90 includes lower base capabilities
826+
let compute90_features = NvvmArch::Compute90.all_target_features();
827+
assert_eq!(
828+
compute90_features,
829+
vec![
830+
"compute_35",
831+
"compute_37",
832+
"compute_50",
833+
"compute_52",
834+
"compute_53",
835+
"compute_60",
836+
"compute_61",
837+
"compute_62",
838+
"compute_70",
839+
"compute_72",
840+
"compute_75",
841+
"compute_80",
842+
"compute_86",
843+
"compute_87",
844+
"compute_89",
845+
"compute_90",
816846
]
817847
);
818848

@@ -839,6 +869,23 @@ mod tests {
839869
// Should include itself
840870
assert!(compute100a_features.contains(&"compute_100a".to_string()));
841871

872+
// 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
880+
881+
// 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+
842889
// Test compute101a
843890
let compute101a_features = NvvmArch::Compute101a.all_target_features();
844891
// Should include all base up to 101
@@ -863,112 +910,6 @@ mod tests {
863910
// Should NOT include different major versions
864911
assert!(!compute120f_features.contains(&"compute_100".to_string()));
865912
assert!(!compute120f_features.contains(&"compute_90".to_string()));
866-
867-
// Test 'f' variant with 100f
868-
let compute100f_features = NvvmArch::Compute100f.all_target_features();
869-
assert!(compute100f_features.contains(&"compute_100".to_string())); // Same version base
870-
assert!(compute100f_features.contains(&"compute_101".to_string())); // Higher minor
871-
assert!(compute100f_features.contains(&"compute_103".to_string())); // Higher minor
872-
assert!(compute100f_features.contains(&"compute_100f".to_string())); // Self
873-
assert!(!compute100f_features.contains(&"compute_101f".to_string())); // No other 'f' variants
874-
assert!(!compute100f_features.contains(&"compute_90".to_string())); // Different major
875-
876-
// Test 'f' variant with 101f
877-
let compute101f_features = NvvmArch::Compute101f.all_target_features();
878-
assert!(!compute101f_features.contains(&"compute_100".to_string())); // Lower minor NOT included
879-
assert!(compute101f_features.contains(&"compute_101".to_string())); // Same version base
880-
assert!(compute101f_features.contains(&"compute_103".to_string())); // Higher minor included
881-
assert!(compute101f_features.contains(&"compute_101f".to_string())); // Self
882-
assert!(!compute101f_features.contains(&"compute_101a".to_string())); // No 'a' variants
883-
884-
// Compute90 includes lower base capabilities
885-
let compute90_features = NvvmArch::Compute90.all_target_features();
886-
assert_eq!(
887-
compute90_features,
888-
vec![
889-
"compute_35",
890-
"compute_37",
891-
"compute_50",
892-
"compute_52",
893-
"compute_53",
894-
"compute_60",
895-
"compute_61",
896-
"compute_62",
897-
"compute_70",
898-
"compute_72",
899-
"compute_75",
900-
"compute_80",
901-
"compute_86",
902-
"compute_87",
903-
"compute_89",
904-
"compute_90"
905-
]
906-
);
907-
}
908-
909-
#[test]
910-
fn target_feature_synthesis_supports_conditional_compilation_patterns() {
911-
use crate::NvvmArch;
912-
913-
// When targeting Compute61, should enable all lower capabilities
914-
let features = NvvmArch::Compute61.all_target_features();
915-
916-
// Should enable compute_60 (for f64 atomics)
917-
assert!(features.contains(&"compute_60".to_string()));
918-
919-
// Should enable compute_50 (for 64-bit integer atomics)
920-
assert!(features.contains(&"compute_50".to_string()));
921-
922-
// Should enable compute_35 (baseline)
923-
assert!(features.contains(&"compute_35".to_string()));
924-
925-
// Should enable the target itself
926-
assert!(features.contains(&"compute_61".to_string()));
927-
928-
// Should NOT enable higher capabilities
929-
assert!(!features.contains(&"compute_62".to_string()));
930-
assert!(!features.contains(&"compute_70".to_string()));
931-
}
932-
933-
#[test]
934-
fn target_feature_synthesis_enables_correct_cfg_patterns() {
935-
use crate::NvvmArch;
936-
937-
// Test that targeting Compute70 enables appropriate cfg patterns
938-
let features = NvvmArch::Compute70.all_target_features();
939-
940-
// These should all be true for compute_70 target
941-
let expected_enabled = [
942-
"compute_35",
943-
"compute_37",
944-
"compute_50",
945-
"compute_52",
946-
"compute_53",
947-
"compute_60",
948-
"compute_61",
949-
"compute_62",
950-
"compute_70",
951-
];
952-
953-
for feature in expected_enabled {
954-
assert!(
955-
features.contains(&feature.to_string()),
956-
"Compute70 should enable {} for cfg(target_feature = \"{}\")",
957-
feature,
958-
feature
959-
);
960-
}
961-
962-
// These should NOT be enabled for compute_70 target
963-
let expected_disabled = ["compute_72", "compute_75", "compute_80", "compute_90"];
964-
965-
for feature in expected_disabled {
966-
assert!(
967-
!features.contains(&feature.to_string()),
968-
"Compute70 should NOT enable {}",
969-
feature
970-
);
971-
}
972913
}
973914

974915
#[test]
@@ -1098,7 +1039,7 @@ mod tests {
10981039
NvvmArch::Compute120
10991040
);
11001041

1101-
// Floating-point variants return base
1042+
// Family-specific variants return base
11021043
assert_eq!(
11031044
NvvmArch::Compute120f.base_architecture(),
11041045
NvvmArch::Compute120
@@ -1155,38 +1096,6 @@ mod tests {
11551096
assert!(compute120f_variants.contains(&NvvmArch::Compute120a));
11561097
}
11571098

1158-
#[test]
1159-
fn nvvm_arch_a_suffix_includes_all_available_instructions() {
1160-
use crate::NvvmArch;
1161-
1162-
// Test that 'a' suffix variants include all available instructions for the architecture
1163-
// While they only RUN on exact CC, they enable all base and family features during compilation
1164-
1165-
// Test Compute90a
1166-
let features = NvvmArch::Compute90a.all_target_features();
1167-
assert!(features.contains(&"compute_90a".to_string())); // Includes itself
1168-
assert!(features.contains(&"compute_90".to_string())); // Includes base
1169-
assert!(features.contains(&"compute_80".to_string())); // Includes lower versions
1170-
assert!(!features.contains(&"compute_100".to_string())); // Does NOT include higher versions
1171-
1172-
// Test Compute100a
1173-
let features = NvvmArch::Compute100a.all_target_features();
1174-
assert!(features.contains(&"compute_100a".to_string())); // Includes itself
1175-
assert!(features.contains(&"compute_100".to_string())); // Includes base
1176-
assert!(features.contains(&"compute_100f".to_string())); // Includes family variant
1177-
assert!(features.contains(&"compute_90".to_string())); // Includes lower base versions
1178-
assert!(!features.contains(&"compute_90a".to_string())); // Does NOT include other 'a' variants
1179-
assert!(!features.contains(&"compute_101f".to_string())); // Does NOT include higher minor family variants
1180-
1181-
// Test Compute120a
1182-
let features = NvvmArch::Compute120a.all_target_features();
1183-
assert!(features.contains(&"compute_120a".to_string())); // Includes itself
1184-
assert!(features.contains(&"compute_120".to_string())); // Includes base
1185-
assert!(features.contains(&"compute_120f".to_string())); // Includes family variant (same minor)
1186-
assert!(features.contains(&"compute_100".to_string())); // Includes lower base versions
1187-
assert!(!features.contains(&"compute_121f".to_string())); // Does NOT include higher minor family variants
1188-
}
1189-
11901099
#[test]
11911100
fn nvvm_arch_variants_for_capability() {
11921101
use crate::NvvmArch;

0 commit comments

Comments
 (0)