dd.test revision 5b360d8da327b38daf0c5b8874fbe55406b70ced
1a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari#!/bin/bash 2a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari 3a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari# Copyright 2013 Robin Mittal <robinmittal.it@gmail.com> 4a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari# Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com> 5a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari 6a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari[ -f testing.sh ] && . testing.sh 7a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari 8a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari# 'dd' command, stderr prints redirecting to /dev/null 9a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothariopt="2>/dev/null" 10a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari 11a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari#testing "name" "command" "result" "infile" "stdin" 12a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari 13d5088a059649daf34e729995bb3daa3eb64fa432Elliott Hughes# Test suffixed number parsing; `count` is representative. 14d5088a059649daf34e729995bb3daa3eb64fa432Elliott Hughestesting "count=2" "dd if=input count=2 ibs=1 $opt" "hi" "high\n" "" 15d5088a059649daf34e729995bb3daa3eb64fa432Elliott Hughestesting "count= 2" "dd if=input 'count= 2' ibs=1 $opt" "hi" "high\n" "" 16d5088a059649daf34e729995bb3daa3eb64fa432Elliott Hughestesting "count=0x2" "dd if=input 'count=0x2' ibs=1 $opt" "hi" "high\n" "" 17d5088a059649daf34e729995bb3daa3eb64fa432Elliott Hughestesting "count=-2" "dd if=input 'count=-2' ibs=1 2>&1" "dd: invalid number '-2'\n" "" "" 18d5088a059649daf34e729995bb3daa3eb64fa432Elliott Hughes 19336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "if=(file)" "dd if=input $opt" "I WANT\n" "I WANT\n" "" 20336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "of=(file)" "dd of=file $opt && cat file" "I WANT\n" "" "I WANT\n" 21336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "if=file of=file" "dd if=input of=foo $opt && cat foo && rm -f foo" \ 22a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari "I WANT\n" "I WANT\n" "" 23336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "if=file | dd of=file" "dd if=input $opt | dd of=foo $opt && 24a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari cat foo && rm -f foo" "I WANT\n" "I WANT\n" "" 25336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "(stdout)" "dd $opt" "I WANT\n" "" "I WANT\n" 26336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "sync,noerror" \ 27a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari "dd if=input of=outFile seek=8860 bs=1M conv=sync,noerror $opt && 28a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari stat -c \"%s\" outFile && rm -f outFile" "9291431936\n" "I WANT\n" "" 29336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "if=file of=(null)" \ 30a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari "dd if=input of=/dev/null $opt && echo 'yes'" "yes\n" "I WANT\n" "" 31336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with if of bs" \ 32a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari "dd if=/dev/zero of=sda.txt bs=512 count=1 $opt && 33a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari stat -c '%s' sda.txt && rm -f sda.txt" "512\n" "" "" 34336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with if of ibs obs" \ 35a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari "dd if=/dev/zero of=sda.txt ibs=512 obs=256 count=1 $opt && 36a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari stat -c '%s' sda.txt && rm -f sda.txt" "512\n" "" "" 37336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with if of ibs obs count" \ 38a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari "dd if=/dev/zero of=sda.txt ibs=512 obs=256 count=3 $opt && 39a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari stat -c '%s' sda.txt && rm -f sda.txt" "1536\n" "" "" 40a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari 41a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothariln -s input softlink 42336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "if=softlink" "dd if=softlink $opt" "I WANT\n" "I WANT\n" "" 43a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothariunlink softlink 44a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari 45a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothariln -s file softlink 46336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "if=file of=softlink" "dd if=input of=softlink $opt && 47a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari [ -f file -a -L softlink ] && cat softlink" "I WANT\n" "I WANT\n" "" 48a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothariunlink softlink && rm -f file 49a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari 50336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "if=file of=file (same file)" "dd if=input of=input $opt && 51a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari [ -f input ] && cat input && echo 'yes'" "yes\n" "I WANT\n" "" 525b360d8da327b38daf0c5b8874fbe55406b70cedRob Landleytesting "same file notrunc" \ 535b360d8da327b38daf0c5b8874fbe55406b70cedRob Landley "dd if=input of=input conv=notrunc $opt && cat input" \ 545b360d8da327b38daf0c5b8874fbe55406b70cedRob Landley "I WANT\n" "I WANT\n" "" 55a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari 56336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with ibs obs bs" "dd ibs=2 obs=5 bs=9 $opt" "I WANT\n" "" "I WANT\n" 57336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with ibs obs bs if" "dd ibs=2 obs=5 bs=9 if=input $opt" \ 58a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari "I WANT\n" "I WANT\n" "" 59a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari 60336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with ibs obs count" "dd ibs=1 obs=1 count=1 $opt" "I" "" "I WANT\n" 61336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with ibs obs count if" "dd ibs=1 obs=1 count=3 if=input $opt" \ 62a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari "I W" "I WANT\n" "" 63a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari 64336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with count" "dd count=1 $opt" "I WANT\n" "" "I WANT\n" 65336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with count if" "dd count=1 if=input $opt" "I WANT\n" "I WANT\n" "" 66a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari 67336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with skip" "dd skip=0 $opt" "I WANT\n" "" "I WANT\n" 68336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with skip if" "dd skip=0 if=input $opt" "I WANT\n" "I WANT\n" "" 69a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari 70336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with seek" "dd seek=0 $opt" "I WANT\n" "" "I WANT\n" 71336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with seek if" "dd seek=0 if=input $opt" "I WANT\n" "I WANT\n" "" 72a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari 73a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari# Testing only 'notrunc', 'noerror', 'fsync', 'sync' 74a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari 75336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "conv=notrunc" "dd conv=notrunc $opt" "I WANT\n" "" "I WANT\n" 76336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "conv=notrunc with IF" "dd conv=notrunc if=input $opt" "I WANT\n" \ 77a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari "I WANT\n" "" 78a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari 79336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "conv=noerror" "dd conv=noerror $opt" "I WANT\n" "" "I WANT\n" 80336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "conv=noerror with IF" "dd conv=noerror if=input $opt" "I WANT\n" \ 81a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari "I WANT\n" "" 82a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari 83336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "conv=fsync" "dd conv=fsync $opt" "I WANT\n" "" "I WANT\n" 84336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "conv=fsync with IF" "dd conv=fsync if=input $opt" "I WANT\n" \ 85a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari "I WANT\n" "" 86a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari 87336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "conv=sync" "dd conv=sync $opt | head -n 1" "I WANT\n" "" "I WANT\n" 88336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "conv=sync with IF" "dd conv=sync if=input $opt | head -n 1" "I WANT\n" \ 89a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari "I WANT\n" "" 90d5088a059649daf34e729995bb3daa3eb64fa432Elliott Hughes 91d5088a059649daf34e729995bb3daa3eb64fa432Elliott Hughes# status=noxfer|none 92d5088a059649daf34e729995bb3daa3eb64fa432Elliott Hughestesting "status=noxfer" "dd if=input status=noxfer ibs=1 2>&1" "input\n6+0 records in\n0+1 records out\n" "input\n" "" 93d5088a059649daf34e729995bb3daa3eb64fa432Elliott Hughestesting "status=none" "dd if=input status=none ibs=1 2>&1" "input\n" "input\n" "" 94