Skip to content

Commit c06d197

Browse files
authored
Merge pull request #1948 from folkertdev/forward-percentage
Forward `TEST_SAMPLE_INTRINSICS_PERCENTAGE`
2 parents 8b2dd9c + 1062fc6 commit c06d197

File tree

7 files changed

+38
-21
lines changed

7 files changed

+38
-21
lines changed

ci/intrinsic-test-docker.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ run() {
3636
--env NORUN \
3737
--env RUSTFLAGS \
3838
--env CARGO_UNSTABLE_BUILD_STD \
39+
--env TEST_SAMPLE_INTRINSICS_PERCENTAGE \
3940
--volume "${HOME}/.cargo":/cargo \
4041
--volume "$(rustc --print sysroot)":/rust:ro \
4142
--volume "$(pwd)":/checkout:ro \

ci/intrinsic-test.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,31 @@ case ${TARGET} in
5151
TEST_SKIP_INTRINSICS=crates/intrinsic-test/missing_aarch64.txt
5252
TEST_CXX_COMPILER="clang++"
5353
TEST_RUNNER="${CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER}"
54+
: "${TEST_SAMPLE_INTRINSICS_PERCENTAGE:=100}"
5455
;;
5556

5657
aarch64_be-unknown-linux-gnu*)
5758
TEST_CPPFLAGS="-fuse-ld=lld"
5859
TEST_SKIP_INTRINSICS=crates/intrinsic-test/missing_aarch64.txt
5960
TEST_CXX_COMPILER="clang++"
6061
TEST_RUNNER="${CARGO_TARGET_AARCH64_BE_UNKNOWN_LINUX_GNU_RUNNER}"
62+
: "${TEST_SAMPLE_INTRINSICS_PERCENTAGE:=100}"
6163
;;
6264

6365
armv7-unknown-linux-gnueabihf*)
6466
TEST_CPPFLAGS="-fuse-ld=lld -I/usr/arm-linux-gnueabihf/include/ -I/usr/arm-linux-gnueabihf/include/c++/9/arm-linux-gnueabihf/"
6567
TEST_SKIP_INTRINSICS=crates/intrinsic-test/missing_arm.txt
6668
TEST_CXX_COMPILER="clang++"
6769
TEST_RUNNER="${CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_RUNNER}"
70+
: "${TEST_SAMPLE_INTRINSICS_PERCENTAGE:=100}"
6871
;;
6972

7073
x86_64-unknown-linux-gnu*)
7174
TEST_CPPFLAGS="-fuse-ld=lld -I/usr/include/x86_64-linux-gnu/"
7275
TEST_CXX_COMPILER="clang++"
7376
TEST_RUNNER="${CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER}"
7477
TEST_SKIP_INTRINSICS=crates/intrinsic-test/missing_x86.txt
75-
TEST_SAMPLE_INTRINSICS_PERCENTAGE=5
78+
: "${TEST_SAMPLE_INTRINSICS_PERCENTAGE:=5}"
7679
;;
7780
*)
7881
;;
@@ -82,23 +85,25 @@ esac
8285
# Arm specific
8386
case "${TARGET}" in
8487
aarch64-unknown-linux-gnu*|armv7-unknown-linux-gnueabihf*)
85-
CPPFLAGS="${TEST_CPPFLAGS}" RUSTFLAGS="${HOST_RUSTFLAGS}" RUST_LOG=warn \
88+
CPPFLAGS="${TEST_CPPFLAGS}" RUSTFLAGS="${HOST_RUSTFLAGS}" RUST_LOG=info \
8689
cargo run "${INTRINSIC_TEST}" "${PROFILE}" \
8790
--bin intrinsic-test -- intrinsics_data/arm_intrinsics.json \
8891
--runner "${TEST_RUNNER}" \
8992
--cppcompiler "${TEST_CXX_COMPILER}" \
9093
--skip "${TEST_SKIP_INTRINSICS}" \
91-
--target "${TARGET}"
94+
--target "${TARGET}" \
95+
--sample-percentage "${TEST_SAMPLE_INTRINSICS_PERCENTAGE}"
9296
;;
9397

9498
aarch64_be-unknown-linux-gnu*)
95-
CPPFLAGS="${TEST_CPPFLAGS}" RUSTFLAGS="${HOST_RUSTFLAGS}" RUST_LOG=warn \
99+
CPPFLAGS="${TEST_CPPFLAGS}" RUSTFLAGS="${HOST_RUSTFLAGS}" RUST_LOG=info \
96100
cargo run "${INTRINSIC_TEST}" "${PROFILE}" \
97101
--bin intrinsic-test -- intrinsics_data/arm_intrinsics.json \
98102
--runner "${TEST_RUNNER}" \
99103
--cppcompiler "${TEST_CXX_COMPILER}" \
100104
--skip "${TEST_SKIP_INTRINSICS}" \
101105
--target "${TARGET}" \
106+
--sample-percentage "${TEST_SAMPLE_INTRINSICS_PERCENTAGE}" \
102107
--linker "${CARGO_TARGET_AARCH64_BE_UNKNOWN_LINUX_GNU_LINKER}" \
103108
--cxx-toolchain-dir "${AARCH64_BE_TOOLCHAIN}"
104109
;;
@@ -109,7 +114,7 @@ case "${TARGET}" in
109114
# Hence the use of `env -u`.
110115
env -u CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER \
111116
CPPFLAGS="${TEST_CPPFLAGS}" RUSTFLAGS="${HOST_RUSTFLAGS}" \
112-
RUST_LOG=warn RUST_BACKTRACE=1 \
117+
RUST_LOG=info RUST_BACKTRACE=1 \
113118
cargo run "${INTRINSIC_TEST}" "${PROFILE}" \
114119
--bin intrinsic-test -- intrinsics_data/x86-intel.xml \
115120
--runner "${TEST_RUNNER}" \

crates/intrinsic-test/src/arm/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
4848
.expect("Error parsing input file");
4949

5050
intrinsics.sort_by(|a, b| a.name.cmp(&b.name));
51+
intrinsics.dedup();
52+
53+
let sample_percentage: usize = cli_options.sample_percentage as usize;
54+
let sample_size = (intrinsics.len() * sample_percentage) / 100;
5155

52-
let mut intrinsics = intrinsics
56+
let intrinsics = intrinsics
5357
.into_iter()
5458
// Not sure how we would compare intrinsic that returns void.
5559
.filter(|i| i.results.kind() != TypeKind::Void)
@@ -61,8 +65,8 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
6165
.filter(|i| !i.arguments.iter().any(|a| a.ty.inner_size() == 128))
6266
.filter(|i| !cli_options.skip.contains(&i.name))
6367
.filter(|i| !(a32 && i.arch_tags == vec!["A64".to_string()]))
68+
.take(sample_size)
6469
.collect::<Vec<_>>();
65-
intrinsics.dedup();
6670

6771
Self {
6872
intrinsics,

crates/intrinsic-test/src/common/compare.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ pub fn compare_outputs(intrinsic_name_list: &Vec<String>, runner: &str, target:
8686
println!("Failed to run rust program for intrinsic {intrinsic}")
8787
}
8888
});
89-
println!("{} differences found", intrinsics.len());
89+
println!(
90+
"{} differences found (tested {} intrinsics)",
91+
intrinsics.len(),
92+
intrinsic_name_list.len()
93+
);
9094
intrinsics.is_empty()
9195
}

crates/intrinsic-test/src/common/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,16 @@ pub trait SupportedArchitectureTest {
7979
trace!("compiling mod_{i}.cpp");
8080
if let Some(cpp_compiler) = cpp_compiler_wrapped.as_ref() {
8181
let compile_output = cpp_compiler
82-
.compile_object_file(&format!("mod_{i}.cpp"), &format!("mod_{i}.o"));
82+
.compile_object_file(&format!("mod_{i}.cpp"), &format!("mod_{i}.o"))
83+
.map_err(|e| format!("Error compiling mod_{i}.cpp: {e:?}"))?;
84+
85+
assert!(
86+
compile_output.status.success(),
87+
"{}",
88+
String::from_utf8_lossy(&compile_output.stderr)
89+
);
8390

8491
trace!("finished compiling mod_{i}.cpp");
85-
if let Err(compile_error) = compile_output {
86-
return Err(format!("Error compiling mod_{i}.cpp: {compile_error:?}"));
87-
}
8892
}
8993
Ok(())
9094
})

crates/intrinsic-test/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn run(test_environment: impl SupportedArchitectureTest) {
3434
if !test_environment.build_rust_file() {
3535
std::process::exit(3);
3636
}
37-
info!("comaparing outputs");
37+
info!("comparing outputs");
3838
if !test_environment.compare_outputs() {
3939
std::process::exit(1);
4040
}

crates/intrinsic-test/src/x86/mod.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::common::compile_c::CppCompilation;
1111
use crate::common::intrinsic::Intrinsic;
1212
use crate::common::intrinsic_helpers::TypeKind;
1313
use intrinsic::X86IntrinsicType;
14-
use itertools::Itertools;
1514
use xml_parser::get_xml_intrinsics;
1615

1716
pub struct X86ArchitectureTest {
@@ -44,12 +43,16 @@ impl SupportedArchitectureTest for X86ArchitectureTest {
4443
const PLATFORM_RUST_CFGS: &str = config::PLATFORM_RUST_CFGS;
4544

4645
fn create(cli_options: ProcessedCli) -> Self {
47-
let intrinsics =
46+
let mut intrinsics =
4847
get_xml_intrinsics(&cli_options.filename).expect("Error parsing input file");
4948

49+
intrinsics.sort_by(|a, b| a.name.cmp(&b.name));
50+
intrinsics.dedup_by(|a, b| a.name == b.name);
51+
5052
let sample_percentage: usize = cli_options.sample_percentage as usize;
53+
let sample_size = (intrinsics.len() * sample_percentage) / 100;
5154

52-
let mut intrinsics = intrinsics
55+
let intrinsics = intrinsics
5356
.into_iter()
5457
// Not sure how we would compare intrinsic that returns void.
5558
.filter(|i| i.results.kind() != TypeKind::Void)
@@ -61,13 +64,9 @@ impl SupportedArchitectureTest for X86ArchitectureTest {
6164
.filter(|i| !i.arguments.iter().any(|a| a.is_ptr()))
6265
.filter(|i| !i.arguments.iter().any(|a| a.ty.inner_size() == 128))
6366
.filter(|i| !cli_options.skip.contains(&i.name))
64-
.unique_by(|i| i.name.clone())
67+
.take(sample_size)
6568
.collect::<Vec<_>>();
6669

67-
let sample_size = (intrinsics.len() * sample_percentage) / 100;
68-
intrinsics.truncate(sample_size);
69-
70-
intrinsics.sort_by(|a, b| a.name.cmp(&b.name));
7170
Self {
7271
intrinsics: intrinsics,
7372
cli_options: cli_options,

0 commit comments

Comments
 (0)