Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
kata-check: modprobe missing kernel modules
Browse files Browse the repository at this point in the history
So that we can possibly verify its parameter later on.

Signed-off-by: Peng Tao <bergwolf@gmail.com>
  • Loading branch information
bergwolf committed Oct 16, 2018
1 parent c3cfe82 commit ea9ecd7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
7 changes: 4 additions & 3 deletions cli/kata-check.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const (
var (
procCPUInfo = "/proc/cpuinfo"
sysModuleDir = "/sys/module"
modInfoCmd = "modinfo"
modProbeCmd = "modprobe"
)

// variables rather than consts to allow tests to modify them
Expand Down Expand Up @@ -120,8 +120,9 @@ func haveKernelModule(module string) bool {
return true
}

// Now, check if the module is unloaded, but available
cmd := exec.Command(modInfoCmd, module)
// Now, check if the module is unloaded, but available.
// And modprobe it if so.
cmd := exec.Command(modProbeCmd, module)
err := cmd.Run()
return err == nil
}
Expand Down
34 changes: 17 additions & 17 deletions cli/kata-check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,15 @@ func TestCheckHaveKernelModule(t *testing.T) {
}
defer os.RemoveAll(dir)

savedModInfoCmd := modInfoCmd
savedModProbeCmd := modProbeCmd
savedSysModuleDir := sysModuleDir

// XXX: override (fake the modprobe command failing)
modInfoCmd = "false"
modProbeCmd = "false"
sysModuleDir = filepath.Join(dir, "sys/module")

defer func() {
modInfoCmd = savedModInfoCmd
modProbeCmd = savedModProbeCmd
sysModuleDir = savedSysModuleDir
}()

Expand All @@ -471,13 +471,13 @@ func TestCheckHaveKernelModule(t *testing.T) {
assert.False(result)

// XXX: override - make our fake "modprobe" succeed
modInfoCmd = "true"
modProbeCmd = "true"

result = haveKernelModule(module)
assert.True(result)

// disable "modprobe" again
modInfoCmd = "false"
modProbeCmd = "false"

fooDir := filepath.Join(sysModuleDir, module)
err = os.MkdirAll(fooDir, testDirMode)
Expand All @@ -498,15 +498,15 @@ func TestCheckCheckKernelModules(t *testing.T) {
}
defer os.RemoveAll(dir)

savedModInfoCmd := modInfoCmd
savedModProbeCmd := modProbeCmd
savedSysModuleDir := sysModuleDir

// XXX: override (fake the modprobe command failing)
modInfoCmd = "false"
modProbeCmd = "false"
sysModuleDir = filepath.Join(dir, "sys/module")

defer func() {
modInfoCmd = savedModInfoCmd
modProbeCmd = savedModProbeCmd
sysModuleDir = savedSysModuleDir
}()

Expand Down Expand Up @@ -590,15 +590,15 @@ func TestCheckCheckKernelModulesUnreadableFile(t *testing.T) {
},
}

savedModInfoCmd := modInfoCmd
savedModProbeCmd := modProbeCmd
savedSysModuleDir := sysModuleDir

// XXX: override (fake the modprobe command failing)
modInfoCmd = "false"
modProbeCmd = "false"
sysModuleDir = filepath.Join(dir, "sys/module")

defer func() {
modInfoCmd = savedModInfoCmd
modProbeCmd = savedModProbeCmd
sysModuleDir = savedSysModuleDir
}()

Expand Down Expand Up @@ -637,15 +637,15 @@ func TestCheckCheckKernelModulesInvalidFileContents(t *testing.T) {
},
}

savedModInfoCmd := modInfoCmd
savedModProbeCmd := modProbeCmd
savedSysModuleDir := sysModuleDir

// XXX: override (fake the modprobe command failing)
modInfoCmd = "false"
modProbeCmd = "false"
sysModuleDir = filepath.Join(dir, "sys/module")

defer func() {
modInfoCmd = savedModInfoCmd
modProbeCmd = savedModProbeCmd
sysModuleDir = savedSysModuleDir
}()

Expand Down Expand Up @@ -700,15 +700,15 @@ func TestCheckKernelParamHandler(t *testing.T) {
}
defer os.RemoveAll(dir)

savedModInfoCmd := modInfoCmd
savedModProbeCmd := modProbeCmd
savedSysModuleDir := sysModuleDir

// XXX: override (fake the modprobe command failing)
modInfoCmd = "false"
modProbeCmd = "false"
sysModuleDir = filepath.Join(dir, "sys/module")

defer func() {
modInfoCmd = savedModInfoCmd
modProbeCmd = savedModProbeCmd
sysModuleDir = savedSysModuleDir
}()

Expand Down

0 comments on commit ea9ecd7

Please sign in to comment.