#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;
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);
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)
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");
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) {
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) {