pid_controller_test.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2016 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 
20 
21 #include <float.h>
22 #include <math.h>
23 
24 #include <gtest/gtest.h>
25 
26 #include <grpc/support/alloc.h>
27 #include <grpc/support/log.h>
29 
32 
33 namespace grpc_core {
34 namespace testing {
35 
38  .set_gain_p(1)
39  .set_gain_i(1)
40  .set_gain_d(1)
41  .set_initial_control_value(1));
42 }
43 
45  double gain_p;
46  double gain_i;
47  double gain_d;
48  double dt;
49  double set_point;
50  double start;
51 };
52 
53 std::ostream& operator<<(std::ostream& out, SimpleConvergenceTestArgs args) {
54  return out << "gain_p:" << args.gain_p << " gain_i:" << args.gain_i
55  << " gain_d:" << args.gain_d << " dt:" << args.dt
56  << " set_point:" << args.set_point << " start:" << args.start;
57 }
58 
60  : public ::testing::TestWithParam<SimpleConvergenceTestArgs> {};
61 
64  .set_gain_p(GetParam().gain_p)
65  .set_gain_i(GetParam().gain_i)
66  .set_gain_d(GetParam().gain_d)
67  .set_initial_control_value(GetParam().start));
68 
69  for (int i = 0; i < 100000; i++) {
70  pid.Update(GetParam().set_point - pid.last_control_value(), GetParam().dt);
71  }
72 
73  EXPECT_LT(fabs(GetParam().set_point - pid.last_control_value()), 0.1);
74  if (GetParam().gain_i > 0) {
75  EXPECT_LT(fabs(pid.error_integral()), 0.1);
76  }
77 }
78 
80  X, SimpleConvergenceTest,
81  ::testing::Values(SimpleConvergenceTestArgs{0.2, 0, 0, 1, 100, 0},
82  SimpleConvergenceTestArgs{0.2, 0.1, 0, 1, 100, 0},
83  SimpleConvergenceTestArgs{0.2, 0.1, 0.1, 1, 100, 0}));
84 
85 } // namespace testing
86 } // namespace grpc_core
87 
88 int main(int argc, char** argv) {
90  ::testing::InitGoogleTest(&argc, argv);
91  return RUN_ALL_TESTS();
92 }
testing
Definition: aws_request_signer_test.cc:25
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
log.h
generate.env
env
Definition: generate.py:37
grpc_core::testing::SimpleConvergenceTest
Definition: pid_controller_test.cc:59
grpc_core::testing::SimpleConvergenceTestArgs::gain_i
double gain_i
Definition: pid_controller_test.cc:46
NoOp
Definition: bm_call_create.cc:477
grpc_core
Definition: call_metric_recorder.h:31
main
int main(int argc, char **argv)
Definition: pid_controller_test.cc:88
string.h
grpc_core::PidController::error_integral
double error_integral() const
Returns the current error integral (mostly for testing)
Definition: pid_controller.h:104
testing::TestWithParam
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1883
string_util.h
start
static uint64_t start
Definition: benchmark-pound.c:74
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
grpc_core::PidController::Args
Definition: pid_controller.h:37
grpc_core::testing::operator<<
std::ostream & operator<<(std::ostream &out, SimpleConvergenceTestArgs args)
Definition: pid_controller_test.cc:53
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2471
grpc_core::testing::SimpleConvergenceTestArgs::set_point
double set_point
Definition: pid_controller_test.cc:49
test_config.h
testing::InitGoogleTest
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6106
grpc_core::PidController::last_control_value
double last_control_value() const
Returns the last control value calculated.
Definition: pid_controller.h:101
testing::Values
internal::ValueArray< T... > Values(T... v)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest-param-test.h:335
grpc_core::PidController::Update
double Update(double error, double dt)
Definition: pid_controller.cc:30
grpc_core::PidController
Definition: pid_controller.h:35
alloc.h
EXPECT_LT
#define EXPECT_LT(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2032
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
grpc_core::testing::INSTANTIATE_TEST_SUITE_P
INSTANTIATE_TEST_SUITE_P(TooManyNames, BdpEstimatorRandomTest, ::testing::Values(3, 4, 6, 9, 13, 19, 28, 42, 63, 94, 141, 211, 316, 474, 711))
grpc_core::testing::TEST
TEST(ServiceConfigParserTest, DoubleRegistration)
Definition: service_config_test.cc:448
pid_controller.h
grpc_core::testing::TEST_P
TEST_P(BdpEstimatorRandomTest, GetEstimateRandomValues)
Definition: bdp_estimator_test.cc:124
grpc_core::testing::SimpleConvergenceTestArgs::dt
double dt
Definition: pid_controller_test.cc:48
grpc_core::testing::SimpleConvergenceTestArgs::gain_d
double gain_d
Definition: pid_controller_test.cc:47
grpc_core::testing::SimpleConvergenceTestArgs::start
double start
Definition: pid_controller_test.cc:50
grpc_core::testing::SimpleConvergenceTestArgs::gain_p
double gain_p
Definition: pid_controller_test.cc:45
grpc_core::testing::SimpleConvergenceTestArgs
Definition: pid_controller_test.cc:44
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:52