1*8a272653SPeter Holm#!/bin/sh 2*8a272653SPeter Holm 3*8a272653SPeter Holm# 4*8a272653SPeter Holm# Copyright (c) 2012 Peter Holm <pho@FreeBSD.org> 5*8a272653SPeter Holm# All rights reserved. 6*8a272653SPeter Holm# 7*8a272653SPeter Holm# Redistribution and use in source and binary forms, with or without 8*8a272653SPeter Holm# modification, are permitted provided that the following conditions 9*8a272653SPeter Holm# are met: 10*8a272653SPeter Holm# 1. Redistributions of source code must retain the above copyright 11*8a272653SPeter Holm# notice, this list of conditions and the following disclaimer. 12*8a272653SPeter Holm# 2. Redistributions in binary form must reproduce the above copyright 13*8a272653SPeter Holm# notice, this list of conditions and the following disclaimer in the 14*8a272653SPeter Holm# documentation and/or other materials provided with the distribution. 15*8a272653SPeter Holm# 16*8a272653SPeter Holm# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17*8a272653SPeter Holm# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*8a272653SPeter Holm# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*8a272653SPeter Holm# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20*8a272653SPeter Holm# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21*8a272653SPeter Holm# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22*8a272653SPeter Holm# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23*8a272653SPeter Holm# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24*8a272653SPeter Holm# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25*8a272653SPeter Holm# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*8a272653SPeter Holm# SUCH DAMAGE. 27*8a272653SPeter Holm# 28*8a272653SPeter Holm 29*8a272653SPeter Holm# Test of access to /dev/sndstat 30*8a272653SPeter Holm 31*8a272653SPeter Holm# Permanent "/dev/sndstat: Device busy" seen. 32*8a272653SPeter Holm# "panic: sbuf_put_byte called with finished or corrupt sbuf" seen. 33*8a272653SPeter Holm# Fixed in r234932 34*8a272653SPeter Holm 35*8a272653SPeter Holm. ../default.cfg 36*8a272653SPeter Holm 37*8a272653SPeter Holm[ -r /dev/sndstat ] || exit 0 38*8a272653SPeter Holm 39*8a272653SPeter Holmhere=`pwd` 40*8a272653SPeter Holmcd /tmp 41*8a272653SPeter Holmsed '1,/^EOF/d' < $here/$0 > sndstat.c 42*8a272653SPeter Holmmycc -o sndstat -Wall -Wextra sndstat.c -lpthread 43*8a272653SPeter Holmrm -f sndstat.c 44*8a272653SPeter Holm 45*8a272653SPeter Holm/tmp/sndstat > /dev/null 46*8a272653SPeter Holm 47*8a272653SPeter Holmrm -f /tmp/sndstat 48*8a272653SPeter Holmexit 0 49*8a272653SPeter HolmEOF 50*8a272653SPeter Holm#include <sys/types.h> 51*8a272653SPeter Holm#include <sys/syscall.h> 52*8a272653SPeter Holm#include <sys/uio.h> 53*8a272653SPeter Holm#include <dirent.h> 54*8a272653SPeter Holm#include <err.h> 55*8a272653SPeter Holm#include <fcntl.h> 56*8a272653SPeter Holm#include <pthread.h> 57*8a272653SPeter Holm#include <stdio.h> 58*8a272653SPeter Holm#include <stdlib.h> 59*8a272653SPeter Holm#include <strings.h> 60*8a272653SPeter Holm#include <sys/wait.h> 61*8a272653SPeter Holm#include <unistd.h> 62*8a272653SPeter Holm 63*8a272653SPeter Holmint fd; 64*8a272653SPeter Holmchar path[] = "/dev/sndstat"; 65*8a272653SPeter Holm 66*8a272653SPeter Holmvoid * 67*8a272653SPeter Holmtest1(void *arg __unused) 68*8a272653SPeter Holm{ 69*8a272653SPeter Holm 70*8a272653SPeter Holm int sfd, i, n; 71*8a272653SPeter Holm char buf[512]; 72*8a272653SPeter Holm 73*8a272653SPeter Holm n = 0; 74*8a272653SPeter Holm for (i = 0; i < 5; i++) { 75*8a272653SPeter Holm if ((sfd = open(path, O_RDONLY)) == -1) 76*8a272653SPeter Holm continue; 77*8a272653SPeter Holm 78*8a272653SPeter Holm read(sfd, buf, sizeof(buf)); 79*8a272653SPeter Holm fprintf(stdout, "%s\n", buf); 80*8a272653SPeter Holm 81*8a272653SPeter Holm n++; 82*8a272653SPeter Holm close(sfd); 83*8a272653SPeter Holm } 84*8a272653SPeter Holm if (n == 0) { 85*8a272653SPeter Holm if ((sfd = open(path, O_RDONLY)) == -1) 86*8a272653SPeter Holm warn("FAIL open(%s)", path); 87*8a272653SPeter Holm if (sfd > 0) 88*8a272653SPeter Holm close(sfd); 89*8a272653SPeter Holm } 90*8a272653SPeter Holm 91*8a272653SPeter Holm return (0); 92*8a272653SPeter Holm} 93*8a272653SPeter Holm 94*8a272653SPeter Holmvoid * 95*8a272653SPeter Holmtest2(void *arg __unused) 96*8a272653SPeter Holm{ 97*8a272653SPeter Holm char buf[512]; 98*8a272653SPeter Holm 99*8a272653SPeter Holm bzero(buf, sizeof(buf)); 100*8a272653SPeter Holm if (read(fd, buf, sizeof(buf)) != -1) 101*8a272653SPeter Holm fprintf(stdout, "%s\n", buf); 102*8a272653SPeter Holm else 103*8a272653SPeter Holm warn("read()"); 104*8a272653SPeter Holm 105*8a272653SPeter Holm return (0); 106*8a272653SPeter Holm} 107*8a272653SPeter Holm 108*8a272653SPeter Holmint 109*8a272653SPeter Holmmain(void) 110*8a272653SPeter Holm{ 111*8a272653SPeter Holm pthread_t rp[10]; 112*8a272653SPeter Holm int e, i, j; 113*8a272653SPeter Holm 114*8a272653SPeter Holm /* Parallel open test */ 115*8a272653SPeter Holm for (i = 0; i < 10; i++) { 116*8a272653SPeter Holm if ((e = pthread_create(&rp[i], NULL, test1, NULL)) != 0) 117*8a272653SPeter Holm errc(1, e, "pthread_create"); 118*8a272653SPeter Holm } 119*8a272653SPeter Holm for (i = 0; i < 10; i++) 120*8a272653SPeter Holm pthread_join(rp[i], NULL); 121*8a272653SPeter Holm 122*8a272653SPeter Holm /* Parallel read test */ 123*8a272653SPeter Holm for (i = 0; i < 10; i++) { 124*8a272653SPeter Holm if ((fd = open(path, O_RDONLY)) == -1) { 125*8a272653SPeter Holm warn("open()"); 126*8a272653SPeter Holm continue; 127*8a272653SPeter Holm } 128*8a272653SPeter Holm for (j = 0; j < 4; j++) 129*8a272653SPeter Holm if ((e = pthread_create(&rp[j], NULL, test2, NULL)) != 0) 130*8a272653SPeter Holm errc(1, e, "pthread_create"); 131*8a272653SPeter Holm for (j = 0; j < 4; j++) 132*8a272653SPeter Holm pthread_join(rp[j], NULL); 133*8a272653SPeter Holm 134*8a272653SPeter Holm close(fd); 135*8a272653SPeter Holm } 136*8a272653SPeter Holm 137*8a272653SPeter Holm return (0); 138*8a272653SPeter Holm} 139