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

xd009642 / tarpaulin / #558

07 Oct 2024 07:19AM UTC coverage: 75.384%. Remained the same
#558

push

web-flow
Bump object from 0.36.4 to 0.36.5 (#1629)

Bumps [object](https://github.com/gimli-rs/object) from 0.36.4 to 0.36.5.
- [Changelog](https://github.com/gimli-rs/object/blob/master/CHANGELOG.md)
- [Commits](https://github.com/gimli-rs/object/compare/0.36.4...0.36.5)

---
updated-dependencies:
- dependency-name: object
  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>

2600 of 3449 relevant lines covered (75.38%)

137016.1 hits per line

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

33.33
/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 std::process::Command;
15
use tracing::{info, warn};
16

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

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

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

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

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

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

65
fn is_aslr_enabled() -> bool {
×
66
    // Create a Command instance with the 'cat' command and the path to the file as arguments
67
    let output = Command::new("cat")
×
68
        .arg("/proc/sys/kernel/random/boot_random")
69
        .output()
70
        .unwrap();
71

72
    // Convert the output to a String and store it in a variable
73
    let output_str = String::from_utf8(output.stdout).unwrap();
×
74

75
    // Check if the output string is not '0' (case-insensitive) and return the result
76
    output_str.trim().to_lowercase() != "0"
×
77
}
78

79
pub fn limit_affinity() -> nix::Result<()> {
174✔
80
    let this = Pid::this();
174✔
81
    // Get current affinity to be able to limit the cores to one of
82
    // those already in the affinity mask.
83
    let affinity = sched_getaffinity(this)?;
348✔
84
    let mut selected_cpu = 0;
85
    for i in 0..CpuSet::count() {
174✔
86
        if affinity.is_set(i)? {
174✔
87
            selected_cpu = i;
174✔
88
            break;
174✔
89
        }
90
    }
91
    let mut cpu_set = CpuSet::new();
174✔
92
    cpu_set.set(selected_cpu)?;
174✔
93
    sched_setaffinity(this, &cpu_set)
174✔
94
}
95

96
pub fn execute(
×
97
    test: &Path,
98
    argv: &[String],
99
    envar: &[(String, String)],
100
) -> Result<TestHandle, RunError> {
101
    let program = CString::new(test.display().to_string()).unwrap_or_default();
×
102
    if is_aslr_enabled() {
×
103
        disable_aslr().map_err(|e| RunError::TestRuntime(format!("ASLR disable failed: {e}")))?;
×
104
    }
105
    request_trace().map_err(|e| RunError::Trace(e.to_string()))?;
×
106

107
    let envar = envar
×
108
        .iter()
109
        .map(|(k, v)| CString::new(format!("{k}={v}").as_str()).unwrap_or_default())
×
110
        .collect::<Vec<CString>>();
111

112
    let argv = argv
×
113
        .iter()
114
        .map(|x| CString::new(x.as_str()).unwrap_or_default())
×
115
        .collect::<Vec<CString>>();
116

117
    let arg_ref = argv.iter().map(AsRef::as_ref).collect::<Vec<&CStr>>();
×
118
    let env_ref = envar.iter().map(AsRef::as_ref).collect::<Vec<&CStr>>();
×
119
    execve(&program, &arg_ref, &env_ref).map_err(|_| RunError::Internal)?;
×
120

121
    unreachable!();
122
}
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