Skip to content

Commit

Permalink
Make various normalization tests end-to-end tests
Browse files Browse the repository at this point in the history
As motivated in commit d8c994d ("Make BPF symbolization tests
end-to-end tests"), in order to stand a chance of having a reasonable
grasp on what part of the public API surface is being tested, it makes
the most sense to make all end-to-end tests co-located next to each
other (and named consistently etc.).
With this change we take another step into this direction and move all
normalization tests into our end-to-end test suite. To make that happen
we do have to expose a few more types and methods from the crate, but we
make sure to only do so in a hidden manner.

Signed-off-by: Daniel Müller <deso@posteo.net>
  • Loading branch information
d-e-s-o authored and danielocfb committed Nov 5, 2024
1 parent cd786e5 commit b565d87
Show file tree
Hide file tree
Showing 8 changed files with 342 additions and 337 deletions.
12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,18 @@ zstd = ["dep:zstd"]
# Below here are dev-mostly features that should not be needed by
# regular users.

# Expose test-only helpers for convenient use in end-to-end tests from
# crate.
test = []
# Enable code paths requiring a nightly toolchain. This feature is only meant to
# be used for testing and benchmarking purposes, not for the core library, which
# is expected to work on stable.
nightly = []

[[test]]
name = "blazesym"
required-features = ["test"]

[[example]]
name = "addr2ln"

Expand All @@ -111,6 +118,7 @@ required-features = ["demangle", "blazesym-dev/generate-unit-test-files"]
[[bench]]
name = "main"
harness = false
required-features = ["test"]

[profile.release]
debug = true
Expand Down Expand Up @@ -140,10 +148,6 @@ zstd = {version = "0.13.1", default-features = false, optional = true}
# APIs.
addr2line = "=0.24.2"
anyhow = "1.0.71"
# TODO: Enable `zstd` feature once toolchain support for it is more
# widespread (enabled by default in `ld`). Remove conditionals in
# test code alongside.
blazesym = {path = ".", features = ["apk", "breakpad", "gsym", "tracing"]}
blazesym-dev = {path = "dev", features = ["generate-unit-test-files"]}
# TODO: Use 0.5.2 once released.
criterion = {git = "https://github.com/bheisler/criterion.rs.git", rev = "b913e232edd98780961ecfbae836ec77ede49259", default-features = false, features = ["rayon", "cargo_bench_support"]}
Expand Down
5 changes: 4 additions & 1 deletion dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ zip = {version = "2.0.0", optional = true, default-features = false}
zstd = {version = "0.13.1", default-features = false, optional = true}

[dependencies]
blazesym = {version = "=0.2.0-rc.2", path = "../"}
# TODO: Enable `zstd` feature once toolchain support for it is more
# widespread (enabled by default in `ld`). Remove conditionals in
# test code alongside.
blazesym = {path = "../", features = ["apk", "breakpad", "gsym", "tracing", "test"]}
libc = "0.2.137"

[target.'cfg(target_os = "linux")'.dependencies]
Expand Down
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub mod normalize;
mod once;
mod pid;
pub mod symbolize;
#[cfg(test)]
#[cfg(any(test, feature = "test"))]
mod test_helper;
mod util;
#[cfg(feature = "apk")]
Expand Down Expand Up @@ -170,6 +170,16 @@ pub mod __private {
pub use crate::util::bytes_to_path;
pub use crate::util::stat;
pub use crate::util::ReadRaw;

#[cfg(feature = "apk")]
pub mod zip {
pub use crate::zip::Archive;
}

#[cfg(feature = "test")]
pub use crate::test_helper::find_the_answer_fn;
#[cfg(feature = "test")]
pub use crate::test_helper::find_the_answer_fn_in_zip;
}


Expand Down
16 changes: 10 additions & 6 deletions src/mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ use crate::ErrorExt as _;
use crate::Result;


#[doc(hidden)]
#[derive(Debug)]
pub(crate) struct Builder {
pub struct Builder {
exec: bool,
}

Expand All @@ -23,14 +24,15 @@ impl Builder {
}

/// Configure the mapping to be executable.
#[cfg(test)]
pub(crate) fn exec(mut self) -> Self {
#[doc(hidden)]
pub fn exec(mut self) -> Self {
self.exec = true;
self
}

/// Memory map the file at the provided `path`.
pub(crate) fn open<P>(self, path: P) -> Result<Mmap>
#[doc(hidden)]
pub fn open<P>(self, path: P) -> Result<Mmap>
where
P: AsRef<Path>,
{
Expand Down Expand Up @@ -81,7 +83,8 @@ pub struct Mmap {

impl Mmap {
/// Create [`Builder`] for creating a customizable memory mapping.
pub(crate) fn builder() -> Builder {
#[doc(hidden)]
pub fn builder() -> Builder {
Builder::new()
}

Expand All @@ -93,7 +96,8 @@ impl Mmap {
/// Create a new `Mmap` object (sharing the same underlying memory mapping
/// as the current one) that restricts its view to the provided `range`.
/// Adjustment happens relative to the current view.
pub(crate) fn constrain(&self, range: Range<u64>) -> Option<Self> {
#[doc(hidden)]
pub fn constrain(&self, range: Range<u64>) -> Option<Self> {
if self.view.start + range.end > self.view.end {
return None
}
Expand Down
Loading

0 comments on commit b565d87

Please sign in to comment.