• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

xd009642 / tarpaulin / #241

pending completion
#241

push

web-flow
Bump proc-macro2 from 1.0.51 to 1.0.52 (#1235)

Bumps [proc-macro2](https://github.com/dtolnay/proc-macro2) from 1.0.51 to 1.0.52.
- [Release notes](https://github.com/dtolnay/proc-macro2/releases)
- [Commits](https://github.com/dtolnay/proc-macro2/compare/1.0.51...1.0.52)

---
updated-dependencies:
- dependency-name: proc-macro2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

3044 of 3870 relevant lines covered (78.66%)

160876.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

38.64
/src/process_handling/linux.rs
1
use crate::config::types::Mode;
2
use crate::errors::*;
3
use crate::process_handling::execute_test;
4
use crate::ptrace_control::*;
5
use crate::Config;
6
use crate::TestBinary;
7
use crate::TestHandle;
8
use lazy_static::lazy_static;
9
use nix::sched::*;
10
use nix::sys::personality;
11
use nix::unistd::*;
12
use std::ffi::{CStr, CString};
13
use std::path::Path;
14
use tracing::{info, warn};
15

16
lazy_static! {
17
    static ref NUM_CPUS: usize = num_cpus::get();
18
}
19

20
/// Returns the coverage statistics for a test executable in the given workspace
21
pub fn get_test_coverage(
22
    test: &TestBinary,
23
    config: &Config,
24
    ignored: bool,
25
) -> Result<Option<TestHandle>, RunError> {
26
    if !test.path().exists() {
27
        warn!("Test at {} doesn't exist", test.path().display());
28
        return Ok(None);
29
    }
30

31
    // Solves CI issue when fixing #953 and #966 in PR #962
32
    let threads = if config.follow_exec { 1 } else { *NUM_CPUS };
33

34
    if let Err(e) = limit_affinity() {
35
        warn!("Failed to set processor affinity {}", e);
36
    }
37

38
    unsafe {
39
        match fork() {
40
            Ok(ForkResult::Parent { child }) => Ok(Some(TestHandle::Id(child))),
41
            Ok(ForkResult::Child) => {
42
                let bin_type = match config.command {
43
                    Mode::Test => "test",
44
                    Mode::Build => "binary",
45
                };
46
                info!("Launching {}", bin_type);
47
                execute_test(test, &[], ignored, config, Some(threads))?;
48
                Ok(None)
49
            }
50
            Err(err) => Err(RunError::TestCoverage(format!(
51
                "Failed to run test {}, Error: {}",
52
                test.path().display(),
53
                err
54
            ))),
55
        }
56
    }
57
}
58

59
fn disable_aslr() -> nix::Result<()> {
60
    let this = personality::get()?;
61
    personality::set(this | personality::Persona::ADDR_NO_RANDOMIZE).map(|_| ())
62
}
63

64
pub fn limit_affinity() -> nix::Result<()> {
65
    let this = Pid::this();
66
    // Get current affinity to be able to limit the cores to one of
67
    // those already in the affinity mask.
68
    let affinity = sched_getaffinity(this)?;
69
    let mut selected_cpu = 0;
70
    for i in 0..CpuSet::count() {
71
        if affinity.is_set(i)? {
72
            selected_cpu = i;
73
            break;
74
        }
75
    }
76
    let mut cpu_set = CpuSet::new();
77
    cpu_set.set(selected_cpu)?;
78
    sched_setaffinity(this, &cpu_set)
79
}
80

81
pub fn execute(
82
    test: &Path,
83
    argv: &[String],
84
    envar: &[(String, String)],
85
) -> Result<TestHandle, RunError> {
86
    let program = CString::new(test.display().to_string()).unwrap_or_default();
87
    disable_aslr().map_err(|e| RunError::TestRuntime(format!("ASLR disable failed: {e}")))?;
88

89
    request_trace().map_err(|e| RunError::Trace(e.to_string()))?;
90

91
    let envar = envar
92
        .iter()
93
        .map(|(k, v)| CString::new(format!("{k}={v}").as_str()).unwrap_or_default())
94
        .collect::<Vec<CString>>();
95

96
    let argv = argv
97
        .iter()
98
        .map(|x| CString::new(x.as_str()).unwrap_or_default())
99
        .collect::<Vec<CString>>();
100

101
    let arg_ref = argv.iter().map(AsRef::as_ref).collect::<Vec<&CStr>>();
102
    let env_ref = envar.iter().map(AsRef::as_ref).collect::<Vec<&CStr>>();
103
    execve(&program, &arg_ref, &env_ref).map_err(|_| RunError::Internal)?;
104

105
    unreachable!();
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc