blob: ab1d5e0ba706142d9db21cb453ea16219b4ff930 [file] [log] [blame] [edit]
#!/bin/sh
# Copyright 2017 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
. /usr/share/misc/shflags
DEFINE_boolean 'test' "${FLAGS_FALSE}" "For unit testing."
# Parse command line.
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
set -e
if [ "${FLAGS_test}" -eq "${FLAGS_FALSE}" ]; then
. /usr/share/cros/disk_utils.sh
else
. ./disk_utils.sh
fi
dmesg_matches() {
if dmesg | grep -q "$1"; then
echo 1
else
echo 0
fi
}
gather_battery_errors() {
# The metrics library requires a max value of 2 rather than 1
# (http://crbug.com/338015).
metrics_client -e Platform.BatteryAbsent "$(
dmesg_matches "ACPI: Battery Slot.*absent")" 2
}
gather_wifi_error() {
local count
count=$(grep -l "^DEVTYPE=wlan" /sys/class/net/*/uevent | wc -l)
if [ "${count}" -gt 9 ]; then
count=9
fi
metrics_client -e Platform.WiFiDeviceCount "${count}" 10
}
gather_errors() {
gather_battery_errors
# The wifi devices may take some time to appear.
sleep 10
gather_wifi_error
}
main() {
if [ "${FLAGS_test}" -eq "${FLAGS_TRUE}" ]; then
return
fi
if [ $# -ne 0 ]; then
flags_help
exit 1
fi
gather_errors
}
main "$@"