| // Copyright (C) 2016 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 device_test |
| |
| import ( |
| "testing" |
| |
| "android.googlesource.com/platform/tools/gpu/framework/assert" |
| "android.googlesource.com/platform/tools/gpu/framework/device" |
| ) |
| |
| var architectureTestData = []struct { |
| architecture device.Architecture |
| name string |
| bitness int |
| align int |
| pointerSize int |
| intSize int |
| endian device.Endian |
| }{ |
| {device.UnknownArchitecture, "unknown", 0, 0, 0, 0, device.LittleEndian}, |
| {device.ARMv7a, "ARMv7a", 32, 4, 4, 4, device.LittleEndian}, |
| {device.ARMv8a, "ARMv8a", 64, 8, 8, 8, device.LittleEndian}, |
| {device.X86, "X86", 32, 4, 4, 4, device.LittleEndian}, |
| {device.X86_64, "X86_64", 64, 8, 8, 8, device.LittleEndian}, |
| {device.MIPS, "MIPS", 32, 4, 4, 4, device.LittleEndian}, |
| {device.MIPS64, "MIPS64", 64, 8, 8, 8, device.LittleEndian}, |
| } |
| |
| func TestArchitecture(t *testing.T) { |
| ctx := assert.Context(t) |
| for _, test := range architectureTestData { |
| ctx := ctx.Enter(test.name) |
| a := test.architecture |
| m := a.MemoryLayout() |
| ctx = ctx.V("Architecture", a) |
| assert.For(ctx, "Architecture.Bitness()").That(a.Bitness()).Equals(test.bitness) |
| assert.For(ctx, "Architecture.MemoryLayout().PointerAlignment").That(m.PointerAlignment).Equals(test.align) |
| assert.For(ctx, "Architecture.MemoryLayout().PointerSize").That(m.PointerSize).Equals(test.pointerSize) |
| assert.For(ctx, "Architecture.MemoryLayout().IntegerSize").That(m.IntegerSize).Equals(test.intSize) |
| assert.For(ctx, "Architecture.MemoryLayout().Endian").That(m.Endian).Equals(test.endian) |
| } |
| } |
| |
| func TestArchitectureByName(t *testing.T) { |
| ctx := assert.Context(t) |
| for _, test := range architectureTestData { |
| ctx := ctx.Enter(test.name) |
| architecture := device.ArchitectureByName(test.name) |
| assert.With(ctx).That(architecture).Equals(test.architecture) |
| } |
| } |
| |
| func TestArchitectureGOARCH(t *testing.T) { |
| ctx := assert.Context(t) |
| for _, test := range []struct { |
| name string |
| architecture device.Architecture |
| }{ |
| {"invalid", device.UnknownArchitecture}, |
| {"386", device.X86}, |
| {"amd64", device.X86_64}, |
| {"arm", device.ARMv7a}, |
| } { |
| ctx := ctx.Enter(test.name) |
| architecture := device.ArchitectureByName(test.name) |
| assert.With(ctx).That(architecture).Equals(test.architecture) |
| } |
| } |