xref: /freebsd/sys/contrib/openzfs/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.memory_limit.ksh (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1#!/bin/ksh -p
2# SPDX-License-Identifier: CDDL-1.0
3#
4# This file and its contents are supplied under the terms of the
5# Common Development and Distribution License ("CDDL"), version 1.0.
6# You may only use this file in accordance with the terms of version
7# 1.0 of the CDDL.
8#
9# A full copy of the text of the CDDL should have accompanied this
10# source.  A copy of the CDDL is also available via the Internet at
11# http://www.illumos.org/license/CDDL.
12#
13
14#
15# Copyright (c) 2016 by Delphix. All rights reserved.
16#
17
18. $STF_SUITE/tests/functional/channel_program/channel_common.kshlib
19
20
21#
22# DESCRIPTION:
23#       Passing memory limit options to channel programs should work correctly.
24#       Programs that exceed these limits should fail gracefully.
25
26
27verify_runnable "global"
28
29log_mustnot_checkerror_program "Memory limit exhausted" \
30    -t 100000000 $TESTPOOL - <<-EOF
31	a = {};
32	i = 0;
33	while true do
34		i = i + 1
35		a[i] = "Here is the " .. i .. "th entry of a"
36	end;
37	return a
38EOF
39
40log_assert "memory limit options work"
41log_mustnot_checkerror_program "Memory limit exhausted" \
42    -m 100000 -t 100000000 $TESTPOOL - <<-EOF
43	a = {};
44	i = 0;
45	while true do
46	  i = i + 1
47	  a[i] = "Here is the " .. i .. "th entry of a"
48	end;
49	return a
50EOF
51
52log_must_program -m 100000 $TESTPOOL - <<-EOF
53	s = "teststring"
54	s = s .. s .. s .. s
55	return s
56EOF
57
58log_assert "very small memory limits fail correctly"
59log_mustnot_checkerror_program "Memory limit exhausted" -m 1 $TESTPOOL - <<-EOF
60	s = "teststring"
61	s = s .. s .. s .. s
62	return s
63EOF
64
65# Set the memlimit, in case it is a non-default value
66log_must set_tunable32 LUA_MAX_MEMLIMIT 100000000
67
68log_mustnot_checkerror_program "Invalid instruction or memory limit" \
69    -m 200000000 $TESTPOOL - <<-EOF
70	return 1;
71EOF
72
73log_mustnot_checkerror_program "Return value too large" \
74    -m 9223372036854775808 $TESTPOOL - <<-EOF
75	return 1;
76EOF
77
78log_pass "Memory limits work correctly."
79