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.

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

mercurial