Lorenz Brun | c7b036b | 2023-06-01 12:23:57 +0200 | [diff] [blame] | 1 | package kmod |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "os" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestManagerIntegration(t *testing.T) { |
| 10 | if os.Getenv("IN_KTEST") != "true" { |
| 11 | t.Skip("Not in ktest") |
| 12 | } |
Lorenz Brun | c7b036b | 2023-06-01 12:23:57 +0200 | [diff] [blame] | 13 | mgr, err := NewManagerFromPath("/lib/modules") |
| 14 | if err != nil { |
| 15 | t.Fatal(err) |
| 16 | } |
| 17 | t.Run("LoadExampleModule", func(t *testing.T) { |
| 18 | if err := mgr.LoadModule("r8169"); err != nil { |
| 19 | t.Error(err) |
| 20 | } |
| 21 | if _, err := os.Stat("/sys/module/r8169"); err != nil { |
| 22 | t.Error("module load returned success, but module not in sysfs") |
| 23 | } |
| 24 | }) |
| 25 | t.Run("LoadNonexistentModule", func(t *testing.T) { |
| 26 | err := mgr.LoadModule("definitelynomodule") |
| 27 | var notFoundErr *ErrNotFound |
| 28 | if !errors.As(err, ¬FoundErr) { |
| 29 | t.Errorf("expected ErrNotFound, got %v", err) |
| 30 | } |
| 31 | }) |
| 32 | t.Run("LoadModuleTwice", func(t *testing.T) { |
| 33 | if err := mgr.LoadModule("r8169"); err != nil { |
| 34 | t.Error(err) |
| 35 | } |
| 36 | }) |
| 37 | // TODO(lorenz): Should test loading dependencies here, but we currently |
| 38 | // have none in the kernel config and I'm not about to build another kernel |
| 39 | // just for this. |
| 40 | t.Run("LoadDeviceModule", func(t *testing.T) { |
| 41 | if err := mgr.LoadModulesForDevice("pci:v00008086d00001591sv00001043sd000085F0bc02sc00i00"); err != nil { |
| 42 | t.Error(err) |
| 43 | } |
| 44 | if _, err := os.Stat("/sys/module/ice"); err != nil { |
| 45 | t.Error("module load returned success, but module not in sysfs") |
| 46 | } |
| 47 | }) |
| 48 | } |