diff options
Diffstat (limited to 'unittest/gtest_hal_cpu.cpp')
-rwxr-xr-x[-rw-r--r--] | unittest/gtest_hal_cpu.cpp | 98 |
1 files changed, 39 insertions, 59 deletions
diff --git a/unittest/gtest_hal_cpu.cpp b/unittest/gtest_hal_cpu.cpp index 5747865..e1541fa 100644..100755 --- a/unittest/gtest_hal_cpu.cpp +++ b/unittest/gtest_hal_cpu.cpp @@ -1,7 +1,6 @@ #include <iostream> #include <gtest/gtest.h> -#include "hw/common.h" #include "hw/cpu.h" using namespace std; @@ -12,6 +11,7 @@ using namespace std; #define LOWBATTERY "LowBattery" +struct hw_info *info; struct cpu_device *cpu_dev; class CPUHalTest : public testing::Test @@ -19,44 +19,12 @@ 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; } }; @@ -65,51 +33,63 @@ class CPUHalTest : public testing::Test */ 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, + ret = hw_get_info(CPU_HARDWARE_DEVICE_ID, (const struct hw_info **)&info); - - EXPECT_NE(info, nullptr); - if (!info->open || !info->close) + if (ret < 0) { + cout << "There is no device for cpu " << ret << endl; return; - info->open(info, NULL, (struct hw_common**)&tmp); - - ret = info->close((struct hw_common *)tmp); - EXPECT_EQ(ret, 0); + } else { + EXPECT_EQ(ret, 0) << "Fail to load cpu hal (" << ret << ")"; + } + if (!info || !info->open) { + cout << "There is no function for info open" << endl; + return; + } + ret = info->open(info, NULL, (struct hw_common**)&cpu_dev); + EXPECT_EQ(ret, 0) << "Fail to open cpu device (" << ret << ")"; } TEST_F(CPUHalTest, StartBoostP) { int ret; - EXPECT_NE(cpu_dev, nullptr); - if (!cpu_dev->start_boost) + if (!cpu_dev || !cpu_dev->start_boost) { + cout << "There is no function for start_boost" << endl; return; - // prprpr TODO + } + + // prprpr TODO ret = cpu_dev->start_boost((void *)LOWBATTERY); - cpu_dev->stop_boost((void *)LOWBATTERY); - EXPECT_EQ(ret, 0); + EXPECT_EQ(ret, 0) << "Fail to start_boost (" << ret << ")"; } TEST_F(CPUHalTest, StopBoostP) { int ret; - EXPECT_NE(cpu_dev, nullptr); - if (!cpu_dev->stop_boost) + if (!cpu_dev || !cpu_dev->stop_boost) { + cout << "There is no function for stop_boost" << endl; return; - // prprpr TODO - cpu_dev->start_boost((void *)LOWBATTERY); + } + + // prprpr TODO ret = cpu_dev->stop_boost((void *)LOWBATTERY); - EXPECT_EQ(ret, 0); + EXPECT_EQ(ret, 0) << "Fail to stop_boost (" << ret << ")"; +} + +TEST_F(CPUHalTest, DeinitP) +{ + int ret; + + if (!info || !info->close) { + cout << "There is no function for info close" << endl; + return; + } + + ret = info->close((struct hw_common *)cpu_dev); + EXPECT_EQ(ret, 0) << "Fail to open cpu device (" << ret << ")"; } int main(int argc, char **argv) |