From b8e15ebaa810cf6766fd1f18ed66321fc2fae84c Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 3 Sep 2024 16:53:59 -0700 Subject: [PATCH] libhealthloop: Make the filterPowerSupplyEvents unit test easier to maintain Instead of hard-coding input lengths, let the compiler calculate the input length. Change-Id: I47d849b85dd983706bfada0293ccbdd04c8a597a Signed-off-by: Bart Van Assche --- .../filterPowerSupplyEventsTest.cpp | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/health/utils/libhealthloop/filterPowerSupplyEventsTest.cpp b/health/utils/libhealthloop/filterPowerSupplyEventsTest.cpp index e885f0b749..04b8bcdfff 100644 --- a/health/utils/libhealthloop/filterPowerSupplyEventsTest.cpp +++ b/health/utils/libhealthloop/filterPowerSupplyEventsTest.cpp @@ -192,16 +192,21 @@ TEST_P(filterPseTest, filterPse) { bpf_object__close(obj); } +static constexpr char input0[] = "a"; +static constexpr char input1[] = "abc\0SUBSYSTEM=block\0"; +static constexpr char input2[] = "\0SUBSYSTEM=block"; +static constexpr char input3[] = "\0SUBSYSTEM=power_supply"; +static constexpr char input4[] = "\0SUBSYSTEM=power_supply\0"; +static constexpr char input5[] = + "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789\0SUBSYSTEM=block\0"; + INSTANTIATE_TEST_SUITE_P( filterPse, filterPseTest, - testing::Values(test_data{false, "a"}, - test_data{true, std::string_view("abc\0SUBSYSTEM=block\0", 20)}, - test_data{true, std::string_view("\0SUBSYSTEM=block", 16)}, - test_data{true, std::string_view("\0SUBSYSTEM=power_supply", 23)}, - test_data{false, std::string_view("\0SUBSYSTEM=power_supply\0", 24)}, - test_data{ - false, - "012345678901234567890123456789012345678901234567890123456789012345" - "678901234567890123456789012345678901234567890123456789012345678901" - "234567890123456789012345678901234567890123456789012345678901234567" - "890123456789012345678901234567890123456789\0SUBSYSTEM=block\0"})); + testing::Values(test_data{false, std::string_view(input0, sizeof(input0) - 1)}, + test_data{true, std::string_view(input1, sizeof(input1) - 1)}, + test_data{true, std::string_view(input2, sizeof(input2) - 1)}, + test_data{true, std::string_view(input3, sizeof(input3) - 1)}, + test_data{false, std::string_view(input4, sizeof(input4) - 1)}, + test_data{false, std::string_view(input5, sizeof(input5) - 1)}));