Address Valgrind issues in CI
Fixes "uninitialized values" errors reported by Valgrind. Problem
occurred from lack of specializations of googletest's PrintTo functions
for several custom types.
Tested:
On local CI container. After applying this patch issues stopped
appearing.
Change-Id: I98d9fd19724bee15add7b19422a9ddc2e4cbef09
Signed-off-by: Michal Orzel <michalx.orzel@intel.com>
diff --git a/tests/src/helpers.hpp b/tests/src/helpers.hpp
index 1c4905c..67e179d 100644
--- a/tests/src/helpers.hpp
+++ b/tests/src/helpers.hpp
@@ -4,5 +4,8 @@
#include "helpers/interfaces/sensor_id_helpers.hpp"
#include "helpers/labeled_tuple_helpers.hpp"
#include "helpers/metric_value_helpers.hpp"
+#include "helpers/report_params_helpers.hpp"
+#include "helpers/trigger_helpers.hpp"
+#include "helpers/types/container_types_helpers.hpp"
#include "helpers/types/duration_types_helpers.hpp"
#include "helpers/types/object_path_helpers.hpp"
diff --git a/tests/src/helpers/report_params_helpers.hpp b/tests/src/helpers/report_params_helpers.hpp
new file mode 100644
index 0000000..24d2ac5
--- /dev/null
+++ b/tests/src/helpers/report_params_helpers.hpp
@@ -0,0 +1,31 @@
+#pragma once
+
+#include "types/readings.hpp"
+#include "types/report_action.hpp"
+
+#include <ostream>
+
+#include <gmock/gmock.h>
+
+template <class Param>
+void PrintTo(const std::vector<Param>& vec, std::ostream* os);
+
+inline void PrintTo(const ReadingData& data, std::ostream* os)
+{
+ const auto& [id, value, timestamp] = data;
+ *os << "( " << id << ", " << std::to_string(value) << ", "
+ << std::to_string(timestamp) << " )";
+}
+
+inline void PrintTo(const Readings& readings, std::ostream* os)
+{
+ const auto& [timestamp, readingDataVec] = readings;
+ *os << "( " << std::to_string(timestamp) << ", ";
+ PrintTo(readingDataVec, os);
+ *os << " )";
+}
+
+inline void PrintTo(const ReportAction& action, std::ostream* os)
+{
+ *os << utils::enumToString(action);
+}
diff --git a/tests/src/helpers/trigger_helpers.hpp b/tests/src/helpers/trigger_helpers.hpp
new file mode 100644
index 0000000..3c8d699
--- /dev/null
+++ b/tests/src/helpers/trigger_helpers.hpp
@@ -0,0 +1,12 @@
+#pragma once
+
+#include "types/trigger_types.hpp"
+
+#include <ostream>
+
+#include <gmock/gmock.h>
+
+inline void PrintTo(const TriggerAction& action, std::ostream* os)
+{
+ *os << actionToString(action);
+}
diff --git a/tests/src/helpers/types/container_types_helpers.hpp b/tests/src/helpers/types/container_types_helpers.hpp
new file mode 100644
index 0000000..9767595
--- /dev/null
+++ b/tests/src/helpers/types/container_types_helpers.hpp
@@ -0,0 +1,23 @@
+#pragma once
+
+#include <iostream>
+#include <vector>
+
+#include <gmock/gmock.h>
+
+template <class Param>
+void PrintTo(const std::vector<Param>& vec, std::ostream* os)
+{
+ *os << "[ ";
+ bool first = true;
+ for (const auto& item : vec)
+ {
+ if (!first)
+ {
+ *os << ", ";
+ }
+ PrintTo(item, os);
+ first = false;
+ }
+ *os << " ]";
+}
diff --git a/tests/src/params/report_params.hpp b/tests/src/params/report_params.hpp
index a10c783..d9937ca 100644
--- a/tests/src/params/report_params.hpp
+++ b/tests/src/params/report_params.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include "helpers.hpp"
#include "report_manager.hpp"
#include "types/report_types.hpp"
@@ -119,6 +120,25 @@
return readingsProperty;
}
+ friend void PrintTo(const ReportParams& params, std::ostream* os)
+ {
+ *os << "{ Id: \"" << params.reportIdProperty << "\", Name: \""
+ << params.reportNameProperty << "\", ReportingType: \""
+ << utils::enumToString(params.reportingTypeProperty)
+ << "\", ReportActions: ";
+ PrintTo(params.reportActionsProperty, os);
+ *os << ", Interval: " << params.intervalProperty
+ << ", Enabled: " << params.enabledProperty
+ << ", AppendLimit: " << std::to_string(params.appendLimitProperty)
+ << ", ReportUpdates: \""
+ << utils::enumToString(params.reportUpdatesProperty)
+ << "\", MetricParameters: ";
+ PrintTo(params.metricParametersProperty, os);
+ *os << ", Readings: ";
+ PrintTo(params.readingsProperty, os);
+ *os << " }";
+ }
+
private:
std::string reportIdProperty = "TestId";
std::string reportNameProperty = "TestReport";
diff --git a/tests/src/test_report.cpp b/tests/src/test_report.cpp
index 31d49c5..10ba120 100644
--- a/tests/src/test_report.cpp
+++ b/tests/src/test_report.cpp
@@ -898,6 +898,16 @@
ReportParams reportParams;
std::vector<ReadingData> expectedReadings;
bool expectedEnabled;
+
+ friend void PrintTo(const ReportUpdatesReportParams& params,
+ std::ostream* os)
+ {
+ *os << "{ ReportParams: ";
+ PrintTo(params.reportParams, os);
+ *os << ", ExpectedReadings: ";
+ PrintTo(params.expectedReadings, os);
+ *os << ", ExpectedEnabled: " << params.expectedEnabled << " }";
+ }
};
class TestReportWithReportUpdatesAndLimit :
diff --git a/tests/src/test_sensor_cache.cpp b/tests/src/test_sensor_cache.cpp
index 218e160..3d12563 100644
--- a/tests/src/test_sensor_cache.cpp
+++ b/tests/src/test_sensor_cache.cpp
@@ -21,6 +21,11 @@
service(service), path(path)
{}
+ friend void PrintTo(const IdParam& param, std::ostream* os)
+ {
+ *os << "(" << param.service << "): " << param.path;
+ }
+
std::string service;
std::string path;
};