/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2014-2023,  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 "common/global.hpp"

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

#include <boost/asio/post.hpp>

#include <thread>

namespace nfd::tests {

BOOST_FIXTURE_TEST_SUITE(TestGlobal, GlobalIoFixture)

BOOST_AUTO_TEST_CASE(ThreadLocalIoService)
{
  boost::asio::io_context* s1 = &getGlobalIoService();
  boost::asio::io_context* s2 = nullptr;

  std::thread t([&s2] { s2 = &getGlobalIoService(); });
  t.join();

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

BOOST_AUTO_TEST_CASE(ThreadLocalScheduler)
{
  scheduler::Scheduler* s1 = &getScheduler();
  scheduler::Scheduler* s2 = nullptr;

  std::thread t([&s2] { s2 = &getScheduler(); });
  t.join();

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

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

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

  boost::asio::post(getRibIoService(), [&] {
    BOOST_CHECK(mainThreadId != std::this_thread::get_id());
    BOOST_CHECK(&getGlobalIoService() == ribIo);
    BOOST_CHECK(&getMainIoService() == mainIo);
    BOOST_CHECK(&getRibIoService() == ribIo);
  });

  boost::asio::post(getRibIoService(), [&] {
    boost::asio::post(getMainIoService(), [&] {
      BOOST_CHECK(mainThreadId == std::this_thread::get_id());
      BOOST_CHECK(&getGlobalIoService() == mainIo);
      BOOST_CHECK(&getMainIoService() == mainIo);
      BOOST_CHECK(&getRibIoService() == ribIo);
    });
  });
}

BOOST_FIXTURE_TEST_CASE(PollInAllThreads, RibIoFixture)
{
  bool hasRibRun = false;
  boost::asio::post(getRibIoService(), [&] { hasRibRun = true; });
  std::this_thread::sleep_for(std::chrono::seconds(1));
  BOOST_CHECK_EQUAL(hasRibRun, false);

  poll();
  BOOST_CHECK_EQUAL(hasRibRun, true);

  hasRibRun = false;
  bool hasMainRun = false;
  boost::asio::post(getMainIoService(), [&] {
    hasMainRun = true;
    boost::asio::post(getRibIoService(), [&] { 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;
  boost::asio::post(getRibIoService(), [&] { hasRibRun = true; });
  std::this_thread::sleep_for(std::chrono::seconds(1));
  BOOST_CHECK_EQUAL(hasRibRun, false);

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

  hasRibRun = false;
  bool hasMainRun = false;
  getScheduler().schedule(250_ms, [&] {
    hasMainRun = true;
    boost::asio::post(getRibIoService(), [&] { 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() // TestGlobal

} // namespace nfd::tests
