util.h 1.3 KB

1234567891011121314151617181920212223242526272829
  1. // Copyright (c) Meta Platforms, Inc. and affiliates.
  2. //
  3. // This source code is licensed under both the GPLv2 (found in the
  4. // COPYING file in the root directory) and Apache 2.0 License
  5. // (found in the LICENSE.Apache file in the root directory).
  6. #pragma once
  7. #define CHECK_OK(expression) \
  8. do { \
  9. auto status = (expression); \
  10. if (!status.ok()) { \
  11. std::cerr << status.ToString() << std::endl; \
  12. abort(); \
  13. } \
  14. } while (0)
  15. #define CHECK_EQ(a, b) \
  16. if (a != b) { \
  17. std::cerr << "(" << #a << "=" << a << ") != (" << #b << "=" << b << ")" \
  18. << std::endl; \
  19. abort(); \
  20. }
  21. #define CHECK_TRUE(cond) \
  22. if (!(cond)) { \
  23. std::cerr << "\"" << #cond << "\" is false" << std::endl; \
  24. abort(); \
  25. }