stack_consumption_test.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // Copyright 2018 The Abseil Authors.
  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. // https://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. #include "absl/debugging/internal/stack_consumption.h"
  16. #ifdef ABSL_INTERNAL_HAVE_DEBUGGING_STACK_CONSUMPTION
  17. #include <string.h>
  18. #include "gtest/gtest.h"
  19. #include "absl/base/internal/raw_logging.h"
  20. namespace absl {
  21. ABSL_NAMESPACE_BEGIN
  22. namespace debugging_internal {
  23. namespace {
  24. static void SimpleSignalHandler(int signo) {
  25. char buf[100];
  26. memset(buf, 'a', sizeof(buf));
  27. // Never true, but prevents compiler from optimizing buf out.
  28. if (signo == 0) {
  29. ABSL_RAW_LOG(INFO, "%p", static_cast<void*>(buf));
  30. }
  31. }
  32. TEST(SignalHandlerStackConsumptionTest, MeasuresStackConsumption) {
  33. // Our handler should consume reasonable number of bytes.
  34. EXPECT_GE(GetSignalHandlerStackConsumption(SimpleSignalHandler), 100);
  35. }
  36. } // namespace
  37. } // namespace debugging_internal
  38. ABSL_NAMESPACE_END
  39. } // namespace absl
  40. #endif // ABSL_INTERNAL_HAVE_DEBUGGING_STACK_CONSUMPTION