profile-extras-test.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (C) 2019 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 <gtest/gtest.h>
  17. #include <sys/system_properties.h>
  18. #include "profile-extras.h"
  19. static int flush_count = 0;
  20. extern "C" {
  21. void __gcov_flush() {
  22. flush_count++;
  23. }
  24. }
  25. static const char kCoveragePropName[] = "debug.coverage.flush";
  26. TEST(profile_extras, smoke) {
  27. flush_count = 0;
  28. ASSERT_EQ(0, flush_count);
  29. kill(getpid(), GCOV_FLUSH_SIGNAL);
  30. sleep(2);
  31. ASSERT_EQ(1, flush_count);
  32. // kCoveragePropName from "0" -> "1" -> "0" -> "1" should trigger two flushes.
  33. // transition 1
  34. __system_property_set(kCoveragePropName, "0");
  35. sleep(2);
  36. ASSERT_EQ(1, flush_count);
  37. __system_property_set(kCoveragePropName, "1");
  38. sleep(2);
  39. ASSERT_EQ(2, flush_count);
  40. // transition 2
  41. __system_property_set(kCoveragePropName, "0");
  42. sleep(2);
  43. ASSERT_EQ(2, flush_count);
  44. __system_property_set(kCoveragePropName, "1");
  45. sleep(2);
  46. ASSERT_EQ(3, flush_count);
  47. }