FileTestFixture.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //===- FileTestFixute.h ---- Test Fixture for File Check style tests ------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef LLVM_CLANG_UNITTESTS_SPIRV_FILE_TEST_FIXTURE_H
  10. #define LLVM_CLANG_UNITTESTS_SPIRV_FILE_TEST_FIXTURE_H
  11. #include "spirv-tools/libspirv.h"
  12. #include "llvm/ADT/StringRef.h"
  13. #include "gtest/gtest.h"
  14. namespace clang {
  15. namespace spirv {
  16. class FileTest : public ::testing::Test {
  17. public:
  18. /// \brief Expected test result to be
  19. enum class Expect {
  20. Success, // Success (with or without warnings) - check disassembly
  21. Warning, // Success (with warnings) - check warning message
  22. Failure, // Failure (with errors) - check error message
  23. ValFailure, // Validation failure (with errors) - check error message
  24. };
  25. FileTest()
  26. : targetEnv(SPV_ENV_VULKAN_1_0), beforeHLSLLegalization(false),
  27. glLayout(false), dxLayout(false) {}
  28. void useVulkan1p1() { targetEnv = SPV_ENV_VULKAN_1_1; }
  29. void useVulkan1p2() { targetEnv = SPV_ENV_VULKAN_1_2; }
  30. void setBeforeHLSLLegalization() { beforeHLSLLegalization = true; }
  31. void setGlLayout() { glLayout = true; }
  32. void setDxLayout() { dxLayout = true; }
  33. void setScalarLayout() { scalarLayout = true; }
  34. /// \brief Runs a File Test! (See class description for more info)
  35. void runFileTest(llvm::StringRef path, Expect expect = Expect::Success,
  36. bool runValidation = true);
  37. private:
  38. /// \brief Reads in the given input file.
  39. bool parseInputFile();
  40. std::string targetProfile; ///< Target profile (argument of -T)
  41. std::string entryPoint; ///< Entry point name (argument of -E)
  42. std::vector<std::string> restArgs; ///< All the other arguments
  43. std::string inputFilePath; ///< Path to the input test file
  44. std::vector<uint32_t> generatedBinary; ///< The generated SPIR-V Binary
  45. std::string checkCommands; ///< CHECK commands that verify output
  46. std::string generatedSpirvAsm; ///< Disassembled binary (SPIR-V code)
  47. spv_target_env targetEnv; ///< Environment to validate against
  48. bool beforeHLSLLegalization;
  49. bool glLayout;
  50. bool dxLayout;
  51. bool scalarLayout;
  52. };
  53. } // end namespace spirv
  54. } // end namespace clang
  55. #endif