assembly_tests 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. #!/bin/sh
  2. ## Check if tests must be run
  3. RUN_ENV_VAR=$(fw_printenv -n assembly_tests 2>/dev/null)
  4. if [ "x${RUN_ENV_VAR}" != "x1" ]; then
  5. exit 0
  6. fi
  7. rw
  8. ## Lock file
  9. LOCK_FILE=/var/lock/assembly_tests.lock
  10. if [ -f ${LOCK_FILE} ]; then
  11. echo "${LOCK_FILE} already exists"
  12. exit 1
  13. fi
  14. touch ${LOCK_FILE}
  15. ## Register ourself as the running FunKey task for receiving USR1
  16. ## signal for shutting down
  17. pid record $$
  18. ## Binaries
  19. PROD_SCREEN_BIN="/usr/local/sbin/funkey_prod_screens"
  20. GET_PROC_UID="/usr/local/sbin/get_sid"
  21. ## Global Vars
  22. test_failed=false
  23. stop_loop=false
  24. ## Get proc unique id
  25. proc_uid=$($GET_PROC_UID)
  26. ## Defines
  27. VERSION="1.01"
  28. LOG_FILE="/root/logs/assembly_tests/assy_tests_${proc_uid}.log"
  29. [ -d $(dirname $LOG_FILE) ] || mkdir -p $(dirname $LOG_FILE)
  30. MAGNET_DETECTED_FILE="/root/.assembly_tests_magnet_detected"
  31. QR_CODE_IMG="/root/logs/assembly_tests/qrcode.png"
  32. [ -d $(dirname $QR_CODE_IMG) ] || mkdir -p $(dirname $QR_CODE_IMG)
  33. ## Function called when SIGURS1 is caught while waiting for it
  34. function function_magnet_detected_ok {
  35. ## Kill scheduled shutdown
  36. pkill -f "powerdown schedule"
  37. ## Write magnet_detected file
  38. if $test_failed; then
  39. echo "1" > $MAGNET_DETECTED_FILE
  40. else
  41. echo "0" > $MAGNET_DETECTED_FILE
  42. fi
  43. ro
  44. ## Clean shutdown
  45. echo " Caught SIGUSR1 signal: magnet detected"
  46. echo " Rebooting now..."
  47. powerdown now
  48. exit 0
  49. }
  50. ## Function called when SIGUSR1 is caught while NOT waiting for it
  51. function function_magnet_detected_ko {
  52. echo "ERROR: Caught SIGUSR1 signal (magnet detected!)"
  53. ## Kill the funkey_prod_screen binary
  54. killall -s USR1 "${PROD_SCREEN_BIN}" > /dev/null 2>&1
  55. sync
  56. }
  57. ## Function that launches all tests before magnet
  58. function launch_tests_up_until_magnet {
  59. ## Force not to process SIGUSR1 events
  60. trap function_magnet_detected_ko SIGUSR1
  61. ## Clear graphical framebuffers
  62. termfix_all > /dev/null
  63. ## Clear all notifs
  64. notif clear
  65. ## Test if log file aleady exists
  66. if [[ -f $LOG_FILE ]]; then
  67. echo -e "\n\n ----------------------- RESTART ---------------------- \n\n"
  68. fi
  69. echo "FunKey S prod tests - v${VERSION}"
  70. echo "UID: $proc_uid"
  71. ## Set date from raspberry and test USB at the same time
  72. # Here we can launch an ssh command such as :
  73. # date -s '@$(ssh root@rapsberry date +%s)'
  74. # This allows also to test the USB connection
  75. echo "DATE: "$(date) - $(date +%s)
  76. echo "USB:"
  77. echo " ifconfig usb0:"
  78. ifconfig usb0 2>&1
  79. echo " OK"
  80. sync
  81. ## Battery tests
  82. echo "TEST BATTERY:"
  83. sync
  84. $PROD_SCREEN_BIN WAIT_BATTERY 2>&1
  85. res="$?"
  86. echo " $res"
  87. if [[ "$res" == "0" ]]; then
  88. echo " OK"
  89. else
  90. echo " FAIL"
  91. test_failed=true
  92. fi
  93. sync
  94. ## Dump power info from AXP209
  95. echo "AXP209 DUMP BATTERY:"
  96. cat /sys/class/power_supply/axp20x-battery/uevent
  97. echo "AXP209 DUMP USB:"
  98. cat /sys/class/power_supply/axp20x-usb//uevent
  99. sync
  100. ## Launch prod screen test display
  101. echo "TEST DISPLAY:"
  102. sync
  103. $PROD_SCREEN_BIN DISPLAY 2>&1
  104. res="$?"
  105. echo " $res"
  106. if [[ "$res" == "0" ]]; then
  107. echo " OK"
  108. else
  109. echo " FAILED"
  110. test_failed=true
  111. return
  112. fi
  113. sync
  114. ## Launch prod screen test buttons
  115. echo "TEST BUTTONS:"
  116. sync
  117. $PROD_SCREEN_BIN BUTTONS 2>&1
  118. res="$?"
  119. echo " $res"
  120. if [[ "$res" == "0" ]]; then
  121. echo " OK"
  122. else
  123. echo " FAILED"
  124. test_failed=true
  125. return
  126. fi
  127. sync
  128. ## Speaker test: set volume to 80%
  129. echo "TEST SPEAKER:"
  130. volume_level=90
  131. echo " Set volume to ${volume_level}%"
  132. volume_set $volume_level 2>&1
  133. ## Play 1kHz sine wave
  134. echo " Play 2kHz sine wave"
  135. notif set 0 "^^^ PLAYING SINE WAVE...^^^ ...... ^ ... ...^ .. ..^.. .^. . .^ . ..^ .. ..^ ... ...^ .......^^"
  136. speaker-test -t sine -s 1 -f 2000 >/dev/null 2>&1
  137. if [ $? -ne 0 ]; then
  138. echo " ERROR: SPEAKER SINE"
  139. test_failed=true
  140. return
  141. fi
  142. sync
  143. notif clear
  144. ## Launch prod screen test speaker
  145. $PROD_SCREEN_BIN SPEAKER 2>&1
  146. res="$?"
  147. echo " $res"
  148. if [[ "$res" == "0" ]]; then
  149. echo " OK"
  150. else
  151. echo " FAILED"
  152. test_failed=true
  153. return
  154. fi
  155. sync
  156. ## LED test: turn on LED
  157. echo "TEST LED:"
  158. echo " Turning LED on"
  159. test-led 1 2>&1
  160. if [ $? -ne 0 ]; then
  161. echo " ERROR LED I2C"
  162. test_failed=true
  163. return
  164. fi
  165. sync
  166. ## Launch prod screen test LED
  167. $PROD_SCREEN_BIN LED 2>&1
  168. res="$?"
  169. echo " $res"
  170. echo " Turning LED off"
  171. test-led 0 2>&1
  172. if [ $? -ne 0 ]; then
  173. echo " ERROR LED I2C"
  174. test_failed=true
  175. return
  176. fi
  177. if [[ "$res" == "0" ]]; then
  178. echo " OK"
  179. else
  180. echo " FAILED"
  181. test_failed=true
  182. return
  183. fi
  184. sync
  185. # Catch SIGUSR1 events
  186. #trap function_magnet_detected_ok SIGUSR1
  187. ## Launch prod screen test magnet
  188. echo "TEST MAGNET:"
  189. sync
  190. $PROD_SCREEN_BIN MAGNET 2>&1
  191. res="$?"
  192. echo " $res"
  193. ## Register ourself back as the running FunKey task for receiving USR1
  194. ## signal for shutting down
  195. pid record $$
  196. # check magnet test result
  197. if [[ "$res" == "0" ]]; then
  198. echo " OK"
  199. function_magnet_detected_ok
  200. else
  201. echo " FAILED"
  202. test_failed=true
  203. return
  204. fi
  205. sync
  206. }
  207. ## Function that launches all tests after reboot from magnet
  208. function launch_tests_after_magnet {
  209. ## Force not to process SIGUSR1 events
  210. trap function_magnet_detected_ko SIGUSR1
  211. ## Clear graphical framebuffers
  212. #termfix_all > /dev/null
  213. ## Clear all notifs
  214. #notif clear
  215. # Log from magnet file
  216. echo " Found file: " $MAGNET_DETECTED_FILE
  217. magnet_file_data=$(cat $MAGNET_DETECTED_FILE)
  218. echo " $magnet_file_data"
  219. sync
  220. # Read file and set test_failed accordingly
  221. if [[ "$magnet_file_data" == "1" ]]; then
  222. test_failed=true
  223. fi
  224. # Remove magnet detected file & Tell that magnet test was successful
  225. rm $MAGNET_DETECTED_FILE
  226. echo " OK"
  227. sync
  228. ## Print validation message
  229. if $test_failed; then
  230. echo "TESTS FINISHED BUT SOME FAILED"
  231. return
  232. else
  233. echo "ALL TESTS PASSED SUCCESSFULLY"
  234. fi
  235. sync
  236. ## Launch prod test validate screen
  237. echo "MANUAL VALIDATION SCREEN:"
  238. sync
  239. $PROD_SCREEN_BIN VALIDATE 2>&1
  240. res="$?"
  241. if [[ "$res" == "0" ]]; then
  242. echo " $res"
  243. echo " OK"
  244. else
  245. echo " $res"
  246. echo " FAIL"
  247. test_failed=true
  248. return
  249. fi
  250. sync
  251. ## Bypassing QRcode screen
  252. perform_QRcode_test=false
  253. if $perform_QRcode_test; then
  254. ## Show datamatrix
  255. test -f $QR_CODE_IMG && rm $QR_CODE_IMG
  256. echo "Writing QR code img to $QR_CODE_IMG"
  257. #echo -n $proc_uid | dmtxwrite > $QR_CODE_IMG
  258. qrencode -m 1 -o $QR_CODE_IMG "$proc_uid"
  259. echo "QRCODE STEP:"
  260. sync
  261. $PROD_SCREEN_BIN SHOW_IMAGE $QR_CODE_IMG 2>&1
  262. res="$?"
  263. if [[ "$res" == "0" ]]; then
  264. echo " $res"
  265. echo " OK"
  266. else
  267. echo " $res"
  268. echo " FAIL"
  269. test_failed=true
  270. return
  271. fi
  272. sync
  273. fi
  274. }
  275. ## Function that displays the fail screen
  276. function launch_fail_screen {
  277. ## Launch prod test fail screen
  278. echo "TEST FAILED:"
  279. $PROD_SCREEN_BIN FAIL 2>&1
  280. res="$?"
  281. if [[ "$res" == "0" ]]; then
  282. echo " $res"
  283. echo " RESTARTING"
  284. else
  285. echo " $res"
  286. echo " STOP"
  287. stop_loop=true
  288. fi
  289. }
  290. ## Main loop for tests
  291. while ! $stop_loop; do
  292. # Reset test_failed
  293. test_failed=false
  294. # Check if first start or instant action
  295. if [[ ! -f $MAGNET_DETECTED_FILE ]]; then
  296. launch_tests_up_until_magnet 2>&1 >> $LOG_FILE
  297. else
  298. launch_tests_after_magnet 2>&1 >> $LOG_FILE
  299. ## Exit loop condition
  300. if ! $test_failed; then
  301. stop_loop=true
  302. fi
  303. fi
  304. # Show fail screen if some tests failed
  305. if $test_failed; then
  306. launch_fail_screen >> $LOG_FILE
  307. fi
  308. done
  309. ## Remove lock file
  310. rm $LOCK_FILE
  311. ro
  312. ## Exit processes
  313. if ! $test_failed; then
  314. ## Remove run file => no assembly tests on next run
  315. fw_setenv assembly_tests 0
  316. sync
  317. exit 0
  318. else
  319. ## Shutdown
  320. powerdown now &
  321. exit 1
  322. fi