blob: 3b558c1b4d5889acf060e9a73c606b0efc02abfa [file] [log] [blame]
package main
import (
"os"
"path/filepath"
"testing"
"go.fuchsia.dev/fuchsia/src/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),
AppendCmdline: "devmgr.log-to-debuglog",
})
i.Start()
if err != nil {
t.Fatal(err)
}
defer i.Kill()
// Ensure the kernel OOM system was properly initialized.
i.WaitForLogMessage("OOM: memory availability state Normal")
// Make sure the shell is ready to accept commands over serial.
i.WaitForLogMessage("vc: Successfully attached")
// Trigger a simulated OOM.
i.RunCommand("k pmm oom")
i.WaitForLogMessage("OOM: memory availability state OutOfMemory")
// Make sure the file system is notified and unmounts.
i.WaitForLogMessage("Successfully waited for VFS exit completion")
// Ensure the OOM thread reboots the target.
i.WaitForLogMessage("OOM: rebooting")
// Ensure that the reboot has stowed a correct crashlog.
i.WaitForLogMessage("stowing crashlog")
i.WaitForLogMessage("ZIRCON REBOOT REASON (OOM)")
}