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