11.2Smartin# $NetBSD: t_envstat.sh,v 1.2 2023/03/23 11:32:49 martin Exp $
21.1Sjruoho#
31.1Sjruoho# Copyright (c) 2020 The NetBSD Foundation, Inc.
41.1Sjruoho# All rights reserved.
51.1Sjruoho#
61.1Sjruoho# This code is derived from software contributed to The NetBSD Foundation
71.1Sjruoho# by Jukka Ruohonen.
81.1Sjruoho#
91.1Sjruoho# Redistribution and use in source and binary forms, with or without
101.1Sjruoho# modification, are permitted provided that the following conditions
111.1Sjruoho# are met:
121.1Sjruoho# 1. Redistributions of source code must retain the above copyright
131.1Sjruoho#    notice, this list of conditions and the following disclaimer.
141.1Sjruoho# 2. Redistributions in binary form must reproduce the above copyright
151.1Sjruoho#    notice, this list of conditions and the following disclaimer in the
161.1Sjruoho#    documentation and/or other materials provided with the distribution.
171.1Sjruoho#
181.1Sjruoho# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
191.1Sjruoho# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
201.1Sjruoho# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
211.1Sjruoho# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
221.1Sjruoho# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
231.1Sjruoho# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
241.1Sjruoho# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
251.1Sjruoho# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
261.1Sjruoho# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
271.1Sjruoho# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
281.1Sjruoho# POSSIBILITY OF SUCH DAMAGE.
291.1Sjruoho#
301.1Sjruoho
311.1Sjruohoatf_test_case zerotemp
321.1Sjruohozerotemp_head() {
331.1Sjruoho	atf_set "descr" "Check with envstat(8) that CPU sensors " \
341.1Sjruoho		"do not show zero temperatures (PR kern/53410)"
351.1Sjruoho}
361.1Sjruoho
371.1Sjruohozerotemp_body() {
381.1Sjruoho
391.2Smartin	for dev in $( envstat -D | awk '{print $1}' )
401.2Smartin	do
411.1Sjruoho
421.1Sjruoho		envstat -d $dev >/dev/null 2>&1
431.1Sjruoho
441.1Sjruoho		if [ ! $? -eq 0 ]; then
451.1Sjruoho			echo "Skipping non-existent $dev"
461.1Sjruoho			continue
471.1Sjruoho		fi
481.1Sjruoho
491.2Smartin		# extract all temperatures from $dev
501.2Smartin		for tempf in $(envstat -d $dev | \
511.2Smartin			awk -F: '/degC$/{print $2}' | \
521.2Smartin			awk '{print $1}' )
531.2Smartin		do
541.2Smartin			tempi=$(printf "%.0f" $tempf)
551.2Smartin
561.2Smartin			echo "$dev = $tempf =~ $tempi"
571.2Smartin
581.2Smartin			if [ $tempi -eq 0 ]; then
591.2Smartin
601.2Smartin				if [ $dev = "amdtemp0" ]; then
611.2Smartin					atf_expect_fail "PR kern/53410"
621.2Smartin				fi
631.2Smartin				atf_fail "Zero-temperature from $dev"
641.2Smartin			fi
651.2Smartin		done
661.1Sjruoho	done
671.1Sjruoho}
681.1Sjruoho
691.1Sjruohoatf_init_test_cases() {
701.1Sjruoho	atf_add_test_case zerotemp
711.1Sjruoho}
72