From 66f28cc23d837d590c5ad6f81d219a04c0ea81d5 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Thu, 14 Nov 2024 22:29:15 +0100 Subject: [PATCH 01/19] tr: generate an error if the input is a directory tested by tests/misc/read-errors --- src/uu/tr/src/operation.rs | 17 ++++++++++++++--- src/uu/tr/src/tr.rs | 10 +++++----- tests/by-util/test_tr.rs | 5 +++++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/uu/tr/src/operation.rs b/src/uu/tr/src/operation.rs index fc01a83608d..475a2b47903 100644 --- a/src/uu/tr/src/operation.rs +++ b/src/uu/tr/src/operation.rs @@ -22,7 +22,7 @@ use std::{ io::{BufRead, Write}, ops::Not, }; -use uucore::error::UError; +use uucore::error::{UError, UResult, USimpleError}; #[derive(Debug, Clone)] pub enum BadSequence { @@ -577,7 +577,7 @@ impl SymbolTranslator for SqueezeOperation { } } -pub fn translate_input(input: &mut R, output: &mut W, mut translator: T) +pub fn translate_input(input: &mut R, output: &mut W, mut translator: T) -> UResult<()> where T: SymbolTranslator, R: BufRead, @@ -585,7 +585,17 @@ where { let mut buf = Vec::new(); let mut output_buf = Vec::new(); - while let Ok(length) = input.read_until(b'\n', &mut buf) { + loop { + let length = match input.read_until(b'\n', &mut buf) { + Ok(0) => break, // EOF reached + Ok(n) => n, + Err(e) => { + return Err(USimpleError::new( + 1, + format!("{}: read error: {}", uucore::util_name(), e), + )); + } + }; if length == 0 { break; } else { @@ -596,4 +606,5 @@ where buf.clear(); output_buf.clear(); } + Ok(()) } diff --git a/src/uu/tr/src/tr.rs b/src/uu/tr/src/tr.rs index 67998d26d4b..ff85002e71d 100644 --- a/src/uu/tr/src/tr.rs +++ b/src/uu/tr/src/tr.rs @@ -132,24 +132,24 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let delete_op = DeleteOperation::new(set1); let squeeze_op = SqueezeOperation::new(set2); let op = delete_op.chain(squeeze_op); - translate_input(&mut locked_stdin, &mut buffered_stdout, op); + translate_input(&mut locked_stdin, &mut buffered_stdout, op)?; } else { let op = DeleteOperation::new(set1); - translate_input(&mut locked_stdin, &mut buffered_stdout, op); + translate_input(&mut locked_stdin, &mut buffered_stdout, op)?; } } else if squeeze_flag { if sets_len < 2 { let op = SqueezeOperation::new(set1); - translate_input(&mut locked_stdin, &mut buffered_stdout, op); + translate_input(&mut locked_stdin, &mut buffered_stdout, op)?; } else { let translate_op = TranslateOperation::new(set1, set2.clone())?; let squeeze_op = SqueezeOperation::new(set2); let op = translate_op.chain(squeeze_op); - translate_input(&mut locked_stdin, &mut buffered_stdout, op); + translate_input(&mut locked_stdin, &mut buffered_stdout, op)?; } } else { let op = TranslateOperation::new(set1, set2)?; - translate_input(&mut locked_stdin, &mut buffered_stdout, op); + translate_input(&mut locked_stdin, &mut buffered_stdout, op)?; } Ok(()) } diff --git a/tests/by-util/test_tr.rs b/tests/by-util/test_tr.rs index ebd7635e432..1c248b1065a 100644 --- a/tests/by-util/test_tr.rs +++ b/tests/by-util/test_tr.rs @@ -13,6 +13,11 @@ fn test_invalid_arg() { new_ucmd!().arg("--definitely-invalid").fails().code_is(1); } +#[test] +fn test_invalid_input() { + new_ucmd!().args(&["1", "1", "<", "."]).fails().code_is(1); +} + #[test] fn test_to_upper() { new_ucmd!() From 0cd58c63cf29fd9bcc2e1b50a927d48de064bfa1 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 16 Nov 2024 00:57:00 +0100 Subject: [PATCH 02/19] code coverage: if LLVM_PROFILE_FILE exists, pass it --- tests/common/util.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/common/util.rs b/tests/common/util.rs index 87c937492f3..ebe13a7749f 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -1614,6 +1614,11 @@ impl UCommand { } } + // Pass LLVM_PROFILE_FILE if it is set in the environment + if let Some(llvm_profile) = env::var_os("LLVM_PROFILE_FILE") { + command.env("LLVM_PROFILE_FILE", llvm_profile); + } + command .envs(DEFAULT_ENV) .envs(self.env_vars.iter().cloned()); From 83b1edd2cba74998ba87d5ceaa765d9bddbe6e46 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 16 Nov 2024 01:00:27 +0100 Subject: [PATCH 03/19] code coverage: Zprofile is deprecated, now replaced by -Cinstrument-coverage --- .github/workflows/CICD.yml | 10 ++++++---- .github/workflows/GnuTests.yml | 7 ++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 941bb49fad3..5e18d2bcc30 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -1014,16 +1014,18 @@ jobs: run: cargo nextest run --profile ci --hide-progress-bar ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} -p uucore -p coreutils env: RUSTC_WRAPPER: "" - RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort" + RUSTFLAGS: "-Cinstrument-coverage -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort" RUSTDOCFLAGS: "-Cpanic=abort" RUST_BACKTRACE: "1" + LLVM_PROFILE_FILE: ${{ github.workspace }}/build/profile-%p-%m.profraw # RUSTUP_TOOLCHAIN: ${{ steps.vars.outputs.TOOLCHAIN }} - name: Test individual utilities run: cargo nextest run --profile ci --hide-progress-bar ${{ steps.dep_vars.outputs.CARGO_UTILITY_LIST_OPTIONS }} env: RUSTC_WRAPPER: "" - RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort" + RUSTFLAGS: "-Cinstrument-coverage -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort" RUSTDOCFLAGS: "-Cpanic=abort" + LLVM_PROFILE_FILE: ${{ github.workspace }}/build/profile-%p-%m.profraw RUST_BACKTRACE: "1" # RUSTUP_TOOLCHAIN: ${{ steps.vars.outputs.TOOLCHAIN }} - name: Generate coverage data (via `grcov`) @@ -1037,9 +1039,9 @@ jobs: # GRCOV_EXCLUDE_OPTION='--excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()"' ## `grcov` ignores these params when passed as an environment variable (why?) mkdir -p "${COVERAGE_REPORT_DIR}" # display coverage files - grcov . --output-type files --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" | sort --unique + grcov ${{ github.workspace }}/build/profile-%p-%m.profraw --output-type files --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" | sort --unique # generate coverage report - grcov . --output-type lcov --output-path "${COVERAGE_REPORT_FILE}" --branch --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" + grcov ${{ github.workspace }}/build/profile-%p-%m.profraw --output-type lcov --output-path "${COVERAGE_REPORT_FILE}" --branch --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" echo "report=${COVERAGE_REPORT_FILE}" >> $GITHUB_OUTPUT - name: Upload coverage results (to Codecov.io) uses: codecov/codecov-action@v4 diff --git a/.github/workflows/GnuTests.yml b/.github/workflows/GnuTests.yml index fc165e0b3e5..41091cc1696 100644 --- a/.github/workflows/GnuTests.yml +++ b/.github/workflows/GnuTests.yml @@ -383,8 +383,9 @@ jobs: locale -a - name: Build binaries env: - RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort" + RUSTFLAGS: "-Cinstrument-coverage -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort" RUSTDOCFLAGS: "-Cpanic=abort" + LLVM_PROFILE_FILE: ${{ github.workspace }}/build/profile-%p-%m.profraw run: | ## Build binaries cd uutils @@ -401,9 +402,9 @@ jobs: mkdir -p "${COVERAGE_REPORT_DIR}" sudo chown -R "$(whoami)" "${COVERAGE_REPORT_DIR}" # display coverage files - grcov . --output-type files --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" | sort --unique + grcov ${{ github.workspace }}/build/profile-%p-%m.profraw --output-type files --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" | sort --unique # generate coverage report - grcov . --output-type lcov --output-path "${COVERAGE_REPORT_FILE}" --branch --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" + grcov ${{ github.workspace }}/build/profile-%p-%m.profraw --output-type lcov --output-path "${COVERAGE_REPORT_FILE}" --branch --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" echo "report=${COVERAGE_REPORT_FILE}" >> $GITHUB_OUTPUT - name: Upload coverage results (to Codecov.io) uses: codecov/codecov-action@v4 From 9bd2c658a6572da168f9542498d037e12dafdd6f Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 16 Nov 2024 01:30:20 +0100 Subject: [PATCH 04/19] env test: filter the coverage output --- tests/by-util/test_env.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/by-util/test_env.rs b/tests/by-util/test_env.rs index 208feab6db2..f9d81dbd97f 100644 --- a/tests/by-util/test_env.rs +++ b/tests/by-util/test_env.rs @@ -512,7 +512,14 @@ fn test_gnu_e20() { ); let out = scene.ucmd().args(&input).succeeds(); - assert_eq!(out.stdout_str(), output); + + // Remove the unwanted substring from stdout + let filtered_stdout = out.stdout_str().replace( + "__LLVM_PROFILE_RT_INIT_ONCE=__LLVM_PROFILE_RT_INIT_ONCE\n", + "", + ); + + assert_eq!(filtered_stdout, output); } #[test] From 4a56972ab9d561a2019910647936fd883c8e5452 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 16 Nov 2024 09:53:01 +0100 Subject: [PATCH 05/19] remove comment code --- .github/workflows/CICD.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 5e18d2bcc30..4ee8cb8b227 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -1035,8 +1035,6 @@ jobs: ## Generate coverage data COVERAGE_REPORT_DIR="target/debug" COVERAGE_REPORT_FILE="${COVERAGE_REPORT_DIR}/lcov.info" - # GRCOV_IGNORE_OPTION='--ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*"' ## `grcov` ignores these params when passed as an environment variable (why?) - # GRCOV_EXCLUDE_OPTION='--excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()"' ## `grcov` ignores these params when passed as an environment variable (why?) mkdir -p "${COVERAGE_REPORT_DIR}" # display coverage files grcov ${{ github.workspace }}/build/profile-%p-%m.profraw --output-type files --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" | sort --unique From 4fe61b339a1f51f9c84aaead1d8368b550a28f4a Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 16 Nov 2024 09:53:17 +0100 Subject: [PATCH 06/19] try to pass the path --- .github/workflows/CICD.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 4ee8cb8b227..5c1697c5bf9 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -1037,9 +1037,9 @@ jobs: COVERAGE_REPORT_FILE="${COVERAGE_REPORT_DIR}/lcov.info" mkdir -p "${COVERAGE_REPORT_DIR}" # display coverage files - grcov ${{ github.workspace }}/build/profile-%p-%m.profraw --output-type files --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" | sort --unique + grcov ${{ github.workspace }}/build/ . --output-type files --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" | sort --unique # generate coverage report - grcov ${{ github.workspace }}/build/profile-%p-%m.profraw --output-type lcov --output-path "${COVERAGE_REPORT_FILE}" --branch --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" + grcov ${{ github.workspace }}/build/ . --output-type lcov --output-path "${COVERAGE_REPORT_FILE}" --branch --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" echo "report=${COVERAGE_REPORT_FILE}" >> $GITHUB_OUTPUT - name: Upload coverage results (to Codecov.io) uses: codecov/codecov-action@v4 From 133eaca2d5e9862a5f544291db152a4a561b8400 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 16 Nov 2024 10:03:42 +0100 Subject: [PATCH 07/19] add debug info --- .github/workflows/CICD.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 5c1697c5bf9..311a42898a6 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -1037,6 +1037,8 @@ jobs: COVERAGE_REPORT_FILE="${COVERAGE_REPORT_DIR}/lcov.info" mkdir -p "${COVERAGE_REPORT_DIR}" # display coverage files + ls -al ${{ github.workspace }}/build/ + ls -al . grcov ${{ github.workspace }}/build/ . --output-type files --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" | sort --unique # generate coverage report grcov ${{ github.workspace }}/build/ . --output-type lcov --output-path "${COVERAGE_REPORT_FILE}" --branch --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" From f22664e19852a6a57dec795e64c47219690c4730 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 16 Nov 2024 10:10:29 +0100 Subject: [PATCH 08/19] try with quotes --- .github/workflows/CICD.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 311a42898a6..f39e74a99e7 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -1017,7 +1017,7 @@ jobs: RUSTFLAGS: "-Cinstrument-coverage -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort" RUSTDOCFLAGS: "-Cpanic=abort" RUST_BACKTRACE: "1" - LLVM_PROFILE_FILE: ${{ github.workspace }}/build/profile-%p-%m.profraw + LLVM_PROFILE_FILE: "${{ github.workspace }}/build/profile-%p-%m.profraw" # RUSTUP_TOOLCHAIN: ${{ steps.vars.outputs.TOOLCHAIN }} - name: Test individual utilities run: cargo nextest run --profile ci --hide-progress-bar ${{ steps.dep_vars.outputs.CARGO_UTILITY_LIST_OPTIONS }} From 38e528288023beb6a6e9f1cfff3a499a274850a5 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 16 Nov 2024 10:12:36 +0100 Subject: [PATCH 09/19] try to pass -b to grcov --- .github/workflows/CICD.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index f39e74a99e7..d348438bb06 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -1039,9 +1039,9 @@ jobs: # display coverage files ls -al ${{ github.workspace }}/build/ ls -al . - grcov ${{ github.workspace }}/build/ . --output-type files --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" | sort --unique + grcov ${{ github.workspace }}/build/ --output-type files -b target/debug/ --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" | sort --unique # generate coverage report - grcov ${{ github.workspace }}/build/ . --output-type lcov --output-path "${COVERAGE_REPORT_FILE}" --branch --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" + grcov ${{ github.workspace }}/build/ --output-type lcov -b target/debug/ --output-path "${COVERAGE_REPORT_FILE}" --branch --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" echo "report=${COVERAGE_REPORT_FILE}" >> $GITHUB_OUTPUT - name: Upload coverage results (to Codecov.io) uses: codecov/codecov-action@v4 From eafca5dc06780c473aac6c3d1dccaf3aa1d76fbb Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 16 Nov 2024 10:27:43 +0100 Subject: [PATCH 10/19] add llvm-tools-preview --- .github/workflows/CICD.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index d348438bb06..3b8da894d7a 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -945,7 +945,7 @@ jobs: - uses: dtolnay/rust-toolchain@master with: toolchain: ${{ matrix.job.toolchain }} - components: rustfmt + components: llvm-tools-preview - uses: taiki-e/install-action@nextest - uses: taiki-e/install-action@grcov - uses: Swatinem/rust-cache@v2 From dd714860959a06c85850f65f027647e87824fbf8 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 16 Nov 2024 10:27:52 +0100 Subject: [PATCH 11/19] remove debug info --- .github/workflows/CICD.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 3b8da894d7a..1af9b4d013c 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -1037,8 +1037,6 @@ jobs: COVERAGE_REPORT_FILE="${COVERAGE_REPORT_DIR}/lcov.info" mkdir -p "${COVERAGE_REPORT_DIR}" # display coverage files - ls -al ${{ github.workspace }}/build/ - ls -al . grcov ${{ github.workspace }}/build/ --output-type files -b target/debug/ --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" | sort --unique # generate coverage report grcov ${{ github.workspace }}/build/ --output-type lcov -b target/debug/ --output-path "${COVERAGE_REPORT_FILE}" --branch --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" From 19eb9aea60b48e51bd0c0a492348fa21715f478c Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 16 Nov 2024 11:03:28 +0100 Subject: [PATCH 12/19] add more debug info --- .github/workflows/CICD.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 1af9b4d013c..938be8eaada 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -1006,6 +1006,8 @@ jobs: run: | ## Dependent VARs setup outputs() { step_id="${{ github.action }}"; for var in "$@" ; do echo steps.${step_id}.outputs.${var}="${!var}"; echo "${var}=${!var}" >> $GITHUB_OUTPUT; done; } + df -h . + df -h ${{ github.workspace }} # * determine sub-crate utility list UTILITY_LIST="$(./util/show-utils.sh ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }})" CARGO_UTILITY_LIST_OPTIONS="$(for u in ${UTILITY_LIST}; do echo -n "-puu_${u} "; done;)" @@ -1017,7 +1019,7 @@ jobs: RUSTFLAGS: "-Cinstrument-coverage -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort" RUSTDOCFLAGS: "-Cpanic=abort" RUST_BACKTRACE: "1" - LLVM_PROFILE_FILE: "${{ github.workspace }}/build/profile-%p-%m.profraw" + LLVM_PROFILE_FILE: "${{ github.workspace }}/build/coverage-%p-%m.profraw" # RUSTUP_TOOLCHAIN: ${{ steps.vars.outputs.TOOLCHAIN }} - name: Test individual utilities run: cargo nextest run --profile ci --hide-progress-bar ${{ steps.dep_vars.outputs.CARGO_UTILITY_LIST_OPTIONS }} @@ -1025,7 +1027,7 @@ jobs: RUSTC_WRAPPER: "" RUSTFLAGS: "-Cinstrument-coverage -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort" RUSTDOCFLAGS: "-Cpanic=abort" - LLVM_PROFILE_FILE: ${{ github.workspace }}/build/profile-%p-%m.profraw + LLVM_PROFILE_FILE: "${{ github.workspace }}/build/coverage-%p-%m.profraw" RUST_BACKTRACE: "1" # RUSTUP_TOOLCHAIN: ${{ steps.vars.outputs.TOOLCHAIN }} - name: Generate coverage data (via `grcov`) @@ -1036,7 +1038,9 @@ jobs: COVERAGE_REPORT_DIR="target/debug" COVERAGE_REPORT_FILE="${COVERAGE_REPORT_DIR}/lcov.info" mkdir -p "${COVERAGE_REPORT_DIR}" - # display coverage files + # display coverage files (for debug) + ls -al ${{ github.workspace }}/build/|head -5 + ls -al target/debug|head -5 grcov ${{ github.workspace }}/build/ --output-type files -b target/debug/ --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" | sort --unique # generate coverage report grcov ${{ github.workspace }}/build/ --output-type lcov -b target/debug/ --output-path "${COVERAGE_REPORT_FILE}" --branch --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" From 50b62fdbf30b9cb0425929e4f674c47c9960e844 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 16 Nov 2024 11:13:00 +0100 Subject: [PATCH 13/19] add more debug info --- .github/workflows/CICD.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 938be8eaada..6e790d384db 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -1040,7 +1040,8 @@ jobs: mkdir -p "${COVERAGE_REPORT_DIR}" # display coverage files (for debug) ls -al ${{ github.workspace }}/build/|head -5 - ls -al target/debug|head -5 + ls -al target/ + ls -al target/debug grcov ${{ github.workspace }}/build/ --output-type files -b target/debug/ --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" | sort --unique # generate coverage report grcov ${{ github.workspace }}/build/ --output-type lcov -b target/debug/ --output-path "${COVERAGE_REPORT_FILE}" --branch --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" From 77155b7dbefd0aab8c1e8b928cce41de005c6732 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 16 Nov 2024 11:21:13 +0100 Subject: [PATCH 14/19] more debug info --- .github/workflows/CICD.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 6e790d384db..3850206c9ac 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -1013,7 +1013,10 @@ jobs: CARGO_UTILITY_LIST_OPTIONS="$(for u in ${UTILITY_LIST}; do echo -n "-puu_${u} "; done;)" outputs CARGO_UTILITY_LIST_OPTIONS - name: Test - run: cargo nextest run --profile ci --hide-progress-bar ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} -p uucore -p coreutils + run: | + df -h + cargo nextest run --profile ci --hide-progress-bar ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} -p uucore -p coreutils + df -h env: RUSTC_WRAPPER: "" RUSTFLAGS: "-Cinstrument-coverage -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort" From e302a3a3a607262d9f76080819ba5645c68f4c0e Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 16 Nov 2024 11:25:33 +0100 Subject: [PATCH 15/19] more debug info --- .github/workflows/CICD.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 3850206c9ac..9190753cf17 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -1011,6 +1011,7 @@ jobs: # * determine sub-crate utility list UTILITY_LIST="$(./util/show-utils.sh ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }})" CARGO_UTILITY_LIST_OPTIONS="$(for u in ${UTILITY_LIST}; do echo -n "-puu_${u} "; done;)" + df -h outputs CARGO_UTILITY_LIST_OPTIONS - name: Test run: | From d6c2ccdcf5d1e00b7fe6d5082ffca91595e5180d Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 16 Nov 2024 11:39:51 +0100 Subject: [PATCH 16/19] more debug info --- .github/workflows/CICD.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 9190753cf17..11ebe8a19ff 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -1043,7 +1043,7 @@ jobs: COVERAGE_REPORT_FILE="${COVERAGE_REPORT_DIR}/lcov.info" mkdir -p "${COVERAGE_REPORT_DIR}" # display coverage files (for debug) - ls -al ${{ github.workspace }}/build/|head -5 + ls -al ${{ github.workspace }}/build/ ls -al target/ ls -al target/debug grcov ${{ github.workspace }}/build/ --output-type files -b target/debug/ --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" | sort --unique From c6f538a99c46c1dd7ea1400ee6c617b30331a99b Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 16 Nov 2024 11:50:05 +0100 Subject: [PATCH 17/19] more debug info --- .github/workflows/CICD.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 11ebe8a19ff..1cc20099dd9 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -1043,7 +1043,8 @@ jobs: COVERAGE_REPORT_FILE="${COVERAGE_REPORT_DIR}/lcov.info" mkdir -p "${COVERAGE_REPORT_DIR}" # display coverage files (for debug) - ls -al ${{ github.workspace }}/build/ + du -h ${{ github.workspace }}/build/ + grcov --version ls -al target/ ls -al target/debug grcov ${{ github.workspace }}/build/ --output-type files -b target/debug/ --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" | sort --unique From f35dbfdb5f227cac408780271a28cf5017fb071d Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 16 Nov 2024 12:16:04 +0100 Subject: [PATCH 18/19] remove the grcov display file list step --- .github/workflows/CICD.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 1cc20099dd9..a65062b22de 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -1047,7 +1047,6 @@ jobs: grcov --version ls -al target/ ls -al target/debug - grcov ${{ github.workspace }}/build/ --output-type files -b target/debug/ --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" | sort --unique # generate coverage report grcov ${{ github.workspace }}/build/ --output-type lcov -b target/debug/ --output-path "${COVERAGE_REPORT_FILE}" --branch --ignore build.rs --ignore "vendor/*" --ignore "/*" --ignore "[a-zA-Z]:/*" --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?!|#\[derive\()" echo "report=${COVERAGE_REPORT_FILE}" >> $GITHUB_OUTPUT From ee4a6bf7acac31ed81c4bedad7057febca9d2dfa Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 16 Nov 2024 13:02:34 +0100 Subject: [PATCH 19/19] try a different approach --- .github/workflows/coverage.yml | 56 ++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 00000000000..f221a3b2ca0 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,56 @@ +name: Coverage + +on: + workflow_dispatch: + push: + branches: + - main + pull_request: + +jobs: + codecov: + name: Code coverage (new) + runs-on: ${{ matrix.job.os }} + timeout-minutes: 90 + + strategy: + fail-fast: false + matrix: + job: + - { os: ubuntu-latest , features: unix, toolchain: nightly } + - { os: macos-latest , features: macos, toolchain: nightly } + # FIXME: Re-enable Code Coverage on windows, which currently fails due to "profiler_builtins". See #6686. + # - { os: windows-latest , features: windows, toolchain: nightly-x86_64-pc-windows-gnu } + env: + CARGO_INCREMENTAL: "0" + + steps: + - uses: actions/checkout@v4 + + - name: Install Rust + run: rustup update stable + + - name: Install cargo-llvm-cov + uses: taiki-e/install-action@cargo-llvm-cov + + - name: Install Rust + run: rustup update stable + + - name: llvm-cov show-env + run: cargo llvm-cov show-env --export-prefix + + - name: Build + run: source <(cargo llvm-cov show-env --export-prefix) && cargo build --features=${{ matrix.job.features }} + + - name: Test main crate + run: source <(cargo llvm-cov show-env --export-prefix) && cargo test --features=${{ matrix.job.features }} -p uucore -p coreutils + + - name: Generate code coverage + run: source <(cargo llvm-cov show-env --export-prefix) && cargo llvm-cov report --lcov --output-path lcov.info + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: lcov.info + fail_ci_if_error: true