Home | History | Annotate | Download | only in utils
      1 #!/bin/sh
      2 
      3 # Copyright 2017 The Chromium OS Authors. All rights reserved.
      4 # Use of this source code is governed by a BSD-style license that can be
      5 # found in the LICENSE file.
      6 
      7 # This script probes the readiness of the DUTs and chameleon boards in
      8 # the wifi-cells in the test lab.
      9 
     10 BT_HOSTS="chromeos15-row1-rack4-host1
     11           chromeos15-row1-rack4-host2
     12           chromeos15-row1-rack4-host3
     13           chromeos15-row1-rack5-host1
     14           chromeos15-row1-rack5-host2
     15           chromeos15-row1-rack5-host3
     16           chromeos15-row1-rack5-host4"
     17 
     18 SSH_OPTIONS="-q -i ~/.ssh/.test_rsa \
     19              -o UserKnownHostsFile=/dev/null \
     20              -o StrictHostKeyChecking=no"
     21 
     22 PROBE_RESULT_DIR="/tmp/bt_probe_result"
     23 
     24 SEP_LINE="------------------------------------------------------------------"
     25 
     26 
     27 function disp_result {
     28   test "$1" -eq "0" && echo ok || echo "-"
     29 }
     30 
     31 function probe_dut {
     32   dut="$1.cros"
     33 
     34   # ping test
     35   ping -q -w 10 -c1 "${dut}" > /dev/null 2>&1
     36   ping_result="$(disp_result $?)"
     37 
     38   # Check board
     39   board=$(ssh ${SSH_OPTIONS} root@"$dut" cat /etc/lsb-release | \
     40           awk -F'=' '/CHROMEOS_RELEASE_BUILDER_PATH/ {print $2}')
     41 
     42   # Print the result
     43   printf "$1            %5s  %s\n" "${ping_result}" "${board}" \
     44     > "${PROBE_RESULT_DIR}/${dut}"
     45 }
     46 
     47 function probe_chameleon {
     48   RN42_MODULE="/usr/lib/python2.7/site-packages/chameleond-0.0.2-py2.7.egg/chameleond/utils/bluetooth_rn42.py"
     49 
     50   chameleon="$1-chameleon.cros"
     51 
     52   # ping test
     53   ping -q -w 10 -c1 "${chameleon}" > /dev/null 2>&1
     54   ping_result="$(disp_result $?)"
     55 
     56   # .usb_host_mode label test
     57   ssh $SSH_OPTIONS root@"$chameleon" "test -f /etc/default/.usb_host_mode"
     58   label_result="$(disp_result $?)"
     59 
     60   # Check if chameleond is running.
     61   test $(ssh ${SSH_OPTIONS} root@"$chameleon" \
     62          ps | awk '$5~"run_chameleond"' | wc -l) -gt "0"
     63   chameleond_result="$(disp_result $?)"
     64 
     65   # RN42 self-test status
     66   ssh ${SSH_OPTIONS} root@"$chameleon" \
     67       "python ${RN42_MODULE} > /dev/null 2>&1"
     68       # "find / -name *bluetooth_rn42.py | xargs python > /dev/null 2>&1"
     69   RN42_result="$(disp_result $?)"
     70 
     71   # TODO: add self test for bluefruit too.
     72 
     73   # Print the result
     74   printf "$1-chameleon  %5s %6s %10s %4s\n" "${ping_result}" \
     75       "${label_result}" "${chameleond_result}" "${RN42_result}" \
     76     > "${PROBE_RESULT_DIR}/${chameleon}"
     77 }
     78 
     79 function probe_duts {
     80   # Fork parallel processes to probe the DUTs.
     81   for host in $BT_HOSTS; do
     82     probe_dut $host &
     83     dut_pids="${dut_pids} $!"
     84   done
     85 }
     86 
     87 function probe_chameleons {
     88   # Fork parallel processes to probe the chameleon boards.
     89   for host in $BT_HOSTS; do
     90     probe_chameleon $host &
     91     chameleon_pids="${chameleon_pids} $!"
     92   done
     93 }
     94 
     95 function create_ping_result_dir {
     96   dut_pids=""
     97   chameleon_pids=""
     98 
     99   mkdir -p "${PROBE_RESULT_DIR}"
    100   rm -fr "${PROBE_RESULT_DIR}"/*
    101 }
    102 
    103 function print_dut_status {
    104   echo
    105   echo "Dut                                    ping                  board"
    106   echo "${SEP_LINE}"
    107 
    108   # Wait for all probing children processes to terminate.
    109   for pid in ${dut_pids}; do
    110     wait ${pid}
    111   done
    112 
    113   # Sort and print the results.
    114   cat "${PROBE_RESULT_DIR}"/*-host?.cros | sort
    115   echo; echo
    116 }
    117 
    118 function print_chameleon_status {
    119   echo "Chameleon                              ping  label chameleond rn42"
    120   echo "${SEP_LINE}"
    121 
    122   # Wait for all probing children processes to terminate.
    123   for pid in ${chameleon_pids}; do
    124     wait ${pid}
    125   done
    126 
    127   # Sort and print the results.
    128   cat "${PROBE_RESULT_DIR}"/*-chameleon.cros | sort
    129   echo; echo
    130 }
    131 
    132 create_ping_result_dir
    133 probe_duts
    134 probe_chameleons
    135 print_dut_status
    136 print_chameleon_status
    137