Fix Solaris compilation (#1499) (#1500)

This patch fixes compilation on Solaris, addressing the problems reported
in Issue #1499:

* Provide `HOST_NAME_MAX` definition.
* Match `sysconf(3C)` return type.
* Avoid `-Wcast-qual` warnings with `libkstat(3KSTAT)` functions.
* Avoid clash with `<floatingpoint.h>` `single` typedef.
This commit is contained in:
rorth 2022-10-06 10:18:55 +02:00 committed by GitHub
parent d2a8a4ee41
commit 12e0d70a43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 11 deletions

View File

@ -51,6 +51,7 @@ Oleksandr Sochka <sasha.sochka@gmail.com>
Ori Livneh <ori.livneh@gmail.com>
Paul Redmond <paul.redmond@gmail.com>
Radoslav Yovchev <radoslav.tm@gmail.com>
Rainer Orth <ro@cebitec.uni-bielefeld.de>
Roman Lebedev <lebedev.ri@gmail.com>
Sayan Bhattacharjee <aero.sayan@gmail.com>
Shapr3D <google-contributors@shapr3d.com>

View File

@ -73,6 +73,7 @@ Pascal Leroy <phl@google.com>
Paul Redmond <paul.redmond@gmail.com>
Pierre Phaneuf <pphaneuf@google.com>
Radoslav Yovchev <radoslav.tm@gmail.com>
Rainer Orth <ro@cebitec.uni-bielefeld.de>
Raul Marin <rmrodriguez@cartodb.com>
Ray Glover <ray.glover@uk.ibm.com>
Robert Guo <robert.guo@mongodb.com>

View File

@ -38,6 +38,7 @@
#endif
#if defined(BENCHMARK_OS_SOLARIS)
#include <kstat.h>
#include <netdb.h>
#endif
#if defined(BENCHMARK_OS_QNX)
#include <sys/syspage.h>
@ -455,6 +456,8 @@ std::string GetSystemName() {
#define HOST_NAME_MAX 154
#elif defined(BENCHMARK_OS_RTEMS)
#define HOST_NAME_MAX 256
#elif defined(BENCHMARK_OS_SOLARIS)
#define HOST_NAME_MAX MAXHOSTNAMELEN
#else
#pragma message("HOST_NAME_MAX not defined. using 64")
#define HOST_NAME_MAX 64
@ -484,12 +487,12 @@ int GetNumCPUs() {
// group
#elif defined(BENCHMARK_OS_SOLARIS)
// Returns -1 in case of a failure.
int num_cpu = sysconf(_SC_NPROCESSORS_ONLN);
long num_cpu = sysconf(_SC_NPROCESSORS_ONLN);
if (num_cpu < 0) {
fprintf(stderr, "sysconf(_SC_NPROCESSORS_ONLN) failed with error: %s\n",
strerror(errno));
}
return num_cpu;
return (int)num_cpu;
#elif defined(BENCHMARK_OS_QNX)
return static_cast<int>(_syspage_ptr->num_cpu);
#elif defined(BENCHMARK_OS_QURT)
@ -671,7 +674,8 @@ double GetCPUCyclesPerSecond(CPUInfo::Scaling scaling) {
std::cerr << "failed to open /dev/kstat\n";
return -1;
}
kstat_t* ksp = kstat_lookup(kc, (char*)"cpu_info", -1, (char*)"cpu_info0");
kstat_t* ksp = kstat_lookup(kc, const_cast<char*>("cpu_info"), -1,
const_cast<char*>("cpu_info0"));
if (!ksp) {
std::cerr << "failed to lookup in /dev/kstat\n";
return -1;
@ -680,8 +684,8 @@ double GetCPUCyclesPerSecond(CPUInfo::Scaling scaling) {
std::cerr << "failed to read from /dev/kstat\n";
return -1;
}
kstat_named_t* knp =
(kstat_named_t*)kstat_data_lookup(ksp, (char*)"current_clock_Hz");
kstat_named_t* knp = (kstat_named_t*)kstat_data_lookup(
ksp, const_cast<char*>("current_clock_Hz"));
if (!knp) {
std::cerr << "failed to lookup data in /dev/kstat\n";
return -1;

View File

@ -10,19 +10,19 @@
// Test that Setup() and Teardown() are called exactly once
// for each benchmark run (single-threaded).
namespace single {
namespace singlethreaded {
static int setup_call = 0;
static int teardown_call = 0;
} // namespace single
} // namespace singlethreaded
static void DoSetup1(const benchmark::State& state) {
++single::setup_call;
++singlethreaded::setup_call;
// Setup/Teardown should never be called with any thread_idx != 0.
assert(state.thread_index() == 0);
}
static void DoTeardown1(const benchmark::State& state) {
++single::teardown_call;
++singlethreaded::teardown_call;
assert(state.thread_index() == 0);
}
@ -134,8 +134,8 @@ int main(int argc, char** argv) {
assert(ret > 0);
// Setup/Teardown is called once for each arg group (1,3,5,7).
assert(single::setup_call == 4);
assert(single::teardown_call == 4);
assert(singlethreaded::setup_call == 4);
assert(singlethreaded::teardown_call == 4);
// 3 group of threads calling this function (3,5,10).
assert(concurrent::setup_call.load(std::memory_order_relaxed) == 3);