Implements insmod kernel module from local file
This commit is contained in:
parent
623a7f08c1
commit
8649c791ea
@ -280,6 +280,16 @@ func (q *QemuSystem) CopyFile(user, localPath, remotePath string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (q *QemuSystem) CopyAndInsmod(localKoPath string) (output string, err error) {
|
||||
remoteKoPath := fmt.Sprintf("/tmp/module_%d.ko", rand.Int())
|
||||
err = q.CopyFile("root", localKoPath, remoteKoPath)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return q.Command("root", "insmod "+remoteKoPath)
|
||||
}
|
||||
|
||||
// CopyAndRun is copy local file to qemu vm then run it
|
||||
func (q *QemuSystem) CopyAndRun(user, path string) (output string, err error) {
|
||||
remotePath := fmt.Sprintf("/tmp/executable_%d", rand.Int())
|
||||
|
@ -213,3 +213,30 @@ func TestQemuSystemCopyAndRun(t *testing.T) {
|
||||
t.Fatal("Wrong output from copyied executable (" + output + "," + randStr + ")")
|
||||
}
|
||||
}
|
||||
|
||||
func TestQemuSystemCopyAndInsmod(t *testing.T) {
|
||||
qemu, err := startTestQemu(t)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer qemu.Stop()
|
||||
|
||||
lsmodBefore, err := qemu.Command("root", "lsmod | wc -l")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = qemu.CopyAndInsmod(testConfigSampleKo)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
lsmodAfter, err := qemu.Command("root", "lsmod | wc -l")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if lsmodBefore == lsmodAfter {
|
||||
t.Fatal("insmod returns ok but there is no new kernel modules")
|
||||
}
|
||||
}
|
||||
|
@ -7,3 +7,4 @@ package qemukernel
|
||||
const testConfigVmlinuz = "tools/qemu-debian-img/vmlinuz-bionic"
|
||||
const testConfigInitrd = "tools/qemu-debian-img/initrd-bionic"
|
||||
const testConfigRootfs = "tools/qemu-debian-img/bionic.img"
|
||||
const testConfigSampleKo = "tools/qemu-debian-img/sample.ko"
|
||||
|
1
tools/qemu-debian-img/.gitignore
vendored
1
tools/qemu-debian-img/.gitignore
vendored
@ -2,3 +2,4 @@
|
||||
*.log
|
||||
vmlinuz*
|
||||
initrd*
|
||||
*.ko
|
1
tools/qemu-debian-img/Vagrantfile
vendored
1
tools/qemu-debian-img/Vagrantfile
vendored
@ -14,5 +14,6 @@ Vagrant.configure("2") do |config|
|
||||
cp bionic.img /vagrant/
|
||||
cp /boot/vmlinuz-* /vagrant/vmlinuz-bionic
|
||||
cp /boot/initrd-* /vagrant/vmlinuz-bionic
|
||||
cp /lib/modules/`uname -r`/kernel/lib/test_static_key_base.ko /vagrant/sample.ko
|
||||
SHELL
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user