reduce_test_util.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright (c) 2018 Google LLC
  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 implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef TEST_REDUCE_REDUCE_TEST_UTIL_H_
  15. #define TEST_REDUCE_REDUCE_TEST_UTIL_H_
  16. #include "gtest/gtest.h"
  17. #include "source/opt/ir_context.h"
  18. #include "source/reduce/reduction_opportunity.h"
  19. #include "spirv-tools/libspirv.h"
  20. namespace spvtools {
  21. namespace reduce {
  22. // Checks whether the given binaries are bit-wise equal.
  23. void CheckEqual(spv_target_env env,
  24. const std::vector<uint32_t>& expected_binary,
  25. const std::vector<uint32_t>& actual_binary);
  26. // Assembles the given text and check whether the resulting binary is bit-wise
  27. // equal to the given binary.
  28. void CheckEqual(spv_target_env env, const std::string& expected_text,
  29. const std::vector<uint32_t>& actual_binary);
  30. // Assembles the given text and turns the given IR into binary, then checks
  31. // whether the resulting binaries are bit-wise equal.
  32. void CheckEqual(spv_target_env env, const std::string& expected_text,
  33. const opt::IRContext* actual_ir);
  34. // Assembles the given IR context and checks whether the resulting binary is
  35. // valid.
  36. void CheckValid(spv_target_env env, const opt::IRContext* ir);
  37. // Assembles the given IR context, then returns its disassembly as a string.
  38. // Useful for debugging.
  39. std::string ToString(spv_target_env env, const opt::IRContext* ir);
  40. // Assembly options for writing reduction tests. It simplifies matters if
  41. // numeric ids do not change.
  42. const uint32_t kReduceAssembleOption =
  43. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS;
  44. // Disassembly options for writing reduction tests.
  45. const uint32_t kReduceDisassembleOption =
  46. SPV_BINARY_TO_TEXT_OPTION_NO_HEADER | SPV_BINARY_TO_TEXT_OPTION_INDENT;
  47. // Don't print reducer info during testing.
  48. void NopDiagnostic(spv_message_level_t /*level*/, const char* /*source*/,
  49. const spv_position_t& /*position*/, const char* /*message*/);
  50. // Prints reducer messages (for debugging).
  51. void CLIMessageConsumer(spv_message_level_t level, const char*,
  52. const spv_position_t& position, const char* message);
  53. // Dumps the SPIRV-V module in |context| to file |filename|. Useful for
  54. // interactive debugging.
  55. void DumpShader(opt::IRContext* context, const char* filename);
  56. // Dumps |binary| to file |filename|. Useful for interactive debugging.
  57. void DumpShader(const std::vector<uint32_t>& binary, const char* filename);
  58. } // namespace reduce
  59. } // namespace spvtools
  60. #endif // TEST_REDUCE_REDUCE_TEST_UTIL_H_