summaryrefslogtreecommitdiff
path: root/unittest/gtest_hal_cpu.cpp
blob: 5747865022cd2f2abcadf0c358014292f23d2e51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

#include <iostream>
#include <gtest/gtest.h>
#include "hw/common.h"
#include "hw/cpu.h"

using namespace std;

/*
 * main class
 */

#define LOWBATTERY "LowBattery"

struct cpu_device *cpu_dev;

class CPUHalTest : public testing::Test
{
	public:
		virtual void SetUp()
		{
			struct hw_info *info;
			int ret;
			ret = hw_get_info(CPU_HARDWARE_DEVICE_ID,
					(const struct hw_info **)&info);

			if (ret < 0) {
				cout << "Fail to load cpu hal(" << ret << ")" << endl;
				assert(true);
				return;
			}
			if (!info->open) {
				cout << "Failed to open cpu device; open(NULL)" << endl;
				assert(true);
				return;
			}

			ret = info->open(info, NULL, (struct hw_common**)&cpu_dev);
			if (ret < 0 || !cpu_dev) {
				cout << "Failed to get cpu device structure (" << ret << ")" << endl;
				assert(true);
				return;
			}

			return;
		}

		virtual void TearDown()
		{
			struct hw_info *info;

			info = cpu_dev->common.info;
			if (!info)
				free(cpu_dev);
			else
				info->close((struct hw_common *)cpu_dev);
			cpu_dev = NULL;

			return;
		}
};

/*
 * testcase
 */
TEST_F(CPUHalTest, InitP)
{
	EXPECT_NE(cpu_dev, nullptr);
}

TEST_F(CPUHalTest, DeinitP)
{
	struct cpu_device *tmp;
	struct hw_info *info;
	int ret;

	hw_get_info(CPU_HARDWARE_DEVICE_ID,
			(const struct hw_info **)&info);

	EXPECT_NE(info, nullptr);
	if (!info->open || !info->close)
		return;
	info->open(info, NULL, (struct hw_common**)&tmp);

	ret = info->close((struct hw_common *)tmp);
	EXPECT_EQ(ret, 0);
}

TEST_F(CPUHalTest, StartBoostP)
{
	int ret;

	EXPECT_NE(cpu_dev, nullptr);
	if (!cpu_dev->start_boost)
		return;
	// prprpr TODO 
	ret = cpu_dev->start_boost((void *)LOWBATTERY);
	cpu_dev->stop_boost((void *)LOWBATTERY);
	EXPECT_EQ(ret, 0);
}

TEST_F(CPUHalTest, StopBoostP)
{
	int ret;

	EXPECT_NE(cpu_dev, nullptr);
	if (!cpu_dev->stop_boost)
		return;
	// prprpr TODO 
	cpu_dev->start_boost((void *)LOWBATTERY);
	ret = cpu_dev->stop_boost((void *)LOWBATTERY);
	EXPECT_EQ(ret, 0);
}

int main(int argc, char **argv)
{
	testing::InitGoogleTest(&argc, argv);

	return RUN_ALL_TESTS();
}