1 /* 2 * Copyright (c) 2021 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 16 #include <unistd.h> 17 18 #include "gtest/gtest.h" 19 20 #include "platform/dl_operation/include/aie_dl_operation.h" 21 #include "utils/log/aie_log.h" 22 23 using namespace testing::ext; 24 25 typedef int(*FUNC_ADD)(int, int); 26 namespace { 27 const int AIE_NUM1 = 1; 28 const int AIE_NUM2 = 2; 29 const int AIE_RESULT = 3; 30 const char * const TEST_SO_PATH = "/usr/lib/libdlOperationSo.so"; 31 } 32 33 class DlOperationTest : public testing::Test { 34 public: 35 // SetUpTestCase:The preset action of the test suite is executed before the first TestCase SetUpTestCase()36 static void SetUpTestCase() {}; 37 38 // TearDownTestCase:The test suite cleanup action is executed after the last TestCase TearDownTestCase()39 static void TearDownTestCase() {}; 40 41 // SetUp:Execute before each test case SetUp()42 void SetUp() {}; 43 44 // TearDown:Execute after each test case TearDown()45 void TearDown() {}; 46 }; 47 48 /** 49 * @tc.name: TestDlOption001 50 * @tc.desc: Test dl-option function, including AieDlopen, AieDlsym and AieDlclose. 51 * @tc.type: FUNC 52 * @tc.require: AR000F77MR 53 */ 54 HWTEST_F(DlOperationTest, TestDlOption001, TestSize.Level1) 55 { 56 void *handle = AieDlopen(TEST_SO_PATH); 57 HILOGD("[Test]Begin to excute handle."); 58 ASSERT_NE(handle, nullptr); 59 FUNC_ADD addFunc = reinterpret_cast<FUNC_ADD>(AieDlsym(handle, "AddFunc")); 60 ASSERT_NE(addFunc, nullptr); 61 int result = addFunc(AIE_NUM1, AIE_NUM2); 62 ASSERT_EQ(result, AIE_RESULT); 63 AieDlclose(handle); 64 } 65