utils_for_testing.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. /*********************************************************************
  2. * _ _ _
  3. * _ __ | |_ _ | | __ _ | |__ ___
  4. * | '__|| __|(_)| | / _` || '_ \ / __|
  5. * | | | |_ _ | || (_| || |_) |\__ \
  6. * |_| \__|(_)|_| \__,_||_.__/ |___/
  7. *
  8. * www.rt-labs.com
  9. * Copyright 2018 rt-labs AB, Sweden.
  10. *
  11. * This software is dual-licensed under GPLv3 and a commercial
  12. * license. See the file LICENSE.md distributed with this software for
  13. * full license information.
  14. ********************************************************************/
  15. #include "utils_for_testing.h"
  16. #include <gtest/gtest.h>
  17. #include <inttypes.h>
  18. /******************** Callbacks defined by p-net *****************************/
  19. int my_connect_ind (
  20. pnet_t * net,
  21. void * arg,
  22. uint32_t arep,
  23. pnet_result_t * p_result)
  24. {
  25. app_data_for_testing_t * p_appdata = (app_data_for_testing_t *)arg;
  26. p_appdata->call_counters.connect_calls++;
  27. return 0;
  28. }
  29. int my_release_ind (
  30. pnet_t * net,
  31. void * arg,
  32. uint32_t arep,
  33. pnet_result_t * p_result)
  34. {
  35. app_data_for_testing_t * p_appdata = (app_data_for_testing_t *)arg;
  36. p_appdata->call_counters.release_calls++;
  37. return 0;
  38. }
  39. int my_dcontrol_ind (
  40. pnet_t * net,
  41. void * arg,
  42. uint32_t arep,
  43. pnet_control_command_t control_command,
  44. pnet_result_t * p_result)
  45. {
  46. app_data_for_testing_t * p_appdata = (app_data_for_testing_t *)arg;
  47. p_appdata->call_counters.dcontrol_calls++;
  48. return 0;
  49. }
  50. int my_ccontrol_cnf (
  51. pnet_t * net,
  52. void * arg,
  53. uint32_t arep,
  54. pnet_result_t * p_result)
  55. {
  56. app_data_for_testing_t * p_appdata = (app_data_for_testing_t *)arg;
  57. p_appdata->call_counters.ccontrol_calls++;
  58. return 0;
  59. }
  60. static int my_signal_led_ind (pnet_t * net, void * arg, bool led_state)
  61. {
  62. app_data_for_testing_t * p_appdata = (app_data_for_testing_t *)arg;
  63. TEST_TRACE ("Callback on set LED state: %u\n", led_state);
  64. if (led_state == 1)
  65. {
  66. p_appdata->call_counters.led_on_calls++;
  67. }
  68. else
  69. {
  70. p_appdata->call_counters.led_off_calls++;
  71. }
  72. return 0;
  73. }
  74. int my_read_ind (
  75. pnet_t * net,
  76. void * arg,
  77. uint32_t arep,
  78. uint32_t api,
  79. uint16_t slot,
  80. uint16_t subslot,
  81. uint16_t idx,
  82. uint16_t sequence_number,
  83. uint8_t ** pp_read_data, /* Out: A pointer to the data */
  84. uint16_t * p_read_length, /* Out: Size of data */
  85. pnet_result_t * p_result) /* Error status if returning != 0 */
  86. {
  87. app_data_for_testing_t * p_appdata = (app_data_for_testing_t *)arg;
  88. TEST_TRACE ("Callback on read\n");
  89. TEST_TRACE (
  90. " API: %" PRIu32 " Slot: %" PRIu16 " Subslot: %" PRIu16
  91. " Index: %" PRIu16 " Sequence: %" PRIu16 "\n",
  92. api,
  93. slot,
  94. subslot,
  95. idx,
  96. sequence_number);
  97. p_appdata->call_counters.read_calls++;
  98. return 0;
  99. }
  100. int my_write_ind (
  101. pnet_t * net,
  102. void * arg,
  103. uint32_t arep,
  104. uint32_t api,
  105. uint16_t slot,
  106. uint16_t subslot,
  107. uint16_t idx,
  108. uint16_t sequence_number,
  109. uint16_t write_length,
  110. const uint8_t * p_write_data,
  111. pnet_result_t * p_result)
  112. {
  113. app_data_for_testing_t * p_appdata = (app_data_for_testing_t *)arg;
  114. TEST_TRACE ("Callback on write\n");
  115. TEST_TRACE (
  116. " API: %" PRIu32 " Slot: %" PRIu16 " Subslot: %" PRIu16
  117. " Index: %" PRIu16 " Sequence: %" PRIu16 " Len: %" PRIu16 "\n",
  118. api,
  119. slot,
  120. subslot,
  121. idx,
  122. sequence_number,
  123. write_length);
  124. p_appdata->call_counters.write_calls++;
  125. return 0;
  126. }
  127. int my_new_data_status_ind (
  128. pnet_t * net,
  129. void * arg,
  130. uint32_t arep,
  131. uint32_t crep,
  132. uint8_t changes,
  133. uint8_t data_status)
  134. {
  135. TEST_TRACE ("Callback on new data\n");
  136. return 0;
  137. }
  138. int my_alarm_ind (
  139. pnet_t * net,
  140. void * arg,
  141. uint32_t arep,
  142. const pnet_alarm_argument_t * p_alarm_arg,
  143. uint16_t data_len,
  144. uint16_t data_usi,
  145. const uint8_t * p_data)
  146. {
  147. TEST_TRACE ("Callback on alarm\n");
  148. return 0;
  149. }
  150. int my_alarm_cnf (
  151. pnet_t * net,
  152. void * arg,
  153. uint32_t arep,
  154. const pnet_pnio_status_t * p_pnio_status)
  155. {
  156. TEST_TRACE ("Callback on alarm confirmation\n");
  157. return 0;
  158. }
  159. int my_state_ind (
  160. pnet_t * net,
  161. void * arg,
  162. uint32_t arep,
  163. pnet_event_values_t state)
  164. {
  165. app_data_for_testing_t * p_appdata = (app_data_for_testing_t *)arg;
  166. int ret;
  167. uint16_t slot = 0;
  168. uint16_t err_cls = 0;
  169. uint16_t err_code = 0;
  170. p_appdata->call_counters.state_calls++;
  171. p_appdata->main_arep = arep;
  172. p_appdata->cmdev_state = state;
  173. if (state == PNET_EVENT_PRMEND)
  174. {
  175. /* Set IOPS for DAP slot (has same numbering as the module identifiers) */
  176. ret = pnet_input_set_data_and_iops (
  177. net,
  178. TEST_API_IDENT,
  179. PNET_SLOT_DAP_IDENT,
  180. PNET_SUBSLOT_DAP_IDENT,
  181. NULL,
  182. 0,
  183. PNET_IOXS_GOOD);
  184. EXPECT_EQ (ret, 0);
  185. ret = pnet_input_set_data_and_iops (
  186. net,
  187. TEST_API_IDENT,
  188. PNET_SLOT_DAP_IDENT,
  189. PNET_SUBSLOT_DAP_INTERFACE_1_IDENT,
  190. NULL,
  191. 0,
  192. PNET_IOXS_GOOD);
  193. EXPECT_EQ (ret, 0);
  194. ret = pnet_input_set_data_and_iops (
  195. net,
  196. TEST_API_IDENT,
  197. PNET_SLOT_DAP_IDENT,
  198. PNET_SUBSLOT_DAP_INTERFACE_1_PORT_1_IDENT,
  199. NULL,
  200. 0,
  201. PNET_IOXS_GOOD);
  202. EXPECT_EQ (ret, 0);
  203. /* Set initial data and IOPS for custom input modules, and IOCS for custom
  204. * output modules */
  205. for (slot = 0; slot < PNET_MAX_SLOTS; slot++)
  206. {
  207. if (p_appdata->custom_input_slots[slot] == true)
  208. {
  209. ret = pnet_input_set_data_and_iops (
  210. net,
  211. TEST_API_IDENT,
  212. slot,
  213. TEST_SUBMOD_CUSTOM_IDENT,
  214. p_appdata->inputdata,
  215. TEST_DATASIZE_INPUT,
  216. PNET_IOXS_GOOD);
  217. EXPECT_EQ (ret, 0);
  218. }
  219. if (p_appdata->custom_output_slots[slot] == true)
  220. {
  221. ret = pnet_output_set_iocs (
  222. net,
  223. TEST_API_IDENT,
  224. slot,
  225. TEST_SUBMOD_CUSTOM_IDENT,
  226. PNET_IOXS_GOOD);
  227. EXPECT_EQ (ret, 0);
  228. }
  229. }
  230. ret = pnet_set_provider_state (net, true);
  231. EXPECT_EQ (ret, 0);
  232. }
  233. else if (state == PNET_EVENT_ABORT)
  234. {
  235. ret = pnet_get_ar_error_codes (net, arep, &err_cls, &err_code);
  236. EXPECT_EQ (ret, 0);
  237. TEST_TRACE (
  238. "ABORT err_cls 0x%02" PRIx16 " err_code 0x%02" PRIx16 "\n",
  239. err_cls,
  240. err_code);
  241. }
  242. return 0;
  243. }
  244. int my_exp_module_ind (
  245. pnet_t * net,
  246. void * arg,
  247. uint32_t api,
  248. uint16_t slot,
  249. uint32_t module_ident)
  250. {
  251. app_data_for_testing_t * p_appdata = (app_data_for_testing_t *)arg;
  252. int ret = -1; /* Not supported in specified slot */
  253. bool found = false;
  254. uint16_t ix;
  255. TEST_TRACE ("Callback on module\n");
  256. /* Find it in the list of supported modules */
  257. ix = 0;
  258. while (ix < TEST_MAX_NUMBER_AVAILABLE_MODULE_TYPES)
  259. {
  260. if (p_appdata->available_module_types[ix] == module_ident)
  261. {
  262. found = true;
  263. break;
  264. }
  265. ix++;
  266. }
  267. if (found == true)
  268. {
  269. /* For now support any module in any slot */
  270. TEST_TRACE (
  271. " Plug module. API: %" PRIu32 " Slot: %" PRIu16 " Module ID: "
  272. "%" PRIu32 " Index in list of supported modules: %" PRIu16 "\n",
  273. api,
  274. slot,
  275. module_ident,
  276. ix);
  277. ret = pnet_plug_module (net, api, slot, module_ident);
  278. EXPECT_EQ (ret, 0);
  279. /* Remember what is plugged in each slot */
  280. if (module_ident == TEST_MOD_8_0_IDENT || module_ident == TEST_MOD_8_8_IDENT)
  281. {
  282. p_appdata->custom_input_slots[slot] = true;
  283. }
  284. if (module_ident == TEST_MOD_8_8_IDENT || module_ident == TEST_MOD_0_8_IDENT)
  285. {
  286. p_appdata->custom_output_slots[slot] = true;
  287. }
  288. }
  289. else
  290. {
  291. TEST_TRACE (" Module ident %08" PRIx32 " not found\n", module_ident);
  292. EXPECT_TRUE (false); // Fail the test
  293. }
  294. return ret;
  295. }
  296. int my_exp_submodule_ind (
  297. pnet_t * net,
  298. void * arg,
  299. uint32_t api,
  300. uint16_t slot,
  301. uint16_t subslot,
  302. uint32_t module_ident,
  303. uint32_t submodule_ident,
  304. const pnet_data_cfg_t * p_exp_data)
  305. {
  306. app_data_for_testing_t * p_appdata = (app_data_for_testing_t *)arg;
  307. int ret = -1;
  308. bool found = false;
  309. uint16_t ix = 0;
  310. TEST_TRACE ("Callback on submodule\n");
  311. /* Find it in the list of supported submodules */
  312. ix = 0;
  313. while (ix < TEST_MAX_NUMBER_AVAILABLE_SUBMODULE_TYPES)
  314. {
  315. if (
  316. p_appdata->available_submodule_types[ix].module_ident_number ==
  317. module_ident &&
  318. p_appdata->available_submodule_types[ix].submodule_ident_number ==
  319. submodule_ident)
  320. {
  321. found = true;
  322. break;
  323. }
  324. ix++;
  325. }
  326. if (found == true)
  327. {
  328. TEST_TRACE (
  329. " Plug submodule. API: %" PRIu32 " Slot: %" PRIu16 " Subslot: "
  330. "%" PRIu16 " Module ID: %" PRIu32 " Submodule ID: %" PRIu32
  331. " (Index in "
  332. "available "
  333. "submodules: %" PRIu16 ") Direction: %u Len in: %" PRIu16
  334. " out: %" PRIu16 "\n",
  335. api,
  336. slot,
  337. subslot,
  338. module_ident,
  339. submodule_ident,
  340. ix,
  341. p_appdata->available_submodule_types[ix].direction,
  342. p_appdata->available_submodule_types[ix].input_length,
  343. p_appdata->available_submodule_types[ix].output_length);
  344. ret = pnet_plug_submodule (
  345. net,
  346. api,
  347. slot,
  348. subslot,
  349. module_ident,
  350. submodule_ident,
  351. p_appdata->available_submodule_types[ix].direction,
  352. p_appdata->available_submodule_types[ix].input_length,
  353. p_appdata->available_submodule_types[ix].output_length);
  354. EXPECT_EQ (ret, 0);
  355. }
  356. else
  357. {
  358. TEST_TRACE (
  359. " Sub-module ident %08" PRIx32 " not found\n",
  360. submodule_ident);
  361. EXPECT_TRUE (false); // Fail the test
  362. }
  363. return ret;
  364. }
  365. /*********************** Base classes for tests *****************************/
  366. void PnetIntegrationTestBase::appdata_init()
  367. {
  368. memset (&appdata, 0, sizeof (appdata));
  369. }
  370. void PnetIntegrationTestBase::callcounter_reset()
  371. {
  372. memset (&appdata.call_counters, 0, sizeof (call_counters_t));
  373. }
  374. void PnetIntegrationTestBase::available_modules_and_submodules_init()
  375. {
  376. appdata.available_module_types[0] = PNET_MOD_DAP_IDENT;
  377. appdata.available_module_types[1] = TEST_MOD_8_8_IDENT;
  378. appdata.available_module_types[2] = TEST_MOD_8_0_IDENT;
  379. appdata.available_submodule_types[0].module_ident_number =
  380. PNET_MOD_DAP_IDENT;
  381. appdata.available_submodule_types[0].submodule_ident_number =
  382. PNET_SUBMOD_DAP_IDENT;
  383. appdata.available_submodule_types[0].direction = PNET_DIR_NO_IO;
  384. appdata.available_submodule_types[0].input_length = 0;
  385. appdata.available_submodule_types[0].output_length = 0;
  386. appdata.available_submodule_types[1].module_ident_number =
  387. PNET_MOD_DAP_IDENT;
  388. appdata.available_submodule_types[1].submodule_ident_number =
  389. PNET_SUBMOD_DAP_INTERFACE_1_IDENT;
  390. appdata.available_submodule_types[1].direction = PNET_DIR_NO_IO;
  391. appdata.available_submodule_types[1].input_length = 0;
  392. appdata.available_submodule_types[1].output_length = 0;
  393. appdata.available_submodule_types[2].module_ident_number =
  394. PNET_MOD_DAP_IDENT;
  395. appdata.available_submodule_types[2].submodule_ident_number =
  396. PNET_SUBMOD_DAP_INTERFACE_1_PORT_1_IDENT;
  397. appdata.available_submodule_types[2].direction = PNET_DIR_NO_IO;
  398. appdata.available_submodule_types[2].input_length = 0;
  399. appdata.available_submodule_types[2].output_length = 0;
  400. appdata.available_submodule_types[3].module_ident_number =
  401. TEST_MOD_8_8_IDENT;
  402. appdata.available_submodule_types[3].submodule_ident_number =
  403. TEST_SUBMOD_CUSTOM_IDENT;
  404. appdata.available_submodule_types[3].direction = PNET_DIR_IO;
  405. appdata.available_submodule_types[3].input_length = TEST_DATASIZE_INPUT;
  406. appdata.available_submodule_types[3].output_length = TEST_DATASIZE_OUTPUT;
  407. appdata.available_submodule_types[4].module_ident_number =
  408. TEST_MOD_8_0_IDENT;
  409. appdata.available_submodule_types[4].submodule_ident_number =
  410. TEST_SUBMOD_CUSTOM_IDENT;
  411. appdata.available_submodule_types[4].direction = PNET_DIR_OUTPUT;
  412. appdata.available_submodule_types[4].input_length = 0;
  413. appdata.available_submodule_types[4].output_length = TEST_DATASIZE_OUTPUT;
  414. }
  415. void PnetIntegrationTestBase::cfg_init()
  416. {
  417. pnet_default_cfg.tick_us = TEST_TICK_INTERVAL_US;
  418. pnet_default_cfg.state_cb = my_state_ind;
  419. pnet_default_cfg.connect_cb = my_connect_ind;
  420. pnet_default_cfg.release_cb = my_release_ind;
  421. pnet_default_cfg.dcontrol_cb = my_dcontrol_ind;
  422. pnet_default_cfg.ccontrol_cb = my_ccontrol_cnf;
  423. pnet_default_cfg.read_cb = my_read_ind;
  424. pnet_default_cfg.write_cb = my_write_ind;
  425. pnet_default_cfg.exp_module_cb = my_exp_module_ind;
  426. pnet_default_cfg.exp_submodule_cb = my_exp_submodule_ind;
  427. pnet_default_cfg.new_data_status_cb = my_new_data_status_ind;
  428. pnet_default_cfg.alarm_ind_cb = my_alarm_ind;
  429. pnet_default_cfg.alarm_cnf_cb = my_alarm_cnf;
  430. pnet_default_cfg.signal_led_cb = my_signal_led_ind;
  431. pnet_default_cfg.reset_cb = NULL;
  432. pnet_default_cfg.cb_arg = &appdata;
  433. /* Device configuration */
  434. pnet_default_cfg.device_id.vendor_id_hi = 0xfe;
  435. pnet_default_cfg.device_id.vendor_id_lo = 0xed;
  436. pnet_default_cfg.device_id.device_id_hi = 0xbe;
  437. pnet_default_cfg.device_id.device_id_lo = 0xef;
  438. pnet_default_cfg.oem_device_id.vendor_id_hi = 0xfe;
  439. pnet_default_cfg.oem_device_id.vendor_id_lo = 0xed;
  440. pnet_default_cfg.oem_device_id.device_id_hi = 0xbe;
  441. pnet_default_cfg.oem_device_id.device_id_lo = 0xef;
  442. strcpy (pnet_default_cfg.station_name, "");
  443. strcpy (pnet_default_cfg.product_name, "PNET unit tests");
  444. pnet_default_cfg.if_cfg.physical_ports[0].netif_name = TEST_INTERFACE_NAME;
  445. /* Timing */
  446. pnet_default_cfg.min_device_interval = 32; /* Corresponds to 1 ms */
  447. /* Network configuration */
  448. pnet_default_cfg.send_hello = 1; /* Send HELLO */
  449. pnet_default_cfg.if_cfg.ip_cfg.dhcp_enable = 0;
  450. pnet_default_cfg.if_cfg.main_netif_name = TEST_INTERFACE_NAME;
  451. pnet_default_cfg.if_cfg.ip_cfg.ip_addr.a = 192;
  452. pnet_default_cfg.if_cfg.ip_cfg.ip_addr.b = 168;
  453. pnet_default_cfg.if_cfg.ip_cfg.ip_addr.c = 1;
  454. pnet_default_cfg.if_cfg.ip_cfg.ip_addr.d = 171;
  455. pnet_default_cfg.if_cfg.ip_cfg.ip_mask.a = 255;
  456. pnet_default_cfg.if_cfg.ip_cfg.ip_mask.b = 255;
  457. pnet_default_cfg.if_cfg.ip_cfg.ip_mask.c = 255;
  458. pnet_default_cfg.if_cfg.ip_cfg.ip_mask.d = 255;
  459. pnet_default_cfg.if_cfg.ip_cfg.ip_gateway.a = 192;
  460. pnet_default_cfg.if_cfg.ip_cfg.ip_gateway.b = 168;
  461. pnet_default_cfg.if_cfg.ip_cfg.ip_gateway.c = 1;
  462. pnet_default_cfg.if_cfg.ip_cfg.ip_gateway.d = 1;
  463. pnet_default_cfg.im_0_data.im_vendor_id_hi = 0x00;
  464. pnet_default_cfg.im_0_data.im_vendor_id_lo = 0x01;
  465. strcpy (pnet_default_cfg.im_0_data.im_order_id, "<orderid> ");
  466. strcpy (pnet_default_cfg.im_0_data.im_serial_number, "<serial nbr> ");
  467. pnet_default_cfg.im_0_data.im_hardware_revision = 1;
  468. pnet_default_cfg.im_0_data.im_sw_revision_prefix = 'P'; /* 'V', 'R', 'P',
  469. 'U', or 'T' */
  470. pnet_default_cfg.im_0_data.im_sw_revision_functional_enhancement = 0;
  471. pnet_default_cfg.im_0_data.im_sw_revision_bug_fix = 0;
  472. pnet_default_cfg.im_0_data.im_sw_revision_internal_change = 0;
  473. pnet_default_cfg.im_0_data.im_revision_counter = 0;
  474. pnet_default_cfg.im_0_data.im_profile_id = 0x1234;
  475. pnet_default_cfg.im_0_data.im_profile_specific_type = 0x5678;
  476. pnet_default_cfg.im_0_data.im_version_major = 0;
  477. pnet_default_cfg.im_0_data.im_version_minor = 1;
  478. pnet_default_cfg.im_0_data.im_supported =
  479. PNET_SUPPORTED_IM1 | PNET_SUPPORTED_IM2 | PNET_SUPPORTED_IM3 |
  480. PNET_SUPPORTED_IM4;
  481. strcpy (pnet_default_cfg.im_1_data.im_tag_function, "");
  482. strcpy (pnet_default_cfg.im_1_data.im_tag_location, "");
  483. strcpy (pnet_default_cfg.im_2_data.im_date, "");
  484. strcpy (pnet_default_cfg.im_3_data.im_descriptor, "");
  485. strcpy (pnet_default_cfg.im_4_data.im_signature, "");
  486. /* Storage */
  487. strcpy (pnet_default_cfg.file_directory, "/disk1");
  488. /* Diagnosis */
  489. pnet_default_cfg.use_qualified_diagnosis = true;
  490. pnet_default_cfg.num_physical_ports = PNET_MAX_PHYSICAL_PORTS;
  491. }
  492. void PnetIntegrationTestBase::run_stack (int us)
  493. {
  494. uint16_t slot = 0;
  495. for (int tmr = 0; tmr < us / TEST_TICK_INTERVAL_US; tmr++)
  496. {
  497. /* Set new output data every 10 ticks */
  498. appdata.tick_ctr++;
  499. if ((appdata.main_arep != 0) && (appdata.tick_ctr > 10))
  500. {
  501. appdata.tick_ctr = 0;
  502. appdata.inputdata[0] = appdata.counter_data++;
  503. /* Set data for custom input modules, if any */
  504. for (slot = 0; slot < PNET_MAX_SLOTS; slot++)
  505. {
  506. if (appdata.custom_input_slots[slot] == true)
  507. {
  508. (void)pnet_input_set_data_and_iops (
  509. net,
  510. TEST_API_IDENT,
  511. slot,
  512. TEST_SUBMOD_CUSTOM_IDENT,
  513. appdata.inputdata,
  514. TEST_DATASIZE_INPUT,
  515. PNET_IOXS_GOOD);
  516. }
  517. }
  518. }
  519. /* Run stack functionality every tick */
  520. pnet_handle_periodic (net);
  521. mock_os_data.current_time_us += TEST_TICK_INTERVAL_US;
  522. }
  523. }
  524. void PnetIntegrationTestBase::send_data (uint8_t * data_packet, uint16_t len)
  525. {
  526. int ret;
  527. pnal_buf_t * p_buf;
  528. uint8_t * p_ctr;
  529. p_buf = pnal_buf_alloc (PF_FRAME_BUFFER_SIZE);
  530. if (p_buf == NULL)
  531. {
  532. TEST_TRACE ("(%d): Out of memory in send_data\n", __LINE__);
  533. }
  534. else
  535. {
  536. memcpy (p_buf->payload, data_packet, len);
  537. /* Insert frame time, store in big-endian */
  538. appdata.data_cycle_ctr++;
  539. p_ctr = &((uint8_t *)(p_buf->payload))[len - 4];
  540. *(p_ctr + 0) = (appdata.data_cycle_ctr >> 8) & 0xff;
  541. *(p_ctr + 1) = appdata.data_cycle_ctr & 0xff;
  542. p_buf->len = len;
  543. ret = pf_eth_recv (mock_os_data.eth_if_handle, net, p_buf);
  544. EXPECT_EQ (ret, 1);
  545. if (ret == 0)
  546. {
  547. TEST_TRACE ("(%d): Unhandled p_buf\n", __LINE__);
  548. pnal_buf_free (p_buf);
  549. }
  550. }
  551. }