Commit Graph

47 Commits

Author SHA1 Message Date
Daniel Martí 6fedfaf3af cmd/gogio: start using testing.T.Cleanup
Now that we use tip due to breaking changes in Go's JS APIs, let's
replace our hacky cleanup list code with 1.14's upcoming
testing.T.Cleanup.

Adding more deliberate uses of tip would ususally be best avoided, but
these will only affect developers working on gio's tests, not regular
users of gio.

While at it, remove some debug t.Logf calls I forgot to remove.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-11-07 16:11:38 +01:00
Elias Naur e683b19b29 .builds: use Go 1.14 for the basic tests
WebAssembly builds require Go 1.14 since the breaking change in Go,
golang.org/cl/203600.

gofmt -w -s . as well.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-06 18:35:44 +01:00
Daniel Martí 6f860200b9 cmd/gogio: join all endtoend tests as subtests
This means we can deduplicate some of the logic, and keep it all in one
place.

Start expanding the logic too; the tests are slow, so they should be
skipped on 'go test -short'. The ones we have so far all run in a matter
of seconds on an average laptop today, but future tests will probably
require heavier work like wine or kvm.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-11-06 18:03:51 +01:00
Elias Naur 4719d56f86 .builds: fix go fmt test and go fmt -w -s .
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-05 12:50:07 +01:00
Daniel Martí 4d7c89fec3 cmd/gogio: simplify the test -race setup
In an earlier commit, we made it possible to run the e2e tests with the
race detector enabled everywhere via GOFLAGS=-race go test.

However, that's not at all standard; most users will simply use 'go test
-race'. Moreover, having 'go test -race' run the test program with the
race detector, but not the e2e gio app, is a bit useless.

Instead, have the tests detect when they run with the race detector, and
enable the race detector in the test app too. As before, the JS test is
skipped whenever -race is used.

This also means we can test with -race in the same way in each of the
modules, which simplifies CI.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-11-04 22:21:21 +01:00
Daniel Martí ec0c2498a1 cmd/gogio: fix a couple of staticcheck positives
Spotted the javac one by chance when reading the code, so I ran the tool
and fixed another small bug while at it.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-11-04 00:09:40 +01:00
Daniel Martí 2a4829d857 cmd/gogio: support running e2e with and without -race
Right now, we can only run the e2e gio app with -race, not without
-race, because the flag is hard-coded in the tests.

The reason for this change was that 'GOFLAGS=-race go test' would fail
with the JS test, since js/wasm doesn't support the race detector. Fix
that by skipping the JS test when -race is used.

Now, we can run multiple levels of -race:

	go test               # no -race at all
	go test -race         # -race for the tests, not the e2e gio app
	GOFLAGS=-race go test # -race for everything (best-effort)

To detect the race detector being on, we use a file with a build tag.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-11-03 13:05:06 +01:00
Elias Naur cc4b407647 .build,cmd: add -race to test programs
It's not possible to set GOFLAGS=-race because some programs are
built for webassembly where -race is not supported.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-03 12:09:02 +01:00
Daniel Martí 12ce899bb5 cmd/gogio: first wayland end-to-end tests
Clicking doesn't quite work yet, but everything else does. We use a
custom sway config to ensure that it's a minimalist setup with no bar or
borders, like the other drivers.

The generic test now adapts to the window's real size when running in
non-headless mode, since tiling window managers resize some drivers like
sway. The default headless mode still expects the exact size that we
specify, as no real windows are at play.

While at it, clean up some now unused code from the x11 file.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-11-02 18:12:46 +01:00
Daniel Martí 97d13922dd cmd/gogio: remove sleeps in x11 e2e test
We can instead synchronize with the gio app via stdout. We need three
states, since we need to first invalidate a frame and then print when
the next frame is drawn.

This is not happening on the JS test yet, because stdout printing
crashes in that case. See the comment.

This change should make the X11 test a bit faster on fast machines,
while making it more stable in small or headless machines like CI.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-11-02 15:00:37 +01:00
Daniel Martí b8e996074b cmd/gogio: rip out cgo deps for x11
Instead rely on more tiny standalone tools. In this case, scrot lets us
take png screenshots, and works well.

On the plus side, we remove some large X Go deps, and we don't need
nearly as much code.

While at it, skip if any of the tools are missing, and actually defer
the cleanup funcs so that they run when we fail the test early.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-11-02 01:19:19 +01:00
Daniel Martí 41402ce524 cmd/gogio: add clicks to the e2e tests
The test app now responds to mouse clicks; clicking on one of the four
sections of the app flips it to red color until clicked again.

Add a Click method to the TestDriver interface, and implement it in both
of the current drivers. Unfortunately, I failed at implementing it in
X11 with the xdg library, after a few wasted hours. Instead, start
relying on more external tools which are simple to use and not heavy to
install.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-11-01 22:24:26 +01:00
Greg Pomerantz af353822fa cmd/gogio: add permissions system for Android
Search for imports of the form gioui.org/app/permission/* and add
required permissions to AndroidManifest.xml.

Signed-off-by: Greg Pomerantz <gmp.gio@wow.st>
2019-11-01 18:58:13 +01:00
Greg Pomerantz 3cd633ee44 cmd/gogio: Android: include jar files from dependencies
On Android, in addition to adding jar files found in the source
directory of the program being compiled, cmd/gogio also searches
every dependency for jar files to include in the output APK.

Signed-off-by: Greg Pomerantz <gmp.gio@wow.st>
2019-11-01 17:59:49 +01:00
Daniel Martí 4e71f195ab cmd/gogio: start using layout.Flex in the e2e app
This vastly simplifies our code, and saves us the ugly math.

While at it, establish that a TestDriver must have a white background,
which is already satisfied by both existing implementations.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-10-31 21:06:34 +01:00
Elias Naur 3a341a3daf cmd/gogio: add -tags nowayland to avoid Wayland in the X11 end-to-end test
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-31 20:57:36 +01:00
Elias Naur f9a3d35184 cmd/gogio/testdate: gofmt -s -w
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-31 14:31:55 +01:00
Elias Naur 34bbf59efa cmd/gogio: double sleep to ensure X11 output is available
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-31 14:24:34 +01:00
Daniel Martí f20c0cc0a6 cmd/gogio: add four colors to the e2e tests
The e2e app now splits the window into four rectangles and paints them
differently.

The first advantage is that we now test that we see the entire Gio app.
Before, with a solid background color, we could be seeing a small part
of the window and we wouldn't tell the difference.

The second advantage is that we test more colors. In particular, the
fourth color includes a different alpha value, which renders the same on
JS and X11.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-10-31 14:06:05 +01:00
Daniel Martí b3d4da6229 cmd/gogio: start using a TestDriver e2e interface
Now we implement the "red background" end-to-end test exactly once.

While at it, start using a 800x600 window size, which is a bit more
realistic than 600x600, and will catch if we got either dimension wrong.

The interface only has two methods for now, but it will be expanded in
the future to also support input such as clicks.

Keeping state in the test driver, such as a context or a connection, is
a bit awkward but necessary so that we don't have to repeat arguments
over and over. The same applies to testing.T.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-10-30 23:10:49 +01:00
Daniel Martí d6f5902c5e cmd/gogio: send all e2e logs to t.Logf
chromedp was defaulting to log.Printf, which is not good for tests.

The xgb and xgbutil logs were suppressed if -v wasn't given, but they
were sent straight to os.Stderr otherwise:

	=== RUN   TestX11
	=== PAUSE TestX11
	=== CONT  TestX11
	XGB: conn.go:47: Could not get authority info: EOF
	XGB: conn.go:48: Trying connection without authority info...
	--- PASS: TestX11 (0.87s)

Instead, direct their loggers to an io.Writer implementation that sends
its output to t.Logf:

	=== RUN   TestX11
	=== PAUSE TestX11
	=== CONT  TestX11
	    TestX11: x11_test.go:187: XGB: conn.go:47: Could not get authority info: EOF
	    TestX11: x11_test.go:187: XGB: conn.go:48: Trying connection without authority info...
	--- PASS: TestX11 (0.86s)

We do end up with duplicate log prefixes, but at least we don't write
straight to stderr, which will be a problem as we add more concurrent
tests.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-10-30 17:30:58 +01:00
Elias Naur dc7af8fba3 cmd/gogio: use a more difficult color for end-to-end tests
RGB 0xff0000 is too easy to get right by accident.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-30 14:56:37 +01:00
Elias Naur d74be30a90 cmd/gogio: ignore alpha in end-to-end tests
On FreeBSD the X11 test seems to succeed except for the alpha
value:

	--- FAIL: TestX11 (2.04s)
	    js_test.go:138: got 0xffff000000000000 at (5,5), want 0xffff00000000ffff
	    js_test.go:138: got 0xffff000000000000 at (595,595), want 0xffff00000000ffff
	FAIL

Ignore alpha values for now.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-30 14:45:05 +01:00
Daniel Martí d31a129bf9 cmd/gogio: fix a couple of x11 e2e TODOs
First, pick a random display number between 1 and 100,000. The pool is
large enough that we don't need to think about collisions for now.

Second, wait for the X server to expose its socket for up to 1s, instead
of doing a single static sleep of 200ms. The average time we actually
need to sleep on my laptop is around 5ms, so this gives a noticeable
speed-up.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-10-30 00:35:47 +01:00
Daniel Martí cea8dc374b cmd/gogio: add the first end-to-end X11 test
Right now it's very similar to the JS test on Chrome. Like it, this one
just runs the "red.go" gio app, takes a screenshot, and expects to see
red.

It also supports the -headless flag; when true, Xvfb is used and it's
entirely headless and hidden. Otherwise, Xephyr is used and once can see
the test in action. If the tool isn't installed, the test is skipped.

We need to add xgb as a dependency, so that we can connect to the X
server and interact with it, like taking screenshots.

Finally, this is an initial version, and a number of TODOs are left for
a later time. They'll get fixed in follow-up patches.

While at it, start making all tests parallel, since the end-to-end tests
take about a second each and neither are very cpu-intensive.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-10-29 20:01:52 +01:00
Daniel Martí 95c47aba55 cmd/gogio: clarify the need for --use-gl=egl in the e2e tests
After some investigation, it turns out that both Alpine and Arch suffer
from the same bug - their packages completely lack SwiftShader.

The current workaround is still the best that we have right now. But at
least we can actually provide a good explanation why, and a TODO to
improve this once the issues filed with the distros are fixed.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-10-29 15:35:23 +01:00
Daniel Martí 4641607cd6 cmd/gogio: log chrome's console messages in TestJSOnChrome
For example, if the browser doesn't have webgl at all, the gio app will
fail to load. This will result in the screenshot being incorrect,
without an apparent reason:

	--- FAIL: TestJSOnChrome (0.89s)
	    js_test.go:122: got 0xffffffffffffffff at (5,5), want 0xffff00000000ffff
	    js_test.go:122: got 0xffffffffffffffff at (595,595), want 0xffff00000000ffff

The underlying webgl error was accessible if one added a sleep and ran
'go test -headless=false', allowing to open the console and see the
error messages.

Instead, capture them via chromedp and print them to the test's logger:

	--- FAIL: TestJSOnChrome (0.89s)
	    js_test.go:79: console log: "2019/10/29 12:41:07 app: webgl is not supported"
	    js_test.go:79: console warning: "exit code:", 1
	    js_test.go:122: got 0xffffffffffffffff at (5,5), want 0xffff00000000ffff
	    js_test.go:122: got 0xffffffffffffffff at (595,595), want 0xffff00000000ffff

JS Exceptions are a completely different mechanism, so they're not
covered by this patch. We can add them at a later time if needed.

While at it, update to the latest tagged version of chromedp.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-10-29 14:06:30 +01:00
Elias Naur a6e452d6d5 cmd/gogio: add -Werror to main.m build
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-28 18:24:27 +01:00
Elias Naur 439d3e652c app/internal: consolidate CFLAGS and move -Werror to #cgo directives
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-28 13:30:51 +01:00
Elias Naur 4a26bdad5d cmd/gogio: build for iOS/macOS without -fmodules and -fobjc-arc
The `gogio` tool adds the `-fmodules -fobjc-arc` flags to the Cgo
C flags. Unfortunately, that masks problems where Cgo packages
accidentally didn't have the flags in their #cgo directives such
as package log.

Move the flags so they're only explicitly mentioned when `gogio`
invokes the host compiler to build the `main.m` shim.

Fix package log to include the missing flags.

While we're here, silence OpenGL ES deprecation warnings on iOS, just
as we do for macOS. The warnings are normally not visible because
the gogio tool suppress output from the go tool.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-28 11:40:53 +01:00
Daniel Martí a0692d74af cmd/gogio: improve the UX of the e2e tests
First, add a headless boolean flag that defaults to true. That way, one
can run 'go test -headless=false' to, for example, see how Chrome runs
the webassembly endtoend test.

Second, skip the Chrome test if the browser isn't installed.

While at it, run 'gofmt -s' on the package.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-10-27 21:31:53 +01:00
Elias Naur 3de204b8ef cmd/gogio/testdata: update gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-27 15:42:18 +01:00
Greg Pomerantz 175144fa99 cmd/gogio: Android: include jar files from package directory
Look for *.jar files in package directory for inclusion in
Android .apk file.

Signed-off-by: Greg Pomerantz <gmp.gio@wow.st>
2019-10-18 16:45:43 +02:00
Elias Naur fc521ec1ff cmd/gogio: update gio version
The path of the supporting Android Java files and iOS header file
moved.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-14 16:43:21 +02:00
Elias Naur 651e31f7e0 cmd/gogio: update gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-12 15:42:47 +02:00
Elias Naur e4b1a46dd2 cmd/gogio: create a temporary signing key if debug.keystore isn't found
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-09 19:08:28 +02:00
Elias Naur 468731538e cmd/gogio: look for javac in JAVA_HOME if it is not in PATH
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-09 18:38:05 +02:00
Elias Naur b749c5dd28 cmd/gogio: fix Android toolchain path for Windows 64-bit
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-09 18:27:09 +02:00
Elias Naur e9db3801cc cmd/gogio: rename gio* files to main*
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-08 13:10:58 +02:00
Greg Pomerantz 81814e6fa4 cmd/gogio: add -minversion flag to specify minimum Android platform
Allow the user to specify a minimum supported Android platform
version.

Signed-off-by: Greg Pomerantz <gmp.gio@wow.st>
2019-10-07 17:00:24 +02:00
Elias Naur 3784ece6dd all: rename package ui to unit
Package ui is now only about units except for the Config.Now method.
Remove Now and rename Config to Converter. Add layout.Config to
replace the old ui.Config.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-30 16:55:47 +02:00
Elias Naur beaec661d2 op/paint: move paint package below the op package
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-30 16:55:47 +02:00
Elias Naur 8cf35a1f97 op: add package op for operations
Extract operation types from package ui into package op.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-30 16:55:47 +02:00
Elias Naur 3c65aa61f6 cmd/gogio,ui: fixups after gioui.org module rename
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-30 13:04:10 +02:00
Elias Naur 962bc36dac apps,cmd: update to renamed gioui.org module
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-30 12:41:29 +02:00
Daniel Martí 687ea833a3 cmd/gogio: add the first end-to-end test for js via chrome
This commit adds the first fully end-to-end test. It builds a very
simple Gio app, loads it on Chrome, and checks that it works.

To control Chrome, we use chromedp, a library in pure Go that takes care
of starting the browser and talking to it via the devtools protocol.

We add the test directly in the cmd module, since it mainly interacts
with the gogio tool, and also because the code might turn into some sort
of 'gogio test' command in the future. This does add chromedp and ui as
test dependencies to go.mod, but GOPROXY should allow a 'go get' of
gogio to not download their entire source code archives.

We don't replace ui with ../../ui in the go.mod, to ensure that testing
the cmd module works from anywhere without unintended differences.

The test app being used is inside a testdata directory, to ensure it's
not go-gettable, and that it doesn't otherwise affect the cmd module.

Finally, the test itself is pretty simple. The app just paints a red
background, and the test verifies that, once loaded, the background of
the browser viewport is indeed red.

The test does currently require Chrome or Chromium to be installed,
which is fine for now. It may also require a GPU, though I don't have a
headless machine to check for sure. The test uses Chrome in headless
mode though, so it doesn't open up any visible browser window.

All in all, the test succeeds in just over a second on my laptop with
Chromium 77.0.3865.75.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-09-23 21:23:31 +02:00
Elias Naur a12912c944 cmd/gogio: rename the gio too to gogio
The `gio` name clashes with a widely deployed GNOME tool.
Rename our tool to `gogio`, "the go tool for gio programs".

Fixes gio#20

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-09-18 22:46:47 +02:00