blob: cd7acafef4eeaed8b4588d1127bfb7449413f28a [file] [log] [blame]
Tim Windelschmidt6d33a432025-02-04 14:34:25 +01001// Copyright The Monogon Project Authors.
2// SPDX-License-Identifier: Apache-2.0
3
Jan Schär1212ea12025-07-03 07:42:43 +00004package bootparam_test
Lorenz Brund67eb4f2023-04-11 16:03:31 +02005
Jan Schär1212ea12025-07-03 07:42:43 +00006import (
7 "testing"
8
9 "source.monogon.dev/osbase/bootparam"
10)
Lorenz Brund67eb4f2023-04-11 16:03:31 +020011
12func TestConsoles(t *testing.T) {
13 cases := []struct {
14 name string
15 cmdline string
16 consoles []string
17 }{
18 {"Empty", "", []string{}},
19 {"None", "notconsole=test", []string{}},
20 {"Single", "asdf=ttyS1 console=ttyS0,115200", []string{"ttyS0"}},
21 {"MultipleSame", "console=ttyS0 noop console=ttyS0", []string{"ttyS0"}},
22 {"MultipleDiff", "console=tty27 console=ttyACM0", []string{"tty27", "ttyACM0"}},
23 {"WithDev", "console=/dev/ttyXYZ0", []string{"ttyXYZ0"}},
24 {"BrokenBadDev", "console=/etc/passwd", []string{}},
25 {"BrokenNoValue", "console=", []string{}},
26 }
27 for _, c := range cases {
28 t.Run(c.name, func(t *testing.T) {
Jan Schär1212ea12025-07-03 07:42:43 +000029 p, _, err := bootparam.Unmarshal(c.cmdline)
Lorenz Brund67eb4f2023-04-11 16:03:31 +020030 if err != nil {
31 t.Fatalf("Failed to parse cmdline %q: %v", c.cmdline, err)
32 }
33 consoles := p.Consoles()
34 wantConsoles := make(map[string]bool)
35 for _, con := range c.consoles {
36 wantConsoles[con] = true
37 }
38 for con := range wantConsoles {
39 if !consoles[con] {
40 t.Errorf("Expected console %s to be returned but it wasn't", con)
41 }
42 }
43 for con := range consoles {
44 if !wantConsoles[con] {
45 t.Errorf("Didn't expect console %s to be returned but it was", con)
46 }
47 }
48 })
49 }
50}