From: Youngjae Cho Date: Thu, 3 Feb 2022 07:25:20 +0000 (+0900) Subject: auto-test: check feature using system-info library X-Git-Tag: submit/tizen/20220208.052553~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=72af31622002613274e134f23b919fc82bc6e956;p=platform%2Fcore%2Fsystem%2Fdeviced.git auto-test: check feature using system-info library Previously, the uniitest is conducted based on statically defined configuration file, auto-test.conf. Replace it to system-info API, which fetches feature on runtime. Therefore it is able to find feature on various target without defining one by one in advance whether a test can be deserved. Change-Id: Iaf445edc4c566517c37106dd00c67c42cd7f813a Signed-off-by: Youngjae Cho --- diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 1cbbc79..9a31220 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -326,7 +326,6 @@ mv %{_libdir}/iot-headless-battery.so %{_libdir}/deviced/battery.so %manifest deviced.manifest %license LICENSE.Apache-2.0 %{_bindir}/deviced-auto-test -%config %{_sysconfdir}/deviced/auto-test.conf %files plugin-profile-mobile %manifest deviced.manifest diff --git a/tests/auto-test/CMakeLists.txt b/tests/auto-test/CMakeLists.txt index 3e72830..21baed4 100644 --- a/tests/auto-test/CMakeLists.txt +++ b/tests/auto-test/CMakeLists.txt @@ -7,7 +7,6 @@ SET(SRCS test.c main.c result.c - config.c battery.c display.c led.c @@ -28,6 +27,7 @@ SET(SRCS INCLUDE(FindPkgConfig) pkg_check_modules(pkgs REQUIRED capi-system-device + capi-system-info vconf udev hal-api-common @@ -48,4 +48,3 @@ ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${deviced_LDFLAGS} deviced-common-private) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/auto-test.conf DESTINATION /etc/deviced) diff --git a/tests/auto-test/auto-test.conf b/tests/auto-test/auto-test.conf deleted file mode 100644 index c7fa510..0000000 --- a/tests/auto-test/auto-test.conf +++ /dev/null @@ -1,60 +0,0 @@ -[mobile] -booting=1 -battery-monitor=0 -battery=1 -display=1 -led=1 -power=1 -proc=1 -extcon=1 -ir=1 -time=1 -udev=1 -touchscreen=1 -pmqos=1 - -[wearable] -booting=1 -battery-monitor=1 -battery=1 -display=1 -brightness=1 -led=0 -power=1 -proc=1 -extcon=1 -ir=0 -time=1 -udev=1 -touchscreen=1 -pmqos=1 - -[tv] -booting=0 -battery-monitor=0 -battery=0 -display=1 -led=0 -power=1 -proc=1 -extcon=1 -ir=0 -time=1 -udev=1 -touchscreen=0 -pmqos=0 - -[common] -booting=1 -battery-monitor=0 -battery=0 -display=1 -led=0 -power=1 -proc=1 -extcon=1 -ir=0 -time=1 -udev=1 -touchscreen=1 -pmqos=1 \ No newline at end of file diff --git a/tests/auto-test/battery-monitor-test.c b/tests/auto-test/battery-monitor-test.c index 1690638..efe1e87 100644 --- a/tests/auto-test/battery-monitor-test.c +++ b/tests/auto-test/battery-monitor-test.c @@ -750,6 +750,7 @@ static const struct test_ops battery_monitor_test_ops = { .init = battery_monitor_init, .exit = battery_monitor_exit, .unit = battery_monitor_unit, + .required_feature = "tizen.org/feature/battery", }; TEST_OPS_REGISTER(&battery_monitor_test_ops) diff --git a/tests/auto-test/battery.c b/tests/auto-test/battery.c index 1e8a1f7..d65c5bb 100644 --- a/tests/auto-test/battery.c +++ b/tests/auto-test/battery.c @@ -1017,6 +1017,7 @@ static const struct test_ops battery_test_ops = { .init = battery_init, .exit = battery_exit, .unit = battery_unit, + .required_feature = "tizen.org/feature/battery", }; TEST_OPS_REGISTER(&battery_test_ops) diff --git a/tests/auto-test/config.c b/tests/auto-test/config.c deleted file mode 100644 index 3a49732..0000000 --- a/tests/auto-test/config.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include - -#include - -#include "test.h" -#include "config.h" - -#define CONF_FILE "/etc/deviced/auto-test.conf" -#define DEF_PROFILE "mobile" - -static char section[256] = {'\0',}; -static GHashTable *config_hash = NULL; - -static int load_config(struct parse_result *result, void *user_data) -{ - int value = 0; - - if (!MATCH(result->section, section)) - return 0; - - _D("%s,%s,%s", result->section, result->name, result->value); - - value = atoi(result->value); - if ((value == 1) && !g_hash_table_contains(config_hash, result->name)) - g_hash_table_add(config_hash, g_strdup(result->name)); - - return 0; -} - -void test_config_load(const char *profile) -{ - int len = 0; - int ret = 0; - - if (NULL != profile) len = strlen(profile); - if ((0 >= len) || (255 < len)) - strncpy(section, DEF_PROFILE, 255); - else - strncpy(section, profile, 255); - - - if (NULL != config_hash) - test_config_unload(); - - config_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); - if (NULL == config_hash) { - _E("Failed to create config hash table!"); - return ; - } - - ret = config_parse(CONF_FILE, load_config, NULL); - - if (ret < 0) { - _E("Failed to load %s, %d Use default value!", CONF_FILE, ret); - test_config_unload(); - } -} - -void test_config_unload() -{ - if (NULL != config_hash) { - g_hash_table_unref(config_hash); - config_hash = NULL; - } -} - -bool test_config_is_supported(const char *module) -{ - // if fail to load config file, all modules are supported as default. - //if ((NULL == module) || (NULL == config_hash) || (0 == g_hash_table_size(config_hash))) - if ((NULL == module) || (NULL == config_hash)) - return TRUE; - - return g_hash_table_contains(config_hash, module); -} diff --git a/tests/auto-test/config.h b/tests/auto-test/config.h deleted file mode 100644 index f541dd7..0000000 --- a/tests/auto-test/config.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2014 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __AUTOTEST_CONFIG_H__ -#define __AUTOTEST_CONFIG_H__ - -#include - -void test_config_load(const char *profile); -void test_config_unload(); -bool test_config_is_supported(const char *module); - - -#endif /* __AUTOTEST_CONFIG_H__ */ diff --git a/tests/auto-test/display.c b/tests/auto-test/display.c index d2b3e85..72f2f29 100644 --- a/tests/auto-test/display.c +++ b/tests/auto-test/display.c @@ -567,6 +567,7 @@ static const struct test_ops display_test_ops = { .init = display_init, .exit = display_exit, .unit = display_unit, + .required_feature = "tizen.org/feature/display,tizen.org/feature/display.state", }; TEST_OPS_REGISTER(&display_test_ops) diff --git a/tests/auto-test/ir.c b/tests/auto-test/ir.c index 665d75f..80406f8 100644 --- a/tests/auto-test/ir.c +++ b/tests/auto-test/ir.c @@ -187,6 +187,7 @@ static const struct test_ops ir_test_ops = { .init = ir_init, .exit = ir_exit, .unit = ir_unit, + .required_feature = "tizen.org/feature/consumer_ir", }; TEST_OPS_REGISTER(&ir_test_ops) diff --git a/tests/auto-test/led.c b/tests/auto-test/led.c index 1e31aa9..7ed9283 100755 --- a/tests/auto-test/led.c +++ b/tests/auto-test/led.c @@ -210,6 +210,7 @@ static const struct test_ops led_test_ops = { .init = led_init, .exit = led_exit, .unit = led_unit, + .required_feature = "tizen.org/feature/led", }; TEST_OPS_REGISTER(&led_test_ops) diff --git a/tests/auto-test/main.c b/tests/auto-test/main.c index a3c8df7..4ab90f9 100644 --- a/tests/auto-test/main.c +++ b/tests/auto-test/main.c @@ -17,7 +17,6 @@ */ #include "test.h" -#include "config.h" static void test_main(int argc, char **argv) { @@ -35,10 +34,12 @@ static void unit_test(int argc, char **argv) _E("there is no test ops : %s", argv[2]); return; } - ops->unit(argc, argv); + + if (feature_supported(ops->required_feature)) + ops->unit(argc, argv); } -void show_usage() +void show_usage(void) { printf("Usage: deviced-auto-test [PROFILE] [MODULE] [UNIT-METHOD] [OPTS]\n\n"); printf("Mandatory arguments\n"); @@ -60,16 +61,11 @@ int main(int argc, char **argv) return 0; } - test_config_load(argv[1]); - config_test(); - if (argc >= 3) unit_test(argc, argv); else test_main(argc, argv); - test_config_unload(); - return 0; } diff --git a/tests/auto-test/test.c b/tests/auto-test/test.c index 696a1d3..f50faf1 100644 --- a/tests/auto-test/test.c +++ b/tests/auto-test/test.c @@ -16,11 +16,43 @@ * limitations under the License. */ +#include +#include + #include "test.h" -#include "config.h" static GList *dd_head; +int feature_supported(const char *feature) +{ + char *token; + char *saveptr; + int retval; + bool supported; + char f[128] = {0, }; + int ret = 1; + + if (!feature) + return 1; + + snprintf(f, sizeof(f) - 1, "%s", feature); + + token = strtok_r(f, ",", &saveptr); + while (token) { + retval = system_info_get_platform_bool(token, &supported); + if (retval != 0 || supported == 0) { + _D("Feature %s not supported", token); + ret = 0; + break; + } + + token = strtok_r(NULL, ",", &saveptr); + } + + return ret; +} + + void add_test(const struct test_ops *d) { if (d->priority == TEST_PRIORITY_HIGH) @@ -46,17 +78,6 @@ const struct test_ops *find_test(const char *name) return NULL; } -void config_test() -{ - GList *elem, *next; - const struct test_ops *d; - - SYS_G_LIST_FOREACH_SAFE(dd_head, elem, next, d) { - if (!test_config_is_supported(d->name)) - SYS_G_LIST_REMOVE(dd_head, d); - } -} - void test_init(void *data) { GList *elem; @@ -64,6 +85,9 @@ void test_init(void *data) _D("test module count(%d)", SYS_G_LIST_LENGTH(dd_head)); SYS_G_LIST_FOREACH(dd_head, elem, d) { + if (!feature_supported(d->required_feature)) + continue; + _D("[%s] initialize", d->name); if (d->init) d->init(data); @@ -76,6 +100,9 @@ void test_exit(void *data) const struct test_ops *d; SYS_G_LIST_FOREACH(dd_head, elem, d) { + if (!feature_supported(d->required_feature)) + continue; + _D("[%s] deinitialize", d->name); if (d->exit) d->exit(data); diff --git a/tests/auto-test/test.h b/tests/auto-test/test.h index da1d423..0ba59c6 100644 --- a/tests/auto-test/test.h +++ b/tests/auto-test/test.h @@ -49,6 +49,7 @@ enum test_priority { struct test_ops { enum test_priority priority; char *name; + const char *required_feature; void (*init) (void *data); void (*exit) (void *data); int (*start) (void); @@ -103,9 +104,9 @@ static void __DESTRUCTOR__ module_exit(void) \ void add_test(const struct test_ops *c); void remove_test(const struct test_ops *c); const struct test_ops *find_test(const char *name); -void config_test(); void _R(const char *format, ...); void __cb(GVariant *result, void *data, GError *err); bool capi_result(const char *method, int val); bool capi_reboot_result(const char *method, int val); +int feature_supported(const char *feature); #endif diff --git a/tests/auto-test/touchscreen.c b/tests/auto-test/touchscreen.c index 88e370e..de5d8a1 100644 --- a/tests/auto-test/touchscreen.c +++ b/tests/auto-test/touchscreen.c @@ -94,6 +94,7 @@ static const struct test_ops touchscreen_test_ops = { .init = touchscreen_init, .exit = touchscreen_exit, .unit = touchscreen_unit, + .required_feature = "tizen.org/feature/display", }; TEST_OPS_REGISTER(&touchscreen_test_ops)