/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2014-2018,  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.
 *
 * NFD 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.
 *
 * NFD 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 a copy of the GNU General Public License along with
 * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "core/global-io.hpp"
#include "core/scheduler.hpp"

#include "tests/rib-io-fixture.hpp"
#include "tests/test-common.hpp"

#include <boost/thread.hpp>

namespace nfd {
namespace tests {

BOOST_FIXTURE_TEST_SUITE(TestGlobalIo, BaseFixture)

BOOST_AUTO_TEST_CASE(ThreadLocalGlobalIoService)
{
  boost::asio::io_service* s1 = &getGlobalIoService();
  boost::asio::io_service* s2 = nullptr;
  boost::thread t([&s2] {
      s2 = &getGlobalIoService();
    });

  t.join();

  BOOST_CHECK(s1 != nullptr);
  BOOST_CHECK(s2 != nullptr);
  BOOST_CHECK(s1 != s2);
}

BOOST_FIXTURE_TEST_CASE(RibIoService, RibIoFixture)
{
  boost::asio::io_service* mainIo = &g_io;
  boost::asio::io_service* ribIo = g_ribIo;

  BOOST_CHECK(mainIo != ribIo);
  BOOST_CHECK(&getGlobalIoService() == mainIo);
  BOOST_CHECK(&getRibIoService() == ribIo);
  auto mainThreadId = boost::this_thread::get_id();

  runOnRibIoService([&] {
    BOOST_CHECK(mainThreadId != boost::this_thread::get_id());
    BOOST_CHECK(&getRibIoService() == ribIo);
    BOOST_CHECK(&getGlobalIoService() == ribIo);
  });
}

BOOST_FIXTURE_TEST_CASE(PollInAllThreads, RibIoFixture)
{
  bool hasRibRun = false;
  runOnRibIoService([&] { hasRibRun = true; });
  boost::this_thread::sleep_for(1_s);
  BOOST_CHECK_EQUAL(hasRibRun, false);

  poll();
  BOOST_CHECK_EQUAL(hasRibRun, true);

  hasRibRun = false;
  bool hasMainRun = false;
  g_io.post([&] {
      hasMainRun = true;
      runOnRibIoService([&] { hasRibRun = true; });
    });
  BOOST_CHECK_EQUAL(hasMainRun, false);
  BOOST_CHECK_EQUAL(hasRibRun, false);

  poll();
  BOOST_CHECK_EQUAL(hasMainRun, true);
  BOOST_CHECK_EQUAL(hasRibRun, true);
}

BOOST_FIXTURE_TEST_CASE(AdvanceClocks, RibIoTimeFixture)
{
  bool hasRibRun = false;
  runOnRibIoService([&] { hasRibRun = true; });
  boost::this_thread::sleep_for(1_s);
  BOOST_CHECK_EQUAL(hasRibRun, false);

  advanceClocks(1_ns, 1);
  BOOST_CHECK_EQUAL(hasRibRun, true);

  hasRibRun = false;
  bool hasMainRun = false;
  scheduler::schedule(250_ms, [&] {
      hasMainRun = true;
      runOnRibIoService([&] { hasRibRun = true; });
    });
  BOOST_CHECK_EQUAL(hasMainRun, false);
  BOOST_CHECK_EQUAL(hasRibRun, false);

  advanceClocks(260_ms, 2);
  BOOST_CHECK_EQUAL(hasMainRun, true);
  BOOST_CHECK_EQUAL(hasRibRun, true);
}

BOOST_AUTO_TEST_SUITE_END()

} // namespace tests
} // namespace nfd
