1 #!/bin/bash 2 3 # Copyright 2013 Robin Mittal <robinmittal.it (at] gmail.com> 4 # Copyright 2013 Divya Kothari <divya.s.kothari (at] gmail.com> 5 6 [ -f testing.sh ] && . testing.sh 7 8 # 'dd' command, stderr prints redirecting to /dev/null 9 opt="2>/dev/null" 10 11 #testing "name" "command" "result" "infile" "stdin" 12 13 # Test suffixed number parsing; `count` is representative. 14 testing "count=2" "dd if=input count=2 ibs=1 $opt" "hi" "high\n" "" 15 testing "count= 2" "dd if=input 'count= 2' ibs=1 $opt" "hi" "high\n" "" 16 testing "count=0x2" "dd if=input 'count=0x2' ibs=1 $opt" "hi" "high\n" "" 17 testing "count=-2" "dd if=input 'count=-2' ibs=1 2>&1" "dd: invalid number '-2'\n" "" "" 18 19 testing "if=(file)" "dd if=input $opt" "I WANT\n" "I WANT\n" "" 20 testing "of=(file)" "dd of=file $opt && cat file" "I WANT\n" "" "I WANT\n" 21 testing "if=file of=file" "dd if=input of=foo $opt && cat foo && rm -f foo" \ 22 "I WANT\n" "I WANT\n" "" 23 testing "if=file | dd of=file" "dd if=input $opt | dd of=foo $opt && 24 cat foo && rm -f foo" "I WANT\n" "I WANT\n" "" 25 testing "(stdout)" "dd $opt" "I WANT\n" "" "I WANT\n" 26 testing "sync,noerror" \ 27 "dd if=input of=outFile seek=8860 bs=1M conv=sync,noerror $opt && 28 stat -c \"%s\" outFile && rm -f outFile" "9291431936\n" "I WANT\n" "" 29 testing "if=file of=(null)" \ 30 "dd if=input of=/dev/null $opt && echo 'yes'" "yes\n" "I WANT\n" "" 31 testing "with if of bs" \ 32 "dd if=/dev/zero of=sda.txt bs=512 count=1 $opt && 33 stat -c '%s' sda.txt && rm -f sda.txt" "512\n" "" "" 34 testing "with if of ibs obs" \ 35 "dd if=/dev/zero of=sda.txt ibs=512 obs=256 count=1 $opt && 36 stat -c '%s' sda.txt && rm -f sda.txt" "512\n" "" "" 37 testing "with if of ibs obs count" \ 38 "dd if=/dev/zero of=sda.txt ibs=512 obs=256 count=3 $opt && 39 stat -c '%s' sda.txt && rm -f sda.txt" "1536\n" "" "" 40 41 ln -s input softlink 42 testing "if=softlink" "dd if=softlink $opt" "I WANT\n" "I WANT\n" "" 43 unlink softlink 44 45 ln -s file softlink 46 testing "if=file of=softlink" "dd if=input of=softlink $opt && 47 [ -f file -a -L softlink ] && cat softlink" "I WANT\n" "I WANT\n" "" 48 unlink softlink && rm -f file 49 50 testing "if=file of=file (same file)" "dd if=input of=input $opt && 51 [ -f input ] && cat input && echo 'yes'" "yes\n" "I WANT\n" "" 52 testing "same file notrunc" \ 53 "dd if=input of=input conv=notrunc $opt && cat input" \ 54 "I WANT\n" "I WANT\n" "" 55 56 testing "with ibs obs bs" "dd ibs=2 obs=5 bs=9 $opt" "I WANT\n" "" "I WANT\n" 57 testing "with ibs obs bs if" "dd ibs=2 obs=5 bs=9 if=input $opt" \ 58 "I WANT\n" "I WANT\n" "" 59 60 testing "with ibs obs count" "dd ibs=1 obs=1 count=1 $opt" "I" "" "I WANT\n" 61 testing "with ibs obs count if" "dd ibs=1 obs=1 count=3 if=input $opt" \ 62 "I W" "I WANT\n" "" 63 64 testing "with count" "dd count=1 $opt" "I WANT\n" "" "I WANT\n" 65 testing "with count if" "dd count=1 if=input $opt" "I WANT\n" "I WANT\n" "" 66 67 testing "with skip" "dd skip=0 $opt" "I WANT\n" "" "I WANT\n" 68 testing "with skip if" "dd skip=0 if=input $opt" "I WANT\n" "I WANT\n" "" 69 70 testing "with seek" "dd seek=0 $opt" "I WANT\n" "" "I WANT\n" 71 testing "with seek if" "dd seek=0 if=input $opt" "I WANT\n" "I WANT\n" "" 72 73 # Testing only 'notrunc', 'noerror', 'fsync', 'sync' 74 75 testing "conv=notrunc" "dd conv=notrunc $opt" "I WANT\n" "" "I WANT\n" 76 testing "conv=notrunc with IF" "dd conv=notrunc if=input $opt" "I WANT\n" \ 77 "I WANT\n" "" 78 79 testing "conv=noerror" "dd conv=noerror $opt" "I WANT\n" "" "I WANT\n" 80 testing "conv=noerror with IF" "dd conv=noerror if=input $opt" "I WANT\n" \ 81 "I WANT\n" "" 82 83 testing "conv=fsync" "dd conv=fsync $opt" "I WANT\n" "" "I WANT\n" 84 testing "conv=fsync with IF" "dd conv=fsync if=input $opt" "I WANT\n" \ 85 "I WANT\n" "" 86 87 testing "conv=sync" "dd conv=sync $opt | head -n 1" "I WANT\n" "" "I WANT\n" 88 testing "conv=sync with IF" "dd conv=sync if=input $opt | head -n 1" "I WANT\n" \ 89 "I WANT\n" "" 90 91 # status=noxfer|none 92 testing "status=noxfer" "dd if=input status=noxfer ibs=1 2>&1" "input\n6+0 records in\n0+1 records out\n" "input\n" "" 93 testing "status=none" "dd if=input status=none ibs=1 2>&1" "input\n" "input\n" "" 94