From b1084c13620053af86a727e6a7b85a3f45a4f935 Mon Sep 17 00:00:00 2001 From: Achilleas Anagnostopoulos Date: Sat, 8 Jul 2017 13:02:15 +0100 Subject: [PATCH] Fix broken unit tests --- src/gopheros/device/tty/vt.go | 10 +++++---- src/gopheros/device/tty/vt_test.go | 17 -------------- src/gopheros/device/video/console/vga_text.go | 22 ++++++++++--------- .../device/video/console/vga_text_test.go | 17 -------------- 4 files changed, 18 insertions(+), 48 deletions(-) diff --git a/src/gopheros/device/tty/vt.go b/src/gopheros/device/tty/vt.go index 4dda34c..ba48be0 100644 --- a/src/gopheros/device/tty/vt.go +++ b/src/gopheros/device/tty/vt.go @@ -260,8 +260,10 @@ func (t *VT) DriverVersion() (uint16, uint16, uint16) { // DriverInit initializes this driver. func (t *VT) DriverInit() *kernel.Error { return nil } -func init() { - ProbeFuncs = append(ProbeFuncs, func() device.Driver { - return NewVT(DefaultTabWidth, DefaultScrollback) - }) +func probeForVT() device.Driver { + return NewVT(DefaultTabWidth, DefaultScrollback) +} + +func init() { + ProbeFuncs = append(ProbeFuncs, probeForVT) } diff --git a/src/gopheros/device/tty/vt_test.go b/src/gopheros/device/tty/vt_test.go index 8d4592d..b1bf40f 100644 --- a/src/gopheros/device/tty/vt_test.go +++ b/src/gopheros/device/tty/vt_test.go @@ -5,7 +5,6 @@ import ( "gopheros/device/video/console" "image/color" "io" - "reflect" "testing" ) @@ -339,22 +338,6 @@ func TestVTDriverInterface(t *testing.T) { } func TestVTProbe(t *testing.T) { - var ( - expProbePtr = reflect.ValueOf(probeForVT).Pointer() - foundProbe bool - ) - - for _, probeFn := range HWProbes() { - if reflect.ValueOf(probeFn).Pointer() == expProbePtr { - foundProbe = true - break - } - } - - if !foundProbe { - t.Fatal("expected probeForVT to be part of the probes returned by HWProbes") - } - if drv := probeForVT(); drv == nil { t.Fatal("expected probeForVT to return a driver") } diff --git a/src/gopheros/device/video/console/vga_text.go b/src/gopheros/device/video/console/vga_text.go index fffa4ec..d30291d 100644 --- a/src/gopheros/device/video/console/vga_text.go +++ b/src/gopheros/device/video/console/vga_text.go @@ -199,15 +199,17 @@ func (cons *VgaTextConsole) DriverVersion() (uint16, uint16, uint16) { // DriverInit initializes this driver. func (cons *VgaTextConsole) DriverInit() *kernel.Error { return nil } -func init() { - ProbeFuncs = append(ProbeFuncs, func() device.Driver { - var drv device.Driver +// probeForVgaTextConsole checks for the presence of a vga text console. +func probeForVgaTextConsole() device.Driver { + var drv device.Driver + fbInfo := getFramebufferInfoFn() + if fbInfo.Type == multiboot.FramebufferTypeEGA { + drv = NewVgaTextConsole(fbInfo.Width, fbInfo.Height, uintptr(fbInfo.PhysAddr)) + } - fbInfo := getFramebufferInfoFn() - if fbInfo.Type == multiboot.FramebufferTypeEGA { - drv = NewVgaTextConsole(fbInfo.Width, fbInfo.Height, uintptr(fbInfo.PhysAddr)) - } - - return drv - }) + return drv +} + +func init() { + ProbeFuncs = append(ProbeFuncs, probeForVgaTextConsole) } diff --git a/src/gopheros/device/video/console/vga_text_test.go b/src/gopheros/device/video/console/vga_text_test.go index 2d76e69..0c81441 100644 --- a/src/gopheros/device/video/console/vga_text_test.go +++ b/src/gopheros/device/video/console/vga_text_test.go @@ -5,7 +5,6 @@ import ( "gopheros/kernel/cpu" "gopheros/kernel/hal/multiboot" "image/color" - "reflect" "testing" "unsafe" ) @@ -330,22 +329,6 @@ func TestVgaTextProbe(t *testing.T) { getFramebufferInfoFn = multiboot.GetFramebufferInfo }() - var ( - expProbePtr = reflect.ValueOf(probeForVgaTextConsole).Pointer() - foundProbe bool - ) - - for _, probeFn := range HWProbes() { - if reflect.ValueOf(probeFn).Pointer() == expProbePtr { - foundProbe = true - break - } - } - - if !foundProbe { - t.Fatal("expected probeForVgaTextConsole to be part of the probes returned by HWProbes") - } - getFramebufferInfoFn = func() *multiboot.FramebufferInfo { return &multiboot.FramebufferInfo{ Width: 80,