google/benchmark

[BUG] Invoking executable without args gives regex error

Open

#1 498 ouverte le 4 oct. 2022

Voir sur GitHub
 (5 commentaires) (0 réactions) (0 assignés)C++ (1 539 forks)batch import
bughelp wanted

Métriques du dépôt

Stars
 (7 968 stars)
Métriques de merge PR
 (Merge moyen 4j 2h) (19 PRs mergées en 30 j)

Description

Describe the bug When I run the following benchmark setup I always see the message Failed to match any benchmarks against regex: . when I invoke the executable (giving --help causes a segfault

System Which OS, compiler, and compiler version are you using:

  • OS: Debian 10 for WSL2
  • Compiler and version: gcc 8.3

To reproduce Steps to reproduce the behavior:

  1. Create a new directory
  2. Place this CMakeLists.txt in that directory:
cmake_minimum_required(VERSION 3.14)
project(my_project)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED YES)

include(FetchContent)

set(BENCHMARK_ENABLE_TESTING off)

FetchContent_Declare(
  googletest
    GIT_REPOSITORY https://github.com/google/googletest.git
    GIT_TAG release-1.12.0)

FetchContent_Declare(
  googlebenchmark
    GIT_REPOSITORY https://github.com/google/benchmark.git
    GIT_TAG v1.7.0)

FetchContent_MakeAvailable(
  googletest
  googlebenchmark)

find_package(OpenMP)

add_library(
  libbench
  bench.cpp)

target_link_libraries(
  libbench
  PRIVATE
    benchmark::benchmark
    pthread
    OpenMP::OpenMP_CXX)

add_executable(bench /dev/null)
target_link_libraries(
  bench
    PRIVATE
      libbench
      benchmark::benchmark_main
      OpenMP::OpenMP_CXX)
  1. Use this .cpp file
    • or write your own as far as I can tell it doesn't matter
    • unsure if all these headers matter but I've left them in case they do
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
#include <fcntl.h>
#include <unistd.h>
#include <sstream>
#include <string>
#include <benchmark/benchmark.h>
#include <vector>
#include <random>
#include <iostream>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <mutex>
#include <omp.h>
#include <array>
#include <memory>

static void BM_vector_push_back(benchmark::State& state) {
  for (auto _ : state) {
    std::vector<int> v;
    v.reserve(1);
    benchmark::DoNotOptimize(v.data()); // Allow v.data() to be clobbered.
    v.push_back(42);
    benchmark::ClobberMemory(); // Force 42 to be written to memory.
  }
}

BENCHMARK(BM_vector_push_back);
  1. cmake -DCMAKE_BUILD_TYPE=Release -S . -B build
  2. cmake --build build -- -j8
  3. ./build/bench
  4. See error, Step 8 should've run the BM_vector_push_back test but instead it says Failed to match any benchmarks against regex: . and fails.

BONUS: 8. if you run build/bench --help you'll see a segmentation fault

Expected behavior I expect all benchmarks in the cpp file to have been run. (in this case BM_vector_push_back) Additionally I expected command line argument parsing to function correctly

Screenshots If applicable, add screenshots to help explain your problem.

Additional context The project where I noticed this problem previously used gcc directly and referred to artifacts that were created manually. I want to use cmake's FetchContent in that project instead this.

Guide contributeur