power-utils: Initially add Updater class
The Updater class is used to do PSU code update, initially add it that
does unbind/bind driver and set PSU present to false/true during the
update.
Tested: Manually verify on Witherspoon that the driver is unbind/bind,
and the PSU present property is set to false/true during the PSU
update:
psutils --update \
/xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply0 \
/tmp/images/xxxxxxxx
Signed-off-by: Lei YU <mine260309@gmail.com>
Change-Id: Ic0a9df7687303caeb9a7f21ba00dc33ee76482db
diff --git a/tools/power-utils/test/meson.build b/tools/power-utils/test/meson.build
index 056f4cc..45052ad 100644
--- a/tools/power-utils/test/meson.build
+++ b/tools/power-utils/test/meson.build
@@ -16,3 +16,22 @@
objects: record_manager,
)
)
+
+test(
+ 'test_updater',
+ executable(
+ 'test_updater',
+ 'test_updater.cpp',
+ '../updater.cpp',
+ dependencies: [
+ gtest,
+ phosphor_logging,
+ ],
+ implicit_include_directories: false,
+ include_directories: '../../..',
+ link_with: [
+ libpower,
+ ],
+ objects: record_manager,
+ )
+)
diff --git a/tools/power-utils/test/test_updater.cpp b/tools/power-utils/test/test_updater.cpp
new file mode 100644
index 0000000..2786986
--- /dev/null
+++ b/tools/power-utils/test/test_updater.cpp
@@ -0,0 +1,42 @@
+/**
+ * Copyright © 2019 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "../updater.hpp"
+
+#include <gtest/gtest.h>
+
+namespace updater
+{
+namespace internal
+{
+
+std::string getDeviceName(std::string devPath);
+
+} // namespace internal
+} // namespace updater
+
+using namespace updater;
+
+TEST(Updater, getDeviceName)
+{
+ auto ret = internal::getDeviceName("");
+ EXPECT_TRUE(ret.empty());
+
+ ret = internal::getDeviceName("/sys/bus/i2c/devices/3-0069");
+ EXPECT_EQ("3-0069", ret);
+
+ ret = internal::getDeviceName("/sys/bus/i2c/devices/3-0069/");
+ EXPECT_EQ("3-0069", ret);
+}