xref: /illumos-gate/usr/src/test/os-tests/tests/stress/dladm-kstat.sh (revision 1a2d662a91cee3bf82f41cd47c7ae6f3825d9db2)
1#!/bin/bash
2
3#
4# This file and its contents are supplied under the terms of the
5# Common Development and Distribution License ("CDDL"), version 1.0.
6# You may only use this file in accordance with the terms of version
7# 1.0 of the CDDL.
8#
9# A full copy of the text of the CDDL should have accompanied this
10# source.  A copy of the CDDL is also available via the Internet at
11# http://www.illumos.org/license/CDDL.
12#
13
14#
15# Copyright (c) 2016 by Delphix. All rights reserved.
16#
17
18#
19# This test attempts to stress the interaction between threads adding
20# and deleting datalinks, and those reading kstats associated with
21# those datalinks.
22#
23
24RUNFILE=$(mktemp)
25linkname1=laverne0
26linkname2=shirley0
27duration=20 # seconds
28
29#
30# Delete any potential datalinks left behind by the etherstub function.
31#
32function cleanup
33{
34	rm -f $RUNFILE
35}
36
37function etherstub
38{
39	while [[ -e $RUNFILE ]]; do
40		dladm create-etherstub -t $linkname1
41		dladm rename-link $linkname1 $linkname2
42		dladm delete-etherstub -t $linkname2
43	done
44}
45
46function readkstat
47{
48	local linkname=$1
49	while [[ -e $RUNFILE ]]; do
50		kstat link:0:$linkname &>/dev/null
51	done
52}
53
54trap "cleanup; exit" SIGHUP SIGINT SIGTERM
55
56etherstub &
57readkstat $linkname1 &
58readkstat $linkname1 &
59readkstat $linkname2 &
60readkstat $linkname2 &
61
62sleep $duration
63cleanup
64
65wait
66
67exit 0
68