* Make --benchmark_list_tests respect --benchmark_format via reporter List() (#1642)
* Export FindBenchmarksInternal for shared-library test link; fix include order
* fix(linux): prevent infinite re-exec loop under AppArmor
The `MaybeReenterWithoutASLR()` function in `src/benchmark.cc` caused infinite execv() loops when running benchmarks under AppArmor-enabled LSMs. The existing fix from #1985 only checked whether personality(ADDR_NO_RANDOMIZE) succeeded in the current process before calling execv(). However, some LSMs like AppArmor can silently reset personality flags during the execve() system call transition, even though the flag was successfully set in the parent process.
Additionally, ensure that we actually report that ASLR is still on in case we fail to unset it.
Signed-off-by: anish <anishesg@users.noreply.github.com>
Co-authored-by: anish <anishesg@users.noreply.github.com>
Co-authored-by: Roman Lebedev <lebedev.ri@gmail.com>
This is particularly problematic because large allocations partially used can get eagerly memset even if they hit the backing allocator, faulting in a ton of pages, so the behavior can diverge substantially from real in-app performance.
The private link library derivation skips CMake targets, so the PFM::libpfm imported target was never translated into linker flags. Static consumers using pkg-config then fail to resolve pfm_* symbols. Resolve imported targets through their IMPORTED_LOCATION and emit the corresponding -L/-l flags alongside the other private libraries.
* Fix cmake detection on pthread_affinity test on FreeBSD
In FreeBSD, non posix thread functions locate in the pthread_np.h. We
check the platform and include the correct header.
Also, pthread related features in some platforms require link to special
library. We append Threads target to BENCHMARK_CXX_LIBRARIES so that it
can be added by cxx_feature_check.
* fixup! Fix cmake detection on pthread_affinity test on FreeBSD
---------
Co-authored-by: Roman Lebedev <lebedev.ri@gmail.com>
* perf: refactor ToExponentAndMantissa to use StrFormat instead of std::stringstream
* return pair instead of using output parameters
* Bump astral-sh/setup-uv from 7.3.0 to 7.3.1 (#2136)
Bumps [astral-sh/setup-uv](https://github.com/astral-sh/setup-uv) from 7.3.0 to 7.3.1.
- [Release notes](https://github.com/astral-sh/setup-uv/releases)
- [Commits](https://github.com/astral-sh/setup-uv/compare/eac588ad8def6316056a12d4907a9d4d84ff7a3b...5a095e7a2014a4212f075830d4f7277575a9d098)
---
updated-dependencies:
- dependency-name: astral-sh/setup-uv
dependency-version: 7.3.1
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>
Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
* lambda for mantissa formatting
* structured bindings and clearer code structure
* multiple fixes to avoid Windows x64 crashes (#2139)
* fix: cast size_t widths to int for variadic printer to avoid Windows x64 crashes
* extend minimum time as Windows can have a coarse timer
* vsnprintf can consume va_list so we need to copy it to avoid UB
* extend longer test runtime to other problematic tests
---------
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* fix: cast size_t widths to int for variadic printer to avoid Windows x64 crashes
* extend minimum time as Windows can have a coarse timer
* vsnprintf can consume va_list so we need to copy it to avoid UB
* extend longer test runtime to other problematic tests
For some reasons, `std::string StrFormat(const char* format, ...)` was declared
with castom format attributes in conditions. The project wide macro
`PRINTF_FORMAT_STRING_FUNC` must be used.
On systems with more than one PMU for the CPUs (e.g. Apple M series SOCs),
generic hardware events are only created for an arbitrary PMU. Usually
this is the big cluster's PMU, which can cause inaccuracies when the
process is scheduled onto a little core. To fix this, teach PerfCounters
to register generic hardware events on all CPU PMUs.
CPU PMUs are identified using the same method as perf.
* Make the build work with -Wformat=2
The -Wformat=2 macro requires every format string either be a string
literal, or a parameter that was tagged with the format attribute. The
upshot is that it expects every printf function to be marked, or you get
warnings like this:
src/console_reporter.cc:104:23: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
104 | out << FormatString(fmt, args);
| ^~~
Marking such things is generally worthwhile since it turns on
error-checking within the library, so fill in the missing ones.
Tested with:
bazelisk build --copt=-Werror --copt=-Wformat=2 :all
* Add -Wformat=2 to catch regressions
It turns out it is useful when a benchmark is generated on the fly
before the enumeration on benchmark registration.
There is a use case in which benchmarks shall be built from
configuration flags.
Without captures, it is actually hard to pass additional data.
Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
* Fix warnings from Clang
This patch addresses a few issues:
- Wformat-nonliteral from colour printing functions
- Wmissing-prototypes from a few internal functions
Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
* Wrap tests in anonymous namespaces
Technically tests should be using internal linkage.
Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
---------
Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
* 2011: Installing contents from benchmark's tools/ subdirectory.
* Incorporating feedback from the PR
* Per PR feedback, removing guards to when setting CMAKE_INSTALL_PYTOOLSDIR
In some docker configurations the `personality()` function may return
inconsistent results. Double check if the persona has been updated
before reentering, otherwise we risk infinite loop.
Fixes https://github.com/google/benchmark/issues/1984.
It seems, on android the argument is narrower than on linux.
Let's try to support that while not introducing any explicit lossy casts.
Fixes https://github.com/google/benchmark/issues/1982
While ASLR is a useful security hardening feature,
it introduces unreproducible noise into benchmarks,
and we really really really don't want any noise,
especially easily avoidable one.
Unless prevented by some other security hardening,
we can disable ASLR for the current process,
and restart it, thus eliminating this noise.
Fixes https://github.com/google/benchmark/issues/461
* Detect and report ASLR status
Theoretically, we could just disable ASLR in `main()`,
but that seems to be disallowed by default
by some other security features.
Refs. https://github.com/google/benchmark/issues/461
* Add a note about ASLR on other OS.
getloadavg returns with -1 if cannot obtain load average, but the
current source casts the return value to size_t right away. The cast
result for such a case is probably maximum unsigned long int, so the
resizing of the res vector is certainly going to fail.
This change keeps the original return type of getloadavg and casts it
just before the resizing of the res vector.
* ThreadManager::WaitForAllThreads removed
* WaitForAllThreads was only called either in single threaded
environments or just before all threads are joined anyway. As this
doesn't add a useful synchronization point, it's removed.
* Formatting issue
* Thread Sanitizer satisfied
* More formatting issues
* fix memory manager result bug
* change is_valid to memory_iterations
* fix test
* some fixes
* fix test
...for msvc
* fix test
* fix test
add the correct explicitly casts
* fix msvc failure
* some fixes
* remove unnecessary include
There is no upstream PFM cmake package config file to use, so this has
to be installed for the benchmark cmake package config file to work.
Bug: https://bugs.gentoo.org/950573
See-Also: c2146397ac
Signed-off-by: Alfred Wingate <parona@protonmail.com>
* [clang-tidy] fix warning about decaying array to pointer
* fix a different warning (old style cast)
* use string_view instead of old-style const char* strings
* ensure bazel windows is using c++17
* learn to use bazel
* and tests
* precommit fix
* more string_view creation and casting
* format
* format
* [clang-tidy] use unique_ptr for benchmark registration (#1927)
* use unique_ptr for benchmark registration