pytest_otbr.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. # SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
  2. # SPDX-License-Identifier: Unlicense OR CC0-1.0
  3. # !/usr/bin/env python3
  4. import os.path
  5. import re
  6. import subprocess
  7. import threading
  8. import time
  9. from typing import Tuple
  10. import ot_ci_function as ocf
  11. import pexpect
  12. import pytest
  13. from pytest_embedded_idf.dut import IdfDut
  14. # This file contains the test scripts for Thread:
  15. # Case 1: Thread network formation and attaching
  16. # A Thread Border Router forms a Thread network, Thread devices attache to it, then test ping connection between them.
  17. # Case 2: Bidirectional IPv6 connectivity
  18. # Test IPv6 ping connection between Thread device and Linux Host (via Thread Border Router).
  19. # Case 3: Multicast forwarding from Wi-Fi to Thread network
  20. # Thread device joins the multicast group, then test group communication from Wi-Fi to Thread network.
  21. # Case 4: Multicast forwarding from Thread to Wi-Fi network
  22. # Linux Host joins the multicast group, test group communication from Thread to Wi-Fi network.
  23. # Case 5: discover Serice published by Thread device
  24. # Thread device publishes the service, Linux Host discovers the service on Wi-Fi network.
  25. # Case 6: discover Serice published by W-Fi device
  26. # Linux Host device publishes the service on Wi-Fi network, Thread device discovers the service.
  27. # Case 7: ICMP communication via NAT64
  28. # Thread device (IPV6) ping the host device (IPV4) via NAT64.
  29. # Case 8: UDP communication via NAT64
  30. # Thread device (IPV6) send udp message to the host device (IPV4) via NAT64.
  31. # Case 9: TCP communication via NAT64
  32. # Thread device (IPV6) send tcp message to the host device (IPV4) via NAT64.
  33. @pytest.fixture(scope='module', name='Init_avahi')
  34. def fixture_Init_avahi() -> bool:
  35. print('Init Avahi')
  36. ocf.start_avahi()
  37. time.sleep(10)
  38. return True
  39. @pytest.fixture(name='Init_interface')
  40. def fixture_Init_interface() -> bool:
  41. print('Init interface')
  42. ocf.init_interface_ipv6_address()
  43. ocf.reset_host_interface()
  44. time.sleep(30)
  45. ocf.set_interface_sysctl_options()
  46. return True
  47. default_br_ot_para = ocf.thread_parameter('leader', '', '12', '7766554433221100', True)
  48. default_br_wifi_para = ocf.wifi_parameter('OTCITE', 'otcitest888', 10)
  49. default_cli_ot_para = ocf.thread_parameter('router', '', '', '', False)
  50. # Case 1: Thread network formation and attaching
  51. @pytest.mark.supported_targets
  52. @pytest.mark.esp32h2
  53. @pytest.mark.esp32c6
  54. @pytest.mark.openthread_br
  55. @pytest.mark.flaky(reruns=1, reruns_delay=1)
  56. @pytest.mark.parametrize(
  57. 'config, count, app_path, target', [
  58. ('rcp|cli_h2|br', 3,
  59. f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
  60. f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
  61. f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
  62. 'esp32c6|esp32h2|esp32s3'),
  63. ],
  64. indirect=True,
  65. )
  66. def test_thread_connect(dut:Tuple[IdfDut, IdfDut, IdfDut]) -> None:
  67. br = dut[2]
  68. cli_h2 = dut[1]
  69. dut[0].serial.stop_redirect_thread()
  70. cli_list = [cli_h2]
  71. router_extaddr_list = ['7766554433221101']
  72. ocf.reset_thread(br)
  73. for cli in cli_list:
  74. ocf.reset_thread(cli)
  75. br_ot_para = default_br_ot_para
  76. ocf.joinThreadNetwork(br, br_ot_para)
  77. cli_ot_para = default_cli_ot_para
  78. cli_ot_para.dataset = ocf.getDataset(br)
  79. try:
  80. order = 0
  81. for cli in cli_list:
  82. cli_ot_para.exaddr = router_extaddr_list[order]
  83. order = order + 1
  84. ocf.joinThreadNetwork(cli, cli_ot_para)
  85. for cli in cli_list:
  86. cli_mleid_addr = ocf.get_mleid_addr(cli)
  87. br_mleid_addr = ocf.get_mleid_addr(br)
  88. rx_nums = ocf.ot_ping(cli, br_mleid_addr, 5)[1]
  89. assert rx_nums == 5
  90. rx_nums = ocf.ot_ping(br, cli_mleid_addr, 5)[1]
  91. assert rx_nums == 5
  92. finally:
  93. br.write('factoryreset')
  94. for cli in cli_list:
  95. cli.write('factoryreset')
  96. time.sleep(3)
  97. # Form a Wi-Fi/Thread network with a Wi-Fi host, a border router and a Thread end device
  98. # Topology:
  99. # Border_Router
  100. # / \
  101. # / \
  102. # Wi-FI_Host Thread_End_Device
  103. def formBasicWiFiThreadNetwork(br:IdfDut, cli:IdfDut) -> None:
  104. ocf.reset_thread(br)
  105. ocf.reset_thread(cli)
  106. ocf.joinWiFiNetwork(br, default_br_wifi_para)
  107. ocf.joinThreadNetwork(br, default_br_ot_para)
  108. ot_para = default_cli_ot_para
  109. ot_para.dataset = ocf.getDataset(br)
  110. ot_para.exaddr = '7766554433221101'
  111. ocf.joinThreadNetwork(cli, ot_para)
  112. ocf.wait(cli,10)
  113. # Case 2: Bidirectional IPv6 connectivity
  114. @pytest.mark.supported_targets
  115. @pytest.mark.esp32h2
  116. @pytest.mark.esp32c6
  117. @pytest.mark.openthread_br
  118. @pytest.mark.flaky(reruns=1, reruns_delay=1)
  119. @pytest.mark.parametrize(
  120. 'config, count, app_path, target', [
  121. ('rcp|cli_h2|br', 3,
  122. f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
  123. f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
  124. f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
  125. 'esp32c6|esp32h2|esp32s3'),
  126. ],
  127. indirect=True,
  128. )
  129. def test_Bidirectional_IPv6_connectivity(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
  130. br = dut[2]
  131. cli = dut[1]
  132. assert Init_interface
  133. dut[0].serial.stop_redirect_thread()
  134. formBasicWiFiThreadNetwork(br, cli)
  135. try:
  136. assert ocf.is_joined_wifi_network(br)
  137. cli_global_unicast_addr = ocf.get_global_unicast_addr(cli, br)
  138. print('cli_global_unicast_addr', cli_global_unicast_addr)
  139. command = 'ping ' + str(cli_global_unicast_addr) + ' -c 10'
  140. out_str = subprocess.getoutput(command)
  141. print('ping result:\n', str(out_str))
  142. role = re.findall(r' (\d+)%', str(out_str))[0]
  143. assert role != '100'
  144. interface_name = ocf.get_host_interface_name()
  145. command = 'ifconfig ' + interface_name
  146. out_bytes = subprocess.check_output(command, shell=True, timeout=5)
  147. out_str = out_bytes.decode('utf-8')
  148. host_global_unicast_addr = re.findall(r'inet6 ((?:\w+:){7}\w+) prefixlen 64 scopeid 0x0<global>', str(out_str))
  149. rx_nums = 0
  150. for ip_addr in host_global_unicast_addr:
  151. txrx_nums = ocf.ot_ping(cli, str(ip_addr), 5)
  152. rx_nums = rx_nums + int(txrx_nums[1])
  153. assert rx_nums != 0
  154. finally:
  155. br.write('factoryreset')
  156. cli.write('factoryreset')
  157. time.sleep(3)
  158. # Case 3: Multicast forwarding from Wi-Fi to Thread network
  159. @pytest.mark.supported_targets
  160. @pytest.mark.esp32h2
  161. @pytest.mark.esp32c6
  162. @pytest.mark.openthread_br
  163. @pytest.mark.flaky(reruns=1, reruns_delay=1)
  164. @pytest.mark.parametrize(
  165. 'config, count, app_path, target', [
  166. ('rcp|cli_h2|br', 3,
  167. f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
  168. f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
  169. f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
  170. 'esp32c6|esp32h2|esp32s3'),
  171. ],
  172. indirect=True,
  173. )
  174. def test_multicast_forwarding_A(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
  175. br = dut[2]
  176. cli = dut[1]
  177. assert Init_interface
  178. dut[0].serial.stop_redirect_thread()
  179. formBasicWiFiThreadNetwork(br, cli)
  180. try:
  181. assert ocf.is_joined_wifi_network(br)
  182. br.write('bbr')
  183. br.expect('server16', timeout=5)
  184. assert ocf.thread_is_joined_group(cli)
  185. interface_name = ocf.get_host_interface_name()
  186. command = 'ping -I ' + str(interface_name) + ' -t 64 ff04::125 -c 10'
  187. out_str = subprocess.getoutput(command)
  188. print('ping result:\n', str(out_str))
  189. role = re.findall(r' (\d+)%', str(out_str))[0]
  190. assert role != '100'
  191. finally:
  192. br.write('factoryreset')
  193. cli.write('factoryreset')
  194. time.sleep(3)
  195. # Case 4: Multicast forwarding from Thread to Wi-Fi network
  196. @pytest.mark.supported_targets
  197. @pytest.mark.esp32h2
  198. @pytest.mark.esp32c6
  199. @pytest.mark.openthread_br
  200. @pytest.mark.flaky(reruns=1, reruns_delay=1)
  201. @pytest.mark.parametrize(
  202. 'config, count, app_path, target', [
  203. ('rcp|cli_h2|br', 3,
  204. f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
  205. f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
  206. f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
  207. 'esp32c6|esp32h2|esp32s3'),
  208. ],
  209. indirect=True,
  210. )
  211. def test_multicast_forwarding_B(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
  212. br = dut[2]
  213. cli = dut[1]
  214. assert Init_interface
  215. dut[0].serial.stop_redirect_thread()
  216. formBasicWiFiThreadNetwork(br, cli)
  217. try:
  218. assert ocf.is_joined_wifi_network(br)
  219. br.write('bbr')
  220. br.expect('server16', timeout=5)
  221. cli.write('udp open')
  222. cli.expect('Done', timeout=5)
  223. ocf.wait(cli, 3)
  224. myudp = ocf.udp_parameter('INET6', '::', 5090, 'ff04::125', False, 15.0, b'')
  225. udp_mission = threading.Thread(target=ocf.create_host_udp_server, args=(myudp, ))
  226. udp_mission.start()
  227. start_time = time.time()
  228. while not myudp.init_flag:
  229. if (time.time() - start_time) > 10:
  230. assert False
  231. for num in range(0, 3):
  232. command = 'udp send ff04::125 5090 hello' + str(num)
  233. cli.write(command)
  234. cli.expect('Done', timeout=5)
  235. ocf.wait(cli, 0.5)
  236. while udp_mission.is_alive():
  237. time.sleep(1)
  238. finally:
  239. br.write('factoryreset')
  240. cli.write('factoryreset')
  241. time.sleep(3)
  242. assert b'hello' in myudp.udp_bytes
  243. # Case 5: discover dervice published by Thread device
  244. @pytest.mark.supported_targets
  245. @pytest.mark.esp32h2
  246. @pytest.mark.esp32c6
  247. @pytest.mark.openthread_br
  248. @pytest.mark.flaky(reruns=1, reruns_delay=1)
  249. @pytest.mark.parametrize(
  250. 'config, count, app_path, target', [
  251. ('rcp|cli_h2|br', 3,
  252. f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
  253. f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
  254. f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
  255. 'esp32c6|esp32h2|esp32s3'),
  256. ],
  257. indirect=True,
  258. )
  259. def test_service_discovery_of_Thread_device(Init_interface:bool, Init_avahi:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
  260. br = dut[2]
  261. cli = dut[1]
  262. assert Init_interface
  263. assert Init_avahi
  264. dut[0].serial.stop_redirect_thread()
  265. formBasicWiFiThreadNetwork(br, cli)
  266. try:
  267. assert ocf.is_joined_wifi_network(br)
  268. command = 'avahi-browse -rt _testyyy._udp'
  269. out_str = subprocess.getoutput(command)
  270. print('avahi-browse:\n', str(out_str))
  271. assert 'myTest' not in str(out_str)
  272. hostname = 'myTest'
  273. command = 'srp client host name ' + hostname
  274. cli.write(command)
  275. cli.expect('Done', timeout=5)
  276. cli_global_unicast_addr = ocf.get_global_unicast_addr(cli, br)
  277. print('cli_global_unicast_addr', cli_global_unicast_addr)
  278. command = 'srp client host address ' + str(cli_global_unicast_addr)
  279. cli.write(command)
  280. cli.expect('Done', timeout=5)
  281. port = '12348'
  282. command = 'srp client service add my-service _testyyy._udp ' + port
  283. cli.write(command)
  284. cli.expect('Done', timeout=5)
  285. cli.write('srp client autostart enable')
  286. cli.expect('Done', timeout=5)
  287. ocf.wait(cli, 3)
  288. command = 'avahi-browse -rt _testyyy._udp'
  289. out_str = subprocess.getoutput(command)
  290. print('avahi-browse:\n', str(out_str))
  291. assert 'myTest' in str(out_str)
  292. finally:
  293. br.write('factoryreset')
  294. cli.write('factoryreset')
  295. time.sleep(3)
  296. # Case 6: discover dervice published by Wi-Fi device
  297. @pytest.mark.supported_targets
  298. @pytest.mark.esp32h2
  299. @pytest.mark.esp32c6
  300. @pytest.mark.openthread_br
  301. @pytest.mark.flaky(reruns=1, reruns_delay=1)
  302. @pytest.mark.parametrize(
  303. 'config, count, app_path, target', [
  304. ('rcp|cli_h2|br', 3,
  305. f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
  306. f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
  307. f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
  308. 'esp32c6|esp32h2|esp32s3'),
  309. ],
  310. indirect=True,
  311. )
  312. def test_service_discovery_of_WiFi_device(Init_interface:bool, Init_avahi:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
  313. br = dut[2]
  314. cli = dut[1]
  315. assert Init_interface
  316. assert Init_avahi
  317. dut[0].serial.stop_redirect_thread()
  318. formBasicWiFiThreadNetwork(br, cli)
  319. try:
  320. assert ocf.is_joined_wifi_network(br)
  321. br_global_unicast_addr = ocf.get_global_unicast_addr(br, br)
  322. command = 'dns config ' + br_global_unicast_addr
  323. ocf.clean_buffer(cli)
  324. cli.write(command)
  325. cli.expect('Done', timeout=5)
  326. ocf.wait(cli, 1)
  327. command = 'dns resolve FA000123.default.service.arpa.'
  328. ocf.clean_buffer(cli)
  329. cli.write(command)
  330. cli.expect('Error', timeout=15)
  331. domain_name = ocf.get_domain()
  332. print('domain name is: ', domain_name)
  333. command = 'dns resolve ' + domain_name + '.default.service.arpa.'
  334. ocf.clean_buffer(cli)
  335. cli.write(command)
  336. cli.expect('TTL', timeout=10)
  337. cli.expect('Done', timeout=10)
  338. ocf.clean_buffer(cli)
  339. cli.write('dns browse _testxxx._udp.default.service.arpa')
  340. tmp = cli.expect(pexpect.TIMEOUT, timeout=5)
  341. assert 'Port:12347' not in str(tmp)
  342. ocf.host_publish_service()
  343. ocf.wait(cli, 5)
  344. ocf.clean_buffer(cli)
  345. cli.write('dns browse _testxxx._udp.default.service.arpa')
  346. tmp = cli.expect(pexpect.TIMEOUT, timeout=5)
  347. assert 'response for _testxxx' in str(tmp)
  348. assert 'Port:12347' in str(tmp)
  349. ocf.clean_buffer(cli)
  350. cli.write('dns service testxxx _testxxx._udp.default.service.arpa.')
  351. tmp = cli.expect(pexpect.TIMEOUT, timeout=5)
  352. assert 'response for testxxx' in str(tmp)
  353. assert 'Port:12347' in str(tmp)
  354. finally:
  355. ocf.host_close_service()
  356. br.write('factoryreset')
  357. cli.write('factoryreset')
  358. time.sleep(3)
  359. # Case 7: ICMP communication via NAT64
  360. @pytest.mark.supported_targets
  361. @pytest.mark.esp32h2
  362. @pytest.mark.esp32c6
  363. @pytest.mark.openthread_br
  364. @pytest.mark.flaky(reruns=1, reruns_delay=1)
  365. @pytest.mark.parametrize(
  366. 'config, count, app_path, target', [
  367. ('rcp|cli_h2|br', 3,
  368. f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
  369. f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
  370. f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
  371. 'esp32c6|esp32h2|esp32s3'),
  372. ],
  373. indirect=True,
  374. )
  375. def test_ICMP_NAT64(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
  376. br = dut[2]
  377. cli = dut[1]
  378. assert Init_interface
  379. dut[0].serial.stop_redirect_thread()
  380. formBasicWiFiThreadNetwork(br, cli)
  381. try:
  382. assert ocf.is_joined_wifi_network(br)
  383. host_ipv4_address = ocf.get_host_ipv4_address()
  384. print('host_ipv4_address: ', host_ipv4_address)
  385. rx_nums = ocf.ot_ping(cli, str(host_ipv4_address), 5)[1]
  386. assert rx_nums != 0
  387. finally:
  388. br.write('factoryreset')
  389. cli.write('factoryreset')
  390. time.sleep(3)
  391. # Case 8: UDP communication via NAT64
  392. @pytest.mark.supported_targets
  393. @pytest.mark.esp32h2
  394. @pytest.mark.esp32c6
  395. @pytest.mark.openthread_br
  396. @pytest.mark.flaky(reruns=1, reruns_delay=1)
  397. @pytest.mark.parametrize(
  398. 'config, count, app_path, target', [
  399. ('rcp|cli_h2|br', 3,
  400. f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
  401. f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
  402. f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
  403. 'esp32c6|esp32h2|esp32s3'),
  404. ],
  405. indirect=True,
  406. )
  407. def test_UDP_NAT64(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
  408. br = dut[2]
  409. cli = dut[1]
  410. assert Init_interface
  411. dut[0].serial.stop_redirect_thread()
  412. formBasicWiFiThreadNetwork(br, cli)
  413. try:
  414. assert ocf.is_joined_wifi_network(br)
  415. br.write('bbr')
  416. br.expect('server16', timeout=5)
  417. cli.write('udp open')
  418. cli.expect('Done', timeout=5)
  419. ocf.wait(cli, 3)
  420. host_ipv4_address = ocf.get_host_ipv4_address()
  421. print('host_ipv4_address: ', host_ipv4_address)
  422. myudp = ocf.udp_parameter('INET4', host_ipv4_address, 5090, '', False, 15.0, b'')
  423. udp_mission = threading.Thread(target=ocf.create_host_udp_server, args=(myudp, ))
  424. udp_mission.start()
  425. start_time = time.time()
  426. while not myudp.init_flag:
  427. if (time.time() - start_time) > 10:
  428. assert False
  429. for num in range(0, 3):
  430. command = 'udp send ' + host_ipv4_address + ' 5090 hello' + str(num)
  431. cli.write(command)
  432. cli.expect('Done', timeout=5)
  433. ocf.wait(cli, 0.5)
  434. while udp_mission.is_alive():
  435. time.sleep(1)
  436. finally:
  437. br.write('factoryreset')
  438. cli.write('factoryreset')
  439. time.sleep(3)
  440. assert b'hello' in myudp.udp_bytes
  441. # Case 9: TCP communication via NAT64
  442. @pytest.mark.supported_targets
  443. @pytest.mark.esp32h2
  444. @pytest.mark.esp32c6
  445. @pytest.mark.openthread_br
  446. @pytest.mark.flaky(reruns=1, reruns_delay=1)
  447. @pytest.mark.parametrize(
  448. 'config, count, app_path, target', [
  449. ('rcp|cli_h2|br', 3,
  450. f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
  451. f'|{os.path.join(os.path.dirname(__file__), "ot_cli")}'
  452. f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
  453. 'esp32c6|esp32h2|esp32s3'),
  454. ],
  455. indirect=True,
  456. )
  457. def test_TCP_NAT64(Init_interface:bool, dut: Tuple[IdfDut, IdfDut, IdfDut]) -> None:
  458. br = dut[2]
  459. cli = dut[1]
  460. assert Init_interface
  461. dut[0].serial.stop_redirect_thread()
  462. formBasicWiFiThreadNetwork(br, cli)
  463. try:
  464. assert ocf.is_joined_wifi_network(br)
  465. br.write('bbr')
  466. br.expect('server16', timeout=5)
  467. cli.write('tcpsockclient open')
  468. cli.expect('Done', timeout=5)
  469. ocf.wait(cli, 3)
  470. host_ipv4_address = ocf.get_host_ipv4_address()
  471. connect_address = ocf.get_ipv6_from_ipv4(host_ipv4_address, br)
  472. print('connect_address is: ', connect_address)
  473. mytcp = ocf.tcp_parameter('INET4', host_ipv4_address, 12345, False, False, 15.0, b'')
  474. tcp_mission = threading.Thread(target=ocf.create_host_tcp_server, args=(mytcp, ))
  475. tcp_mission.start()
  476. start_time = time.time()
  477. while not mytcp.listen_flag:
  478. if (time.time() - start_time) > 10:
  479. assert False
  480. command = 'tcpsockclient connect ' + connect_address + ' 12345'
  481. cli.write(command)
  482. cli.expect('Successfully connected', timeout=10)
  483. start_time = time.time()
  484. while not mytcp.recv_flag:
  485. if (time.time() - start_time) > 10:
  486. assert False
  487. command = 'tcpsockclient send hello'
  488. cli.write(command)
  489. cli.expect('Done', timeout=5)
  490. while tcp_mission.is_alive():
  491. time.sleep(1)
  492. finally:
  493. br.write('factoryreset')
  494. cli.write('factoryreset')
  495. time.sleep(3)
  496. assert b'hello' in mytcp.tcp_bytes