Add crash manager API
[platform/core/system/crash-worker.git] / tests / system / utils / libcrash-servicetest.c
1 #include <libcrash-service.h>
2
3 #include <linux/limits.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7
8 void help(char *argv_0)
9 {
10         printf("Usage: %s [-r dump_reason] pid\n", argv_0);
11 }
12
13 int main(int argc, char *argv[])
14 {
15         int opt;
16         const char *dump_reason = NULL;
17
18         while ((opt = getopt(argc, argv, "r:")) != -1) {
19                 switch (opt) {
20                 case 'r':
21                         dump_reason = optarg;
22                         break;
23                 default:
24                         help(argv[0]);
25                         exit(EXIT_FAILURE);
26                 }
27         }
28
29         if (dump_reason == NULL)
30                 dump_reason = "no reason";
31
32         if (optind >= argc) {
33                 help(argv[0]);
34                 exit(EXIT_FAILURE);
35         }
36         pid_t pid = strtol(argv[optind], NULL, 10);
37         if (pid == 0) {
38                 printf("ERROR: pid must be a number\n");
39                 help(argv[0]);
40                 return EXIT_FAILURE;
41         }
42
43         char BUFF[PATH_MAX];
44         bool res = livedump_pid(pid, dump_reason, BUFF, PATH_MAX);
45         printf("res: %s\nreport_path: %s\n", res ? "true" : "false", BUFF);
46         return res ? EXIT_SUCCESS : EXIT_FAILURE;
47 }