tests: unittest: Add pass-hal-mock class for unittest 03/283603/2
authorChanwoo Choi <cw00.choi@samsung.com>
Tue, 13 Sep 2022 23:16:48 +0000 (08:16 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Tue, 13 Dec 2022 02:45:00 +0000 (11:45 +0900)
Change-Id: I0862b7cfdbf300a4ef906f073ef34c0acf670570
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
tests/unittest/pass-rescon/pass-hal-mock.cpp [new file with mode: 0644]
tests/unittest/pass-rescon/pass-hal-mock.hpp [new file with mode: 0644]

diff --git a/tests/unittest/pass-rescon/pass-hal-mock.cpp b/tests/unittest/pass-rescon/pass-hal-mock.cpp
new file mode 100644 (file)
index 0000000..5f3eb2f
--- /dev/null
@@ -0,0 +1,302 @@
+/*
+ * Copyright (C) 2022 Samsung Electronics Co., Ltd.
+ *
+ * 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 <iostream>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include <gio/gio.h>
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+extern "C" {
+#include "pass.h"
+#include "pass-hal.h"
+}
+
+#include "pass-hal-mock.hpp"
+
+using namespace std;
+using ::testing::Return;
+using ::testing::_;
+
+PassHalMock *gPassHalMock;
+
+int pass_hal_get_curr_governor(struct pass_resource *res, char *governor)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_get_curr_governor(res, governor);
+}
+
+int pass_hal_set_curr_governor(struct pass_resource *res, char *governor)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_set_curr_governor(res, governor);
+}
+
+int pass_hal_get_curr_freq(struct pass_resource *res)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_get_curr_freq(res);
+}
+
+int pass_hal_get_min_freq(struct pass_resource *res)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_get_min_freq(res);
+}
+
+int pass_hal_set_min_freq(struct pass_resource *res, int freq)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_set_min_freq(res, freq);
+}
+
+int pass_hal_get_max_freq(struct pass_resource *res)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_get_max_freq(res);
+}
+
+int pass_hal_set_max_freq(struct pass_resource *res, int freq)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_set_max_freq(res, freq);
+}
+
+int pass_hal_get_available_min_freq(struct pass_resource *res)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_get_available_min_freq(res);
+}
+
+int pass_hal_get_available_max_freq(struct pass_resource *res)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_get_available_max_freq(res);
+}
+
+int pass_hal_get_up_threshold(struct pass_resource *res)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_get_up_threshold(res);
+}
+
+int pass_hal_set_up_threshold(struct pass_resource *res, int up_threshold)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_set_up_threshold(res, up_threshold);
+}
+
+int pass_hal_get_online_state(struct pass_resource *res, int cpu)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_get_online_state(res, cpu);
+}
+
+int pass_hal_set_online_state(struct pass_resource *res, int cpu, int on)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_set_online_state(res, cpu, on);
+}
+
+int pass_hal_get_online_min_num(struct pass_resource *res)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_get_online_min_num(res);
+}
+
+int pass_hal_set_online_min_num(struct pass_resource *res, int num)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_set_online_min_num(res, num);
+}
+
+int pass_hal_get_online_max_num(struct pass_resource *res)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_get_online_max_num(res);
+}
+
+int pass_hal_set_online_max_num(struct pass_resource *res, int num)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_set_online_max_num(res, num);
+}
+
+int pass_hal_get_temp(struct pass_resource *res)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_get_temp(res);
+}
+
+int pass_hal_get_tmu_policy(struct pass_resource *res, char *policy)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_get_tmu_policy(res, policy);
+}
+
+int pass_hal_get_cooling_device_state(struct pass_resource *res)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_get_cooling_device_state(res);
+}
+
+int pass_hal_set_cooling_device_state(struct pass_resource *res, int state)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_set_cooling_device_state(res, state);
+}
+
+int pass_hal_get_cooling_device_max_state(struct pass_resource *res)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_get_cooling_device_max_state(res);
+}
+
+int pass_hal_set_battery_charging_status(struct pass_resource *res, int charging_status)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_set_battery_charging_status(res, charging_status);
+}
+
+int pass_hal_get_battery_charging_status(struct pass_resource *res)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_get_battery_charging_status(res);
+}
+
+int pass_hal_set_battery_charging_current(struct pass_resource *res,
+                                       int charging_current_uA)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_set_battery_charging_current(res, charging_current_uA);
+}
+
+int pass_hal_get_battery_charging_current(struct pass_resource *res)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_get_battery_charging_current(res);
+}
+
+int pass_hal_set_fault_around_bytes(struct pass_resource *res,
+                               int fault_around_bytes)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_set_fault_around_bytes(res, fault_around_bytes);
+}
+
+int pass_hal_get_fault_around_bytes(struct pass_resource *res)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_get_fault_around_bytes(res);
+}
+
+int pass_hal_set_pmqos_data(struct pass_resource *res, void *data)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_set_pmqos_data(res, data);
+}
+
+int pass_hal_save_initdata(struct pass_resource *res)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_save_initdata(res);
+}
+
+int pass_hal_restore_initdata(struct pass_resource *res)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_restore_initdata(res);
+}
+
+int pass_hal_get_resource(struct pass_resource *res)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_get_resource(res);
+}
+
+int pass_hal_put_resource(struct pass_resource *res)
+{
+       if (!gPassHalMock)
+               return -ENOTSUP;
+
+       return gPassHalMock->pass_hal_put_resource(res);
+}
diff --git a/tests/unittest/pass-rescon/pass-hal-mock.hpp b/tests/unittest/pass-rescon/pass-hal-mock.hpp
new file mode 100644 (file)
index 0000000..6d93b8e
--- /dev/null
@@ -0,0 +1,215 @@
+/*
+ * Copyright (C) 2022 Samsung Electronics Co., Ltd.
+ *
+ * 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 <iostream>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include <gio/gio.h>
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+extern "C" {
+#include "pass.h"
+#include "pass-hal.h"
+}
+
+using namespace std;
+using ::testing::Return;
+using ::testing::_;
+
+class PassHalMockInterface {
+public:
+       virtual ~PassHalMockInterface() {};
+
+       /***
+        * Functions for all H/W resources
+        */
+       /* Get and put the h/w resource. */
+       virtual int pass_hal_get_resource(struct pass_resource *res) = 0;
+       virtual int pass_hal_put_resource(struct pass_resource *res) = 0;
+
+       /* Save and restore the initial data of the h/w resource. */
+       virtual int pass_hal_save_initdata(struct pass_resource *pass_res) = 0;
+       virtual int pass_hal_restore_initdata(struct pass_resource *pass_res) = 0;
+
+       /***
+        * Functions for CPU/BUS/GPU H/W resources
+        */
+       /* Get and the current governor. */
+       virtual int pass_hal_get_curr_governor(struct pass_resource *res, char *governor) = 0;
+       virtual int pass_hal_set_curr_governor(struct pass_resource *res, char *governor) = 0;
+
+       /* Get the current frequency. */
+       virtual int pass_hal_get_curr_freq(struct pass_resource *res) = 0;
+
+       /* Get and set the minimum frequency. */
+       virtual int pass_hal_get_min_freq(struct pass_resource *res) = 0;
+       virtual int pass_hal_set_min_freq(struct pass_resource *res, int freq) = 0;
+
+       /* Get and set the maximum frequency. */
+       virtual int pass_hal_get_max_freq(struct pass_resource *res) = 0;
+       virtual int pass_hal_set_max_freq(struct pass_resource *res, int freq) = 0;
+
+       /* Get the minimum/maximum frequency which can be set to resource. */
+       virtual int pass_hal_get_available_min_freq(struct pass_resource *res) = 0;
+       virtual int pass_hal_get_available_max_freq(struct pass_resource *res) = 0;
+
+       /* Get and set the up_threshold to support boosting. */
+       virtual int pass_hal_get_up_threshold(struct pass_resource *res) = 0;
+       virtual int pass_hal_set_up_threshold(struct pass_resource *res, int up_threshold) = 0;
+
+       /* Get the temperature and policy of thermal unit on specific h/w. */
+       virtual int pass_hal_get_temp(struct pass_resource *res) = 0;
+       virtual int pass_hal_get_tmu_policy(struct pass_resource *res, char *policy) = 0;
+
+       /* Get and set the state of cooling device on specific h/w. */
+       virtual int pass_hal_get_cooling_device_state(struct pass_resource *res) = 0;
+       virtual int pass_hal_set_cooling_device_state(struct pass_resource *res, int state) = 0;
+       virtual int pass_hal_get_cooling_device_max_state(struct pass_resource *res) = 0;
+
+       /* Get and set the battery charging state. */
+       virtual int pass_hal_set_battery_charging_status(struct pass_resource *res, int charging_status) = 0;
+       virtual int pass_hal_get_battery_charging_status(struct pass_resource *res) = 0;
+
+       /* Get and set the battery charging current. */
+       virtual int pass_hal_set_battery_charging_current(struct pass_resource *res, int charging_current_uA) = 0;
+       virtual int pass_hal_get_battery_charging_current(struct pass_resource *res) = 0;
+
+       /***
+        * Functions for CPU H/W resources
+        */
+       /* Get and set online state of cpu. */
+       virtual int pass_hal_get_online_state(struct pass_resource *res, int cpu) = 0;
+       virtual int pass_hal_set_online_state(struct pass_resource *res, int cpu, int on) = 0;
+       /* Get and set the minimum number of online CPUs */
+       virtual int pass_hal_get_online_min_num(struct pass_resource *res) = 0;
+       virtual int pass_hal_set_online_min_num(struct pass_resource *res, int num) = 0;
+       /* Get and set the maximum number of online CPUs */
+       virtual int pass_hal_get_online_max_num(struct pass_resource *res) = 0;
+       virtual int pass_hal_set_online_max_num(struct pass_resource *res, int num) = 0;
+
+       /***
+        * Functions for Memory h/w resource
+        */
+       /* Get and set the /sys/kernel/debug/fault_around_bytes */
+       virtual int pass_hal_get_fault_around_bytes(struct pass_resource *res) = 0;
+       virtual int pass_hal_set_fault_around_bytes(struct pass_resource *res, int fault_around_bytes) = 0;
+
+       /***
+        * Functions for Nonstandard H/W resources
+        */
+       /*
+        * NOTE: It is not propper method. But PASS must need to keep
+        * the backwards compatibility, set the PMQoS's data from
+        * platform to hal. So, It is not recommended to use it.
+        *
+        * This function will be removed after finding the proper method.
+        */
+       virtual int pass_hal_set_pmqos_data(struct pass_resource *res, void *data) = 0;
+};
+
+class PassHalMock:PassHalMockInterface {
+public:
+       /***
+        * Functions for all H/W resources
+        */
+       /* Get and put the h/w resource. */
+       MOCK_METHOD1(pass_hal_get_resource, int (struct pass_resource *res));
+       MOCK_METHOD1(pass_hal_put_resource, int (struct pass_resource *res));
+
+       /* Save and restore the initial data of the h/w resource. */
+       MOCK_METHOD1(pass_hal_save_initdata, int (struct pass_resource *pass_res));
+       MOCK_METHOD1(pass_hal_restore_initdata, int (struct pass_resource *pass_res));
+
+       /***
+        * Functions for CPU/BUS/GPU H/W resources
+        */
+       /* Get and the current governor. */
+       MOCK_METHOD2(pass_hal_get_curr_governor, int (struct pass_resource *res, char *governor));
+       MOCK_METHOD2(pass_hal_set_curr_governor, int (struct pass_resource *res, char *governor));
+
+       /* Get the current frequency. */
+       MOCK_METHOD1(pass_hal_get_curr_freq, int (struct pass_resource *res));
+
+       /* Get and set the minimum frequency. */
+       MOCK_METHOD1(pass_hal_get_min_freq, int (struct pass_resource *res));
+       MOCK_METHOD2(pass_hal_set_min_freq, int (struct pass_resource *res, int freq));
+
+       /* Get and set the maximum frequency. */
+       MOCK_METHOD1(pass_hal_get_max_freq, int (struct pass_resource *res));
+       MOCK_METHOD2(pass_hal_set_max_freq, int (struct pass_resource *res, int freq));
+
+       /* Get the minimum/maximum frequency which can be set to resource. */
+       MOCK_METHOD1(pass_hal_get_available_min_freq, int (struct pass_resource *res));
+       MOCK_METHOD1(pass_hal_get_available_max_freq, int (struct pass_resource *res));
+
+       /* Get and set the up_threshold to support boosting. */
+       MOCK_METHOD1(pass_hal_get_up_threshold, int (struct pass_resource *res));
+       MOCK_METHOD2(pass_hal_set_up_threshold, int (struct pass_resource *res, int up_threshold));
+
+       /* Get the temperature and policy of thermal unit on specific h/w. */
+       MOCK_METHOD1(pass_hal_get_temp, int (struct pass_resource *res));
+       MOCK_METHOD2(pass_hal_get_tmu_policy, int (struct pass_resource *res, char *policy));
+
+       /* Get and set the state of cooling device on specific h/w. */
+       MOCK_METHOD1(pass_hal_get_cooling_device_state, int (struct pass_resource *res));
+       MOCK_METHOD2(pass_hal_set_cooling_device_state, int (struct pass_resource *res, int state));
+       MOCK_METHOD1(pass_hal_get_cooling_device_max_state, int (struct pass_resource *res));
+
+       /* Get and set the battery charging state. */
+       MOCK_METHOD2(pass_hal_set_battery_charging_status, int (struct pass_resource *res, int charging_status));
+       MOCK_METHOD1(pass_hal_get_battery_charging_status, int (struct pass_resource *res));
+
+       /* Get and set the battery charging current. */
+       MOCK_METHOD2(pass_hal_set_battery_charging_current, int (struct pass_resource *res, int charging_current_uA));
+       MOCK_METHOD1(pass_hal_get_battery_charging_current, int (struct pass_resource *res));
+
+       /***
+        * Functions for CPU H/W resources
+        */
+       /* Get and set online state of cpu. */
+       MOCK_METHOD2(pass_hal_get_online_state, int (struct pass_resource *res, int cpu));
+       MOCK_METHOD3(pass_hal_set_online_state, int (struct pass_resource *res, int cpu, int on));
+       /* Get and set the minimum number of online CPUs */
+       MOCK_METHOD1(pass_hal_get_online_min_num, int (struct pass_resource *res));
+       MOCK_METHOD2(pass_hal_set_online_min_num, int (struct pass_resource *res, int num));
+       /* Get and set the maximum number of online CPUs */
+       MOCK_METHOD1(pass_hal_get_online_max_num, int (struct pass_resource *res));
+       MOCK_METHOD2(pass_hal_set_online_max_num, int (struct pass_resource *res, int num));
+
+       /***
+        * Functions for Memory h/w resource
+        */
+       /* Get and set the /sys/kernel/debug/fault_around_bytes */
+       MOCK_METHOD1(pass_hal_get_fault_around_bytes, int (struct pass_resource *res));
+       MOCK_METHOD2(pass_hal_set_fault_around_bytes, int (struct pass_resource *res, int fault_around_bytes));
+
+       /***
+        * Functions for Nonstandard H/W resources
+        */
+       /*
+        * NOTE: It is not propper method. But PASS must need to keep
+        * the backwards compatibility, set the PMQoS's data from
+        * platform to hal. So, It is not recommended to use it.
+        *
+        * This function will be removed after finding the proper method.
+        */
+       MOCK_METHOD2(pass_hal_set_pmqos_data, int (struct pass_resource *res, void *data));
+
+};
+
+extern PassHalMock *gPassHalMock;