Skip to content

Apache DataFusion SQL Query Engine

ci: reintroduce code coverage reporting with cargo-llvm-cov (#23336)

Burak Şen80bc64f3d225
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index 94a583f09e..d69f6a69c1 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -306,16 +306,22 @@ jobs:
uses: ./.github/actions/setup-builder
with:
rust-version: stable
+ - name: Install llvm-tools-preview
+ run: rustup component add llvm-tools-preview
+ - name: Install cargo-llvm-cov
+ uses: taiki-e/install-action@9bcaee1dcae34154180f412e2fa69355a7cda9f6 # v2.82.6
+ with:
+ tool: cargo-llvm-cov
- name: Rust Dependency Cache
uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
with:
- save-if: ${{ github.ref_name == 'main' }}
- shared-key: "amd-ci"
+ save-if: ${{ github.ref_name == 'main' }}
+ shared-key: "amd-ci"
- name: Run tests (excluding doctests and datafusion-cli)
env:
RUST_BACKTRACE: 1
run: |
- cargo test \
+ cargo llvm-cov \
--profile ci \
--exclude datafusion-examples \
--exclude ffi_example_table_provider \
@@ -324,7 +330,9 @@ jobs:
--lib \
--tests \
--bins \
- --features serde,avro,json,backtrace,integration-tests,parquet_encryption,substrait
+ --features serde,avro,json,backtrace,integration-tests,parquet_encryption,substrait \
+ --codecov \
+ --output-path target/codecov.json
- parallel:
- name: Verify Working Directory Clean
run: git diff --exit-code
@@ -337,6 +345,12 @@ jobs:
echo "$STATUS"
exit 1
fi
+ - name: Upload coverage to codecov.io
+ uses: codecov/codecov-action@0fb7174895f61a3b6b78fc075e0cd60383518dac # v5
+ with:
+ files: target/codecov.json
+ fail_ci_if_error: false
+ token: ${{ secrets.CODECOV_TOKEN }}
# datafusion-cli tests
linux-test-datafusion-cli:
@@ -639,50 +653,6 @@ jobs:
- name: Check workflow tool installs
run: ci/scripts/check_no_cargo_install_in_workflows.sh
- # Coverage job disabled due to
- # https://github.com/apache/datafusion/issues/3678
-
- # coverage:
- # name: coverage
- # runs-on: ubuntu-latest
- # steps:
- # - uses: actions/checkout@v4
- # with:
- # submodules: true
- # - name: Install protobuf compiler
- # shell: bash
- # run: |
- # mkdir -p $HOME/d/protoc
- # cd $HOME/d/protoc
- # export PROTO_ZIP="protoc-21.4-linux-x86_64.zip"
- # curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v21.4/$PROTO_ZIP
- # unzip $PROTO_ZIP
- # export PATH=$PATH:$HOME/d/protoc/bin
- # protoc --version
- # - name: Setup Rust toolchain
- # run: |
- # rustup toolchain install stable
- # rustup default stable
- # rustup component add rustfmt clippy
- # - name: Cache Cargo
- # uses: actions/cache@v4
- # with:
- # path: /home/runner/.cargo
- # # this key is not equal because the user is different than on a container (runner vs github)
- # key: cargo-coverage-cache3-
- # - name: Install cargo-tarpaulin
- # uses: taiki-e/install-action@43aecc8d72668fbcfe75c31400bc4f890f1c5853 # v2.83.2
- # with:
- # - name: Run coverage
- # run: |
- # export PATH=$PATH:$HOME/d/protoc/bin
- # rustup toolchain install stable
- # rustup default stable
- # cargo tarpaulin --all --out Xml
- # - name: Report coverage
- # continue-on-error: true
- # run: bash <(curl -s https://codecov.io/bash)
clippy:
name: clippy
diff --git a/Cargo.toml b/Cargo.toml
index 72676c8263..fef23162ff 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -226,8 +226,8 @@ assigning_clones = "warn"
[workspace.lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(datafusion_coop, values("tokio", "tokio_fallback", "per_stream"))',
- "cfg(tarpaulin)",
- "cfg(tarpaulin_include)",
+ "cfg(coverage)",
+ "cfg(coverage_nightly)",
] }
unused_qualifications = "deny"
diff --git a/datafusion/core/tests/fuzz_cases/sort_fuzz.rs b/datafusion/core/tests/fuzz_cases/sort_fuzz.rs
index 0d8a066d43..675854ddb5 100644
--- a/datafusion/core/tests/fuzz_cases/sort_fuzz.rs
+++ b/datafusion/core/tests/fuzz_cases/sort_fuzz.rs
@@ -40,7 +40,6 @@ use test_utils::{batches_to_vec, partitions_to_sorted_vec};
const KB: usize = 1 << 10;
#[tokio::test]
-#[cfg_attr(tarpaulin, ignore)]
async fn test_sort_10k_mem() {
for (batch_size, should_spill) in [(5, false), (20000, true), (500000, true)] {
let (input, collected) = SortTest::new()
@@ -58,7 +57,6 @@ async fn test_sort_10k_mem() {
}
#[tokio::test]
-#[cfg_attr(tarpaulin, ignore)]
async fn test_sort_100k_mem() {
for (batch_size, should_spill) in
[(5, false), (10000, false), (20000, true), (1000000, true)]
@@ -78,7 +76,6 @@ async fn test_sort_100k_mem() {
}
#[tokio::test]
-#[cfg_attr(tarpaulin, ignore)]
async fn test_sort_strings_100k_mem() {
for (batch_size, should_spill) in
[(5, false), (1000, false), (10000, true), (20000, true)]
@@ -116,7 +113,6 @@ async fn test_sort_strings_100k_mem() {
}
#[tokio::test]
-#[cfg_attr(tarpaulin, ignore)]
async fn test_sort_multi_columns_100k_mem() {
for (batch_size, should_spill) in
[(5, false), (1000, false), (10000, true), (20000, true)]
diff --git a/datafusion/core/tests/sql/explain_analyze.rs b/datafusion/core/tests/sql/explain_analyze.rs
index 2293098bb8..4c8b8f9c01 100644
--- a/datafusion/core/tests/sql/explain_analyze.rs
+++ b/datafusion/core/tests/sql/explain_analyze.rs
@@ -827,7 +827,7 @@ async fn test_physical_plan_display_indent_multi_children() {
}
#[tokio::test]
-#[cfg_attr(tarpaulin, ignore)]
+#[cfg_attr(coverage, ignore)]
async fn csv_explain_analyze() {
// This test uses the execute function to run an actual plan under EXPLAIN ANALYZE
let ctx = SessionContext::new();
@@ -849,7 +849,7 @@ async fn csv_explain_analyze() {
}
#[tokio::test]
-#[cfg_attr(tarpaulin, ignore)]
+#[cfg_attr(coverage, ignore)]
async fn csv_explain_analyze_order_by() {
let ctx = SessionContext::new();
register_aggregate_csv_by_sql(&ctx).await;
@@ -866,7 +866,7 @@ async fn csv_explain_analyze_order_by() {
}
#[tokio::test]
-#[cfg_attr(tarpaulin, ignore)]
+#[cfg_attr(coverage, ignore)]
async fn parquet_explain_analyze() {
let ctx = SessionContext::new();
register_alltypes_parquet(&ctx).await;
@@ -913,7 +913,7 @@ async fn parquet_explain_analyze() {
// (e.g. nested/recursive expansion causing full schema to be scanned).
// Keeping this test ensures we don't regress that behavior.
#[tokio::test]
-#[cfg_attr(tarpaulin, ignore)]
+#[cfg_attr(coverage, ignore)]
async fn parquet_recursive_projection_pushdown() -> Result<()> {
use parquet::arrow::arrow_writer::ArrowWriter;
use parquet::file::properties::WriterProperties;
@@ -1030,7 +1030,7 @@ async fn parquet_recursive_projection_pushdown() -> Result<()> {
}
#[tokio::test]
-#[cfg_attr(tarpaulin, ignore)]
+#[cfg_attr(coverage, ignore)]
async fn parquet_explain_analyze_verbose() {
let ctx = SessionContext::new();
register_alltypes_parquet(&ctx).await;
@@ -1047,7 +1047,7 @@ async fn parquet_explain_analyze_verbose() {
}
#[tokio::test]
-#[cfg_attr(tarpaulin, ignore)]
+#[cfg_attr(coverage, ignore)]
async fn csv_explain_analyze_verbose() {
// This test uses the execute function to run an actual plan under EXPLAIN VERBOSE ANALYZE
let ctx = SessionContext::new();
diff --git a/datafusion/ffi/Cargo.toml b/datafusion/ffi/Cargo.toml
index e50530c868..affcff3dbd 100644
--- a/datafusion/ffi/Cargo.toml
+++ b/datafusion/ffi/Cargo.toml
@@ -91,4 +91,3 @@ integration-tests = [
"datafusion-functions-window",
]
parquet = ["datafusion-proto/parquet"]
-tarpaulin_include = [] # Exists only to prevent warnings on stable and still have accurate coverage
diff --git a/datafusion/ffi/src/arrow_wrappers.rs b/datafusion/ffi/src/arrow_wrappers.rs
index 1c921b0f83..62fb36f836 100644
--- a/datafusion/ffi/src/arrow_wrappers.rs
+++ b/datafusion/ffi/src/arrow_wrappers.rs
@@ -49,7 +49,6 @@ impl From<SchemaRef> for WrappedSchema {
/// Since going through the FFI always has the potential to fail, we need to catch these errors,
/// give the user a warning, and return some kind of result. In this case we default to an
/// empty schema.
-#[cfg(not(tarpaulin_include))]
fn catch_df_schema_error(e: &ArrowError) -> Schema {
error!(
"Unable to convert from FFI_ArrowSchema to DataFusion Schema in FFI_PlanProperties. {e}"
diff --git a/datafusion/ffi/src/tests/utils.rs b/datafusion/ffi/src/tests/utils.rs
index e1374c7862..b6b50cbce8 100644
--- a/datafusion/ffi/src/tests/utils.rs
+++ b/datafusion/ffi/src/tests/utils.rs
@@ -21,29 +21,6 @@ use datafusion_common::{DataFusionError, Result};
use crate::tests::ForeignLibraryModule;
-/// Compute the path to the built cdylib. Checks debug, release, and ci profile dirs.
-fn compute_library_dir(target_path: &Path) -> PathBuf {
- let debug_dir = target_path.join("debug");
- let release_dir = target_path.join("release");
- let ci_dir = target_path.join("ci");
-
- let all_dirs = vec![debug_dir.clone(), release_dir, ci_dir];
-
- all_dirs
- .into_iter()
- .filter(|dir| dir.join("deps").exists())
- .filter_map(|dir| {
- dir.join("deps")
- .metadata()
- .and_then(|m| m.modified())
- .ok()
- .map(|date| (dir, date))
- })
- .max_by_key(|(_, date)| *date)
- .map(|(dir, _)| dir)
- .unwrap_or(debug_dir)
-}
-
/// Find the cdylib file for datafusion_ffi in the given directory.
fn find_cdylib(deps_dir: &Path) -> Result<PathBuf> {
let lib_prefix = if cfg!(target_os = "windows") {
@@ -71,19 +48,24 @@ fn find_cdylib(deps_dir: &Path) -> Result<PathBuf> {
))
}
+/// Locate the built `datafusion_ffi` cdylib.
+///
+/// The cdylib sits next to the running test binary, so this follows Cargo's
+/// actual output directory and is robust to the active profile and a custom
+/// `--target-dir` (e.g. `cargo llvm-cov`).
+fn find_library() -> Result<PathBuf> {
+ let exe =
+ std::env::current_exe().map_err(|e| DataFusionError::External(Box::new(e)))?;
+ let deps_dir = exe.parent().ok_or_else(|| {
+ DataFusionError::External("Failed to find test binary directory".into())
+ })?;
+ find_cdylib(deps_dir)
+}
+
pub fn get_module() -> Result<ForeignLibraryModule> {
let expected_version = crate::version();
- let crate_root = Path::new(env!("CARGO_MANIFEST_DIR"));
- let target_dir = crate_root
- .parent()
- .expect("Failed to find crate parent")
- .parent()
- .expect("Failed to find workspace root")
- .join("target");
-
- let library_dir = compute_library_dir(target_dir.as_path());
- let lib_path = find_cdylib(&library_dir.join("deps"))?;
+ let lib_path = find_library()?;
// Load the library using libloading
let lib = unsafe {