tests: in LimitedIo, use std::exception_ptr to avoid slicing
Change-Id: I459792cf80ee189842ada84c3a514134bcd79a29 Refs: #3327
This commit is contained in:
1 parent
f68f378a23
commit
f35a5a9b08
2 files changed
+30
-37
No files matched your search
+16
-25
@@ -1,12 +1,12 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/**
|
||||
* Copyright (c) 2014, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis
|
||||
* Copyright (c) 2014-2015, Regents of the University of California,
|
||||
* Arizona Board of Regents,
|
||||
* Colorado State University,
|
||||
* University Pierre & Marie Curie, Sorbonne University,
|
||||
* Washington University in St. Louis,
|
||||
* Beijing Institute of Technology,
|
||||
* The University of Memphis.
|
||||
*
|
||||
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
||||
* See AUTHORS.md for complete list of NFD authors and contributors.
|
||||
@@ -24,6 +24,8 @@
|
||||
*/
|
||||
|
||||
#include "limited-io.hpp"
|
||||
#include "core/extended-error-message.hpp"
|
||||
#include "core/global-io.hpp"
|
||||
#include "core/logger.hpp"
|
||||
|
||||
namespace nfd {
|
||||
@@ -34,17 +36,10 @@ NFD_LOG_INIT("LimitedIo");
|
||||
const int LimitedIo::UNLIMITED_OPS = std::numeric_limits<int>::max();
|
||||
const time::nanoseconds LimitedIo::UNLIMITED_TIME = time::nanoseconds::min();
|
||||
|
||||
LimitedIo::LimitedIo()
|
||||
: m_uttf(nullptr)
|
||||
, m_isRunning(false)
|
||||
, m_nOpsRemaining(0)
|
||||
{
|
||||
}
|
||||
|
||||
LimitedIo::LimitedIo(UnitTestTimeFixture* uttf)
|
||||
: m_uttf(uttf)
|
||||
, m_isRunning(false)
|
||||
, m_nOpsRemaining(0)
|
||||
, m_isRunning(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -74,17 +69,18 @@ LimitedIo::run(int nOpsLimit, const time::nanoseconds& timeLimit, const time::na
|
||||
m_uttf->advanceClocks(tick, time::nanoseconds::max());
|
||||
}
|
||||
}
|
||||
catch (StopException&) {
|
||||
catch (const StopException&) {
|
||||
}
|
||||
catch (std::exception& ex) {
|
||||
catch (const std::exception& ex) {
|
||||
NFD_LOG_ERROR("g_io.run() exception: " << getExtendedErrorMessage(ex));
|
||||
m_reason = EXCEPTION;
|
||||
NFD_LOG_ERROR("g_io.run() exception: " << ex.what());
|
||||
m_lastException = ex;
|
||||
m_lastException = std::current_exception();
|
||||
}
|
||||
|
||||
getGlobalIoService().reset();
|
||||
scheduler::cancel(m_timeout);
|
||||
m_isRunning = false;
|
||||
|
||||
return m_reason;
|
||||
}
|
||||
|
||||
@@ -97,6 +93,7 @@ LimitedIo::afterOp()
|
||||
}
|
||||
|
||||
--m_nOpsRemaining;
|
||||
|
||||
if (m_nOpsRemaining <= 0) {
|
||||
m_reason = EXCEED_OPS;
|
||||
getGlobalIoService().stop();
|
||||
@@ -116,11 +113,5 @@ LimitedIo::afterTimeout()
|
||||
}
|
||||
}
|
||||
|
||||
const std::exception&
|
||||
LimitedIo::getLastException() const
|
||||
{
|
||||
return m_lastException;
|
||||
}
|
||||
|
||||
} // namespace tests
|
||||
} // namespace nfd
|
||||
+14
-12
@@ -27,9 +27,10 @@
|
||||
#define NFD_TESTS_LIMITED_IO_HPP
|
||||
|
||||
#include "test-common.hpp"
|
||||
#include "core/global-io.hpp"
|
||||
#include "core/scheduler.hpp"
|
||||
|
||||
#include <exception>
|
||||
|
||||
namespace nfd {
|
||||
namespace tests {
|
||||
|
||||
@@ -38,15 +39,13 @@ namespace tests {
|
||||
class LimitedIo : noncopyable
|
||||
{
|
||||
public:
|
||||
LimitedIo();
|
||||
|
||||
/** \brief construct with UnitTestTimeFixture
|
||||
*/
|
||||
LimitedIo(UnitTestTimeFixture* uttf);
|
||||
explicit
|
||||
LimitedIo(UnitTestTimeFixture* uttf = nullptr);
|
||||
|
||||
/// indicates why .run returns
|
||||
enum StopReason
|
||||
{
|
||||
enum StopReason {
|
||||
/// g_io.run() returns normally because there's no work to do
|
||||
NO_WORK,
|
||||
/// .afterOp() has been invoked nOpsLimit times
|
||||
@@ -71,9 +70,6 @@ public:
|
||||
void
|
||||
afterOp();
|
||||
|
||||
const std::exception&
|
||||
getLastException() const;
|
||||
|
||||
/** \brief defer for specified duration
|
||||
*
|
||||
* equivalent to .run(UNLIMITED_OPS, d)
|
||||
@@ -84,6 +80,12 @@ public:
|
||||
this->run(UNLIMITED_OPS, d);
|
||||
}
|
||||
|
||||
std::exception_ptr
|
||||
getLastException() const
|
||||
{
|
||||
return m_lastException;
|
||||
}
|
||||
|
||||
private:
|
||||
/** \brief an exception to stop IO operation
|
||||
*/
|
||||
@@ -100,11 +102,11 @@ public:
|
||||
|
||||
private:
|
||||
UnitTestTimeFixture* m_uttf;
|
||||
bool m_isRunning;
|
||||
StopReason m_reason;
|
||||
int m_nOpsRemaining;
|
||||
scheduler::EventId m_timeout;
|
||||
StopReason m_reason;
|
||||
std::exception m_lastException;
|
||||
std::exception_ptr m_lastException;
|
||||
bool m_isRunning;
|
||||
};
|
||||
|
||||
} // namespace tests
|
||||
|
||||
Reference in new issue
Block a user