• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2024 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,DeviceProperty)23 TEST_F(AmberScriptParserTest, DeviceProperty) {
24   std::string in = R"(
25 DEVICE_PROPERTY FloatControlsProperties.shaderSignedZeroInfNanPreserveFloat16
26 DEVICE_PROPERTY FloatControlsProperties.shaderSignedZeroInfNanPreserveFloat32
27 DEVICE_PROPERTY FloatControlsProperties.shaderSignedZeroInfNanPreserveFloat64
28 DEVICE_PROPERTY FloatControlsProperties.shaderDenormPreserveFloat16
29 DEVICE_PROPERTY FloatControlsProperties.shaderDenormPreserveFloat32
30 DEVICE_PROPERTY FloatControlsProperties.shaderDenormPreserveFloat64
31 DEVICE_PROPERTY FloatControlsProperties.shaderDenormFlushToZeroFloat16
32 DEVICE_PROPERTY FloatControlsProperties.shaderDenormFlushToZeroFloat32
33 DEVICE_PROPERTY FloatControlsProperties.shaderDenormFlushToZeroFloat64
34 DEVICE_PROPERTY FloatControlsProperties.shaderRoundingModeRTEFloat16
35 DEVICE_PROPERTY FloatControlsProperties.shaderRoundingModeRTEFloat32
36 DEVICE_PROPERTY FloatControlsProperties.shaderRoundingModeRTEFloat64
37 DEVICE_PROPERTY FloatControlsProperties.shaderRoundingModeRTZFloat16
38 DEVICE_PROPERTY FloatControlsProperties.shaderRoundingModeRTZFloat32
39 DEVICE_PROPERTY FloatControlsProperties.shaderRoundingModeRTZFloat64)";
40 
41   Parser parser;
42   Result r = parser.Parse(in);
43   ASSERT_TRUE(r.IsSuccess()) << r.Error();
44 
45   auto script = parser.GetScript();
46   const auto& properties = script->GetRequiredProperties();
47   ASSERT_EQ(15U, properties.size());
48   EXPECT_EQ("FloatControlsProperties.shaderSignedZeroInfNanPreserveFloat16",
49             properties[0]);
50   EXPECT_EQ("FloatControlsProperties.shaderSignedZeroInfNanPreserveFloat32",
51             properties[1]);
52   EXPECT_EQ("FloatControlsProperties.shaderSignedZeroInfNanPreserveFloat64",
53             properties[2]);
54   EXPECT_EQ("FloatControlsProperties.shaderDenormPreserveFloat16",
55             properties[3]);
56   EXPECT_EQ("FloatControlsProperties.shaderDenormPreserveFloat32",
57             properties[4]);
58   EXPECT_EQ("FloatControlsProperties.shaderDenormPreserveFloat64",
59             properties[5]);
60   EXPECT_EQ("FloatControlsProperties.shaderDenormFlushToZeroFloat16",
61             properties[6]);
62   EXPECT_EQ("FloatControlsProperties.shaderDenormFlushToZeroFloat32",
63             properties[7]);
64   EXPECT_EQ("FloatControlsProperties.shaderDenormFlushToZeroFloat64",
65             properties[8]);
66   EXPECT_EQ("FloatControlsProperties.shaderRoundingModeRTEFloat16",
67             properties[9]);
68   EXPECT_EQ("FloatControlsProperties.shaderRoundingModeRTEFloat32",
69             properties[10]);
70   EXPECT_EQ("FloatControlsProperties.shaderRoundingModeRTEFloat64",
71             properties[11]);
72   EXPECT_EQ("FloatControlsProperties.shaderRoundingModeRTZFloat16",
73             properties[12]);
74   EXPECT_EQ("FloatControlsProperties.shaderRoundingModeRTZFloat32",
75             properties[13]);
76   EXPECT_EQ("FloatControlsProperties.shaderRoundingModeRTZFloat64",
77             properties[14]);
78 }
79 
TEST_F(AmberScriptParserTest,DevicePropertyMissingProperty)80 TEST_F(AmberScriptParserTest, DevicePropertyMissingProperty) {
81   std::string in = "DEVICE_PROPERTY";
82 
83   Parser parser;
84   Result r = parser.Parse(in);
85   ASSERT_FALSE(r.IsSuccess());
86   EXPECT_EQ("1: missing property name for DEVICE_PROPERTY command", r.Error());
87 }
88 
TEST_F(AmberScriptParserTest,DevicePropertyUnknown)89 TEST_F(AmberScriptParserTest, DevicePropertyUnknown) {
90   std::string in = "DEVICE_PROPERTY unknown";
91 
92   Parser parser;
93   Result r = parser.Parse(in);
94   ASSERT_FALSE(r.IsSuccess());
95   EXPECT_EQ("1: unknown property name for DEVICE_PROPERTY command", r.Error());
96 }
97 
TEST_F(AmberScriptParserTest,DevicePropertyInvalid)98 TEST_F(AmberScriptParserTest, DevicePropertyInvalid) {
99   std::string in = "DEVICE_PROPERTY 12345";
100 
101   Parser parser;
102   Result r = parser.Parse(in);
103   ASSERT_FALSE(r.IsSuccess());
104   EXPECT_EQ("1: invalid property name for DEVICE_PROPERTY command", r.Error());
105 }
106 
TEST_F(AmberScriptParserTest,DevicePropertyExtraParams)107 TEST_F(AmberScriptParserTest, DevicePropertyExtraParams) {
108   std::string in =
109       "DEVICE_PROPERTY FloatControlsProperties.shaderDenormPreserveFloat16 "
110       "EXTRA";
111 
112   Parser parser;
113   Result r = parser.Parse(in);
114   ASSERT_FALSE(r.IsSuccess());
115   EXPECT_EQ("1: extra parameters after DEVICE_PROPERTY command: EXTRA",
116             r.Error());
117 }
118 
119 }  // namespace amberscript
120 }  // namespace amber
121