Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 1983804 | 2014-06-21 00:34:01 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2014, Regents of the University of California, |
| 4 | * 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 |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 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/>. |
Junxiao Shi | 1983804 | 2014-06-21 00:34:01 -0700 | [diff] [blame^] | 24 | */ |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 25 | |
| 26 | #include "table/measurements.hpp" |
| 27 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 28 | #include "tests/test-common.hpp" |
Junxiao Shi | 1983804 | 2014-06-21 00:34:01 -0700 | [diff] [blame^] | 29 | #include "tests/limited-io.hpp" |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 30 | |
| 31 | namespace nfd { |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 32 | namespace tests { |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 33 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 34 | BOOST_FIXTURE_TEST_SUITE(TableMeasurements, BaseFixture) |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 35 | |
| 36 | BOOST_AUTO_TEST_CASE(Get_Parent) |
| 37 | { |
Haowei Yuan | f52dac7 | 2014-03-24 23:35:03 -0500 | [diff] [blame] | 38 | NameTree nameTree; |
HangZhang | c85a23c | 2014-03-01 15:55:55 +0800 | [diff] [blame] | 39 | Measurements measurements(nameTree); |
Junxiao Shi | c041ca3 | 2014-02-25 20:01:15 -0700 | [diff] [blame] | 40 | |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 41 | Name name0; |
| 42 | Name nameA ("ndn:/A"); |
| 43 | Name nameAB("ndn:/A/B"); |
| 44 | |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 45 | shared_ptr<measurements::Entry> entryAB = measurements.get(nameAB); |
| 46 | BOOST_REQUIRE(static_cast<bool>(entryAB)); |
| 47 | BOOST_CHECK_EQUAL(entryAB->getName(), nameAB); |
| 48 | |
| 49 | shared_ptr<measurements::Entry> entry0 = measurements.get(name0); |
| 50 | BOOST_REQUIRE(static_cast<bool>(entry0)); |
| 51 | |
| 52 | shared_ptr<measurements::Entry> entryA = measurements.getParent(entryAB); |
| 53 | BOOST_REQUIRE(static_cast<bool>(entryA)); |
| 54 | BOOST_CHECK_EQUAL(entryA->getName(), nameA); |
| 55 | |
| 56 | shared_ptr<measurements::Entry> entry0c = measurements.getParent(entryA); |
| 57 | BOOST_CHECK_EQUAL(entry0, entry0c); |
| 58 | } |
| 59 | |
Junxiao Shi | 1983804 | 2014-06-21 00:34:01 -0700 | [diff] [blame^] | 60 | BOOST_AUTO_TEST_CASE(Lifetime) |
| 61 | { |
| 62 | LimitedIo limitedIo; |
| 63 | NameTree nameTree; |
| 64 | Measurements measurements(nameTree); |
| 65 | Name nameA("ndn:/A"); |
| 66 | Name nameB("ndn:/B"); |
| 67 | Name nameC("ndn:/C"); |
| 68 | |
| 69 | BOOST_CHECK_EQUAL(measurements.size(), 0); |
| 70 | |
| 71 | shared_ptr<measurements::Entry> entryA = measurements.get(nameA); |
| 72 | shared_ptr<measurements::Entry> entryB = measurements.get(nameB); |
| 73 | shared_ptr<measurements::Entry> entryC = measurements.get(nameC); |
| 74 | BOOST_CHECK_EQUAL(measurements.size(), 3); |
| 75 | |
| 76 | const time::nanoseconds EXTEND_A = time::seconds(2); |
| 77 | const time::nanoseconds CHECK1 = time::seconds(3); |
| 78 | const time::nanoseconds CHECK2 = time::seconds(5); |
| 79 | const time::nanoseconds EXTEND_C = time::seconds(6); |
| 80 | const time::nanoseconds CHECK3 = time::seconds(7); |
| 81 | BOOST_ASSERT(EXTEND_A < CHECK1 && |
| 82 | CHECK1 < Measurements::getInitialLifetime() && |
| 83 | Measurements::getInitialLifetime() < CHECK2 && |
| 84 | CHECK2 < EXTEND_C && |
| 85 | EXTEND_C < CHECK3); |
| 86 | |
| 87 | measurements.extendLifetime(*entryA, EXTEND_A); |
| 88 | measurements.extendLifetime(*entryC, EXTEND_C); |
| 89 | // remaining lifetime: |
| 90 | // A = initial lifetime, because it's extended by less duration |
| 91 | // B = initial lifetime |
| 92 | // C = EXTEND_C |
| 93 | entryA.reset(); |
| 94 | entryB.reset(); |
| 95 | entryC.reset(); |
| 96 | |
| 97 | BOOST_CHECK_EQUAL(limitedIo.run(LimitedIo::UNLIMITED_OPS, CHECK1), LimitedIo::EXCEED_TIME); |
| 98 | BOOST_CHECK_EQUAL(static_cast<bool>(measurements.findExactMatch(nameA)), true); |
| 99 | BOOST_CHECK_EQUAL(static_cast<bool>(measurements.findExactMatch(nameB)), true); |
| 100 | BOOST_CHECK_EQUAL(static_cast<bool>(measurements.findExactMatch(nameC)), true); |
| 101 | BOOST_CHECK_EQUAL(measurements.size(), 3); |
| 102 | |
| 103 | BOOST_CHECK_EQUAL(limitedIo.run(LimitedIo::UNLIMITED_OPS, CHECK2 - CHECK1), |
| 104 | LimitedIo::EXCEED_TIME); |
| 105 | BOOST_CHECK_EQUAL(static_cast<bool>(measurements.findExactMatch(nameA)), false); |
| 106 | BOOST_CHECK_EQUAL(static_cast<bool>(measurements.findExactMatch(nameB)), false); |
| 107 | BOOST_CHECK_EQUAL(static_cast<bool>(measurements.findExactMatch(nameC)), true); |
| 108 | BOOST_CHECK_EQUAL(measurements.size(), 1); |
| 109 | |
| 110 | BOOST_CHECK_EQUAL(limitedIo.run(LimitedIo::UNLIMITED_OPS, CHECK3 - CHECK2), |
| 111 | LimitedIo::EXCEED_TIME); |
| 112 | BOOST_CHECK_EQUAL(static_cast<bool>(measurements.findExactMatch(nameA)), false); |
| 113 | BOOST_CHECK_EQUAL(static_cast<bool>(measurements.findExactMatch(nameB)), false); |
| 114 | BOOST_CHECK_EQUAL(static_cast<bool>(measurements.findExactMatch(nameC)), false); |
| 115 | BOOST_CHECK_EQUAL(measurements.size(), 0); |
| 116 | } |
| 117 | |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 118 | BOOST_AUTO_TEST_SUITE_END() |
| 119 | |
Junxiao Shi | d9ee45c | 2014-02-27 15:38:11 -0700 | [diff] [blame] | 120 | } // namespace tests |
Junxiao Shi | 65d0072 | 2014-02-17 10:50:20 -0700 | [diff] [blame] | 121 | } // namespace nfd |