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" ""
167450ecd568e94e9bdde01afc3b60dc953a12bdc1Rob LandleySKIP_HOST=1 testing "count=0x2" "dd if=input 'count=0x2' ibs=1 $opt" "hi" \
177450ecd568e94e9bdde01afc3b60dc953a12bdc1Rob Landley  "high\n" ""
187450ecd568e94e9bdde01afc3b60dc953a12bdc1Rob Landleytesting "count=-2" "dd if=input 'count=-2' ibs=1 2>/dev/null || echo errored" "errored\n" "" ""
19d5088a059649daf34e729995bb3daa3eb64fa432Elliott Hughes
20336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "if=(file)" "dd if=input $opt" "I WANT\n" "I WANT\n" ""
21336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "of=(file)" "dd of=file $opt && cat file" "I WANT\n" "" "I WANT\n"
22336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "if=file of=file" "dd if=input of=foo $opt && cat foo && rm -f foo" \
23a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari  "I WANT\n" "I WANT\n" ""
24336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "if=file | dd of=file" "dd if=input $opt | dd of=foo $opt &&
25a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari   cat foo && rm -f foo" "I WANT\n" "I WANT\n" ""
26336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "(stdout)" "dd $opt" "I WANT\n" "" "I WANT\n"
27336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "sync,noerror" \
28a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari  "dd if=input of=outFile seek=8860 bs=1M conv=sync,noerror $opt &&
29a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari   stat -c \"%s\" outFile && rm -f outFile" "9291431936\n" "I WANT\n" ""
30336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "if=file of=(null)" \
31a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari  "dd if=input of=/dev/null $opt && echo 'yes'" "yes\n" "I WANT\n" ""
32336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with if of bs" \
33a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari  "dd if=/dev/zero of=sda.txt bs=512 count=1 $opt &&
34a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari   stat -c '%s' sda.txt && rm -f sda.txt" "512\n" "" ""
35336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with if of ibs obs" \
36a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari  "dd if=/dev/zero of=sda.txt ibs=512 obs=256 count=1 $opt &&
37a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari   stat -c '%s' sda.txt && rm -f sda.txt" "512\n" "" ""
38336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with if of ibs obs count" \
39a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari  "dd if=/dev/zero of=sda.txt ibs=512 obs=256 count=3 $opt &&
40a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari   stat -c '%s' sda.txt && rm -f sda.txt" "1536\n" "" ""
41a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari
42a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothariln -s input softlink
43336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "if=softlink" "dd if=softlink $opt" "I WANT\n" "I WANT\n" ""
44a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothariunlink softlink
45a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari
46a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothariln -s file softlink
47336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "if=file of=softlink" "dd if=input of=softlink $opt &&
48a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari   [ -f file -a -L softlink ] && cat softlink" "I WANT\n" "I WANT\n" ""
49a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothariunlink softlink && rm -f file
50a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari
51336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "if=file of=file (same file)" "dd if=input of=input $opt &&
52a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari   [ -f input ] && cat input && echo 'yes'" "yes\n" "I WANT\n" ""
535b360d8da327b38daf0c5b8874fbe55406b70cedRob Landleytesting "same file notrunc" \
545b360d8da327b38daf0c5b8874fbe55406b70cedRob Landley  "dd if=input of=input conv=notrunc $opt && cat input" \
555b360d8da327b38daf0c5b8874fbe55406b70cedRob Landley  "I WANT\n" "I WANT\n" ""
56a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari
57336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with ibs obs bs" "dd ibs=2 obs=5 bs=9 $opt" "I WANT\n" "" "I WANT\n"
58336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with ibs obs bs if" "dd ibs=2 obs=5 bs=9 if=input $opt" \
59a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari  "I WANT\n" "I WANT\n" ""
60a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari
61336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with ibs obs count" "dd ibs=1 obs=1 count=1 $opt" "I" "" "I WANT\n"
62336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with ibs obs count if" "dd ibs=1 obs=1 count=3 if=input $opt" \
63a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari  "I W" "I WANT\n" ""
64a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari
65336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with count" "dd count=1 $opt" "I WANT\n" "" "I WANT\n"
66336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with count if" "dd count=1 if=input $opt" "I WANT\n" "I WANT\n" ""
67a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari
68336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with skip" "dd skip=0 $opt" "I WANT\n" "" "I WANT\n"
69336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with skip if" "dd skip=0 if=input $opt" "I WANT\n" "I WANT\n" ""
70a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari
71336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with seek" "dd seek=0 $opt" "I WANT\n" "" "I WANT\n"
72336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "with seek if" "dd seek=0 if=input $opt" "I WANT\n" "I WANT\n" ""
73a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari
74a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari# Testing only 'notrunc', 'noerror', 'fsync', 'sync'
75a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari
76336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "conv=notrunc" "dd conv=notrunc $opt" "I WANT\n" "" "I WANT\n"
77336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "conv=notrunc with IF" "dd conv=notrunc if=input $opt" "I WANT\n" \
78a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari  "I WANT\n" ""
79a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari
80336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "conv=noerror" "dd conv=noerror $opt" "I WANT\n" "" "I WANT\n"
81336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "conv=noerror with IF" "dd conv=noerror if=input $opt" "I WANT\n" \
82a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari  "I WANT\n" ""
83a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari
84336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "conv=fsync" "dd conv=fsync $opt" "I WANT\n" "" "I WANT\n"
85336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "conv=fsync with IF" "dd conv=fsync if=input $opt" "I WANT\n" \
86a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari  "I WANT\n" ""
87a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari
88336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "conv=sync" "dd conv=sync $opt | head -n 1" "I WANT\n" "" "I WANT\n"
89336c44adca1768ada1e1e2f4d7dbbc33e994e582Rob Landleytesting "conv=sync with IF" "dd conv=sync if=input $opt | head -n 1" "I WANT\n" \
90a0f56beaf63052179c69fb258478f851ef1e5ca2Divya Kothari  "I WANT\n" ""
91d5088a059649daf34e729995bb3daa3eb64fa432Elliott Hughes
92d5088a059649daf34e729995bb3daa3eb64fa432Elliott Hughes# status=noxfer|none
93d5088a059649daf34e729995bb3daa3eb64fa432Elliott Hughestesting "status=noxfer" "dd if=input status=noxfer ibs=1 2>&1" "input\n6+0 records in\n0+1 records out\n" "input\n" ""
94d5088a059649daf34e729995bb3daa3eb64fa432Elliott Hughestesting "status=none" "dd if=input status=none ibs=1 2>&1" "input\n" "input\n" ""
95