From: Ankur Date: Mon, 23 Mar 2015 07:05:03 +0000 (+0530) Subject: Adding new test case for testing sensors in parallel X-Git-Tag: submit/tizen/20151218.070016~88 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ab1a0791801b6c91316a3e032b6dcfea5bbbae77;p=platform%2Fcore%2Fsystem%2Fsensord.git Adding new test case for testing sensors in parallel This test case runs multiple sensor tests in parallel. It can be used for performance analysis of the various modules. Change-Id: I10a3e7ec98140ce6ecdcb6a29a0b8d6052e3287e --- diff --git a/packaging/sensord.spec b/packaging/sensord.spec index af660f2..0f3c296 100755 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -140,5 +140,6 @@ systemctl daemon-reload %defattr(-,root,root,-) %{_bindir}/api-test %{_bindir}/sensor-test +%{_bindir}/performance-test %license LICENSE.APLv2 %endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0f6c8d4..8716991 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -27,12 +27,16 @@ link_directories(../src/libsensord/) add_executable(api-test src/api-test.c) add_executable(sensor-test src/sensor-test.c src/check-sensor.c) +add_executable(performance-test src/performance-test.c src/check-sensor.c) SET_TARGET_PROPERTIES(api-test PROPERTIES LINKER_LANGUAGE C) SET_TARGET_PROPERTIES(sensor-test PROPERTIES LINKER_LANGUAGE C) +SET_TARGET_PROPERTIES(performance-test PROPERTIES LINKER_LANGUAGE C) target_link_libraries(api-test glib-2.0 dlog sensor) target_link_libraries(sensor-test glib-2.0 dlog sensor) +target_link_libraries(performance-test glib-2.0 dlog sensor) INSTALL(TARGETS api-test DESTINATION /usr/bin/) INSTALL(TARGETS sensor-test DESTINATION /usr/bin/) +INSTALL(TARGETS performance-test DESTINATION /usr/bin/) diff --git a/test/src/performance-test.c b/test/src/performance-test.c new file mode 100644 index 0000000..207b6fc --- /dev/null +++ b/test/src/performance-test.c @@ -0,0 +1,110 @@ +/* + * sensord + * + * Copyright (c) 2015 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 +#include +#include +#include +#include + +#include "check-sensor.h" + +void usage() +{ + printf("Usage : ./performance-test (optional)\n\n"); + + printf("TIMEOUT:\n"); + printf("time for which the parallel sensor test cases should run\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.\n"); + printf("If no value for sensor is entered default value by the driver will be used.\n"); +} + +int main(int argc, char** argv) +{ + pid_t b = 1; + + int i = 0; + int interval = DEFAULT_EVENT_INTERVAL; + int TIMEOUT = 10; //in seconds for which all the sensor tests should run + + if(argc < 2) { + usage(); + return -1; + } + else if(argc == 2){ + TIMEOUT = atoi(argv[1]); + if (TIMEOUT == 0) { + usage(); + return -1; + } + } + else { + TIMEOUT = atoi(argv[1]); + interval = atoi(argv[2]); + if (TIMEOUT == 0 || interval == 0) { + usage(); + return -1; + } + } + + //make an array of size MAX and fill it with all the sensors needed to run + int MAX = 6; + pid_t pids[MAX]; + sensor_type_t sensor[MAX]; + + //Update the value of MAX and add more sensors here to test more sensors in parallel + sensor[0] = ACCELEROMETER_SENSOR; + sensor[1] = GYROSCOPE_SENSOR; + sensor[2] = GEOMAGNETIC_SENSOR; + sensor[3] = PRESSURE_SENSOR; + sensor[4] = PROXIMITY_SENSOR; + sensor[MAX-1] = LIGHT_SENSOR; + + while (i < MAX) { + if (b > 0) { + b = fork(); + if (b == -1) perror("Fork failed\n"); + else if (b == 0) { + break; + } + pids[i] = b; + i++; + } + } + + if (i < MAX) { + // call the sensord test tc-common for a sensor. + int event = (sensor[i] << 16) | 0x0001; + check_sensor(sensor[i], event, interval); + } + else { + // Main Parent Child. Waits for TIMEOUT and then kills all child processes. + sleep (TIMEOUT); + int j = 0; + + for (j = 0; j < MAX; j++) { + char command[100]; + sprintf(command, "kill %d", pids[j]); + system(command); + } + } + + return 0; +}