Make use of logger provided by ndn-cxx
This commit also introduces a basic implmentation of DummyForwarder to
remove dependency on (and uncertainty of) the running instance of NFD.
Change-Id: Iba9fcbf3d3ebb1a5ae47018ad3be5d7d2b9c7462
diff --git a/tests/logger-config-global-fixture.cpp b/tests/logger-config-global-fixture.cpp
index fab5a29..659edf9 100644
--- a/tests/logger-config-global-fixture.cpp
+++ b/tests/logger-config-global-fixture.cpp
@@ -34,8 +34,6 @@
public:
GlobalConfigurationFixture()
{
- INIT_LOGGERS();
-
if (getenv("HOME") != nullptr) {
m_home = getenv("HOME");
}
diff --git a/tests/unit-tests/action-log.t.cpp b/tests/unit-tests/action-log.t.cpp
index f598276..2281026 100644
--- a/tests/unit-tests/action-log.t.cpp
+++ b/tests/unit-tests/action-log.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -38,8 +38,6 @@
BOOST_AUTO_TEST_CASE(ActionLogTest)
{
- INIT_LOGGERS();
-
Name localName("/alex");
fs::path tmpdir = fs::unique_path(fs::temp_directory_path() / "%%%%-%%%%-%%%%-%%%%");
diff --git a/tests/unit-tests/dispatcher.t.cpp b/tests/unit-tests/dispatcher.t.cpp
index 572db31..5270102 100644
--- a/tests/unit-tests/dispatcher.t.cpp
+++ b/tests/unit-tests/dispatcher.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -32,11 +32,10 @@
using namespace boost;
namespace fs = boost::filesystem;
-INIT_LOGGER("Test.Dispatcher");
+_LOG_INIT(Test.Dispatcher);
BOOST_AUTO_TEST_SUITE(TestDispatcher)
-
void
cleanDir(fs::path dir)
{
@@ -53,8 +52,6 @@
BOOST_AUTO_TEST_CASE(DispatcherTest)
{
- INIT_LOGGERS();
-
fs::path dir1("./TestDispatcher/test-white-house");
fs::path dir2("./TestDispatcher/test-black-house");
diff --git a/tests/unit-tests/dummy-forwarder.cpp b/tests/unit-tests/dummy-forwarder.cpp
new file mode 100644
index 0000000..6ee9990
--- /dev/null
+++ b/tests/unit-tests/dummy-forwarder.cpp
@@ -0,0 +1,70 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2017, Regents of the University of California.
+ *
+ * This file is part of ChronoShare, a decentralized file sharing application over NDN.
+ *
+ * ChronoShare is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * ChronoShare is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License along with
+ * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ChronoShare authors and contributors.
+ */
+
+#include "dummy-forwarder.hpp"
+
+#include <boost/asio/io_service.hpp>
+
+namespace ndn {
+namespace chronoshare {
+
+DummyForwarder::DummyForwarder(boost::asio::io_service& io, KeyChain& keyChain)
+ : m_io(io)
+ , m_keyChain(keyChain)
+{
+}
+
+Face&
+DummyForwarder::addFace()
+{
+ auto face = std::make_shared<util::DummyClientFace>(m_io, m_keyChain, util::
+ DummyClientFace::Options{true, true});
+ face->onSendInterest.connect([this, face] (const Interest& interest) {
+ for (auto& otherFace : m_faces) {
+ if (&*face == &*otherFace) {
+ continue;
+ }
+ otherFace->receive(interest);
+ }
+ });
+ face->onSendData.connect([this, face] (const Data& data) {
+ for (auto& otherFace : m_faces) {
+ if (&*face == &*otherFace) {
+ continue;
+ }
+ otherFace->receive(data);
+ }
+ });
+
+ face->onSendNack.connect([this, face] (const lp::Nack& nack) {
+ for (auto& otherFace : m_faces) {
+ if (&*face == &*otherFace) {
+ continue;
+ }
+ otherFace->receive(nack);
+ }
+ });
+
+ m_faces.push_back(face);
+ return *face;
+}
+
+} // namespace chronoshare
+} // namespace ndn
diff --git a/tests/unit-tests/dummy-forwarder.hpp b/tests/unit-tests/dummy-forwarder.hpp
new file mode 100644
index 0000000..ea5a736
--- /dev/null
+++ b/tests/unit-tests/dummy-forwarder.hpp
@@ -0,0 +1,62 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2017, Regents of the University of California.
+ *
+ * This file is part of ChronoShare, a decentralized file sharing application over NDN.
+ *
+ * ChronoShare is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * ChronoShare is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License along with
+ * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ChronoShare authors and contributors.
+ */
+
+#include <ndn-cxx/interest.hpp>
+#include <ndn-cxx/data.hpp>
+#include <ndn-cxx/lp/nack.hpp>
+#include <ndn-cxx/util/dummy-client-face.hpp>
+#include <ndn-cxx/security/key-chain.hpp>
+
+#ifndef NDN_CHRONOSHARE_TESTS_DUMMY_FORWARDER_HPP
+#define NDN_CHRONOSHARE_TESTS_DUMMY_FORWARDER_HPP
+
+namespace ndn {
+namespace chronoshare {
+
+/**
+ * @brief Very basic implementation of the dummy forwarder
+ *
+ * Interests expressed by any added face, will be forwarded to all other faces.
+ * Similarly, any pushed data, will be pushed to all other faces.
+ */
+class DummyForwarder
+{
+public:
+ DummyForwarder(boost::asio::io_service& io, KeyChain& keyChain);
+
+ Face&
+ addFace();
+
+ Face&
+ getFace(size_t nFace)
+ {
+ return *m_faces.at(nFace);
+ }
+
+private:
+ boost::asio::io_service& m_io;
+ KeyChain& m_keyChain;
+ std::vector<shared_ptr<util::DummyClientFace>> m_faces;
+};
+
+} // namespace chronoshare
+} // namespace ndn
+
+#endif // NDN_CHRONOSHARE_TESTS_DUMMY_FORWARDER_HPP
diff --git a/tests/unit-tests/fetch-manager.t.cpp b/tests/unit-tests/fetch-manager.t.cpp
index 24ec688..9ce544f 100644
--- a/tests/unit-tests/fetch-manager.t.cpp
+++ b/tests/unit-tests/fetch-manager.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -25,7 +25,7 @@
#include <boost/make_shared.hpp>
#include <boost/test/unit_test.hpp>
-INIT_LOGGER("Test.FetchManager");
+_LOG_INIT(Test.FetchManager);
using namespace Ndnx;
using namespace std;
@@ -113,8 +113,6 @@
BOOST_AUTO_TEST_CASE(TestFetcher)
{
- INIT_LOGGERS();
-
CcnxWrapperPtr ccnx = make_shared<CcnxWrapper>();
Name baseName("/base");
@@ -206,8 +204,6 @@
BOOST_AUTO_TEST_CASE (TestFetcher2)
{
- INIT_LOGGERS ();
-
NdnxWrapperPtr ndnx = make_shared<NdnxWrapper> ();
Name baseName ("/base");
diff --git a/tests/unit-tests/fetch-task-db.t.cpp b/tests/unit-tests/fetch-task-db.t.cpp
index 03c5de8..3fd940e 100644
--- a/tests/unit-tests/fetch-task-db.t.cpp
+++ b/tests/unit-tests/fetch-task-db.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -34,7 +34,7 @@
#include <unistd.h>
#include <utility>
-INIT_LOGGER("Test.FetchTaskDb");
+_LOG_INIT(Test.FetchTaskDb);
using namespace Ndnx;
using namespace std;
@@ -104,7 +104,6 @@
BOOST_AUTO_TEST_CASE(FetchTaskDbTest)
{
- INIT_LOGGERS();
fs::path folder("TaskDbTest");
fs::create_directories(folder / ".chronoshare");
diff --git a/tests/unit-tests/object-manager.t.cpp b/tests/unit-tests/object-manager.t.cpp
index c19cd75..7b721c1 100644
--- a/tests/unit-tests/object-manager.t.cpp
+++ b/tests/unit-tests/object-manager.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -30,7 +30,7 @@
#include <iterator>
#include <unistd.h>
-INIT_LOGGER("Test.ObjectManager");
+_LOG_INIT(Test.ObjectManager);
using namespace Ndnx;
using namespace std;
@@ -41,8 +41,6 @@
BOOST_AUTO_TEST_CASE(ObjectManagerTest)
{
- INIT_LOGGERS();
-
fs::path tmpdir = fs::unique_path(fs::temp_directory_path() / "%%%%-%%%%-%%%%-%%%%");
_LOG_DEBUG("tmpdir: " << tmpdir);
Name deviceName("/device");
diff --git a/tests/unit-tests/serve-and-fetch.t.cpp b/tests/unit-tests/serve-and-fetch.t.cpp
index d9aa6c7..da6aa1a 100644
--- a/tests/unit-tests/serve-and-fetch.t.cpp
+++ b/tests/unit-tests/serve-and-fetch.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016, Regents of the University of California.
+ * Copyright (c) 2013-2017, Regents of the University of California.
*
* This file is part of ChronoShare, a decentralized file sharing application over NDN.
*
@@ -37,7 +37,7 @@
#include "logging.hpp"
-INIT_LOGGER("Test.ServerAndFetch");
+_LOG_INIT(Test.ServerAndFetch);
using namespace Ndnx;
using namespace std;
@@ -114,8 +114,6 @@
BOOST_AUTO_TEST_CASE(TestServeAndFetch)
{
- INIT_LOGGERS();
-
_LOG_DEBUG("Setting up test environment ...");
setup();
diff --git a/tests/unit-tests/sync-core.t.cpp b/tests/unit-tests/sync-core.t.cpp
index 5fdd5fa..d0c47f5 100644
--- a/tests/unit-tests/sync-core.t.cpp
+++ b/tests/unit-tests/sync-core.t.cpp
@@ -21,6 +21,7 @@
#include "sync-core.hpp"
#include "test-common.hpp"
+#include "dummy-forwarder.hpp"
namespace ndn {
namespace chronoshare {
@@ -28,19 +29,18 @@
namespace fs = boost::filesystem;
-INIT_LOGGER("Test.SyncCore")
+_LOG_INIT(Test.SyncCore);
class TestSyncCoreFixture : public IdentityManagementTimeFixture
{
public:
- void
- advanceClocks()
+ TestSyncCoreFixture()
+ : forwarder(m_io, m_keyChain)
{
- for (int i = 0; i < 100; ++i) {
- usleep(10000);
- IdentityManagementTimeFixture::advanceClocks(time::milliseconds(10), 1);
- }
}
+
+public:
+ DummyForwarder forwarder;
};
BOOST_FIXTURE_TEST_SUITE(TestSyncCore, TestSyncCoreFixture)
@@ -77,47 +77,42 @@
Name loc2("/locator2");
Name syncPrefix("/broadcast/arslan");
- shared_ptr<Face> c1 = make_shared<Face>(this->m_io);
+ Face& c1 = forwarder.addFace();
auto log1 = make_shared<SyncLog>(dir1, user1);
- auto core1 = make_shared<SyncCore>(*c1, log1, user1, loc1, syncPrefix, bind(&callback, _1));
+ auto core1 = make_shared<SyncCore>(c1, log1, user1, loc1, syncPrefix, bind(&callback, _1));
- shared_ptr<Face> c2 = make_shared<Face>(this->m_io);
+ Face& c2 = forwarder.addFace();
auto log2 = make_shared<SyncLog>(dir2, user2);
- auto core2 = make_shared<SyncCore>(*c2, log2, user2, loc2, syncPrefix, bind(&callback, _1));
+ auto core2 = make_shared<SyncCore>(c2, log2, user2, loc2, syncPrefix, bind(&callback, _1));
- // @TODO: Implement test using the dummy forwarder and disable dependency on real time
-
- this->advanceClocks();
+ advanceClocks(time::milliseconds(10), 100);
BOOST_CHECK_EQUAL(toHex(*core1->root()), toHex(*core2->root()));
- // _LOG_TRACE("\n\n\n\n\n\n----------\n");
-
core1->updateLocalState(1);
- this->advanceClocks();
+ advanceClocks(time::milliseconds(10), 10);
BOOST_CHECK_EQUAL(toHex(*core1->root()), toHex(*core2->root()));
BOOST_CHECK_EQUAL(core2->seq(user1), 1);
BOOST_CHECK_EQUAL(log2->LookupLocator(user1), loc1);
core1->updateLocalState(5);
- this->advanceClocks();
+ advanceClocks(time::milliseconds(10), 10);
BOOST_CHECK_EQUAL(toHex(*core1->root()), toHex(*core2->root()));
BOOST_CHECK_EQUAL(core2->seq(user1), 5);
BOOST_CHECK_EQUAL(log2->LookupLocator(user1), loc1);
core2->updateLocalState(10);
- this->advanceClocks();
+ advanceClocks(time::milliseconds(10), 10);
BOOST_CHECK_EQUAL(toHex(*core1->root()), toHex(*core2->root()));
BOOST_CHECK_EQUAL(core1->seq(user2), 10);
BOOST_CHECK_EQUAL(log1->LookupLocator(user2), loc2);
// simple simultaneous data generation
- _LOG_TRACE("\n\n\n\n\n\n----------Simultaneous\n");
core1->updateLocalState(11);
- this->advanceClocks();
+ advanceClocks(time::milliseconds(10), 10);
core2->updateLocalState(15);
- this->advanceClocks();
+ advanceClocks(time::milliseconds(10), 10);
BOOST_CHECK_EQUAL(toHex(*core1->root()), toHex(*core2->root()));
BOOST_CHECK_EQUAL(core1->seq(user2), 15);
BOOST_CHECK_EQUAL(core2->seq(user1), 11);
diff --git a/tests/unit-tests/sync-log.t.cpp b/tests/unit-tests/sync-log.t.cpp
index bf5801e..7d4eeeb 100644
--- a/tests/unit-tests/sync-log.t.cpp
+++ b/tests/unit-tests/sync-log.t.cpp
@@ -28,8 +28,6 @@
namespace fs = boost::filesystem;
-INIT_LOGGER("Test.SyncLog")
-
BOOST_FIXTURE_TEST_SUITE(TestSyncLog, IdentityManagementTimeFixture)
BOOST_AUTO_TEST_CASE(BasicDatabaseTest)
diff --git a/tests/unit-tests/sync-state.pb.t.cpp b/tests/unit-tests/sync-state.pb.t.cpp
index b0ce112..d1910db 100644
--- a/tests/unit-tests/sync-state.pb.t.cpp
+++ b/tests/unit-tests/sync-state.pb.t.cpp
@@ -31,8 +31,6 @@
namespace chronoshare {
namespace tests {
-INIT_LOGGER("Test.protobuf")
-
BOOST_AUTO_TEST_SUITE(TestSyncStatePb)
BOOST_AUTO_TEST_CASE(Serialize)
diff --git a/tests/wscript b/tests/wscript
index b47447b..0b08cc0 100644
--- a/tests/wscript
+++ b/tests/wscript
@@ -22,6 +22,7 @@
target='../unit-tests',
features='cxx cxxprogram',
source=bld.path.ant_glob(['*.cpp',
+ 'unit-tests/dummy-forwarder.cpp',
'unit-tests/sync-*.t.cpp',
],
excl=['main.cpp']),