Re: regress: installboot: add initial tests, don't hook up yet

2022-08-20 Thread Klemens Nanni
On Sat, Aug 20, 2022 at 09:26:03AM +, Klemens Nanni wrote:
> installboot is not trivial, especially when it comes to the matrix of
> platforms, softraid softraid support and boot loader filesystem support.
> 
> It is especially annoying to run into issues in the installer where
> debugging capabilities are limited -- I've had that with softraid on
> sparc64 where the issue turns out to be reproducible with vnd(4) in
> multi-user, i.e. a much quicker and safer setup to squash installboot
> bugs.
> 
> OK to add the first round of checks?
> 
> It'll need some MD bits wrt. vnd disk setup to work on more platforms,
> but I'd like to do that in-tree.
> 
> I could then hook it up per-arch as I run and improve the tests on more
> platforms/machines.
> 
> Feedback?

Improved version passing on amd64, failing one test on sparc64 and
needing more work on arm64.

I'll commit it eventually, but would appreciate some feedback on it.
These tests really help getting softraid boot/install support into shape
on !amd64.

Index: regress/usr.sbin/installboot/Makefile
===
RCS file: regress/usr.sbin/installboot/Makefile
diff -N regress/usr.sbin/installboot/Makefile
--- /dev/null   1 Jan 1970 00:00:00 -
+++ regress/usr.sbin/installboot/Makefile   20 Aug 2022 17:13:15 -
@@ -0,0 +1,117 @@
+#  $OpenBSD: $
+
+INSTALLBOOT ?= /usr/sbin/installboot -v
+DRY_RUN =  ${INSTALLBOOT} -n
+REAL_RUN = ${INSTALLBOOT}
+
+# installboot(8) behaviour for multi-chunk softraid(4) differs across platforms
+NCHUNKS ?= 1 2
+CHUNKFILES =   ${NCHUNKS:=chunk%.img}
+DEVFILES = ${NCHUNKS:=vnd%.txt}
+SRFILE =   sr.txt
+# allow testing with real bootstrap, e.g. for size constraints or formats
+STAGEFILE ?=   stage.empty
+MOUNTPOINT ?=  /mnt
+
+REGRESS_SETUP_ONCE =   copy-bootstrap-to-softraid
+
+create-new-chunks:
+.for n in ${NCHUNKS}
+   dd if=/dev/zero  of=chunk${n}.img bs=1m count=0 seek=32 status=none
+   ${SUDO} vnconfig -- chunk${n}.img 1>vnd${n}.txt
+.endfor
+
+# what the installer does, see /usr/src/distrib/$(machine)/ramdisk/install.md
+format-new-chunks: create-new-chunks
+.for devfile in ${DEVFILES}
+.if   ${MACHINE} == "amd64"# assume BIOS/MBR
+   ${SUDO} fdisk -iy -- "$$(<${devfile})" 1>/dev/null
+.elif ${MACHINE} == "arm64"
+   ${SUDO} fdisk -g -y -b32768 -- "$$(<${devfile})" 1>/dev/null
+.endif
+   printf 'a\n\n\n\nRAID\nw\nq\n' | \
+   ${SUDO} disklabel -E -- "$$(<${devfile})" 1>/dev/null
+.endfor
+
+create-new-softraid: format-new-chunks
+   ${SUDO} bioctl -l"$$(sed -- s/$$/a/ ${DEVFILES} | paste -sd, -- -)" \
+   -cc -- softraid0 | \
+   awk -- '{ print $$NF }' 1>${SRFILE}
+
+format-new-softraid: create-new-softraid
+   ${SUDO} disklabel -Aw -- "$$(<${SRFILE})"
+   ${SUDO} newfs -- "$$(<${SRFILE})"a
+   ${SUDO} mount -- /dev/"$$(<${SRFILE})"a ${MOUNTPOINT}
+
+copy-bootstrap-to-softraid: format-new-softraid
+   ${SUDO} mkdir -- ${MOUNTPOINT}/usr
+   ${SUDO} cp -r -- /usr/mdec ${MOUNTPOINT}/usr/
+
+
+# most but not all usages rquire the EFI filesystem to be usable
+.if ${MACHINE} == "arm64"
+REGRESS_TARGETS = prepare
+
+# what the installer does, see /usr/src/distrib/$(machine)/ramdisk/install.md
+# do this as regress target and not in format-new-chunks
+# XXX -p is not yet softraid(4) aware
+prepare:
+   ${SUDO} ${REAL_RUN} -p -- "$$(<${SRFILE})"
+.else
+REGRESS_TARGETS =  # empty
+.endif
+REGRESS_TARGETS += dry-prepare \
+   dry-default \
+   dry-root \
+   root-installer \
+   root-explicit-stages
+
+dry-prepare:
+   ${SUDO} ${DRY_RUN} -p -- "$$(<${SRFILE})"
+
+dry-default:
+   ${SUDO} ${DRY_RUN} -- "$$(<${SRFILE})"
+
+dry-root:
+   ${SUDO} ${DRY_RUN} -r/ -- "$$(<${SRFILE})"
+
+# what the installer does, see /usr/src/distrib/$(machine)/ramdisk/install.md
+# XXX fails with N > 1 on sparc64, 1 <= N <= 4 works on amd64
+root-installer:
+   ${SUDO} installboot -r /mnt "$$(<${SRFILE})"
+
+
+REGRESS_EXPECTED_FAILURES =dry-prepare-root \
+   dry-prepare-stage \
+   dry-nodisk-stage \
+   dry-toomany
+REGRESS_TARGETS += ${REGRESS_EXPECTED_FAILURES}
+
+dry-prepare-root:
+   ${DRY_RUN} -p -r/ -- "$$(<${SRFILE})"
+
+dry-prepare-stage:
+   touch -- ${STAGEFILE}
+   ${DRY_RUN} -p -- "$$(<${SRFILE})" ${STAGEFILE}
+
+dry-nodisk-stage:
+   touch -- ${STAGEFILE}
+   ${SUDO} ${DRY_RUN} -- ${STAGEFILE}
+
+dry-toomany:
+   touch -- ${STAGEFILE}
+   ${DRY_RUN} -- disk stage1 stage2 too many
+
+
+CLEANFILES =   ${CHUNKFILES} ${DEVFILES} ${SRFILE} ${STAGEFILE}
+REGRESS_CLEANUP =  cleanup
+
+# allow failure to always cleanup as much as possible
+cleanup:
+   -${SUDO} 

regress: installboot: add initial tests, don't hook up yet

2022-08-20 Thread Klemens Nanni
installboot is not trivial, especially when it comes to the matrix of
platforms, softraid softraid support and boot loader filesystem support.

It is especially annoying to run into issues in the installer where
debugging capabilities are limited -- I've had that with softraid on
sparc64 where the issue turns out to be reproducible with vnd(4) in
multi-user, i.e. a much quicker and safer setup to squash installboot
bugs.

OK to add the first round of checks?

It'll need some MD bits wrt. vnd disk setup to work on more platforms,
but I'd like to do that in-tree.

I could then hook it up per-arch as I run and improve the tests on more
platforms/machines.

Feedback?

Index: regress/usr.sbin/installboot/Makefile
===
RCS file: regress/usr.sbin/installboot/Makefile
diff -N regress/usr.sbin/installboot/Makefile
--- /dev/null   1 Jan 1970 00:00:00 -
+++ regress/usr.sbin/installboot/Makefile   20 Aug 2022 09:00:13 -
@@ -0,0 +1,83 @@
+#  $OpenBSD: $
+
+INSTALLBOOT ?= /usr/sbin/installboot
+DRY_RUN =  ${INSTALLBOOT} -n
+
+# dry-r fails with N > 2 on sparc64, N = 4 works on amd64
+N ?=   1 2 3 4
+IMGFILES = ${N:=disk%.img}
+DEVFILES = ${N:=vnd%.txt}
+SRFILE =   sr.txt
+# CONCAT takes any positive number of chunks
+SRLEVEL ?= c
+# allow testing with real bootstrap, e.g. for size constraints or formats
+STAGEFILE ?=   stage.empty
+
+REGRESS_SETUP_ONCE =   create-new-softraid
+
+create-new-disks:
+.for n in ${N}
+   dd if=/dev/zero  of=disk${n}.img bs=1m count=0 seek=32 status=none
+   ${SUDO} vnconfig -- disk${n}.img 1>vnd${n}.txt
+.endfor
+
+format-new-disks: create-new-disks
+.for devfile in ${DEVFILES}
+   @# XXX MD (sparc64 does not need fdisk)
+   ${SUDO} fdisk -iy -- "$$(<${devfile})" 1>/dev/null
+   printf 'a\n\n\n\nRAID\nw\nq\n' | \
+   ${SUDO} disklabel -E -- "$$(<${devfile})" 1>/dev/null
+.endfor
+
+create-new-softraid: format-new-disks
+   ${SUDO} bioctl -c${SRLEVEL} \
+   -l"$$(sed s/$$/a/ vnd?.txt | paste -sd, -)" -- softraid0 | \
+   awk '{ print $$NF }' 1>${SRFILE}
+
+
+REGRESS_TARGETS =  dry-p \
+   dry-default \
+   dry-r
+
+dry-p:
+   ${SUDO} ${DRY_RUN} -p -- "$$(<${SRFILE})"
+
+dry-default:
+   ${SUDO} ${DRY_RUN} -- "$$(<${SRFILE})"
+
+dry-r:
+   ${SUDO} ${DRY_RUN} -r/ -- "$$(<${SRFILE})"
+
+
+REGRESS_EXPECTED_FAILURES =dry-p-r \
+   dry-p-stage \
+   dry-nodisk-stage \
+   dry-toomany
+REGRESS_TARGETS += ${REGRESS_EXPECTED_FAILURES}
+
+dry-p-r:
+   ${DRY_RUN} -p -r/ -- "$$(<${SRFILE})"
+
+dry-p-stage:
+   touch -- ${STAGEFILE}
+   ${DRY_RUN} -p -- "$$(<${SRFILE})" ${STAGEFILE}
+
+dry-nodisk-stage:
+   touch -- ${STAGEFILE}
+   ${SUDO} ${DRY_RUN} -- ${STAGEFILE}
+
+dry-toomany:
+   touch -- ${STAGEFILE}
+   ${DRY_RUN} -- disk stage1 stage2 too many
+
+
+CLEANFILES =   ${IMGFILES} ${DEVFILES} ${SRFILE} ${STAGEFILE}
+REGRESS_CLEANUP =  cleanup
+
+cleanup:
+   ${SUDO} bioctl -d -- "$$(<${SRFILE})"
+.for devfile in ${DEVFILES}
+   ${SUDO} vnconfig -u -- "$$(<${devfile})"
+.endfor
+
+.include