• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Amber 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 parseried.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "gtest/gtest.h"
16 #include "src/amberscript/parser.h"
17 
18 namespace amber {
19 namespace amberscript {
20 
21 using AmberScriptParserTest = testing::Test;
22 
TEST_F(AmberScriptParserTest,DeviceFeature)23 TEST_F(AmberScriptParserTest, DeviceFeature) {
24   std::string in = R"(
25 DEVICE_FEATURE vertexPipelineStoresAndAtomics
26 DEVICE_FEATURE VariablePointerFeatures.variablePointersStorageBuffer
27 DEVICE_FEATURE Float16Int8Features.shaderFloat16
28 DEVICE_FEATURE Float16Int8Features.shaderInt8
29 DEVICE_FEATURE Storage8BitFeatures.storageBuffer8BitAccess
30 DEVICE_FEATURE Storage8BitFeatures.uniformAndStorageBuffer8BitAccess
31 DEVICE_FEATURE Storage8BitFeatures.storagePushConstant8
32 DEVICE_FEATURE Storage16BitFeatures.storageBuffer16BitAccess
33 DEVICE_FEATURE Storage16BitFeatures.uniformAndStorageBuffer16BitAccess
34 DEVICE_FEATURE Storage16BitFeatures.storagePushConstant16
35 DEVICE_FEATURE Storage16BitFeatures.storageInputOutput16
36 DEVICE_FEATURE SubgroupSizeControl.subgroupSizeControl
37 DEVICE_FEATURE SubgroupSizeControl.computeFullSubgroups)";
38 
39   Parser parser;
40   Result r = parser.Parse(in);
41   ASSERT_TRUE(r.IsSuccess()) << r.Error();
42 
43   auto script = parser.GetScript();
44   const auto& features = script->GetRequiredFeatures();
45   ASSERT_EQ(13U, features.size());
46   EXPECT_EQ("vertexPipelineStoresAndAtomics", features[0]);
47   EXPECT_EQ("VariablePointerFeatures.variablePointersStorageBuffer",
48             features[1]);
49   EXPECT_EQ("Float16Int8Features.shaderFloat16", features[2]);
50   EXPECT_EQ("Float16Int8Features.shaderInt8", features[3]);
51   EXPECT_EQ("Storage8BitFeatures.storageBuffer8BitAccess", features[4]);
52   EXPECT_EQ("Storage8BitFeatures.uniformAndStorageBuffer8BitAccess",
53             features[5]);
54   EXPECT_EQ("Storage8BitFeatures.storagePushConstant8", features[6]);
55   EXPECT_EQ("Storage16BitFeatures.storageBuffer16BitAccess", features[7]);
56   EXPECT_EQ("Storage16BitFeatures.uniformAndStorageBuffer16BitAccess",
57             features[8]);
58   EXPECT_EQ("Storage16BitFeatures.storagePushConstant16", features[9]);
59   EXPECT_EQ("Storage16BitFeatures.storageInputOutput16", features[10]);
60   EXPECT_EQ("SubgroupSizeControl.subgroupSizeControl", features[11]);
61   EXPECT_EQ("SubgroupSizeControl.computeFullSubgroups", features[12]);
62 }
63 
TEST_F(AmberScriptParserTest,DeviceFeatureMissingFeature)64 TEST_F(AmberScriptParserTest, DeviceFeatureMissingFeature) {
65   std::string in = "DEVICE_FEATURE";
66 
67   Parser parser;
68   Result r = parser.Parse(in);
69   ASSERT_FALSE(r.IsSuccess());
70   EXPECT_EQ("1: missing feature name for DEVICE_FEATURE command", r.Error());
71 }
72 
TEST_F(AmberScriptParserTest,DeviceFeatureUnknown)73 TEST_F(AmberScriptParserTest, DeviceFeatureUnknown) {
74   std::string in = "DEVICE_FEATURE unknown";
75 
76   Parser parser;
77   Result r = parser.Parse(in);
78   ASSERT_FALSE(r.IsSuccess());
79   EXPECT_EQ("1: unknown feature name for DEVICE_FEATURE command", r.Error());
80 }
81 
TEST_F(AmberScriptParserTest,DeviceFeatureInvalid)82 TEST_F(AmberScriptParserTest, DeviceFeatureInvalid) {
83   std::string in = "DEVICE_FEATURE 12345";
84 
85   Parser parser;
86   Result r = parser.Parse(in);
87   ASSERT_FALSE(r.IsSuccess());
88   EXPECT_EQ("1: invalid feature name for DEVICE_FEATURE command", r.Error());
89 }
90 
TEST_F(AmberScriptParserTest,DeviceFeatureExtraParams)91 TEST_F(AmberScriptParserTest, DeviceFeatureExtraParams) {
92   std::string in = "DEVICE_FEATURE vertexPipelineStoresAndAtomics EXTRA";
93 
94   Parser parser;
95   Result r = parser.Parse(in);
96   ASSERT_FALSE(r.IsSuccess());
97   EXPECT_EQ("1: extra parameters after DEVICE_FEATURE command: EXTRA",
98             r.Error());
99 }
100 
101 }  // namespace amberscript
102 }  // namespace amber
103