1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
/*******************************************************************************
* Copyright (c) 2013 Linaro
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Linaro <linaro-dev@lists.linaro.org>
*******************************************************************************/
/*
* logger-dev-test.c Trivial Android logger-dev unit test
*
* By: AppalaNaidu Bade <appala.bade@linaro.org>
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#ifdef UBUNTU_LOGGER
#include <sys/ioctl.h>
#define __LOGGERIO 0xAE
#define LOGGER_GET_LOG_BUF_SIZE _IO(__LOGGERIO, 1) /* size of log */
#define LOGGER_GET_LOG_LEN _IO(__LOGGERIO, 2) /* used log len */
#define LOGGER_GET_NEXT_ENTRY_LEN _IO(__LOGGERIO, 3) /* next entry len */
#define LOGGER_FLUSH_LOG _IO(__LOGGERIO, 4) /* flush log */
#define LOGGER_LOG_RADIO "/dev/log_radio"
#define LOGGER_LOG_EVENTS "/dev/log_events"
#define LOGGER_LOG_SYSTEM "/dev/log_system"
#define LOGGER_LOG_MAIN "/dev/log_main"
#else
#include <cutils/logger.h>
#define LOGGER_LOG_RADIO "/dev/log/radio"
#define LOGGER_LOG_EVENTS "/dev/log/events"
#define LOGGER_LOG_SYSTEM "/dev/log/system"
#define LOGGER_LOG_MAIN "/dev/log/main"
#endif // UBUNTU_LOGGER
void show_help()
{
printf("Usage:\n loggerdevtest logdevicename(main/events/radio/system)\n\n");
return;
}
int clearlog(int logfd)
{
return ioctl(logfd, LOGGER_FLUSH_LOG);
}
int getlogsize(int logfd)
{
return ioctl(logfd, LOGGER_GET_LOG_BUF_SIZE);
}
int getlogreadablesize(int logfd)
{
return ioctl(logfd, LOGGER_GET_LOG_LEN);
}
int getlognextentrysize(int logfd)
{
return ioctl(logfd, LOGGER_GET_NEXT_ENTRY_LEN);
}
int main(int argc, char *argv[])
{
char *logdevicename;
int log_fd;
int log_ret;
if (argc !=2) {
show_help();
exit(0);
}
if (strcmp(argv[argc-1],"help") == 0) {
show_help();
exit(0);
}
if(strcmp(argv[argc-1],"main")==0)
logdevicename = LOGGER_LOG_MAIN;
else if(strcmp(argv[argc-1], "events")==0)
logdevicename = LOGGER_LOG_EVENTS;
else if(strcmp(argv[argc-1], "radio")==0)
logdevicename = LOGGER_LOG_RADIO;
else if(strcmp(argv[argc-1], "system")==0)
logdevicename = LOGGER_LOG_SYSTEM;
else {
printf("wrong input check usage and try again\n");
exit(0);
}
log_fd = open(logdevicename,O_RDWR);
if (log_fd < 0) {
printf("FAIL :Failed to open %s \n",logdevicename);
exit(EXIT_FAILURE);
} else
printf("PASS :Able to open %s logdevice and fd is %d\n", logdevicename,log_fd);
log_ret = getlogsize(log_fd);
if(log_ret < 0) {
printf("FAIL : Failed to get %s logdevice size \n ", logdevicename);
perror("ioctl:\n");
} else
printf("PASS : %s logdevice size = %d\n",logdevicename,log_ret);
log_ret = getlogreadablesize(log_fd);
if(log_ret < 0){
printf("FAIL : Failed to get %s logdevice readablesize\n", logdevicename);
perror("ioctl:\n");
} else
printf("PASS : %s logdevice readablesize = %d\n", logdevicename,log_ret);
log_ret = getlognextentrysize(log_fd);
if(log_ret < 0) {
printf("FAIL : Failed to get %s logdevice size of next log entry\n" , logdevicename);
perror("ioctl:\n");
} else
printf("PASS : %s logdevice size of next log entry = %d\n", logdevicename,log_ret);
log_ret = clearlog(log_fd);
if(log_ret) {
printf("FAIL : Failed to clear the log of data %s logdevice\n" , logdevicename);
perror("ioctl:\n");
} else
printf("PASS : clears the log of data %s logdevice\n" , logdevicename);
close(log_fd);
exit(0);
}
|