xref: /freebsd/tools/test/stress2/misc/pty2.sh (revision f7c32ed617858bcd22f8d1b03199099d50125721)
1#!/bin/sh
2
3#
4# Copyright (c) 2016 EMC Corp.
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26# SUCH DAMAGE.
27#
28
29# pty(4) test scenario.
30
31# "panic: make_dev_sv: bad si_name (error=17, si_name=ptyp0)" seen.
32# Fixed by r293825.
33
34# Based on test scenario by Bruce Evans.
35
36[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
37
38. ../default.cfg
39
40kldstat -v | grep -q pty || { kldload pty || exit 0; }
41
42here=`pwd`
43cd /tmp
44sed '1,/^EOF/d' < $here/$0 > pty2.c
45mycc -o pty2 -Wall -Wextra -O2 pty2.c || exit 1
46rm -f pty2.c
47
48/tmp/pty2
49
50rm -f /tmp/pty2
51exit
52EOF
53#include <sys/types.h>
54#include <sys/wait.h>
55
56#include <err.h>
57#include <errno.h>
58#include <fcntl.h>
59#include <stdio.h>
60#include <stdlib.h>
61#include <time.h>
62#include <unistd.h>
63
64#define PARALLEL 3
65#define RUNTIME 180
66
67#define IN "/dev/ptyp0"
68
69void
70test(void)
71{
72	time_t start;
73	int fd;
74
75	start = time(NULL);
76	while (time(NULL) - start < RUNTIME) {
77		if ((fd = open(IN, O_RDONLY)) == -1) {
78			if (errno != EBUSY && errno != ENXIO && errno != ENOENT)
79				err(1, "open(%s)", IN);
80		} else
81			close(fd);
82
83	}
84	_exit(0);
85}
86
87int
88main(void)
89{
90	int i;
91
92	for (i = 0; i < PARALLEL; i++)
93		if (fork() == 0)
94			test();
95
96	for (i = 0; i < PARALLEL; i++)
97		wait(NULL);
98
99	return(0);
100}
101
102