diff options
author | Ben Clayton <bclayton@google.com> | 2015-03-02 16:30:01 +0000 |
---|---|---|
committer | Ben Clayton <bclayton@google.com> | 2015-03-03 13:36:31 +0000 |
commit | 9b5e9bb39b00a3c4e583597c6017bc83e95d2fc0 (patch) | |
tree | fde44a56ea6d4d4c3091b935f57753e63eea633e /integration/replay/gles | |
parent | 733d7d53983927c6d001e98ba73249bf6dc5411b (diff) | |
download | gpu-9b5e9bb39b00a3c4e583597c6017bc83e95d2fc0.tar.gz |
Add gles integration tests.
Improve error handling and reporting based on these tests.
Change-Id: I108dac34c5b41e3dd5aa73143443e76b5ddd9b8e
Diffstat (limited to 'integration/replay/gles')
-rw-r--r-- | integration/replay/gles/doc.go | 16 | ||||
-rw-r--r-- | integration/replay/gles/gles_test.go | 90 | ||||
-rw-r--r-- | integration/replay/gles/image.go | 70 | ||||
-rw-r--r-- | integration/replay/gles/reference/solid-blue.png | bin | 0 -> 158 bytes | |||
-rw-r--r-- | integration/replay/gles/reference/solid-green.png | bin | 0 -> 157 bytes | |||
-rw-r--r-- | integration/replay/gles/reference/solid-red.png | bin | 0 -> 157 bytes | |||
-rw-r--r-- | integration/replay/gles/reference/transparent.png | bin | 0 -> 148 bytes |
7 files changed, 176 insertions, 0 deletions
diff --git a/integration/replay/gles/doc.go b/integration/replay/gles/doc.go new file mode 100644 index 000000000..7696ce2b1 --- /dev/null +++ b/integration/replay/gles/doc.go @@ -0,0 +1,16 @@ +// Copyright (C) 2015 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package gles contains the OpenGL ES integration tests with the replay system. +package gles diff --git a/integration/replay/gles/gles_test.go b/integration/replay/gles/gles_test.go new file mode 100644 index 000000000..3599ec565 --- /dev/null +++ b/integration/replay/gles/gles_test.go @@ -0,0 +1,90 @@ +// Copyright (C) 2015 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package gles + +import ( + "flag" + "image" + "testing" + "time" + + "android.googlesource.com/platform/tools/gpu/atom" + "android.googlesource.com/platform/tools/gpu/gfxapi/gles" + "android.googlesource.com/platform/tools/gpu/integration/replay/utils" + "android.googlesource.com/platform/tools/gpu/log" + "android.googlesource.com/platform/tools/gpu/replay" +) + +const replayTimeout = time.Second * 3 + +var generateReferenceImages = flag.Bool("generate", false, "generate reference images") + +func checkColorBuffer(t *testing.T, ctx *replay.Context, mgr *replay.Manager, after atom.ID, w, h uint32, name string, threshold float64) { + select { + case img := <-gles.API().ColorBuffer(ctx, mgr, after, w, h, false): + if img.Error != nil { + t.Errorf("Failed to read ColorBuffer at %d for %s. Reason: %v", after, name, img.Error) + return + } + got := &image.NRGBA{ + Pix: img.Data, + Rect: image.Rect(0, 0, int(w), int(h)), + } + if *generateReferenceImages { + storeReferenceImage(t, name, got) + } else { + expected := loadReferenceImage(t, name) + err := compareImages(t, expected, got) + if err > threshold { + t.Errorf("%v had error of %v%% which is above the threshold of %v%%", name, err*100, threshold*100) + } + } + case <-time.Tick(replayTimeout): + t.Errorf("Timeout reading ColorBuffer at %d for %s", after, name) + } +} + +func TestClear(t *testing.T) { + db, logger := utils.NewInMemoryDatabase(), log.Testing(t) + w, h := uint32(64), uint32(64) + atoms := atom.List{ + /* 0 */ gles.NewInit(int32(w), int32(h), + gles.RenderbufferFormat_GL_RGB565, // Unused + gles.RenderbufferFormat_GL_DEPTH_COMPONENT16, // Unused + gles.RenderbufferFormat_GL_STENCIL_INDEX8, // Unused + ), + /* 1 */ gles.NewGlClearColor(1.0, 0.0, 0.0, 0.0), + /* 2 */ gles.NewGlClear(gles.ClearMask_GL_COLOR_BUFFER_BIT), + /* 3 */ gles.NewGlClearColor(0.0, 1.0, 0.0, 0.0), + /* 4 */ gles.NewGlClear(gles.ClearMask_GL_COLOR_BUFFER_BIT), + /* 5 */ gles.NewGlClearColor(0.0, 0.0, 1.0, 0.0), + /* 6 */ gles.NewGlClear(gles.ClearMask_GL_COLOR_BUFFER_BIT), + /* 7 */ gles.NewGlClearColor(0.0, 0.0, 0.0, 1.0), + /* 8 */ gles.NewGlClear(gles.ClearMask_GL_COLOR_BUFFER_BIT), + } + + mgr := replay.New(db, logger) + device := utils.FindLocalDevice(t, mgr) + + ctx := &replay.Context{ + CaptureID: utils.StoreCapture(t, atoms, gles.API(), db, logger), + DeviceID: device.ID(), + } + + checkColorBuffer(t, ctx, mgr, 2, w, h, "solid-red", 0) + checkColorBuffer(t, ctx, mgr, 4, w, h, "solid-green", 0) + checkColorBuffer(t, ctx, mgr, 6, w, h, "solid-blue", 0) + checkColorBuffer(t, ctx, mgr, 8, w, h, "transparent", 0) +} diff --git a/integration/replay/gles/image.go b/integration/replay/gles/image.go new file mode 100644 index 000000000..87ed173fb --- /dev/null +++ b/integration/replay/gles/image.go @@ -0,0 +1,70 @@ +package gles + +import ( + "bytes" + "image" + "image/png" + "io/ioutil" + "path/filepath" + "testing" +) + +const referenceImageDir = "reference" + +// storeReferenceImage replaces the reference image with img. +func storeReferenceImage(t *testing.T, name string, img image.Image) { + data := &bytes.Buffer{} + if err := png.Encode(data, img); err != nil { + t.Errorf("Failed to encode reference image %s: %v", name, err) + return + } + path := filepath.Join(referenceImageDir, name+".png") + err := ioutil.WriteFile(path, data.Bytes(), 0666) + if err != nil { + t.Errorf("Failed to store reference image %s: %v", name, err) + } +} + +// loadReferenceImage loads the reference image with the specified name. +func loadReferenceImage(t *testing.T, name string) image.Image { + path := filepath.Join(referenceImageDir, name+".png") + data, err := ioutil.ReadFile(path) + if err != nil { + t.Errorf("Failed to load reference image %s: %v", name, err) + return nil + } + img, err := png.Decode(bytes.NewBuffer(data)) + if err != nil { + t.Errorf("Failed to decode reference image %s: %v", name, err) + return nil + } + return img +} + +func sqr(f float64) float64 { return f * f } + +// compareImages returns the normalized square error between the two images. +// A return value of 0 denotes identical images, a return value of 1 denotes +// a complete mismatch (black vs white). +func compareImages(t *testing.T, expected, got image.Image) float64 { + s := expected.Bounds().Size() + if s != got.Bounds().Size() { + t.Errorf("Image dimensions are not as expected. Expected: %v, Got: %v", s, got.Bounds().Size()) + return 1 + } + + sqrErr := float64(0) + for y := 0; y < s.Y; y++ { + for x := 0; x < s.X; x++ { + e := expected.At(x, y) + g := got.At(x, y) + er, eg, eb, ea := e.RGBA() + gr, gg, gb, ga := g.RGBA() + sqrErr += sqr((float64(er) - float64(gr)) / 0xffff) + sqrErr += sqr((float64(eg) - float64(gg)) / 0xffff) + sqrErr += sqr((float64(eb) - float64(gb)) / 0xffff) + sqrErr += sqr((float64(ea) - float64(ga)) / 0xffff) + } + } + return sqrErr / float64(4*s.Y*s.X) +} diff --git a/integration/replay/gles/reference/solid-blue.png b/integration/replay/gles/reference/solid-blue.png Binary files differnew file mode 100644 index 000000000..0f4ee3434 --- /dev/null +++ b/integration/replay/gles/reference/solid-blue.png diff --git a/integration/replay/gles/reference/solid-green.png b/integration/replay/gles/reference/solid-green.png Binary files differnew file mode 100644 index 000000000..a2523c615 --- /dev/null +++ b/integration/replay/gles/reference/solid-green.png diff --git a/integration/replay/gles/reference/solid-red.png b/integration/replay/gles/reference/solid-red.png Binary files differnew file mode 100644 index 000000000..99fa0ddbd --- /dev/null +++ b/integration/replay/gles/reference/solid-red.png diff --git a/integration/replay/gles/reference/transparent.png b/integration/replay/gles/reference/transparent.png Binary files differnew file mode 100644 index 000000000..eb3a92e5e --- /dev/null +++ b/integration/replay/gles/reference/transparent.png |