qahw: test: Handle SIGINT signal internally in test app

Avoid standard SIGINT implementation and handle internally in
test app.Also Fix some warnings during compilation.

Change-Id: I6e64d149437775b00862f4bb2cf00e1a91a69e15
diff --git a/qahw_api/test/Makefile.am b/qahw_api/test/Makefile.am
index 46a2ee7..5378e0b 100644
--- a/qahw_api/test/Makefile.am
+++ b/qahw_api/test/Makefile.am
@@ -1,6 +1,6 @@
 bin_PROGRAMS = hal_play_test
 
-PLAY_CPPFLAGS = -Wno-sign-compare
+PLAY_CPPFLAGS = -Wno-sign-compare -Werror
 PLAY_INCLUDES = -I $(top_srcdir)/qahw_api/inc
 
 hal_play_test_SOURCES = qahw_playback_test.c \
diff --git a/qahw_api/test/qahw_multi_record_test.c b/qahw_api/test/qahw_multi_record_test.c
index 81924a3..b67df4d 100644
--- a/qahw_api/test/qahw_multi_record_test.c
+++ b/qahw_api/test/qahw_multi_record_test.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
  * Not a Contribution.
  *
  * Copyright (C) 2015 The Android Open Source Project *
@@ -37,6 +37,7 @@
 
 static bool kpi_mode;
 FILE * log_file = NULL;
+volatile bool stop_record = false;
 
 #define ID_RIFF 0x46464952
 #define ID_WAVE 0x45564157
@@ -92,16 +93,12 @@
 static pthread_mutex_t sourcetrack_lock;
 char soundfocus_param[100];
 
-void sourcetrack_signal_handler(void)
+void stop_signal_handler(int signal)
 {
-/* Function to read keyboard interupt to enable user to set parameters
-   for sourcetracking usecase Dynamically */
-
-    pthread_mutex_lock(&sourcetrack_lock);
-    read_soundfocus_param();
-    pthread_mutex_unlock(&sourcetrack_lock);
+   stop_record = true;
 }
 
+
 void read_soundfocus_param(void)
 {
     char params[50] = {0};
@@ -121,6 +118,16 @@
              gain_step);
 }
 
+void sourcetrack_signal_handler(int signal)
+{
+/* Function to read keyboard interupt to enable user to set parameters
+   for sourcetracking usecase Dynamically */
+
+    pthread_mutex_lock(&sourcetrack_lock);
+    read_soundfocus_param();
+    pthread_mutex_unlock(&sourcetrack_lock);
+}
+
 void *read_sourcetrack_data(void* data)
 {
     int idx =0, status = 0,count = 0, sect = 0;
@@ -336,7 +343,7 @@
 
   memset(&in_buf,0, sizeof(qahw_in_buffer_t));
   start_time = time(0);
-  while(true) {
+  while(true && !stop_record) {
       if(time_elapsed < params->record_delay) {
           usleep(1000000*(params->record_delay - time_elapsed));
           time_elapsed = difftime(time(0), start_time);
@@ -729,8 +736,10 @@
                source_tracking = 0;
                goto sourcetrack_error;
         }
-        signal(SIGQUIT, sourcetrack_signal_handler);
-        printf("NOTE::::To set sourcetracking params at runtime press 'Ctrl+\\' from keyboard\n");
+        if (signal(SIGQUIT, sourcetrack_signal_handler) == SIG_ERR)
+            fprintf(log_file, "Failed to register SIGQUIT:%d\n",errno);
+        else
+            printf("NOTE::::To set sourcetracking params at runtime press 'Ctrl+\\' from keyboard\n");
         read_soundfocus_param();
         printf("Create source tracking thread \n");
         ret = pthread_create(&sourcetrack_thread,
@@ -744,6 +753,10 @@
         }
     }
 
+    /* Register the SIGINT to close the App properly */
+    if (signal(SIGINT, stop_signal_handler) == SIG_ERR)
+        fprintf(log_file, "Failed to register SIGINT:%d\n",errno);
+
     if (thread_active[0] == 1) {
         fprintf(log_file, "\n Create first record thread \n");
         ret = pthread_create(&tid[0], NULL, start_input, (void *)&params[0]);
diff --git a/qahw_api/test/qahw_playback_test.c b/qahw_api/test/qahw_playback_test.c
index d539ce2..4590f87 100644
--- a/qahw_api/test/qahw_playback_test.c
+++ b/qahw_api/test/qahw_playback_test.c
@@ -25,6 +25,7 @@
 #include <string.h>
 #include <errno.h>
 #include <time.h>
+#include <signal.h>
 #include "qahw_api.h"
 #include "qahw_defs.h"
 #include "qahw_effect_api.h"
@@ -80,6 +81,7 @@
     struct wav_header hdr;
 };
 FILE * log_file = NULL;
+volatile bool stop_playback = false;
 const char *log_filename = NULL;
 float vol_level = 0.01;
 pthread_t proxy_thread;
@@ -153,6 +155,11 @@
                    "music_offload_wma_encode_option2=%d;" \
                    "music_offload_wma_format_tag=%d;"
 
+void stop_signal_handler(int signal)
+{
+   stop_playback = true;
+}
+
 void read_kvpair(char *kvpair, char* kvpair_values, int filetype)
 {
     char *kvpair_type;
@@ -350,7 +357,7 @@
         return -ENOMEM;
     }
 
-    while (!exit) {
+    while (!exit && !stop_playback) {
         if (!bytes_remaining) {
             bytes_read = fread(data, 1, bytes_wanted, in_file);
             fprintf(log_file, "fread from file %zd\n", bytes_read);
@@ -968,6 +975,9 @@
         // enable effect
         effect_thread_command(ethread_data, EFFECT_CMD, QAHW_EFFECT_CMD_ENABLE, 0, NULL);
     }
+    /* Register the SIGINT to close the App properly */
+    if (signal(SIGINT, stop_signal_handler) == SIG_ERR)
+        fprintf(log_file, "Failed to register SIGINT:%d\n",errno);
 
     play_file(out_handle,
               file_stream,