blob: 73a43bc06bd7c1dad71c7d70f8113935d2a8443a [file] [log] [blame]
Teng Liang952d6fd2018-05-29 21:09:52 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesaventoe422f9e2022-06-03 01:30:23 -04003 * Copyright (c) 2014-2022, Regents of the University of California,
Teng Liang952d6fd2018-05-29 21:09:52 -07004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
Davide Pesavento3dade002019-03-19 11:29:56 -060026#ifndef NFD_TESTS_DAEMON_RIB_IO_FIXTURE_HPP
27#define NFD_TESTS_DAEMON_RIB_IO_FIXTURE_HPP
Teng Liang952d6fd2018-05-29 21:09:52 -070028
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040029#include "tests/daemon/global-io-fixture.hpp"
Davide Pesavento2bdf60c2019-02-19 18:23:45 -050030
Teng Liang952d6fd2018-05-29 21:09:52 -070031#include <condition_variable>
32#include <mutex>
Davide Pesavento2bdf60c2019-02-19 18:23:45 -050033#include <thread>
Teng Liang952d6fd2018-05-29 21:09:52 -070034
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040035namespace nfd::tests {
Teng Liang952d6fd2018-05-29 21:09:52 -070036
Davide Pesaventob7703ad2019-03-23 21:12:56 -040037/** \brief A base test fixture that provides both main and RIB io_service.
Teng Liang952d6fd2018-05-29 21:09:52 -070038 */
Davide Pesaventocf7db2f2019-03-24 23:17:28 -040039class RibIoFixture : public GlobalIoFixture
Teng Liang952d6fd2018-05-29 21:09:52 -070040{
41protected:
42 RibIoFixture();
43
44 ~RibIoFixture();
45
46protected:
Davide Pesaventob7703ad2019-03-23 21:12:56 -040047 /** \brief Poll main and RIB thread io_service to process all pending I/O events.
Teng Liang952d6fd2018-05-29 21:09:52 -070048 *
49 * This call will execute all pending I/O events, including events that are posted
50 * inside the processing event, i.e., main and RIB thread io_service will be polled
51 * repeatedly until all pending events are processed.
52 *
Davide Pesaventob7703ad2019-03-23 21:12:56 -040053 * \warning Must be called from the main thread
Teng Liang952d6fd2018-05-29 21:09:52 -070054 */
55 void
56 poll();
57
58protected:
Teng Liangf59e58f2018-09-07 16:41:54 -070059 /** \brief pointer to global main io_service
60 */
61 boost::asio::io_service* g_mainIo = nullptr;
62
Teng Liang952d6fd2018-05-29 21:09:52 -070063 /** \brief pointer to global RIB io_service
64 */
65 boost::asio::io_service* g_ribIo = nullptr;
66
67 /** \brief global RIB thread
68 */
Davide Pesavento2bdf60c2019-02-19 18:23:45 -050069 std::thread g_ribThread;
Teng Liang952d6fd2018-05-29 21:09:52 -070070
71private:
72 bool m_shouldStopRibIo = false;
73 bool m_shouldPollRibIo = false;
74 std::mutex m_ribPollMutex;
75 std::condition_variable m_ribPollStartCv;
76 std::condition_variable m_ribPollEndCv;
77};
78
Davide Pesaventob7703ad2019-03-23 21:12:56 -040079/** \brief RibIoFixture that also overrides steady clock and system clock.
Teng Liang952d6fd2018-05-29 21:09:52 -070080 */
Davide Pesavento21353752020-11-20 00:43:44 -050081class RibIoTimeFixture : public ClockFixture, public RibIoFixture
Teng Liang952d6fd2018-05-29 21:09:52 -070082{
Davide Pesaventob7703ad2019-03-23 21:12:56 -040083private:
Teng Liang952d6fd2018-05-29 21:09:52 -070084 void
Davide Pesavento21353752020-11-20 00:43:44 -050085 afterTick() final;
Teng Liang952d6fd2018-05-29 21:09:52 -070086};
87
Davide Pesaventoe422f9e2022-06-03 01:30:23 -040088} // namespace nfd::tests
Teng Liang952d6fd2018-05-29 21:09:52 -070089
Davide Pesavento3dade002019-03-19 11:29:56 -060090#endif // NFD_TESTS_DAEMON_RIB_IO_FIXTURE_HPP