quickstep-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbdeshm...@apache.org
Subject [05/51] [abbrv] [partial] incubator-quickstep git commit: Added shell script to download prerequisite third party libs
Date Thu, 19 Jan 2017 20:06:42 GMT
http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b249eb11/third_party/gperftools/src/tests/profile-handler_unittest.cc
----------------------------------------------------------------------
diff --git a/third_party/gperftools/src/tests/profile-handler_unittest.cc b/third_party/gperftools/src/tests/profile-handler_unittest.cc
deleted file mode 100644
index e49d23e..0000000
--- a/third_party/gperftools/src/tests/profile-handler_unittest.cc
+++ /dev/null
@@ -1,519 +0,0 @@
-// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
-// Copyright 2009 Google Inc. All Rights Reserved.
-// Author: Nabeel Mian (nabeelmian@google.com)
-//         Chris Demetriou (cgd@google.com)
-//
-// Use of this source code is governed by a BSD-style license that can
-// be found in the LICENSE file.
-//
-//
-// This file contains the unit tests for profile-handler.h interface.
-//
-// It is linked into three separate unit tests:
-//     profile-handler_unittest tests basic functionality
-//     profile-handler_disable_test tests that the profiler
-//         is disabled with --install_signal_handlers=false
-//     profile-handler_conflict_test tests that the profiler
-//         is disabled when a SIGPROF handler is registered before InitGoogle.
-
-#include "config.h"
-#include "profile-handler.h"
-
-#include <assert.h>
-#include <pthread.h>
-#include <sys/time.h>
-#include <time.h>
-#include "base/logging.h"
-#include "base/simple_mutex.h"
-
-// Some helpful macros for the test class
-#define TEST_F(cls, fn)    void cls :: fn()
-
-// Do we expect the profiler to be enabled?
-DEFINE_bool(test_profiler_enabled, true,
-            "expect profiler to be enabled during tests");
-
-// Should we look at the kernel signal handler settings during the test?
-// Not if we're in conflict_test, because we can't distinguish its nop
-// handler from the real one.
-DEFINE_bool(test_profiler_signal_handler, true,
-            "check profiler signal handler during tests");
-
-namespace {
-
-// TODO(csilvers): error-checking on the pthreads routines
-class Thread {
- public:
-  Thread() : joinable_(false) { }
-  void SetJoinable(bool value) { joinable_ = value; }
-  void Start() {
-    pthread_attr_t attr;
-    pthread_attr_init(&attr);
-    pthread_attr_setdetachstate(&attr, joinable_ ? PTHREAD_CREATE_JOINABLE
-                                                 : PTHREAD_CREATE_DETACHED);
-    pthread_create(&thread_, &attr, &DoRun, this);
-    pthread_attr_destroy(&attr);
-  }
-  void Join()  {
-    assert(joinable_);
-    pthread_join(thread_, NULL);
-  }
-  virtual void Run() = 0;
- private:
-  static void* DoRun(void* cls) {
-    ProfileHandlerRegisterThread();
-    reinterpret_cast<Thread*>(cls)->Run();
-    return NULL;
-  }
-  pthread_t thread_;
-  bool joinable_;
-};
-
-// Sleep interval in nano secs. ITIMER_PROF goes off only afer the specified CPU
-// time is consumed. Under heavy load this process may no get scheduled in a
-// timely fashion. Therefore, give enough time (20x of ProfileHandle timer
-// interval 10ms (100Hz)) for this process to accumulate enought CPU time to get
-// a profile tick.
-int kSleepInterval = 200000000;
-
-// Sleep interval in nano secs. To ensure that if the timer has expired it is
-// reset.
-int kTimerResetInterval = 5000000;
-
-// Whether each thread has separate timers.
-static bool linux_per_thread_timers_mode_ = false;
-static bool timer_separate_ = false;
-static int timer_type_ = ITIMER_PROF;
-static int signal_number_ = SIGPROF;
-
-// Delays processing by the specified number of nano seconds. 'delay_ns'
-// must be less than the number of nano seconds in a second (1000000000).
-void Delay(int delay_ns) {
-  static const int kNumNSecInSecond = 1000000000;
-  EXPECT_LT(delay_ns, kNumNSecInSecond);
-  struct timespec delay = { 0, delay_ns };
-  nanosleep(&delay, 0);
-}
-
-// Checks whether the profile timer is enabled for the current thread.
-bool IsTimerEnabled() {
-  itimerval current_timer;
-  EXPECT_EQ(0, getitimer(timer_type_, &current_timer));
-  if ((current_timer.it_value.tv_sec == 0) &&
-      (current_timer.it_value.tv_usec != 0)) {
-    // May be the timer has expired. Sleep for a bit and check again.
-    Delay(kTimerResetInterval);
-    EXPECT_EQ(0, getitimer(timer_type_, &current_timer));
-  }
-  return (current_timer.it_value.tv_sec != 0 ||
-          current_timer.it_value.tv_usec != 0);
-}
-
-class VirtualTimerGetterThread : public Thread {
- public:
-  VirtualTimerGetterThread() {
-    memset(&virtual_timer_, 0, sizeof virtual_timer_);
-  }
-  struct itimerval virtual_timer_;
-
- private:
-  void Run() {
-    CHECK_EQ(0, getitimer(ITIMER_VIRTUAL, &virtual_timer_));
-  }
-};
-
-// This function checks whether the timers are shared between thread. This
-// function spawns a thread, so use it carefully when testing thread-dependent
-// behaviour.
-static bool threads_have_separate_timers() {
-  struct itimerval new_timer_val;
-
-  // Enable the virtual timer in the current thread.
-  memset(&new_timer_val, 0, sizeof new_timer_val);
-  new_timer_val.it_value.tv_sec = 1000000;  // seconds
-  CHECK_EQ(0, setitimer(ITIMER_VIRTUAL, &new_timer_val, NULL));
-
-  // Spawn a thread, get the virtual timer's value there.
-  VirtualTimerGetterThread thread;
-  thread.SetJoinable(true);
-  thread.Start();
-  thread.Join();
-
-  // Disable timer here.
-  memset(&new_timer_val, 0, sizeof new_timer_val);
-  CHECK_EQ(0, setitimer(ITIMER_VIRTUAL, &new_timer_val, NULL));
-
-  bool target_timer_enabled = (thread.virtual_timer_.it_value.tv_sec != 0 ||
-                               thread.virtual_timer_.it_value.tv_usec != 0);
-  if (!target_timer_enabled) {
-    LOG(INFO, "threads have separate timers");
-    return true;
-  } else {
-    LOG(INFO, "threads have shared timers");
-    return false;
-  }
-}
-
-// Dummy worker thread to accumulate cpu time.
-class BusyThread : public Thread {
- public:
-  BusyThread() : stop_work_(false) {
-  }
-
-  // Setter/Getters
-  bool stop_work() {
-    MutexLock lock(&mu_);
-    return stop_work_;
-  }
-  void set_stop_work(bool stop_work) {
-    MutexLock lock(&mu_);
-    stop_work_ = stop_work;
-  }
-
- private:
-  // Protects stop_work_ below.
-  Mutex mu_;
-  // Whether to stop work?
-  bool stop_work_;
-
-  // Do work until asked to stop.
-  void Run() {
-    while (!stop_work()) {
-    }
-    // If timers are separate, check that timer is enabled for this thread.
-    EXPECT_TRUE(linux_per_thread_timers_mode_ || !timer_separate_ || IsTimerEnabled());
-  }
-};
-
-class NullThread : public Thread {
- private:
-  void Run() {
-    // If timers are separate, check that timer is enabled for this thread.
-    EXPECT_TRUE(linux_per_thread_timers_mode_ || !timer_separate_ || IsTimerEnabled());
-  }
-};
-
-// Signal handler which tracks the profile timer ticks.
-static void TickCounter(int sig, siginfo_t* sig_info, void *vuc,
-                        void* tick_counter) {
-  int* counter = static_cast<int*>(tick_counter);
-  ++(*counter);
-}
-
-// This class tests the profile-handler.h interface.
-class ProfileHandlerTest {
- protected:
-
-  // Determines whether threads have separate timers.
-  static void SetUpTestCase() {
-    timer_type_ = (getenv("CPUPROFILE_REALTIME") ? ITIMER_REAL : ITIMER_PROF);
-    signal_number_ = (getenv("CPUPROFILE_REALTIME") ? SIGALRM : SIGPROF);
-
-    timer_separate_ = threads_have_separate_timers();
-#if HAVE_LINUX_SIGEV_THREAD_ID
-    linux_per_thread_timers_mode_ = (getenv("CPUPROFILE_PER_THREAD_TIMERS") != NULL);
-#endif
-    Delay(kTimerResetInterval);
-  }
-
-  // Sets up the profile timers and SIGPROF/SIGALRM handler in a known state.
-  // It does the following:
-  // 1. Unregisters all the callbacks, stops the timer (if shared) and
-  //    clears out timer_sharing state in the ProfileHandler. This clears
-  //    out any state left behind by the previous test or during module
-  //    initialization when the test program was started.
-  // 2. Spawns two threads which will be registered with the ProfileHandler.
-  //    At this time ProfileHandler knows if the timers are shared.
-  // 3. Starts a busy worker thread to accumulate CPU usage.
-  virtual void SetUp() {
-    // Reset the state of ProfileHandler between each test. This unregisters
-    // all callbacks, stops timer (if shared) and clears timer sharing state.
-    ProfileHandlerReset();
-    EXPECT_EQ(0, GetCallbackCount());
-    VerifyDisabled();
-    // ProfileHandler requires at least two threads to be registerd to determine
-    // whether timers are shared.
-    RegisterThread();
-    RegisterThread();
-    // Now that two threads are started, verify that the signal handler is
-    // disabled and the timers are correctly enabled/disabled.
-    VerifyDisabled();
-    // Start worker to accumulate cpu usage.
-    StartWorker();
-  }
-
-  virtual void TearDown() {
-    ProfileHandlerReset();
-    // Stops the worker thread.
-    StopWorker();
-  }
-
-  // Starts a no-op thread that gets registered with the ProfileHandler. Waits
-  // for the thread to stop.
-  void RegisterThread() {
-    NullThread t;
-    t.SetJoinable(true);
-    t.Start();
-    t.Join();
-  }
-
-  // Starts a busy worker thread to accumulate cpu time. There should be only
-  // one busy worker running. This is required for the case where there are
-  // separate timers for each thread.
-  void StartWorker() {
-    busy_worker_ = new BusyThread();
-    busy_worker_->SetJoinable(true);
-    busy_worker_->Start();
-    // Wait for worker to start up and register with the ProfileHandler.
-    // TODO(nabeelmian) This may not work under very heavy load.
-    Delay(kSleepInterval);
-  }
-
-  // Stops the worker thread.
-  void StopWorker() {
-    busy_worker_->set_stop_work(true);
-    busy_worker_->Join();
-    delete busy_worker_;
-  }
-
-  // Checks whether SIGPROF/SIGALRM signal handler is enabled.
-  bool IsSignalEnabled() {
-    struct sigaction sa;
-    CHECK_EQ(sigaction(signal_number_, NULL, &sa), 0);
-    return ((sa.sa_handler == SIG_IGN) || (sa.sa_handler == SIG_DFL)) ?
-        false : true;
-  }
-
-  // Gets the number of callbacks registered with the ProfileHandler.
-  uint32 GetCallbackCount() {
-    ProfileHandlerState state;
-    ProfileHandlerGetState(&state);
-    return state.callback_count;
-  }
-
-  // Gets the current ProfileHandler interrupt count.
-  uint64 GetInterruptCount() {
-    ProfileHandlerState state;
-    ProfileHandlerGetState(&state);
-    return state.interrupts;
-  }
-
-  // Verifies that a callback is correctly registered and receiving
-  // profile ticks.
-  void VerifyRegistration(const int& tick_counter) {
-    // Check the callback count.
-    EXPECT_GT(GetCallbackCount(), 0);
-    // Check that the profile timer is enabled.
-    EXPECT_EQ(FLAGS_test_profiler_enabled, linux_per_thread_timers_mode_ || IsTimerEnabled());
-    // Check that the signal handler is enabled.
-    if (FLAGS_test_profiler_signal_handler) {
-      EXPECT_EQ(FLAGS_test_profiler_enabled, IsSignalEnabled());
-    }
-    uint64 interrupts_before = GetInterruptCount();
-    // Sleep for a bit and check that tick counter is making progress.
-    int old_tick_count = tick_counter;
-    Delay(kSleepInterval);
-    int new_tick_count = tick_counter;
-    uint64 interrupts_after = GetInterruptCount();
-    if (FLAGS_test_profiler_enabled) {
-      EXPECT_GT(new_tick_count, old_tick_count);
-      EXPECT_GT(interrupts_after, interrupts_before);
-    } else {
-      EXPECT_EQ(new_tick_count, old_tick_count);
-      EXPECT_EQ(interrupts_after, interrupts_before);
-    }
-  }
-
-  // Verifies that a callback is not receiving profile ticks.
-  void VerifyUnregistration(const int& tick_counter) {
-    // Sleep for a bit and check that tick counter is not making progress.
-    int old_tick_count = tick_counter;
-    Delay(kSleepInterval);
-    int new_tick_count = tick_counter;
-    EXPECT_EQ(old_tick_count, new_tick_count);
-    // If no callbacks, signal handler and shared timer should be disabled.
-    if (GetCallbackCount() == 0) {
-      if (FLAGS_test_profiler_signal_handler) {
-        EXPECT_FALSE(IsSignalEnabled());
-      }
-      if (!linux_per_thread_timers_mode_) {
-        if (timer_separate_) {
-          EXPECT_TRUE(IsTimerEnabled());
-        } else {
-          EXPECT_FALSE(IsTimerEnabled());
-        }
-      }
-    }
-  }
-
-  // Verifies that the SIGPROF/SIGALRM interrupt handler is disabled and the
-  // timer, if shared, is disabled. Expects the worker to be running.
-  void VerifyDisabled() {
-    // Check that the signal handler is disabled.
-    if (FLAGS_test_profiler_signal_handler) {
-      EXPECT_FALSE(IsSignalEnabled());
-    }
-    // Check that the callback count is 0.
-    EXPECT_EQ(0, GetCallbackCount());
-    // Check that the timer is disabled if shared, enabled otherwise.
-    if (!linux_per_thread_timers_mode_) {
-      if (timer_separate_) {
-        EXPECT_TRUE(IsTimerEnabled());
-      } else {
-        EXPECT_FALSE(IsTimerEnabled());
-      }
-    }
-    // Verify that the ProfileHandler is not accumulating profile ticks.
-    uint64 interrupts_before = GetInterruptCount();
-    Delay(kSleepInterval);
-    uint64 interrupts_after = GetInterruptCount();
-    EXPECT_EQ(interrupts_before, interrupts_after);
-  }
-
-  // Registers a callback and waits for kTimerResetInterval for timers to get
-  // reset.
-  ProfileHandlerToken* RegisterCallback(void* callback_arg) {
-    ProfileHandlerToken* token = ProfileHandlerRegisterCallback(
-        TickCounter, callback_arg);
-    Delay(kTimerResetInterval);
-    return token;
-  }
-
-  // Unregisters a callback and waits for kTimerResetInterval for timers to get
-  // reset.
-  void UnregisterCallback(ProfileHandlerToken* token) {
-    ProfileHandlerUnregisterCallback(token);
-    Delay(kTimerResetInterval);
-  }
-
-  // Busy worker thread to accumulate cpu usage.
-  BusyThread* busy_worker_;
-
- private:
-  // The tests to run
-  void RegisterUnregisterCallback();
-  void MultipleCallbacks();
-  void Reset();
-  void RegisterCallbackBeforeThread();
-
- public:
-#define RUN(test)  do {                         \
-    printf("Running %s\n", #test);              \
-    ProfileHandlerTest pht;                     \
-    pht.SetUp();                                \
-    pht.test();                                 \
-    pht.TearDown();                             \
-} while (0)
-
-  static int RUN_ALL_TESTS() {
-    SetUpTestCase();
-    RUN(RegisterUnregisterCallback);
-    RUN(MultipleCallbacks);
-    RUN(Reset);
-    RUN(RegisterCallbackBeforeThread);
-    printf("Done\n");
-    return 0;
-  }
-};
-
-// Verifies ProfileHandlerRegisterCallback and
-// ProfileHandlerUnregisterCallback.
-TEST_F(ProfileHandlerTest, RegisterUnregisterCallback) {
-  int tick_count = 0;
-  ProfileHandlerToken* token = RegisterCallback(&tick_count);
-  VerifyRegistration(tick_count);
-  UnregisterCallback(token);
-  VerifyUnregistration(tick_count);
-}
-
-// Verifies that multiple callbacks can be registered.
-TEST_F(ProfileHandlerTest, MultipleCallbacks) {
-  // Register first callback.
-  int first_tick_count;
-  ProfileHandlerToken* token1 = RegisterCallback(&first_tick_count);
-  // Check that callback was registered correctly.
-  VerifyRegistration(first_tick_count);
-  EXPECT_EQ(1, GetCallbackCount());
-
-  // Register second callback.
-  int second_tick_count;
-  ProfileHandlerToken* token2 = RegisterCallback(&second_tick_count);
-  // Check that callback was registered correctly.
-  VerifyRegistration(second_tick_count);
-  EXPECT_EQ(2, GetCallbackCount());
-
-  // Unregister first callback.
-  UnregisterCallback(token1);
-  VerifyUnregistration(first_tick_count);
-  EXPECT_EQ(1, GetCallbackCount());
-  // Verify that second callback is still registered.
-  VerifyRegistration(second_tick_count);
-
-  // Unregister second callback.
-  UnregisterCallback(token2);
-  VerifyUnregistration(second_tick_count);
-  EXPECT_EQ(0, GetCallbackCount());
-
-  // Verify that the signal handler and timers are correctly disabled.
-  VerifyDisabled();
-}
-
-// Verifies ProfileHandlerReset
-TEST_F(ProfileHandlerTest, Reset) {
-  // Verify that the profile timer interrupt is disabled.
-  VerifyDisabled();
-  int first_tick_count;
-  RegisterCallback(&first_tick_count);
-  VerifyRegistration(first_tick_count);
-  EXPECT_EQ(1, GetCallbackCount());
-
-  // Register second callback.
-  int second_tick_count;
-  RegisterCallback(&second_tick_count);
-  VerifyRegistration(second_tick_count);
-  EXPECT_EQ(2, GetCallbackCount());
-
-  // Reset the profile handler and verify that callback were correctly
-  // unregistered and timer/signal are disabled.
-  ProfileHandlerReset();
-  VerifyUnregistration(first_tick_count);
-  VerifyUnregistration(second_tick_count);
-  VerifyDisabled();
-}
-
-// Verifies that ProfileHandler correctly handles a case where a callback was
-// registered before the second thread started.
-TEST_F(ProfileHandlerTest, RegisterCallbackBeforeThread) {
-  // Stop the worker.
-  StopWorker();
-  // Unregister all existing callbacks, stop the timer (if shared), disable
-  // the signal handler and reset the timer sharing state in the Profile
-  // Handler.
-  ProfileHandlerReset();
-  EXPECT_EQ(0, GetCallbackCount());
-  VerifyDisabled();
-
-  // Start the worker. At this time ProfileHandler doesn't know if timers are
-  // shared as only one thread has registered so far.
-  StartWorker();
-  // Register a callback and check that profile ticks are being delivered.
-  int tick_count;
-  RegisterCallback(&tick_count);
-  EXPECT_EQ(1, GetCallbackCount());
-  VerifyRegistration(tick_count);
-
-  // Register a second thread and verify that timer and signal handler are
-  // correctly enabled.
-  RegisterThread();
-  EXPECT_EQ(1, GetCallbackCount());
-  EXPECT_EQ(FLAGS_test_profiler_enabled, linux_per_thread_timers_mode_ || IsTimerEnabled());
-  if (FLAGS_test_profiler_signal_handler) {
-    EXPECT_EQ(FLAGS_test_profiler_enabled, IsSignalEnabled());
-  }
-}
-
-}  // namespace
-
-int main(int argc, char** argv) {
-  return ProfileHandlerTest::RUN_ALL_TESTS();
-}

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b249eb11/third_party/gperftools/src/tests/profiledata_unittest.cc
----------------------------------------------------------------------
diff --git a/third_party/gperftools/src/tests/profiledata_unittest.cc b/third_party/gperftools/src/tests/profiledata_unittest.cc
deleted file mode 100644
index 972c1b0..0000000
--- a/third_party/gperftools/src/tests/profiledata_unittest.cc
+++ /dev/null
@@ -1,611 +0,0 @@
-// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
-// Copyright (c) 2007, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//     * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-//     * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-//     * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// ---
-// Author: Chris Demetriou
-//
-// This file contains the unit tests for the ProfileData class.
-
-#if defined HAVE_STDINT_H
-#include <stdint.h>             // to get uintptr_t
-#elif defined HAVE_INTTYPES_H
-#include <inttypes.h>           // another place uintptr_t might be defined
-#endif
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <string.h>
-#include <string>
-
-#include "profiledata.h"
-
-#include "base/commandlineflags.h"
-#include "base/logging.h"
-
-using std::string;
-
-// Some helpful macros for the test class
-#define TEST_F(cls, fn)    void cls :: fn()
-
-namespace {
-
-template<typename T> class scoped_array {
- public:
-  scoped_array(T* data) : data_(data) { }
-  ~scoped_array() { delete[] data_; }
-  T* get() { return data_; }
-  T& operator[](int i) { return data_[i]; }
- private:
-  T* const data_;
-};
-
-// Re-runs fn until it doesn't cause EINTR.
-#define NO_INTR(fn)   do {} while ((fn) < 0 && errno == EINTR)
-
-// Read up to "count" bytes from file descriptor "fd" into the buffer
-// starting at "buf" while handling short reads and EINTR.  On
-// success, return the number of bytes read.  Otherwise, return -1.
-static ssize_t ReadPersistent(const int fd, void *buf, const size_t count) {
-  CHECK_GE(fd, 0);
-  char *buf0 = reinterpret_cast<char *>(buf);
-  ssize_t num_bytes = 0;
-  while (num_bytes < count) {
-    ssize_t len;
-    NO_INTR(len = read(fd, buf0 + num_bytes, count - num_bytes));
-    if (len < 0) {  // There was an error other than EINTR.
-      return -1;
-    }
-    if (len == 0) {  // Reached EOF.
-      break;
-    }
-    num_bytes += len;
-  }
-  CHECK(num_bytes <= count);
-  return num_bytes;
-}
-
-// Thin wrapper around a file descriptor so that the file descriptor
-// gets closed for sure.
-struct FileDescriptor {
-  const int fd_;
-  explicit FileDescriptor(int fd) : fd_(fd) {}
-  ~FileDescriptor() {
-    if (fd_ >= 0) {
-      NO_INTR(close(fd_));
-    }
-  }
-  int get() { return fd_; }
-};
-
-// must be the same as with ProfileData::Slot.
-typedef uintptr_t ProfileDataSlot;
-
-// Quick and dirty function to make a number into a void* for use in a
-// sample.
-inline void* V(intptr_t x) { return reinterpret_cast<void*>(x); }
-
-// String returned by ProfileDataChecker helper functions to indicate success.
-const char kNoError[] = "";
-
-class ProfileDataChecker {
- public:
-  ProfileDataChecker() {
-    const char* tmpdir = getenv("TMPDIR");
-    if (tmpdir == NULL)
-      tmpdir = "/tmp";
-    mkdir(tmpdir, 0755);     // if necessary
-    filename_ = string(tmpdir) + "/profiledata_unittest.tmp";
-  }
-
-  string filename() const { return filename_; }
-
-  // Checks the first 'num_slots' profile data slots in the file
-  // against the data pointed to by 'slots'.  Returns kNoError if the
-  // data matched, otherwise returns an indication of the cause of the
-  // mismatch.
-  string Check(const ProfileDataSlot* slots, int num_slots) {
-    return CheckWithSkips(slots, num_slots, NULL, 0);
-  }
-
-  // Checks the first 'num_slots' profile data slots in the file
-  // against the data pointed to by 'slots', skipping over entries
-  // described by 'skips' and 'num_skips'.
-  //
-  // 'skips' must be a sorted list of (0-based) slot numbers to be
-  // skipped, of length 'num_skips'.  Note that 'num_slots' includes
-  // any skipped slots, i.e., the first 'num_slots' profile data slots
-  // will be considered, but some may be skipped.
-  //
-  // Returns kNoError if the data matched, otherwise returns an
-  // indication of the cause of the mismatch.
-  string CheckWithSkips(const ProfileDataSlot* slots, int num_slots,
-                        const int* skips, int num_skips);
-
-  // Validate that a profile is correctly formed.  The profile is
-  // assumed to have been created by the same kind of binary (e.g.,
-  // same slot size, same endian, etc.) as is validating the profile.
-  //
-  // Returns kNoError if the profile appears valid, otherwise returns
-  // an indication of the problem with the profile.
-  string ValidateProfile();
-
- private:
-  string filename_;
-};
-
-string ProfileDataChecker::CheckWithSkips(const ProfileDataSlot* slots,
-                                          int num_slots, const int* skips,
-                                          int num_skips) {
-  FileDescriptor fd(open(filename_.c_str(), O_RDONLY));
-  if (fd.get() < 0)
-    return "file open error";
-
-  scoped_array<ProfileDataSlot> filedata(new ProfileDataSlot[num_slots]);
-  size_t expected_bytes = num_slots * sizeof filedata[0];
-  ssize_t bytes_read = ReadPersistent(fd.get(), filedata.get(), expected_bytes);
-  if (expected_bytes != bytes_read)
-    return "file too small";
-
-  for (int i = 0; i < num_slots; i++) {
-    if (num_skips > 0 && *skips == i) {
-      num_skips--;
-      skips++;
-      continue;
-    }
-    if (slots[i] != filedata[i])
-      return "data mismatch";
-  }
-  return kNoError;
-}
-
-string ProfileDataChecker::ValidateProfile() {
-  FileDescriptor fd(open(filename_.c_str(), O_RDONLY));
-  if (fd.get() < 0)
-    return "file open error";
-
-  struct stat statbuf;
-  if (fstat(fd.get(), &statbuf) != 0)
-    return "fstat error";
-  if (statbuf.st_size != static_cast<ssize_t>(statbuf.st_size))
-    return "file impossibly large";
-  ssize_t filesize = statbuf.st_size;
-
-  scoped_array<char> filedata(new char[filesize]);
-  if (ReadPersistent(fd.get(), filedata.get(), filesize) != filesize)
-    return "read of whole file failed";
-
-  // Must have enough data for the header and the trailer.
-  if (filesize < (5 + 3) * sizeof(ProfileDataSlot))
-    return "not enough data in profile for header + trailer";
-
-  // Check the header
-  if (reinterpret_cast<ProfileDataSlot*>(filedata.get())[0] != 0)
-    return "error in header: non-zero count";
-  if (reinterpret_cast<ProfileDataSlot*>(filedata.get())[1] != 3)
-    return "error in header: num_slots != 3";
-  if (reinterpret_cast<ProfileDataSlot*>(filedata.get())[2] != 0)
-    return "error in header: non-zero format version";
-  // Period (slot 3) can have any value.
-  if (reinterpret_cast<ProfileDataSlot*>(filedata.get())[4] != 0)
-    return "error in header: non-zero padding value";
-  ssize_t cur_offset = 5 * sizeof(ProfileDataSlot);
-
-  // While there are samples, skip them.  Each sample consists of
-  // at least three slots.
-  bool seen_trailer = false;
-  while (!seen_trailer) {
-    if (cur_offset > filesize - 3 * sizeof(ProfileDataSlot))
-      return "truncated sample header";
-    ProfileDataSlot* sample =
-        reinterpret_cast<ProfileDataSlot*>(filedata.get() + cur_offset);
-    ProfileDataSlot slots_this_sample = 2 + sample[1];
-    ssize_t size_this_sample = slots_this_sample * sizeof(ProfileDataSlot);
-    if (cur_offset > filesize - size_this_sample)
-      return "truncated sample";
-
-    if (sample[0] == 0 && sample[1] == 1 && sample[2] == 0) {
-      seen_trailer = true;
-    } else {
-      if (sample[0] < 1)
-        return "error in sample: sample count < 1";
-      if (sample[1] < 1)
-        return "error in sample: num_pcs < 1";
-      for (int i = 2; i < slots_this_sample; i++) {
-        if (sample[i] == 0)
-          return "error in sample: NULL PC";
-      }
-    }
-    cur_offset += size_this_sample;
-  }
-
-  // There must be at least one line in the (text) list of mapped objects,
-  // and it must be terminated by a newline.  Note, the use of newline
-  // here and below Might not be reasonable on non-UNIX systems.
-  if (cur_offset >= filesize)
-    return "no list of mapped objects";
-  if (filedata[filesize - 1] != '\n')
-    return "profile did not end with a complete line";
-
-  while (cur_offset < filesize) {
-    char* line_start = filedata.get() + cur_offset;
-
-    // Find the end of the line, and replace it with a NUL for easier
-    // scanning.
-    char* line_end = strchr(line_start, '\n');
-    *line_end = '\0';
-
-    // Advance past any leading space.  It's allowed in some lines,
-    // but not in others.
-    bool has_leading_space = false;
-    char* line_cur = line_start;
-    while (*line_cur == ' ') {
-      has_leading_space = true;
-      line_cur++;
-    }
-
-    bool found_match = false;
-
-    // Check for build lines.
-    if (!found_match) {
-      found_match = (strncmp(line_cur, "build=", 6) == 0);
-      // Anything may follow "build=", and leading space is allowed.
-    }
-
-    // A line from ProcMapsIterator::FormatLine, of the form:
-    //
-    // 40000000-40015000 r-xp 00000000 03:01 12845071   /lib/ld-2.3.2.so
-    //
-    // Leading space is not allowed.  The filename may be omitted or
-    // may consist of multiple words, so we scan only up to the
-    // space before the filename.
-    if (!found_match) {
-      int chars_scanned = -1;
-      sscanf(line_cur, "%*x-%*x %*c%*c%*c%*c %*x %*x:%*x %*d %n",
-             &chars_scanned);
-      found_match = (chars_scanned > 0 && !has_leading_space);
-    }
-
-    // A line from DumpAddressMap, of the form:
-    //
-    // 40000000-40015000: /lib/ld-2.3.2.so
-    //
-    // Leading space is allowed.  The filename may be omitted or may
-    // consist of multiple words, so we scan only up to the space
-    // before the filename.
-    if (!found_match) {
-      int chars_scanned = -1;
-      sscanf(line_cur, "%*x-%*x: %n", &chars_scanned);
-      found_match = (chars_scanned > 0);
-    }
-
-    if (!found_match)
-      return "unrecognized line in text section";
-
-    cur_offset += (line_end - line_start) + 1;
-  }
-
-  return kNoError;
-}
-
-class ProfileDataTest {
- protected:
-  void ExpectStopped() {
-    EXPECT_FALSE(collector_.enabled());
-  }
-
-  void ExpectRunningSamples(int samples) {
-    ProfileData::State state;
-    collector_.GetCurrentState(&state);
-    EXPECT_TRUE(state.enabled);
-    EXPECT_EQ(samples, state.samples_gathered);
-  }
-
-  void ExpectSameState(const ProfileData::State& before,
-                       const ProfileData::State& after) {
-    EXPECT_EQ(before.enabled, after.enabled);
-    EXPECT_EQ(before.samples_gathered, after.samples_gathered);
-    EXPECT_EQ(before.start_time, after.start_time);
-    EXPECT_STREQ(before.profile_name, after.profile_name);
-  }
-
-  ProfileData        collector_;
-  ProfileDataChecker checker_;
-
- private:
-  // The tests to run
-  void OpsWhenStopped();
-  void StartStopEmpty();
-  void StartStopNoOptionsEmpty();
-  void StartWhenStarted();
-  void StartStopEmpty2();
-  void CollectOne();
-  void CollectTwoMatching();
-  void CollectTwoFlush();
-  void StartResetRestart();
-
- public:
-#define RUN(test)  do {                         \
-    printf("Running %s\n", #test);              \
-    ProfileDataTest pdt;                        \
-    pdt.test();                                 \
-} while (0)
-
-  static int RUN_ALL_TESTS() {
-    RUN(OpsWhenStopped);
-    RUN(StartStopEmpty);
-    RUN(StartWhenStarted);
-    RUN(StartStopEmpty2);
-    RUN(CollectOne);
-    RUN(CollectTwoMatching);
-    RUN(CollectTwoFlush);
-    RUN(StartResetRestart);
-    return 0;
-  }
-};
-
-// Check that various operations are safe when stopped.
-TEST_F(ProfileDataTest, OpsWhenStopped) {
-  ExpectStopped();
-  EXPECT_FALSE(collector_.enabled());
-
-  // Verify that state is disabled, all-empty/all-0
-  ProfileData::State state_before;
-  collector_.GetCurrentState(&state_before);
-  EXPECT_FALSE(state_before.enabled);
-  EXPECT_EQ(0, state_before.samples_gathered);
-  EXPECT_EQ(0, state_before.start_time);
-  EXPECT_STREQ("", state_before.profile_name);
-
-  // Safe to call stop again.
-  collector_.Stop();
-
-  // Safe to call FlushTable.
-  collector_.FlushTable();
-
-  // Safe to call Add.
-  const void *trace[] = { V(100), V(101), V(102), V(103), V(104) };
-  collector_.Add(arraysize(trace), trace);
-
-  ProfileData::State state_after;
-  collector_.GetCurrentState(&state_after);
-
-  ExpectSameState(state_before, state_after);
-}
-
-// Start and Stop, collecting no samples.  Verify output contents.
-TEST_F(ProfileDataTest, StartStopEmpty) {
-  const int frequency = 1;
-  ProfileDataSlot slots[] = {
-    0, 3, 0, 1000000 / frequency, 0,    // binary header
-    0, 1, 0                             // binary trailer
-  };
-
-  ExpectStopped();
-  ProfileData::Options options;
-  options.set_frequency(frequency);
-  EXPECT_TRUE(collector_.Start(checker_.filename().c_str(), options));
-  ExpectRunningSamples(0);
-  collector_.Stop();
-  ExpectStopped();
-  EXPECT_EQ(kNoError, checker_.ValidateProfile());
-  EXPECT_EQ(kNoError, checker_.Check(slots, arraysize(slots)));
-}
-
-// Start and Stop with no options, collecting no samples.  Verify
-// output contents.
-TEST_F(ProfileDataTest, StartStopNoOptionsEmpty) {
-  // We're not requesting a specific period, implementation can do
-  // whatever it likes.
-  ProfileDataSlot slots[] = {
-    0, 3, 0, 0 /* skipped */, 0,        // binary header
-    0, 1, 0                             // binary trailer
-  };
-  int slots_to_skip[] = { 3 };
-
-  ExpectStopped();
-  EXPECT_TRUE(collector_.Start(checker_.filename().c_str(),
-                               ProfileData::Options()));
-  ExpectRunningSamples(0);
-  collector_.Stop();
-  ExpectStopped();
-  EXPECT_EQ(kNoError, checker_.ValidateProfile());
-  EXPECT_EQ(kNoError, checker_.CheckWithSkips(slots, arraysize(slots),
-                                              slots_to_skip,
-                                              arraysize(slots_to_skip)));
-}
-
-// Start after already started.  Should return false and not impact
-// collected data or state.
-TEST_F(ProfileDataTest, StartWhenStarted) {
-  const int frequency = 1;
-  ProfileDataSlot slots[] = {
-    0, 3, 0, 1000000 / frequency, 0,    // binary header
-    0, 1, 0                             // binary trailer
-  };
-
-  ProfileData::Options options;
-  options.set_frequency(frequency);
-  EXPECT_TRUE(collector_.Start(checker_.filename().c_str(), options));
-
-  ProfileData::State state_before;
-  collector_.GetCurrentState(&state_before);
-
-  options.set_frequency(frequency * 2);
-  CHECK(!collector_.Start("foobar", options));
-
-  ProfileData::State state_after;
-  collector_.GetCurrentState(&state_after);
-  ExpectSameState(state_before, state_after);
-
-  collector_.Stop();
-  ExpectStopped();
-  EXPECT_EQ(kNoError, checker_.ValidateProfile());
-  EXPECT_EQ(kNoError, checker_.Check(slots, arraysize(slots)));
-}
-
-// Like StartStopEmpty, but uses a different file name and frequency.
-TEST_F(ProfileDataTest, StartStopEmpty2) {
-  const int frequency = 2;
-  ProfileDataSlot slots[] = {
-    0, 3, 0, 1000000 / frequency, 0,    // binary header
-    0, 1, 0                             // binary trailer
-  };
-
-  ExpectStopped();
-  ProfileData::Options options;
-  options.set_frequency(frequency);
-  EXPECT_TRUE(collector_.Start(checker_.filename().c_str(), options));
-  ExpectRunningSamples(0);
-  collector_.Stop();
-  ExpectStopped();
-  EXPECT_EQ(kNoError, checker_.ValidateProfile());
-  EXPECT_EQ(kNoError, checker_.Check(slots, arraysize(slots)));
-}
-
-TEST_F(ProfileDataTest, CollectOne) {
-  const int frequency = 2;
-  ProfileDataSlot slots[] = {
-    0, 3, 0, 1000000 / frequency, 0,    // binary header
-    1, 5, 100, 101, 102, 103, 104,      // our sample
-    0, 1, 0                             // binary trailer
-  };
-
-  ExpectStopped();
-  ProfileData::Options options;
-  options.set_frequency(frequency);
-  EXPECT_TRUE(collector_.Start(checker_.filename().c_str(), options));
-  ExpectRunningSamples(0);
-
-  const void *trace[] = { V(100), V(101), V(102), V(103), V(104) };
-  collector_.Add(arraysize(trace), trace);
-  ExpectRunningSamples(1);
-
-  collector_.Stop();
-  ExpectStopped();
-  EXPECT_EQ(kNoError, checker_.ValidateProfile());
-  EXPECT_EQ(kNoError, checker_.Check(slots, arraysize(slots)));
-}
-
-TEST_F(ProfileDataTest, CollectTwoMatching) {
-  const int frequency = 2;
-  ProfileDataSlot slots[] = {
-    0, 3, 0, 1000000 / frequency, 0,    // binary header
-    2, 5, 100, 201, 302, 403, 504,      // our two samples
-    0, 1, 0                             // binary trailer
-  };
-
-  ExpectStopped();
-  ProfileData::Options options;
-  options.set_frequency(frequency);
-  EXPECT_TRUE(collector_.Start(checker_.filename().c_str(), options));
-  ExpectRunningSamples(0);
-
-  for (int i = 0; i < 2; ++i) {
-    const void *trace[] = { V(100), V(201), V(302), V(403), V(504) };
-    collector_.Add(arraysize(trace), trace);
-    ExpectRunningSamples(i + 1);
-  }
-
-  collector_.Stop();
-  ExpectStopped();
-  EXPECT_EQ(kNoError, checker_.ValidateProfile());
-  EXPECT_EQ(kNoError, checker_.Check(slots, arraysize(slots)));
-}
-
-TEST_F(ProfileDataTest, CollectTwoFlush) {
-  const int frequency = 2;
-  ProfileDataSlot slots[] = {
-    0, 3, 0, 1000000 / frequency, 0,    // binary header
-    1, 5, 100, 201, 302, 403, 504,      // first sample (flushed)
-    1, 5, 100, 201, 302, 403, 504,      // second identical sample
-    0, 1, 0                             // binary trailer
-  };
-
-  ExpectStopped();
-  ProfileData::Options options;
-  options.set_frequency(frequency);
-  EXPECT_TRUE(collector_.Start(checker_.filename().c_str(), options));
-  ExpectRunningSamples(0);
-
-  const void *trace[] = { V(100), V(201), V(302), V(403), V(504) };
-
-  collector_.Add(arraysize(trace), trace);
-  ExpectRunningSamples(1);
-  collector_.FlushTable();
-
-  collector_.Add(arraysize(trace), trace);
-  ExpectRunningSamples(2);
-
-  collector_.Stop();
-  ExpectStopped();
-  EXPECT_EQ(kNoError, checker_.ValidateProfile());
-  EXPECT_EQ(kNoError, checker_.Check(slots, arraysize(slots)));
-}
-
-// Start then reset, verify that the result is *not* a valid profile.
-// Then start again and make sure the result is OK.
-TEST_F(ProfileDataTest, StartResetRestart) {
-  ExpectStopped();
-  ProfileData::Options options;
-  options.set_frequency(1);
-  EXPECT_TRUE(collector_.Start(checker_.filename().c_str(), options));
-  ExpectRunningSamples(0);
-  collector_.Reset();
-  ExpectStopped();
-  // We expect the resulting file to be empty.  This is a minimal test
-  // of ValidateProfile.
-  EXPECT_NE(kNoError, checker_.ValidateProfile());
-
-  struct stat statbuf;
-  EXPECT_EQ(0, stat(checker_.filename().c_str(), &statbuf));
-  EXPECT_EQ(0, statbuf.st_size);
-
-  const int frequency = 2;  // Different frequency than used above.
-  ProfileDataSlot slots[] = {
-    0, 3, 0, 1000000 / frequency, 0,    // binary header
-    0, 1, 0                             // binary trailer
-  };
-
-  options.set_frequency(frequency);
-  EXPECT_TRUE(collector_.Start(checker_.filename().c_str(), options));
-  ExpectRunningSamples(0);
-  collector_.Stop();
-  ExpectStopped();
-  EXPECT_EQ(kNoError, checker_.ValidateProfile());
-  EXPECT_EQ(kNoError, checker_.Check(slots, arraysize(slots)));
-}
-
-}  // namespace
-
-int main(int argc, char** argv) {
-  int rc = ProfileDataTest::RUN_ALL_TESTS();
-  printf("%s\n", rc == 0 ? "PASS" : "FAIL");
-  return rc;
-}

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b249eb11/third_party/gperftools/src/tests/profiler_unittest.cc
----------------------------------------------------------------------
diff --git a/third_party/gperftools/src/tests/profiler_unittest.cc b/third_party/gperftools/src/tests/profiler_unittest.cc
deleted file mode 100644
index 321f848..0000000
--- a/third_party/gperftools/src/tests/profiler_unittest.cc
+++ /dev/null
@@ -1,147 +0,0 @@
-// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
-// Copyright (c) 2005, Google Inc.
-// All rights reserved.
-// 
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-// 
-//     * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-//     * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-//     * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// Author: Craig Silverstein
-//
-// Does some simple arithmetic and a few libc routines, so we can profile it.
-// Define WITH_THREADS to add pthread functionality as well (otherwise, btw,
-// the num_threads argument to this program is ingored).
-
-#include "config_for_unittests.h"
-#include <stdio.h>
-#include <stdlib.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>                 // for fork()
-#endif
-#include <sys/wait.h>               // for wait()
-#include "gperftools/profiler.h"
-#include "base/simple_mutex.h"
-#include "tests/testutil.h"
-
-static int result = 0;
-static int g_iters = 0;   // argv[1]
-
-Mutex mutex(Mutex::LINKER_INITIALIZED);
-
-static void test_other_thread() {
-#ifndef NO_THREADS
-  ProfilerRegisterThread();
-
-  int i, m;
-  char b[128];
-  MutexLock ml(&mutex);
-  for (m = 0; m < 1000000; ++m) {          // run millions of times
-    for (i = 0; i < g_iters; ++i ) {
-      result ^= i;
-    }
-    snprintf(b, sizeof(b), "other: %d", result);  // get some libc action
-  }
-#endif
-}
-
-static void test_main_thread() {
-  int i, m;
-  char b[128];
-  MutexLock ml(&mutex);
-  for (m = 0; m < 1000000; ++m) {          // run millions of times
-    for (i = 0; i < g_iters; ++i ) {
-      result ^= i;
-    }
-    snprintf(b, sizeof(b), "same: %d", result);  // get some libc action
-  }
-}
-
-int main(int argc, char** argv) {
-  if ( argc <= 1 ) {
-    fprintf(stderr, "USAGE: %s <iters> [num_threads] [filename]\n", argv[0]);
-    fprintf(stderr, "   iters: How many million times to run the XOR test.\n");
-    fprintf(stderr, "   num_threads: how many concurrent threads.\n");
-    fprintf(stderr, "                0 or 1 for single-threaded mode,\n");
-    fprintf(stderr, "                -# to fork instead of thread.\n");
-    fprintf(stderr, "   filename: The name of the output profile.\n");
-    fprintf(stderr, ("             If you don't specify, set CPUPROFILE "
-                     "in the environment instead!\n"));
-    return 1;
-  }
-
-  g_iters = atoi(argv[1]);
-  int num_threads = 1;
-  const char* filename = NULL;
-  if (argc > 2) {
-    num_threads = atoi(argv[2]);
-  }
-  if (argc > 3) {
-    filename = argv[3];
-  }
-
-  if (filename) {
-    ProfilerStart(filename);
-  }
-
-  test_main_thread();
-
-  ProfilerFlush();                           // just because we can
-
-  // The other threads, if any, will run only half as long as the main thread
-  if(num_threads > 0) {
-    RunManyThreads(test_other_thread, num_threads);
-  } else {
-  // Or maybe they asked to fork.  The fork test is only interesting
-  // when we use CPUPROFILE to name, so check for that
-#ifdef HAVE_UNISTD_H
-    for (; num_threads < 0; ++num_threads) {   // -<num_threads> to fork
-      if (filename) {
-        printf("FORK test only makes sense when no filename is specified.\n");
-        return 2;
-      }
-      switch (fork()) {
-        case -1:
-          printf("FORK failed!\n");
-          return 1;
-        case 0:             // child
-          return execl(argv[0], argv[0], argv[1], NULL);
-        default:
-          wait(NULL);       // we'll let the kids run one at a time
-      }
-    }
-#else
-    fprintf(stderr, "%s was compiled without support for fork() and exec()\n", argv[0]);
-#endif
-  }
-
-  test_main_thread();
-
-  if (filename) {
-    ProfilerStop();
-  }
-
-  return 0;
-}

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b249eb11/third_party/gperftools/src/tests/profiler_unittest.sh
----------------------------------------------------------------------
diff --git a/third_party/gperftools/src/tests/profiler_unittest.sh b/third_party/gperftools/src/tests/profiler_unittest.sh
deleted file mode 100755
index 4085f2c..0000000
--- a/third_party/gperftools/src/tests/profiler_unittest.sh
+++ /dev/null
@@ -1,269 +0,0 @@
-#!/bin/sh
-
-# Copyright (c) 2005, Google Inc.
-# All rights reserved.
-# 
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are
-# met:
-# 
-#     * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-#     * Redistributions in binary form must reproduce the above
-# copyright notice, this list of conditions and the following disclaimer
-# in the documentation and/or other materials provided with the
-# distribution.
-#     * Neither the name of Google Inc. nor the names of its
-# contributors may be used to endorse or promote products derived from
-# this software without specific prior written permission.
-# 
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-# ---
-# Author: Craig Silverstein
-#
-# Runs the 4 profiler unittests and makes sure their profiles look
-# appropriate.  We expect two commandline args, as described below.
-#
-# We run under the assumption that if $PROFILER1 is run with no
-# arguments, it prints a usage line of the form
-#   USAGE: <actual executable being run> [...]
-#
-# This is because libtool sometimes turns the 'executable' into a
-# shell script which runs an actual binary somewhere else.
-
-# We expect BINDIR and PPROF_PATH to be set in the environment.
-# If not, we set them to some reasonable values
-BINDIR="${BINDIR:-.}"
-PPROF_PATH="${PPROF_PATH:-$BINDIR/src/pprof}"
-
-if [ "x$1" = "x-h" -o "x$1" = "x--help" ]; then
-  echo "USAGE: $0 [unittest dir] [path to pprof]"
-  echo "       By default, unittest_dir=$BINDIR, pprof_path=$PPROF_PATH"
-  exit 1
-fi
-
-TMPDIR=/tmp/profile_info
-
-UNITTEST_DIR=${1:-$BINDIR}
-PPROF=${2:-$PPROF_PATH}
-
-# We test the sliding-window functionality of the cpu-profile reader
-# by using a small stride, forcing lots of reads.
-PPROF_FLAGS="--test_stride=128"
-
-PROFILER1="$UNITTEST_DIR/profiler1_unittest"
-PROFILER2="$UNITTEST_DIR/profiler2_unittest"
-PROFILER3="$UNITTEST_DIR/profiler3_unittest"
-PROFILER4="$UNITTEST_DIR/profiler4_unittest"
-
-# Unfortunately, for us, libtool can replace executables with a shell
-# script that does some work before calling the 'real' executable
-# under a different name.  We need the 'real' executable name to run
-# pprof on it.  We've constructed all the binaries used in this
-# unittest so when they are called with no arguments, they report
-# their argv[0], which is the real binary name.
-Realname() {
-  "$1" 2>&1 | awk '{print $2; exit;}'
-}
-
-PROFILER1_REALNAME=`Realname "$PROFILER1"`
-PROFILER2_REALNAME=`Realname "$PROFILER2"`
-PROFILER3_REALNAME=`Realname "$PROFILER3"`
-PROFILER4_REALNAME=`Realname "$PROFILER4"`
-
-# It's meaningful to the profiler, so make sure we know its state
-unset CPUPROFILE
-
-# Some output/logging in the profiler can cause issues when running the unit
-# tests. For example, logging a warning when the profiler is detected as being
-# present but no CPUPROFILE is specified in the environment. Especially when
-# we are checking for a silent run or specific timing constraints are being
-# checked. So set the env variable signifying that we are running in a unit
-# test environment.
-PERFTOOLS_UNITTEST=1 
-
-rm -rf "$TMPDIR"
-mkdir "$TMPDIR" || exit 2
-
-num_failures=0
-
-RegisterFailure() {
-  num_failures=`expr $num_failures + 1`
-}
-
-# Takes two filenames representing profiles, with their executable scripts,
-# and a multiplier, and verifies that the 'contentful' functions in each
-# profile take the same time (possibly scaled by the given multiplier). It
-# used to be "same" meant within 50%, after adding an noise-reducing X units
-# to each value.  But even that would often spuriously fail, so now it's
-# "both non-zero". We're pretty forgiving.
-VerifySimilar() {
-  prof1="$TMPDIR/$1"
-  exec1="$2"
-  prof2="$TMPDIR/$3"
-  exec2="$4"
-  mult="$5"
-
-  # We are careful not to put exec1 and exec2 in quotes, because if
-  # they are the empty string, it means we want to use the 1-arg
-  # version of pprof.
-  mthread1=`"$PPROF" $PPROF_FLAGS $exec1 "$prof1" | grep test_main_thread | awk '{print $1}'`
-  mthread2=`"$PPROF" $PPROF_FLAGS $exec2 "$prof2" | grep test_main_thread | awk '{print $1}'`
-  mthread1_plus=`expr $mthread1 + 5`
-  mthread2_plus=`expr $mthread2 + 5`
-  if [ -z "$mthread1" ] || [ -z "$mthread2" ] || \
-     [ "$mthread1" -le 0 -o "$mthread2" -le 0 ]
-#    || [ `expr $mthread1_plus \* $mult` -gt `expr $mthread2_plus \* 2` -o \
-#         `expr $mthread1_plus \* $mult \* 2` -lt `expr $mthread2_plus` ]
-  then
-    echo
-    echo ">>> profile on $exec1 vs $exec2 with multiplier $mult failed:"
-    echo "Actual times (in profiling units) were '$mthread1' vs. '$mthread2'"
-    echo
-    RegisterFailure
-  fi
-}
-
-# Takes two filenames representing profiles, and optionally their
-# executable scripts (these may be empty if the profiles include
-# symbols), and verifies that the two profiles are identical.
-VerifyIdentical() {
-  prof1="$TMPDIR/$1"
-  exec1="$2"
-  prof2="$TMPDIR/$3"
-  exec2="$4"
-
-  # We are careful not to put exec1 and exec2 in quotes, because if
-  # they are the empty string, it means we want to use the 1-arg
-  # version of pprof.
-  "$PPROF" $PPROF_FLAGS $exec1 "$prof1" > "$TMPDIR/out1"
-  "$PPROF" $PPROF_FLAGS $exec2 "$prof2" > "$TMPDIR/out2"
-  diff=`diff "$TMPDIR/out1" "$TMPDIR/out2"`
-
-  if [ ! -z "$diff" ]; then
-    echo
-    echo ">>> profile doesn't match, args: $exec1 $prof1 vs. $exec2 $prof2"
-    echo ">>> Diff:"
-    echo "$diff"
-    echo
-    RegisterFailure
-  fi
-}
-
-# Takes a filename representing a profile, with its executable,
-# and a multiplier, and verifies that the main-thread function takes
-# the same amount of time as the other-threads function (possibly scaled
-# by the given multiplier).  Figuring out the multiplier can be tricky,
-# since by design the main thread runs twice as long as each of the
-# 'other' threads!  It used to be "same" meant within 50%, after adding an 
-# noise-reducing X units to each value.  But even that would often
-# spuriously fail, so now it's "both non-zero".  We're pretty forgiving.
-VerifyAcrossThreads() {
-  prof1="$TMPDIR/$1"
-  # We need to run the script with no args to get the actual exe name
-  exec1="$2"
-  mult="$3"
-
-  # We are careful not to put exec1 in quotes, because if it is the
-  # empty string, it means we want to use the 1-arg version of pprof.
-  mthread=`$PPROF $PPROF_FLAGS $exec1 "$prof1" | grep test_main_thread | awk '{print $1}'`
-  othread=`$PPROF $PPROF_FLAGS $exec1 "$prof1" | grep test_other_thread | awk '{print $1}'`
-  if [ -z "$mthread" ] || [ -z "$othread" ] || \
-     [ "$mthread" -le 0 -o "$othread" -le 0 ]
-#    || [ `expr $mthread \* $mult \* 3` -gt `expr $othread \* 10` -o \
-#         `expr $mthread \* $mult \* 10` -lt `expr $othread \* 3` ]
-  then
-    echo
-    echo ">>> profile on $exec1 (main vs thread) with multiplier $mult failed:"
-    echo "Actual times (in profiling units) were '$mthread' vs. '$othread'"
-    echo
-    RegisterFailure
-  fi
-}
-
-echo
-echo ">>> WARNING <<<"
-echo "This test looks at timing information to determine correctness."
-echo "If your system is loaded, the test may spuriously fail."
-echo "If the test does fail with an 'Actual times' error, try running again."
-echo
-
-# profiler1 is a non-threaded version
-"$PROFILER1" 50 1 "$TMPDIR/p1" || RegisterFailure
-"$PROFILER1" 100 1 "$TMPDIR/p2" || RegisterFailure
-VerifySimilar p1 "$PROFILER1_REALNAME" p2 "$PROFILER1_REALNAME" 2
-
-# Verify the same thing works if we statically link
-"$PROFILER2" 50 1 "$TMPDIR/p3" || RegisterFailure
-"$PROFILER2" 100 1 "$TMPDIR/p4" || RegisterFailure
-VerifySimilar p3 "$PROFILER2_REALNAME" p4 "$PROFILER2_REALNAME" 2
-
-# Verify the same thing works if we specify via CPUPROFILE
-CPUPROFILE="$TMPDIR/p5" "$PROFILER2" 50 || RegisterFailure
-CPUPROFILE="$TMPDIR/p6" "$PROFILER2" 100 || RegisterFailure
-VerifySimilar p5 "$PROFILER2_REALNAME" p6 "$PROFILER2_REALNAME" 2
-
-CPUPROFILE="$TMPDIR/p5b" "$PROFILER3" 30 || RegisterFailure
-CPUPROFILE="$TMPDIR/p5c" "$PROFILER3" 60 || RegisterFailure
-VerifySimilar p5b "$PROFILER3_REALNAME" p5c "$PROFILER3_REALNAME" 2
-
-# Now try what happens when we use threads
-"$PROFILER3" 30 2 "$TMPDIR/p7" || RegisterFailure
-"$PROFILER3" 60 2 "$TMPDIR/p8" || RegisterFailure
-VerifySimilar p7 "$PROFILER3_REALNAME" p8 "$PROFILER3_REALNAME" 2
-
-"$PROFILER4" 30 2 "$TMPDIR/p9" || RegisterFailure
-"$PROFILER4" 60 2 "$TMPDIR/p10" || RegisterFailure
-VerifySimilar p9 "$PROFILER4_REALNAME" p10 "$PROFILER4_REALNAME" 2
-
-# More threads!
-"$PROFILER4" 25 3 "$TMPDIR/p9" || RegisterFailure
-"$PROFILER4" 50 3 "$TMPDIR/p10" || RegisterFailure
-VerifySimilar p9 "$PROFILER4_REALNAME" p10 "$PROFILER4_REALNAME" 2
-
-# Compare how much time the main thread takes compared to the other threads
-# Recall the main thread runs twice as long as the other threads, by design.
-"$PROFILER4" 20 4 "$TMPDIR/p11" || RegisterFailure
-VerifyAcrossThreads p11 "$PROFILER4_REALNAME" 2
-
-# Test symbol save and restore
-"$PROFILER1" 50 1 "$TMPDIR/p12" || RegisterFailure
-"$PPROF" $PPROF_FLAGS "$PROFILER1_REALNAME" "$TMPDIR/p12" --raw \
-    >"$TMPDIR/p13" 2>/dev/null || RegisterFailure
-VerifyIdentical p12 "$PROFILER1_REALNAME" p13 "" || RegisterFailure
-
-"$PROFILER3" 30 2 "$TMPDIR/p14" || RegisterFailure
-"$PPROF" $PPROF_FLAGS "$PROFILER3_REALNAME" "$TMPDIR/p14" --raw \
-    >"$TMPDIR/p15" 2>/dev/null || RegisterFailure
-VerifyIdentical p14 "$PROFILER3_REALNAME" p15 "" || RegisterFailure
-
-# Test using ITIMER_REAL instead of ITIMER_PROF.
-env CPUPROFILE_REALTIME=1 "$PROFILER3" 30 2 "$TMPDIR/p16" || RegisterFailure
-env CPUPROFILE_REALTIME=1 "$PROFILER3" 60 2 "$TMPDIR/p17" || RegisterFailure
-VerifySimilar p16 "$PROFILER3_REALNAME" p17 "$PROFILER3_REALNAME" 2
-
-
-# Make sure that when we have a process with a fork, the profiles don't
-# clobber each other
-CPUPROFILE="$TMPDIR/pfork" "$PROFILER1" 1 -2 || RegisterFailure
-n=`ls $TMPDIR/pfork* | wc -l`
-if [ $n != 3 ]; then
-  echo "FORK test FAILED: expected 3 profiles (for main + 2 children), found $n"
-  num_failures=`expr $num_failures + 1`
-fi
-
-rm -rf "$TMPDIR"      # clean up
-
-echo "Tests finished with $num_failures failures"
-exit $num_failures

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b249eb11/third_party/gperftools/src/tests/raw_printer_test.cc
----------------------------------------------------------------------
diff --git a/third_party/gperftools/src/tests/raw_printer_test.cc b/third_party/gperftools/src/tests/raw_printer_test.cc
deleted file mode 100644
index 2c7be6a..0000000
--- a/third_party/gperftools/src/tests/raw_printer_test.cc
+++ /dev/null
@@ -1,64 +0,0 @@
-// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
-// Copyright 2009 Google Inc. All Rights Reserved.
-// Author: sanjay@google.com (Sanjay Ghemawat)
-//
-// Use of this source code is governed by a BSD-style license that can
-// be found in the LICENSE file.
-
-#include "raw_printer.h"
-#include <stdio.h>
-#include <string>
-#include "base/logging.h"
-
-using std::string;
-
-#define TEST(a, b)  void TEST_##a##_##b()
-#define RUN_TEST(a, b)  TEST_##a##_##b()
-
-TEST(RawPrinter, Empty) {
-  char buffer[1];
-  base::RawPrinter printer(buffer, arraysize(buffer));
-  CHECK_EQ(0, printer.length());
-  CHECK_EQ(string(""), buffer);
-  CHECK_EQ(0, printer.space_left());
-  printer.Printf("foo");
-  CHECK_EQ(string(""), string(buffer));
-  CHECK_EQ(0, printer.length());
-  CHECK_EQ(0, printer.space_left());
-}
-
-TEST(RawPrinter, PartiallyFilled) {
-  char buffer[100];
-  base::RawPrinter printer(buffer, arraysize(buffer));
-  printer.Printf("%s %s", "hello", "world");
-  CHECK_EQ(string("hello world"), string(buffer));
-  CHECK_EQ(11, printer.length());
-  CHECK_LT(0, printer.space_left());
-}
-
-TEST(RawPrinter, Truncated) {
-  char buffer[3];
-  base::RawPrinter printer(buffer, arraysize(buffer));
-  printer.Printf("%d", 12345678);
-  CHECK_EQ(string("12"), string(buffer));
-  CHECK_EQ(2, printer.length());
-  CHECK_EQ(0, printer.space_left());
-}
-
-TEST(RawPrinter, ExactlyFilled) {
-  char buffer[12];
-  base::RawPrinter printer(buffer, arraysize(buffer));
-  printer.Printf("%s %s", "hello", "world");
-  CHECK_EQ(string("hello world"), string(buffer));
-  CHECK_EQ(11, printer.length());
-  CHECK_EQ(0, printer.space_left());
-}
-
-int main(int argc, char **argv) {
-  RUN_TEST(RawPrinter, Empty);
-  RUN_TEST(RawPrinter, PartiallyFilled);
-  RUN_TEST(RawPrinter, Truncated);
-  RUN_TEST(RawPrinter, ExactlyFilled);
-  printf("PASS\n");
-  return 0;   // 0 means success
-}

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b249eb11/third_party/gperftools/src/tests/realloc_unittest.cc
----------------------------------------------------------------------
diff --git a/third_party/gperftools/src/tests/realloc_unittest.cc b/third_party/gperftools/src/tests/realloc_unittest.cc
deleted file mode 100644
index e3d7b59..0000000
--- a/third_party/gperftools/src/tests/realloc_unittest.cc
+++ /dev/null
@@ -1,125 +0,0 @@
-// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
-// Copyright (c) 2004, Google Inc.
-// All rights reserved.
-// 
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-// 
-//     * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-//     * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-//     * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// Author: Sanjay Ghemawat
-//
-// Test realloc() functionality
-
-#include "config_for_unittests.h"
-#include <assert.h>                     // for assert
-#include <stdio.h>
-#include <stddef.h>                     // for size_t, NULL
-#include <stdlib.h>                     // for free, malloc, realloc
-#include <algorithm>                    // for min
-#include "base/logging.h"
-
-using std::min;
-
-
-// Fill a buffer of the specified size with a predetermined pattern
-static void Fill(unsigned char* buffer, int n) {
-  for (int i = 0; i < n; i++) {
-    buffer[i] = (i & 0xff);
-  }
-}
-
-// Check that the specified buffer has the predetermined pattern
-// generated by Fill()
-static bool Valid(unsigned char* buffer, int n) {
-  for (int i = 0; i < n; i++) {
-    if (buffer[i] != (i & 0xff)) {
-      return false;
-    }
-  }
-  return true;
-}
-
-// Return the next interesting size/delta to check.  Returns -1 if no more.
-static int NextSize(int size) {
-  if (size < 100) {
-    return size+1;
-  } else if (size < 100000) {
-    // Find next power of two
-    int power = 1;
-    while (power < size) {
-      power <<= 1;
-    }
-
-    // Yield (power-1, power, power+1)
-    if (size < power-1) {
-      return power-1;
-    } else if (size == power-1) {
-      return power;
-    } else {
-      assert(size == power);
-      return power+1;
-    }
-  } else {
-    return -1;
-  }
-}
-
-int main(int argc, char** argv) {
-  for (int src_size = 0; src_size >= 0; src_size = NextSize(src_size)) {
-    for (int dst_size = 0; dst_size >= 0; dst_size = NextSize(dst_size)) {
-      unsigned char* src = (unsigned char*) malloc(src_size);
-      Fill(src, src_size);
-      unsigned char* dst = (unsigned char*) realloc(src, dst_size);
-      CHECK(Valid(dst, min(src_size, dst_size)));
-      Fill(dst, dst_size);
-      CHECK(Valid(dst, dst_size));
-      if (dst != NULL) free(dst);
-    }
-  }
-
-  // Now make sure realloc works correctly even when we overflow the
-  // packed cache, so some entries are evicted from the cache.
-  // The cache has 2^12 entries, keyed by page number.
-  const int kNumEntries = 1 << 14;
-  int** p = (int**)malloc(sizeof(*p) * kNumEntries);
-  int sum = 0;
-  for (int i = 0; i < kNumEntries; i++) {
-    p[i] = (int*)malloc(8192);   // no page size is likely to be bigger
-    p[i][1000] = i;              // use memory deep in the heart of p
-  }
-  for (int i = 0; i < kNumEntries; i++) {
-    p[i] = (int*)realloc(p[i], 9000);
-  }
-  for (int i = 0; i < kNumEntries; i++) {
-    sum += p[i][1000];
-    free(p[i]);
-  }
-  CHECK_EQ(kNumEntries/2 * (kNumEntries - 1), sum);  // assume kNE is even
-  free(p);
-
-  printf("PASS\n");
-  return 0;
-}

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/b249eb11/third_party/gperftools/src/tests/sampler_test.cc
----------------------------------------------------------------------
diff --git a/third_party/gperftools/src/tests/sampler_test.cc b/third_party/gperftools/src/tests/sampler_test.cc
deleted file mode 100755
index cd64b0f..0000000
--- a/third_party/gperftools/src/tests/sampler_test.cc
+++ /dev/null
@@ -1,658 +0,0 @@
-// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-
-// Copyright (c) 2008, Google Inc.
-// All rights reserved.
-// 
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-// 
-//     * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-//     * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-//     * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// ---
-// All Rights Reserved.
-//
-// Author: Daniel Ford
-//
-// Checks basic properties of the sampler
-
-#include "config_for_unittests.h"
-#include <stdlib.h>        // defines posix_memalign
-#include <stdio.h>         // for the printf at the end
-#if defined HAVE_STDINT_H
-#include <stdint.h>             // to get uintptr_t
-#elif defined HAVE_INTTYPES_H
-#include <inttypes.h>           // another place uintptr_t might be defined
-#endif
-#include <sys/types.h>
-#include <iostream>
-#include <algorithm>
-#include <vector>
-#include <string>
-#include <cmath>
-#include "base/logging.h"
-#include "base/commandlineflags.h"
-#include "sampler.h"       // The Sampler class being tested
-
-using std::sort;
-using std::min;
-using std::max;
-using std::vector;
-using std::abs;
-
-vector<void (*)()> g_testlist;  // the tests to run
-
-#define TEST(a, b)                                      \
-  struct Test_##a##_##b {                               \
-    Test_##a##_##b() { g_testlist.push_back(&Run); }    \
-    static void Run();                                  \
-  };                                                    \
-  static Test_##a##_##b g_test_##a##_##b;               \
-  void Test_##a##_##b::Run()
-
-
-static int RUN_ALL_TESTS() {
-  vector<void (*)()>::const_iterator it;
-  for (it = g_testlist.begin(); it != g_testlist.end(); ++it) {
-    (*it)();   // The test will error-exit if there's a problem.
-  }
-  fprintf(stderr, "\nPassed %d tests\n\nPASS\n", (int)g_testlist.size());
-  return 0;
-}
-
-#undef LOG   // defined in base/logging.h
-// Ideally, we'd put the newline at the end, but this hack puts the
-// newline at the end of the previous log message, which is good enough :-)
-#define LOG(level)  std::cerr << "\n"
-
-static std::string StringPrintf(const char* format, ...) {
-  char buf[256];   // should be big enough for all logging
-  va_list ap;
-  va_start(ap, format);
-  perftools_vsnprintf(buf, sizeof(buf), format, ap);
-  va_end(ap);
-  return buf;
-}
-
-namespace {
-template<typename T> class scoped_array {
- public:
-  scoped_array(T* p) : p_(p) { }
-  ~scoped_array() { delete[] p_; }
-  const T* get() const { return p_; }
-  T* get() { return p_; }
-  T& operator[](int i) { return p_[i]; }
- private:
-  T* p_;
-};
-}
-
-// Note that these tests are stochastic.
-// This mean that the chance of correct code passing the test is,
-// in the case of 5 standard deviations:
-// kSigmas=5:    ~99.99994267%
-// in the case of 4 standard deviations:
-// kSigmas=4:    ~99.993666%
-static const double kSigmas = 4;
-static const size_t kSamplingInterval = 512*1024;
-
-// Tests that GetSamplePeriod returns the expected value
-// which is 1<<19
-TEST(Sampler, TestGetSamplePeriod) {
-  tcmalloc::Sampler sampler;
-  sampler.Init(1);
-  uint64_t sample_period;
-  sample_period = sampler.GetSamplePeriod();
-  CHECK_GT(sample_period, 0);
-}
-
-// Tests of the quality of the random numbers generated
-// This uses the Anderson Darling test for uniformity.
-// See "Evaluating the Anderson-Darling Distribution" by Marsaglia
-// for details.
-
-// Short cut version of ADinf(z), z>0 (from Marsaglia)
-// This returns the p-value for Anderson Darling statistic in
-// the limit as n-> infinity. For finite n, apply the error fix below.
-double AndersonDarlingInf(double z) {
-  if (z < 2) {
-    return exp(-1.2337141 / z) / sqrt(z) * (2.00012 + (0.247105 -
-                (0.0649821 - (0.0347962 - (0.011672 - 0.00168691
-                * z) * z) * z) * z) * z);
-  }
-  return exp( - exp(1.0776 - (2.30695 - (0.43424 - (0.082433 -
-                    (0.008056 - 0.0003146 * z) * z) * z) * z) * z));
-}
-
-// Corrects the approximation error in AndersonDarlingInf for small values of n
-// Add this to AndersonDarlingInf to get a better approximation
-// (from Marsaglia)
-double AndersonDarlingErrFix(int n, double x) {
-  if (x > 0.8) {
-    return (-130.2137 + (745.2337 - (1705.091 - (1950.646 -
-            (1116.360 - 255.7844 * x) * x) * x) * x) * x) / n;
-  }
-  double cutoff = 0.01265 + 0.1757 / n;
-  double t;
-  if (x < cutoff) {
-    t = x / cutoff;
-    t = sqrt(t) * (1 - t) * (49 * t - 102);
-    return t * (0.0037 / (n * n) + 0.00078 / n + 0.00006) / n;
-  } else {
-    t = (x - cutoff) / (0.8 - cutoff);
-    t = -0.00022633 + (6.54034 - (14.6538 - (14.458 - (8.259 - 1.91864
-          * t) * t) * t) * t) * t;
-    return t * (0.04213 + 0.01365 / n) / n;
-  }
-}
-
-// Returns the AndersonDarling p-value given n and the value of the statistic
-double AndersonDarlingPValue(int n, double z) {
-  double ad = AndersonDarlingInf(z);
-  double errfix = AndersonDarlingErrFix(n, ad);
-  return ad + errfix;
-}
-
-double AndersonDarlingStatistic(int n, double* random_sample) {
-  double ad_sum = 0;
-  for (int i = 0; i < n; i++) {
-    ad_sum += (2*i + 1) * log(random_sample[i] * (1 - random_sample[n-1-i]));
-  }
-  double ad_statistic = - n - 1/static_cast<double>(n) * ad_sum;
-  return ad_statistic;
-}
-
-// Tests if the array of doubles is uniformly distributed.
-// Returns the p-value of the Anderson Darling Statistic
-// for the given set of sorted random doubles
-// See "Evaluating the Anderson-Darling Distribution" by
-// Marsaglia and Marsaglia for details.
-double AndersonDarlingTest(int n, double* random_sample) {
-  double ad_statistic = AndersonDarlingStatistic(n, random_sample);
-  LOG(INFO) << StringPrintf("AD stat = %f, n=%d\n", ad_statistic, n);
-  double p = AndersonDarlingPValue(n, ad_statistic);
-  return p;
-}
-
-// Test the AD Test. The value of the statistic should go to zero as n->infty
-// Not run as part of regular tests
-void ADTestTest(int n) {
-  scoped_array<double> random_sample(new double[n]);
-  for (int i = 0; i < n; i++) {
-    random_sample[i] = (i+0.01)/n;
-  }
-  sort(random_sample.get(), random_sample.get() + n);
-  double ad_stat = AndersonDarlingStatistic(n, random_sample.get());
-  LOG(INFO) << StringPrintf("Testing the AD test. n=%d, ad_stat = %f",
-                            n, ad_stat);
-}
-
-// Print the CDF of the distribution of the Anderson-Darling Statistic
-// Used for checking the Anderson-Darling Test
-// Not run as part of regular tests
-void ADCDF() {
-  for (int i = 1; i < 40; i++) {
-    double x = i/10.0;
-    LOG(INFO) << "x= " << x << "  adpv= "
-              << AndersonDarlingPValue(100, x) << ", "
-              << AndersonDarlingPValue(1000, x);
-  }
-}
-
-// Testing that NextRandom generates uniform
-// random numbers.
-// Applies the Anderson-Darling test for uniformity
-void TestNextRandom(int n) {
-  tcmalloc::Sampler sampler;
-  sampler.Init(1);
-  uint64_t x = 1;
-  // This assumes that the prng returns 48 bit numbers
-  uint64_t max_prng_value = static_cast<uint64_t>(1)<<48;
-  // Initialize
-  for (int i = 1; i <= 20; i++) {  // 20 mimics sampler.Init()
-    x = sampler.NextRandom(x);
-  }
-  scoped_array<uint64_t> int_random_sample(new uint64_t[n]);
-  // Collect samples
-  for (int i = 0; i < n; i++) {
-    int_random_sample[i] = x;
-    x = sampler.NextRandom(x);
-  }
-  // First sort them...
-  sort(int_random_sample.get(), int_random_sample.get() + n);
-  scoped_array<double> random_sample(new double[n]);
-  // Convert them to uniform randoms (in the range [0,1])
-  for (int i = 0; i < n; i++) {
-    random_sample[i] = static_cast<double>(int_random_sample[i])/max_prng_value;
-  }
-  // Now compute the Anderson-Darling statistic
-  double ad_pvalue = AndersonDarlingTest(n, random_sample.get());
-  LOG(INFO) << StringPrintf("pvalue for AndersonDarlingTest "
-                            "with n= %d is p= %f\n", n, ad_pvalue);
-  CHECK_GT(min(ad_pvalue, 1 - ad_pvalue), 0.0001);
-  //           << StringPrintf("prng is not uniform, %d\n", n);
-}
-
-
-TEST(Sampler, TestNextRandom_MultipleValues) {
-  TestNextRandom(10);  // Check short-range correlation
-  TestNextRandom(100);
-  TestNextRandom(1000);
-  TestNextRandom(10000);  // Make sure there's no systematic error
-}
-
-// Tests that PickNextSamplePeriod generates
-// geometrically distributed random numbers.
-// First converts to uniforms then applied the
-// Anderson-Darling test for uniformity.
-void TestPickNextSample(int n) {
-  tcmalloc::Sampler sampler;
-  sampler.Init(1);
-  scoped_array<uint64_t> int_random_sample(new uint64_t[n]);
-  int sample_period = sampler.GetSamplePeriod();
-  int ones_count = 0;
-  for (int i = 0; i < n; i++) {
-    int_random_sample[i] = sampler.PickNextSamplingPoint();
-    CHECK_GE(int_random_sample[i], 1);
-    if (int_random_sample[i] == 1) {
-      ones_count += 1;
-    }
-    CHECK_LT(ones_count, 4); // << " out of " << i << " samples.";
-  }
-  // First sort them...
-  sort(int_random_sample.get(), int_random_sample.get() + n);
-  scoped_array<double> random_sample(new double[n]);
-  // Convert them to uniform random numbers
-  // by applying the geometric CDF
-  for (int i = 0; i < n; i++) {
-    random_sample[i] = 1 - exp(-static_cast<double>(int_random_sample[i])
-                           / sample_period);
-  }
-  // Now compute the Anderson-Darling statistic
-  double geom_ad_pvalue = AndersonDarlingTest(n, random_sample.get());
-  LOG(INFO) << StringPrintf("pvalue for geometric AndersonDarlingTest "
-                             "with n= %d is p= %f\n", n, geom_ad_pvalue);
-  CHECK_GT(min(geom_ad_pvalue, 1 - geom_ad_pvalue), 0.0001);
-      //          << "PickNextSamplingPoint does not produce good "
-      //             "geometric/exponential random numbers\n";
-}
-
-TEST(Sampler, TestPickNextSample_MultipleValues) {
-  TestPickNextSample(10);  // Make sure the first few are good (enough)
-  TestPickNextSample(100);
-  TestPickNextSample(1000);
-  TestPickNextSample(10000);  // Make sure there's no systematic error
-}
-
-
-// This is superceeded by the Anderson-Darling Test
-// and it not run now.
-// Tests how fast nearby values are spread out with  LRand64
-// The purpose of this code is to determine how many
-// steps to apply to the seed during initialization
-void TestLRand64Spread() {
-  tcmalloc::Sampler sampler;
-  sampler.Init(1);
-  uint64_t current_value;
-  printf("Testing LRand64 Spread\n");
-  for (int i = 1; i < 10; i++) {
-    printf("%d ", i);
-    current_value = i;
-    for (int j = 1; j < 100; j++) {
-      current_value = sampler.NextRandom(current_value);
-    }
-    LOG(INFO) << current_value;
-  }
-}
-
-
-// Test for Fastlog2 code
-// We care about the percentage error because we're using this
-// for choosing step sizes, so "close" is relative to the size of
-// the step we would get if we used the built-in log function
-TEST(Sampler, FastLog2) {
-  tcmalloc::Sampler sampler;
-  sampler.Init(1);
-  double max_ratio_error = 0;
-  for (double d = -1021.9; d < 1; d+= 0.13124235) {
-    double e = pow(2.0, d);
-    double truelog = log(e) / log(2.0);  // log_2(e)
-    double fastlog = sampler.FastLog2(e);
-    max_ratio_error = max(max_ratio_error,
-                          max(truelog/fastlog-1, fastlog/truelog-1));
-    CHECK_LE(max_ratio_error, 0.01);
-        //        << StringPrintf("d = %f, e=%f, truelog = %f, fastlog= %f\n",
-        //                        d, e, truelog, fastlog);
-  }
-  LOG(INFO) << StringPrintf("Fastlog2: max_ratio_error = %f\n",
-                            max_ratio_error);
-}
-
-// Futher tests
-
-bool CheckMean(size_t mean, int num_samples) {
-  tcmalloc::Sampler sampler;
-  sampler.Init(1);
-  size_t total = 0;
-  for (int i = 0; i < num_samples; i++) {
-    total += sampler.PickNextSamplingPoint();
-  }
-  double empirical_mean = total / static_cast<double>(num_samples);
-  double expected_sd = mean / pow(num_samples * 1.0, 0.5);
-  return(fabs(mean-empirical_mean) < expected_sd * kSigmas);
-}
-
-// Prints a sequence so you can look at the distribution
-void OutputSequence(int sequence_length) {
-  tcmalloc::Sampler sampler;
-  sampler.Init(1);
-  size_t next_step;
-  for (int i = 0; i< sequence_length; i++) {
-    next_step = sampler.PickNextSamplingPoint();
-    LOG(INFO) << next_step;
-  }
-}
-
-
-double StandardDeviationsErrorInSample(
-              int total_samples, int picked_samples,
-              int alloc_size, int sampling_interval) {
-  double p = 1 - exp(-(static_cast<double>(alloc_size) / sampling_interval));
-  double expected_samples = total_samples * p;
-  double sd = pow(p*(1-p)*total_samples, 0.5);
-  return((picked_samples - expected_samples) / sd);
-}
-
-TEST(Sampler, LargeAndSmallAllocs_CombinedTest) {
-  tcmalloc::Sampler sampler;
-  sampler.Init(1);
-  int counter_big = 0;
-  int counter_small = 0;
-  int size_big = 129*8*1024+1;
-  int size_small = 1024*8;
-  int num_iters = 128*4*8;
-  // Allocate in mixed chunks
-  for (int i = 0; i < num_iters; i++) {
-    if (sampler.SampleAllocation(size_big)) {
-      counter_big += 1;
-    }
-    for (int i = 0; i < 129; i++) {
-      if (sampler.SampleAllocation(size_small)) {
-        counter_small += 1;
-      }
-    }
-  }
-  // Now test that there are the right number of each
-  double large_allocs_sds =
-     StandardDeviationsErrorInSample(num_iters, counter_big,
-                                     size_big, kSamplingInterval);
-  double small_allocs_sds =
-     StandardDeviationsErrorInSample(num_iters*129, counter_small,
-                                     size_small, kSamplingInterval);
-  LOG(INFO) << StringPrintf("large_allocs_sds = %f\n", large_allocs_sds);
-  LOG(INFO) << StringPrintf("small_allocs_sds = %f\n", small_allocs_sds);
-  CHECK_LE(fabs(large_allocs_sds), kSigmas);
-  CHECK_LE(fabs(small_allocs_sds), kSigmas);
-}
-
-// Tests whether the mean is about right over 1000 samples
-TEST(Sampler, IsMeanRight) {
-  CHECK(CheckMean(kSamplingInterval, 1000));
-}
-
-// This flag is for the OldSampler class to use
-const int64 FLAGS_mock_tcmalloc_sample_parameter = 1<<19;
-
-// A cut down and slightly refactored version of the old Sampler
-class OldSampler {
- public:
-  void Init(uint32_t seed);
-  void Cleanup() {}
-
-  // Record allocation of "k" bytes.  Return true iff allocation
-  // should be sampled
-  bool SampleAllocation(size_t k);
-
-  // Generate a geometric with mean 1M (or FLAG value)
-  void PickNextSample(size_t k);
-
-  // Initialize the statics for the Sample class
-  static void InitStatics() {
-    sample_period = 1048583;
-  }
-  size_t bytes_until_sample_;
-
- private:
-  uint32_t rnd_;                   // Cheap random number generator
-  static uint64_t sample_period;
-  // Should be a prime just above a power of 2:
-  // 2, 5, 11, 17, 37, 67, 131, 257,
-  // 521, 1031, 2053, 4099, 8209, 16411,
-  // 32771, 65537, 131101, 262147, 524309, 1048583,
-  // 2097169, 4194319, 8388617, 16777259, 33554467
-};
-
-// Statics for OldSampler
-uint64_t OldSampler::sample_period;
-
-void OldSampler::Init(uint32_t seed) {
-  // Initialize PRNG -- run it for a bit to get to good values
-  if (seed != 0) {
-    rnd_ = seed;
-  } else {
-    rnd_ = 12345;
-  }
-  bytes_until_sample_ = 0;
-  for (int i = 0; i < 100; i++) {
-    PickNextSample(sample_period * 2);
-  }
-};
-
-// A cut-down version of the old PickNextSampleRoutine
-void OldSampler::PickNextSample(size_t k) {
-  // Make next "random" number
-  // x^32+x^22+x^2+x^1+1 is a primitive polynomial for random numbers
-  static const uint32_t kPoly = (1 << 22) | (1 << 2) | (1 << 1) | (1 << 0);
-  uint32_t r = rnd_;
-  rnd_ = (r << 1) ^ ((static_cast<int32_t>(r) >> 31) & kPoly);
-
-  // Next point is "rnd_ % (sample_period)".  I.e., average
-  // increment is "sample_period/2".
-  const int flag_value = FLAGS_mock_tcmalloc_sample_parameter;
-  static int last_flag_value = -1;
-
-  if (flag_value != last_flag_value) {
-    // There should be a spinlock here, but this code is
-    // for benchmarking only.
-    sample_period = 1048583;
-    last_flag_value = flag_value;
-  }
-
-  bytes_until_sample_ += rnd_ % sample_period;
-
-  if (k > (static_cast<size_t>(-1) >> 2)) {
-    // If the user has asked for a huge allocation then it is possible
-    // for the code below to loop infinitely.  Just return (note that
-    // this throws off the sampling accuracy somewhat, but a user who
-    // is allocating more than 1G of memory at a time can live with a
-    // minor inaccuracy in profiling of small allocations, and also
-    // would rather not wait for the loop below to terminate).
-    return;
-  }
-
-  while (bytes_until_sample_ < k) {
-    // Increase bytes_until_sample_ by enough average sampling periods
-    // (sample_period >> 1) to allow us to sample past the current
-    // allocation.
-    bytes_until_sample_ += (sample_period >> 1);
-  }
-
-  bytes_until_sample_ -= k;
-}
-
-inline bool OldSampler::SampleAllocation(size_t k) {
-  if (bytes_until_sample_ < k) {
-    PickNextSample(k);
-    return true;
-  } else {
-    bytes_until_sample_ -= k;
-    return false;
-  }
-}
-
-// This checks that the stated maximum value for the
-// tcmalloc_sample_parameter flag never overflows bytes_until_sample_
-TEST(Sampler, bytes_until_sample_Overflow_Underflow) {
-  tcmalloc::Sampler sampler;
-  sampler.Init(1);
-  uint64_t one = 1;
-  // sample_parameter = 0;  // To test the edge case
-  uint64_t sample_parameter_array[4] = {0, 1, one<<19, one<<58};
-  for (int i = 0; i < 4; i++) {
-    uint64_t sample_parameter = sample_parameter_array[i];
-    LOG(INFO) << "sample_parameter = " << sample_parameter;
-    double sample_scaling = - log(2.0) * sample_parameter;
-    // Take the top 26 bits as the random number
-    // (This plus the 1<<26 sampling bound give a max step possible of
-    // 1209424308 bytes.)
-    const uint64_t prng_mod_power = 48;  // Number of bits in prng
-
-    // First, check the largest_prng value
-    uint64_t largest_prng_value = (static_cast<uint64_t>(1)<<48) - 1;
-    double q = (largest_prng_value >> (prng_mod_power - 26)) + 1.0;
-    LOG(INFO) << StringPrintf("q = %f\n", q);
-    LOG(INFO) << StringPrintf("FastLog2(q) = %f\n", sampler.FastLog2(q));
-    LOG(INFO) << StringPrintf("log2(q) = %f\n", log(q)/log(2.0));
-    // Replace min(sampler.FastLog2(q) - 26, 0.0) with
-    // (sampler.FastLog2(q) - 26.000705) when using that optimization
-    uint64_t smallest_sample_step
-        = static_cast<uint64_t>(min(sampler.FastLog2(q) - 26, 0.0)
-                                * sample_scaling + 1);
-    LOG(INFO) << "Smallest sample step is " << smallest_sample_step;
-    uint64_t cutoff = static_cast<uint64_t>(10)
-                      * (sample_parameter/(one<<24) + 1);
-    LOG(INFO) << "Acceptable value is < " << cutoff;
-    // This checks that the answer is "small" and positive
-    CHECK_LE(smallest_sample_step, cutoff);
-
-    // Next, check with the smallest prng value
-    uint64_t smallest_prng_value = 0;
-    q = (smallest_prng_value >> (prng_mod_power - 26)) + 1.0;
-    LOG(INFO) << StringPrintf("q = %f\n", q);
-    // Replace min(sampler.FastLog2(q) - 26, 0.0) with
-    // (sampler.FastLog2(q) - 26.000705) when using that optimization
-    uint64_t largest_sample_step
-        = static_cast<uint64_t>(min(sampler.FastLog2(q) - 26, 0.0)
-                                * sample_scaling + 1);
-    LOG(INFO) << "Largest sample step is " << largest_sample_step;
-    CHECK_LE(largest_sample_step, one<<63);
-    CHECK_GE(largest_sample_step, smallest_sample_step);
-  }
-}
-
-
-// Test that NextRand is in the right range.  Unfortunately, this is a
-// stochastic test which could miss problems.
-TEST(Sampler, NextRand_range) {
-  tcmalloc::Sampler sampler;
-  sampler.Init(1);
-  uint64_t one = 1;
-  // The next number should be (one << 48) - 1
-  uint64_t max_value = (one << 48) - 1;
-  uint64_t x = (one << 55);
-  int n = 22;  // 27;
-  LOG(INFO) << "Running sampler.NextRandom 1<<" << n << " times";
-  for (int i = 1; i <= (1<<n); i++) {  // 20 mimics sampler.Init()
-    x = sampler.NextRandom(x);
-    CHECK_LE(x, max_value);
-  }
-}
-
-// Tests certain arithmetic operations to make sure they compute what we
-// expect them too (for testing across different platforms)
-TEST(Sampler, arithmetic_1) {
-  tcmalloc::Sampler sampler;
-  sampler.Init(1);
-  uint64_t rnd;  // our 48 bit random number, which we don't trust
-  const uint64_t prng_mod_power = 48;
-  uint64_t one = 1;
-  rnd = one;
-  uint64_t max_value = (one << 48) - 1;
-  for (int i = 1; i <= (1>>27); i++) {  // 20 mimics sampler.Init()
-    rnd = sampler.NextRandom(rnd);
-    CHECK_LE(rnd, max_value);
-    double q = (rnd >> (prng_mod_power - 26)) + 1.0;
-    CHECK_GE(q, 0); // << rnd << "  " << prng_mod_power;
-  }
-  // Test some potentially out of bounds value for rnd
-  for (int i = 1; i <= 66; i++) {
-    rnd = one << i;
-    double q = (rnd >> (prng_mod_power - 26)) + 1.0;
-    LOG(INFO) << "rnd = " << rnd << " i=" << i << " q=" << q;
-    CHECK_GE(q, 0);
-    //        << " rnd=" << rnd << "  i=" << i << " prng_mod_power" << prng_mod_power;
-  }
-}
-
-void test_arithmetic(uint64_t rnd) {
-  const uint64_t prng_mod_power = 48;  // Number of bits in prng
-  uint64_t shifted_rnd = rnd >> (prng_mod_power - 26);
-  CHECK_GE(shifted_rnd, 0);
-  CHECK_LT(shifted_rnd, (1<<26));
-  LOG(INFO) << shifted_rnd;
-  LOG(INFO) << static_cast<double>(shifted_rnd);
-  CHECK_GE(static_cast<double>(static_cast<uint32_t>(shifted_rnd)), 0);
-      //      << " rnd=" << rnd << "  srnd=" << shifted_rnd;
-  CHECK_GE(static_cast<double>(shifted_rnd), 0);
-      //      << " rnd=" << rnd << "  srnd=" << shifted_rnd;
-  double q = static_cast<double>(shifted_rnd) + 1.0;
-  CHECK_GT(q, 0);
-}
-
-// Tests certain arithmetic operations to make sure they compute what we
-// expect them too (for testing across different platforms)
-// know bad values under with -c dbg --cpu piii for _some_ binaries:
-// rnd=227453640600554
-// shifted_rnd=54229173
-// (hard to reproduce)
-TEST(Sampler, arithmetic_2) {
-  uint64_t rnd = 227453640600554LL;
-  test_arithmetic(rnd);
-}
-
-
-// It's not really a test, but it's good to know
-TEST(Sample, size_of_class) {
-  tcmalloc::Sampler sampler;
-  sampler.Init(1);
-  LOG(INFO) << "Size of Sampler class is: " << sizeof(tcmalloc::Sampler);
-  LOG(INFO) << "Size of Sampler object is: " << sizeof(sampler);
-}
-
-// Make sure sampling is enabled, or the tests won't work right.
-DECLARE_int64(tcmalloc_sample_parameter);
-
-int main(int argc, char **argv) {
-  if (FLAGS_tcmalloc_sample_parameter == 0)
-    FLAGS_tcmalloc_sample_parameter = 524288;
-  return RUN_ALL_TESTS();
-}



Mime
View raw message