xref: /netbsd-src/tests/sbin/envstat/t_envstat.sh (revision 9da6df7d4c8e43c985083a8908fa7cc17bf98b44)
1*9da6df7dSmartin# $NetBSD: t_envstat.sh,v 1.2 2023/03/23 11:32:49 martin Exp $
277e941ddSjruoho#
377e941ddSjruoho# Copyright (c) 2020 The NetBSD Foundation, Inc.
477e941ddSjruoho# All rights reserved.
577e941ddSjruoho#
677e941ddSjruoho# This code is derived from software contributed to The NetBSD Foundation
777e941ddSjruoho# by Jukka Ruohonen.
877e941ddSjruoho#
977e941ddSjruoho# Redistribution and use in source and binary forms, with or without
1077e941ddSjruoho# modification, are permitted provided that the following conditions
1177e941ddSjruoho# are met:
1277e941ddSjruoho# 1. Redistributions of source code must retain the above copyright
1377e941ddSjruoho#    notice, this list of conditions and the following disclaimer.
1477e941ddSjruoho# 2. Redistributions in binary form must reproduce the above copyright
1577e941ddSjruoho#    notice, this list of conditions and the following disclaimer in the
1677e941ddSjruoho#    documentation and/or other materials provided with the distribution.
1777e941ddSjruoho#
1877e941ddSjruoho# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1977e941ddSjruoho# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2077e941ddSjruoho# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2177e941ddSjruoho# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2277e941ddSjruoho# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2377e941ddSjruoho# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2477e941ddSjruoho# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2577e941ddSjruoho# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2677e941ddSjruoho# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2777e941ddSjruoho# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2877e941ddSjruoho# POSSIBILITY OF SUCH DAMAGE.
2977e941ddSjruoho#
3077e941ddSjruoho
3177e941ddSjruohoatf_test_case zerotemp
3277e941ddSjruohozerotemp_head() {
3377e941ddSjruoho	atf_set "descr" "Check with envstat(8) that CPU sensors " \
3477e941ddSjruoho		"do not show zero temperatures (PR kern/53410)"
3577e941ddSjruoho}
3677e941ddSjruoho
3777e941ddSjruohozerotemp_body() {
3877e941ddSjruoho
39*9da6df7dSmartin	for dev in $( envstat -D | awk '{print $1}' )
40*9da6df7dSmartin	do
4177e941ddSjruoho
4277e941ddSjruoho		envstat -d $dev >/dev/null 2>&1
4377e941ddSjruoho
4477e941ddSjruoho		if [ ! $? -eq 0 ]; then
4577e941ddSjruoho			echo "Skipping non-existent $dev"
4677e941ddSjruoho			continue
4777e941ddSjruoho		fi
4877e941ddSjruoho
49*9da6df7dSmartin		# extract all temperatures from $dev
50*9da6df7dSmartin		for tempf in $(envstat -d $dev | \
51*9da6df7dSmartin			awk -F: '/degC$/{print $2}' | \
52*9da6df7dSmartin			awk '{print $1}' )
53*9da6df7dSmartin		do
5477e941ddSjruoho			tempi=$(printf "%.0f" $tempf)
5577e941ddSjruoho
5677e941ddSjruoho			echo "$dev = $tempf =~ $tempi"
5777e941ddSjruoho
5877e941ddSjruoho			if [ $tempi -eq 0 ]; then
59*9da6df7dSmartin
60*9da6df7dSmartin				if [ $dev = "amdtemp0" ]; then
61*9da6df7dSmartin					atf_expect_fail "PR kern/53410"
62*9da6df7dSmartin				fi
6377e941ddSjruoho				atf_fail "Zero-temperature from $dev"
6477e941ddSjruoho			fi
6577e941ddSjruoho		done
66*9da6df7dSmartin	done
6777e941ddSjruoho}
6877e941ddSjruoho
6977e941ddSjruohoatf_init_test_cases() {
7077e941ddSjruoho	atf_add_test_case zerotemp
7177e941ddSjruoho}
72