t_repeated_scan.sh revision 1.6
11.6Smrg# $NetBSD: t_repeated_scan.sh,v 1.6 2020/12/10 08:16:59 mrg 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.1Sjruohoatf_test_case repeated_scan
311.1Sjruohorepeated_scan_head() {
321.3Sjruoho	atf_set "require.user" "root"
331.1Sjruoho	atf_set "descr" "Test with ifconfig(8) that repeated 802.11 " \
341.4Sjruoho		"scanning does not panic (PR kern/53860; PR kern/55389)"
351.1Sjruoho}
361.1Sjruoho
371.1Sjruohorepeated_scan_body() {
381.1Sjruoho
391.6Smrg	if ! [ $(atf_config_get "run_unsafe" "no") = "yes" ]
401.6Smrg	then
411.6Smrg		atf_skip "can disrupt networking; also PR port-evbarm/55521"
421.6Smrg	fi
431.6Smrg
441.1Sjruoho	# Even though this should amount to a "few minutes",
451.1Sjruoho	# try to still avoid stalling any automated test runs.
461.1Sjruoho	#
471.1Sjruoho	n=15
481.1Sjruoho
491.1Sjruoho	pkill -9 hostapd
501.1Sjruoho	pkill -9 wpa_supplicant
511.1Sjruoho
521.1Sjruoho	for i in $(ifconfig -l); do
531.1Sjruoho
541.1Sjruoho		state="up"
551.1Sjruoho		ifconfig -s $i
561.1Sjruoho
571.1Sjruoho		if [ $? -eq 1 ]; then
581.1Sjruoho
591.1Sjruoho			state="down"
601.1Sjruoho			ifconfig $i up
611.1Sjruoho
621.1Sjruoho			if [ ! $? -eq 0 ]; then
631.1Sjruoho				echo "Failed to set $i up"
641.1Sjruoho				continue
651.1Sjruoho			fi
661.1Sjruoho		fi
671.1Sjruoho
681.1Sjruoho		sleep 1
691.1Sjruoho		ifconfig $i list scan >/dev/null 2>&1
701.1Sjruoho
711.1Sjruoho		if [ ! $? -eq 0 ]; then
721.1Sjruoho			echo "Skipping $i; scan not supported"
731.1Sjruoho			continue
741.1Sjruoho		fi
751.1Sjruoho
761.1Sjruoho		while [ $n -gt 0 ]; do
771.1Sjruoho			echo "Test $n for $i"
781.1Sjruoho			ifconfig $i list scan >/dev/null 2>&1
791.1Sjruoho			n=$(expr $n - 1)
801.1Sjruoho		done
811.1Sjruoho
821.1Sjruoho		ifconfig $i $state
831.1Sjruoho		echo "Restored state of $i to $state"
841.1Sjruoho		sleep 1
851.1Sjruoho	done
861.1Sjruoho
871.1Sjruoho	/bin/sh /etc/rc.d/hostapd restart >/dev/null 2>&1
881.1Sjruoho	/bin/sh /etc/rc.d/wpa_supplicant restart >/dev/null 2>&1
891.5Sjruoho
901.5Sjruoho	atf_pass
911.1Sjruoho}
921.1Sjruoho
931.1Sjruohoatf_init_test_cases() {
941.1Sjruoho	atf_add_test_case repeated_scan
951.1Sjruoho}
96