Restructuring test folder to include parallel sensor test case 93/37193/2
authorAnkur <ankur29.garg@samsung.com>
Fri, 20 Mar 2015 10:38:08 +0000 (16:08 +0530)
committerAnkur <ankur29.garg@samsung.com>
Fri, 20 Mar 2015 10:43:45 +0000 (16:13 +0530)
Restructured the test folder to separate the functions from tc-common because
they will also be used by a new test case (to be added in the next patch) for testing multiple test cases in parallel.

Change-Id: If36de3b1123bd3811516fa859be73a753dc686e7

packaging/sensord.spec
test/CMakeLists.txt
test/src/api-test.c [moved from test/src/auto_test.c with 100% similarity]
test/src/check-sensor.c [moved from test/src/tc-common.c with 61% similarity]
test/src/check-sensor.h [new file with mode: 0644]
test/src/sensor-test.c [new file with mode: 0644]

index e311020..af660f2 100755 (executable)
@@ -138,7 +138,7 @@ systemctl daemon-reload
 %if %{build_test_suite} == "ON"
 %files -n sensor-test
 %defattr(-,root,root,-)
-%{_bindir}/auto_test
-%{_bindir}/tc-common
+%{_bindir}/api-test
+%{_bindir}/sensor-test
 %license LICENSE.APLv2
 %endif
index e81b9c0..0f6c8d4 100644 (file)
@@ -25,14 +25,14 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 
 link_directories(../src/libsensord/)
 
-add_executable(auto_test src/auto_test.c)
-add_executable(tc-common src/tc-common.c)
+add_executable(api-test src/api-test.c)
+add_executable(sensor-test src/sensor-test.c src/check-sensor.c)
 
-SET_TARGET_PROPERTIES(auto_test PROPERTIES LINKER_LANGUAGE C)
-SET_TARGET_PROPERTIES(tc-common PROPERTIES LINKER_LANGUAGE C)
+SET_TARGET_PROPERTIES(api-test PROPERTIES LINKER_LANGUAGE C)
+SET_TARGET_PROPERTIES(sensor-test PROPERTIES LINKER_LANGUAGE C)
 
-target_link_libraries(auto_test glib-2.0 dlog sensor)
-target_link_libraries(tc-common glib-2.0 dlog sensor)
+target_link_libraries(api-test glib-2.0 dlog sensor)
+target_link_libraries(sensor-test glib-2.0 dlog sensor)
 
-INSTALL(TARGETS auto_test DESTINATION /usr/bin/)
-INSTALL(TARGETS tc-common DESTINATION /usr/bin/)
+INSTALL(TARGETS api-test DESTINATION /usr/bin/)
+INSTALL(TARGETS sensor-test DESTINATION /usr/bin/)
similarity index 100%
rename from test/src/auto_test.c
rename to test/src/api-test.c
similarity index 61%
rename from test/src/tc-common.c
rename to test/src/check-sensor.c
index 634af34..3c28feb 100644 (file)
 #include <unistd.h>
 #include <string.h>
 
-#define DEFAULT_EVENT_INTERVAL 100
+#include "check-sensor.h"
 
 static GMainLoop *mainloop;
 
-void usage()
-{
-       printf("Usage : ./tc-common <Sensor_type> <event>(optional) <interval>(optional)\n\n");
-
-       printf("Sensor_type: ");
-       printf("[accelerometer] ");
-       printf("[gyroscope] ");
-       printf("[pressure] ");
-       printf("[temperature] ");
-       printf("[geomagnetic] ");
-       printf("[orientation] ");
-       printf("[gravity] ");
-       printf("[linear_accel] ");
-       printf("[rotation_vector] ");
-       printf("[geomagnetic_rv] ");
-       printf("[gaming_rv] ");
-       printf("[light]\n");
-       printf("event:");
-       printf("[RAW_DATA_REPORT_ON_TIME]\n");
-
-       printf("Sensor_type: ");
-       printf("[proximity]\n");
-       printf("event:");
-       printf("[EVENT_CHANGE_STATE]\n");
-
-       printf("interval:\n");
-       printf("The time interval should be entered based on the sampling frequency supported by accelerometer driver on the device in ms.If no value for sensor is entered default value by the driver will be used.\n");
-}
-
 int get_event_driven(sensor_type_t sensor_type, char str[])
 {
        switch (sensor_type) {
@@ -168,107 +139,11 @@ void callback(sensor_t sensor, unsigned int event_type, sensor_data_t *data, voi
        }
 }
 
-int main(int argc, char **argv)
+int check_sensor(sensor_type_t sensor_type, unsigned int event, int interval)
 {
-       int result, handle, start_handle, stop_handle, interval;
-       char *end1, *end2;
-       int event;
-       bool EVENT_NOT_ENTERED = TRUE;
-       sensor_type_t sensor_type;
-       mainloop = g_main_loop_new(NULL, FALSE);
-
-       if (argc < 2 || argc > 4) {
-               printf("Wrong number of arguments\n");
-               usage();
-               return 0;
-       }
+       int handle, result, start_handle, stop_handle;
 
-       if (strcmp(argv[1], "accelerometer") == 0) {
-                sensor_type = ACCELEROMETER_SENSOR;
-                event = ACCELEROMETER_RAW_DATA_EVENT;
-       }
-       else if (strcmp(argv[1], "gyroscope") == 0) {
-                sensor_type = GYROSCOPE_SENSOR;
-                event = GYROSCOPE_RAW_DATA_EVENT;
-       }
-       else if (strcmp(argv[1], "pressure") == 0) {
-                sensor_type = PRESSURE_SENSOR;
-                event = PRESSURE_RAW_DATA_EVENT;
-       }
-       else if (strcmp(argv[1], "temperature") == 0) {
-                sensor_type = TEMPERATURE_SENSOR;
-                event = TEMPERATURE_RAW_DATA_EVENT;
-       }
-       else if (strcmp(argv[1], "geomagnetic") == 0) {
-                sensor_type = GEOMAGNETIC_SENSOR;
-                event = GEOMAGNETIC_RAW_DATA_EVENT;
-       }
-       else if (strcmp(argv[1], "orientation") == 0) {
-                sensor_type = ORIENTATION_SENSOR;
-                event = ORIENTATION_RAW_DATA_EVENT;
-       }
-       else if (strcmp(argv[1], "gravity") == 0) {
-                sensor_type = GRAVITY_SENSOR;
-                event = GRAVITY_RAW_DATA_EVENT;
-       }
-       else if (strcmp(argv[1], "linear_accel") == 0) {
-                sensor_type = LINEAR_ACCEL_SENSOR;
-                event = LINEAR_ACCEL_RAW_DATA_EVENT;
-       }
-       else if (strcmp(argv[1], "rotation_vector") == 0) {
-                sensor_type = ROTATION_VECTOR_SENSOR;
-                event = ROTATION_VECTOR_RAW_DATA_EVENT;
-       }
-       else if (strcmp(argv[1], "geomagnetic_rv") == 0) {
-                sensor_type = GEOMAGNETIC_RV_SENSOR;
-                event = GEOMAGNETIC_RV_RAW_DATA_EVENT;
-       }
-       else if (strcmp(argv[1], "gaming_rv") == 0) {
-                sensor_type = GAMING_RV_SENSOR;
-                event = GAMING_RV_RAW_DATA_EVENT;
-       }
-       else if (strcmp(argv[1], "light") == 0) {
-                sensor_type = LIGHT_SENSOR;
-                event = LIGHT_LUX_DATA_EVENT;
-       }
-       else if (strcmp(argv[1], "proximity") == 0) {
-                sensor_type = PROXIMITY_SENSOR;
-                event = PROXIMITY_CHANGE_STATE_EVENT;
-       }
-       else {
-                usage();
-       }
-
-       interval = DEFAULT_EVENT_INTERVAL;
-
-       if (argc > 2) {
-               event = get_event_driven(sensor_type, argv[2]);
-
-               if (event == -1) {
-                       usage();
-                       return -1;
-               }
-
-               EVENT_NOT_ENTERED = FALSE;
-       }
-
-       if (argc == 4) {
-               interval = strtol(argv[3], &end1, 10);
-
-               if (*end1) {
-                       printf("Conversion error, non-convertible part: %s\n", end1);
-                       return -1;
-               }
-       }
-
-       if (argc == 3 && EVENT_NOT_ENTERED) {
-               interval = strtol(argv[2], &end2, 10);
-
-               if (*end2) {
-                       printf("Conversion error, non-convertible part: %s\n", end2);
-                       return -1;
-               }
-       }
+       mainloop = g_main_loop_new(NULL, FALSE);
 
        sensor_t sensor = sensord_get_sensor(sensor_type);
        handle = sensord_connect(sensor);
@@ -276,7 +151,7 @@ int main(int argc, char **argv)
        result = sensord_register_event(handle, event, interval, 0, callback, NULL);
 
        if (result < 0) {
-               printf("Can't register %s\n", argv[1]);
+               printf("Can't register sensor\n");
                return -1;
        }
 
diff --git a/test/src/check-sensor.h b/test/src/check-sensor.h
new file mode 100644 (file)
index 0000000..097a770
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * sensord
+ *
+ * Copyright (c) 2014-15 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef CHECK_SENSOR_H
+#define CHECK_SENSOR_H
+
+#define DEFAULT_EVENT_INTERVAL 100
+
+int get_event_driven(sensor_type_t sensor_type, char str[]);
+void callback(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data);
+int check_sensor(sensor_type_t sensor_type, unsigned int event, int interval);
+
+#endif
diff --git a/test/src/sensor-test.c b/test/src/sensor-test.c
new file mode 100644 (file)
index 0000000..0b55112
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ * sensord
+ *
+ * Copyright (c) 2014-15 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <glib.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sensor_internal.h>
+#include <stdbool.h>
+#include <sensor_common.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "check-sensor.h"
+
+void usage()
+{
+       printf("Usage : ./sensor-test <Sensor_type> <event>(optional) <interval>(optional)\n\n");
+
+       printf("Sensor_type: ");
+       printf("[accelerometer] ");
+       printf("[gyroscope] ");
+       printf("[pressure] ");
+       printf("[temperature] ");
+       printf("[geomagnetic] ");
+       printf("[orientation] ");
+       printf("[gravity] ");
+       printf("[linear_accel] ");
+       printf("[rotation_vector] ");
+       printf("[geomagnetic_rv] ");
+       printf("[gaming_rv] ");
+       printf("[light]\n");
+       printf("event:");
+       printf("[RAW_DATA_REPORT_ON_TIME]\n");
+
+       printf("Sensor_type: ");
+       printf("[proximity]\n");
+       printf("event:");
+       printf("[EVENT_CHANGE_STATE]\n");
+
+       printf("interval:\n");
+       printf("The time interval should be entered based on the sampling frequency supported by accelerometer driver on the device in ms.If no value for sensor is entered default value by the driver will be used.\n");
+}
+
+int main(int argc, char **argv)
+{
+       int interval;
+       unsigned int event;
+       sensor_type_t sensor_type;
+
+       char *end1;
+
+       if (argc < 2 || argc > 4) {
+               printf("Wrong number of arguments\n");
+               usage();
+               return 0;
+       }
+
+       if (strcmp(argv[1], "accelerometer") == 0) {
+                sensor_type = ACCELEROMETER_SENSOR;
+                event = ACCELEROMETER_RAW_DATA_EVENT;
+       }
+       else if (strcmp(argv[1], "gyroscope") == 0) {
+                sensor_type = GYROSCOPE_SENSOR;
+                event = GYROSCOPE_RAW_DATA_EVENT;
+       }
+       else if (strcmp(argv[1], "pressure") == 0) {
+                sensor_type = PRESSURE_SENSOR;
+                event = PRESSURE_RAW_DATA_EVENT;
+       }
+       else if (strcmp(argv[1], "temperature") == 0) {
+                sensor_type = TEMPERATURE_SENSOR;
+                event = TEMPERATURE_RAW_DATA_EVENT;
+       }
+       else if (strcmp(argv[1], "geomagnetic") == 0) {
+                sensor_type = GEOMAGNETIC_SENSOR;
+                event = GEOMAGNETIC_RAW_DATA_EVENT;
+       }
+       else if (strcmp(argv[1], "orientation") == 0) {
+                sensor_type = ORIENTATION_SENSOR;
+                event = ORIENTATION_RAW_DATA_EVENT;
+       }
+       else if (strcmp(argv[1], "gravity") == 0) {
+                sensor_type = GRAVITY_SENSOR;
+                event = GRAVITY_RAW_DATA_EVENT;
+       }
+       else if (strcmp(argv[1], "linear_accel") == 0) {
+                sensor_type = LINEAR_ACCEL_SENSOR;
+                event = LINEAR_ACCEL_RAW_DATA_EVENT;
+       }
+       else if (strcmp(argv[1], "rotation_vector") == 0) {
+                sensor_type = ROTATION_VECTOR_SENSOR;
+                event = ROTATION_VECTOR_RAW_DATA_EVENT;
+       }
+       else if (strcmp(argv[1], "geomagnetic_rv") == 0) {
+                sensor_type = GEOMAGNETIC_RV_SENSOR;
+                event = GEOMAGNETIC_RV_RAW_DATA_EVENT;
+       }
+       else if (strcmp(argv[1], "gaming_rv") == 0) {
+                sensor_type = GAMING_RV_SENSOR;
+                event = GAMING_RV_RAW_DATA_EVENT;
+       }
+       else if (strcmp(argv[1], "light") == 0) {
+                sensor_type = LIGHT_SENSOR;
+                event = LIGHT_LUX_DATA_EVENT;
+       }
+       else if (strcmp(argv[1], "proximity") == 0) {
+                sensor_type = PROXIMITY_SENSOR;
+                event = PROXIMITY_CHANGE_STATE_EVENT;
+       }
+       else {
+                usage();
+       }
+
+       interval = DEFAULT_EVENT_INTERVAL;
+
+       if (argc == 3) {
+               int temp_event = get_event_driven(sensor_type, argv[2]);
+
+               if (temp_event == -1) {
+                       interval = atoi(argv[2]);
+                       if (interval == 0){
+                               usage();
+                               return -1;
+                       }
+               }
+               else {
+                       event = temp_event;
+               }
+       }
+       else if (argc == 4) {
+               event = get_event_driven(sensor_type, argv[2]);
+               interval = strtol(argv[3], &end1, 10);
+
+               if (*end1) {
+                       printf("Conversion error, non-convertible part: %s\n", end1);
+                       return -1;
+               }
+       }
+
+       return check_sensor(sensor_type, event, interval);
+}