1# 2# Copyright (c) 2017 Spectra Logic Corporation 3# Copyright (c) 2023 Klara, Inc. 4# 5# SPDX-License-Identifier: BSD-2-Clause 6# 7 8atf_test_case max_seek 9max_seek_head() 10{ 11 atf_set "descr" "dd(1) can seek by the maximum amount" 12} 13max_seek_body() 14{ 15 case $(df -T . | tail -n 1 | cut -wf 2) in 16 "ufs") 17 atf_skip "UFS's maximum file size is too small" 18 ;; 19 "zfs") 20 # ZFS is fine 21 ;; 22 "tmpfs") 23 atf_skip "tmpfs can't create arbitrarily large sparse files" 24 ;; 25 *) 26 atf_skip "Unknown file system" 27 ;; 28 esac 29 30 touch f.in 31 seek=$(bc -e "2^63 / 4096 - 1") 32 atf_check -s exit:0 -e ignore dd if=f.in of=f.out bs=4096 seek=$seek 33} 34 35atf_test_case seek_overflow 36seek_overflow_head() 37{ 38 atf_set "descr" "dd(1) should reject too-large seek values" 39} 40seek_overflow_body() 41{ 42 touch f.in 43 seek=$(bc -e "2^63 / 4096") 44 atf_check -s not-exit:0 -e match:"seek offsets cannot be larger than" \ 45 dd if=f.in of=f.out bs=4096 seek=$seek 46 atf_check -s not-exit:0 -e match:"seek offsets cannot be larger than" \ 47 dd if=f.in of=f.out bs=4096 seek=-1 48} 49 50atf_test_case sigint 51sigint_open_head() 52{ 53 atf_set "descr" "SIGINT while opening destination" 54} 55sigint_open_body() 56{ 57 atf_check mkfifo fifo 58 set -m 59 dd if=fifo of=/dev/null 2>stderr & 60 pid=$! 61 sleep 3 62 kill -INT $pid 63 wait $pid 64 rv=$? 65 atf_check test "$rv" -gt 128 66 atf_check -o inline:"INT\n" kill -l $((rv-128)) 67 atf_check test -s stderr 68} 69 70atf_test_case sigint 71sigint_read_head() 72{ 73 atf_set "descr" "SIGINT while reading source" 74} 75sigint_read_body() 76{ 77 atf_check mkfifo fifo 78 (sleep 30 >fifo &) # ensures that dd does not block on open 79 set -m 80 dd if=fifo of=/dev/null 2>stderr & 81 pid=$! 82 sleep 3 83 kill -INT $pid 84 wait $pid 85 rv=$? 86 atf_check test "$rv" -gt 128 87 atf_check -o inline:"INT\n" kill -l $((rv-128)) 88 atf_check test -s stderr 89} 90 91atf_init_test_cases() 92{ 93 atf_add_test_case max_seek 94 atf_add_test_case seek_overflow 95 atf_add_test_case sigint_open 96 atf_add_test_case sigint_read 97} 98