test : enhance requirement 52/142952/7 accepted/tizen/4.0/unified/20170828.223704 accepted/tizen/unified/20170810.171811 submit/tizen/20170809.071335 submit/tizen_4.0/20170828.100002
authorKichan Kwon <k_c.kwon@samsung.com>
Tue, 8 Aug 2017 03:28:17 +0000 (12:28 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Wed, 9 Aug 2017 08:23:49 +0000 (17:23 +0900)
- 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 <k_c.kwon@samsung.com>
packaging/capi-system-runtime-info.spec
test/runtime_info_test.c
test/runtime_info_test.h
test/runtime_info_test_resourced.c
test/runtime_info_test_vconf.c

index e219f78..fa652ec 100644 (file)
@@ -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
index 1b66abf..49f820b 100644 (file)
@@ -17,6 +17,7 @@
 #include <signal.h>
 
 #include <stdio.h>
+#include <string.h>
 #include <sys/types.h>
 #include <unistd.h>
 
index 90a5742..599bdc7 100644 (file)
@@ -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);
index 18b585c..292c231 100644 (file)
 #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) {
index e5ba13a..2fe712d 100644 (file)
@@ -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)