OLD | NEW |
1 /* Copyright (c) 2011-2014 Stanford University | 1 /* Copyright (c) 2011-2014 Stanford University |
2 * | 2 * |
3 * Permission to use, copy, modify, and distribute this software for any purpose | 3 * Permission to use, copy, modify, and distribute this software for any purpose |
4 * with or without fee is hereby granted, provided that the above copyright | 4 * with or without fee is hereby granted, provided that the above copyright |
5 * notice and this permission notice appear in all copies. | 5 * notice and this permission notice appear in all copies. |
6 * | 6 * |
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES | 7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES |
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | 8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR ANY | 9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR ANY |
10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER | 10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
11 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF | 11 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
12 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | 12 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
14 */ | 14 */ |
15 | 15 |
| 16 #include <regex> |
| 17 |
16 #include "TestUtil.h" | 18 #include "TestUtil.h" |
17 #include "DpdkDriver.h" | 19 #include "DpdkDriver.h" |
| 20 #include "PerfStats.h" |
18 | 21 |
19 namespace RAMCloud { | 22 namespace RAMCloud { |
20 | 23 |
21 class DpdkDriverTest : public ::testing::Test { | 24 class DpdkDriverTest : public ::testing::Test { |
22 public: | 25 public: |
23 Context context; | 26 Context context; |
24 | 27 |
| 28 DpdkDriver driver; |
| 29 |
| 30 TestLog::Enable logEnabler; |
| 31 |
25 DpdkDriverTest() | 32 DpdkDriverTest() |
26 : context() | 33 : context() |
27 {} | 34 , driver() |
| 35 , logEnabler() |
| 36 { |
| 37 driver.context = &context; |
| 38 } |
28 | 39 |
29 ~DpdkDriverTest() {} | 40 ~DpdkDriverTest() {} |
30 | 41 |
31 private: | 42 private: |
32 DISALLOW_COPY_AND_ASSIGN(DpdkDriverTest); | 43 DISALLOW_COPY_AND_ASSIGN(DpdkDriverTest); |
33 }; | 44 }; |
34 | 45 |
35 // Currently don't know of anything that can be effectively tested | 46 // Currently receivePackets cannot be effectively tested with unit tests. |
36 // with unit tests. | 47 |
| 48 TEST_F(DpdkDriverTest, getHighestPacketPriority) { |
| 49 driver.lowestPriorityAvail = 0; |
| 50 driver.highestPriorityAvail = 7; |
| 51 EXPECT_EQ(7, driver.getHighestPacketPriority()); |
| 52 |
| 53 driver.lowestPriorityAvail = 2; |
| 54 driver.highestPriorityAvail = 5; |
| 55 EXPECT_EQ(3, driver.getHighestPacketPriority()); |
| 56 } |
| 57 |
| 58 TEST_F(DpdkDriverTest, sendPacket_success) { |
| 59 PerfStats::threadStats.networkOutputBytes = 0; |
| 60 driver.lowestPriorityAvail = 1; |
| 61 driver.highestPriorityAvail = 6; |
| 62 |
| 63 MacAddress address("ff:ff:ff:ff:ff:ff"); |
| 64 string header = "ABCDEFGH"; |
| 65 string payload = "abcdefgh"; |
| 66 Buffer buffer; |
| 67 buffer.append(payload.c_str(), downCast<uint32_t>(payload.length())); |
| 68 Buffer::Iterator iterator(&buffer); |
| 69 |
| 70 TestLog::reset(); |
| 71 driver.sendPacket(&address, header.c_str(), (uint32_t)header.length(), |
| 72 &iterator, 3); |
| 73 |
| 74 string testLog = TestLog::get(); |
| 75 std::regex regex("Ethernet frame header (.*), payload (.*)"); |
| 76 std::smatch match; |
| 77 std::regex_search(testLog, match, regex); |
| 78 string hexEtherFrame = match.str(1); |
| 79 string etherPayload = match.str(2); |
| 80 |
| 81 // src mac address |
| 82 EXPECT_EQ("ffffffffffff", hexEtherFrame.substr(0, 12)); |
| 83 // dest mac address |
| 84 EXPECT_EQ("0123456789ab", hexEtherFrame.substr(12, 12)); |
| 85 // VLAN tagging frame type ID in network order |
| 86 EXPECT_EQ("8100", hexEtherFrame.substr(24, 4)); |
| 87 // PCP field |
| 88 EXPECT_EQ("8000", hexEtherFrame.substr(28, 4)); |
| 89 // RAMCloud raw-Ethernet frame type ID in network order |
| 90 EXPECT_EQ("88b5", hexEtherFrame.substr(32, 4)); |
| 91 // Ethernet frame payload content |
| 92 EXPECT_EQ("ABCDEFGHabcdefgh", etherPayload); |
| 93 |
| 94 uint64_t packetBufLen = DpdkDriver::ETHER_VLAN_HDR_LEN + header.length() + |
| 95 payload.length(); |
| 96 EXPECT_EQ(packetBufLen, (uint64_t) driver.queueEstimator.queueSize); |
| 97 EXPECT_EQ(packetBufLen, PerfStats::threadStats.networkOutputBytes); |
| 98 } |
37 | 99 |
38 } // namespace RAMCloud | 100 } // namespace RAMCloud |
OLD | NEW |