Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4c31edd6 authored by Sachin Mohan Gadag's avatar Sachin Mohan Gadag
Browse files

qahw: test: Handle power suspend scenario

Test app is entering to suspend state while playback
is running in power suspend scenario.Avoid this by
acquiring wakelock in write_to_hal api.

Change-Id: Id7632de2786d839daba0384b167c61b580ad37b5
parent 28718c54
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -89,6 +89,40 @@ int sourcetrack_done = 0;
static pthread_mutex_t sourcetrack_lock;
struct qahw_sound_focus_param sound_focus_data;

static bool request_wake_lock(bool wakelock_acquired, bool enable)
{
   int system_ret;

   if (enable) {
       if (!wakelock_acquired) {
           system_ret = system("echo audio_services > /sys/power/wake_lock");
           if (system_ret < 0) {
               fprintf(stderr, "%s.Failed to acquire audio_service lock\n", __func__);
               fprintf(log_file, "%s.Failed to acquire audio_service lock\n", __func__);
           } else {
               wakelock_acquired = true;
               fprintf(log_file, "%s.Success to acquire audio_service lock\n", __func__);
           }
       } else
            fprintf(log_file, "%s.Lock is already acquired\n", __func__);
   }

   if (!enable) {
       if (wakelock_acquired) {
           system_ret = system("echo audio_services > /sys/power/wake_unlock");
           if (system_ret < 0) {
               fprintf(stderr, "%s.Failed to release audio_service lock\n", __func__);
               fprintf(log_file, "%s.Failed to release audio_service lock\n", __func__);
           } else {
               wakelock_acquired = false;
               fprintf(log_file, "%s.Success to release audio_service lock\n", __func__);
           }
       } else
            fprintf(log_file, "%s.No Lock is acquired to release\n", __func__);
   }
   return wakelock_acquired;
}

void stop_signal_handler(int signal __unused)
{
   stop_record = true;
@@ -547,6 +581,7 @@ int main(int argc, char* argv[]) {
    bool interactive_mode = false, source_tracking = false;
    struct listnode param_list;
    char log_filename[256] = "stdout";
    bool wakelock_acquired = false;

    log_file = stdout;
    list_init(&param_list);
@@ -624,6 +659,7 @@ int main(int argc, char* argv[]) {
         }
    }

    wakelock_acquired = request_wake_lock(wakelock_acquired, true);
    qahw_mod_handle = qahw_load_module(mod_name);
    if(qahw_mod_handle == NULL) {
        fprintf(log_file, " qahw_load_module failed");
@@ -862,5 +898,6 @@ sourcetrack_error:
        fprintf(stdout, "\n Done with hal record test \n");
        fclose(log_file);
    }
    wakelock_acquired = request_wake_lock(wakelock_acquired, false);
    return 0;
}
+37 −0
Original line number Diff line number Diff line
@@ -237,6 +237,40 @@ audio_io_handle_t stream_handle = 0x999;
                   "music_offload_wma_encode_option2=%d;" \
                   "music_offload_wma_format_tag=%d;"

static bool request_wake_lock(bool wakelock_acquired, bool enable)
{
   int system_ret;

   if (enable) {
       if (!wakelock_acquired) {
           system_ret = system("echo audio_services > /sys/power/wake_lock");
           if (system_ret < 0) {
               fprintf(stderr, "%s.Failed to acquire audio_service lock\n", __func__);
               fprintf(log_file, "%s.Failed to acquire audio_service lock\n", __func__);
           } else {
               wakelock_acquired = true;
               fprintf(log_file, "%s.Success to acquire audio_service lock\n", __func__);
           }
       } else
            fprintf(log_file, "%s.Lock is already acquired\n", __func__);
   }

   if (!enable) {
       if (wakelock_acquired) {
           system_ret = system("echo audio_services > /sys/power/wake_unlock");
           if (system_ret < 0) {
               fprintf(stderr, "%s.Failed to release audio_service lock\n", __func__);
               fprintf(log_file, "%s.Failed to release audio_service lock\n", __func__);
           } else {
               wakelock_acquired = false;
               fprintf(log_file, "%s.Success to release audio_service lock\n", __func__);
           }
       } else
            fprintf(log_file, "%s.No Lock is acquired to release\n", __func__);
   }
   return wakelock_acquired;
}

void stop_signal_handler(int signal __unused)
{
   stop_playback = true;
@@ -1574,6 +1608,7 @@ int main(int argc, char* argv[]) {
    int j = 0;
    kpi_mode = false;
    event_trigger = false;
    bool wakelock_acquired = false;

    log_file = stdout;
    proxy_params.acp.file_name = "/data/pcm_dump.wav";
@@ -1739,6 +1774,7 @@ int main(int argc, char* argv[]) {
        }
    }

    wakelock_acquired = request_wake_lock(wakelock_acquired, true);
    num_of_streams = i+1;
    fprintf(log_file, "Starting audio hal tests for streams : %d\n", num_of_streams);

@@ -1913,6 +1949,7 @@ exit:
    if ((log_file != stdout) && (log_file != nullptr))
        fclose(log_file);

    wakelock_acquired = request_wake_lock(wakelock_acquired, false);
    fprintf(log_file, "\nBYE BYE\n");
    return 0;
}