9 #define DBG(...) EINA_LOG_DBG(__VA_ARGS__)
10 #define INF(...) EINA_LOG_INFO(__VA_ARGS__)
11 #define WRN(...) EINA_LOG_WARN(__VA_ARGS__)
12 #define ERR(...) EINA_LOG_ERR(__VA_ARGS__)
14 static int success = 0;
15 static int failure = 0;
16 static Ecore_Timer *exiter = NULL;
19 _test_string_get(E_Connman_Element *element, const char *name, bool (*func)(const E_Connman_Element *element, const char **value))
24 INF("BEGIN: testing string get %s of element %s...\n", name, element->path);
25 ret = func(element, &value);
27 INF("SUCCESS: testing string get %s of element %s: %s\n",
28 name, element->path, value);
30 WRN("FAILURE: testing string get %s of element %s\n",
37 _test_bool_get(E_Connman_Element *element, const char *name, bool (*func)(const E_Connman_Element *element, bool *value))
41 INF("BEGIN: testing bool get %s of element %s...\n", name, element->path);
42 ret = func(element, &value);
44 INF("SUCCESS: testing bool get %s of element %s: %hhu\n",
45 name, element->path, value);
47 WRN("FAILURE: testing bool get %s of element %s\n",
54 _test_uchar_get(E_Connman_Element *element, const char *name, bool (*func)(const E_Connman_Element *element, unsigned char *value))
59 INF("BEGIN: testing uchar get %s of element %s...\n", name, element->path);
60 ret = func(element, &value);
62 INF("SUCCESS: testing uchar get %s of element %s: %hhu\n",
63 name, element->path, value);
65 WRN("FAILURE: testing uchar get %s of element %s\n",
72 _test_ushort_get(E_Connman_Element *element, const char *name, bool (*func)(const E_Connman_Element *element, unsigned short *value))
77 INF("BEGIN: testing ushort get %s of element %s...\n", name, element->path);
78 ret = func(element, &value);
80 INF("SUCCESS: testing ushort get %s of element %s: %hu\n",
81 name, element->path, value);
83 WRN("FAILURE: testing ushort get %s of element %s\n",
90 _test_uchar_array_get(E_Connman_Element *element, const char *name, bool (*func)(const E_Connman_Element *element, unsigned int *count, unsigned char **value))
96 INF("BEGIN: testing ushort get %s of element %s...\n", name, element->path);
97 ret = func(element, &count, &value);
100 INF("SUCCESS: testing ushort get %s of element %s: %p\n",
101 name, element->path, value);
105 WRN("FAILURE: testing ushort get %s of element %s\n",
106 name, element->path);
112 _test_element_get(E_Connman_Element *element, const char *name, bool (*func)(const E_Connman_Element *element, E_Connman_Element **value))
114 E_Connman_Element *value;
117 INF("BEGIN: testing element get %s of element %s...\n", name, element->path);
118 ret = func(element, &value);
120 INF("SUCCESS: testing element get %s of element %s: %p\n",
121 name, element->path, value);
123 WRN("FAILURE: testing element get %s of element %s\n",
124 name, element->path);
130 _test_elements_get(E_Connman_Element *element, const char *name, bool (*func)(const E_Connman_Element *element, unsigned int *count, E_Connman_Element ***elements))
132 E_Connman_Element **value;
136 INF("BEGIN: testing elements get %s of element %s...\n",
137 name, element->path);
138 ret = func(element, &count, &value);
141 INF("SUCCESS: testing elements get %s of element %s: %p\n",
142 name, element->path, value);
146 WRN("FAILURE: testing elements get %s of element %s\n",
147 name, element->path);
153 _test_element_get_global(const char *name, bool (*func)(E_Connman_Element **value))
155 E_Connman_Element *value;
158 INF("BEGIN: testing element get %s\n", name);
161 INF("SUCCESS: testing element get %s: %p\n", name, value);
163 WRN("FAILURE: testing element get %s\n", name);
169 _test_elements_get_global(const char *name, bool (*func)(unsigned int *count, E_Connman_Element ***elements))
171 E_Connman_Element **value;
175 INF("BEGIN: testing elements get %s\n", name);
176 ret = func(&count, &value);
179 INF("SUCCESS: testing elements get %s: %p\n", name, value);
183 WRN("FAILURE: testing elements get %s\n", name);
189 _test_string_get_global(const char *name, bool (*func)(const char **value))
194 INF("BEGIN: testing string get %s...\n", name);
197 INF("SUCCESS: testing string get %s: %s\n", name, value);
199 WRN("FAILURE: testing string get %s\n", name);
205 _test_bool_get_global(const char *name, bool (*func)(bool *value))
209 INF("BEGIN: testing bool get %s...\n", name);
212 INF("SUCCESS: testing bool get %s: %hhu\n", name, value);
214 WRN("FAILURE: testing bool get %s\n", name);
220 _test_strings_get_global(const char *name, bool (*func)(unsigned int *count, const char ***elements))
226 INF("BEGIN: testing strings get %s\n", name);
227 ret = func(&count, &value);
230 INF("SUCCESS: testing strings get %s: %p\n", name, value);
234 WRN("FAILURE: testing strings get %s\n", name);
244 TEST_DESC_TYPE_STRING_GET,
245 TEST_DESC_TYPE_BOOL_GET,
246 TEST_DESC_TYPE_UCHAR_GET,
247 TEST_DESC_TYPE_USHORT_GET,
248 TEST_DESC_TYPE_UCHAR_ARRAY_GET,
249 TEST_DESC_TYPE_ELEMENT_GET,
250 TEST_DESC_TYPE_ELEMENTS_GET,
251 TEST_DESC_TYPE_ELEMENT_GET_GLOBAL,
252 TEST_DESC_TYPE_ELEMENTS_GET_GLOBAL,
253 TEST_DESC_TYPE_STRING_GET_GLOBAL,
254 TEST_DESC_TYPE_BOOL_GET_GLOBAL,
255 TEST_DESC_TYPE_STRINGS_GET_GLOBAL,
259 bool (*string_get)(const E_Connman_Element *element, const char **value);
260 bool (*bool_get)(const E_Connman_Element *element, bool *value);
261 bool (*uchar_get)(const E_Connman_Element *element, unsigned char *value);
262 bool (*ushort_get)(const E_Connman_Element *element, unsigned short*value);
263 bool (*uchar_array_get)(const E_Connman_Element *element, unsigned int *count, unsigned char **value);
264 bool (*element_get)(const E_Connman_Element *element, E_Connman_Element **value);
265 bool (*elements_get)(const E_Connman_Element *element, unsigned int *count, E_Connman_Element ***elements);
266 bool (*element_get_global)(E_Connman_Element **element);
267 bool (*elements_get_global)(unsigned int *count, E_Connman_Element ***elements);
268 bool (*string_get_global)(const char **value);
269 bool (*bool_get_global)(bool *value);
270 bool (*strings_get_global)(unsigned int *count, const char ***strings);
276 #define TEST_DESC_STRING_GET(_func, may_fail) \
277 {#_func, TEST_DESC_TYPE_STRING_GET, .func.string_get=_func, may_fail}
278 #define TEST_DESC_BOOL_GET(_func, may_fail) \
279 {#_func, TEST_DESC_TYPE_BOOL_GET, .func.bool_get=_func, may_fail}
280 #define TEST_DESC_UCHAR_GET(_func, may_fail) \
281 {#_func, TEST_DESC_TYPE_UCHAR_GET, .func.uchar_get=_func, may_fail}
282 #define TEST_DESC_USHORT_GET(_func, may_fail) \
283 {#_func, TEST_DESC_TYPE_USHORT_GET, .func.ushort_get=_func, may_fail}
284 #define TEST_DESC_UCHAR_ARRAY_GET(_func, may_fail) \
285 {#_func, TEST_DESC_TYPE_UCHAR_ARRAY_GET, .func.uchar_array_get=_func, may_fail}
286 #define TEST_DESC_ELEMENT_GET(_func, may_fail) \
287 {#_func, TEST_DESC_TYPE_ELEMENT_GET, .func.element_get=_func, may_fail}
288 #define TEST_DESC_ELEMENTS_GET(_func, may_fail) \
289 {#_func, TEST_DESC_TYPE_ELEMENTS_GET, .func.elements_get=_func, may_fail}
290 #define TEST_DESC_ELEMENT_GET_GLOBAL(_func, may_fail) \
291 {#_func, TEST_DESC_TYPE_ELEMENT_GET_GLOBAL, .func.element_get_global=_func, may_fail}
292 #define TEST_DESC_ELEMENTS_GET_GLOBAL(_func, may_fail) \
293 {#_func, TEST_DESC_TYPE_ELEMENTS_GET_GLOBAL, .func.elements_get_global=_func, may_fail}
294 #define TEST_DESC_STRING_GET_GLOBAL(_func, may_fail) \
295 {#_func, TEST_DESC_TYPE_STRING_GET_GLOBAL, .func.string_get_global=_func, may_fail}
296 #define TEST_DESC_BOOL_GET_GLOBAL(_func, may_fail) \
297 {#_func, TEST_DESC_TYPE_BOOL_GET_GLOBAL, .func.bool_get_global=_func, may_fail}
298 #define TEST_DESC_STRINGS_GET_GLOBAL(_func, may_fail) \
299 {#_func, TEST_DESC_TYPE_STRINGS_GET_GLOBAL, .func.strings_get_global=_func, may_fail}
300 #define TEST_DESC_SENTINEL {NULL, TEST_DESC_TYPE_LAST, .func.dummy=NULL}
303 _test_element(E_Connman_Element *element, const struct test_desc *test_descs)
305 const struct test_desc *itr;
306 int total, ok = 0, fail = 0;
309 for (itr = test_descs; itr->type != TEST_DESC_TYPE_LAST; itr++)
315 case TEST_DESC_TYPE_STRING_GET:
316 r = _test_string_get(element, itr->name, itr->func.string_get);
318 case TEST_DESC_TYPE_BOOL_GET:
319 r = _test_bool_get(element, itr->name, itr->func.bool_get);
321 case TEST_DESC_TYPE_UCHAR_GET:
322 r = _test_uchar_get(element, itr->name, itr->func.uchar_get);
324 case TEST_DESC_TYPE_USHORT_GET:
325 r = _test_ushort_get(element, itr->name, itr->func.ushort_get);
327 case TEST_DESC_TYPE_UCHAR_ARRAY_GET:
328 r = _test_uchar_array_get
329 (element, itr->name, itr->func.uchar_array_get);
331 case TEST_DESC_TYPE_ELEMENT_GET:
332 r = _test_element_get
333 (element, itr->name, itr->func.element_get);
335 case TEST_DESC_TYPE_ELEMENTS_GET:
336 r = _test_elements_get
337 (element, itr->name, itr->func.elements_get);
339 case TEST_DESC_TYPE_ELEMENT_GET_GLOBAL:
340 r = _test_element_get_global
341 (itr->name, itr->func.element_get_global);
343 case TEST_DESC_TYPE_ELEMENTS_GET_GLOBAL:
344 r = _test_elements_get_global
345 (itr->name, itr->func.elements_get_global);
347 case TEST_DESC_TYPE_STRING_GET_GLOBAL:
348 r = _test_string_get_global
349 (itr->name, itr->func.string_get_global);
351 case TEST_DESC_TYPE_BOOL_GET_GLOBAL:
352 r = _test_bool_get_global
353 (itr->name, itr->func.bool_get_global);
355 case TEST_DESC_TYPE_STRINGS_GET_GLOBAL:
356 r = _test_strings_get_global
357 (itr->name, itr->func.strings_get_global);
360 ERR("unknown test type %d (%s)\n", itr->type, itr->name);
365 if (r || itr->may_fail)
369 ERR("test failed %s, element %s [%s]\n",
370 itr->name, element->path, element->interface);
376 total = ok + failure;
381 INF("no tests for %s [%s]\n", element->path, element->interface);
385 INF("testing %s success: %d, failure: %d: %d%% [%s]\n",
386 element->path, ok, fail, (ok * 100) / total,
392 static const struct test_desc test_desc_manager[] = {
393 TEST_DESC_STRING_GET_GLOBAL(e_connman_manager_state_get, 0),
394 TEST_DESC_BOOL_GET_GLOBAL(e_connman_manager_offline_mode_get, 0),
395 //TEST_DESC_STRING_SET_GLOBAL(e_connman_manager_request_scan, 0),
396 //TEST_DESC_BOOL_SET_GLOBAL(e_connman_manager_offline_mode_set, 0),
397 TEST_DESC_ELEMENTS_GET_GLOBAL(e_connman_manager_profiles_get, 0),
398 TEST_DESC_ELEMENTS_GET_GLOBAL(e_connman_manager_services_get, 1),
399 TEST_DESC_STRING_GET_GLOBAL(e_connman_manager_technology_default_get, 0),
400 TEST_DESC_STRINGS_GET_GLOBAL(e_connman_manager_technologies_available_get, 0),
401 TEST_DESC_STRINGS_GET_GLOBAL(e_connman_manager_technologies_enabled_get, 0),
402 TEST_DESC_STRINGS_GET_GLOBAL(e_connman_manager_technologies_connected_get, 0),
403 TEST_DESC_ELEMENT_GET_GLOBAL(e_connman_manager_profile_active_get, 0),
407 static const struct test_desc test_desc_device[] = {
408 TEST_DESC_STRING_GET(e_connman_device_address_get, 0),
409 TEST_DESC_STRING_GET(e_connman_device_name_get, 0),
410 TEST_DESC_STRING_GET(e_connman_device_type_get, 0),
411 TEST_DESC_STRING_GET(e_connman_device_interface_get, 0),
412 TEST_DESC_BOOL_GET(e_connman_device_powered_get, 0),
413 //TEST_DESC_BOOL_SET(e_connman_device_powered_set, 0),
414 TEST_DESC_USHORT_GET(e_connman_device_scan_interval_get, 1),
415 //TEST_DESC_USHORT_SET(e_connman_device_scan_interval_set, 1),
416 TEST_DESC_BOOL_GET(e_connman_device_scanning_get, 1),
417 TEST_DESC_ELEMENTS_GET(e_connman_device_networks_get, 1),
421 static const struct test_desc test_desc_profile[] = {
422 TEST_DESC_STRING_GET(e_connman_profile_name_get, 1),
423 //TEST_DESC_STRING_SET(e_connman_profile_name_set, 1),
424 TEST_DESC_BOOL_GET(e_connman_profile_offline_mode_get, 0),
425 //TEST_DESC_BOOL_SET(e_connman_profile_offline_mode_set, 0),
426 TEST_DESC_ELEMENTS_GET(e_connman_profile_services_get, 1),
430 static const struct test_desc test_desc_network[] = {
431 TEST_DESC_STRING_GET(e_connman_network_address_get, 0),
432 TEST_DESC_STRING_GET(e_connman_network_name_get, 0),
433 TEST_DESC_BOOL_GET(e_connman_network_connected_get, 0),
434 TEST_DESC_UCHAR_GET(e_connman_network_strength_get, 1),
435 TEST_DESC_USHORT_GET(e_connman_network_frequency_get, 1),
436 TEST_DESC_ELEMENT_GET(e_connman_network_device_get, 0),
437 TEST_DESC_UCHAR_ARRAY_GET(e_connman_network_wifi_ssid_get, 1),
438 TEST_DESC_STRING_GET(e_connman_network_wifi_mode_get, 1),
439 TEST_DESC_STRING_GET(e_connman_network_wifi_security_get, 1),
440 TEST_DESC_STRING_GET(e_connman_network_wifi_passphrase_get, 1),
441 TEST_DESC_USHORT_GET(e_connman_network_wifi_channel_get, 1),
442 TEST_DESC_STRING_GET(e_connman_network_wifi_eap_get, 1),
446 static const struct test_desc test_desc_service[] = {
447 /* TODO: need to check exactly what properties may fail */
448 TEST_DESC_STRING_GET(e_connman_service_state_get, 1),
449 TEST_DESC_STRING_GET(e_connman_service_error_get, 1),
450 TEST_DESC_STRING_GET(e_connman_service_name_get, 0),
451 TEST_DESC_STRING_GET(e_connman_service_type_get, 0),
452 TEST_DESC_STRING_GET(e_connman_service_mode_get, 1),
453 TEST_DESC_STRING_GET(e_connman_service_security_get, 1),
454 TEST_DESC_STRING_GET(e_connman_service_passphrase_get, 1),
455 //TEST_DESC_STRING_SET(e_connman_service_passphrase_set, 1),
456 TEST_DESC_BOOL_GET(e_connman_service_passphrase_required_get, 1),
457 TEST_DESC_UCHAR_GET(e_connman_service_strength_get, 1),
458 TEST_DESC_BOOL_GET(e_connman_service_favorite_get, 0),
459 TEST_DESC_BOOL_GET(e_connman_service_immutable_get, 0),
460 TEST_DESC_BOOL_GET(e_connman_service_auto_connect_get, 0),
461 //TEST_DESC_BOOL_SET(e_connman_service_auto_connect_set, 1),
462 TEST_DESC_BOOL_GET(e_connman_service_setup_required_get, 1),
463 TEST_DESC_STRING_GET(e_connman_service_apn_get, 1),
464 //TEST_DESC_STRING_SET(e_connman_service_apn_set, 1),
465 TEST_DESC_STRING_GET(e_connman_service_mcc_get, 1),
466 TEST_DESC_STRING_GET(e_connman_service_mnc_get, 1),
467 TEST_DESC_BOOL_GET(e_connman_service_roaming_get, 1),
468 TEST_DESC_STRING_GET(e_connman_service_ipv4_method_get, 1),
469 TEST_DESC_STRING_GET(e_connman_service_ipv4_address_get, 1),
470 TEST_DESC_STRING_GET(e_connman_service_ipv4_gateway_get, 1),
471 TEST_DESC_STRING_GET(e_connman_service_ipv4_netmask_get, 1),
472 TEST_DESC_STRING_GET(e_connman_service_ipv4_configuration_method_get, 1),
473 TEST_DESC_STRING_GET(e_connman_service_ipv4_configuration_address_get, 1),
474 TEST_DESC_STRING_GET(e_connman_service_ipv4_configuration_gateway_get, 1),
475 TEST_DESC_STRING_GET(e_connman_service_ipv4_configuration_netmask_get, 1),
476 TEST_DESC_STRING_GET(e_connman_service_ethernet_method_get, 1),
477 TEST_DESC_STRING_GET(e_connman_service_ethernet_address_get, 1),
478 TEST_DESC_USHORT_GET(e_connman_service_ethernet_mtu_get, 1),
479 TEST_DESC_STRING_GET(e_connman_service_ethernet_netmask_get, 1),
484 _quit(__UNUSED__ void *data)
486 ecore_main_loop_quit();
487 return ECORE_CALLBACK_CANCEL;
491 _on_exiter(__UNUSED__ void *data)
493 e_connman_system_shutdown();
494 ecore_idle_enterer_add(_quit, NULL);
496 return ECORE_CALLBACK_CANCEL;
500 _exiter_reschedule(void)
503 ecore_timer_del(exiter);
504 exiter = ecore_timer_add(10, _on_exiter, NULL);
507 struct test_element_timer_data
509 E_Connman_Element *element;
514 _test_element_timer(void *data)
516 struct test_element_timer_data *d = data;
517 E_Connman_Element *element = d->element;
519 if (e_connman_element_is_device(element))
520 _test_element(element, test_desc_device);
521 else if (e_connman_element_is_profile(element))
522 _test_element(element, test_desc_profile);
523 else if (e_connman_element_is_network(element))
524 _test_element(element, test_desc_network);
525 else if (e_connman_element_is_manager(element))
526 _test_element(element, test_desc_manager);
527 else if (e_connman_element_is_service(element))
528 _test_element(element, test_desc_service);
530 ERR("!!! don't know how to test %s [%s]\n",
531 element->path, element->interface);
533 _exiter_reschedule();
536 return ECORE_CALLBACK_CANCEL;
540 _element_listener(void *data, __UNUSED__ const E_Connman_Element *element)
542 struct test_element_timer_data *d = data;
544 ecore_timer_del(d->timer);
545 d->timer = ecore_timer_add(1.0, _test_element_timer, d);
546 _exiter_reschedule();
550 _element_listener_free(void *data)
552 struct test_element_timer_data *d = data;
554 ecore_timer_del(d->timer);
559 _on_element_add(__UNUSED__ void *data, __UNUSED__ int type, void *info)
561 E_Connman_Element *element = info;
562 struct test_element_timer_data *d;
564 d = malloc(sizeof(*d));
566 return ECORE_CALLBACK_PASS_ON;
568 d->element = element;
569 d->timer = ecore_timer_add(1.0, _test_element_timer, d);
570 e_connman_element_listener_add
571 (element, _element_listener, d, _element_listener_free);
573 return ECORE_CALLBACK_PASS_ON;
577 _on_element_del(__UNUSED__ void *data, __UNUSED__ int type, __UNUSED__ void *info)
579 return ECORE_CALLBACK_PASS_ON;
583 _on_element_updated(__UNUSED__ void *data, __UNUSED__ int type, __UNUSED__ void *info)
585 return ECORE_CALLBACK_PASS_ON;
589 main(__UNUSED__ int argc, __UNUSED__ char *argv[])
591 E_DBus_Connection *c;
598 c = e_dbus_bus_get(DBUS_BUS_SYSTEM);
600 printf("ERROR: can't connect to system session\n");
604 e_connman_system_init(c);
605 ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_ADD, _on_element_add, NULL);
606 ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_DEL, _on_element_del, NULL);
607 ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_UPDATED,
608 _on_element_updated, NULL);
610 _exiter_reschedule();
612 ecore_main_loop_begin();
614 e_dbus_connection_close(c);
615 eina_stringshare_dump();
620 total = success + failure;
622 fputs("DBG: clean exit, no tests executed.\n", stderr);
624 fprintf(stderr, "DBG: clean exit, success: %d, failure: %d, %d%%\n",
625 success, failure, (success * 100) / total);