2014-01-04 01:36:37 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
// Original author: bcampen@mozilla.com
|
|
|
|
|
|
|
|
#ifndef gtest_ringbuffer_dumper_h__
|
|
|
|
#define gtest_ringbuffer_dumper_h__
|
|
|
|
|
|
|
|
#include "mozilla/SyncRunnable.h"
|
|
|
|
|
|
|
|
#define GTEST_HAS_RTTI 0
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2016-02-09 21:02:40 +03:00
|
|
|
#include "mtransport_test_utils.h"
|
2014-01-04 01:36:37 +04:00
|
|
|
#include "runnable_utils.h"
|
2016-10-11 10:17:26 +03:00
|
|
|
#include "rlogconnector.h"
|
2014-01-04 01:36:37 +04:00
|
|
|
|
2016-10-11 10:17:26 +03:00
|
|
|
using mozilla::RLogConnector;
|
2014-01-04 01:36:37 +04:00
|
|
|
using mozilla::WrapRunnable;
|
|
|
|
|
|
|
|
namespace test {
|
|
|
|
class RingbufferDumper : public ::testing::EmptyTestEventListener {
|
|
|
|
public:
|
|
|
|
explicit RingbufferDumper(MtransportTestUtils* test_utils)
|
|
|
|
: test_utils_(test_utils) {}
|
2018-12-14 21:10:35 +03:00
|
|
|
|
2014-01-04 01:36:37 +04:00
|
|
|
void ClearRingBuffer_s() {
|
2016-10-11 10:17:26 +03:00
|
|
|
RLogConnector::CreateInstance();
|
2014-01-04 01:36:37 +04:00
|
|
|
// Set limit to zero to clear the ringbuffer
|
2016-10-11 10:17:26 +03:00
|
|
|
RLogConnector::GetInstance()->SetLogLimit(0);
|
|
|
|
RLogConnector::GetInstance()->SetLogLimit(UINT32_MAX);
|
2018-12-14 21:10:35 +03:00
|
|
|
}
|
|
|
|
|
2016-10-11 10:17:26 +03:00
|
|
|
void DestroyRingBuffer_s() { RLogConnector::DestroyInstance(); }
|
2018-12-14 21:10:35 +03:00
|
|
|
|
2014-01-04 01:36:37 +04:00
|
|
|
void DumpRingBuffer_s() {
|
|
|
|
std::deque<std::string> logs;
|
|
|
|
// Get an unlimited number of log lines, with no filter
|
2016-10-11 10:17:26 +03:00
|
|
|
RLogConnector::GetInstance()->GetAny(0, &logs);
|
2014-01-04 01:36:37 +04:00
|
|
|
for (auto l = logs.begin(); l != logs.end(); ++l) {
|
|
|
|
std::cout << *l << std::endl;
|
|
|
|
}
|
|
|
|
ClearRingBuffer_s();
|
2018-12-14 21:10:35 +03:00
|
|
|
}
|
|
|
|
|
2014-01-04 01:36:37 +04:00
|
|
|
virtual void OnTestStart(const ::testing::TestInfo& testInfo) override {
|
2016-10-11 10:17:26 +03:00
|
|
|
mozilla::SyncRunnable::DispatchToThread(
|
|
|
|
test_utils_->sts_target(),
|
2014-01-04 01:36:37 +04:00
|
|
|
WrapRunnable(this, &RingbufferDumper::ClearRingBuffer_s));
|
|
|
|
}
|
2018-12-14 21:10:35 +03:00
|
|
|
|
2017-11-06 06:37:28 +03:00
|
|
|
virtual void OnTestEnd(const ::testing::TestInfo& testInfo) override {
|
2014-01-04 01:36:37 +04:00
|
|
|
mozilla::SyncRunnable::DispatchToThread(
|
2017-11-06 06:37:28 +03:00
|
|
|
test_utils_->sts_target(),
|
2014-01-04 01:36:37 +04:00
|
|
|
WrapRunnable(this, &RingbufferDumper::DestroyRingBuffer_s));
|
2018-12-14 21:10:35 +03:00
|
|
|
}
|
|
|
|
|
2014-01-04 01:36:37 +04:00
|
|
|
// Called after a failed assertion or a SUCCEED() invocation.
|
2017-11-06 06:37:28 +03:00
|
|
|
virtual void OnTestPartResult(
|
|
|
|
const ::testing::TestPartResult& testResult) override {
|
2014-01-04 01:36:37 +04:00
|
|
|
if (testResult.failed()) {
|
2016-10-11 10:17:26 +03:00
|
|
|
// Dump (and empty) the RLogConnector
|
2014-01-04 01:36:37 +04:00
|
|
|
mozilla::SyncRunnable::DispatchToThread(
|
|
|
|
test_utils_->sts_target(),
|
|
|
|
WrapRunnable(this, &RingbufferDumper::DumpRingBuffer_s));
|
|
|
|
}
|
2018-12-14 21:10:35 +03:00
|
|
|
}
|
2014-01-04 01:36:37 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
MtransportTestUtils* test_utils_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace test
|
|
|
|
|
|
|
|
#endif // gtest_ringbuffer_dumper_h__
|