get_cpu_stats_test.cc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. *
  3. * Copyright 2018 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #include <grpc/impl/codegen/port_platform.h>
  19. #include "src/cpp/server/load_reporter/get_cpu_stats.h"
  20. #include <gtest/gtest.h>
  21. #include <grpc/grpc.h>
  22. #include "test/core/util/port.h"
  23. #include "test/core/util/test_config.h"
  24. namespace grpc {
  25. namespace testing {
  26. namespace {
  27. TEST(GetCpuStatsTest, ReadOnce) { grpc::load_reporter::GetCpuStatsImpl(); }
  28. TEST(GetCpuStatsTest, BusyNoLargerThanTotal) {
  29. auto p = grpc::load_reporter::GetCpuStatsImpl();
  30. uint64_t busy = p.first;
  31. uint64_t total = p.second;
  32. ASSERT_LE(busy, total);
  33. }
  34. TEST(GetCpuStatsTest, Ascending) {
  35. const size_t kRuns = 100;
  36. auto prev = grpc::load_reporter::GetCpuStatsImpl();
  37. for (size_t i = 0; i < kRuns; ++i) {
  38. auto cur = grpc::load_reporter::GetCpuStatsImpl();
  39. ASSERT_LE(prev.first, cur.first);
  40. ASSERT_LE(prev.second, cur.second);
  41. prev = cur;
  42. }
  43. }
  44. } // namespace
  45. } // namespace testing
  46. } // namespace grpc
  47. int main(int argc, char** argv) {
  48. grpc::testing::TestEnvironment env(argc, argv);
  49. ::testing::InitGoogleTest(&argc, argv);
  50. return RUN_ALL_TESTS();
  51. }