DataPathTests.cpp 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. /*
  2. * Copyright (c) 2017,2020 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 "hton.h" /* for htonl*/
  35. #include "DataPathTestFixture.h"
  36. #include "Constants.h"
  37. #include "TestsUtils.h"
  38. #include "linux/msm_ipa.h"
  39. #define PACKET_SIZE ((10)*(4))
  40. class IpaTxDpTest:public DataPathTestFixture {
  41. public:
  42. IpaTxDpTest() {
  43. m_name = "IpaTxDpTest";
  44. m_description = "Sending one SKB via ipa_tx_dp() and checking"
  45. "if it was received";
  46. m_runInRegression = true;
  47. }
  48. bool TestLogic() {
  49. LOG_MSG_DEBUG("Entering %s\n", __func__);
  50. int ret;
  51. unsigned char *input, *output;
  52. unsigned char pkt[PACKET_SIZE] = {
  53. 0x59, 0x61, 0x6e, 0x69,
  54. 0x76, 0x5f, 0x48 ,0x61,
  55. 0x73 ,0x62 ,0x61 ,0x6e,
  56. 0x69 ,0x5f ,0x54 ,0x68,
  57. 0x65 ,0x5f ,0x47 ,0x72,
  58. 0x65 ,0x61 ,0x74 ,0x16,
  59. 0x32 ,0x49 ,0x0c ,0x3f,
  60. 0x37 ,0x23 ,0x6d ,0x15,
  61. 0x50 ,0x10 ,0x3f ,0xbd,
  62. 0xcc ,0xd8 ,0x00, 0x00
  63. };
  64. input = (unsigned char *)malloc(PACKET_SIZE);
  65. if(!input) {
  66. LOG_MSG_ERROR("Error in allocation\n");
  67. goto fail;
  68. }
  69. output = (unsigned char *)malloc(PACKET_SIZE);
  70. if(!output) {
  71. LOG_MSG_ERROR("Error in allocation\n");
  72. free(input);
  73. goto fail;
  74. }
  75. memcpy(input, pkt, PACKET_SIZE);
  76. LOG_MSG_DEBUG("Sending packet through ipa_tx_dp() in func %s\n", __func__);
  77. ret = m_IpaDriverPipe.Send(input, PACKET_SIZE);
  78. if (ret != PACKET_SIZE) {
  79. LOG_MSG_ERROR(
  80. "Amount of bits sent are: %d instead of %d\nExiting..\n"
  81. , ret
  82. , PACKET_SIZE);
  83. free(input);
  84. free(output);
  85. goto fail;
  86. }
  87. ret = m_FromIPAPipe.Receive(output, PACKET_SIZE);
  88. if (ret != PACKET_SIZE) {
  89. LOG_MSG_ERROR(
  90. "Amount of bits sent are: %d instead of %d\nExiting..\n",
  91. ret,
  92. PACKET_SIZE);
  93. free(input);
  94. free(output);
  95. goto fail;
  96. }
  97. LOG_MSG_INFO("Input buff:\n");
  98. print_buff(input, PACKET_SIZE);
  99. LOG_MSG_INFO("Output buff:\n");
  100. print_buff(output, PACKET_SIZE);
  101. if (memcmp(input,output, PACKET_SIZE)) {
  102. free(input);
  103. free(output);
  104. return false;
  105. }
  106. free(input);
  107. free(output);
  108. return true;
  109. fail:
  110. return false;
  111. }
  112. };
  113. class IpaTxDpMultipleTest:public DataPathTestFixture {
  114. public:
  115. IpaTxDpMultipleTest() {
  116. m_name = "IpaTxDpMultipleTest";
  117. m_description = "Sending multiple SKB via ipa_tx_dp() and checking"
  118. "if it was received";
  119. m_runInRegression = false;
  120. }
  121. bool TestLogic() {
  122. int packet_to_send = 10;
  123. int loop_size = 100;
  124. int i;
  125. int j;
  126. LOG_MSG_DEBUG("Entering %s\n", __func__);
  127. int ret;
  128. unsigned char *input, *output;
  129. unsigned char pkt[PACKET_SIZE] = {
  130. 0x59, 0x61, 0x6e, 0x69,
  131. 0x76, 0x5f, 0x48 ,0x61,
  132. 0x73 ,0x62 ,0x61 ,0x6e,
  133. 0x69 ,0x5f ,0x54 ,0x68,
  134. 0x65 ,0x5f ,0x47 ,0x72,
  135. 0x65 ,0x61 ,0x74 ,0x16,
  136. 0x32 ,0x49 ,0x0c ,0x3f,
  137. 0x37 ,0x23 ,0x6d ,0x15,
  138. 0x50 ,0x10 ,0x3f ,0xbd,
  139. 0xcc ,0xd8 ,0x00, 0x00
  140. };
  141. input = (unsigned char *)malloc(PACKET_SIZE);
  142. if(!input) {
  143. LOG_MSG_ERROR("Error in allocation\n");
  144. goto fail;
  145. }
  146. output = (unsigned char *)malloc(PACKET_SIZE);
  147. if(!output) {
  148. LOG_MSG_ERROR("Error in allocation\n");
  149. free(input);
  150. goto fail;
  151. }
  152. memcpy(input, pkt, PACKET_SIZE);
  153. for (i = 0; i < loop_size; i++) {
  154. for (j = 0; j < packet_to_send; j++) {
  155. input[0] = i;
  156. input[1] = j;
  157. LOG_MSG_DEBUG("Sending packet through ipa_tx_dp() in func %s\n", __func__);
  158. ret = m_IpaDriverPipe.Send(input, PACKET_SIZE);
  159. if (ret != PACKET_SIZE) {
  160. LOG_MSG_ERROR(
  161. "Amount of bits sent are: %d instead of %d\nExiting..\n"
  162. , ret
  163. , PACKET_SIZE);
  164. free(input);
  165. free(output);
  166. goto fail;
  167. }
  168. }
  169. for (j = 0; j < packet_to_send; j++) {
  170. ret = m_FromIPAPipe.Receive(output, PACKET_SIZE);
  171. if (ret != PACKET_SIZE) {
  172. LOG_MSG_ERROR(
  173. "Amount of bits sent are: %d instead of %d\nExiting..\n",
  174. ret,
  175. PACKET_SIZE);
  176. free(input);
  177. free(output);
  178. goto fail;
  179. }
  180. input[0] = i;
  181. input[1] = j;
  182. LOG_MSG_INFO("Input buff:\n");
  183. print_buff(input, PACKET_SIZE);
  184. LOG_MSG_INFO("Output buff:\n");
  185. print_buff(output, PACKET_SIZE);
  186. if (memcmp(input,output, PACKET_SIZE)) {
  187. free(input);
  188. free(output);
  189. LOG_MSG_ERROR("Failed in buffers comparison");
  190. return false;
  191. }
  192. }
  193. }
  194. free(input);
  195. free(output);
  196. return true;
  197. fail:
  198. return false;
  199. }
  200. };
  201. class IPAToAppsTest:public DataPathTestFixture {
  202. public:
  203. IPAToAppsTest() {
  204. m_name = "IPAToApps";
  205. m_description = "Sending one SKB via USB_PROD pipe and checking"
  206. "if it was received";
  207. m_runInRegression = true;
  208. }
  209. bool TestLogic() {
  210. int ret;
  211. unsigned char *input, *output;
  212. unsigned char pkt[PACKET_SIZE] = {
  213. 0x59, 0x61, 0x6e, 0x69,
  214. 0x76, 0x5f, 0x48 ,0x61,
  215. 0x73 ,0x62 ,0x61 ,0x6e,
  216. 0x69 ,0x5f ,0x54 ,0x68,
  217. 0x65 ,0x5f ,0x47 ,0x72,
  218. 0x65 ,0x61 ,0x74 ,0x16,
  219. 0x32 ,0x49 ,0x0c ,0x3f,
  220. 0x37 ,0x23 ,0x6d ,0x15,
  221. 0x50 ,0x10 ,0x3f ,0xbd,
  222. 0xcc ,0xd8 ,0x00, 0x00
  223. };
  224. input = (unsigned char *)malloc(PACKET_SIZE);
  225. if(!input) {
  226. LOG_MSG_ERROR("Error in allocation\n");
  227. goto fail;
  228. }
  229. output = (unsigned char *)malloc(PACKET_SIZE);
  230. if(!output) {
  231. LOG_MSG_ERROR("Error in allocation\n");
  232. free(input);
  233. goto fail;
  234. }
  235. memcpy(input, pkt, PACKET_SIZE);
  236. LOG_MSG_DEBUG("Sending packet through USB_PROD pipe in func %s\n", __func__);
  237. ret = m_ToIpaPipe.Send(input, PACKET_SIZE);
  238. if (ret != PACKET_SIZE) {
  239. LOG_MSG_ERROR(
  240. "Amount of bits sent are: %d instead of %d\nExiting..\n",
  241. ret,
  242. PACKET_SIZE);
  243. goto fail;
  244. }
  245. LOG_MSG_DEBUG("Reading packet through Dummy Endpoint pipe in func %s\n", __func__);
  246. ret = m_IpaDriverPipe.Receive(output, PACKET_SIZE);
  247. if (ret != 0) {
  248. LOG_MSG_ERROR("Failed in reading buffer. %d error", ret);
  249. free(input);
  250. free(output);
  251. goto fail;
  252. }
  253. LOG_MSG_DEBUG("SKB original packet:\n");
  254. print_buff(input, PACKET_SIZE);
  255. LOG_MSG_DEBUG("SKB received packet:\n");
  256. print_buff(output, PACKET_SIZE);
  257. if (memcmp(input,output, PACKET_SIZE)) {
  258. free(input);
  259. free(output);
  260. return false;
  261. }
  262. free(input);
  263. free(output);
  264. return true;
  265. fail:
  266. return false;
  267. }
  268. };
  269. class IPAToAppsMultipleTest:public DataPathTestFixture {
  270. public:
  271. IPAToAppsMultipleTest() {
  272. m_name = "IPAToAppsMultipleTest";
  273. m_description = "Sending multiple SKB via USB_PROD pipe and checking"
  274. "if they was received";
  275. m_runInRegression = false;
  276. }
  277. bool TestLogic() {
  278. int packet_to_send = 10;
  279. int loop_size = 100;
  280. int i;
  281. int j;
  282. int ret;
  283. unsigned char *input, *output;
  284. unsigned char pkt[PACKET_SIZE] = {
  285. 0x59, 0x61, 0x6e, 0x69,
  286. 0x76, 0x5f, 0x48 ,0x61,
  287. 0x73 ,0x62 ,0x61 ,0x6e,
  288. 0x69 ,0x5f ,0x54 ,0x68,
  289. 0x65 ,0x5f ,0x47 ,0x72,
  290. 0x65 ,0x61 ,0x74 ,0x16,
  291. 0x32 ,0x49 ,0x0c ,0x3f,
  292. 0x37 ,0x23 ,0x6d ,0x15,
  293. 0x50 ,0x10 ,0x3f ,0xbd,
  294. 0xcc ,0xd8 ,0x00, 0x00
  295. };
  296. input = (unsigned char *)malloc(PACKET_SIZE);
  297. if(!input) {
  298. LOG_MSG_ERROR("Error in allocation\n");
  299. goto fail;
  300. }
  301. output = (unsigned char *)malloc(PACKET_SIZE);
  302. if(!output) {
  303. LOG_MSG_ERROR("Error in allocation\n");
  304. free(input);
  305. goto fail;
  306. }
  307. memcpy(input, pkt, PACKET_SIZE);
  308. for (i = 0; i < loop_size; i++) {
  309. for (j = 0; j < packet_to_send; j++) {
  310. input[0] = i;
  311. input[1] = j;
  312. LOG_MSG_DEBUG("Sending packet through USB_PROD pipe in func %s\n", __func__);
  313. ret = m_ToIpaPipe.Send(input, PACKET_SIZE);
  314. if (ret != PACKET_SIZE) {
  315. LOG_MSG_ERROR(
  316. "Amount of bits sent are: %d instead of %d\nExiting..\n",
  317. ret,
  318. PACKET_SIZE);
  319. free(input);
  320. free(output);
  321. goto fail;
  322. }
  323. }
  324. for (j = 0; j < packet_to_send; j++) {
  325. input[0] = i;
  326. input[1] = j;
  327. LOG_MSG_DEBUG("Reading packet through Dummy Endpoint pipe in func %s\n", __func__);
  328. ret = m_IpaDriverPipe.Receive(output, PACKET_SIZE);
  329. if (ret != 0) {
  330. LOG_MSG_ERROR("Failed in reading buffer. %d error", ret);
  331. free(input);
  332. free(output);
  333. goto fail;
  334. }
  335. LOG_MSG_DEBUG("SKB original packet:\n");
  336. print_buff(input, PACKET_SIZE);
  337. LOG_MSG_DEBUG("SKB received packet:\n");
  338. print_buff(output, PACKET_SIZE);
  339. if (memcmp(input,output, PACKET_SIZE)) {
  340. free(input);
  341. free(output);
  342. LOG_MSG_ERROR("Failed in buffers comparison");
  343. return false;
  344. }
  345. }
  346. }
  347. free(input);
  348. free(output);
  349. return true;
  350. fail:
  351. return false;
  352. }
  353. };
  354. static IpaTxDpTest ipaTxDpTest;
  355. static IpaTxDpMultipleTest ipaTxDpMultipleTest;
  356. static IPAToAppsTest ipaToApps;
  357. static IPAToAppsMultipleTest iPAToAppsMultipleTestApps;