test_function.py 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068
  1. #!/usr/bin/python
  2. # _*_ coding: utf-8 _*_
  3. try:
  4. from Tkinter import * # python2
  5. import ttk
  6. import tkMessageBox
  7. except Exception as e:
  8. from tkinter import * # python3
  9. from tkinter import ttk
  10. from tkinter import messagebox as tkMessageBox
  11. import time
  12. import os
  13. import threading
  14. import random
  15. from requests_offline import requests
  16. def ask_choice_with_timeout(title, message, timeout=5, default_choice=False):
  17. # 创建顶层弹窗窗口(Python 2 Tkinter语法)
  18. import Tkinter as tk
  19. top = tk.Toplevel()
  20. top.title(title)
  21. top.geometry("350x180") # 弹窗大小
  22. top.resizable(False, False) # 禁止调整大小
  23. # 设置模态窗口(阻塞主窗口操作)
  24. top.transient(top.master)
  25. top.grab_set()
  26. # 存储结果(用列表实现可变变量,Python 2中nonlocal仅在3.x支持)
  27. result = [default_choice]
  28. # 显示提示信息
  29. msg_label = tk.Label(top, text=message, padx=20, pady=20, font=("Arial", 10))
  30. msg_label.pack(fill=tk.X)
  31. # 显示倒计时提示
  32. timeout_text = "{}秒后自动{}...".format(timeout, "确认" if default_choice else "取消")
  33. timeout_label = tk.Label(top, text=timeout_text, fg="gray", font=("Arial", 9))
  34. timeout_label.pack()
  35. # 按钮回调函数
  36. def on_ok():
  37. result[0] = True
  38. top.destroy()
  39. def on_cancel():
  40. result[0] = False
  41. top.destroy()
  42. # 按钮布局
  43. btn_frame = tk.Frame(top)
  44. btn_frame.pack(pady=15)
  45. ok_btn = tk.Button(btn_frame, text="OK", command=on_ok, width=8)
  46. cancel_btn = tk.Button(btn_frame, text="Cancel", command=on_cancel, width=8)
  47. ok_btn.pack(side=tk.LEFT, padx=10)
  48. cancel_btn.pack(side=tk.LEFT, padx=10)
  49. # 倒计时线程(Python 2 threading语法)
  50. def countdown():
  51. current_timeout = timeout
  52. while current_timeout > 0:
  53. current_timeout -= 1
  54. # 更新倒计时文本
  55. new_text = "{}秒后自动{}...".format(current_timeout, "确认" if default_choice else "取消")
  56. print(new_text)
  57. timeout_label.config(text=new_text)
  58. top.update() # 刷新界面
  59. time.sleep(1) # 等待1秒
  60. top.destroy() # 超时关闭窗口
  61. # 启动守护线程(Python 2兼容)
  62. t = threading.Thread(target=countdown)
  63. t.setDaemon(True) # 守护线程,主程序退出时自动结束
  64. t.start()
  65. # 等待窗口关闭
  66. top.wait_window()
  67. return result[0]
  68. def step1_routine(context, *args):
  69. # bios_version
  70. context.print1("==SubTest: 检查BIOS版本号 - Titem_1")
  71. time.sleep(0.1)
  72. context.print1("-:) sh os-ver.sh bios")
  73. a = os.popen("sh os-ver.sh bios").read().replace('\n', '').replace('\r', '').strip()
  74. if len(a) == 0:
  75. return False, "Error! No Device found!\n" + a
  76. else:
  77. return True, 'PASS-{}'.format(a)
  78. def step2_routine(context):
  79. # bios release date # ec version
  80. context.print1("==SubTest: 检查EC版本号 - Titem_2")
  81. context.print1("-:) sh os-ver.sh ec")
  82. a = os.popen('sh os-ver.sh ec').read().replace('\n', '').replace('\r', '').strip()
  83. if len(a) == 0:
  84. return False, "Error! No Device found!\n" + a
  85. else:
  86. return True, 'PASS-{}'.format(a)
  87. def step3_routine(context):
  88. # CPU type
  89. context.print1("==SubTest: 检查CPU type - Titem_4")
  90. context.print1("-:) cat /proc/cpuinfo | grep \"model name\" | awk '{print $5}' | head -1")
  91. a = os.popen("cat /proc/cpuinfo").read().strip()
  92. context.print1("output: {}".format(a))
  93. a = os.popen("cat /proc/cpuinfo | grep \"model name\" | awk '{print $5}' | head -1").read().replace('\n','').replace('\r', '').strip()
  94. if len(a) == 0:
  95. return False, "Error! No Device found!\n" + a
  96. else:
  97. return True, 'PASS-{}'.format(a)
  98. def step4_routine(context):
  99. # memory_version
  100. context.print1("==SubTest: 检查Memory内存版本号 - Titem_5")
  101. context.print1("-:) sh mem-ver.sh")
  102. a = os.popen("sh mem-ver.sh").read().replace('\n', '').replace('\r', '').strip()
  103. if len(a) == 0:
  104. return False, "Error! No Device found!\n" + a
  105. else:
  106. return True, 'PASS-{}'.format(a)
  107. def step5_routine(context):
  108. # hdd_version
  109. context.print1("==SubTest: 检查HDD硬盘版本号 - Titem_6")
  110. context.print1("-:) sh hdd-ver.sh")
  111. b = os.popen("sh hdd-ver.sh").read().strip()
  112. a = os.popen("cat /sys/block/nvme0n1/device/firmware_rev").read().replace('\n', '').replace('\r', '').strip()
  113. context.print1("output: {}".format(a))
  114. if len(a) == 0:
  115. return False, "Error! No Device found! " + a
  116. else:
  117. return True, 'PASS-{}'.format(a)
  118. def step6_routine(context):
  119. # os_version
  120. context.print1("==SubTest: 检查OS操作系统版本号 - Titem_7")
  121. context.print1("-:) lsb_release -rs")
  122. string = "os"
  123. a = os.popen("lsb_release -rs").read().strip()
  124. context.print1("output: {}".format(a))
  125. if a == "22.04":
  126. return True, 'PASS-{}'.format(a)
  127. else:
  128. return False, "Error! No Device found! " + a
  129. def step7_routine(context):
  130. context.print1("==SubTest: RTC电池 - Titem_8")
  131. context.print1("-:) sh os-ver.sh RTCBATTERY")
  132. a = os.popen("sh os-ver.sh RTCBATTERY").read().replace('\n', '').replace('\r', '').strip()
  133. try:
  134. a_int = int(a)
  135. except ValueError:
  136. return False, "Invalid output: {}".format(a)
  137. if 2900 <= a_int <= 4000:
  138. return True, a_int
  139. else:
  140. return False, "FAIL " + a
  141. def step8_routine(context):
  142. # usb function
  143. context.print1("==SubTest: USB基本功能测试 - Titem_9")
  144. context.print1("-:) lsblk -d -o TRAN,NAME,SIZE")
  145. b = os.popen("lsblk -d -o TRAN,NAME,SIZE").read().replace('\n', '').replace('\r', '').strip()
  146. context.print1("output: {}".format(b))
  147. b = os.popen("lsusb").read().replace('\n', '').replace('\r', '').strip()
  148. context.print1("output: {}".format(b))
  149. context.print1("-:) lsblk -d -o TRAN,NAME,SIZE | grep usb | wc -l")
  150. a = os.popen("lsblk -d -o TRAN,NAME,SIZE | grep usb | wc -l").read().replace('\n', '').replace('\r', '').strip()
  151. try:
  152. a_int = int(a)
  153. except ValueError:
  154. return False, "Invalid output: {}".format(a)
  155. if a_int == 5:
  156. return True, a
  157. else:
  158. return False, "FAIL " + a
  159. def step9_routine(context):
  160. # network speed cli
  161. context.print1("==SubTest: 检查网络在线速度测试 - Titem_10")
  162. context.print1("-:) ip link show | grep -c 'BROADCAST,MULTICAST,UP,LOWER_UP'")
  163. c = os.popen("ip link show | grep -c \"BROADCAST,MULTICAST,UP,LOWER_UP\"").read().strip()
  164. context.print1("output: {}".format(c))
  165. try:
  166. c_int = int(c)
  167. except ValueError:
  168. return False, "Invalid output c: {}".format(c)
  169. if c_int != 1:
  170. return False, "FAIL " + "Error! No Device found!"
  171. if(context.device_info['offline_test']):
  172. context.print1("-:) ping -c 10 www.baidu.com | grep -E 'packet loss' | awk -F'[,%]' '{print $2}' | tr -d ' ' | tr -d 'received'")
  173. b = os.popen("ping -c 10 www.baidu.com")
  174. context.print1("output: {}".format(b))
  175. b = os.popen("ping -c 10 www.baidu.com | grep -E 'packet loss' | awk -F'[,%]' '{print $2}' | tr -d ' ' | tr -d 'received'").read().replace('\n', '').replace('\r', '').strip()
  176. else:
  177. context.print1("-:) ping -c 10 10.60.64.87 | grep -E 'packet loss' | awk -F'[,%]' '{print $2}' | tr -d ' ' | tr -d 'received'")
  178. b = os.popen("ping -c 10 10.60.64.87")
  179. context.print1("output: {}".format(b))
  180. b = os.popen("ping -c 10 10.60.64.87 | grep -E 'packet loss' | awk -F'[,%]' '{print $2}' | tr -d ' ' | tr -d 'received'").read().replace('\n', '').replace('\r', '').strip()
  181. try:
  182. b_int = int(b)
  183. except ValueError:
  184. return False, "Invalid output b: {}".format(b)
  185. if b_int == 10:
  186. return True, b
  187. else:
  188. return False, "FAIL " + "Error! No Device found! {}".format(b)
  189. def step10_routine(context):
  190. return True, 'AAPASS'
  191. #serialA
  192. context.print1("==SubTest: UartA_Test - Titem_9")
  193. context.print1("-:) sh pcie.sh")
  194. a = os.popen("sh pcie.sh").read().strip()
  195. context.print1("{}".format(a))
  196. context.print1("-:) sh serialport-test.sh /dev/ttyWCH0")
  197. time.sleep(1)
  198. ttyWCH0 = os.popen("sh serialport-test.sh /dev/ttyWCH0").read().strip()
  199. try:
  200. a_int = int(ttyWCH0)
  201. except ValueError:
  202. return False, "Invalid output ttyWCH0: {}".format(ttyWCH0)
  203. if a_int == 1:
  204. context.print1("output ttyWCH0: {}".format(ttyWCH0))
  205. context.print1("output A: {}".format("A1-2"))
  206. pass
  207. else:
  208. context.print1("output ttyWCH0: {}".format(ttyWCH0))
  209. context.print1("output A: {}".format("A1-2"))
  210. return False, "FAIL " + "Error! No Device found! A1-2"
  211. context.print1("-:) sh serialport-test.sh /dev/ttyWCH1")
  212. ttyWCH1 = os.popen("sh serialport-test.sh /dev/ttyWCH1").read().strip()
  213. try:
  214. a_int = int(ttyWCH1)
  215. except ValueError:
  216. return False, "Invalid output ttyWCH1: {}".format(ttyWCH1)
  217. if a_int == 1:
  218. context.print1("output ttyWCH1: {}".format(ttyWCH1))
  219. context.print1("output A: {}".format("A1-6"))
  220. pass
  221. else:
  222. context.print1("output ttyWCH1: {}".format(ttyWCH1))
  223. context.print1("output A: {}".format("A1-6"))
  224. return False, "FAIL " + "Error! No Device found! A1-6"
  225. context.print1("-:) sh serialport-test.sh /dev/ttyWCH2")
  226. ttyWCH2 = os.popen("sh serialport-test.sh /dev/ttyWCH2").read().strip()
  227. try:
  228. a_int = int(ttyWCH2)
  229. except ValueError:
  230. return False, "Invalid output ttyWCH2: {}".format(ttyWCH2)
  231. if a_int == 1:
  232. context.print1("output ttyWCH2: {}".format(ttyWCH2))
  233. context.print1("output A: {}".format("A1-1"))
  234. pass
  235. else:
  236. context.print1("output ttyWCH2: {}".format(ttyWCH2))
  237. context.print1("output A: {}".format("A1-1"))
  238. return False, "FAIL " + "Error! No Device found! A1-1"
  239. context.print1("-:) sh serialport-test.sh /dev/ttyWCH3")
  240. ttyWCH3 = os.popen("sh serialport-test.sh /dev/ttyWCH3").read().strip()
  241. try:
  242. a_int = int(ttyWCH3)
  243. except ValueError:
  244. return False, "Invalid output ttyWCH3: {}".format(ttyWCH3)
  245. if a_int == 1:
  246. context.print1("output ttyWCH3: {}".format(ttyWCH3))
  247. context.print1("output A: {}".format("A1-5"))
  248. pass
  249. else:
  250. context.print1("output ttyWCH3: {}".format(ttyWCH3))
  251. context.print1("output A: {}".format("A1-5"))
  252. return False, "FAIL " + "Error! No Device found! A1-5"
  253. context.print1("-:) sh serialport-test.sh /dev/ttyWCH4")
  254. ttyWCH4 = os.popen("sh serialport-test.sh /dev/ttyWCH4").read().strip()
  255. try:
  256. a_int = int(ttyWCH4)
  257. except ValueError:
  258. return False, "Invalid output ttyWCH4: {}".format(ttyWCH4)
  259. if a_int == 1:
  260. context.print1("output ttyWCH4: {}".format(ttyWCH4))
  261. context.print1("output A: {}".format("A1-4"))
  262. pass
  263. else:
  264. context.print1("output ttyWCH4: {}".format(ttyWCH4))
  265. context.print1("output A: {}".format("A1-4"))
  266. return False, "FAIL " + "Error! No Device found! A1-4"
  267. context.print1("-:) sh serialport-test.sh /dev/ttyWCH5")
  268. ttyWCH5 = os.popen("sh serialport-test.sh /dev/ttyWCH5").read().strip()
  269. try:
  270. a_int = int(ttyWCH5)
  271. except ValueError:
  272. return False, "Invalid output ttyWCH5: {}".format(ttyWCH5)
  273. if a_int == 1:
  274. context.print1("output ttyWCH5: {}".format(ttyWCH5))
  275. context.print1("output A: {}".format("A1-8"))
  276. pass
  277. else:
  278. context.print1("output ttyWCH5: {}".format(ttyWCH5))
  279. context.print1("output A: {}".format("A1-8"))
  280. return False, "FAIL " + "Error! No Device found! A1-8"
  281. context.print1("-:) sh serialport-test.sh /dev/ttyWCH6")
  282. ttyWCH6 = os.popen("sh serialport-test.sh /dev/ttyWCH6").read().strip()
  283. try:
  284. a_int = int(ttyWCH6)
  285. except ValueError:
  286. return False, "Invalid output ttyWCH6: {}".format(ttyWCH6)
  287. if a_int == 1:
  288. context.print1("output ttyWCH6: {}".format(ttyWCH6))
  289. context.print1("output A: {}".format("A1-3"))
  290. pass
  291. else:
  292. context.print1("output ttyWCH6: {}".format(ttyWCH6))
  293. context.print1("output A: {}".format("A1-3"))
  294. return False, "FAIL " + "Error! No Device found! A1-3"
  295. context.print1("-:) sh serialport-test.sh /dev/ttyWCH7")
  296. ttyWCH7 = os.popen("sh serialport-test.sh /dev/ttyWCH7").read().strip()
  297. try:
  298. a_int = int(ttyWCH7)
  299. except ValueError:
  300. return False, "Invalid output ttyWCH7: {}".format(ttyWCH7)
  301. if a_int == 1:
  302. context.print1("output ttyWCH7: {}".format(ttyWCH7))
  303. context.print1("output A: {}".format("A1-7"))
  304. pass
  305. else:
  306. context.print1("output ttyWCH7: {}".format(ttyWCH7))
  307. context.print1("output A: {}".format("A1-7"))
  308. return False, "FAIL " + "Error! No Device found! A1-7"
  309. return True, "PASS"
  310. def step11_routine(context):
  311. return True, 'AAPASS'
  312. #serialB
  313. context.print1("==SubTest: UartB_Test - Titem_10")
  314. a = os.popen("sh pcie.sh").read().strip()
  315. time.sleep(1)
  316. context.print1("-:) sh serialport-test.sh /dev/ttyWCH8")
  317. ttyWCH8 = os.popen("sh serialport-test.sh /dev/ttyWCH8").read().strip()
  318. try:
  319. a_int = int(ttyWCH8)
  320. except ValueError:
  321. return False, "Invalid output ttyWCH8: {}".format(ttyWCH8)
  322. if a_int == 1:
  323. context.print1("output ttyWCH8: {}".format(ttyWCH8))
  324. context.print1("output A: {}".format("A2-4"))
  325. pass
  326. else:
  327. context.print1("output ttyWCH8: {}".format(ttyWCH8))
  328. context.print1("output A: {}".format("A2-4"))
  329. return False, "FAIL " + "Error! No Device found! A2-4"
  330. context.print1("-:) sh serialport-test.sh /dev/ttyWCH9")
  331. ttyWCH9 = os.popen("sh serialport-test.sh /dev/ttyWCH9").read().strip()
  332. try:
  333. a_int = int(ttyWCH9)
  334. except ValueError:
  335. return False, "Invalid output ttyWCH9: {}".format(ttyWCH9)
  336. if a_int == 1:
  337. context.print1("output ttyWCH9: {}".format(ttyWCH9))
  338. context.print1("output A: {}".format("A2-8"))
  339. pass
  340. else:
  341. context.print1("output ttyWCH9: {}".format(ttyWCH9))
  342. context.print1("output A: {}".format("A2-8"))
  343. return False, "FAIL " + "Error! No Device found! A2-8"
  344. context.print1("-:) sh serialport-test.sh /dev/ttyWCH10")
  345. ttyWCH10 = os.popen("sh serialport-test.sh /dev/ttyWCH10").read().strip()
  346. try:
  347. a_int = int(ttyWCH10)
  348. except ValueError:
  349. return False, "Invalid output ttyWCH10: {}".format(ttyWCH10)
  350. if a_int == 1:
  351. context.print1("output ttyWCH10: {}".format(ttyWCH10))
  352. context.print1("output A: {}".format("A2-3"))
  353. pass
  354. else:
  355. context.print1("output ttyWCH10: {}".format(ttyWCH10))
  356. context.print1("output A: {}".format("A2-3"))
  357. return False, "FAIL " + "Error! No Device found! A2-3"
  358. context.print1("-:) sh serialport-test.sh /dev/ttyWCH11")
  359. ttyWCH11 = os.popen("sh serialport-test.sh /dev/ttyWCH11").read().strip()
  360. try:
  361. a_int = int(ttyWCH11)
  362. except ValueError:
  363. return False, "Invalid output ttyWCH11: {}".format(ttyWCH11)
  364. if a_int == 1:
  365. context.print1("output ttyWCH11: {}".format(ttyWCH11))
  366. context.print1("output A: {}".format("A2-7"))
  367. pass
  368. else:
  369. context.print1("output ttyWCH11: {}".format(ttyWCH11))
  370. context.print1("output A: {}".format("A2-7"))
  371. return False, "FAIL " + "Error! No Device found! A2-7"
  372. context.print1("-:) sh serialport-test.sh /dev/ttyWCH12")
  373. ttyWCH12 = os.popen("sh serialport-test.sh /dev/ttyWCH12").read().strip()
  374. try:
  375. a_int = int(ttyWCH12)
  376. except ValueError:
  377. return False, "Invalid output ttyWCH12: {}".format(ttyWCH12)
  378. if a_int == 1:
  379. context.print1("output ttyWCH12: {}".format(ttyWCH12))
  380. context.print1("output A: {}".format("A2-2"))
  381. pass
  382. else:
  383. context.print1("output ttyWCH12: {}".format(ttyWCH12))
  384. context.print1("output A: {}".format("A2-2"))
  385. return False, "FAIL " + "Error! No Device found! A2-2"
  386. context.print1("-:) sh serialport-test.sh /dev/ttyWCH13")
  387. ttyWCH13 = os.popen("sh serialport-test.sh /dev/ttyWCH13").read().strip()
  388. try:
  389. a_int = int(ttyWCH13)
  390. except ValueError:
  391. return False, "Invalid output ttyWCH13: {}".format(ttyWCH13)
  392. if a_int == 1:
  393. context.print1("output ttyWCH13: {}".format(ttyWCH13))
  394. context.print1("output A: {}".format("A2-6"))
  395. pass
  396. else:
  397. context.print1("output ttyWCH13: {}".format(ttyWCH13))
  398. context.print1("output A: {}".format("A2-6"))
  399. return False, "FAIL " + "Error! No Device found! A2-6"
  400. context.print1("-:) sh serialport-test.sh /dev/ttyWCH14")
  401. ttyWCH14 = os.popen("sh serialport-test.sh /dev/ttyWCH14").read().strip()
  402. try:
  403. a_int = int(ttyWCH14)
  404. except ValueError:
  405. return False, "Invalid output ttyWCH14: {}".format(ttyWCH14)
  406. if a_int == 1:
  407. context.print1("output ttyWCH14: {}".format(ttyWCH14))
  408. context.print1("output A: {}".format("A2-1"))
  409. pass
  410. else:
  411. context.print1("output ttyWCH14: {}".format(ttyWCH14))
  412. context.print1("output A: {}".format("A2-1"))
  413. return False, "FAIL " + "Error! No Device found! A2-1"
  414. context.print1("-:) sh serialport-test.sh /dev/ttyWCH15")
  415. ttyWCH15 = os.popen("sh serialport-test.sh /dev/ttyWCH15").read().strip()
  416. try:
  417. a_int = int(ttyWCH15)
  418. except ValueError:
  419. return False, "Invalid output ttyWCH15: {}".format(ttyWCH15)
  420. if a_int == 1:
  421. context.print1("output ttyWCH15: {}".format(ttyWCH15))
  422. context.print1("output A: {}".format("A2-5"))
  423. pass
  424. else:
  425. context.print1("output ttyWCH15: {}".format(ttyWCH15))
  426. context.print1("output A: {}".format("A2-5"))
  427. return False, "FAIL " + "Error! No Device found! A2-5"
  428. return True, "PASS"
  429. def step12_routine(context):
  430. #serialC
  431. context.print1("==SubTest: UartC_Test - Titem_11")
  432. context.print1("-:) sh serialport-test.sh /dev/ttyS0")
  433. ttyS0 = os.popen("sh serialport-test.sh /dev/ttyS0").read().strip()
  434. try:
  435. a_int = int(ttyS0)
  436. except ValueError:
  437. return False, "Invalid output ttyS0: {}".format(ttyS0)
  438. if a_int == 1:
  439. context.print1("output ttyS0: {}".format(ttyS0))
  440. context.print1("output COM: {}".format("COM2"))
  441. pass
  442. else:
  443. context.print1("output ttyS0: {}".format(ttyS0))
  444. context.print1("output COM: {}".format("COM2"))
  445. return False, "FAIL " + "Error! No Device found! COM2"
  446. context.print1("-:) sh serialport-test.sh /dev/ttyS1")
  447. ttyS1 = os.popen("sh serialport-test.sh /dev/ttyS1").read().strip()
  448. try:
  449. a_int = int(ttyS1)
  450. except ValueError:
  451. return False, "Invalid output ttyS1: {}".format(ttyS1)
  452. if a_int == 1:
  453. context.print1("output ttyS1: {}".format(ttyS1))
  454. context.print1("output COM: {}".format("COM5"))
  455. pass
  456. else:
  457. context.print1("output ttyS1: {}".format(ttyS1))
  458. context.print1("output COM: {}".format("COM5"))
  459. return False, "FAIL " + "Error! No Device found! COM5"
  460. context.print1("-:) sh serialport-test.sh /dev/ttyS2")
  461. ttyS2 = os.popen("sh serialport-test.sh /dev/ttyS2").read().strip()
  462. try:
  463. a_int = int(ttyS2)
  464. except ValueError:
  465. return False, "Invalid output ttyS2: {}".format(ttyS2)
  466. if a_int == 1:
  467. context.print1("output ttyS2: {}".format(ttyS2))
  468. context.print1("output COM: {}".format("COM1"))
  469. pass
  470. else:
  471. context.print1("output ttyS2: {}".format(ttyS2))
  472. context.print1("output COM: {}".format("COM1"))
  473. return False, "FAIL " + "Error! No Device found! COM1"
  474. context.print1("-:) sh serialport-test.sh /dev/ttyS3")
  475. ttyS3 = os.popen("sh serialport-test.sh /dev/ttyS3").read().strip()
  476. try:
  477. a_int = int(ttyS3)
  478. except ValueError:
  479. return False, "Invalid output ttyS3: {}".format(ttyS3)
  480. if a_int == 1:
  481. context.print1("output ttyS3: {}".format(ttyS3))
  482. context.print1("output COM: {}".format("COM4"))
  483. pass
  484. else:
  485. context.print1("output ttyS3: {}".format(ttyS3))
  486. context.print1("output COM: {}".format("COM4"))
  487. return False, "FAIL " + "Error! No Device found! COM4"
  488. # ttyS4 = os.popen("sh serialport-test.sh /dev/ttyS4").read().strip()
  489. # try:
  490. # a_int = int(ttyS4)
  491. # except ValueError:
  492. # return False, "Invalid output ttyS4: {}".format(ttyS4)
  493. # if a_int == 1:
  494. # pass
  495. # else:
  496. # return False, "FAIL " + "Error! No Device found! ttyS4"
  497. # ttyS5 = os.popen("sh serialport-test.sh /dev/ttyS5").read().strip()
  498. # try:
  499. # a_int = int(ttyS5)
  500. # except ValueError:
  501. # return False, "Invalid output ttyS5: {}".format(ttyS5)
  502. # if a_int == 1:
  503. # pass
  504. # else:
  505. # return False, "FAIL " + "Error! No Device found! ttyS5"
  506. context.print1("-:) sh serialport-test.sh /dev/ttyS6")
  507. ttyS6 = os.popen("sh serialport-test.sh /dev/ttyS6").read().strip()
  508. try:
  509. a_int = int(ttyS6)
  510. except ValueError:
  511. return False, "Invalid output ttyS6: {}".format(ttyS6)
  512. if a_int == 1:
  513. context.print1("output ttyS6: {}".format(ttyS6))
  514. context.print1("output COM: {}".format("COM3"))
  515. pass
  516. else:
  517. context.print1("output ttyS6: {}".format(ttyS6))
  518. context.print1("output COM: {}".format("COM3"))
  519. return False, "FAIL " + "Error! No Device found! COM3"
  520. context.print1("-:) sh serialport-test.sh /dev/ttyS7")
  521. ttyS7 = os.popen("sh serialport-test.sh /dev/ttyS7").read().strip()
  522. try:
  523. a_int = int(ttyS7)
  524. except ValueError:
  525. return False, "Invalid output ttyS7: {}".format(ttyS7)
  526. if a_int == 1:
  527. context.print1("output ttyS7: {}".format(ttyS7))
  528. context.print1("output COM: {}".format("COM6"))
  529. pass
  530. else:
  531. context.print1("output ttyS7: {}".format(ttyS7))
  532. context.print1("output COM: {}".format("COM6"))
  533. return False, "FAIL " + "Error! No Device found! COM6"
  534. return True, "PASS"
  535. def step13_routine(context):
  536. #LCD Test
  537. context.print1("==SubTest: lcd测试 - Titem_14")
  538. context.print1("-:) ./lcd/lcd/lcd_app | grep -c 'LCD test completed'")
  539. a = os.popen('./lcd/lcd/lcd_app').read().replace('\n', '').replace('\r', '').strip()
  540. context.print1("output: {}".format(a))
  541. a = os.popen('./lcd/lcd/lcd_app | grep -c "LCD test completed"').read().replace('\n', '').replace('\r', '').strip()
  542. try:
  543. a_int = int(a)
  544. except ValueError:
  545. return False, "Invalid output a: {}".format(a)
  546. if a_int == 1:
  547. return True, 'PASS-{}'.format(a)
  548. else:
  549. return False, "FAIL " + "Error! No Device found!"
  550. def step14_routine(context):
  551. #LED Test
  552. context.print1("==SubTest: led测试 - Titem_15")
  553. context.print1("-:) sh led-test.sh")
  554. a = os.popen("sh led-test.sh").read().replace('\n', '').replace('\r', '').strip()
  555. context.print1("output: {}".format(a))
  556. a = os.popen("sh led-test.sh | tail -1").read().replace('\n', '').replace('\r', '').strip()
  557. try:
  558. a_int = int(a)
  559. except ValueError:
  560. return False, "Invalid output: {}".format(a)
  561. if a_int == 1:
  562. return True, 'PASS-{}'.format(a)
  563. else:
  564. return False, "FAIL " + "Error! No Device found!"
  565. def step15_routine(context):
  566. context.print1("==SubTest: 检查电池健康指示灯功能测试 - Titem_16")
  567. context.print1("-:) sh led-test.sh")
  568. a = os.popen("sh led-test.sh | tail -1").read().replace('\n', '').replace('\r', '').strip()
  569. try:
  570. a_int = int(a)
  571. except ValueError:
  572. return False, "Invalid output: {}".format(a)
  573. if a_int == 1:
  574. return True, 'PASS-{}'.format(a)
  575. else:
  576. return False, "FAIL " + "Error! No Device found!"
  577. def step16_routine(context):
  578. context.print1("==SubTest: 检查拨码开关功能测试 - Titem_17")
  579. context.print1("-:) ls /dev/")
  580. return True, 'AAPASS'
  581. # a = os.popen("sh os-ver.sh USB394").read().replace('\n', '').replace('\r', '').strip()
  582. # if a == "0":
  583. # return False, "Error! No Device found!\n" + a
  584. # else:
  585. # return True, 'PASS-{}'.format(a)
  586. def step17_routine(context):
  587. context.print1("==SubTest: Console接口测试 - Titem_18")
  588. context.print1("-:) ls /dev/")
  589. return True, 'AAPASS'
  590. a = os.popen("sh os-ver.sh speedcliDownload").read().replace('\n', '').replace('\r', '').strip()
  591. if len(a) == 0:
  592. return False, "Error! No Device found!\n" + a
  593. elif a == "Download: Upload:":
  594. return False, "Error! no ethernet!\n" + a
  595. else:
  596. return True, 'PASS-{}'.format(a)
  597. def step18_routine(context):
  598. context.print1("==SubTest: Buzzer基本功能测试 - Titem_19")
  599. context.print1("-:) sh beep.sh")
  600. a = os.popen("sh beep.sh").read().replace('\n', '').replace('\r', '').strip()
  601. if tkMessageBox.askokcancel("PASS?", "测试蜂鸣器是否正常."):
  602. # if ask_choice_with_timeout("PASS?", "测试蜂鸣器是否正常.",30):
  603. return True, 'PASS'
  604. else:
  605. return False, "FAIL"
  606. def step19_routine(context):
  607. context.print1("==SubTest: SATA_SSD基本功能测试 - Titem_20")
  608. context.print1("-:) lsblk -o NAME,TYPE,MOUNTPOINT,MODEL")
  609. a = os.popen("lsblk -o NAME,TYPE,MOUNTPOINT,MODEL").read().strip()
  610. context.print1("output: {}".format(a))
  611. context.print1("-:) ls -l /dev/disk/by-id/ | grep ata-")
  612. b = os.popen("ls -l /dev/disk/by-id/ | grep -c ata-").read().strip()
  613. context.print1("output: {}".format(b))
  614. b = os.popen("ls -l /dev/disk/by-id/ | grep -c ata-").read().replace('\n', '').replace('\r', '').strip()
  615. if b == "1":
  616. return True, 'PASS-{}'.format(b)
  617. else:
  618. return False, "Error! No Device found! " + b
  619. def step20_routine(context):
  620. context.print1("==SubTest: HeadBest_Test - Titem_21")
  621. return True, 'AAPASS'
  622. def step21_routine(context):
  623. context.print1("==SubTest: 数码管测试 - Titem_22")
  624. context.print1("-:) sh seven_segment_display.sh")
  625. a = os.popen("sh seven_segment_display.sh").read().replace('\n', '').replace('\r', '').strip()
  626. if tkMessageBox.askokcancel("PASS?", "测试数码管是否正常."):
  627. # if ask_choice_with_timeout("PASS?", "测试数码管是否正常.",30):
  628. return True, 'PASS'
  629. else:
  630. return False, "FAIL"
  631. def step22_routine(context):
  632. return True, 'AAPASS'
  633. def step23_routine(context):
  634. return True, 'AAPASS'
  635. def step24_routine(context):
  636. return True, 'AAPASS'
  637. def step25_routine(context):
  638. return True, 'AAPASS'
  639. def step26_routine(context):
  640. return True, 'AAPASS'
  641. def step27_routine(context):
  642. context.print1("==SubTest: 检查gsensor基本功能测试 - Titem_23")
  643. context.print1("-:) bash ./gsensor-SC7A20H/C180_gsensor_function_script.sh")
  644. context.print1("10s内手动转动屏幕,才能测试PASS!")
  645. a = os.popen("bash ./gsensor-SC7A20H/C180_gsensor_function_script.sh | grep -c \"pass\"").read().replace('\n', '').replace('\r', '').strip()
  646. try:
  647. a_int = int(a)
  648. except ValueError:
  649. return False, "Invalid output: {}".format(a)
  650. if a_int == 1:
  651. return True, 'PASS-{}'.format(a)
  652. else:
  653. return False, "FAIL " + "Error! No Device found!"
  654. def step28_routine(context):
  655. return True, 'AAPASS'
  656. def step29_routine(context):
  657. a = os.popen("sh display.sh 111111 | wc -l").read().replace('\n', '').replace('\r', '').strip()
  658. a = os.popen("find ./test_picture/ -name '*.jpg' | wc -l").read().strip()
  659. try:
  660. a_int = int(a)
  661. except ValueError:
  662. return False, "Invalid output: {}".format(a)
  663. if a_int >= 0:
  664. return True, 'PASS-{}'.format(a)
  665. else:
  666. return False, "FAIL " + "Error! No Device found!"
  667. def step30_routine(context):
  668. a = os.popen("sh fio.sh 111111 | wc -l").read().replace('\n', '').replace('\r', '').strip()
  669. try:
  670. a_int = int(a)
  671. except ValueError:
  672. return False, "Invalid output: {}".format(a)
  673. if a_int >= 0:
  674. return True, 'PASS-{}'.format(a)
  675. else:
  676. return False, "FAIL " + "Error! No Device found!"
  677. def step31_routine(context):
  678. a = os.popen("sh os-ver.sh speaker | wc -l").read().replace('\n', '').replace('\r', '').strip()
  679. try:
  680. a_int = int(a)
  681. except ValueError:
  682. return False, "Invalid output: {}".format(a)
  683. if a_int >= 0:
  684. return True, 'PASS-{}'.format(a)
  685. else:
  686. return False, "FAIL " + "Error! No Device found!"
  687. def step32_routine(context):
  688. a = os.popen("sh record_play.sh 111111 | wc -l").read().replace('\n', '').replace('\r', '').strip()
  689. a = os.popen("echo 111111 | sudo -S find /tmp/ -name 'my_recording.wav' 2>&1 | wc -l").read().strip()
  690. try:
  691. a_int = int(a)
  692. except ValueError:
  693. return False, "Invalid output: {}".format(a)
  694. if a_int >= 0:
  695. return True, 'PASS-{}'.format(a)
  696. else:
  697. return False, "FAIL " + "Error! No Device found!"
  698. def step33_routine(context):
  699. a = os.popen("sh led-test.sh | tail -1").read().replace('\n', '').replace('\r', '').strip()
  700. try:
  701. a_int = int(a)
  702. except ValueError:
  703. return False, "Invalid output: {}".format(a)
  704. if a_int == 1:
  705. return True, 'PASS-{}'.format(a)
  706. else:
  707. return False, "FAIL " + "Error! No Device found!"
  708. def step34_routine(context):
  709. #a = os.popen("/usr/bin/guvcview &").read().replace('\n', '').replace('\r', '').strip()
  710. os.system("/usr/bin/guvcview &")
  711. time.sleep(15)
  712. os.system("sh os-ver.sh exit &")
  713. return True, 'PASS'
  714. def step35_routine(context):
  715. context.print1("==SubTest: 外置键盘测试 - Titem_24")
  716. context.print1("-:) sh ./keyboard.sh 111111")
  717. a = os.popen("sh ./keyboard.sh 111111").read().replace('\n', '').replace('\r', '').strip()
  718. context.print1("output: {}".format(a))
  719. try:
  720. if len(a) == 1:
  721. return False, "FAIL " + "Error! No Device found! {}".format(a)
  722. elif a == "":
  723. return False, "FAIL " + "Error! no cashDrawer!"
  724. except ValueError:
  725. return False, "Invalid output: {}".format(a)
  726. if len(a) != 0:
  727. return True, 'PASS-{}'.format(a)
  728. else:
  729. return False, "FAIL " + "Error! No Device found!"
  730. def step36_routine(context):
  731. # network speed cli
  732. c = os.popen("ip link show | grep -c \"BROADCAST,MULTICAST,UP,LOWER_UP\"").read().strip()
  733. try:
  734. c_int = int(c)
  735. except ValueError:
  736. return False, "Invalid output c: {}".format(c)
  737. if c_int != 1:
  738. return False, "FAIL " + "Error! No Device found!"
  739. a = os.popen("sh os-ver.sh speedcliDownload").read().replace('\n', '').replace('\r', '').strip()
  740. if len(a) == 0:
  741. return False, "FAIL " + "Error! No Device found! {}".format(a)
  742. elif a == "Download: Upload:":
  743. return False, "FAIL " + "Error! no ethernet!"
  744. else:
  745. b = os.popen("ip link show | grep -c \"BROADCAST,MULTICAST,UP,LOWER_UP\"").read().strip()
  746. try:
  747. b_int = int(b)
  748. except ValueError:
  749. return False, "Invalid output b: {}".format(b)
  750. if b_int == 1:
  751. return True, a
  752. else:
  753. return False, "FAIL " + "Error! No Device found! {}".format(a)
  754. def step37_routine(context):
  755. a = os.popen("lsblk -d -o TRAN,NAME,SIZE | grep usb | wc -l").read().replace('\n', '').replace('\r', '').strip()
  756. try:
  757. a_int = int(a)
  758. except ValueError:
  759. return False, "Invalid output: {}".format(a)
  760. if a_int >= 6:
  761. return True, 'PASS-{}'.format(a)
  762. else:
  763. return False, "FAIL " + "Error! No Device found!"
  764. def step38_routine(context):
  765. time.sleep(1)
  766. os.system("sh os-ver.sh 1080p &")
  767. time.sleep(15)
  768. os.system("sh os-ver.sh exit &")
  769. return True, 'PASS'
  770. def step39_routine(context):
  771. context.print1("==SubTest: 钱箱基本功能测试 - Titem_27")
  772. context.print1("-:) sh ./cashDrawer_test.sh 111111 | tail -n 1")
  773. b = os.popen("sh ./cashDrawer_test.sh 111111").read().replace('\n', '').replace('\r', '').strip()
  774. context.print1("output: {}".format(b))
  775. a = os.popen("sh ./cashDrawer_test.sh 111111 | tail -n 1").read().replace('\n', '').replace('\r', '').strip()
  776. try:
  777. if len(a) == 0:
  778. return False, "FAIL " + "Error! No Device found! {}".format(a)
  779. elif a == "cashDrawer1: , cashDrawer2: ":
  780. return False, "FAIL " + "Error! no cashDrawer!"
  781. except ValueError:
  782. return False, "Invalid output: {}".format(a)
  783. if len(a) > 0:
  784. return True, 'PASS-{}'.format(a)
  785. else:
  786. return False, "FAIL " + "Error! No Device found!"
  787. def step40_routine(context):
  788. #serialC
  789. ttyS0 = os.popen("sh serialport-test.sh /dev/ttyS0").read().strip()
  790. try:
  791. a_int = int(ttyS0)
  792. except ValueError:
  793. return False, "Invalid output ttyS0: {}".format(ttyS0)
  794. if a_int == 1:
  795. pass
  796. else:
  797. return False, "FAIL " + "Error! No Device found! ttyS0"
  798. ttyS1 = os.popen("sh serialport-test.sh /dev/ttyS1").read().strip()
  799. try:
  800. a_int = int(ttyS1)
  801. except ValueError:
  802. return False, "Invalid output ttyS1: {}".format(ttyS1)
  803. if a_int == 1:
  804. pass
  805. else:
  806. return False, "FAIL " + "Error! No Device found! ttyS1"
  807. ttyS2 = os.popen("sh serialport-test.sh /dev/ttyS2").read().strip()
  808. try:
  809. a_int = int(ttyS2)
  810. except ValueError:
  811. return False, "Invalid output ttyS2: {}".format(ttyS2)
  812. if a_int == 1:
  813. pass
  814. else:
  815. return False, "FAIL " + "Error! No Device found! ttyS2"
  816. ttyS3 = os.popen("sh serialport-test.sh /dev/ttyS3").read().strip()
  817. try:
  818. a_int = int(ttyS3)
  819. except ValueError:
  820. return False, "Invalid output ttyS3: {}".format(ttyS3)
  821. if a_int == 1:
  822. pass
  823. else:
  824. return False, "FAIL " + "Error! No Device found! ttyS3"
  825. ttyS6 = os.popen("sh serialport-test.sh /dev/ttyS6").read().strip()
  826. try:
  827. a_int = int(ttyS6)
  828. except ValueError:
  829. return False, "Invalid output ttyS6: {}".format(ttyS6)
  830. if a_int == 1:
  831. pass
  832. else:
  833. return False, "FAIL " + "Error! No Device found! ttyS6"
  834. ttyS7 = os.popen("sh serialport-test.sh /dev/ttyS7").read().strip()
  835. try:
  836. a_int = int(ttyS7)
  837. except ValueError:
  838. return False, "Invalid output ttyS7: {}".format(ttyS7)
  839. if a_int == 1:
  840. pass
  841. else:
  842. return False, "FAIL " + "Error! No Device found! ttyS7"
  843. return True, "PASS"
  844. def step41_routine(context):
  845. a = os.popen("bash usb_test.sh 111111 | grep -s 'PASSED' | wc -l").read().replace('\n', '').replace('\r', '').strip()
  846. #b = os.popen("bash usb_test.sh 111111").read().replace('\n', '').replace('\r', '').strip()
  847. try:
  848. a_int = int(a)
  849. except ValueError:
  850. return False, "Invalid output: {}".format(a)
  851. if a_int >= 1:
  852. return True, 'PASS-{}'.format(a)
  853. else:
  854. return False, "FAIL " + "Error! No Device found!"
  855. def step42_routine(context):
  856. a = os.popen("sh readsn.sh").read().replace('\n', '').replace('\r', '').strip()
  857. try:
  858. if len(a) == 0:
  859. return False, "Error! Serial Number is empty!\n" + a
  860. except ValueError:
  861. return False, "Invalid output: {}".format(a)
  862. if len(a) == 11:
  863. return True, 'PASS-{}'.format(a)
  864. else:
  865. return False, "FAIL " + "Error! No Device found!"
  866. def step43_routine(context):
  867. context.print1("==SubTest: 相机基本功能测试 - Titem_20")
  868. context.print1("-:) /usr/bin/guvcview &")
  869. a = os.popen("/usr/bin/guvcview &").read().replace('\n', '').replace('\r', '').strip()
  870. if tkMessageBox.askokcancel("PASS?", "测试相机是否正常."):
  871. # if ask_choice_with_timeout("PASS?", "测试数码管是否正常.",30):
  872. return True, 'PASS'
  873. else:
  874. return False, "FAIL"
  875. def step44_routine(context):
  876. context.print1("==SubTest: 检查喇叭基本功能测试 - Titem_21")
  877. context.print1("-:) sh os-ver.sh speaker")
  878. a = os.popen("sh os-ver.sh speaker").read().replace('\n', '').replace('\r', '').strip()
  879. if tkMessageBox.askokcancel("PASS?", "测试喇叭是否正常."):
  880. # if ask_choice_with_timeout("PASS?", "测试数码管是否正常.",30):
  881. return True, 'PASS'
  882. else:
  883. return False, "FAIL"
  884. def step45_routine(context):
  885. context.print1("==SubTest: 检查Microphone_Test基本功能测试 - Titem_22")
  886. context.print1("-:) sh os-ver.sh arecord")
  887. a = os.popen("sh os-ver.sh arecord").read().replace('\n', '').replace('\r', '').strip()
  888. if tkMessageBox.askokcancel("PASS?", "测试Microphone_Test是否正常."):
  889. # if ask_choice_with_timeout("PASS?", "测试数码管是否正常.",30):
  890. return True, 'PASS'
  891. else:
  892. return False, "FAIL"
  893. def step46_routine(context):
  894. context.print1("==SubTest: 检查LEDBlinking基本功能测试 - Titem_26")
  895. context.print1("-:) sh lightRing.sh")
  896. a = os.popen("sh lightRing.sh").read().replace('\n', '').replace('\r', '').strip()
  897. if tkMessageBox.askokcancel("PASS?", "测试确定LEDBlinking是否正常?"):
  898. # if ask_choice_with_timeout("PASS?", "测试数码管是否正常.",30):
  899. return True, 'PASS'
  900. else:
  901. return False, "FAIL"
  902. def step47_routine(context):
  903. context.print1("==SubTest: 触摸TP测试C180 - Titem_20")
  904. context.print1("-:) xinput --list | grep -c 'TouchScreen'")
  905. a = os.popen("xinput --list | grep -c 'TouchScreen'").read().replace('\n', '').replace('\r', '').strip()
  906. try:
  907. a_int = int(a)
  908. except ValueError:
  909. return False, "Invalid output: {}".format(a)
  910. if a_int >= 1:
  911. return True, 'PASS-{}'.format(a)
  912. else:
  913. return False, "FAIL " + "Error! No Device found!"