home: hub: mkinitfs

Download patch

ref: b09b86e6ccceeda5cbcee398feb5935297ea582c
parent: 060a3bfee6e66d05743013c846cefa15c888dfed
author: Natanael Copa <ncopa@alpinelinux.org>
date: Mon May 1 17:03:11 CDT 2023

init: add test for serial console in /etc/inittab

--- a/initramfs-init.in
+++ b/initramfs-init.in
@@ -96,12 +96,12 @@
 
 # Recursively resolve tty aliases like console or tty0
 list_console_devices() {
-	if ! [ -e /sys/class/tty/$1/active ]; then
+	if ! [ -e "$ROOT"/sys/class/tty/$1/active ]; then
 		echo $1
 		return
 	fi
 
-	for dev in $(cat /sys/class/tty/$1/active); do
+	for dev in $(cat "$ROOT"/sys/class/tty/$1/active); do
 		list_console_devices $dev
 	done
 }
--- a/tests/initramfs-init.test
+++ b/tests/initramfs-init.test
@@ -7,7 +7,8 @@
 	initramfs_init_blacklist \
 	initramfs_init_tmpfs_root \
 	initramfs_init_tmpfs_root_modloop_sign \
-	initramfs_init_tmpfs_root_net_apkovl
+	initramfs_init_tmpfs_root_net_apkovl \
+	initramfs_init_tmpfs_root_console_serial
 
 fake_cmdline() {
 	mkdir -p proc
@@ -90,5 +91,26 @@
 	atf_check \
 		-o match:"wget .* https://example.com/c7c29fe0-cf90-4024-8ba3-208387fc7ac6/foo.apkovl.tar.gz" \
 		initramfs-init
+}
+
+initramfs_init_tmpfs_root_console_serial_body() {
+	fake_cmdline "console=ttyS0"
+	fake_switch_root
+	fake_sysroot_init
+	fake_bin stty <<-EOF
+		#!/bin/sh
+		true
+	EOF
+
+	mkdir -p sys/class/tty/console
+	echo tty0 > sys/class/tty/console/active
+
+	atf_check \
+		-o ignore \
+		initramfs-init
+	atf_check \
+		-o match:"tty0::respawn:/sbin/getty" \
+		-o match:"ttyS0::respawn:/sbin/getty" \
+		cat sysroot/etc/inittab
 }