Supplement cpu boosting test 72/278572/3
authorUnsung Lee <unsung.lee@samsung.com>
Fri, 22 Jul 2022 06:07:19 +0000 (15:07 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Fri, 22 Jul 2022 07:14:08 +0000 (07:14 +0000)
Change-Id: I9e1b0fa30247e3ca341c7e99c7512253645de8b5
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
tests/main.c

index a50e7a7..06fb85c 100644 (file)
@@ -44,6 +44,8 @@
 
 #endif
 
+static void test_get_cpu_boosting(resource_pid_t pid, cpu_boosting_level_info_t *level, bool forked);
+
 static void *thread_worker(void *arg)
 {
        pid_t *tid = (pid_t *)arg;
@@ -54,6 +56,19 @@ static void *thread_worker(void *arg)
        pthread_exit(NULL);
 }
 
+static void *thread_attr_check(void *arg)
+{
+       cpu_boosting_level_info_t cur_level;
+       resource_pid_t pid;
+
+       pid.pid = 0;
+       pid.tid = NULL;
+       pid.tid_count = 0;
+
+       test_get_cpu_boosting(pid, &cur_level, true); /* Expect CPU_BOOSTING_LEVEL_NONE */
+       pthread_exit(NULL);
+}
+
 static void test_set_cpu_boosting(resource_pid_t pid, cpu_boosting_level_e level, cpu_boosting_flag_e flag, int timeout_msec)
 {
        int ret;
@@ -74,7 +89,7 @@ static void test_clear_cpu_boosting(resource_pid_t pid)
        }
 }
 
-static void test_get_cpu_boosting(resource_pid_t pid, cpu_boosting_level_info_t *level)
+static void test_get_cpu_boosting(resource_pid_t pid, cpu_boosting_level_info_t *level, bool forked)
 {
        int ret;
 
@@ -85,7 +100,7 @@ static void test_get_cpu_boosting(resource_pid_t pid, cpu_boosting_level_info_t
        }
        else {
                for(int i = 0; i < level->tid_count; i++)
-                       _I("[CPU-BOOSTING-TEST] boosting level is %s",
+                       _I("[CPU-BOOSTING-TEST] %sboosting level is %s", forked ? "Child thread " : "",
                          level->tid_level[i] == CPU_BOOSTING_LEVEL_STRONG ? "strong" :
                          level->tid_level[i] == CPU_BOOSTING_LEVEL_MEDIUM ? "medium" :
                          level->tid_level[i] == CPU_BOOSTING_LEVEL_WEAK ? "weak" : "none");
@@ -102,10 +117,21 @@ static void test_cpu_boosting(resource_pid_t pid, cpu_boosting_flag_e flag)
        for (int level = CPU_BOOSTING_LEVEL_WEAK; level > CPU_BOOSTING_LEVEL_NONE; level--)
                test_set_cpu_boosting(pid, level, flag, 3000);
 
-       test_get_cpu_boosting(pid, &cur_level); /* Expect CPU_BOOSTING_LEVEL_STRONG */
+       if (flag & CPU_BOOSTING_RESET_ON_FORK) {
+               pthread_t thread;
+               int ret = pthread_create(&thread, NULL, thread_attr_check, NULL);
+               if (ret == 0) {
+                       ret = pthread_detach(thread);
+                       if (ret)
+                               _E("[CPU-BOOSTING-TEST] Failed to join a new thread");
+               }
+               else
+                       _E("[CPU-BOOSTING-TEST] Failed to create a new thread");
+       }
 
+       test_get_cpu_boosting(pid, &cur_level, false); /* Expect CPU_BOOSTING_LEVEL_STRONG */
        test_clear_cpu_boosting(pid);
-       test_get_cpu_boosting(pid, &cur_level); /* Expect CPU_BOOSTING_LEVEL_NONE */
+       test_get_cpu_boosting(pid, &cur_level, false);  /* Expect CPU_BOOSTING_LEVEL_NONE */
 }
 
 static void one_process_one_thread_test(cpu_boosting_flag_e flag)
@@ -178,6 +204,8 @@ static void one_process_multi_thread_test(int tid_count)
        }
        pid.pid = 0;
        pid.tid_count = real_tid_count;
+
+       usleep(300000);
        test_cpu_boosting(pid, 0);
        free(pid.tid);
 }
@@ -221,8 +249,6 @@ int main (void)
        _D("[CPU-BOOSTING-TEST] <<<<<<<<<< One Process One Thread >>>>>>>>>>");
        one_process_one_thread_test(0);
 
-       return 0;
-
        /* Case 2: Boosting single-threaded processes */
        _D("[CPU-BOOSTING-TEST] <<<<<<<<<< Multi Processes One Thread >>>>>>>>>>");
        multi_process_one_thread_test(7);