Remove a useless field
[platform/core/system/dlog.git] / tests / test_libdlog.c
1 #define LOG_TAG "SRPOL_LOGGER"
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <pthread.h>
7
8 #include <dlog.h>
9 #include <logcommon.h>
10
11 void *func(void *data)
12 {
13         (void) data;
14         int i;
15
16         for (i = 0; i < 10000; ++i)
17                 LOGE("Multithreading test %d", i);
18
19         return NULL;
20 }
21
22 int main(int argc, char **argv)
23 {
24         if (argc == 1) {
25                 char *const huge_buffer = malloc(LOG_MAX_PAYLOAD_SIZE * 3);
26                 if (!huge_buffer)
27                         return 1;
28
29                 char buffer[LOG_MAX_PAYLOAD_SIZE - 20 /* leeway for tag, prio etc */];
30                 int i;
31                 pthread_t threads[50];
32
33                 // check buffer overflow
34                 for (int i = 0; i < 3; ++i)
35                         memset(huge_buffer + i * LOG_MAX_PAYLOAD_SIZE, 'a' + i, LOG_MAX_PAYLOAD_SIZE);
36                 huge_buffer[LOG_MAX_PAYLOAD_SIZE * 3 - 1] = '\0';
37
38                 LOGE("%s", huge_buffer);
39
40                 // check garbage data
41                 for (size_t i = 0; i < sizeof buffer; ++i)
42                         buffer[i] = rand() & 255;
43
44                 LOGE("%s", buffer);
45
46                 // check multithreading
47                 for (i = 0; i < 50; ++i)
48                         pthread_create(threads + i, NULL, func, NULL);
49
50                 for (i = 0; i < 50; ++i)
51                         pthread_join(threads[i], NULL);
52
53                 free(huge_buffer);
54
55                 return 0;
56         } else {
57                 int mode = 0;
58                 int count = atoi(argv[1]);
59
60                 while (count--) {
61                         if (mode) // alternate logging levels to allow testing of filters
62                                 LOGE("%s", "test data, level: error");
63                         else
64                                 LOGI("%s", "test data, level: info");
65
66                         mode = !mode;
67                 }
68         }
69
70         return 0;
71 }