1#! /usr/bin/ksh 2# 3# This file and its contents are supplied under the terms of the 4# Common Development and Distribution License ("CDDL"), version 1.0. 5# You may only use this file in accordance with the terms of version 6# 1.0 of the CDDL. 7# 8# A full copy of the text of the CDDL should have accompanied this 9# source. A copy of the CDDL is also available via the Internet at 10# http://www.illumos.org/license/CDDL. 11# 12 13# 14# Copyright 2012, Richard Lowe. 15# 16 17TESTDIR=$(dirname $0) 18 19fail() { 20 print -u2 "ERROR: $@" 21 exit 1 22} 23 24FIFODIR=/tmp/saveargs-test.$$ 25 26mkdir ${FIFODIR} || fail "couldn't create temp directory ${TMPDIR}" 27 28cleanup() { 29 [[ -n $pid ]] && kill $pid >/dev/null 2>&1 30 cd / 31 rm -fr ${FIFODIR} || fail "couldn't remote temp directory ${FIFODIR}" 32} 33 34trap cleanup EXIT 35 36ret=0 37pid= 38 39# Run the program and compare its stack (via pstack(1)) to what we expect. We 40# use a FIFO as a simple condition variable to indicate that the program is 41# ready to have its stack examined. 42function tester { 43 prog=${1} 44 pattern=${2} 45 46 mkfifo ${FIFODIR}/${prog} 47 48 ${TESTDIR}/$prog >> /tmp/saveargs-test.$$/${prog} & 49 pid=$! 50 51 head -n 1 ${FIFODIR}/${prog} > /dev/null 2>&1 52 53 if (/usr/bin/pstack $pid | /usr/bin/grep -q "${pattern}"); then 54 echo "pass: ${prog}" 55 else 56 echo "FAIL: ${prog}" 57 ret=1 58 fi 59 kill $pid 60} 61 62tester align "test (1, 2, 3, 4, 5)" 63tester basic "test (1, 2, 3, 4)" 64tester big-struct-ret "test (1, 2, 3, 4)" 65tester big-struct-ret-and-spill "test (1, 2, 3, 4, 5, 6, 7, 8)" 66tester small-struct-ret "test (1, 2, 3, 4)" 67tester small-struct-ret-and-spill "test (1, 2, 3, 4, 5, 6, 7, 8)" 68tester stack-spill "test (1, 2, 3, 4, 5, 6, 7, 8)" 69 70exit $ret 71