File tree 2 files changed +29
-2
lines changed
test-framework/sudo-test/src
2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ use std::{
3
3
env,
4
4
fs:: { self , File } ,
5
5
io:: { Seek , SeekFrom , Write } ,
6
- path:: PathBuf ,
6
+ path:: { Path , PathBuf } ,
7
7
process:: { self , Command as StdCommand , Stdio } ,
8
8
} ;
9
9
@@ -92,10 +92,35 @@ impl Container {
92
92
93
93
Ok ( ( ) )
94
94
}
95
+
96
+ fn copy_profraw_data ( & mut self , profraw_dir : impl AsRef < Path > ) -> Result < ( ) > {
97
+ let profraw_dir = profraw_dir. as_ref ( ) ;
98
+ fs:: create_dir_all ( profraw_dir) ?;
99
+
100
+ self . exec ( Command :: new ( "sh" ) . args ( [
101
+ "-c" ,
102
+ "mkdir /tmp/profraw; find / -name '*.profraw' -exec cp {} /tmp/profraw/ \\ ; || true" ,
103
+ ] ) ) ?
104
+ . assert_success ( ) ?;
105
+
106
+ let src_path = format ! ( "{}:/tmp/profraw" , self . id) ;
107
+ let dst_path = profraw_dir. join ( & self . id ) . display ( ) . to_string ( ) ;
108
+ run (
109
+ StdCommand :: new ( "docker" ) . args ( [ "cp" , & src_path, & dst_path] ) ,
110
+ None ,
111
+ ) ?
112
+ . assert_success ( ) ?;
113
+
114
+ Ok ( ( ) )
115
+ }
95
116
}
96
117
97
118
impl Drop for Container {
98
119
fn drop ( & mut self ) {
120
+ if let Ok ( dir) = env:: var ( "SUDO_TEST_PROFRAW_DIR" ) {
121
+ let _ = self . copy_profraw_data ( dir) ;
122
+ }
123
+
99
124
// running this to completion would block the current thread for several seconds so just
100
125
// fire and forget
101
126
let _ = StdCommand :: new ( "docker" )
Original file line number Diff line number Diff line change @@ -5,7 +5,9 @@ RUN apt-get update && \
5
5
RUN cargo search sudo
6
6
WORKDIR /usr/src/sudo
7
7
COPY . .
8
- RUN --mount=type=cache,target=/usr/src/sudo/target cargo build --locked -p sudo && mkdir -p build && cp target/debug/sudo build/sudo
8
+ RUN --mount=type=cache,target=/usr/src/sudo/target RUSTFLAGS="-C instrument-coverage" cargo build --locked -p sudo && mkdir -p build && cp target/debug/sudo build/sudo
9
+ # discard code coverage data created during `cargo build`
10
+ RUN find / -name '*.profraw' -exec rm {} \;
9
11
# set setuid on install
10
12
RUN install --mode 4755 build/sudo /usr/bin/sudo
11
13
# remove build dependencies
You can’t perform that action at this time.
0 commit comments