Blob Blame History Raw
From 43e2ea9a31c301e162507a3f656b8719454df086 Mon Sep 17 00:00:00 2001
From: Stefan Hajnoczi <stefanha@redhat.com>
Date: Tue, 6 Aug 2013 15:44:49 +0800
Subject: [PATCH 03/13] qemu-iotests: add poke_file utility function

Message-id: <1377573001-27070-4-git-send-email-famz@redhat.com>
Patchwork-id: 53783
O-Subject: [RHEL-7 qemu-kvm PATCH 03/13] qemu-iotests: add poke_file utility function
Bugzilla: 995866
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>

The new poke_file function sets bytes at an offset in a file given a
printf-style format string.  It can be used to corrupt an image file for
test coverage of error paths.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit 23ea2ecc2a43d850bc9482068201ece5da36a448)
Signed-off-by: Fam Zheng <famz@redhat.com>
---
 tests/qemu-iotests/common.rc |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
index 1e9b2f4..1187b86 100644
--- a/tests/qemu-iotests/common.rc
+++ b/tests/qemu-iotests/common.rc
@@ -34,6 +34,12 @@ dd()
    fi
 }
 
+# poke_file 'test.img' 512 '\xff\xfe'
+poke_file()
+{
+    printf "$3" | dd "of=$1" bs=1 "seek=$2" conv=notrunc &>/dev/null
+}
+
 # we need common.config
 if [ "$iam" != "check" ]
 then
-- 
1.7.1