1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #include <cstring> 16 #include "gtest/gtest.h" 17 18 #include <unistd.h> 19 #include "client_executor/include/i_aie_client.inl" 20 #include "service_dead_cb.h" 21 #include "utils/log/aie_log.h" 22 #include "communication_adapter/source/sa_client.cpp" 23 #include "protocol/struct_definition/aie_info_define.h" 24 25 using namespace OHOS::AI; 26 using namespace testing::ext; 27 28 namespace { 29 const char * const INPUT_CHARACTER = "inputData"; 30 const char * const CONFIG_DESCRIPTION = "config information"; 31 const long long CLIENT_INFO_VERSION = 1; 32 const int CLIENT_ID = -1; 33 const int SESSION_ID = -1; 34 const long long ALGORITHM_INFO_CLIENT_VERSION = 2; 35 const int ALGORITHM_TYPE_SYNC = 0; 36 const int ALGORITHM_TYPE_ASYNC = 1; 37 const long long ALGORITHM_VERSION = 1; 38 const int OPERATE_ID = 2; 39 const int REQUEST_ID = 3; 40 } 41 42 class SaClientTest : public testing::Test { 43 public: 44 // SetUpTestCase:The preset action of the test suite is executed before the first TestCase SetUpTestCase()45 static void SetUpTestCase() {}; 46 47 // TearDownTestCase:The test suite cleanup action is executed after the last TestCase TearDownTestCase()48 static void TearDownTestCase() {}; 49 50 // SetUp:Execute before each test case SetUp()51 void SetUp() {}; 52 53 // TearDown:Execute after each test case TearDown()54 void TearDown() {}; 55 }; 56 57 /** 58 * @tc.name: TestSaClient001 59 * @tc.desc: Test Call SA proxy, to connect the server to get the client ID. 60 * @tc.type: FUNC 61 * @tc.require: AR000F77NK 62 */ 63 static HWTEST_F(SaClientTest, TestSaClient001, TestSize.Level0) 64 { 65 HILOGI("[Test]TestSaClient001."); 66 67 ConfigInfo configInfo {.description = CONFIG_DESCRIPTION}; 68 const char *inputData = INPUT_CHARACTER; 69 int len = strlen(inputData) + 1; 70 71 ClientInfo clientInfo = { 72 .clientVersion = CLIENT_INFO_VERSION, 73 .clientId = CLIENT_ID, 74 .sessionId = SESSION_ID, 75 .serverUid = INVALID_UID, 76 .clientUid = INVALID_UID, 77 .extendLen = len, 78 .extendMsg = reinterpret_cast<unsigned char*>(const_cast<char *>(inputData)), 79 }; 80 AlgorithmInfo algoInfo = { 81 .clientVersion = ALGORITHM_INFO_CLIENT_VERSION, 82 .isAsync = false, 83 .algorithmType = ALGORITHM_TYPE_SYNC, 84 .algorithmVersion = ALGORITHM_VERSION, 85 .isCloud = true, 86 .operateId = OPERATE_ID, 87 .requestId = REQUEST_ID, 88 .extendLen = len, 89 .extendMsg = reinterpret_cast<unsigned char*>(const_cast<char *>(inputData)), 90 }; 91 92 ServiceDeadCb deadCb = ServiceDeadCb(); 93 int resultCodeInit = AieClientInit(configInfo, clientInfo, algoInfo, &deadCb); 94 ASSERT_EQ(resultCodeInit, RETCODE_SUCCESS); 95 ASSERT_TRUE(clientInfo.clientId > 0); 96 97 SaClient *client = SaClient::GetInstance(); 98 if (client == nullptr) { 99 HILOGE("[SaClientAdapter] Fail to SaClient::GetInstance"); 100 return; 101 } 102 103 int retCode = client->Init(configInfo, clientInfo); 104 if (retCode != RETCODE_SUCCESS || clientInfo.clientId == INVALID_CLIENT_ID) { 105 HILOGE("[SaClientAdapter] Fail to Init to server. errorCode:%d", retCode); 106 return; 107 } 108 ASSERT_EQ(retCode, RETCODE_SUCCESS); 109 } 110