• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2024 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 #ifndef GWP_ASAN_TEST_H
17 #define GWP_ASAN_TEST_H
18 
19 #include <stdbool.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include "gwp_asan.h"
24 
config_gwp_asan_environment(bool logPath)25 void config_gwp_asan_environment(bool logPath)
26 {
27     system("param set gwp_asan.sample.all true");
28 
29     // If gwp_asan is inited by __dls3,
30     // it just samples some allocations randomly,
31     // the test may not be able to trigger the error,
32     // so just skip the test.
33     if (!may_init_gwp_asan(true)) {
34         system("param set gwp_asan.sample.all false");
35         printf("Skip gwp_asan test because it may be inited by __dls3 randomly, just rerun the test.\n");
36         exit(0);
37     }
38 
39     if (logPath) {
40         system("param set gwp_asan.log.path file");
41     }
42 }
43 
cancel_gwp_asan_environment(bool logPath)44 void cancel_gwp_asan_environment(bool logPath)
45 {
46     if (logPath) {
47         system("param set gwp_asan.log.path default");
48     }
49     system("param set gwp_asan.sample.all false");
50 }
51 
send_sig36(void)52 void send_sig36(void)
53 {
54     pid_t pid = getpid();
55 
56     char command[64];
57     snprintf(command, sizeof(command), "kill -36 %d", pid);
58     system(command);
59     printf("Exec command: %s .\n", command);
60 }
61 
62 #endif
63