xref: /freebsd/tools/test/stress2/misc/chain.sh (revision 2008043f386721d58158e37e0d7e50df8095942d)
1#!/bin/sh
2
3#
4# SPDX-License-Identifier: BSD-2-Clause
5#
6# Copyright (c) 2021 Peter Jeremy <peterj@FreeBSD.org>
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27# SUCH DAMAGE.
28#
29# Unkillable process in "vm map (user)" seen.
30# https://people.freebsd.org/~pho/stress/log/kostik1070.txt
31# Fixed by: r327468
32
33# OOM killing: https://people.freebsd.org/~pho/stress/log/chain.txt
34
35if [ ! -f /usr/local/include/libmill.h -o \
36    ! -x /usr/local/lib/libmill.so ]; then
37	echo "ports/devel/libmill needed."
38	exit 0
39fi
40
41. ../default.cfg
42
43cat > /tmp/chain.c <<EOF
44#include <stdio.h>
45#include <stdlib.h>
46#include <libmill.h>
47
48coroutine void f(chan left, chan right) {
49    chs(left, int, 1 + chr(right, int));
50}
51
52int
53main(int argc __unused, char **argv)
54{
55	int i, n = argv[1] ? atoi(argv[1]) : 10000;
56	chan leftmost = chmake(int, 0);
57	chan left = NULL;
58	chan right = leftmost;
59
60	alarm(600);
61	for (i = 0; i < n; i++) {
62		left = right;
63		right = chmake(int, 0);
64		go(f(left, right));
65	}
66	chs(right, int, 0);
67	i = chr(leftmost, int);
68	printf("result = %d\n", i);
69	return(0);
70}
71EOF
72
73mycc -o /tmp/chain -I /usr/local/include -L /usr/local/lib -Wall -Wextra \
74	 -O2 -g /tmp/chain.c -lmill || exit 1
75limits -c 0 /tmp/chain 1000000
76rm -f /tmp/chain /tmp/chain.c
77exit 0
78