mirror of https://github.com/liamg/aminal.git
Solve intermittent build errors
This commit is contained in:
parent
4710948cd1
commit
b3cf187c01
34
gui/gui.go
34
gui/gui.go
|
@ -67,6 +67,7 @@ type GUI struct {
|
||||||
selectionRegionMode buffer.SelectionRegionMode
|
selectionRegionMode buffer.SelectionRegionMode
|
||||||
|
|
||||||
mainThreadFunc chan func()
|
mainThreadFunc chan func()
|
||||||
|
wakerEnded chan bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func Min(x, y int) int {
|
func Min(x, y int) int {
|
||||||
|
@ -412,16 +413,6 @@ func (gui *GUI) Render() error {
|
||||||
gl.Disable(gl.DEPTH_TEST)
|
gl.Disable(gl.DEPTH_TEST)
|
||||||
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
|
gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
|
||||||
|
|
||||||
ticker := time.NewTicker(time.Second)
|
|
||||||
defer ticker.Stop()
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
<-ticker.C
|
|
||||||
gui.logger.Sync()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
gui.terminal.SetProgram(program)
|
gui.terminal.SetProgram(program)
|
||||||
|
|
||||||
latestVersion := ""
|
latestVersion := ""
|
||||||
|
@ -502,9 +493,13 @@ Buffer Size: %d lines
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close(stop) // Tell waker to end.
|
gui.logger.Debug("Stopping render...")
|
||||||
|
|
||||||
|
close(stop) // Tell waker to end...
|
||||||
|
<-gui.wakerEnded // ...and wait it to end
|
||||||
|
|
||||||
|
gui.logger.Debug("Render stopped")
|
||||||
|
|
||||||
gui.logger.Debugf("Stopping render...")
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -514,9 +509,11 @@ Buffer Size: %d lines
|
||||||
// redrawn. Limiting is applied on wakeups to avoid excessive CPU
|
// redrawn. Limiting is applied on wakeups to avoid excessive CPU
|
||||||
// usage when the terminal is being updated rapidly.
|
// usage when the terminal is being updated rapidly.
|
||||||
func (gui *GUI) waker(stop <-chan struct{}) {
|
func (gui *GUI) waker(stop <-chan struct{}) {
|
||||||
|
gui.wakerEnded = make(chan bool)
|
||||||
dirty := gui.terminal.Dirty()
|
dirty := gui.terminal.Dirty()
|
||||||
var nextWake <-chan time.Time
|
var nextWake <-chan time.Time
|
||||||
var last time.Time
|
var last time.Time
|
||||||
|
forLoop:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-dirty:
|
case <-dirty:
|
||||||
|
@ -540,9 +537,10 @@ func (gui *GUI) waker(stop <-chan struct{}) {
|
||||||
glfw.PostEmptyEvent()
|
glfw.PostEmptyEvent()
|
||||||
nextWake = nil
|
nextWake = nil
|
||||||
case <-stop:
|
case <-stop:
|
||||||
return
|
break forLoop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
gui.wakerEnded <- true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *GUI) renderTerminalData(shouldLock bool) {
|
func (gui *GUI) renderTerminalData(shouldLock bool) {
|
||||||
|
@ -819,9 +817,15 @@ func (gui *GUI) Screenshot(path string) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
file, _ := os.Create(path)
|
file, err := os.Create(path)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
png.Encode(file, img)
|
err = png.Encode(file, img)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *GUI) windowPosChangeCallback(w *glfw.Window, xpos int, ypos int) {
|
func (gui *GUI) windowPosChangeCallback(w *glfw.Window, xpos int, ypos int) {
|
||||||
|
|
15
main.go
15
main.go
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/liamg/aminal/platform"
|
"github.com/liamg/aminal/platform"
|
||||||
"github.com/liamg/aminal/terminal"
|
"github.com/liamg/aminal/terminal"
|
||||||
"github.com/riywo/loginshell"
|
"github.com/riywo/loginshell"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type callback func(terminal *terminal.Terminal, g *gui.GUI)
|
type callback func(terminal *terminal.Terminal, g *gui.GUI)
|
||||||
|
@ -32,7 +33,17 @@ func initialize(unitTestfunc callback, configOverride *config.Config) {
|
||||||
fmt.Printf("Failed to create logger: %s\n", err)
|
fmt.Printf("Failed to create logger: %s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
defer logger.Sync()
|
ticker := time.NewTicker(time.Second)
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
<-ticker.C
|
||||||
|
logger.Sync()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
defer func() {
|
||||||
|
ticker.Stop()
|
||||||
|
logger.Sync()
|
||||||
|
}()
|
||||||
|
|
||||||
if conf.CPUProfile != "" {
|
if conf.CPUProfile != "" {
|
||||||
logger.Infof("Starting CPU profiling...")
|
logger.Infof("Starting CPU profiling...")
|
||||||
|
@ -61,7 +72,7 @@ func initialize(unitTestfunc callback, configOverride *config.Config) {
|
||||||
guestProcess, err := pty.CreateGuestProcess(shellStr)
|
guestProcess, err := pty.CreateGuestProcess(shellStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
pty.Close()
|
pty.Close()
|
||||||
logger.Fatalf("Failed to start your shell: %s", err)
|
logger.Fatalf("Failed to start your shell \"%s\": %s", shellStr, err)
|
||||||
}
|
}
|
||||||
defer guestProcess.Close()
|
defer guestProcess.Close()
|
||||||
|
|
||||||
|
|
102
main_test.go
102
main_test.go
|
@ -5,17 +5,15 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/carlogit/phash"
|
||||||
|
"github.com/liamg/aminal/config"
|
||||||
|
"github.com/liamg/aminal/gui"
|
||||||
|
"github.com/liamg/aminal/terminal"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/liamg/aminal/config"
|
|
||||||
"github.com/liamg/aminal/gui"
|
|
||||||
"github.com/liamg/aminal/terminal"
|
|
||||||
|
|
||||||
"github.com/carlogit/phash"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var termRef *terminal.Terminal
|
var termRef *terminal.Terminal
|
||||||
|
@ -47,10 +45,14 @@ func hash(path string) string {
|
||||||
return imageHash
|
return imageHash
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func imagesAreEqual(expected string, actual string) int {
|
||||||
|
expectedHash := hash(expected)
|
||||||
|
actualHash := hash(actual)
|
||||||
|
return phash.GetDistance(expectedHash, actualHash)
|
||||||
|
}
|
||||||
|
|
||||||
func compareImages(expected string, actual string) {
|
func compareImages(expected string, actual string) {
|
||||||
template := hash(expected)
|
distance := imagesAreEqual(expected, actual)
|
||||||
screen := hash(actual)
|
|
||||||
distance := phash.GetDistance(template, screen)
|
|
||||||
if distance != 0 {
|
if distance != 0 {
|
||||||
os.Exit(terminate(fmt.Sprintf("Screenshot \"%s\" doesn't match expected image \"%s\". Distance of hashes difference: %d\n",
|
os.Exit(terminate(fmt.Sprintf("Screenshot \"%s\" doesn't match expected image \"%s\". Distance of hashes difference: %d\n",
|
||||||
actual, expected, distance)))
|
actual, expected, distance)))
|
||||||
|
@ -58,19 +60,48 @@ func compareImages(expected string, actual string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func send(terminal *terminal.Terminal, cmd string) {
|
func send(terminal *terminal.Terminal, cmd string) {
|
||||||
terminal.Write([]byte(cmd))
|
err := terminal.Write([]byte(cmd))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func enter(terminal *terminal.Terminal) {
|
func enter(terminal *terminal.Terminal) {
|
||||||
terminal.Write([]byte("\n"))
|
err := terminal.Write([]byte("\n"))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateScreen(img string) {
|
func validateScreen(img string, waitForChange bool) {
|
||||||
|
fmt.Printf("taking screenshot: %s and comparing...", img)
|
||||||
|
|
||||||
guiRef.Screenshot(img)
|
guiRef.Screenshot(img)
|
||||||
compareImages(strings.Join([]string{"vttest/", img}, ""), img)
|
compareImages(strings.Join([]string{"vttest/", img}, ""), img)
|
||||||
|
|
||||||
|
fmt.Printf("compare OK\n")
|
||||||
|
|
||||||
enter(termRef)
|
enter(termRef)
|
||||||
|
|
||||||
|
if waitForChange {
|
||||||
|
fmt.Print("Waiting for screen change...")
|
||||||
|
attempts := 10
|
||||||
|
for {
|
||||||
sleep()
|
sleep()
|
||||||
|
actualScren := "temp.png"
|
||||||
|
guiRef.Screenshot(actualScren)
|
||||||
|
distance := imagesAreEqual(actualScren, img)
|
||||||
|
if distance != 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
fmt.Printf(" %d", attempts)
|
||||||
|
attempts--
|
||||||
|
if attempts <= 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Print("done\n")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
@ -115,12 +146,12 @@ func TestCursorMovement(t *testing.T) {
|
||||||
os.Exit(terminate(fmt.Sprintf("ActiveBuffer doesn't match vttest template vttest/test-cursor-movement-1")))
|
os.Exit(terminate(fmt.Sprintf("ActiveBuffer doesn't match vttest template vttest/test-cursor-movement-1")))
|
||||||
}
|
}
|
||||||
|
|
||||||
validateScreen("test-cursor-movement-1.png")
|
validateScreen("test-cursor-movement-1.png", true)
|
||||||
validateScreen("test-cursor-movement-2.png")
|
validateScreen("test-cursor-movement-2.png", true)
|
||||||
validateScreen("test-cursor-movement-3.png")
|
validateScreen("test-cursor-movement-3.png", true)
|
||||||
validateScreen("test-cursor-movement-4.png")
|
validateScreen("test-cursor-movement-4.png", true)
|
||||||
validateScreen("test-cursor-movement-5.png")
|
validateScreen("test-cursor-movement-5.png", true)
|
||||||
validateScreen("test-cursor-movement-6.png")
|
validateScreen("test-cursor-movement-6.png", false)
|
||||||
|
|
||||||
g.Close()
|
g.Close()
|
||||||
}
|
}
|
||||||
|
@ -142,21 +173,21 @@ func TestScreenFeatures(t *testing.T) {
|
||||||
send(term, "2\n")
|
send(term, "2\n")
|
||||||
sleep()
|
sleep()
|
||||||
|
|
||||||
validateScreen("test-screen-features-1.png")
|
validateScreen("test-screen-features-1.png", true)
|
||||||
validateScreen("test-screen-features-2.png")
|
validateScreen("test-screen-features-2.png", true)
|
||||||
validateScreen("test-screen-features-3.png")
|
validateScreen("test-screen-features-3.png", true)
|
||||||
validateScreen("test-screen-features-4.png")
|
validateScreen("test-screen-features-4.png", true)
|
||||||
validateScreen("test-screen-features-5.png")
|
validateScreen("test-screen-features-5.png", true)
|
||||||
validateScreen("test-screen-features-6.png")
|
validateScreen("test-screen-features-6.png", true)
|
||||||
validateScreen("test-screen-features-7.png")
|
validateScreen("test-screen-features-7.png", true)
|
||||||
validateScreen("test-screen-features-8.png")
|
validateScreen("test-screen-features-8.png", true)
|
||||||
validateScreen("test-screen-features-9.png")
|
validateScreen("test-screen-features-9.png", true)
|
||||||
validateScreen("test-screen-features-10.png")
|
validateScreen("test-screen-features-10.png", true)
|
||||||
validateScreen("test-screen-features-11.png")
|
validateScreen("test-screen-features-11.png", true)
|
||||||
validateScreen("test-screen-features-12.png")
|
validateScreen("test-screen-features-12.png", true)
|
||||||
validateScreen("test-screen-features-13.png")
|
validateScreen("test-screen-features-13.png", true)
|
||||||
validateScreen("test-screen-features-14.png")
|
validateScreen("test-screen-features-14.png", true)
|
||||||
validateScreen("test-screen-features-15.png")
|
validateScreen("test-screen-features-15.png", false)
|
||||||
|
|
||||||
g.Close()
|
g.Close()
|
||||||
}
|
}
|
||||||
|
@ -178,10 +209,9 @@ func TestSixel(t *testing.T) {
|
||||||
send(term, "clear\n")
|
send(term, "clear\n")
|
||||||
sleep()
|
sleep()
|
||||||
send(term, "cat example.sixel\n")
|
send(term, "cat example.sixel\n")
|
||||||
sleep(4)
|
sleep(10) // Displaying SIXEL graphics *sometimes* takes long time. Excessive synchronization???
|
||||||
|
|
||||||
guiRef.Screenshot("test-sixel.png")
|
validateScreen("test-sixel.png", false)
|
||||||
validateScreen("test-sixel.png")
|
|
||||||
|
|
||||||
g.Close()
|
g.Close()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue