Create stubs for regulator Device, Rail, and Rule
Create stub versions of the Device, Rail, and Rule classes for the
phosphor-regulators application. Having a stub version of these classes
is a pre-requisite for implementing the action framework.
Also updated the top level meson.build file to build the
phosphor-regulators directory. Created new meson.build files for
several phosphor-regulators sub-directories.
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: I50b018db744191acd1e473652019906a8506745f
diff --git a/meson.build b/meson.build
index a31edac..8567052 100644
--- a/meson.build
+++ b/meson.build
@@ -76,6 +76,7 @@
],
)
+subdir('phosphor-regulators')
subdir('power-sequencer')
subdir('power-supply')
subdir('tools/power-utils')
diff --git a/phosphor-regulators/meson.build b/phosphor-regulators/meson.build
new file mode 100644
index 0000000..7142616
--- /dev/null
+++ b/phosphor-regulators/meson.build
@@ -0,0 +1,4 @@
+phosphor_regulators_includes = include_directories('src')
+
+subdir('src')
+subdir('test')
diff --git a/phosphor-regulators/src/device.hpp b/phosphor-regulators/src/device.hpp
new file mode 100644
index 0000000..3b3a91b
--- /dev/null
+++ b/phosphor-regulators/src/device.hpp
@@ -0,0 +1,71 @@
+/**
+ * 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.
+ */
+#pragma once
+
+#include <string>
+
+namespace phosphor
+{
+namespace power
+{
+namespace regulators
+{
+
+/**
+ * @class Device
+ *
+ * A hardware device, such as a voltage regulator or I/O expander.
+ */
+class Device
+{
+ public:
+ // Specify which compiler-generated methods we want
+ Device() = delete;
+ Device(const Device&) = delete;
+ Device(Device&&) = delete;
+ Device& operator=(const Device&) = delete;
+ Device& operator=(Device&&) = delete;
+ ~Device() = default;
+
+ /**
+ * Constructor.
+ *
+ * @param id unique device ID
+ */
+ Device(const std::string& id) : id{id}
+ {
+ }
+
+ /**
+ * Returns the unique ID of this device.
+ *
+ * @return device ID
+ */
+ const std::string& getId() const
+ {
+ return id;
+ }
+
+ private:
+ /**
+ * Unique ID of this device.
+ */
+ const std::string id{};
+};
+
+} // namespace regulators
+} // namespace power
+} // namespace phosphor
diff --git a/phosphor-regulators/src/meson.build b/phosphor-regulators/src/meson.build
new file mode 100644
index 0000000..19f1bb5
--- /dev/null
+++ b/phosphor-regulators/src/meson.build
@@ -0,0 +1 @@
+# subdir('actions')
diff --git a/phosphor-regulators/src/rail.hpp b/phosphor-regulators/src/rail.hpp
new file mode 100644
index 0000000..3fa516b
--- /dev/null
+++ b/phosphor-regulators/src/rail.hpp
@@ -0,0 +1,74 @@
+/**
+ * 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.
+ */
+#pragma once
+
+#include <string>
+
+namespace phosphor
+{
+namespace power
+{
+namespace regulators
+{
+
+/**
+ * @class Rail
+ *
+ * A voltage rail produced by a voltage regulator.
+ *
+ * Voltage regulators produce one or more rails. Each rail typically provides a
+ * different output voltage level, such as 1.1V.
+ */
+class Rail
+{
+ public:
+ // Specify which compiler-generated methods we want
+ Rail() = delete;
+ Rail(const Rail&) = delete;
+ Rail(Rail&&) = delete;
+ Rail& operator=(const Rail&) = delete;
+ Rail& operator=(Rail&&) = delete;
+ ~Rail() = default;
+
+ /**
+ * Constructor.
+ *
+ * @param id unique rail ID
+ */
+ Rail(const std::string& id) : id{id}
+ {
+ }
+
+ /**
+ * Returns the unique ID of this rail.
+ *
+ * @return rail ID
+ */
+ const std::string& getId() const
+ {
+ return id;
+ }
+
+ private:
+ /**
+ * Unique ID of this rail.
+ */
+ const std::string id{};
+};
+
+} // namespace regulators
+} // namespace power
+} // namespace phosphor
diff --git a/phosphor-regulators/src/rule.hpp b/phosphor-regulators/src/rule.hpp
new file mode 100644
index 0000000..ccc47fa
--- /dev/null
+++ b/phosphor-regulators/src/rule.hpp
@@ -0,0 +1,78 @@
+/**
+ * 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.
+ */
+#pragma once
+
+#include <string>
+
+namespace phosphor
+{
+namespace power
+{
+namespace regulators
+{
+
+/**
+ * @class Rule
+ *
+ * A rule is a sequence of actions that can be shared by multiple voltage
+ * regulators.
+ *
+ * Rules define a standard way to perform an operation. For example, the
+ * following action sequences might be sharable using a rule:
+ * - Actions that set the output voltage of a regulator rail
+ * - Actions that read all the sensors of a regulator rail
+ * - Actions that detect down-level hardware using version registers
+ */
+class Rule
+{
+ public:
+ // Specify which compiler-generated methods we want
+ Rule() = delete;
+ Rule(const Rule&) = delete;
+ Rule(Rule&&) = delete;
+ Rule& operator=(const Rule&) = delete;
+ Rule& operator=(Rule&&) = delete;
+ ~Rule() = default;
+
+ /**
+ * Constructor.
+ *
+ * @param id unique rule ID
+ */
+ Rule(const std::string& id) : id{id}
+ {
+ }
+
+ /**
+ * Returns the unique ID of this rule.
+ *
+ * @return rule ID
+ */
+ const std::string& getId() const
+ {
+ return id;
+ }
+
+ private:
+ /**
+ * Unique ID of this rule.
+ */
+ const std::string id{};
+};
+
+} // namespace regulators
+} // namespace power
+} // namespace phosphor
diff --git a/phosphor-regulators/test/device_tests.cpp b/phosphor-regulators/test/device_tests.cpp
new file mode 100644
index 0000000..bee4bdc
--- /dev/null
+++ b/phosphor-regulators/test/device_tests.cpp
@@ -0,0 +1,32 @@
+/**
+ * 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 "device.hpp"
+
+#include <gtest/gtest.h>
+
+using namespace phosphor::power::regulators;
+
+TEST(DeviceTests, Constructor)
+{
+ Device device("vdd_vrm2");
+ EXPECT_EQ(device.getId(), "vdd_vrm2");
+}
+
+TEST(DeviceTests, GetId)
+{
+ Device device("vio_vrm");
+ EXPECT_EQ(device.getId(), "vio_vrm");
+}
diff --git a/phosphor-regulators/test/meson.build b/phosphor-regulators/test/meson.build
new file mode 100644
index 0000000..0e32ad7
--- /dev/null
+++ b/phosphor-regulators/test/meson.build
@@ -0,0 +1,15 @@
+test('phosphor-regulators-tests',
+ executable('phosphor-regulators-tests',
+ 'device_tests.cpp',
+ 'rail_tests.cpp',
+ 'rule_tests.cpp',
+ dependencies: [
+ gmock,
+ gtest,
+ ],
+ implicit_include_directories: false,
+ include_directories: phosphor_regulators_includes,
+ )
+)
+
+# subdir('actions')
diff --git a/phosphor-regulators/test/rail_tests.cpp b/phosphor-regulators/test/rail_tests.cpp
new file mode 100644
index 0000000..09932f6
--- /dev/null
+++ b/phosphor-regulators/test/rail_tests.cpp
@@ -0,0 +1,32 @@
+/**
+ * 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 "rail.hpp"
+
+#include <gtest/gtest.h>
+
+using namespace phosphor::power::regulators;
+
+TEST(RailTests, Constructor)
+{
+ Rail rail("vdd0");
+ EXPECT_EQ(rail.getId(), "vdd0");
+}
+
+TEST(RailTests, GetId)
+{
+ Rail rail("vio2");
+ EXPECT_EQ(rail.getId(), "vio2");
+}
diff --git a/phosphor-regulators/test/rule_tests.cpp b/phosphor-regulators/test/rule_tests.cpp
new file mode 100644
index 0000000..6c32dc8
--- /dev/null
+++ b/phosphor-regulators/test/rule_tests.cpp
@@ -0,0 +1,32 @@
+/**
+ * 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 "rule.hpp"
+
+#include <gtest/gtest.h>
+
+using namespace phosphor::power::regulators;
+
+TEST(RuleTests, Constructor)
+{
+ Rule rule("set_voltage_rule");
+ EXPECT_EQ(rule.getId(), "set_voltage_rule");
+}
+
+TEST(RuleTests, GetId)
+{
+ Rule rule("read_sensor_values");
+ EXPECT_EQ(rule.getId(), "read_sensor_values");
+}