Wrapper_test.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #include "Wrapper.h"
  17. #include "bcinfo/MetadataExtractor.h"
  18. #include "builder.h"
  19. #include "file_utils.h"
  20. #include "instructions.h"
  21. #include "module.h"
  22. #include "test_utils.h"
  23. #include "gtest/gtest.h"
  24. namespace android {
  25. namespace spirit {
  26. class WrapperTest : public ::testing::Test {
  27. protected:
  28. virtual void SetUp() {
  29. mWordsGreyscale = readWords("greyscale.spv");
  30. mWordsGreyscale2 = readWords("greyscale2.spv");
  31. mWordsInvert = readWords("invert.spv");
  32. }
  33. std::vector<uint32_t> mWordsGreyscale;
  34. std::vector<uint32_t> mWordsGreyscale2;
  35. std::vector<uint32_t> mWordsInvert;
  36. private:
  37. std::vector<uint32_t> readWords(const char *testFile) {
  38. static const std::string testDataPath(
  39. "frameworks/rs/rsov/compiler/spirit/test_data/");
  40. const std::string &fullPath = getAbsolutePath(testDataPath + testFile);
  41. return readFile<uint32_t>(fullPath);
  42. }
  43. };
  44. TEST_F(WrapperTest, testAddBuffer) {
  45. Builder b;
  46. Module m(&b);
  47. auto elemType = m.getIntType(32);
  48. VariableInst *buffer = AddBuffer(elemType, 2, b, &m);
  49. ASSERT_NE(nullptr, buffer);
  50. GlobalSection *gs = m.getGlobalSection();
  51. EXPECT_EQ(1, countEntity<TypeRuntimeArrayInst>(gs));
  52. EXPECT_EQ(1, countEntity<TypeStructInst>(gs));
  53. EXPECT_EQ(1, countEntity<VariableInst>(gs));
  54. }
  55. TEST_F(WrapperTest, testAddWrapper1) {
  56. std::unique_ptr<Module> m(Deserialize<Module>(mWordsGreyscale));
  57. ASSERT_NE(nullptr, m);
  58. m->resolveIds();
  59. Builder b;
  60. m->setBuilder(&b);
  61. constexpr uint32_t sig =
  62. bcinfo::MD_SIG_Kernel | bcinfo::MD_SIG_In | bcinfo::MD_SIG_Out;
  63. EXPECT_FALSE(AddWrapper("foo", sig, 1, b, m.get()));
  64. EXPECT_TRUE(AddWrapper("greyscale(vf4;", sig, 1, b, m.get()));
  65. // The input already has an entry point
  66. EXPECT_EQ(2, countEntity<EntryPointDefinition>(m.get()));
  67. }
  68. TEST_F(WrapperTest, testAddWrapper2) {
  69. std::unique_ptr<Module> m(Deserialize<Module>(mWordsInvert));
  70. ASSERT_NE(nullptr, m);
  71. m->resolveIds();
  72. Builder b;
  73. m->setBuilder(&b);
  74. uint32_t sig = bcinfo::MD_SIG_Kernel | bcinfo::MD_SIG_In | bcinfo::MD_SIG_Out;
  75. EXPECT_FALSE(AddWrapper("foo", sig, 1, b, m.get()));
  76. ASSERT_TRUE(AddWrapper("invert", sig, 1, b, m.get()));
  77. EXPECT_EQ(1, countEntity<EntryPointDefinition>(m.get()));
  78. }
  79. TEST_F(WrapperTest, testAddWrapperForRoot) {
  80. std::unique_ptr<Module> m(Deserialize<Module>(mWordsInvert));
  81. ASSERT_NE(nullptr, m);
  82. Builder b;
  83. m->setBuilder(&b);
  84. bool success = AddWrapper("root", 0, 1, b, m.get());
  85. ASSERT_TRUE(success);
  86. }
  87. } // namespace spirit
  88. } // namespace android