Skip to content

Commit da03d5b

Browse files
authored
Merge pull request jfrimmel#133 from jfrimmel/valgrind-newer-xml-versions
Add support for newer Valgrind XML output versions
2 parents 14fb994 + 420ba56 commit da03d5b

File tree

4 files changed

+123
-6
lines changed

4 files changed

+123
-6
lines changed

src/valgrind/xml/mod.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,28 @@ pub struct Output {
2828

2929
/// The version of the XML format.
3030
///
31-
/// Although there are also versions 1-3, there is only a variant for version 4,
32-
/// so that all older formats will fail. The other `struct`s in this file assume
33-
/// the newest protocol version.
31+
/// Although there are also versions 1-3, there is only a variant for version 4
32+
/// and newer, so that all older formats will fail. The other `struct`s in this
33+
/// file assume the newer protocol versions, which are largely compatible.
3434
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Deserialize)]
3535
enum ProtocolVersion {
36+
// older formats are not supported and won't be in the future
37+
/// Protocol [version 4].
38+
///
39+
/// [version 4]: https://sourceware.org/git/?p=valgrind.git;a=blob_plain;f=docs/internals/xml-output-protocol4.txt;hb=d772e25995c3400eecf2b6070e0bf3411447c3d1
3640
#[serde(rename = "4")]
3741
Version4,
38-
// other formats are not supported
42+
/// Protocol [version 5].
43+
///
44+
/// [version 5]: https://sourceware.org/git/?p=valgrind.git;a=blob_plain;f=docs/internals/xml-output-protocol5.txt;hb=48d64d0e6bb72220bb2557be4f427a57038dfbc6
45+
#[serde(rename = "5")]
46+
Version5,
47+
/// Protocol [version 6].
48+
///
49+
/// [version 6]: https://sourceware.org/git/?p=valgrind.git;a=blob_plain;f=docs/internals/xml-output-protocol6.txt;hb=7786b075abef51ca3d84b9717915f04b32950b32
50+
#[serde(rename = "6")]
51+
Version6,
52+
// newer versions are not yet supported! Feel free to add one via a PR.
3953
}
4054

4155
/// The check tool used by valgrind.

src/valgrind/xml/tests.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ use std::{fs, io::BufReader};
44
use serde_xml_rs::{from_reader, from_str};
55

66
#[test]
7-
fn sample_output() {
7+
fn support_for_xml_version4() {
88
let xml: Output = from_reader(BufReader::new(
9-
fs::File::open("src/valgrind/xml/memory-leaks.xml").expect("Could not open test file"),
9+
fs::File::open("src/valgrind/xml/version4.xml").expect("Could not open test file"),
1010
))
1111
.expect("Could not read test file");
12+
assert_eq!(xml.protocol_version, super::ProtocolVersion::Version4);
1213

1314
let errors = xml.errors.expect("There are errors in the test case");
1415
assert_eq!(errors.len(), 8);
@@ -56,6 +57,17 @@ fn sample_output() {
5657
);
5758
}
5859

60+
#[test]
61+
fn support_for_xml_version6() {
62+
let xml: Output = from_reader(BufReader::new(
63+
fs::File::open("src/valgrind/xml/version6.xml").expect("Could not open test file"),
64+
))
65+
.expect("Could not read test file");
66+
67+
assert_eq!(xml.protocol_version, super::ProtocolVersion::Version6);
68+
assert_eq!(xml.errors, None);
69+
}
70+
5971
#[test]
6072
fn unique_ids_have_to_be_in_hex_with_prefix() {
6173
let result: Error = from_str(

src/valgrind/xml/version6.xml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0"?>
2+
<!-- taken from https://github.com/jfrimmel/cargo-valgrind/issues/132 -->
3+
<valgrindoutput>
4+
5+
<protocolversion>6</protocolversion>
6+
<protocoltool>memcheck</protocoltool>
7+
8+
<preamble>
9+
<line>Memcheck, a memory error detector</line>
10+
<line>Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.</line>
11+
<line>Using Valgrind-3.26.0 and LibVEX; rerun with -h for copyright info</line>
12+
<line>Command: /__w/koji-retriever/koji-retriever/target/debug/deps/koji_retriever-00c939be2d6a6711</line>
13+
</preamble>
14+
15+
<pid>3802</pid>
16+
<ppid>3801</ppid>
17+
<tool>memcheck</tool>
18+
19+
<args>
20+
<vargv>
21+
<exe>/usr/bin/valgrind</exe>
22+
<arg>--suppressions=/tmp/valgrind-suppressionsed90</arg>
23+
<arg>--xml=yes</arg>
24+
<arg>--xml-socket=127.0.0.1:45275</arg>
25+
</vargv>
26+
<argv>
27+
<exe>/__w/koji-retriever/koji-retriever/target/debug/deps/koji_retriever-00c939be2d6a6711</exe>
28+
</argv>
29+
</args>
30+
31+
<status>
32+
<state>RUNNING</state>
33+
<time>00:00:00:00.025 </time>
34+
</status>
35+
36+
<status>
37+
<state>FINISHED</state>
38+
<time>00:00:00:00.656 </time>
39+
</status>
40+
41+
<heap_summary>
42+
<memory_in_use_at_exit>
43+
<bytes>64,146</bytes>
44+
<blocks>2,095</blocks>
45+
</memory_in_use_at_exit>
46+
<total_heap_usage>
47+
<allocs>3,386</allocs>
48+
<frees>1,291</frees>
49+
<bytes_allocated>170,706</bytes_allocated>
50+
</total_heap_usage>
51+
</heap_summary>
52+
53+
<all_heap_blocks_freed>false</all_heap_blocks_freed>
54+
55+
<leak_summary>
56+
<definitely_lost>
57+
<bytes>0</bytes>
58+
<blocks>0</blocks>
59+
</definitely_lost>
60+
<indirectly_lost>
61+
<bytes>0</bytes>
62+
<blocks>0</blocks>
63+
</indirectly_lost>
64+
<possibly_lost>
65+
<bytes>0</bytes>
66+
<blocks>0</blocks>
67+
</possibly_lost>
68+
<still_reachable>
69+
<bytes>64,146</bytes>
70+
<blocks>2,095</blocks>
71+
</still_reachable>
72+
<suppressed>
73+
<bytes>0</bytes>
74+
<blocks>0</blocks>
75+
</suppressed>
76+
</leak_summary>
77+
78+
<errorcounts>
79+
</errorcounts>
80+
81+
<suppcounts>
82+
</suppcounts>
83+
84+
<error_summary>
85+
<errors>0</errors>
86+
<error_contexts>0</error_contexts>
87+
<suppressed>0</suppressed>
88+
<suppressed_contexts>0</suppressed_contexts>
89+
</error_summary>
90+
91+
</valgrindoutput>

0 commit comments

Comments
 (0)