TLPAggregationTests.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  1. /*
  2. * Copyright (c) 2017 The Linux Foundation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above
  10. * copyright notice, this list of conditions and the following
  11. * disclaimer in the documentation and/or other materials provided
  12. * with the distribution.
  13. * * Neither the name of The Linux Foundation nor the names of its
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  21. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  24. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  25. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  26. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  27. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <unistd.h>
  32. #include <string.h>
  33. #include <stdint.h>
  34. #include "TLPAggregationTestFixture.h"
  35. #include "Constants.h"
  36. #include "TestsUtils.h"
  37. #include "linux/msm_ipa.h"
  38. #define NUM_PACKETS 5
  39. #define TIME_LIMIT_NUM_PACKETS 1
  40. #define MAX_PACKET_SIZE 1024
  41. #define AGGREGATION_LOOP 4
  42. int test_num = 0;
  43. /////////////////////////////////////////////////////////////////////////////////
  44. /////////////////////////////////////////////////////////////////////////////////
  45. /////////////////////////////////////////////////////////////////////////////////
  46. class TLPAggregationTest: public TLPAggregationTestFixture {
  47. public:
  48. /////////////////////////////////////////////////////////////////////////////////
  49. TLPAggregationTest()
  50. {
  51. m_name = "TLPAggregationTest";
  52. m_description = "TLP Aggregation test - sends 5 packets and receives 1 "
  53. "aggregated packet";
  54. }
  55. /////////////////////////////////////////////////////////////////////////////////
  56. bool Run()
  57. {
  58. bool bTestResult = true;
  59. //The packets that will be sent
  60. Byte pPackets[NUM_PACKETS][MAX_PACKET_SIZE];
  61. //The real sizes of the packets that will be sent
  62. int pPacketsSizes[NUM_PACKETS];
  63. //Buffer for the packet that will be received
  64. Byte pReceivedPacket[MAX_PACKET_SIZE];
  65. //Total size of all sent packets (this is the max size of the aggregated packet
  66. //minus 2 bytes for each packet in the aggregated packet)
  67. int nTotalPacketsSize = MAX_PACKET_SIZE - (2 * NUM_PACKETS);
  68. //The expected aggregated packet
  69. Byte pExpectedAggregatedPacket[MAX_PACKET_SIZE] = {0};
  70. //initialize the packets
  71. //example: for NUM_PACKETS = 5 and MAX_PACKET_SIZE = 1024:
  72. //nTotalPacketsSize will be 1024 - 5*2 = 1014
  73. //packets[0] size will be 1014/5 = 202 bytes of 0
  74. //packets[1] size will be (1014 - 202) / 5 = 162 bytes of 1
  75. //packets[2] size will be (1014 - 201 - 162) / 5 = 130 bytes of 2
  76. //packets[3] size will be (1014 - 201 - 162 - 130) / 5 = 104 bytes of 3
  77. //packets[4] size will be 1014 - 201 - 162 - 130 - 104 = 416 bytes of 4
  78. for (int i = 0; i < NUM_PACKETS; i++)
  79. {
  80. if (NUM_PACKETS - 1 == i)
  81. pPacketsSizes[i] = nTotalPacketsSize;
  82. else
  83. pPacketsSizes[i] = nTotalPacketsSize / NUM_PACKETS;
  84. nTotalPacketsSize -= pPacketsSizes[i];
  85. for (int j = 0; j < pPacketsSizes[i]; j++)
  86. pPackets[i][j] = i + 16*test_num;
  87. }
  88. test_num++;
  89. //send the packets
  90. for (int i = 0; i < NUM_PACKETS; i++)
  91. {
  92. LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d bytes)\n", i,
  93. pPacketsSizes[i]);
  94. int nBytesSent = m_UsbNoAggToIpaPipeAgg.Send(pPackets[i],
  95. pPacketsSizes[i]);
  96. if (pPacketsSizes[i] != nBytesSent)
  97. {
  98. LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d bytes) "
  99. "failed!\n", i, pPacketsSizes[i]);
  100. return false;
  101. }
  102. }
  103. //receive the aggregated packet
  104. LOG_MSG_DEBUG("Reading packet from the USB pipe(%d bytes should be "
  105. "there)\n", MAX_PACKET_SIZE);
  106. int nBytesReceived = m_IpaToUsbPipeAggr.Receive(pReceivedPacket,
  107. MAX_PACKET_SIZE);
  108. if (MAX_PACKET_SIZE != nBytesReceived)
  109. {
  110. LOG_MSG_DEBUG("Receiving aggregated packet from the USB pipe(%d "
  111. "bytes) failed!\n", MAX_PACKET_SIZE);
  112. print_buff(pReceivedPacket, nBytesReceived);
  113. return false;
  114. }
  115. //initializing the aggregated packet
  116. int k = 0;
  117. for (int i = 0; i < NUM_PACKETS; i++)
  118. {
  119. //the first 2 bytes are the packet length in little endian
  120. pExpectedAggregatedPacket[k] = pPacketsSizes[i] & 0x00FF;
  121. pExpectedAggregatedPacket[k+1] = pPacketsSizes[i] >> 8;
  122. k += 2;
  123. for (int j = 0; j < pPacketsSizes[i]; j++)
  124. {
  125. pExpectedAggregatedPacket[k] = pPackets[i][j];
  126. k++;
  127. }
  128. }
  129. //comparing the received packet to the aggregated packet
  130. LOG_MSG_DEBUG("Checking sent.vs.received packet\n");
  131. bTestResult &= !memcmp(pExpectedAggregatedPacket, pReceivedPacket,
  132. sizeof(pReceivedPacket));
  133. return bTestResult;
  134. }
  135. /////////////////////////////////////////////////////////////////////////////////
  136. };
  137. /////////////////////////////////////////////////////////////////////////////////
  138. /////////////////////////////////////////////////////////////////////////////////
  139. /////////////////////////////////////////////////////////////////////////////////
  140. class TLPDeaggregationTest: public TLPAggregationTestFixture {
  141. public:
  142. /////////////////////////////////////////////////////////////////////////////////
  143. TLPDeaggregationTest()
  144. {
  145. m_name = "TLPDeaggregationTest";
  146. m_description = "TLP Deaggregation test - sends an aggregated packet made from"
  147. "5 packets and receives 5 packets";
  148. }
  149. /////////////////////////////////////////////////////////////////////////////////
  150. bool Run()
  151. {
  152. bool bTestResult = true;
  153. //The packets that the aggregated packet will be made of
  154. Byte pExpectedPackets[NUM_PACKETS][MAX_PACKET_SIZE];
  155. //The real sizes of the packets that the aggregated packet will be made of
  156. int pPacketsSizes[NUM_PACKETS];
  157. //Buffers for the packets that will be received
  158. Byte pReceivedPackets[NUM_PACKETS][MAX_PACKET_SIZE];
  159. //Total size of all the packets that the aggregated packet will be made of
  160. //(this is the max size of the aggregated packet
  161. //minus 2 bytes for each packet in the aggregated packet)
  162. int nTotalPacketsSize = MAX_PACKET_SIZE - (2 * NUM_PACKETS);
  163. //The aggregated packet that will be sent
  164. Byte pAggregatedPacket[MAX_PACKET_SIZE] = {0};
  165. //initialize the packets
  166. //example: for NUM_PACKETS = 5 and MAX_PACKET_SIZE = 1024:
  167. //nTotalPacketsSize will be 1024 - 5*2 = 1014
  168. //packets[0] size will be 1014/5 = 202 bytes of 0
  169. //packets[1] size will be (1014 - 202) / 5 = 162 bytes of 1
  170. //packets[2] size will be (1014 - 201 - 162) / 5 = 130 bytes of 2
  171. //packets[3] size will be (1014 - 201 - 162 - 130) / 5 = 104 bytes of 3
  172. //packets[4] size will be 1014 - 201 - 162 - 130 - 104 = 416 bytes of 4
  173. for (int i = 0; i < NUM_PACKETS; i++)
  174. {
  175. if (NUM_PACKETS - 1 == i)
  176. pPacketsSizes[i] = nTotalPacketsSize;
  177. else
  178. pPacketsSizes[i] = nTotalPacketsSize / NUM_PACKETS;
  179. nTotalPacketsSize -= pPacketsSizes[i];
  180. for (int j = 0; j < pPacketsSizes[i]; j++)
  181. pExpectedPackets[i][j] = i+ 16*test_num;
  182. }
  183. test_num++;
  184. //initializing the aggregated packet
  185. int k = 0;
  186. for (int i = 0; i < NUM_PACKETS; i++)
  187. {
  188. //the first 2 bytes are the packet length in little endian
  189. pAggregatedPacket[k] = pPacketsSizes[i] & 0x00FF;
  190. pAggregatedPacket[k+1] = pPacketsSizes[i] >> 8;
  191. k += 2;
  192. for (int j = 0; j < pPacketsSizes[i]; j++)
  193. {
  194. pAggregatedPacket[k] = pExpectedPackets[i][j];
  195. k++;
  196. }
  197. }
  198. //send the aggregated packet
  199. LOG_MSG_DEBUG("Sending aggregated packet into the USB pipe(%d bytes)\n",
  200. sizeof(pAggregatedPacket));
  201. int nBytesSent = m_UsbDeaggToIpaPipeNoAgg.Send(pAggregatedPacket,
  202. sizeof(pAggregatedPacket));
  203. if (sizeof(pAggregatedPacket) != nBytesSent)
  204. {
  205. LOG_MSG_DEBUG("Sending aggregated packet into the USB pipe(%d bytes) "
  206. "failed!\n", sizeof(pAggregatedPacket));
  207. return false;
  208. }
  209. //receive the packets
  210. for (int i = 0; i < NUM_PACKETS; i++)
  211. {
  212. LOG_MSG_DEBUG("Reading packet %d from the USB pipe(%d bytes should be "
  213. "there)\n", i, pPacketsSizes[i]);
  214. int nBytesReceived = m_IpaToUsbPipeNoAgg.Receive(pReceivedPackets[i],
  215. pPacketsSizes[i]);
  216. if (pPacketsSizes[i] != nBytesReceived)
  217. {
  218. LOG_MSG_DEBUG("Receiving packet %d from the USB pipe(%d bytes) "
  219. "failed!\n", i, pPacketsSizes[i]);
  220. print_buff(pReceivedPackets[i], nBytesReceived);
  221. return false;
  222. }
  223. }
  224. //comparing the received packet to the aggregated packet
  225. LOG_MSG_DEBUG("Checking sent.vs.received packet\n");
  226. for (int i = 0; i < NUM_PACKETS; i++)
  227. bTestResult &= !memcmp(pExpectedPackets[i], pReceivedPackets[i], pPacketsSizes[i]);
  228. return bTestResult;
  229. }
  230. /////////////////////////////////////////////////////////////////////////////////
  231. };
  232. /////////////////////////////////////////////////////////////////////////////////
  233. /////////////////////////////////////////////////////////////////////////////////
  234. /////////////////////////////////////////////////////////////////////////////////
  235. class TLPDeaggregationAndAggregationTest: public TLPAggregationTestFixture {
  236. public:
  237. /////////////////////////////////////////////////////////////////////////////////
  238. TLPDeaggregationAndAggregationTest()
  239. {
  240. m_name = "TLPDeaggregationAndAggregationTest";
  241. m_description = "TLP Deaggregation and Aggregation test - sends an aggregated "
  242. "packet made from 5 packets and receives the same aggregated packet";
  243. }
  244. /////////////////////////////////////////////////////////////////////////////////
  245. bool Run()
  246. {
  247. bool bTestResult = true;
  248. //The packets that the aggregated packet will be made of
  249. Byte pPackets[NUM_PACKETS][MAX_PACKET_SIZE];
  250. //The real sizes of the packets that the aggregated packet will be made of
  251. int pPacketsSizes[NUM_PACKETS];
  252. //Buffers for the packets that will be received
  253. Byte pReceivedPacket[MAX_PACKET_SIZE];
  254. //Total size of all the packets that the aggregated packet will be made of
  255. //(this is the max size of the aggregated packet
  256. //minus 2 bytes for each packet in the aggregated packet)
  257. int nTotalPacketsSize = MAX_PACKET_SIZE - (2 * NUM_PACKETS);
  258. //The aggregated packet that will be sent
  259. Byte pAggregatedPacket[MAX_PACKET_SIZE] = {0};
  260. //initialize the packets
  261. //example: for NUM_PACKETS = 5 and MAX_PACKET_SIZE = 1024:
  262. //nTotalPacketsSize will be 1024 - 5*2 = 1014
  263. //packets[0] size will be 1014/5 = 202 bytes of 0
  264. //packets[1] size will be (1014 - 202) / 5 = 162 bytes of 1
  265. //packets[2] size will be (1014 - 201 - 162) / 5 = 130 bytes of 2
  266. //packets[3] size will be (1014 - 201 - 162 - 130) / 5 = 104 bytes of 3
  267. //packets[4] size will be 1014 - 201 - 162 - 130 - 104 = 416 bytes of 4
  268. for (int i = 0; i < NUM_PACKETS; i++)
  269. {
  270. if (NUM_PACKETS - 1 == i)
  271. pPacketsSizes[i] = nTotalPacketsSize;
  272. else
  273. pPacketsSizes[i] = nTotalPacketsSize / NUM_PACKETS;
  274. nTotalPacketsSize -= pPacketsSizes[i];
  275. for (int j = 0; j < pPacketsSizes[i]; j++)
  276. pPackets[i][j] = i+ 16*test_num;
  277. }
  278. test_num++;
  279. //initializing the aggregated packet
  280. int k = 0;
  281. for (int i = 0; i < NUM_PACKETS; i++)
  282. {
  283. //the first 2 bytes are the packet length in little endian
  284. pAggregatedPacket[k] = pPacketsSizes[i] & 0x00FF;
  285. pAggregatedPacket[k+1] = pPacketsSizes[i] >> 8;
  286. k += 2;
  287. for (int j = 0; j < pPacketsSizes[i]; j++)
  288. {
  289. pAggregatedPacket[k] = pPackets[i][j];
  290. k++;
  291. }
  292. }
  293. //send the aggregated packet
  294. LOG_MSG_DEBUG("Sending aggregated packet into the USB pipe(%d bytes)\n",
  295. sizeof(pAggregatedPacket));
  296. int nBytesSent = m_UsbDeaggToIpaPipeAgg.Send(pAggregatedPacket,
  297. sizeof(pAggregatedPacket));
  298. if (sizeof(pAggregatedPacket) != nBytesSent)
  299. {
  300. LOG_MSG_DEBUG("Sending aggregated packet into the USB pipe(%d bytes)"
  301. " failed!\n", sizeof(pAggregatedPacket));
  302. return false;
  303. }
  304. //receive the aggregated packet
  305. LOG_MSG_DEBUG("Reading aggregated packet from the USB pipe(%d bytes "
  306. "should be there)\n", sizeof(pAggregatedPacket));
  307. int nBytesReceived = m_IpaToUsbPipeAggr.Receive(pReceivedPacket,
  308. sizeof(pAggregatedPacket));
  309. if (sizeof(pAggregatedPacket) != nBytesReceived)
  310. {
  311. LOG_MSG_DEBUG("Receiving aggregated packet from the USB pipe(%d "
  312. "bytes) failed!\n", sizeof(pAggregatedPacket));
  313. LOG_MSG_DEBUG("Received %d bytes\n", nBytesReceived);
  314. print_buff(pReceivedPacket, nBytesReceived);
  315. return false;
  316. }
  317. print_buff(pReceivedPacket, nBytesReceived);
  318. //comparing the received packet to the aggregated packet
  319. LOG_MSG_DEBUG("Checking sent.vs.received packet\n");
  320. bTestResult &= !memcmp(pAggregatedPacket, pReceivedPacket,
  321. sizeof(pReceivedPacket));
  322. return bTestResult;
  323. }
  324. /////////////////////////////////////////////////////////////////////////////////
  325. };
  326. /////////////////////////////////////////////////////////////////////////////////
  327. /////////////////////////////////////////////////////////////////////////////////
  328. /////////////////////////////////////////////////////////////////////////////////
  329. class TLPAggregationLoopTest: public TLPAggregationTestFixture {
  330. public:
  331. /////////////////////////////////////////////////////////////////////////////////
  332. TLPAggregationLoopTest()
  333. {
  334. m_name = "TLPAggregationLoopTest";
  335. m_description = "TLP Aggregation Loop test - sends 5 packets and expects to"
  336. "receives 1 aggregated packet a few times";
  337. }
  338. /////////////////////////////////////////////////////////////////////////////////
  339. bool Run()
  340. {
  341. //The packets that will be sent
  342. Byte pPackets[NUM_PACKETS][MAX_PACKET_SIZE];
  343. //The real sizes of the packets that will be sent
  344. int pPacketsSizes[NUM_PACKETS];
  345. //Buffer for the packet that will be received
  346. Byte pReceivedPacket[MAX_PACKET_SIZE];
  347. //Total size of all sent packets (this is the max size of the aggregated packet
  348. //minus 2 bytes for each packet in the aggregated packet)
  349. int nTotalPacketsSize = MAX_PACKET_SIZE - (2 * NUM_PACKETS);
  350. //The expected aggregated packet
  351. Byte pExpectedAggregatedPacket[MAX_PACKET_SIZE] = {0};
  352. //initialize the packets
  353. //example: for NUM_PACKETS = 5 and MAX_PACKET_SIZE = 1024:
  354. //nTotalPacketsSize will be 1024 - 5*2 = 1014
  355. //packets[0] size will be 1014/5 = 202 bytes of 0
  356. //packets[1] size will be (1014 - 202) / 5 = 162 bytes of 1
  357. //packets[2] size will be (1014 - 201 - 162) / 5 = 130 bytes of 2
  358. //packets[3] size will be (1014 - 201 - 162 - 130) / 5 = 104 bytes of 3
  359. //packets[4] size will be 1014 - 201 - 162 - 130 - 104 = 416 bytes of 4
  360. for (int i = 0; i < NUM_PACKETS; i++)
  361. {
  362. if (NUM_PACKETS - 1 == i)
  363. pPacketsSizes[i] = nTotalPacketsSize;
  364. else
  365. pPacketsSizes[i] = nTotalPacketsSize / NUM_PACKETS;
  366. nTotalPacketsSize -= pPacketsSizes[i];
  367. for (int j = 0; j < pPacketsSizes[i]; j++)
  368. pPackets[i][j] = i+ 16*test_num;
  369. }
  370. test_num++;
  371. //initializing the aggregated packet
  372. int k = 0;
  373. for (int i = 0; i < NUM_PACKETS; i++)
  374. {
  375. //the first 2 bytes are the packet length in little endian
  376. pExpectedAggregatedPacket[k] = pPacketsSizes[i] & 0x00FF;
  377. pExpectedAggregatedPacket[k+1] = pPacketsSizes[i] >> 8;
  378. k += 2;
  379. for (int j = 0; j < pPacketsSizes[i]; j++)
  380. {
  381. pExpectedAggregatedPacket[k] = pPackets[i][j];
  382. k++;
  383. }
  384. }
  385. for (int j = 0; j < AGGREGATION_LOOP; j++)
  386. {
  387. //send the packets
  388. for (int i = 0; i < NUM_PACKETS; i++)
  389. {
  390. LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d bytes)\n",
  391. i, pPacketsSizes[i]);
  392. int nBytesSent = m_UsbNoAggToIpaPipeAgg.Send(pPackets[i],
  393. pPacketsSizes[i]);
  394. if (pPacketsSizes[i] != nBytesSent)
  395. {
  396. LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d bytes) "
  397. "failed!\n", i, pPacketsSizes[i]);
  398. return false;
  399. }
  400. }
  401. memset(pReceivedPacket, 0, sizeof(pReceivedPacket));
  402. //receive the aggregated packet
  403. LOG_MSG_DEBUG("Reading packet from the USB pipe(%d bytes should be "
  404. "there)\n", MAX_PACKET_SIZE);
  405. int nBytesReceived = m_IpaToUsbPipeAggr.Receive(pReceivedPacket,
  406. MAX_PACKET_SIZE);
  407. if (MAX_PACKET_SIZE != nBytesReceived)
  408. {
  409. LOG_MSG_DEBUG("Receiving aggregated packet from the USB pipe(%d "
  410. "bytes) failed!\n", MAX_PACKET_SIZE);
  411. return false;
  412. }
  413. //comparing the received packet to the aggregated packet
  414. LOG_MSG_DEBUG("Checking sent.vs.received packet\n");
  415. if (0 != memcmp(pExpectedAggregatedPacket, pReceivedPacket,
  416. sizeof(pReceivedPacket)))
  417. {
  418. LOG_MSG_DEBUG("Comparison of packet %d failed!\n", j);
  419. return false;
  420. }
  421. }
  422. return true;
  423. }
  424. /////////////////////////////////////////////////////////////////////////////////
  425. };
  426. /////////////////////////////////////////////////////////////////////////////////
  427. /////////////////////////////////////////////////////////////////////////////////
  428. /////////////////////////////////////////////////////////////////////////////////
  429. class TLPAggregationTimeLimitTest: public TLPAggregationTestFixture {
  430. public:
  431. /////////////////////////////////////////////////////////////////////////////////
  432. TLPAggregationTimeLimitTest()
  433. {
  434. m_name = "TLPAggregationTimeLimitTest";
  435. m_description = "TLP Aggregation time limit test - sends 1 packet "
  436. "smaller than the byte limit and receives 1 aggregated packet";
  437. }
  438. /////////////////////////////////////////////////////////////////////////////////
  439. bool Run()
  440. {
  441. bool bTestResult = true;
  442. //The packets that will be sent
  443. Byte pPackets[TIME_LIMIT_NUM_PACKETS][MAX_PACKET_SIZE];
  444. //The real sizes of the packets that will be sent
  445. int pPacketsSizes[TIME_LIMIT_NUM_PACKETS];
  446. //Buffer for the packet that will be received
  447. Byte pReceivedPacket[MAX_PACKET_SIZE] = {0};
  448. //The expected aggregated packet
  449. Byte pExpectedAggregatedPacket[MAX_PACKET_SIZE] = {0};
  450. //Size of aggregated packet
  451. int nTotalPacketsSize = 0;
  452. //initialize the packets
  453. for (int i = 0; i < TIME_LIMIT_NUM_PACKETS; i++)
  454. {
  455. pPacketsSizes[i] = i + 1;
  456. nTotalPacketsSize += pPacketsSizes[i] + 2; //size of the packet + 2 bytes for length
  457. for (int j = 0; j < pPacketsSizes[i]; j++)
  458. pPackets[i][j] = i+ 16*test_num;
  459. }
  460. test_num++;
  461. //send the packets
  462. for (int i = 0; i < TIME_LIMIT_NUM_PACKETS; i++)
  463. {
  464. LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d bytes)\n", i,
  465. pPacketsSizes[i]);
  466. int nBytesSent = m_UsbNoAggToIpaPipeAggTime.Send(pPackets[i],
  467. pPacketsSizes[i]);
  468. if (pPacketsSizes[i] != nBytesSent)
  469. {
  470. LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d bytes) "
  471. "failed!\n", i, pPacketsSizes[i]);
  472. return false;
  473. }
  474. }
  475. //receive the aggregated packet
  476. LOG_MSG_DEBUG("Reading packet from the USB pipe(%d bytes should be "
  477. "there)\n", nTotalPacketsSize);
  478. int nBytesReceived = m_IpaToUsbPipeAggTime.Receive(pReceivedPacket,
  479. nTotalPacketsSize);
  480. if (nTotalPacketsSize != nBytesReceived)
  481. {
  482. LOG_MSG_DEBUG("Receiving aggregated packet from the USB pipe(%d "
  483. "bytes) failed!\n", nTotalPacketsSize);
  484. print_buff(pReceivedPacket, nBytesReceived);
  485. return false;
  486. }
  487. //initializing the aggregated packet
  488. int k = 0;
  489. for (int i = 0; i < TIME_LIMIT_NUM_PACKETS; i++)
  490. {
  491. //the first 2 bytes are the packet length in little endian
  492. pExpectedAggregatedPacket[k] = pPacketsSizes[i] & 0x00FF;
  493. pExpectedAggregatedPacket[k+1] = pPacketsSizes[i] >> 8;
  494. k += 2;
  495. for (int j = 0; j < pPacketsSizes[i]; j++)
  496. {
  497. pExpectedAggregatedPacket[k] = pPackets[i][j];
  498. k++;
  499. }
  500. }
  501. //comparing the received packet to the aggregated packet
  502. LOG_MSG_DEBUG("Checking sent.vs.received packet\n");
  503. bTestResult &= !memcmp(pExpectedAggregatedPacket, pReceivedPacket,
  504. sizeof(pReceivedPacket));
  505. return bTestResult;
  506. }
  507. /////////////////////////////////////////////////////////////////////////////////
  508. };
  509. /////////////////////////////////////////////////////////////////////////////////
  510. /////////////////////////////////////////////////////////////////////////////////
  511. /////////////////////////////////////////////////////////////////////////////////
  512. class TLPAggregationByteLimitTest: public TLPAggregationTestFixture {
  513. public:
  514. /////////////////////////////////////////////////////////////////////////////////
  515. TLPAggregationByteLimitTest()
  516. {
  517. m_name = "TLPAggregationByteLimitTest";
  518. m_description = "TLP Aggregation byte limit test - sends 2 packets that together "
  519. "are larger than the byte limit ";
  520. }
  521. /////////////////////////////////////////////////////////////////////////////////
  522. bool Run()
  523. {
  524. bool bTestResult = true;
  525. //The packets that will be sent
  526. Byte pPackets[2][MAX_PACKET_SIZE];
  527. //The real sizes of the packets that will be sent
  528. int pPacketsSizes[2];
  529. //Buffer for the packet that will be received
  530. Byte pReceivedPacket[2*MAX_PACKET_SIZE] = {0};
  531. //The expected aggregated packet
  532. Byte pExpectedAggregatedPacket[2*MAX_PACKET_SIZE] = {0};
  533. //Size of aggregated packet
  534. int nTotalPacketsSize = 0;
  535. //initialize the packets
  536. for (int i = 0; i < 2; i++)
  537. {
  538. pPacketsSizes[i] = (MAX_PACKET_SIZE / 2) + 10;
  539. nTotalPacketsSize += pPacketsSizes[i] + 2;
  540. for (int j = 0; j < pPacketsSizes[i]; j++)
  541. pPackets[i][j] = i+ 16*test_num;
  542. }
  543. test_num++;
  544. //send the packets
  545. for (int i = 0; i < 2; i++)
  546. {
  547. LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d bytes)\n", i,
  548. pPacketsSizes[i]);
  549. int nBytesSent = m_UsbNoAggToIpaPipeAgg.Send(pPackets[i],
  550. pPacketsSizes[i]);
  551. if (pPacketsSizes[i] != nBytesSent)
  552. {
  553. LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d bytes) "
  554. "failed!\n", i, pPacketsSizes[i]);
  555. return false;
  556. }
  557. }
  558. //receive the aggregated packet
  559. LOG_MSG_DEBUG("Reading packet from the USB pipe(%d bytes should be "
  560. "there)\n", nTotalPacketsSize);
  561. int nBytesReceived = m_IpaToUsbPipeAggr.Receive(pReceivedPacket,
  562. nTotalPacketsSize);
  563. if (nTotalPacketsSize != nBytesReceived)
  564. {
  565. LOG_MSG_DEBUG("Receiving aggregated packet from the USB pipe(%d"
  566. " bytes) failed!\n", nTotalPacketsSize);
  567. print_buff(pReceivedPacket, nBytesReceived);
  568. return false;
  569. }
  570. //initializing the aggregated packet
  571. int k = 0;
  572. for (int i = 0; i < 2; i++)
  573. {
  574. //the first 2 bytes are the packet length in little endian
  575. pExpectedAggregatedPacket[k] = pPacketsSizes[i] & 0x00FF;
  576. pExpectedAggregatedPacket[k+1] = pPacketsSizes[i] >> 8;
  577. k += 2;
  578. for (int j = 0; j < pPacketsSizes[i]; j++)
  579. {
  580. pExpectedAggregatedPacket[k] = pPackets[i][j];
  581. k++;
  582. }
  583. }
  584. //comparing the received packet to the aggregated packet
  585. LOG_MSG_DEBUG("Checking sent.vs.received packet\n");
  586. bTestResult &= !memcmp(pExpectedAggregatedPacket, pReceivedPacket,
  587. sizeof(pReceivedPacket));
  588. return bTestResult;
  589. }
  590. /////////////////////////////////////////////////////////////////////////////////
  591. };
  592. /////////////////////////////////////////////////////////////////////////////////
  593. /////////////////////////////////////////////////////////////////////////////////
  594. /////////////////////////////////////////////////////////////////////////////////
  595. class TLPAggregation2PipesTest: public TLPAggregationTestFixture {
  596. public:
  597. /////////////////////////////////////////////////////////////////////////////////
  598. TLPAggregation2PipesTest()
  599. {
  600. m_name = "TLPAggregation2PipesTest";
  601. m_description = "TLP Aggregation 2 pipes test - sends 3 packets from one pipe"
  602. "and an aggregated packet made of 2 packets from another pipe and "
  603. "receives 1 aggregated packet made of all 5 packets";
  604. }
  605. /////////////////////////////////////////////////////////////////////////////////
  606. bool Run()
  607. {
  608. bool bTestResult = true;
  609. //The packets that will be sent
  610. Byte pPackets[NUM_PACKETS][MAX_PACKET_SIZE];
  611. //The real sizes of the packets that will be sent
  612. int pPacketsSizes[NUM_PACKETS];
  613. //Buffer for the packet that will be received
  614. Byte pReceivedPacket[MAX_PACKET_SIZE];
  615. //Total size of all sent packets (this is the max size of the aggregated packet
  616. //minus 2 bytes for each packet in the aggregated packet)
  617. int nTotalPacketsSize = MAX_PACKET_SIZE - (2 * NUM_PACKETS);
  618. //The expected aggregated packet
  619. Byte pExpectedAggregatedPacket[MAX_PACKET_SIZE] = {0};
  620. //The aggregated packet that will be sent
  621. Byte pAggregatedPacket[MAX_PACKET_SIZE] = {0};
  622. //The size of the sent aggregated packet
  623. int nAggregatedPacketSize = 0;
  624. //initialize the packets
  625. //example: for NUM_PACKETS = 5 and MAX_PACKET_SIZE = 1024:
  626. //nTotalPacketsSize will be 1024 - 5*2 = 1014
  627. //packets[0] size will be 1014/5 = 202 bytes of 0
  628. //packets[1] size will be (1014 - 202) / 5 = 162 bytes of 1
  629. //packets[2] size will be (1014 - 201 - 162) / 5 = 130 bytes of 2
  630. //packets[3] size will be (1014 - 201 - 162 - 130) / 5 = 104 bytes of 3
  631. //packets[4] size will be 1014 - 201 - 162 - 130 - 104 = 416 bytes of 4
  632. for (int i = 0; i < NUM_PACKETS; i++)
  633. {
  634. if (NUM_PACKETS - 1 == i)
  635. pPacketsSizes[i] = nTotalPacketsSize;
  636. else
  637. pPacketsSizes[i] = nTotalPacketsSize / NUM_PACKETS;
  638. nTotalPacketsSize -= pPacketsSizes[i];
  639. for (int j = 0; j < pPacketsSizes[i]; j++)
  640. pPackets[i][j] = i+ 16*test_num;
  641. }
  642. test_num++;
  643. //initializing the aggregated packet
  644. int k = 0;
  645. for (int i = 0; i < 2; i++)
  646. {
  647. nAggregatedPacketSize += pPacketsSizes[i] + 2;
  648. //the first 2 bytes are the packet length in little endian
  649. pAggregatedPacket[k] = pPacketsSizes[i] & 0x00FF;
  650. pAggregatedPacket[k+1] = pPacketsSizes[i] >> 8;
  651. k += 2;
  652. for (int j = 0; j < pPacketsSizes[i]; j++)
  653. {
  654. pAggregatedPacket[k] = pPackets[i][j];
  655. k++;
  656. }
  657. }
  658. //send the aggregated packet
  659. LOG_MSG_DEBUG("Sending aggregated packet into the USB pipe(%d "
  660. "bytes)\n", nAggregatedPacketSize);
  661. int nBytesSent = m_UsbDeaggToIpaPipeAgg.Send(pAggregatedPacket,
  662. nAggregatedPacketSize);
  663. if (nAggregatedPacketSize != nBytesSent)
  664. {
  665. LOG_MSG_DEBUG("Sending aggregated packet into the USB pipe(%d "
  666. "bytes) failed!\n", nAggregatedPacketSize);
  667. return false;
  668. }
  669. //send the packets
  670. for (int i = 2; i < NUM_PACKETS; i++)
  671. {
  672. LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d bytes)\n", i,
  673. pPacketsSizes[i]);
  674. int nBytesSent = m_UsbNoAggToIpaPipeAgg.Send(pPackets[i],
  675. pPacketsSizes[i]);
  676. if (pPacketsSizes[i] != nBytesSent)
  677. {
  678. LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d bytes) "
  679. "failed!\n", i, pPacketsSizes[i]);
  680. return false;
  681. }
  682. }
  683. //receive the aggregated packet
  684. LOG_MSG_DEBUG("Reading packet from the USB pipe(%d bytes should be "
  685. "there)\n", MAX_PACKET_SIZE);
  686. int nBytesReceived = m_IpaToUsbPipeAggr.Receive(pReceivedPacket,
  687. MAX_PACKET_SIZE);
  688. if (MAX_PACKET_SIZE != nBytesReceived)
  689. {
  690. LOG_MSG_DEBUG("Receiving aggregated packet from the USB pipe(%d "
  691. "bytes) failed!\n", MAX_PACKET_SIZE);
  692. print_buff(pReceivedPacket, nBytesReceived);
  693. return false;
  694. }
  695. //initializing the aggregated packet
  696. k = 0;
  697. for (int i = 0; i < NUM_PACKETS; i++)
  698. {
  699. //the first 2 bytes are the packet length in little endian
  700. pExpectedAggregatedPacket[k] = pPacketsSizes[i] & 0x00FF;
  701. pExpectedAggregatedPacket[k+1] = pPacketsSizes[i] >> 8;
  702. k += 2;
  703. for (int j = 0; j < pPacketsSizes[i]; j++)
  704. {
  705. pExpectedAggregatedPacket[k] = pPackets[i][j];
  706. k++;
  707. }
  708. }
  709. //comparing the received packet to the aggregated packet
  710. LOG_MSG_DEBUG("Checking sent.vs.received packet\n");
  711. bTestResult &= !memcmp(pExpectedAggregatedPacket, pReceivedPacket,
  712. sizeof(pReceivedPacket));
  713. return bTestResult;
  714. }
  715. /////////////////////////////////////////////////////////////////////////////////
  716. };
  717. /////////////////////////////////////////////////////////////////////////////////
  718. /////////////////////////////////////////////////////////////////////////////////
  719. /////////////////////////////////////////////////////////////////////////////////
  720. class TLPAggregationTimeLimitLoopTest: public TLPAggregationTestFixture {
  721. public:
  722. /////////////////////////////////////////////////////////////////////////////////
  723. TLPAggregationTimeLimitLoopTest()
  724. {
  725. m_name = "TLPAggregationTimeLimitLoopTest";
  726. m_description = "TLP Aggregation time limit loop test - sends 1 packet "
  727. "smaller than the byte limit and receives 1 aggregated packets";
  728. }
  729. /////////////////////////////////////////////////////////////////////////////////
  730. bool Run()
  731. {
  732. //The packets that will be sent
  733. Byte pPackets[TIME_LIMIT_NUM_PACKETS][MAX_PACKET_SIZE];
  734. //The real sizes of the packets that will be sent
  735. int pPacketsSizes[TIME_LIMIT_NUM_PACKETS];
  736. //Buffer for the packet that will be received
  737. Byte pReceivedPacket[MAX_PACKET_SIZE] = {0};
  738. //The expected aggregated packet
  739. Byte pExpectedAggregatedPacket[MAX_PACKET_SIZE] = {0};
  740. //Size of aggregated packet
  741. int nTotalPacketsSize = 0;
  742. //initialize the packets
  743. for (int i = 0; i < TIME_LIMIT_NUM_PACKETS; i++)
  744. {
  745. pPacketsSizes[i] = i + 1;
  746. nTotalPacketsSize += pPacketsSizes[i] + 2; //size of the packet + 2 bytes for length
  747. for (int j = 0; j < pPacketsSizes[i]; j++)
  748. pPackets[i][j] = i+ 16*test_num;
  749. }
  750. test_num++;
  751. for (int n = 0; n < NUM_PACKETS; n++)
  752. {
  753. //send the packets
  754. for (int i = 0; i < TIME_LIMIT_NUM_PACKETS; i++)
  755. {
  756. LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d bytes)\n",
  757. i, pPacketsSizes[i]);
  758. int nBytesSent = m_UsbNoAggToIpaPipeAggTime.Send(pPackets[i],
  759. pPacketsSizes[i]);
  760. if (pPacketsSizes[i] != nBytesSent)
  761. {
  762. LOG_MSG_DEBUG("Sending packet %d into the USB pipe(%d "
  763. "bytes) failed!\n", i, pPacketsSizes[i]);
  764. return false;
  765. }
  766. }
  767. //receive the aggregated packet
  768. LOG_MSG_DEBUG("Reading packet from the USB pipe(%d bytes should be "
  769. "there)\n", nTotalPacketsSize);
  770. int nBytesReceived = m_IpaToUsbPipeAggTime.Receive(pReceivedPacket,
  771. nTotalPacketsSize);
  772. if (nTotalPacketsSize != nBytesReceived)
  773. {
  774. LOG_MSG_DEBUG("Receiving aggregated packet from the USB pipe(%d "
  775. "bytes) failed!\n", nTotalPacketsSize);
  776. print_buff(pReceivedPacket, nBytesReceived);
  777. return false;
  778. }
  779. //initializing the aggregated packet
  780. int k = 0;
  781. for (int i = 0; i < TIME_LIMIT_NUM_PACKETS; i++)
  782. {
  783. //the first 2 bytes are the packet length in little endian
  784. pExpectedAggregatedPacket[k] = pPacketsSizes[i] & 0x00FF;
  785. pExpectedAggregatedPacket[k+1] = pPacketsSizes[i] >> 8;
  786. k += 2;
  787. for (int j = 0; j < pPacketsSizes[i]; j++)
  788. {
  789. pExpectedAggregatedPacket[k] = pPackets[i][j];
  790. k++;
  791. }
  792. }
  793. //comparing the received packet to the aggregated packet
  794. LOG_MSG_DEBUG("Checking sent.vs.received packet\n");
  795. if (0 != memcmp(pExpectedAggregatedPacket, pReceivedPacket,
  796. sizeof(pReceivedPacket)))
  797. {
  798. LOG_MSG_DEBUG("Comparison of packet %d failed!\n", n);
  799. return false;
  800. }
  801. }
  802. return true;
  803. }
  804. /////////////////////////////////////////////////////////////////////////////////
  805. };
  806. /////////////////////////////////////////////////////////////////////////////////
  807. /////////////////////////////////////////////////////////////////////////////////
  808. /////////////////////////////////////////////////////////////////////////////////
  809. //Those tests should be run with configuration number 8.
  810. //Please look at the Fixture for more configurations update.
  811. static TLPAggregationTest tlpAggregationTest;
  812. static TLPDeaggregationTest tlpDeaggregationTest;
  813. static TLPAggregationLoopTest tlpAggregationLoopTest;
  814. static TLPAggregationTimeLimitTest tlpAggregationTimeLimitTest;
  815. static TLPAggregationByteLimitTest tlpAggregationByteLimitTest;
  816. static TLPAggregation2PipesTest tlpAggregation2PipesTest;
  817. static TLPAggregationTimeLimitLoopTest tlpAggregationTimeLimitLoopTest;
  818. static TLPDeaggregationAndAggregationTest tlpDeaggregationAndAggregationTest;
  819. /////////////////////////////////////////////////////////////////////////////////
  820. // EOF ////
  821. /////////////////////////////////////////////////////////////////////////////////