1#!/bin/sh 2# Ensure dd handles the 'nocache' flag 3 4# Copyright (C) 2011-2023 Free Software Foundation, Inc. 5 6# This program is free software: you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation, either version 3 of the License, or 9# (at your option) any later version. 10 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15 16# You should have received a copy of the GNU General Public License 17# along with this program. If not, see <https://www.gnu.org/licenses/>. 18 19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src 20print_ver_ dd 21 22# This should not call posix_fadvise 23dd iflag=nocache oflag=nocache if=/dev/null of=/dev/null || fail=1 24 25# We should get an error for trying to process a pipe 26dd count=0 | returns_ 1 dd iflag=nocache count=0 || fail=1 27 28# O_DIRECT is orthogonal to drop cache so mutually exclusive 29returns_ 1 dd iflag=nocache,direct if=/dev/null || fail=1 30 31# The rest ensure that the documented uses cases 32# proceed without error 33for f in ifile ofile; do 34 dd if=/dev/zero of=$f conv=fdatasync count=100 || framework_failure_ 35done 36 37# Advise to drop cache for whole file 38if ! dd if=ifile iflag=nocache count=0 2>err; then 39 # We could check for 'Operation not supported' in err here, 40 # but that was seen to be brittle. HPUX returns ENOTTY for example. 41 # So assume that if this basic operation fails, it's due to lack 42 # of support by the system. 43 warn_ 'skipping part; this file system lacks support for posix_fadvise()' 44 skip=1 45fi 46 47if test "$skip" != 1; then 48 # Ensure drop cache for whole file 49 dd of=ofile oflag=nocache conv=notrunc,fdatasync count=0 || fail=1 50 51 # Drop cache for part of file 52 dd if=ifile iflag=nocache skip=10 count=10 of=/dev/null || fail=1 53 54 # Stream data just using readahead cache 55 dd if=ifile of=ofile iflag=nocache oflag=nocache || fail=1 56fi 57 58Exit $fail 59