summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2019-11-01 13:04:59 -0500
committerMatt Spinler <spinler@us.ibm.com>2019-11-12 16:14:42 +0000
commit1ea78801ce35583c988a45555160adcdac280a83 (patch)
tree31bd978e54e8b116e8a76e2d18d7764bd84905a6 /test
parent0688545ba47676829d52aebed21f4ed290c5643a (diff)
downloadphosphor-logging-1ea78801ce35583c988a45555160adcdac280a83.tar.gz
phosphor-logging-1ea78801ce35583c988a45555160adcdac280a83.zip
PEL: Run a user defined function on every PEL
Add a for_each() function to the PEL repository that takes a user defined function that will be run on every PEL, unless that function says to stop early. The user defined function is a std::function<bool>(const PEL&); For example, to save up to 100 IDs in the repo into a vector: std::vector<uint32_t> ids; ForEachFunc f = [&ids](const PEL& pel) { ids.push_back(pel.id()); return ids.size() == 100 ? true : false; }; repo.for_each(f); This will be used to find which PELs still need to be sent up to the host after a reboot, among other things. Signed-off-by: Matt Spinler <spinler@us.ibm.com> Change-Id: Ic60525a8ab3dd593ba37e43a6cb0b3db8dda7cee
Diffstat (limited to 'test')
-rw-r--r--test/openpower-pels/repository_test.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/openpower-pels/repository_test.cpp b/test/openpower-pels/repository_test.cpp
index 118cb12..0c927f6 100644
--- a/test/openpower-pels/repository_test.cpp
+++ b/test/openpower-pels/repository_test.cpp
@@ -176,3 +176,39 @@ TEST_F(RepositoryTest, TestGetPELData)
ASSERT_TRUE(pelData);
EXPECT_EQ(dataCopy, *pelData);
}
+
+TEST_F(RepositoryTest, TestForEach)
+{
+ Repository repo{repoPath};
+
+ // Add 2 PELs
+ auto data = pelDataFactory(TestPELType::pelSimple);
+ auto pel = std::make_unique<PEL>(data);
+ repo.add(pel);
+
+ pel = std::make_unique<PEL>(data);
+ pel->assignID();
+ pel->setCommitTime();
+ repo.add(pel);
+
+ // Make a function that saves the IDs
+ std::vector<uint32_t> ids;
+ Repository::ForEachFunc f1 = [&ids](const PEL& pel) {
+ ids.push_back(pel.id());
+ return false;
+ };
+
+ repo.for_each(f1);
+
+ EXPECT_EQ(ids.size(), 2);
+
+ // Stop after the first time in.
+ Repository::ForEachFunc f2 = [&ids](const PEL& pel) {
+ ids.push_back(pel.id());
+ return true;
+ };
+
+ ids.clear();
+ repo.for_each(f2);
+ EXPECT_EQ(ids.size(), 1);
+}
OpenPOWER on IntegriCloud