Pick up xml files in the producer (#142)

This commit is contained in:
Gabriel Vîjială 2018-06-29 11:48:58 +01:00 коммит произвёл Marco
Родитель 08306f723e
Коммит a5e886f5d4
5 изменённых файлов: 139 добавлений и 21 удалений

Просмотреть файл

@ -26,10 +26,12 @@ pub struct GCOVResult {
pub branch_number: libc::uint32_t,
}
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Copy, Clone)]
#[allow(non_camel_case_types)]
pub enum ItemFormat {
GCNO,
INFO,
JACOCO_XML,
}
#[derive(Debug)]

Просмотреть файл

@ -210,20 +210,18 @@ pub fn consumer(
}
}
}
ItemFormat::INFO => match work_item.item {
ItemType::Path(info_path) => {
let f = File::open(&info_path).expect("Failed to open lcov file");
let file = BufReader::new(&f);
try_parse!(parse_lcov(file, branch_enabled), work_item.name)
ItemFormat::INFO | ItemFormat::JACOCO_XML => {
if let ItemType::Content(content) = work_item.item {
let buffer = BufReader::new(Cursor::new(content));
if work_item.format == ItemFormat::INFO {
try_parse!(parse_lcov(buffer, branch_enabled), work_item.name)
} else {
try_parse!(parse_jacoco_xml_report(buffer), work_item.name)
}
} else {
panic!("Invalid content type")
}
ItemType::Content(info_content) => {
let buffer = BufReader::new(Cursor::new(info_content));
try_parse!(parse_lcov(buffer, branch_enabled), work_item.name)
}
ItemType::Buffers(_) => {
panic!("Invalid content type");
}
},
}
};
add_results(new_results, result_map, source_dir);

Просмотреть файл

@ -58,6 +58,7 @@ impl Archive {
gcno_stem_archives: &RefCell<HashMap<GCNOStem, &'a Archive>>,
gcda_stem_archives: &RefCell<HashMap<String, Vec<&'a Archive>>>,
infos: &RefCell<HashMap<String, Vec<&'a Archive>>>,
xmls: &RefCell<HashMap<String, Vec<&'a Archive>>>,
linked_files_maps: &RefCell<HashMap<String, &'a Archive>>,
is_llvm: bool,
) {
@ -88,6 +89,10 @@ impl Archive {
let filename = path.to_str().unwrap().to_string();
self.insert_vec(filename, infos);
}
"xml" => {
let filename = path.to_str().unwrap().to_string();
self.insert_vec(filename, xmls);
}
"json" => {
let filename = path.file_name().unwrap();
if filename == "linked-files-map.json" {
@ -120,6 +125,7 @@ impl Archive {
gcno_stem_archives: &RefCell<HashMap<GCNOStem, &'a Archive>>,
gcda_stem_archives: &RefCell<HashMap<String, Vec<&'a Archive>>>,
infos: &RefCell<HashMap<String, Vec<&'a Archive>>>,
xmls: &RefCell<HashMap<String, Vec<&'a Archive>>>,
linked_files_maps: &RefCell<HashMap<String, &'a Archive>>,
is_llvm: bool,
) {
@ -135,6 +141,7 @@ impl Archive {
gcno_stem_archives,
gcda_stem_archives,
infos,
xmls,
linked_files_maps,
is_llvm,
);
@ -152,6 +159,7 @@ impl Archive {
gcno_stem_archives,
gcda_stem_archives,
infos,
xmls,
linked_files_maps,
is_llvm,
);
@ -334,13 +342,17 @@ fn gcno_gcda_producer(
}
}
pub fn info_producer(infos: HashMap<String, Vec<&Archive>>, queue: &WorkQueue) {
for (name, archives) in infos.iter() {
fn file_content_producer(
files: HashMap<String, Vec<&Archive>>,
queue: &WorkQueue,
item_format: ItemFormat,
) {
for (name, archives) in files.iter() {
for archive in archives {
let mut buffer = Vec::new();
archive.read_in_buffer(name, &mut buffer);
queue.push(Some(WorkItem {
format: ItemFormat::INFO,
format: item_format,
item: ItemType::Content(buffer),
name: archive.get_name().to_string(),
}));
@ -398,6 +410,7 @@ pub fn producer(
let gcno_stems_archives: RefCell<HashMap<GCNOStem, &Archive>> = RefCell::new(HashMap::new());
let gcda_stems_archives: RefCell<HashMap<String, Vec<&Archive>>> = RefCell::new(HashMap::new());
let infos: RefCell<HashMap<String, Vec<&Archive>>> = RefCell::new(HashMap::new());
let xmls: RefCell<HashMap<String, Vec<&Archive>>> = RefCell::new(HashMap::new());
let linked_files_maps: RefCell<HashMap<String, &Archive>> = RefCell::new(HashMap::new());
for archive in archives.iter_mut() {
@ -405,16 +418,21 @@ pub fn producer(
&gcno_stems_archives,
&gcda_stems_archives,
&infos,
&xmls,
&linked_files_maps,
is_llvm,
);
}
if gcno_stems_archives.borrow().is_empty() {
assert!(!infos.borrow().is_empty());
}
assert!(
!(gcno_stems_archives.borrow().is_empty()
&& infos.borrow().is_empty()
&& xmls.borrow().is_empty()),
"No input files found"
);
info_producer(infos.into_inner(), queue);
file_content_producer(infos.into_inner(), queue, ItemFormat::INFO);
file_content_producer(xmls.into_inner(), queue, ItemFormat::JACOCO_XML);
gcno_gcda_producer(
tmp_dir,
gcno_stems_archives.into_inner(),
@ -582,6 +600,30 @@ mod tests {
false,
),
(ItemFormat::GCNO, false, "llvm/file_1", true),
(
ItemFormat::JACOCO_XML,
false,
"jacoco/basic-jacoco.xml",
false,
),
(
ItemFormat::JACOCO_XML,
false,
"jacoco/inner-classes.xml",
false,
),
(
ItemFormat::JACOCO_XML,
false,
"jacoco/multiple-top-level-classes.xml",
false,
),
(
ItemFormat::JACOCO_XML,
false,
"jacoco/full-junit4-report-multiple-top-level-classes.xml",
false,
),
];
check_produced(tmp_path, &queue, expected);
@ -916,6 +958,82 @@ mod tests {
check_produced(tmp_path, &queue, expected);
}
// Test extracting jacoco report XML files.
#[test]
fn test_zip_producer_jacoco_xml_files() {
let queue: Arc<WorkQueue> = Arc::new(MsQueue::new());
let tmp_dir = TempDir::new("grcov").expect("Failed to create temporary directory");
let tmp_path = tmp_dir.path().to_owned();
producer(
&tmp_path,
&[
"test/jacoco1.zip".to_string(),
"test/jacoco2.zip".to_string(),
],
&queue,
false,
false,
);
let expected = vec![
(
ItemFormat::JACOCO_XML,
false,
"jacoco/basic-jacoco.xml",
true,
),
(ItemFormat::JACOCO_XML, false, "inner-classes.xml", true),
];
check_produced(tmp_path, &queue, expected);
}
// Test extracting both jacoco xml and info files.
#[test]
fn test_zip_producer_both_info_and_jacoco_xml() {
let queue: Arc<WorkQueue> = Arc::new(MsQueue::new());
let tmp_dir = TempDir::new("grcov").expect("Failed to create temporary directory");
let tmp_path = tmp_dir.path().to_owned();
producer(
&tmp_path,
&[
"test/jacoco1.zip".to_string(),
"test/jacoco2.zip".to_string(),
"test/info1.zip".to_string(),
"test/info2.zip".to_string(),
],
&queue,
false,
false,
);
let expected = vec![
(
ItemFormat::JACOCO_XML,
false,
"jacoco/basic-jacoco.xml",
true,
),
(ItemFormat::JACOCO_XML, false, "inner-classes.xml", true),
(ItemFormat::INFO, false, "1494603967-2977-2_0.info", true),
(ItemFormat::INFO, false, "1494603967-2977-3_0.info", true),
(ItemFormat::INFO, false, "1494603967-2977-4_0.info", true),
(ItemFormat::INFO, false, "1494603968-2977-5_0.info", true),
(ItemFormat::INFO, false, "1494603972-2977-6_0.info", true),
(ItemFormat::INFO, false, "1494603973-2977-7_0.info", true),
(ItemFormat::INFO, false, "1494603967-2977-2_1.info", true),
(ItemFormat::INFO, false, "1494603967-2977-3_1.info", true),
(ItemFormat::INFO, false, "1494603967-2977-4_1.info", true),
(ItemFormat::INFO, false, "1494603968-2977-5_1.info", true),
(ItemFormat::INFO, false, "1494603972-2977-6_1.info", true),
(ItemFormat::INFO, false, "1494603973-2977-7_1.info", true),
];
check_produced(tmp_path, &queue, expected);
}
// Test extracting both info and gcno/gcda files.
#[test]
fn test_zip_producer_both_info_and_gcnogcda_files() {

Двоичные данные
test/jacoco1.zip Normal file

Двоичный файл не отображается.

Двоичные данные
test/jacoco2.zip Normal file

Двоичный файл не отображается.