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/utils | |
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/utils')
-rw-r--r-- | integration/replay/utils/doc.go | 16 | ||||
-rw-r--r-- | integration/replay/utils/find_local_device.go | 43 | ||||
-rw-r--r-- | integration/replay/utils/in_memory_db.go | 91 | ||||
-rw-r--r-- | integration/replay/utils/store_capture.go | 61 |
4 files changed, 211 insertions, 0 deletions
diff --git a/integration/replay/utils/doc.go b/integration/replay/utils/doc.go new file mode 100644 index 000000000..f642ac12e --- /dev/null +++ b/integration/replay/utils/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 utils contains utilities for replay integration tests. +package utils diff --git a/integration/replay/utils/find_local_device.go b/integration/replay/utils/find_local_device.go new file mode 100644 index 000000000..7e0175e4d --- /dev/null +++ b/integration/replay/utils/find_local_device.go @@ -0,0 +1,43 @@ +// 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 utils + +import ( + "testing" + "time" + + "android.googlesource.com/platform/tools/gpu/replay" +) + +const findLocalDeviceAttempts = 5 +const msBetweenFindLocalDeviceAttempts = 500 +const localDeviceName = "Local machine" // TODO: Remove hard-coded string. + +// FindLocalDevice returns the replay Device for the local host. If the local +// host cannot be found then the test fails and nil is returned. +func FindLocalDevice(t *testing.T, mgr *replay.Manager) replay.Device { + for i := 0; i < findLocalDeviceAttempts; i++ { + for _, d := range mgr.Devices() { + info := d.Info() + t.Logf("Found device: '%s'", info.Name) + if info.Name == localDeviceName { + return d + } + } + time.Sleep(time.Millisecond * msBetweenFindLocalDeviceAttempts) + } + t.Fatalf("Local replay device not found") + return nil +} diff --git a/integration/replay/utils/in_memory_db.go b/integration/replay/utils/in_memory_db.go new file mode 100644 index 000000000..8a0cc5af2 --- /dev/null +++ b/integration/replay/utils/in_memory_db.go @@ -0,0 +1,91 @@ +// 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 utils + +import ( + "bytes" + "fmt" + + "android.googlesource.com/platform/tools/gpu/binary" + "android.googlesource.com/platform/tools/gpu/database" + "android.googlesource.com/platform/tools/gpu/database/store" + "android.googlesource.com/platform/tools/gpu/log" +) + +type inMemoryDatabase struct { + links map[binary.ID]binary.ID + entries map[binary.ID]binary.Object +} + +// NewInMemoryDatabase returns a partial implementation of Database, keeping +// all entries in-memory. +func NewInMemoryDatabase() database.Database { + return &inMemoryDatabase{ + links: make(map[binary.ID]binary.ID), + entries: make(map[binary.ID]binary.Object), + } +} + +func (d *inMemoryDatabase) StoreLink(to, id binary.ID, _ log.Logger) error { + d.links[id] = to + return nil +} + +func (d *inMemoryDatabase) StoreRequest(request binary.Object, _ log.Logger) (binary.ID, error) { + panic("StoreRequest() not supported by the inMemoryDatabase") + return binary.ID{}, nil +} + +func (d *inMemoryDatabase) Store(o binary.Object, _ log.Logger) (binary.ID, error) { + id := hash(o) + d.entries[id] = o + return id, nil +} + +func (d *inMemoryDatabase) Load(id binary.ID, l log.Logger, out binary.Object) error { + if link, found := d.links[id]; found { + return d.Load(link, l, out) + } + if entry, found := d.entries[id]; found { + store.CopyResource(out, entry) + return nil + } + return fmt.Errorf("Resource '%v' not found", id) +} + +func (d *inMemoryDatabase) Contains(id binary.ID, _ log.Logger) bool { + if _, found := d.links[id]; found { + return true + } + if _, found := d.entries[id]; found { + return true + } + return false +} + +func (d *inMemoryDatabase) Captures() (map[string]binary.ID, error) { + panic("Captures() not supported by the inMemoryDatabase") +} + +func (d *inMemoryDatabase) Close() {} + +func hash(o binary.Encodable) binary.ID { + b := bytes.Buffer{} + e := binary.NewEncoder(&b) + if err := o.Encode(e); err != nil { + panic(err) + } + return binary.NewID(b.Bytes()) +} diff --git a/integration/replay/utils/store_capture.go b/integration/replay/utils/store_capture.go new file mode 100644 index 000000000..4699eaee2 --- /dev/null +++ b/integration/replay/utils/store_capture.go @@ -0,0 +1,61 @@ +// 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 utils + +import ( + "testing" + + "android.googlesource.com/platform/tools/gpu/atom" + "android.googlesource.com/platform/tools/gpu/database" + "android.googlesource.com/platform/tools/gpu/gfxapi" + "android.googlesource.com/platform/tools/gpu/log" + "android.googlesource.com/platform/tools/gpu/service" +) + +func storeSchema(t *testing.T, api gfxapi.API, db database.Database, l log.Logger) service.SchemaId { + schema := api.Schema() + id, err := db.Store(&schema, l) + if err != nil { + t.Fatalf("Failed to store schema: %v", err) + } + return service.SchemaId{id} +} + +func storeAtoms(t *testing.T, atoms atom.List, api gfxapi.API, db database.Database, l log.Logger) service.AtomStreamId { + stream, err := service.NewAtomStream(atoms, storeSchema(t, api, db, l)) + if err != nil { + t.Fatalf("Failed to build atom stream: %v", err) + } + id, err := db.Store(&stream, l) + if err != nil { + t.Fatalf("Failed to store atom stream: %v", err) + } + return service.AtomStreamId{id} +} + +// StoreCapture encodes and writes the atom list to the database, returning an +// identifier to the newly constructed and stored Capture. +func StoreCapture(t *testing.T, atoms atom.List, api gfxapi.API, db database.Database, l log.Logger) service.CaptureId { + capture := service.Capture{ + Name: "test-capture", + API: api.Name(), + Atoms: storeAtoms(t, atoms, api, db, l), + } + id, err := db.Store(&capture, l) + if err != nil { + t.Fatalf("Failed to store test capture: %v", err) + } + return service.CaptureId{id} +} |