Subject: bug#17105: [PATCH 4/4] tests: Use msdos-overlap to setup t0283

From: "Brian C. Lane" <[email-masked]>
Date: Wed, 26 Mar 2014 10:56:22 -0700

xxd isn't present in minimal build systems, as it is part of vim. Change
to using a simple python script to mangle the msdos disklabel for the
test.

* tests/msdos-overlap.py: New file
* tests/t0283-overlap-partitions.sh: Use msdos-overlap.py
---
 tests/msdos-overlap.py            | 25 ++++++++++++++++++++++++
 tests/t0283-overlap-partitions.sh | 40 +++------------------------------------
 2 files changed, 28 insertions(+), 37 deletions(-)
 create mode 100755 tests/msdos-overlap.py

diff --git a/tests/msdos-overlap.py b/tests/msdos-overlap.py
new file mode 100755
index 0000000..5bddfb0
--- /dev/null
+++ b/tests/msdos-overlap.py
@@ -0,0 +1,25 @@
+#!/usr/bin/python
+"""
+    Write an overlapping partition to a msdos disk
+
+    Call with disk image/device to mangle
+"""
+import sys
+
+BAD_ENTRY = (0x72, 0xf5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+             0x01, 0x10, 0x83, 0x03, 0x20, 0x4f, 0x00, 0x08,
+             0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00,
+             0x00, 0x50, 0x83, 0x00, 0x0a, 0x7a, 0xff, 0x27,
+             0x00, 0x00, 0x0a, 0x15, 0x00, 0x00, 0x00, 0x00 )
+OFFSET = 0x1b8
+
+if len(sys.argv) < 2:
+    print "%s: <image or device>"
+    sys.exit(1)
+
+data = "".join(chr(c) for c in BAD_ENTRY)
+with open(sys.argv[1], "rb+") as f:
+    f.seek(OFFSET, 0)
+    f.write(data)
+
+sys.exit(0)
diff --git a/tests/t0283-overlap-partitions.sh b/tests/t0283-overlap-partitions.sh
index c7ae52a..221332d 100644
--- a/tests/t0283-overlap-partitions.sh
+++ b/tests/t0283-overlap-partitions.sh
@@ -21,43 +21,9 @@
 require_512_byte_sector_size_
 dev=loop-file
 
-truncate -s 10m $dev || fail=1
-
-# write damaged label
-xxd -r - $dev <<EOF
-0000000: fab8 0010 8ed0 bc00 b0b8 0000 8ed8 8ec0  ................
-0000010: fbbe 007c bf00 06b9 0002 f3a4 ea21 0600  ...|.........!..
-0000020: 00be be07 3804 750b 83c6 1081 fefe 0775  ....8.u........u
-0000030: f3eb 16b4 02b0 01bb 007c b280 8a74 018b  .........|...t..
-0000040: 4c02 cd13 ea00 7c00 00eb fe00 0000 0000  L.....|.........
-0000050: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-0000060: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-0000070: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-0000080: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-0000090: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-00000a0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-00000b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-00000c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-00000d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-00000e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-00000f0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-0000100: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-0000110: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-0000120: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-0000130: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-0000140: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-0000150: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-0000160: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-0000170: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-0000180: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-0000190: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-00001a0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-00001b0: 0000 0000 0000 0000 72f5 0000 0000 0000  ........r.......
-00001c0: 0110 8303 204f 0008 0000 0020 0000 0000  .... O..... ....
-00001d0: 0050 8300 0a7a ff27 0000 0a15 0000 0000  .P...z.'........
-00001e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
-00001f0: 0000 0000 0000 0000 0000 0000 0000 55aa  ..............U.
-EOF
+truncate -s 10m $dev || framework_failure
+parted -s $dev mklabel msdos || framework_failure
+python ../msdos-overlap.py $dev || framework_failure
 
 # print the empty table
 parted ---pretend-input-tty $dev <<EOF > out 2>&1 || fail=1
-- 
1.8.5.3