move manifest to packaging directory
[platform/adaptation/intel_mfld/device-manager-plugin-mfld-blackbay.git] / src / test / slp_plugin_test.c
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <stdlib.h>
4 #include <errno.h>
5 #include <string.h>
6 #include <devman_plugin_intf.h>
7 #include <devman.h>
8 #include <svi.h>
9
10 #define TEST_GET(_func, _value) {\
11         if((err = _func(&(_value))) < 0) { \
12                 printf("test "#_func" err:%d\n", err);\
13         } else {\
14                 printf(#_func" get value: %d OK\n", _value); \
15         }\
16 }\
17
18 #define TEST_SET(_func, _value) {\
19         if((err = _func(_value)) < 0) { \
20                 printf("test "#_func" err:%d\n", err);\
21         } else {\
22                 printf("test "#_func" OK\n");\
23         }\
24 }\
25
26 #define TEST_INDEX_GET(_func, _index, _value) {\
27         if((err = _func(_index, &(_value))) < 0) { \
28                 printf("test "#_func" ,index = %d err:%d\n", _index, err);\
29         } else {\
30                 printf(#_func" ,index = %d get value: %d OK\n", _index, _value); \
31         }\
32 }\
33
34 #define TEST_INDEX_SET(_func, _index, _value) {\
35         if((err = _func(_index, _value)) < 0) { \
36                 printf("test "#_func" ,index = %d err:%d\n", _index, err);\
37         } else {\
38                 printf("test "#_func" ,index = %d OK\n", _index);\
39         }\
40 }\
41
42 int err = 0;
43
44 void test_set_enable()
45 {
46         int value;
47
48         printf("set enable value (0:disable,1:enable,-1:quit):");
49         if((err = scanf("%d", &value)) <= 0) {
50                 return;
51         }
52
53         if(value == -1)
54                 return;
55
56         TEST_SET(OEM_sys_set_haptic_motor_enable, value);
57 }
58
59 void test_get_max_level()
60 {
61         int max_level;
62
63         TEST_GET(OEM_sys_get_haptic_motor_level_max, max_level);
64 }
65
66 int test_set_level()
67 {
68         int level;
69
70         while(1) {
71                 printf("set level (-1:quit):");
72                 if((err = scanf("%d", &level)) <= 0) {
73                         return -1;
74                 }
75
76                 switch(level) {
77                         case 0 ... 100:
78                                 TEST_SET(OEM_sys_set_haptic_motor_level, level);
79                                 printf("set level: %d\n", level);
80                         case -1:
81                                 return 0;
82                         default:
83                                 break;
84                 }
85         }
86         return 0;
87 }
88
89 void test_get_level()
90 {
91         int value;
92         TEST_GET(OEM_sys_get_haptic_motor_level, value);
93 }
94
95 void test_one_shot()
96 {
97         int value;
98
99         printf("set oneshot times :");
100         if((err = scanf("%d", &value)) <= 0) {
101                 printf("scanf failed %d\n", err);
102                 return;
103         }
104
105         TEST_SET(OEM_sys_set_haptic_motor_oneshot, value);
106 }
107
108 void svi_test()
109 {
110         int r = 0;
111         int handle = 0;
112
113         r = svi_init(&handle);
114         if (r != SVI_SUCCESS){
115                 printf("Cannot initialize svi.\n");
116         } else {
117 #if 0
118                 r = svi_play (handle, SVI_VIB_TOUCH_TOUCH, SVI_SND_TOUCH_TOUCH1);
119                 if (r != SVI_SUCCESS) {
120                         printf("Cannot play sound or vibration.\n");
121                 }
122 #endif
123
124 #if 0
125                 r = svi_play_sound (handle, SVI_SND_TOUCH_TOUCH1);
126                 if (r != SVI_SUCCESS) {
127                         printf("Cannot play sound.\n");
128                 }
129 #endif
130
131
132 #if 1
133                 r = svi_play_vib (handle, SVI_VIB_OPERATION_VIBRATION);
134                 if (r != SVI_SUCCESS) {
135                         printf("Cannot play vibration.\n");
136                 }
137 #endif
138                 // don't close handle too fast, vibrator needs time to boost
139                 sleep(1);
140
141                 r = svi_fini(handle);
142                 if (r != SVI_SUCCESS) {
143                         printf("Cannot close svi.\n");
144                 }
145         }
146 }
147
148 void vib_test()
149 {
150         char input,tmp;
151
152         while(1) {
153                 printf("=======================1. vib_test==========================\n");
154                 printf("1 : test OEM_sys_get_haptic_motor_level_max\n");
155                 printf("2 : test OEM_sys_get_haptic_motor_level\n");
156                 printf("3 : test OEM_sys_set_haptic_motor_level\n");
157                 printf("4 : test OEM_sys_set_haptic_motor_enable\n");
158                 printf("5 : test OEM_sys_set_haptic_motor_oneshot\n");
159                 printf("q : quit\n");
160                 printf("============================================================\n");
161
162                 scanf("%c", &input);
163                 while((tmp = getchar()) != '\n');
164
165                 switch(input) {
166                         case '1':
167                                 test_get_max_level();
168                                 break;
169                         case '2':
170                                 test_get_level();
171                                 break;
172                         case '3':
173                                 test_set_level();
174                                 break;
175                         case '4':
176                                 test_set_enable();
177                                 break;
178                         case '5':
179                                 test_one_shot();
180                                 break;
181                         case 'q':
182                                 return;
183                         default:
184                                 break;
185                 }
186         }
187 }
188
189 void battery_test()
190 {
191         int value;
192
193         TEST_GET(OEM_sys_get_battery_capacity, value);
194         TEST_GET(OEM_sys_get_battery_capacity_raw, value);
195         TEST_GET(OEM_sys_get_battery_charge_full, value);
196         TEST_GET(OEM_sys_get_battery_charge_now, value);
197         TEST_GET(OEM_sys_get_battery_present, value);
198         TEST_GET(OEM_sys_get_battery_health, value);
199         TEST_GET(OEM_sys_get_battery_polling_required, value);
200         TEST_GET(OEM_sys_get_battery_support_insuspend_charging, value);
201 }
202
203 void powner_test()
204 {
205         int value;
206
207         TEST_GET(OEM_sys_get_power_wakeup_count, value);
208         TEST_SET(OEM_sys_set_power_wakeup_count, value);
209         TEST_SET(OEM_sys_set_power_state, POWER_STATE_SUSPEND);
210         TEST_SET(OEM_sys_set_power_state, POWER_STATE_PRE_SUSPEND);
211         TEST_SET(OEM_sys_set_power_state, POWER_STATE_POST_RESUME);
212 }
213
214 void cpufreq_test()
215 {
216         int value;
217
218         TEST_GET(OEM_sys_get_cpufreq_cpuinfo_max_freq, value);
219         TEST_GET(OEM_sys_get_cpufreq_cpuinfo_min_freq, value);
220         TEST_GET(OEM_sys_get_cpufreq_scaling_max_freq, value);
221         TEST_SET(OEM_sys_set_cpufreq_scaling_max_freq, value);
222         TEST_GET(OEM_sys_get_cpufreq_scaling_min_freq, value);
223         TEST_SET(OEM_sys_set_cpufreq_scaling_min_freq, value);
224 }
225
226 void jack_test()
227 {
228         int value;
229
230         TEST_GET(OEM_sys_get_jack_charger_online, value);
231         TEST_GET(OEM_sys_get_jack_earjack_online, value);
232         TEST_GET(OEM_sys_get_jack_earkey_online, value);
233         TEST_GET(OEM_sys_get_jack_hdmi_online, value);
234         TEST_GET(OEM_sys_get_jack_usb_online, value);
235         TEST_GET(OEM_sys_get_jack_cradle_online, value);
236         TEST_GET(OEM_sys_get_jack_tvout_online, value);
237         TEST_GET(OEM_sys_get_jack_keyboard_online, value);
238 }
239
240 void backlight_test()
241 {
242         int value, power_saving, index, i;
243
244         OEM_sys_get_display_count(&index);
245
246         for(i = 0; i < index; i++) {
247                 printf("================= test index = %d ==================\n", i);
248                 TEST_INDEX_GET(OEM_sys_get_backlight_min_brightness, i, value);
249                 TEST_INDEX_GET(OEM_sys_get_backlight_max_brightness, i, value);
250
251                 if((err = OEM_sys_get_backlight_brightness(i, &value, 0)) < 0) {
252                         printf("test OEM_sys_get_backlight_brightness power_saving = 0 err:%d\n", err);
253                 } else {
254                         printf("OEM_sys_get_backlight_brightness power_saving = 0 get value: %d OK\n", value);
255                 }
256
257                 if((err = OEM_sys_get_backlight_brightness(i, &value, 1)) < 0) {
258                         printf("test OEM_sys_get_backlight_brightness  power_saving = 1 err:%d\n", err);
259                 } else {
260                         printf("OEM_sys_get_backlight_brightness power_saving = 1 get value: %d OK\n", value);
261                 }
262
263                 if((err = OEM_sys_set_backlight_brightness(i, &value, 0)) < 0) {
264                         printf("test OEM_sys_set_backlight_brightness  power_saving = 0 err:%d\n", err);
265                 } else {
266                         printf("OEM_sys_set_backlight_brightness  power_saving = 0 get value: %d OK\n", value);
267                 }
268
269                 if((err = OEM_sys_set_backlight_brightness(i, &value, 1)) < 0) {
270                         printf("test OEM_sys_set_backlight_brightness  power_saving = 1 err:%d\n", err);
271                 } else {
272                         printf("OEM_sys_set_backlight_brightness  power_saving = 1 get value: %d OK\n", value);
273                 }
274
275                 OEM_sys_get_backlight_brightness(i, &value, 1);
276
277                 TEST_INDEX_SET(OEM_sys_set_backlight_dimming, i, 1);
278                 TEST_INDEX_GET(OEM_sys_get_backlight_acl_control, i, value);
279                 TEST_INDEX_SET(OEM_sys_set_backlight_acl_control, i, value)
280         }
281 }
282
283 int main()
284 {
285         char input,tmp;
286
287         OEM_sys_get_devman_plugin_interface();
288
289         while(1) {
290                 printf("===================slp_device_manager_plugin test====================\n");
291                 printf("1 : vib_test\n");
292                 printf("2 : svi_test\n");
293                 printf("3 : battery_test\n");
294                 printf("4 : power_test\n");
295                 printf("5 : cpufreq_test\n");
296                 printf("6 : jack_test\n");
297                 printf("7 : backlight\n");
298                 printf("q : quit\n");
299                 printf("=====================================================================\n");
300
301                 scanf("%c", &input);
302                 while((tmp = getchar()) != '\n');
303
304                 switch(input) {
305                         case '1':
306                                 vib_test();
307                                 break;
308                         case '2':
309                                 svi_test();
310                                 break;
311                         case '3':
312                                 battery_test();
313                                 break;
314                         case '4':
315                                 powner_test();
316                                 break;
317                         case '5':
318                                 cpufreq_test();
319                                 break;
320                         case '6':
321                                 jack_test();
322                                 break;
323                         case '7':
324                                 backlight_test();
325                                 break;
326                         case 'q':
327                                 return 0;
328                         default:
329                                 break;
330                 }
331         }
332         return 0;
333 }