5747865022cd2f2abcadf0c358014292f23d2e51
[platform/core/system/libdevice-node.git] / unittest / gtest_hal_cpu.cpp
1
2 #include <iostream>
3 #include <gtest/gtest.h>
4 #include "hw/common.h"
5 #include "hw/cpu.h"
6
7 using namespace std;
8
9 /*
10  * main class
11  */
12
13 #define LOWBATTERY "LowBattery"
14
15 struct cpu_device *cpu_dev;
16
17 class CPUHalTest : public testing::Test
18 {
19         public:
20                 virtual void SetUp()
21                 {
22                         struct hw_info *info;
23                         int ret;
24                         ret = hw_get_info(CPU_HARDWARE_DEVICE_ID,
25                                         (const struct hw_info **)&info);
26
27                         if (ret < 0) {
28                                 cout << "Fail to load cpu hal(" << ret << ")" << endl;
29                                 assert(true);
30                                 return;
31                         }
32                         if (!info->open) {
33                                 cout << "Failed to open cpu device; open(NULL)" << endl;
34                                 assert(true);
35                                 return;
36                         }
37
38                         ret = info->open(info, NULL, (struct hw_common**)&cpu_dev);
39                         if (ret < 0 || !cpu_dev) {
40                                 cout << "Failed to get cpu device structure (" << ret << ")" << endl;
41                                 assert(true);
42                                 return;
43                         }
44
45                         return;
46                 }
47
48                 virtual void TearDown()
49                 {
50                         struct hw_info *info;
51
52                         info = cpu_dev->common.info;
53                         if (!info)
54                                 free(cpu_dev);
55                         else
56                                 info->close((struct hw_common *)cpu_dev);
57                         cpu_dev = NULL;
58
59                         return;
60                 }
61 };
62
63 /*
64  * testcase
65  */
66 TEST_F(CPUHalTest, InitP)
67 {
68         EXPECT_NE(cpu_dev, nullptr);
69 }
70
71 TEST_F(CPUHalTest, DeinitP)
72 {
73         struct cpu_device *tmp;
74         struct hw_info *info;
75         int ret;
76
77         hw_get_info(CPU_HARDWARE_DEVICE_ID,
78                         (const struct hw_info **)&info);
79
80         EXPECT_NE(info, nullptr);
81         if (!info->open || !info->close)
82                 return;
83         info->open(info, NULL, (struct hw_common**)&tmp);
84
85         ret = info->close((struct hw_common *)tmp);
86         EXPECT_EQ(ret, 0);
87 }
88
89 TEST_F(CPUHalTest, StartBoostP)
90 {
91         int ret;
92
93         EXPECT_NE(cpu_dev, nullptr);
94         if (!cpu_dev->start_boost)
95                 return;
96         // prprpr TODO 
97         ret = cpu_dev->start_boost((void *)LOWBATTERY);
98         cpu_dev->stop_boost((void *)LOWBATTERY);
99         EXPECT_EQ(ret, 0);
100 }
101
102 TEST_F(CPUHalTest, StopBoostP)
103 {
104         int ret;
105
106         EXPECT_NE(cpu_dev, nullptr);
107         if (!cpu_dev->stop_boost)
108                 return;
109         // prprpr TODO 
110         cpu_dev->start_boost((void *)LOWBATTERY);
111         ret = cpu_dev->stop_boost((void *)LOWBATTERY);
112         EXPECT_EQ(ret, 0);
113 }
114
115 int main(int argc, char **argv)
116 {
117         testing::InitGoogleTest(&argc, argv);
118
119         return RUN_ALL_TESTS();
120 }