/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2014-2024,  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)
{
  ndn::scheduler::Scheduler* s1 = &getScheduler();
  ndn::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
