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
16 #include <stdlib.h>
17 #include "functionalext.h"
18
19 extern int __cxa_atexit(void (*func)(void *), void *arg, void *dso);
20 const int32_t INVALID_LEN = -1;
21 const int32_t INIT_LEN = 0;
22 const int32_t INCREASE_LEN = 1;
23 const int32_t COUNT = 32;
24 const int32_t SLOT_LEN = 10;
exitFunc(void * arg)25 void exitFunc(void *arg){};
26
27 /**
28 * @tc.name: cxa_atexit_0100
29 * @tc.desc: Verify cxa_atexit process success when second and third args is null.
30 * @tc.level: level 1.
31 */
cxa_atexit_0100(void)32 void cxa_atexit_0100(void)
33 {
34 int32_t ret = __cxa_atexit(exitFunc, NULL, NULL);
35 EXPECT_EQ("cxa_atexit_0100", ret, INIT_LEN);
36 }
37
38 /**
39 * @tc.name: cxa_atexit_0200
40 * @tc.desc: Verify cxa atexit process success when third args is null and slot less than COUNT.
41 * @tc.level: level 0.
42 */
cxa_atexit_0200(void)43 void cxa_atexit_0200(void)
44 {
45 int32_t slot = SLOT_LEN;
46 int32_t var = INIT_LEN;
47 int32_t ret = __cxa_atexit(exitFunc, &var, NULL);
48 EXPECT_LT("cxa_atexit_0200", slot + INCREASE_LEN, COUNT);
49 EXPECT_EQ("cxa_atexit_0200", ret, 0);
50 }
51
52 /**
53 * @tc.name: cxa_atexit_0300
54 * @tc.desc: Verify cxa atexit process success when third args is null and slot equal COUNT.
55 * @tc.level: level 1.
56 */
cxa_atexit_0300(void)57 void cxa_atexit_0300(void)
58 {
59 int32_t slot = COUNT;
60 int32_t var = 0;
61 int32_t ret = __cxa_atexit(exitFunc, &var, NULL);
62 EXPECT_EQ("cxa_atexit_0300", slot, COUNT);
63 EXPECT_EQ("cxa_atexit_0300", ret, 0);
64 }
65
main(int argc,char * argv[])66 int main(int argc, char *argv[])
67 {
68 cxa_atexit_0100();
69 cxa_atexit_0200();
70 cxa_atexit_0300();
71 return t_status;
72 }
73