# parted part 1 -- build a GPT partition table inside a plain image file and # read it back. This is the ticket's stated acceptance criterion. # # Every case works on a regular FILE, not a block device, which is what makes # this port testable at all: this kernel has no block layer, so parted's # PED_DEVICE_FILE path is the only one that exists here. That is also why no # case rereads a kernel partition table (BLKRRPART) -- there is none to reread. # # Split across three files (this, -edit, -probe) for the same reason # 94-e2fsprogs is: the runner bounds each suite at 60 s of WALL CLOCK, parted is # a process per invocation, and a single combined file measured right at that # boundary -- it passed on an idle host and timed out on a loaded one. Splitting # gives each group its own budget instead of leaving the suite to flake. # # /tmp IS A tmpfs here ("mounted tmpfs -> /tmp (session-local scratch)"), i.e. # RAM, so fixtures are MiB rather than tens of MiB and are removed as soon as # their cases are done. . "$BST_LIB" require parted parted/present T=${TMPDIR:-/tmp}/bst-parted.$$ mkdir -p "$T" || exit 0 trap 'rm -rf "$T"' EXIT IMG=$T/disk.img # `parted -m` prints: "BYT;" / disk line / one line per partition, all ending # in ';'. Disk line fields: path:size:transport:logsec:physsec:label:name:flags # Partition fields: num:start:end:size:fs:name:flags # The whole point of -m here is process count: each STATE of the table is # snapshotted ONCE and every field assertion is a string compare against that # snapshot, rather than another parted run per field. snap() { parted -m -s "$1" print 2>/dev/null | sed 's/;$//'; } disk() { printf '%s\n' "$1" | awk -F: 'NR==2{print $'"$2"'}'; } part() { printf '%s\n' "$1" | awk -F: '/^'"$2"':/{print $'"$3"'}'; } check_out parted/version "GNU parted" parted --version # 8 MiB: room for two 2 MiB partitions plus GPT's primary and backup headers at # either end, and small enough to live in a RAM-backed /tmp. dd if=/dev/zero of="$IMG" bs=1M count=8 2>/dev/null check parted/mklabel-gpt parted -s "$IMG" mklabel gpt check parted/mkpart-1 parted -s "$IMG" mkpart primary ext4 1MiB 3MiB check parted/mkpart-2 parted -s "$IMG" mkpart data fat32 3MiB 5MiB S=$(snap "$IMG") check_eq parted/gpt-label "gpt" "$(disk "$S" 6)" check_eq parted/gpt-transport "file" "$(disk "$S" 3)" check_eq parted/gpt-sectorsize "512" "$(disk "$S" 4)" check_eq parted/gpt-p1-start "1049kB" "$(part "$S" 1 2)" check_eq parted/gpt-p1-end "3146kB" "$(part "$S" 1 3)" check_eq parted/gpt-p1-name "primary" "$(part "$S" 1 6)" check_eq parted/gpt-p2-name "data" "$(part "$S" 2 6)" # fat32 on GPT carries the Microsoft basic-data type GUID; asserting the flag # proves mkpart's filesystem-type argument reached the on-disk type field # rather than being parsed and dropped. check_eq parted/gpt-p2-flag "msftdata" "$(part "$S" 2 7)" check_eq parted/gpt-count "2" "$(printf '%s\n' "$S" | grep -c '^[0-9]*:')" # The human-readable renderer is a separate code path from -m, and it is the one # the ticket's acceptance criterion actually names. check_out parted/print-human "Partition Table: gpt" parted -s "$IMG" print # `unit s` re-renders the SAME table in sectors. 1 MiB / 512 B = sector 2048, so # this proves the unit conversion rather than a second read of the file. check_out parted/unit-sectors "2048s" parted -s "$IMG" unit s print