3 # Copyright (C) 2018-2020 Red Hat Inc.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # * Neither the name of Red Hat nor the names of its contributors may be
17 # used to endorse or promote products derived from this software without
18 # specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
24 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 # Test the memory plugin with the malloc allocator and mlock. Usually
34 # mlock limits are very low, so this test only tries to allocate a
35 # very tiny disk, in the hope that this way we at least end up with
36 # some test coverage of the feature.
43 if ! nbdkit memory
--dump-plugin |
grep -sq mlock
=yes; then
44 echo "$0: mlock not enabled in this build of nbdkit"
48 # ulimit -l is measured in kilobytes and so for this test must be at
49 # least 10 (kilobytes) and we actually check it's a bit larger to
50 # allow room for error. On Linux the default is usually 64.
51 if test "$(ulimit -l)" != "unlimited" && test "$(ulimit -l)" -le 16; then
52 echo "$0: limit for mlock memory (ulimit -l) too low for test"
56 sock
=$
(mktemp
-u /tmp
/nbdkit-test-sock.XXXXXX
)
57 files
="memory-allocator-malloc-mlock.pid $sock"
59 cleanup_fn
rm -f $files
61 # Run nbdkit with memory plugin.
62 start_nbdkit
-P memory-allocator-malloc-mlock.pid
-U $sock \
63 memory
10240 allocator
=malloc
,mlock
=true
65 nbdsh
--connect "nbd+unix://?socket=$sock" \
77 h.pwrite(buf5, 10240-len(buf5))
80 buf11 = h.pread(len(buf1), 0)
82 buf22 = h.pread(len(buf2), 1024)
84 buf33 = h.pread(len(buf3), 1536)
86 buf44 = h.pread(len(buf4), 4096)
88 buf55 = h.pread(len(buf5), 10240-len(buf5))