blob: 33492f9eeb083065e624f530630d32e2f8c3ec7a [file] [log] [blame]
package main
import (
"os"
"path/filepath"
"testing"
"fuchsia.googlesource.com/testing/qemu"
)
func zbiPath(t *testing.T) string {
ex, err := os.Executable()
if err != nil {
t.Fatal(err)
return ""
}
exPath := filepath.Dir(ex)
return filepath.Join(exPath, "../fuchsia.zbi")
}
func TestOOM(t *testing.T) {
distro, err := qemu.Unpack()
if err != nil {
t.Fatal(err)
}
defer distro.Delete()
arch, err := distro.TargetCPU()
if err != nil {
t.Fatal(err)
}
i := distro.Create(qemu.Params{
Arch: arch,
ZBI: zbiPath(t),
})
i.Start()
if err != nil {
t.Fatal(err)
}
defer i.Kill()
// Ensure the OOM thread was enabled in the kernel.
i.WaitForLogMessage("OOM: started thread")
// Make sure the shell is ready to accept commands over serial.
i.WaitForLogMessage("vc: Successfully attached")
// Trigger a simulated OOM.
i.RunCommand("k oom lowmem")
// Make sure the file system is notified and unmounts.
i.WaitForLogMessage("devcoordinator: Successfully waited for VFS exit completion")
// Ensure the OOM thread reboots the target.
i.WaitForLogMessage("OOM: rebooting")
}