From 6b5ffe7f0e4a7bf9aaf2b9261efece5c5610d746 Mon Sep 17 00:00:00 2001 From: Kichan Kwon Date: Tue, 8 Aug 2017 12:28:17 +0900 Subject: [PATCH] test : enhance requirement - Some TCs return NOT_SUPPORTED - If resourced(-headless) is not installed - If there is no running app - Require memps used by test binary Change-Id: I204ae84fc2e56c060b8ced8deb93060338848b05 Signed-off-by: Kichan Kwon --- packaging/capi-system-runtime-info.spec | 1 + test/runtime_info_test.c | 1 + test/runtime_info_test.h | 1 - test/runtime_info_test_resourced.c | 56 ++++++++++++++++++++------------- test/runtime_info_test_vconf.c | 2 ++ 5 files changed, 38 insertions(+), 23 deletions(-) diff --git a/packaging/capi-system-runtime-info.spec b/packaging/capi-system-runtime-info.spec index e219f78..fa652ec 100644 --- a/packaging/capi-system-runtime-info.spec +++ b/packaging/capi-system-runtime-info.spec @@ -32,6 +32,7 @@ Requires: pkgconfig(capi-base-common) %package test Summary: A Runtime Information test binary Requires: %{name} = %{version}-%{release} +Requires: memps %description test Binary for testing Runtime-info APIs diff --git a/test/runtime_info_test.c b/test/runtime_info_test.c index 1b66abf..49f820b 100644 --- a/test/runtime_info_test.c +++ b/test/runtime_info_test.c @@ -17,6 +17,7 @@ #include #include +#include #include #include diff --git a/test/runtime_info_test.h b/test/runtime_info_test.h index 90a5742..599bdc7 100644 --- a/test/runtime_info_test.h +++ b/test/runtime_info_test.h @@ -30,7 +30,6 @@ enum test_result { #define PRINT_RESULT(result) ((result) == SUCCESS) ? "\x1b[32mSUCCESS\x1b[0m" : (((result) == FAIL) ? "\x1b[31mFAIL\x1b[0m" : (((result) == ERROR) ? "\x1b[31mERROR\x1b[0m" : (((result) == NOT_SUPPORTED) ? "\x1b[34mNOT SUPPORTED\x1b[0m" : NULL))) #define PRINT_LINE printf("\n-----------------------------------------------------\n\n"); -#define PRINT_NOTICE(msg) printf("\x1b[33mNOTICE : %s\x1b[0m\n", msg); /* Compare two values and judge */ int check_value(int val1, int val2, int max_err); diff --git a/test/runtime_info_test_resourced.c b/test/runtime_info_test_resourced.c index 18b585c..292c231 100644 --- a/test/runtime_info_test_resourced.c +++ b/test/runtime_info_test_resourced.c @@ -28,6 +28,32 @@ #define KBtoPage(kb) ((kb) / 4) #define START_TIME_FILE "/run/resourced/appinfo/%s/starttime" +/** + * @brief Check return value and print appropriate message + * @param[in] name Test name + * @param[in] ret The return value of runtime-info API + * @return 1 if this test should be ended, otherwise 0 + */ +int runtime_info_test_helper_check_return_value(const char *name, int ret) +{ + switch (ret) { + case RUNTIME_INFO_ERROR_NONE: + return 0; + case RUNTIME_INFO_ERROR_REMOTE_IO: + printf("Resourced isn't installed\n\n"); + printf(" Result : %s\n", PRINT_RESULT(NOT_SUPPORTED)); + return 1; + case RUNTIME_INFO_ERROR_NO_DATA: + printf("There is no running app\n\n"); + printf(" Result : %s\n", PRINT_RESULT(NOT_SUPPORTED)); + return 1; + default: + printf("%s failed (%d)\n\n", name, ret); + printf(" Result : %s\n", PRINT_RESULT(ERROR)); + return 1; + } +} + void runtime_info_test_get_process_memory_info(pid_t pid) { int ret; @@ -40,11 +66,8 @@ void runtime_info_test_get_process_memory_info(pid_t pid) printf("Runtime_info_get_process_memory_info test\n"); ret = runtime_info_get_process_memory_info(&pid, 1, &info); - if (ret) { - printf("runtime_info_get_process_memory_info failed (%d)\n\n", ret); - printf(" Result : %s\n", PRINT_RESULT(ERROR)); + if (runtime_info_test_helper_check_return_value("runtime_info_get_process_memory_info", ret)) return; - } /* Read /proc/PID/stat */ snprintf(buf, BUF_SIZE, "/proc/%u/stat", pid); @@ -85,15 +108,15 @@ void runtime_info_test_get_process_memory_info(pid_t pid) fclose(fp); printf(" Virtual memory size : %s\n", - PRINT_RESULT(check_value(info[0].vsz, BytetoKiB(vsz), 0))); + PRINT_RESULT(check_value(info[0].vsz, BytetoKiB(vsz), 10))); printf(" Proportional set size : %s\n", - PRINT_RESULT(check_value(info[0].pss, pss, 0))); + PRINT_RESULT(check_value(info[0].pss, pss, 10))); printf(" Clean memory size : %s\n", PRINT_RESULT(check_value(info[0].shared_clean + info[0].private_clean, - code, 0))); + code, 10))); printf(" Dirty memory size : %s\n", PRINT_RESULT(check_value(info[0].shared_dirty + info[0].private_dirty, - data, 0))); + data, 10))); } void runtime_info_test_get_process_cpu_usage(pid_t pid) @@ -107,11 +130,8 @@ void runtime_info_test_get_process_cpu_usage(pid_t pid) printf("Runtime_info_get_process_cpu_usage test\n"); ret = runtime_info_get_process_cpu_usage(&pid, 1, &usage); - if (ret) { - printf("runtime_info_get_process_cpu_usage failed (%d)\n\n", ret); - printf(" Result : %s\n", PRINT_RESULT(ERROR)); + if (runtime_info_test_helper_check_return_value("runtime_info_get_process_cpu_usage", ret)) return; - } snprintf(buf, BUF_SIZE, "/proc/%u/stat", pid); fp = fopen(buf, "r"); @@ -202,15 +222,11 @@ void runtime_info_test_get_all_apps_memory_usage(void) int vmswap; printf("Runtime_info_get_all_apps_memory_usage test\n"); - PRINT_NOTICE("Resourced-headless doesn't support this API.\n"); /* Call runtime-info APIs */ ret = runtime_info_get_all_apps_memory_usage(&handle); - if (ret) { - printf("Failed to call runtime_info_get_all_apps_memory_usage (%d)\n\n", ret); - printf("Result : %s\n", PRINT_RESULT(ERROR)); + if (runtime_info_test_helper_check_return_value("runtime_info_get_all_apps_memory_usage", ret)) return; - } ret = runtime_info_app_usage_get_usage(handle, 0, &usage_r); if (ret) { @@ -285,15 +301,11 @@ void runtime_info_test_get_all_apps_cpu_rate(void) unsigned long utime, stime, cputime; printf("Runtime_info_get_all_apps_cpu_rate test\n"); - PRINT_NOTICE("Resourced-headless doesn't support this API.\n"); /* Call runtime-info APIs */ ret = runtime_info_get_all_apps_cpu_rate(&handle); - if (ret) { - printf("Failed to call runtime_info_get_all_apps_memory_usage (%d)\n\n", ret); - printf("Result : %s\n", PRINT_RESULT(ERROR)); + if (runtime_info_test_helper_check_return_value("runtime_info_get_all_apps_cpu_rate", ret)) return; - } ret = runtime_info_app_usage_get_usage(handle, 0, &rate_r); if (ret) { diff --git a/test/runtime_info_test_vconf.c b/test/runtime_info_test_vconf.c index e5ba13a..2fe712d 100644 --- a/test/runtime_info_test_vconf.c +++ b/test/runtime_info_test_vconf.c @@ -263,7 +263,9 @@ void runtime_info_test_get_value_int(void) static void runtime_info_test_changed_cb(runtime_info_key_e key, void *user_data) { + g_mutex_lock(&mutex); g_cond_signal(&cond); + g_mutex_unlock(&mutex); } static gpointer runtime_info_test_cb_thread(gpointer data) -- 2.7.4