xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/channel_program/lua_core/tst.timeout.ksh (revision bf5d9f18edeb77c14df996d367853599bdd43fd1)
1#!/bin/ksh -p
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 (c) 2016 by Delphix. All rights reserved.
15#
16
17verify_runnable "global"
18
19. $STF_SUITE/tests/functional/channel_program/channel_common.kshlib
20
21#
22# DESCRIPTION:
23#       Passing the instruction limit option to channel programs should work
24#       correctly. Programs that exceed these instruction limits should fail
25#       gracefully.
26#
27
28verify_runnable "both"
29
30log_assert "Timeouts work correctly."
31
32log_mustnot_checkerror_program "Channel program timed out" \
33    $TESTPOOL $ZCP_ROOT/lua_core/tst.timeout.zcp
34
35function test_instr_limit
36{
37	typeset lim=$1
38	instrs_run=$(dtrace -q \
39	    -n 'zfs_ioc_channel_program:entry{x=0}' \
40	    -n 'zfs_ioc_channel_program:return{printf("%d", x)}' \
41	    -n 'zcp_lua_counthook:entry{x+=100}' \
42	    -c "zfs program -t $lim $TESTPOOL $ZCP_ROOT/lua_core/tst.timeout.zcp")
43	if [[ $instrs_run -lt $(( $lim - 100 )) ]]; then
44		log_fail "Runtime (${instrs_run} instr) < limit (${lim} - 100 instr)"
45	elif [[ $instrs_run -gt $(( $lim + 100 )) ]]; then
46		log_fail "Runtime (${instrs_run} instr) > limit (${lim} + 100 instr)"
47	fi
48}
49
50test_instr_limit 1000
51test_instr_limit 10000
52test_instr_limit 100000
53test_instr_limit 1000000
54test_instr_limit 2000000
55
56log_pass "Timeouts work correctly."
57