• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "instructions.h"
18 
19 #include "gtest/gtest.h"
20 
21 #include <memory>
22 #include <vector>
23 
24 namespace android {
25 namespace spirit {
26 
TEST(InstructionTest,testOpCapability)27 TEST(InstructionTest, testOpCapability) {
28   std::vector<uint32_t> words = {0x00020011, 0x00000001};
29   auto *i = Deserialize<CapabilityInst>(words);
30   EXPECT_NE(nullptr, i);
31 }
32 
TEST(InstructionTest,testOpExtension)33 TEST(InstructionTest, testOpExtension) {
34   uint8_t bytes[] = {0x0a, 0x00, 0x03, 0x00, 0x41, 0x42,
35                      0x43, 0x44, 0x45, 0x46, 'G',  0x00};
36   std::vector<uint32_t> words((uint32_t *)bytes,
37                               (uint32_t *)(bytes + sizeof(bytes)));
38   auto *i = Deserialize<ExtensionInst>(words);
39   ASSERT_NE(nullptr, i);
40   EXPECT_STREQ("ABCDEFG", i->mOperand1.c_str());
41 }
42 
TEST(InstructionTest,testOpExtInstImport)43 TEST(InstructionTest, testOpExtInstImport) {
44   uint8_t bytes[] = {0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00,
45                      0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64,
46                      0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, 0x00};
47   std::vector<uint32_t> words((uint32_t *)bytes,
48                               (uint32_t *)(bytes + sizeof(bytes)));
49   auto *i = Deserialize<ExtInstImportInst>(words);
50   ASSERT_NE(nullptr, i);
51   EXPECT_STREQ("GLSL.std.450", i->mOperand1.c_str());
52 }
53 
54 } // namespace spirit
55 } // namespace android
56