1
0
mirror of https://github.com/google/benchmark.git synced 2025-03-27 04:27:12 +08:00

Merge pull request from DiracResearch/android-fix

Android fix
This commit is contained in:
Dominic Hamon 2015-10-12 09:16:25 -07:00
commit 3c83ed5b47
5 changed files with 24 additions and 10 deletions

View File

@ -14,6 +14,7 @@
#include "commandlineflags.h"
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <limits>

View File

@ -5,6 +5,7 @@
#include <array>
#include <memory>
#include <sstream>
#include <stdio.h>
#include "arraysize.h"
@ -127,7 +128,8 @@ std::string StringPrintFImp(const char *msg, va_list args)
// allocation guess what the size might be
std::array<char, 256> local_buff;
std::size_t size = local_buff.size();
auto ret = std::vsnprintf(local_buff.data(), size, msg, args_cp);
// 2015-10-08: vsnprintf is used instead of snd::vsnprintf due to a limitation in the android-ndk
auto ret = vsnprintf(local_buff.data(), size, msg, args_cp);
va_end(args_cp);
@ -141,7 +143,8 @@ std::string StringPrintFImp(const char *msg, va_list args)
// add 1 to size to account for null-byte in size cast to prevent overflow
size = static_cast<std::size_t>(ret) + 1;
auto buff_ptr = std::unique_ptr<char[]>(new char[size]);
ret = std::vsnprintf(buff_ptr.get(), size, msg, args);
// 2015-10-08: vsnprintf is used instead of snd::vsnprintf due to a limitation in the android-ndk
ret = vsnprintf(buff_ptr.get(), size, msg, args);
return std::string(buff_ptr.get());
}

View File

@ -23,9 +23,11 @@
#include <fcntl.h>
#include <sys/resource.h>
#include <sys/types.h> // this header must be included before 'sys/sysctl.h' to avoid compilation error on FreeBSD
#include <sys/sysctl.h>
#include <sys/time.h>
#include <unistd.h>
#if defined BENCHMARK_OS_FREEBSD || defined BENCHMARK_OS_MACOSX
#include <sys/sysctl.h>
#endif
#endif
#include <cerrno>

View File

@ -4,6 +4,7 @@
#include <math.h>
#include <stdint.h>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <list>

View File

@ -3,6 +3,7 @@
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <limits>
@ -73,12 +74,18 @@ int main(int argc, char* argv[]) {
TestReporter test_reporter;
benchmark::RunSpecifiedBenchmarks(&test_reporter);
// Make sure we ran all of the tests
const size_t count = test_reporter.GetCount();
const size_t expected = (argc == 2) ? std::stoul(argv[1]) : count;
if (count != expected) {
std::cerr << "ERROR: Expected " << expected << " tests to be ran but only "
<< count << " completed" << std::endl;
return -1;
if (argc == 2) {
// Make sure we ran all of the tests
std::stringstream ss(argv[1]);
size_t expected;
ss >> expected;
const size_t count = test_reporter.GetCount();
if (count != expected) {
std::cerr << "ERROR: Expected " << expected << " tests to be ran but only "
<< count << " completed" << std::endl;
return -1;
}
}
return 0;
}