media/mtransport/test/gtest_ringbuffer_dumper.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim: set ts=2 et sw=2 tw=80: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     5  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 // Original author: bcampen@mozilla.com
     9 #ifndef gtest_ringbuffer_dumper_h__
    10 #define gtest_ringbuffer_dumper_h__
    12 #include "mozilla/SyncRunnable.h"
    14 #define GTEST_HAS_RTTI 0
    15 #include "gtest/gtest.h"
    16 #include "gtest_utils.h"
    18 #include "runnable_utils.h"
    19 #include "rlogringbuffer.h"
    21 using mozilla::RLogRingBuffer;
    22 using mozilla::WrapRunnable;
    24 namespace test {
    25 class RingbufferDumper : public ::testing::EmptyTestEventListener {
    26   public:
    27     explicit RingbufferDumper(MtransportTestUtils* test_utils) :
    28       test_utils_(test_utils)
    29     {}
    31     void ClearRingBuffer_s() {
    32       RLogRingBuffer::CreateInstance();
    33       // Set limit to zero to clear the ringbuffer
    34       RLogRingBuffer::GetInstance()->SetLogLimit(0);
    35       RLogRingBuffer::GetInstance()->SetLogLimit(UINT32_MAX);
    36     }
    38     void DestroyRingBuffer_s() {
    39       RLogRingBuffer::DestroyInstance();
    40     }
    42     void DumpRingBuffer_s() {
    43       std::deque<std::string> logs;
    44       // Get an unlimited number of log lines, with no filter
    45       RLogRingBuffer::GetInstance()->GetAny(0, &logs);
    46       for (auto l = logs.begin(); l != logs.end(); ++l) {
    47         std::cout << *l << std::endl;
    48       }
    49       ClearRingBuffer_s();
    50     }
    52     virtual void OnTestStart(const ::testing::TestInfo& testInfo) {
    53       mozilla::SyncRunnable::DispatchToThread(
    54           test_utils_->sts_target(),
    55           WrapRunnable(this, &RingbufferDumper::ClearRingBuffer_s));
    56     }
    58     virtual void OnTestEnd(const ::testing::TestInfo& testInfo) {
    59       mozilla::SyncRunnable::DispatchToThread(
    60           test_utils_->sts_target(),
    61           WrapRunnable(this, &RingbufferDumper::DestroyRingBuffer_s));
    62     }
    64     // Called after a failed assertion or a SUCCEED() invocation.
    65     virtual void OnTestPartResult(const ::testing::TestPartResult& testResult) {
    66       if (testResult.failed()) {
    67         // Dump (and empty) the RLogRingBuffer
    68         mozilla::SyncRunnable::DispatchToThread(
    69             test_utils_->sts_target(),
    70             WrapRunnable(this, &RingbufferDumper::DumpRingBuffer_s));
    71       }
    72     }
    74   private:
    75     MtransportTestUtils *test_utils_;
    76 };
    78 } // namespace test
    80 #endif // gtest_ringbuffer_dumper_h__

mercurial