Adding test automation suite for sensord 98/26898/21
authorVibhor Gaur <vibhor.gaur@samsung.com>
Mon, 1 Sep 2014 05:19:09 +0000 (10:49 +0530)
committerKibak Yoon <kibak.yoon@samsung.com>
Mon, 22 Sep 2014 04:28:20 +0000 (21:28 -0700)
1.Adding seperate test case folder for sensord along with necessary make files and updated spec file.
2.Test suite is disabled by default by setting build_test_suite to OFF in the spec file in the packaging folder.Test suite can be enabled by setting build_test_suite ON.

Change-Id: I6e46febc7011f3faf18e216f4dfc327648fd91d5

CMakeLists.txt
test/CMakeLists.txt [new file with mode: 0644]
test/sensor-tc.pc [new file with mode: 0644]
test/sensor-tc.pc.in [new file with mode: 0644]
test/src/accelerometer.c [new file with mode: 0644]

index fbcfe9a..b555de8 100755 (executable)
@@ -16,7 +16,6 @@ set(PROJECT_MAJOR_VERSION "0")
 set(PROJECT_MINOR_VERSION "2")
 set(PROJECT_RELEASE_VERSION "1")
 set(CMAKE_VERBOSE_MAKEFILE OFF)
-
 add_definitions(-Wall -O3 -omit-frame-pointer)
 add_definitions(-DUSE_DLOG_LOG)
 #add_definitions(-Wall -g -D_DEBUG)
@@ -50,4 +49,13 @@ ENDIF("${ARCH}" MATCHES "^arm.*")
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.APLv2 DESTINATION share/license RENAME sensord)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.APLv2 DESTINATION share/license RENAME libsensord)
 
+IF("${TEST_SUITE}" STREQUAL "ON")
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.APLv2 DESTINATION share/license RENAME test)
+ENDIF()
+
 add_subdirectory(src)
+
+IF("${TEST_SUITE}" STREQUAL "ON")
+add_subdirectory(test)
+ENDIF()
+
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..c9d75d4
--- /dev/null
@@ -0,0 +1,40 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+project(sensor-tc C)
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "\${prefix}")
+SET(LIBDIR "\${prefix}/lib")
+SET(INCLUDEDIR "\${prefix}/include")
+SET(VERSION 1.0)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED glib-2.0 dlog)
+
+add_definitions(${rpkgs_CFLAGS})
+add_definitions(-DPREFIX="${CMAKE_INSTALL_PREFIX}")
+
+configure_file(${PROJECT_NAME}.pc.in ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc @ONLY)
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+include_directories(${CMAKE_SOURCE_DIR}/src/libsensord)
+include_directories(${CMAKE_SOURCE_DIR}/src/shared)
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+link_directories(../src/libsensord/)
+
+add_executable(accelerometer src/accelerometer.c)
+
+SET_TARGET_PROPERTIES(accelerometer PROPERTIES LINKER_LANGUAGE C)
+
+target_link_libraries(accelerometer glib-2.0 dlog sensor)
+
+INSTALL(TARGETS accelerometer DESTINATION /usr/bin/)
+
+
+
+
diff --git a/test/sensor-tc.pc b/test/sensor-tc.pc
new file mode 100644 (file)
index 0000000..33b2994
--- /dev/null
@@ -0,0 +1,13 @@
+# Package Information for pkg-config
+
+prefix=/usr/bin
+exec_prefix=${prefix}
+libdir=${prefix}/lib
+includedir=${prefix}/include/sensor-tc
+
+Name: sensor-tc
+Description: Sensor functional testing library
+Version: 1.0
+Requires:
+Libs: -L${libdir} -lsensor-tc
+Cflags: -I${includedir}
diff --git a/test/sensor-tc.pc.in b/test/sensor-tc.pc.in
new file mode 100644 (file)
index 0000000..0f821b6
--- /dev/null
@@ -0,0 +1,13 @@
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=@EXEC_PREFIX@
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@/sensor-tc
+
+Name: sensor-tc
+Description: Sensor functional testing library
+Version: @VERSION@
+Requires:
+Libs: -L${libdir} -lsensor-tc
+Cflags: -I${includedir}
diff --git a/test/src/accelerometer.c b/test/src/accelerometer.c
new file mode 100644 (file)
index 0000000..fd2bc5e
--- /dev/null
@@ -0,0 +1,105 @@
+#include <time.h>
+#include <glib.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sensor.h>
+#include <stdbool.h>
+
+static GMainLoop *mainloop;
+
+void callback(unsigned int event_type, sensor_event_data_t *event, void *user_data)
+{
+       sensor_data_t *data = (sensor_data_t *)event->event_data;
+       printf("Accelerometer [%6.6f] [%6.6f] [%6.6f] [%lld]\n\n", data->values[0], data->values[1], data->values[2], data->timestamp);
+}
+
+void printformat()
+{
+       printf("Usage : ./accelerometer <event> <interval>(optional)\n\n");
+       printf("event:\n");
+       printf("ROTATION_CHECK\n");
+       printf("RAW_DATA_REPORT_ON_TIME\n");
+       printf("CALIBRATION_NEEDED\n");
+       printf("SET_HORIZON\n");
+       printf("SET_WAKEUP\n");
+       printf("ORIENTATION_DATA_REPORT_ON_TIME\n");
+       printf("LINEAR_ACCELERATION_DATA_REPORT_ON_TIME\n");
+       printf("GRAVITY_DATA_REPORT_ON_TIME\n\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 result, handle;
+       unsigned int event;
+       bool error_state = FALSE;
+
+       mainloop = g_main_loop_new(NULL, FALSE);
+       sensor_type_t type = ACCELEROMETER_SENSOR;
+       event_condition_t *event_condition = (event_condition_t*) malloc(sizeof(event_condition_t));
+       event_condition->cond_op = CONDITION_EQUAL;
+       event_condition->cond_value1=100;
+
+       if (argc != 2 && argc != 3) {
+               printformat();
+               error_state = TRUE;
+       }
+       else {
+               if (strcmp(argv[1], "ROTATION_CHECK") == 0)
+                       event = ACCELEROMETER_EVENT_ROTATION_CHECK;
+               else if (strcmp(argv[1], "RAW_DATA_REPORT_ON_TIME") == 0)
+                       event = ACCELEROMETER_EVENT_RAW_DATA_REPORT_ON_TIME;
+               else if (strcmp(argv[1], "CALIBRATION_NEEDED") == 0)
+                       event = ACCELEROMETER_EVENT_CALIBRATION_NEEDED;
+               else if (strcmp(argv[1], "SET_HORIZON") == 0)
+                       event = ACCELEROMETER_EVENT_SET_HORIZON;
+               else if (strcmp(argv[1], "SET_WAKEUP") == 0)
+                       event = ACCELEROMETER_EVENT_SET_WAKEUP;
+               else if (strcmp(argv[1], "ORIENTATION_DATA_REPORT_ON_TIME") == 0)
+                       event = ACCELEROMETER_EVENT_ORIENTATION_DATA_REPORT_ON_TIME;
+               else if (strcmp(argv[1], "LINEAR_ACCELERATION_DATA_REPORT_ON_TIME") == 0)
+                       event = ACCELEROMETER_EVENT_LINEAR_ACCELERATION_DATA_REPORT_ON_TIME;
+               else if (strcmp(argv[1], "GRAVITY_DATA_REPORT_ON_TIME") == 0)
+                       event = ACCELEROMETER_EVENT_GRAVITY_DATA_REPORT_ON_TIME;
+               else {
+                       printformat();
+                       error_state = TRUE;
+               }
+               if (argc == 3)
+                       event_condition->cond_value1 = atof(argv[2]);
+       }
+
+       if (!error_state) {
+               handle = sf_connect(type);
+               result = sf_register_event(handle, event, event_condition, callback, NULL);
+
+               if (result < 0)
+                       printf("Can't register accelerometer\n");
+
+               if (!(sf_start(handle,0) < 0)) {
+                       printf("Success start \n");
+               }
+               else {
+                       printf("Error\n\n\n\n");
+                       sf_unregister_event(handle, event);
+                       sf_disconnect(handle);
+                       return -1;
+               }
+
+               g_main_loop_run(mainloop);
+               g_main_loop_unref(mainloop);
+
+               sf_unregister_event(handle, event);
+
+               if (!(sf_stop(handle) < 0))
+                       printf("Success stop \n");
+
+               sf_disconnect(handle);
+       }
+
+       free(event_condition);
+
+       return 0;
+}
+