From c52e9ae5dc63d73e8185e19c9f8c85fab08da32a Mon Sep 17 00:00:00 2001 From: Hayley Call Date: Mon, 10 Jan 2022 15:15:42 -0800 Subject: [PATCH 1/5] Integrate cobertura format and output as file in coverage container --- src/agent/onefuzz-agent/src/tasks/coverage/generic.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs b/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs index 7f546e4c1e..c7efe54f7f 100644 --- a/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs +++ b/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs @@ -13,6 +13,7 @@ use coverage::block::CommandBlockCov; use coverage::cache::ModuleCache; use coverage::code::{CmdFilter, CmdFilterDef}; use coverage::debuginfo::DebugInfo; +use coverage::cobertura::cobertura; use onefuzz::expand::{Expand, PlaceHolder}; use onefuzz::syncdir::SyncedDir; use onefuzz_telemetry::{warn, Event::coverage_data, EventData}; @@ -30,6 +31,7 @@ use crate::tasks::heartbeat::{HeartbeatSender, TaskHeartbeatClient}; const MAX_COVERAGE_RECORDING_ATTEMPTS: usize = 2; const COVERAGE_FILE: &str = "coverage.json"; const SOURCE_COVERAGE_FILE: &str = "source-coverage.json"; +const COBERTURA_COVERAGE_FILE: &str = "cobertura-coverage.json"; const MODULE_CACHE_FILE: &str = "module-cache.json"; const DEFAULT_TARGET_TIMEOUT: Duration = Duration::from_secs(5); @@ -362,6 +364,13 @@ impl<'a> TaskContext<'a> { .await .with_context(|| format!("writing source coverage to {}", path.display()))?; + let path = self.config.coverage.local_path.join(COBERTURA_COVERAGE_FILE); + let cobertura_source_coverage = cobertura(src_coverage)?; + let text = serde_json::to_string(&cobertura_source_coverage).context("serializing cobertura source coverage")?; + fs::write(&path, &text) + .await + .with_context(|| format!("writing cobertura source coverage to {}", path.display()))?; + self.config.coverage.sync_push().await?; Ok(()) From cf4f9a5a4a1efde8efd73cefe42023f82fd2673c Mon Sep 17 00:00:00 2001 From: Hayley Call Date: Mon, 10 Jan 2022 15:26:43 -0800 Subject: [PATCH 2/5] cobertura output file is txt, not json --- src/agent/onefuzz-agent/src/tasks/coverage/generic.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs b/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs index c7efe54f7f..8a514f39a6 100644 --- a/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs +++ b/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs @@ -31,7 +31,7 @@ use crate::tasks::heartbeat::{HeartbeatSender, TaskHeartbeatClient}; const MAX_COVERAGE_RECORDING_ATTEMPTS: usize = 2; const COVERAGE_FILE: &str = "coverage.json"; const SOURCE_COVERAGE_FILE: &str = "source-coverage.json"; -const COBERTURA_COVERAGE_FILE: &str = "cobertura-coverage.json"; +const COBERTURA_COVERAGE_FILE: &str = "cobertura-coverage.txt"; const MODULE_CACHE_FILE: &str = "module-cache.json"; const DEFAULT_TARGET_TIMEOUT: Duration = Duration::from_secs(5); @@ -366,7 +366,7 @@ impl<'a> TaskContext<'a> { let path = self.config.coverage.local_path.join(COBERTURA_COVERAGE_FILE); let cobertura_source_coverage = cobertura(src_coverage)?; - let text = serde_json::to_string(&cobertura_source_coverage).context("serializing cobertura source coverage")?; + let text = &cobertura_source_coverage; fs::write(&path, &text) .await .with_context(|| format!("writing cobertura source coverage to {}", path.display()))?; From 822b01793ef097107b5480b9687c16d79666b281 Mon Sep 17 00:00:00 2001 From: Hayley Call Date: Mon, 10 Jan 2022 15:31:55 -0800 Subject: [PATCH 3/5] Format --- .../onefuzz-agent/src/tasks/coverage/generic.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs b/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs index 8a514f39a6..ce6848e6c9 100644 --- a/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs +++ b/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs @@ -11,9 +11,9 @@ use anyhow::{Context, Result}; use async_trait::async_trait; use coverage::block::CommandBlockCov; use coverage::cache::ModuleCache; +use coverage::cobertura::cobertura; use coverage::code::{CmdFilter, CmdFilterDef}; use coverage::debuginfo::DebugInfo; -use coverage::cobertura::cobertura; use onefuzz::expand::{Expand, PlaceHolder}; use onefuzz::syncdir::SyncedDir; use onefuzz_telemetry::{warn, Event::coverage_data, EventData}; @@ -364,12 +364,16 @@ impl<'a> TaskContext<'a> { .await .with_context(|| format!("writing source coverage to {}", path.display()))?; - let path = self.config.coverage.local_path.join(COBERTURA_COVERAGE_FILE); + let path = self + .config + .coverage + .local_path + .join(COBERTURA_COVERAGE_FILE); let cobertura_source_coverage = cobertura(src_coverage)?; let text = &cobertura_source_coverage; fs::write(&path, &text) - .await - .with_context(|| format!("writing cobertura source coverage to {}", path.display()))?; + .await + .with_context(|| format!("writing cobertura source coverage to {}", path.display()))?; self.config.coverage.sync_push().await?; From 3a0173f43cb7ee8c2c0c7e764674d2651cd256a9 Mon Sep 17 00:00:00 2001 From: Hayley Call Date: Mon, 10 Jan 2022 15:34:47 -0800 Subject: [PATCH 4/5] xml file not txt --- src/agent/onefuzz-agent/src/tasks/coverage/generic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs b/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs index ce6848e6c9..ff2271d2f7 100644 --- a/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs +++ b/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs @@ -31,7 +31,7 @@ use crate::tasks::heartbeat::{HeartbeatSender, TaskHeartbeatClient}; const MAX_COVERAGE_RECORDING_ATTEMPTS: usize = 2; const COVERAGE_FILE: &str = "coverage.json"; const SOURCE_COVERAGE_FILE: &str = "source-coverage.json"; -const COBERTURA_COVERAGE_FILE: &str = "cobertura-coverage.txt"; +const COBERTURA_COVERAGE_FILE: &str = "cobertura-coverage.xml"; const MODULE_CACHE_FILE: &str = "module-cache.json"; const DEFAULT_TARGET_TIMEOUT: Duration = Duration::from_secs(5); From cfbae8c99980c48e913a06e132d56a9120e2ed43 Mon Sep 17 00:00:00 2001 From: Hayley Call Date: Mon, 10 Jan 2022 16:09:23 -0800 Subject: [PATCH 5/5] Improved syntax --- src/agent/onefuzz-agent/src/tasks/coverage/generic.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs b/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs index ff2271d2f7..e6690c7975 100644 --- a/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs +++ b/src/agent/onefuzz-agent/src/tasks/coverage/generic.rs @@ -370,8 +370,7 @@ impl<'a> TaskContext<'a> { .local_path .join(COBERTURA_COVERAGE_FILE); let cobertura_source_coverage = cobertura(src_coverage)?; - let text = &cobertura_source_coverage; - fs::write(&path, &text) + fs::write(&path, &cobertura_source_coverage) .await .with_context(|| format!("writing cobertura source coverage to {}", path.display()))?;