| // Copyright 2020 The Fuchsia Authors. All rights reserved. | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| package main | |
| import ( | |
| "context" | |
| "os" | |
| "path/filepath" | |
| "testing" | |
| "go.fuchsia.dev/fuchsia/tools/emulator" | |
| "go.fuchsia.dev/fuchsia/tools/emulator/emulatortest" | |
| ) | |
| func TestDlog(t *testing.T) { | |
| exDir := execDir(t) | |
| distro := emulatortest.UnpackFrom(t, filepath.Join(exDir, "test_data"), emulator.DistributionParams{ | |
| Emulator: emulator.Qemu, | |
| }) | |
| arch := distro.TargetCPU() | |
| device := emulator.DefaultVirtualDevice(string(arch)) | |
| ctx, cancel := context.WithCancel(context.Background()) | |
| defer cancel() | |
| i := distro.NewInstance(ctx, device) | |
| i.Start() | |
| i.WaitForLogMessage("initializing platform") | |
| // Make sure the shell is ready to accept commands over serial. | |
| i.WaitForLogMessage("console.shell: enabled") | |
| // Run dlog | |
| i.RunCommand("dlog") | |
| // Look for the same log message again. | |
| i.WaitForLogMessage("initializing platform") | |
| } | |
| func execDir(t *testing.T) string { | |
| ex, err := os.Executable() | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| return filepath.Dir(ex) | |
| } |