blob: 7100756a86d0bbe66350b9351bd31351eee4b8eb [file] [log] [blame]
b.liu8583dce2024-04-03 13:30:08 +08001#include <stdlib.h>
2#include <stdio.h>
3#include <string.h>
4#include <sys/types.h>
5#include <sys/stat.h>
6#include <unistd.h>
7#include <dlfcn.h>
8#include <errno.h>
9#include <fcntl.h>
10#include <lynq/lynq-qser-autosuspend.h>
11
12#define FILE_LOCK_TABLE "/tmp/.lock_table"
13
14#define MAX_LOCK_NUM 128
15
16static void qser_lpm_handler(qser_lpm_edge_t edge_state)
17{
18 printf("this is qser_lpm_handler, edge_state=%d\n", edge_state);
19
20}
21
22static void printUsage(void)
23{
24 printf("-i --qser_lpm_init\n");
25 printf("-d --qser_lpm_deinit\n");
26 printf("-q --quit\n");
27 printf("-e --qser_autosuspend_enable\n");
28 printf("-cl [wakelock name] --qser_wakelock_create \n");
29 printf("-al [wakelock num] --qser_wakelock_lock \n");
30 printf("-rl [wakelock num] --qser_wakelock_unlock \n");
31 printf("-dl [wakelock num] --qser_wakelock_destroy\n");
32 printf("-ws [whitelist num] --qser_whitelist_set\n");
33 printf("-wg --qser_whitelist_get\n");
34 printf("-ccl --check created locks\n");
35 printf("-cll --check lockup locks\n");
36 printf("-cws --check wakeup sources\n");
37 printf("Please input an cmd:");
38}
39
40
41int check_lock(void)
42{
43 int err;
44 int file_fd;
45 int i;
46 int ret;
47 LOCK_TABLE lock_status;
48 file_fd = open(FILE_LOCK_TABLE,O_RDWR);
49 if(file_fd < 0)
50 {
51 err = errno;
52 printf("Error open lock_table file:%s\n", strerror(errno));
53 return -2;
54 }
55
56 memset(&lock_status, 0, sizeof(lock_status));
57 lseek(file_fd,0,SEEK_SET);
58 ret = read(file_fd,(unsigned char *)&lock_status,sizeof(lock_status));
59 if(ret <= 0)
60 {
61 close(file_fd);
62 return -2;
63 }
64 for(i=0;i<MAX_LOCK_NUM;i++)
65 {
66 if(strlen(lock_status.lock_name[i]) != 0)
67 {
68 printf("fd: %d lock_name:%s strlen:%d, pid=%d\n", i, lock_status.lock_name[i], strlen(lock_status.lock_name[i]), lock_status.lock_pid[i]);
69 }
70 }
71
72 close(file_fd);
73 return 0;
74
75}
76
77
78void delete_enter(char *data)
79{
80 char *find = strchr(data, '\n');
81 if(find)
82 *find = '\0';
83 return ;
84}
85
86int main(int argc,char** argv)
87{
88
89 int num;
90 int ret;
91 int len;
92 FILE *fp;
93 char buf[256];
94 char cmd[64];
95 char *cmd2;
96 char *cmd1;
97 char tmp[8];
98 qser_pm_cfg_t *qser_lpm_cfg = NULL;
99 qser_lpm_cfg = (qser_pm_cfg_t *)malloc(sizeof(qser_pm_cfg_t));
100 qser_lpm_cfg->wakeupin.wakeupin_pin = 50;
101 qser_lpm_cfg->wakeupin.wakeupin_edge = E_QL_LPM_FALLING;
102 while(1)
103 {
104 printUsage();
105 memset(cmd,0,sizeof(cmd));
106 fgets(cmd, sizeof(cmd), stdin);
107 cmd1 = strtok(cmd, " ");
108 cmd2 = strtok(NULL, " ");
109 delete_enter(cmd1);
110 printf("cmd1:%s\n", cmd1);
111 if(strcmp(cmd1,"-i") == 0)
112 {
113 ret = qser_lpm_init( qser_lpm_handler, qser_lpm_cfg);
114 if(ret != 0)
115 {
116 printf("lpm init fail\n");
117 break;
118 }
119 else
120 {
121 printf("lpm init success\n");
122 }
123 }
124 else if(strcmp(cmd1,"-e") == 0)
125 {
126 char num='1';
127 ret = qser_autosuspend_enable(num);
128 if(ret != 0)
129 {
130 printf("qser_autosuspend_enable fail\n");
131 }
132 else
133 {
134 printf("qser_autosuspend_enable success\n");
135 }
136 }
137 else if(strcmp(cmd1,"-cl") == 0)
138 {
139 if(cmd2 == NULL)
140 {
141 printf("name is null\n");
142 continue;
143 }
144 len = strlen(cmd2);
145 printf("len =%d\n", len);
146 ret = qser_wakelock_create(cmd2, len);
147 if(ret < 0)
148 {
149 printf("wakelock create fail\n");
150 printf("ret=%d\n", ret);
151 }
152 else
153 {
154 printf("wakelock create success\n");
155 printf("fd=%d\n", ret);
156 }
157 }
158 else if (strcmp(cmd1,"-al") == 0)
159 {
160 if(cmd2 == NULL)
161 {
162 printf("fd is null\n");
163 continue;
164 }
165 num = atoi(cmd2);
166 ret = qser_wakelock_lock(num);
167 if(ret != 0)
168 {
169 printf("wakelock lock fail\n");
170 printf("ret=%d\n", ret);
171 }
172 else
173 {
174 printf("wakelock lock success\n");
175 }
176 }
177
178 else if (strcmp(cmd1,"-rl") == 0)
179 {
180 if(cmd2 == NULL)
181 {
182 printf("fd is null\n");
183 continue;
184 }
185 num = atoi(cmd2);
186 ret = qser_wakelock_unlock(num);
187 if(ret != 0)
188 {
189 printf("wakelock unlock fail\n");
190 printf("ret=%d\n", ret);
191 }
192 else
193 {
194 printf("wakelock unlock success\n");
195 }
196 }
197 else if(strcmp(cmd1,"-dl") == 0)
198 {
199 if(cmd2 == NULL)
200 {
201 printf("fd is null\n");
202 continue;
203 }
204 num = atoi(cmd2);
205 ret = qser_wakelock_destroy(num);
206 if(ret != 0)
207 {
208 printf("wakelock destroy fail\n");
209 printf("ret=%d\n", ret);
210 }
211 else
212 {
213 printf("wakelock destroy success\n");
214 }
215 }
216 else if(strcmp(cmd1, "-ws") == 0)
217 {
218 if(cmd2 == NULL)
219 {
220 printf("num is null\n");
221 continue;
222 }
223 delete_enter(cmd2);
224 ret = qser_whitelist_set(cmd2);
225 if(ret != 0)
226 {
227 printf("qser_whitlist_set fail\n");
228 printf("ret=%d\n", ret);
229 }
230 else
231 {
232 printf("qser_whitlist_set success\n");
233 }
234 }
235 else if(strcmp(cmd1, "-wg") == 0)
236 {
237 ret = qser_whitelist_get(tmp);
238 if(ret != 0)
239 {
240 printf("qser_whitlist_set fail\n");
241 }
242 else
243 {
244 printf("qser_whitlist_set success\n");
245 printf("ret=%d, whilelist state is %s\n", ret, tmp);
246 }
247 }
248 else if(strcmp(cmd1,"-ccl") == 0)
249 {
250 int ret;
251 ret = check_lock();
252 if(ret != 0)
253 {
254 printf("check lock fail\n");
255 printf("ret=%d\n", ret);
256 }
257 else
258 {
259 printf("check lock success\n");
260 }
261 }
262 else if(strcmp(cmd1,"-cll") == 0)
263 {
264 int ret;
265 ret = system("cat /sys/power/wake_lock");
266 if(ret != 0)
267 {
268 printf("check created lock fail\n");
269 }
270 }
271 else if(strcmp(cmd1,"-cws") == 0)
272 {
273 printf("start check active wakeup_sources !!!\n");
274 memset(buf,0,sizeof(buf));
275 fp = popen("cat /sys/kernel/debug/wakeup_sources|sed -e 's/\"^ \"/\"unnamed\"/g' | awk '{print $6 \"\t\" $1}'| grep -v \"^0\" |sort -n \n","r");
276 while(fgets(buf, 255, fp) != NULL)
277 {
278 printf("%s", buf);
279 }
280 pclose(fp);
281 }
282 else if(strcmp(cmd1, "-d") == 0)
283 {
284 ret = qser_lpm_deinit();
285 if(ret != 0)
286 {
287 printf("lpm deinit fail\n");
288 }
289 else
290 {
291 printf("lpm deinit success\n");
292 }
293 }
294 else if(strcmp(cmd1,"-q") == 0)
295 {
296 break;
297 }
298 }
299
300 return 0;
301
302}