• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Dawn Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "tests/DawnTest.h"
16 
17 #include "utils/WGPUHelpers.h"
18 
19 class BasicTests : public DawnTest {};
20 
21 // Test adapter filter by vendor id.
TEST_P(BasicTests,VendorIdFilter)22 TEST_P(BasicTests, VendorIdFilter) {
23     DAWN_TEST_UNSUPPORTED_IF(!HasVendorIdFilter());
24 
25     ASSERT_EQ(GetAdapterProperties().vendorID, GetVendorIdFilter());
26 }
27 
28 // Test adapter filter by backend type.
TEST_P(BasicTests,BackendType)29 TEST_P(BasicTests, BackendType) {
30     DAWN_TEST_UNSUPPORTED_IF(!HasBackendTypeFilter());
31 
32     ASSERT_EQ(GetAdapterProperties().backendType, GetBackendTypeFilter());
33 }
34 
35 // Test Queue::WriteBuffer changes the content of the buffer, but really this is the most
36 // basic test possible, and tests the test harness
TEST_P(BasicTests,QueueWriteBuffer)37 TEST_P(BasicTests, QueueWriteBuffer) {
38     wgpu::BufferDescriptor descriptor;
39     descriptor.size = 4;
40     descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
41     wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
42 
43     uint32_t value = 0x01020304;
44     queue.WriteBuffer(buffer, 0, &value, sizeof(value));
45 
46     EXPECT_BUFFER_U32_EQ(value, buffer, 0);
47 }
48 
49 // Test a validation error for Queue::WriteBuffer but really this is the most basic test possible
50 // for ASSERT_DEVICE_ERROR
TEST_P(BasicTests,QueueWriteBufferError)51 TEST_P(BasicTests, QueueWriteBufferError) {
52     wgpu::BufferDescriptor descriptor;
53     descriptor.size = 4;
54     descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
55     wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
56 
57     uint8_t value = 187;
58     ASSERT_DEVICE_ERROR(queue.WriteBuffer(buffer, 1000, &value, sizeof(value)));
59 }
60 
61 DAWN_INSTANTIATE_TEST(BasicTests,
62                       D3D12Backend(),
63                       MetalBackend(),
64                       OpenGLBackend(),
65                       OpenGLESBackend(),
66                       VulkanBackend());
67