1 /*
2 * Copyright (C) 2021–2022 Beijing OSWare Technology Co., Ltd
3 * This file contains confidential and proprietary information of
4 * OSWare Technology Co., Ltd
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 #include <cstdint>
20 #include <cstdio>
21 #include <cstdlib>
22 #include <fcntl.h>
23 #include <gtest/gtest.h>
24 #include <string>
25 #include <unistd.h>
26 #include "hdf_uhdf_test.h"
27 #include "i2c_test.h"
28 #include "hdf_io_service_if.h"
29
30 using namespace testing::ext;
31
32 class HdfLiteI2cTest : public testing::Test {
33 public:
34 static void SetUpTestCase();
35 static void TearDownTestCase();
36 void SetUp();
37 void TearDown();
38 };
39
SetUpTestCase()40 void HdfLiteI2cTest::SetUpTestCase()
41 {
42 struct HdfTestMsg msg = {TEST_PAL_I2C_TYPE, I2C_TEST_CMD_SETUP_ALL, -1};
43 HdfTestOpenService();
44 HdfTestSendMsgToService(&msg);
45 }
46
TearDownTestCase()47 void HdfLiteI2cTest::TearDownTestCase()
48 {
49 struct HdfTestMsg msg = {TEST_PAL_I2C_TYPE, I2C_TEST_CMD_TEARDOWN_ALL, -1};
50 HdfTestSendMsgToService(&msg);
51 HdfTestCloseService();
52 }
53
SetUp()54 void HdfLiteI2cTest::SetUp()
55 {
56 }
57
TearDown()58 void HdfLiteI2cTest::TearDown()
59 {
60 }
61
62 /**
63 * @tc.name: HdfLiteI2cTestTransfer001
64 * @tc.desc: i2c transfer test
65 * @tc.type: FUNC
66 * @tc.require: AR000F8688
67 */
68 HWTEST_F(HdfLiteI2cTest, HdfLiteI2cTestTransfer001, TestSize.Level1)
69 {
70 struct HdfTestMsg msg = {TEST_PAL_I2C_TYPE, I2C_TEST_CMD_TRANSFER, -1};
71 EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
72 }
73
74 /**
75 * @tc.name: HdfLiteI2cTestWriteRead001
76 * @tc.desc: i2c write and read test
77 * @tc.type: FUNC
78 * @tc.require: AR000F8688
79 */
80 HWTEST_F(HdfLiteI2cTest, HdfLiteI2cTestWriteRead001, TestSize.Level1)
81 {
82 struct HdfTestMsg msg = {TEST_PAL_I2C_TYPE, I2C_TEST_CMD_WRITE_READ, -1};
83 EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
84 }
85
86 /**
87 * @tc.name: HdfLiteI2cTestMultiThread001
88 * @tc.desc: i2c multithread test
89 * @tc.type: FUNC
90 * @tc.require: AR000F8688
91 */
92 HWTEST_F(HdfLiteI2cTest, HdfLiteI2cTestMultiThread001, TestSize.Level1)
93 {
94 struct HdfTestMsg msg = {TEST_PAL_I2C_TYPE, I2C_TEST_CMD_MULTI_THREAD, -1};
95 EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
96 }
97
98 /**
99 * @tc.name: HdfLiteI2cTestReliability001
100 * @tc.desc: i2c reliability test
101 * @tc.type: FUNC
102 * @tc.require: AR000F8688
103 */
104 HWTEST_F(HdfLiteI2cTest, HdfLiteI2cTestReliability001, TestSize.Level1)
105 {
106 struct HdfTestMsg msg = {TEST_PAL_I2C_TYPE, I2C_TEST_CMD_RELIABILITY, -1};
107 EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
108 }
109