• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #include <cstdint>
10 #include <cstdio>
11 #include <cstdlib>
12 #include <fcntl.h>
13 #include <gtest/gtest.h>
14 #include <string>
15 #include <unistd.h>
16 #include "hdf_uhdf_test.h"
17 #include "i2c_test.h"
18 #include "hdf_io_service_if.h"
19 
20 using namespace testing::ext;
21 
22 class HdfLiteI2cTest : public testing::Test {
23 public:
24     static void SetUpTestCase();
25     static void TearDownTestCase();
26     void SetUp();
27     void TearDown();
28 };
29 
SetUpTestCase()30 void HdfLiteI2cTest::SetUpTestCase()
31 {
32     int32_t ret;
33     struct HdfTestMsg msg = {TEST_PAL_I2C_TYPE, I2C_TEST_CMD_SETUP_ALL, -1};
34     HdfTestOpenService();
35     HdfTestSendMsgToService(&msg);
36 
37     ret = I2cTestExecute(I2C_TEST_CMD_SETUP_ALL);
38     if (ret != 0) {
39         printf("%s: User SetUp FAIL:%d\n\r", __func__, ret);
40     }
41     printf("%s: exit!\n", __func__);
42 }
43 
TearDownTestCase()44 void HdfLiteI2cTest::TearDownTestCase()
45 {
46     int32_t ret;
47     struct HdfTestMsg msg = {TEST_PAL_I2C_TYPE, I2C_TEST_CMD_TEARDOWN_ALL, -1};
48     HdfTestSendMsgToService(&msg);
49     HdfTestCloseService();
50 
51     ret = I2cTestExecute(I2C_TEST_CMD_TEARDOWN_ALL);
52     if (ret != 0) {
53         printf("%s: User TearDown FAIL:%d\n\r", __func__, ret);
54     }
55     printf("%s: exit!\n", __func__);
56 }
57 
SetUp()58 void HdfLiteI2cTest::SetUp()
59 {
60 }
61 
TearDown()62 void HdfLiteI2cTest::TearDown()
63 {
64 }
65 
66 /**
67   * @tc.name: HdfLiteI2cTestTransfer001
68   * @tc.desc: i2c transfer test
69   * @tc.type: FUNC
70   * @tc.require: AR000F8688
71   */
72 HWTEST_F(HdfLiteI2cTest, HdfLiteI2cTestTransfer001, TestSize.Level1)
73 {
74     struct HdfTestMsg msg = {TEST_PAL_I2C_TYPE, I2C_TEST_CMD_TRANSFER, -1};
75     EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
76     printf("%s: kernel test done, then for user...\n", __func__);
77     EXPECT_EQ(0, I2cTestExecute(I2C_TEST_CMD_TRANSFER));
78     printf("%s: exit!\n", __func__);
79 }
80 
81 /**
82   * @tc.name: HdfLiteI2cTestWriteRead001
83   * @tc.desc: i2c write and read test
84   * @tc.type: FUNC
85   * @tc.require: AR000F8688
86   */
87 HWTEST_F(HdfLiteI2cTest, HdfLiteI2cTestWriteRead001, TestSize.Level1)
88 {
89     struct HdfTestMsg msg = {TEST_PAL_I2C_TYPE, I2C_TEST_CMD_WRITE_READ, -1};
90     EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
91     printf("%s: kernel test done, then for user...\n", __func__);
92     EXPECT_EQ(0, I2cTestExecute(I2C_TEST_CMD_WRITE_READ));
93     printf("%s: exit!\n", __func__);
94 }
95 
96 /**
97   * @tc.name: HdfLiteI2cTestMultiThread001
98   * @tc.desc: i2c multithread test
99   * @tc.type: FUNC
100   * @tc.require: AR000F8688
101   */
102 HWTEST_F(HdfLiteI2cTest, HdfLiteI2cTestMultiThread001, TestSize.Level1)
103 {
104     struct HdfTestMsg msg = {TEST_PAL_I2C_TYPE, I2C_TEST_CMD_MULTI_THREAD, -1};
105     EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
106     printf("%s: kernel test done, then for user...\n", __func__);
107     EXPECT_EQ(0, I2cTestExecute(I2C_TEST_CMD_MULTI_THREAD));
108     printf("%s: exit!\n", __func__);
109 }
110 
111 /**
112   * @tc.name: HdfLiteI2cTestReliability001
113   * @tc.desc: i2c reliability test
114   * @tc.type: FUNC
115   * @tc.require: AR000F8688
116   */
117 HWTEST_F(HdfLiteI2cTest, HdfLiteI2cTestReliability001, TestSize.Level1)
118 {
119     struct HdfTestMsg msg = {TEST_PAL_I2C_TYPE, I2C_TEST_CMD_RELIABILITY, -1};
120     EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
121     printf("%s: kernel test done, then for user...\n", __func__);
122     EXPECT_EQ(0, I2cTestExecute(I2C_TEST_CMD_RELIABILITY));
123     printf("%s: exit!\n", __func__);
124 }
125 
126 /**
127   * @tc.name: HdfLiteI2cTestPeformance001
128   * @tc.desc: i2c reliability test
129   * @tc.type: FUNC
130   * @tc.require: AR000F8688
131   */
132 HWTEST_F(HdfLiteI2cTest, HdfLiteI2cTestPeformance001, TestSize.Level1)
133 {
134     EXPECT_EQ(0, I2cTestExecute(I2C_TEST_CMD_PERFORMANCE));
135 }
136