• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <signal.h>
17 #include <sys/time.h>
18 #include "functionalext.h"
19 
20 extern int __getitimer_time64(int, struct itimerval *);
21 
22 static int count = 0;
expireTimer(int signo)23 void expireTimer(int signo)
24 {
25     struct itimerval val;
26     count++;
27     if (count > 1) {
28         __getitimer_time64(signo, &val);
29         val.it_value.tv_sec = 0;
30         val.it_value.tv_usec = 0;
31         setitimer(signo, &val, NULL);
32         count = 0;
33     }
34 }
35 
signalHandler(int signo)36 void signalHandler(int signo)
37 {
38     switch (signo) {
39         case SIGALRM:
40             printf("catch a SIGALRM signal\n");
41             expireTimer(signo);
42             break;
43         case SIGVTALRM:
44             printf("catch a SIGVTALRM signal\n");
45             break;
46         case SIGPROF:
47             printf("catch a SIGPROF signal\n");
48             break;
49         default:
50             printf("no signal\n");
51             break;
52     }
53 }
54 
55 /**
56  * @tc.name      : getitimer_0100
57  * @tc.desc      : Verify the value of the interval timer (parameter is ITIMER_REAL)
58  * @tc.level     : Level 0
59  */
getitimer_time64_0100(void)60 void getitimer_time64_0100(void)
61 {
62     signal(SIGALRM, signalHandler);
63     struct itimerval old;
64     int result = __getitimer_time64(ITIMER_REAL, &old);
65     EXPECT_EQ("getitimer_time64_0100", result, 0);
66 }
67 
main(void)68 int main(void)
69 {
70     getitimer_time64_0100();
71     return t_status;
72 }