xref: /freebsd/tools/test/stress2/misc/poll.sh (revision e0c4386e)
1#!/bin/sh
2
3# A pipe_poll() regression test.
4# Python test scenario by Alexander Motin <mav@FreeBSD.org>
5# https://reviews.freebsd.org/D21333
6
7# Hang seen:
8# $ procstat -k 19529
9#   PID    TID COMM        KSTACK
10# 19529 101381 python3.7 - ... _sleep kqueue_kevent kern_kevent_fp kern_kevent kern_kevent_generic sys_kevent amd64_syscall fast_syscall_common
11# 19529 101630 python3.7 - ... _sleep pipe_read dofileread kern_readv sys_read amd64_syscall fast_syscall_common
12# 19529 101631 python3.7 - ... _sleep umtxq_sleep do_sem2_wait __umtx_op_sem2_wait amd64_syscall fast_syscall_common
13# $
14
15# Fixed by r351348
16
17[ -z "`type python3 2>/dev/null`" ] && exit 0
18cat > /tmp/poll.py <<EOF
19#!/usr/local/bin/python3
20
21import concurrent.futures
22import asyncio
23
24procpool = concurrent.futures.ProcessPoolExecutor(
25    max_workers=1,
26)
27
28def x():
29    return ['x'] * 10241
30
31async def say():
32    for i in range(100000):
33        await asyncio.get_event_loop().run_in_executor(procpool, x)
34        print(i)
35
36loop = asyncio.get_event_loop()
37loop.run_until_complete(say())
38loop.close()
39EOF
40chmod +x /tmp/poll.py
41
42log=/tmp/poll.log
43start=`date +%s`
44cpuset -l 0 /tmp/poll.py > $log &
45pid=$!
46sleep 60
47s1=`wc -l < $log`
48sleep 60
49s2=`wc -l < $log`
50while pgrep -qf poll.py; do pkill -f poll.py; done
51wait $pid
52[ $s2 -gt $s1 ] && s=0 || s=1
53
54rm -f /tmp/poll.py $log
55exit $s
56
57dtrace -wn '*::pipe_poll:entry {@rw[execname,probefunc] = count(); }'
58