xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/channel_program/lua_core/tst.return_nvlist_neg.ksh (revision b7daf79982d77b491ef9662483cd4549e0e5da9a)
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#	Try returning various values that lua allows you to construct,
24#       but that cannot be represented as nvlists and therefore should
25#       cause the script to fail (but not panic). Try sending the values
26#       back to userland from both "return" and "error()".
27#
28
29verify_runnable "both"
30
31set -A args 'function() return 1 end' \
32	'{[{}]=true}' \
33	'{[function() return 1 end]=0}' \
34	'assert' \
35	'0, assert' \
36	'true, {[{}]=0}' \
37	'{val=true}, {val=false}' \
38	'{1, 2, 3}, {[4]=5}' \
39	'nil, true, 1, "test", {}, {val=true}' \
40	'{[false]=true, ["false"]=false}' \
41	'{[true]=false, ["true"]=true}' \
42	'{[0]=true, ["0"]=false}' \
43	'{0,0,0,["1"]=0}' \
44	'{0,0,0,["2"]=0}' \
45	'{0,0,0,["3"]=0}'
46
47typeset -i last_index=$((${#args[*]} - 1))
48for i in $(seq 0 $last_index); do
49	log_note "running program: ${args[i]}"
50	log_mustnot_checkerror_program "execution failed" $TESTPOOL - <<-EOF
51		return ${args[i]}
52	EOF
53	((i = i + 1))
54done
55
56for i in $(seq 0 $last_index); do
57	log_note "running program: ${args[i]}"
58	log_mustnot_checkerror_program "execution failed" $TESTPOOL - <<-EOF
59		error(${args[i]})
60	EOF
61	((i = i + 1))
62done
63
64log_pass "Returning lua constructs that cannot be converted to " \
65    "nvlists fails as expected."
66