From 7e5e59db51bfd47b644492262730ea56b7a75bb3 Mon Sep 17 00:00:00 2001 From: TaeminYeom Date: Tue, 5 Apr 2022 17:38:15 +0900 Subject: [PATCH] Implement a test tool for sensor spec test and stress test Change-Id: I69393e5ad5c0539f051573e91a36bc73abebf11e Signed-off-by: TaeminYeom --- packaging/capi-system-sensor.spec | 2 +- tests/stress_test/CMakeLists.txt | 4 +- tests/stress_test/main.c | 318 ++++++++++------------------------- tests/stress_test/sensor_info.h | 38 +++++ tests/stress_test/spec_test.c | 346 ++++++++++++++++++++++++++++++++++++++ tests/stress_test/spec_test.h | 20 +++ tests/stress_test/stress_test.c | 114 +++++++++++++ tests/stress_test/stress_test.h | 20 +++ 8 files changed, 634 insertions(+), 228 deletions(-) create mode 100644 tests/stress_test/sensor_info.h create mode 100644 tests/stress_test/spec_test.c create mode 100644 tests/stress_test/spec_test.h create mode 100644 tests/stress_test/stress_test.c create mode 100644 tests/stress_test/stress_test.h diff --git a/packaging/capi-system-sensor.spec b/packaging/capi-system-sensor.spec index 03e5ec0..ee395d4 100644 --- a/packaging/capi-system-sensor.spec +++ b/packaging/capi-system-sensor.spec @@ -112,7 +112,7 @@ install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj/%{name} %files test %manifest packaging/capi-system-sensor.manifest %defattr(-,root,root,-) -%{_bindir}/sensor-stress_test +%{_bindir}/sensor-test %{_bindir}/sensor-orientation_test %files tools diff --git a/tests/stress_test/CMakeLists.txt b/tests/stress_test/CMakeLists.txt index 7c26911..9f63335 100644 --- a/tests/stress_test/CMakeLists.txt +++ b/tests/stress_test/CMakeLists.txt @@ -1,5 +1,5 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(sensor-stress_test C) +PROJECT(sensor-test C) SET(PKG_MODULES glib-2.0) @@ -18,7 +18,7 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE") SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie") # Installing files -FILE(GLOB_RECURSE SRCS main.c) +FILE(GLOB_RECURSE SRCS main.c spec_test.c stress_test.c) ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PKGS_LDFLAGS} capi-system-sensor) diff --git a/tests/stress_test/main.c b/tests/stress_test/main.c index 355135e..de7da07 100644 --- a/tests/stress_test/main.c +++ b/tests/stress_test/main.c @@ -1,251 +1,119 @@ -#define SENSOR_NUM 27 -#define TEST_COUNT 1000 -#define PASS 90 +/* + * sensor-test + * + * Copyright (c) 2022 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 -static const sensor_type_e sensor_type[] = -{ - SENSOR_ACCELEROMETER, - SENSOR_GRAVITY, - SENSOR_LINEAR_ACCELERATION, - SENSOR_MAGNETIC, - SENSOR_ROTATION_VECTOR, - SENSOR_ORIENTATION, - SENSOR_GYROSCOPE, - SENSOR_LIGHT, - SENSOR_PROXIMITY, - SENSOR_PRESSURE, - SENSOR_ULTRAVIOLET, - SENSOR_TEMPERATURE, - SENSOR_HUMIDITY, - SENSOR_HRM, - SENSOR_HRM_LED_GREEN, - SENSOR_HRM_LED_IR, - SENSOR_HRM_LED_RED, - SENSOR_GYROSCOPE_UNCALIBRATED, - SENSOR_GEOMAGNETIC_UNCALIBRATED, - SENSOR_GYROSCOPE_ROTATION_VECTOR, - SENSOR_GEOMAGNETIC_ROTATION_VECTOR, - SENSOR_SIGNIFICANT_MOTION, - SENSOR_HRM_BATCH, - SENSOR_HRM_LED_GREEN_BATCH, - SENSOR_HUMAN_PEDOMETER, - SENSOR_HUMAN_SLEEP_MONITOR, - SENSOR_HUMAN_SLEEP_DETECTOR -}; - -static const char *sensor_name[] = { - "Accelerometer", - "Gravity sensor", - "Linear acceleration sensor", - "Magnetic sensor", - "Rotation vector sensor", - "Orientation sensor", - "Gyroscope", - "Light sensor", - "Proximity sensor", - "Pressure sensor", - "Ultraviolet sensor", - "Temperature sensor", - "Humidity sensor", - "Heart-rate monitor", - "Green LED sensor of HRM", - "Infra-Red LED sensor of HRM", - "Red LED sensor of HRM", - "Uncalibrated Gyroscope sensor", - "Uncalibrated Geomagnetic sensor", - "Gyroscope-based rotation vector sensor", - "Geomagnetic-based rotation vector sensor", - "Significant motion sensor", - "Heart-rate monitor batch sensor", - "Green LED of HRM batch sensor", - "Pedometer", - "Sleep monitor", - "Sleep detector" -}; - -// the number of value to be verified of the sensor -static const int value_num[] = {3, 3, 3, 3, 4, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 6, 6, 4, 4, 1, 1, 1, 3, 1}; - -static GMainLoop *loop; -static bool turned_on[SENSOR_NUM]; -static int min_range[SENSOR_NUM]; -static int max_range[SENSOR_NUM]; -static int called_num[SENSOR_NUM]; -static int miss[SENSOR_NUM]; -static int callback_count; -static bool running; +#include "spec_test.h" +#include "stress_test.h" +#include "sensor_info.h" -static void sensor_callback(sensor_h sensor, sensor_event_s events[], int events_count, void *user_data) +static void usage(void) { - sensor_type_e type; - sensor_get_type(sensor, &type); - int num = 0; - bool missed; - - ++callback_count; - - for (int i = 0; i < SENSOR_NUM; ++i){ - if (sensor_type[i] == type){ - num = i; - break; - } - } - - for (int i = 0; i < events_count; ++i) { - missed = false; - ++called_num[num]; - - int value_count; - if (events[i].value_count < value_num[num]) - value_count = events[i].value_count; - else - value_count = value_num[num]; - - for (int j = 0; j < value_count; ++j) { - if (events[i].values[j] < min_range[num] || events[i].values[j] > max_range[num]) { - missed = true; - } + static bool printed = false; + + if (!printed) { + printf("Usage : sensor-test [OPTION]\n"); + printf("Example : sensor-test -t stress -s 1\n"); + printf("[-h|--help] : Show this help\n"); + printf("[-t|--test_type] : spec, stress\n"); + printf("\tspec : verifying measured value of range\n"); + printf("\tstress : giving stress to sensord\n"); + printf("[-s|--sensor_type] : (default is all in spec, accelerometer in stress)\n"); + printf("\t0 : %s (It is valid in only spec test, not stress test)\n", sensor_infos[0].name); + for (int i = 1; i < SENSOR_NUM; ++i) { + printf("\t%d : %s\n", i, sensor_infos[i].name); } - - if(missed) - ++miss[num]; - } - - if (running && callback_count >= TEST_COUNT) { - g_print("done.\n"); - running = false; - g_main_loop_quit(loop); - } - - else if (callback_count == TEST_COUNT / 10 * 2) { - g_print("20%%... "); - } - - else if (callback_count == TEST_COUNT / 10 * 4) { - g_print("40%%... "); - } - - else if (callback_count == TEST_COUNT / 10 * 6) { - g_print("60%%... "); - } - - else if (callback_count == TEST_COUNT / 10 * 8) { - g_print("80%%... "); + printed = true; } } -static int create_sensor_listener(int num, sensor_h *sensor, sensor_listener_h *listener) +int main(int argc, char *argv[]) { - bool supported; - int ret; - float min, max; - const char *name = sensor_name[num]; - sensor_type_e type = sensor_type[num]; - - sensor_is_supported(type, &supported); - if(!supported) { - return -1; - } - - sensor_get_default_sensor(type, sensor); - - sensor_create_listener(*sensor, listener); - sensor_listener_set_events_cb(*listener, sensor_callback, NULL); - sensor_listener_set_option(*listener, SENSOR_OPTION_ALWAYS_ON); - sensor_listener_set_interval(*listener, 100); - - sensor_get_min_range(*sensor, &min); - sensor_get_max_range(*sensor, &max); - min_range[num] = min; - max_range[num] = max; - - g_print("%s : %f ~ %f\n", name, min, max); - - ret = sensor_listener_start(*listener); - if (ret < 0) { - g_print("%s error in listnener_start : %d\n", name, ret); - return ret; + if (argc < 2) { + usage(); + return 0; } - return 0; -} + static const struct option long_options[] = { + {"test_type", required_argument, NULL, 't'}, + {"sensor_type", required_argument, NULL, 's'}, + {"help", no_argument, NULL, 'h'}, + {0, 0, 0, 0}, + }; -int main() -{ - g_print("====================\n"); - g_print("sensor stress test\n"); - g_print("====================\n"); + int mode = 0; + int sensor_type = 0; - sensor_h sensor[29]; - sensor_listener_h listener[29]; - int usable = 0; + for (;;) { + int opt = getopt_long(argc, argv, "t:s:h", long_options, NULL); + if (opt == -1) + break; - for (int i = 0; i < SENSOR_NUM; ++i) { - called_num[i] = 0; - miss[i] = 0; - if (create_sensor_listener(i, &sensor[i], &listener[i])) { - turned_on[i] = false; - } - else { - turned_on[i] = true; - ++usable; + switch (opt) { + case 't': + if (!strcmp(optarg, "spec")) + mode = 1; + else if (!strcmp(optarg, "stress")) + mode = 2; + break; + case 's': + sensor_type = atoi(optarg); + if (sensor_type < 0 || sensor_type >= SENSOR_NUM) { + printf("Wrong sensor number. Sensor number range is 0 ~ %d.\n", SENSOR_NUM - 1); + return 0; + } + break; + case 'h': + usage(); + break; + default: + break; } } - if (usable == 0) { - g_print("There is no supported sensor.\n"); - return -1; - } - - g_print("testing... "); - - running = true; - loop = g_main_loop_new(NULL, FALSE); - g_main_loop_run(loop); - - g_print("====================\n"); - g_print("test result\n"); - g_print("====================\n"); - - int total_miss = 0; - double rate = 0; - for (int i = 0; i < SENSOR_NUM; ++i) { - if (turned_on[i]) { - if (called_num[i]) { - rate = (double) (called_num[i] - miss[i]) / called_num[i] * 100; - g_print("%s : %d / %d \n", sensor_name[i], called_num[i] - miss[i], called_num[i]); - - if (rate >= PASS) - g_print("PASS %.2lf%%\n", rate); - else - g_print("FAIL %.2lf%%\n", rate); - } - else { - g_print("%s value change was not occurred.\n", sensor_name[i]); - } + if (sensor_type) { + bool supported; + int ret; + ret = sensor_is_supported(sensor_infos[sensor_type].type, &supported); + if (ret < 0 || !supported) { + printf("%s is not supported in this device.\n", sensor_infos[sensor_type].name); + return 0; } - total_miss += miss[i]; } - g_print("total : %d / %d \n", callback_count - total_miss, callback_count); - rate = (double) (callback_count - total_miss) / callback_count * 100; - if (rate >= PASS) - g_print("PASS %.2lf%%\n", rate); - else - g_print("FAIL %.2lf%%\n", rate); - - g_print("====================\n"); - g_print("Not supported sensors list\n"); - g_print("====================\n"); + else if (mode == 2) { + sensor_type = 1; + } - for (int i = 0; i < SENSOR_NUM; ++i) { - if (turned_on[i] == false) - g_print("%s\n", sensor_name[i]); + if (mode == 1) + spec_test(sensor_type); + else if (mode == 2) + stress_test(sensor_type); + else { + printf("Enter the test type (spec or stress).\n"); + usage(); } return 0; } - diff --git a/tests/stress_test/sensor_info.h b/tests/stress_test/sensor_info.h new file mode 100644 index 0000000..8662c95 --- /dev/null +++ b/tests/stress_test/sensor_info.h @@ -0,0 +1,38 @@ +#define SENSOR_NUM 28 + +struct sensor_info { + sensor_type_e type; + const char* name; + int value_num; +}; + +static const struct sensor_info sensor_infos[] = { + {SENSOR_ALL, "All", 0}, + {SENSOR_ACCELEROMETER, "Accelerometer", 3}, + {SENSOR_GRAVITY, "Gravity sensor", 3}, + {SENSOR_LINEAR_ACCELERATION, "Linear acceleration sensor", 3}, + {SENSOR_MAGNETIC, "Magnetic sensor", 3}, + {SENSOR_ROTATION_VECTOR, "Rotation vector sensor", 4}, + {SENSOR_ORIENTATION, "Orientation sensor", 3}, + {SENSOR_GYROSCOPE, "Gyroscope", 3}, + {SENSOR_LIGHT, "Light sensor", 1}, + {SENSOR_PROXIMITY, "Proximity sensor", 1}, + {SENSOR_PRESSURE, "Pressure sensor", 1}, + {SENSOR_ULTRAVIOLET, "Ultraviolet sensor", 1}, + {SENSOR_TEMPERATURE, "Temperature sensor", 1}, + {SENSOR_HUMIDITY, "Humidity sensor", 1}, + {SENSOR_HRM, "Heart-rate monitor", 1}, + {SENSOR_HRM_LED_GREEN, "Green LED sensor of HRM", 1}, + {SENSOR_HRM_LED_IR, "Infra-Red LED sensor of HRM", 1}, + {SENSOR_HRM_LED_RED, "Red LED sensor of HRM", 1}, + {SENSOR_GYROSCOPE_UNCALIBRATED, "Uncalibrated Gyroscope sensor", 6}, + {SENSOR_GEOMAGNETIC_UNCALIBRATED, "Uncalibrated Geomagnetic sensor", 6}, + {SENSOR_GYROSCOPE_ROTATION_VECTOR, "Gyroscope-based rotation vector sensor", 4}, + {SENSOR_GEOMAGNETIC_ROTATION_VECTOR, "Geomagnetic-based rotation vector sensor", 4}, + {SENSOR_SIGNIFICANT_MOTION, "Significant motion sensor", 1}, + {SENSOR_HRM_BATCH, "Heart-rate monitor batch sensor", 1}, + {SENSOR_HRM_LED_GREEN_BATCH, "Green LED of HRM batch sensor", 1}, + {SENSOR_HUMAN_PEDOMETER, "Pedometer", 3}, + {SENSOR_HUMAN_SLEEP_MONITOR, "Sleep monitor", 1}, + {SENSOR_HUMAN_SLEEP_DETECTOR, "Sleep detector", 1}, +}; diff --git a/tests/stress_test/spec_test.c b/tests/stress_test/spec_test.c new file mode 100644 index 0000000..2315ad9 --- /dev/null +++ b/tests/stress_test/spec_test.c @@ -0,0 +1,346 @@ +/* + * sensor-test + * + * Copyright (c) 2022 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 "spec_test.h" +#include "sensor_info.h" + +#define TEST_COUNT_ONE 100 +#define TEST_COUNT_ALL 1000 +#define PASS 90 + +static GMainLoop *loop; +static bool turned_on[SENSOR_NUM]; +static int min_range[SENSOR_NUM]; +static int max_range[SENSOR_NUM]; +static int called_num[SENSOR_NUM]; +static int miss[SENSOR_NUM]; +static int callback_count; +static bool running; + + +static void sensor_one_callback(sensor_h sensor, sensor_event_s events[], int events_count, void *user_data) +{ + sensor_type_e type; + sensor_get_type(sensor, &type); + int num = 0; + bool missed; + + ++callback_count; + + for (int i = 1; i < SENSOR_NUM; ++i){ + if (sensor_infos[i].type == type){ + num = i; + break; + } + } + + for (int i = 0; i < events_count; ++i) { + missed = false; + ++called_num[num]; + + int value_count; + if (events[i].value_count < sensor_infos[num].value_num) + value_count = events[i].value_count; + else + value_count = sensor_infos[num].value_num; + + for (int j = 0; j < value_count; ++j) { + if (events[i].values[j] < min_range[num] || events[i].values[j] > max_range[num]) + missed = true; + } + + if (missed) { + ++miss[num]; + g_print("miss : "); + for (int j = 0; j < value_count; ++j) + g_print("%lf ", events[i].values[j]); + g_print("\n"); + } + } + + + if (running && callback_count >= TEST_COUNT_ONE) { + g_print("done.\n"); + running = false; + g_main_loop_quit(loop); + } + + else if (callback_count == TEST_COUNT_ONE / 10 * 2) { + g_print("20%%...\n"); + } + + else if (callback_count == TEST_COUNT_ONE / 10 * 4) { + g_print("40%%...\n"); + } + + else if (callback_count == TEST_COUNT_ONE / 10 * 6) { + g_print("60%%...\n"); + } + + else if (callback_count == TEST_COUNT_ONE / 10 * 8) { + g_print("80%%...\n"); + } +} + +static void sensor_all_callback(sensor_h sensor, sensor_event_s events[], int events_count, void *user_data) +{ + sensor_type_e type; + sensor_get_type(sensor, &type); + int num = 0; + bool missed; + + ++callback_count; + + for (int i = 1; i < SENSOR_NUM; ++i){ + if (sensor_infos[i].type == type){ + num = i; + break; + } + } + + for (int i = 0; i < events_count; ++i) { + missed = false; + ++called_num[num]; + + int value_count; + if (events[i].value_count < sensor_infos[num].value_num) + value_count = events[i].value_count; + else + value_count = sensor_infos[num].value_num; + + for (int j = 0; j < value_count; ++j) { + if (events[i].values[j] < min_range[num] || events[i].values[j] > max_range[num]) { + missed = true; + } + } + + if (missed) + ++miss[num]; + } + + if (running && callback_count >= TEST_COUNT_ALL) { + g_print("done.\n"); + running = false; + g_main_loop_quit(loop); + } + + else if (callback_count == TEST_COUNT_ALL / 10 * 2) { + g_print("20%%..."); + } + + else if (callback_count == TEST_COUNT_ALL / 10 * 4) { + g_print("40%%..."); + } + + else if (callback_count == TEST_COUNT_ALL / 10 * 6) { + g_print("60%%..."); + } + + else if (callback_count == TEST_COUNT_ALL / 10 * 8) { + g_print("80%%..."); + } +} + +static int create_sensor_listener(int num, sensor_h *sensor, sensor_listener_h *listener, bool all) +{ + bool supported; + int ret = 0; + float min, max; + const char *name = sensor_infos[num].name; + sensor_type_e type = sensor_infos[num].type; + + ret = sensor_is_supported(type, &supported); + if (ret < 0) { + printf("fail \"sensor_is_supported\"\n"); + return ret; + } + + else if (!supported) { + return -1; + } + + ret = sensor_get_default_sensor(type, sensor); + if (ret < 0) { + printf("fail \"sensor_get_default_sensor\"\n"); + return ret; + } + + ret = sensor_create_listener(*sensor, listener); + if (ret < 0) { + printf("fail \"sensor_create_listener\"\n"); + return ret; + } + + if (all) + ret = sensor_listener_set_events_cb(*listener, sensor_all_callback, NULL); + else + ret = sensor_listener_set_events_cb(*listener, sensor_one_callback, NULL); + if (ret < 0) { + printf("fail \"sensor_listener_set_events_cb\"\n"); + return ret; + } + + ret = sensor_listener_set_option(*listener, SENSOR_OPTION_ALWAYS_ON); + if (ret < 0) { + printf("fail \"sensor_listener_set_option\"\n"); + return ret; + } + + ret = sensor_listener_set_interval(*listener, 10); + if (ret < 0) { + printf("fail \"sensor_listener_set_interval\"\n"); + return ret; + } + + ret = sensor_get_min_range(*sensor, &min); + if (ret < 0) { + printf("fail \"sensor_get_min_range\"\n"); + return ret; + } + + ret = sensor_get_max_range(*sensor, &max); + if (ret < 0) { + printf("fail \"sensor_get_max_range\"\n"); + return ret; + } + + min_range[num] = min; + max_range[num] = max; + + printf("%s : %f ~ %f\n", name, min, max); + + ret = sensor_listener_start(*listener); + if (ret < 0) { + printf("%s error in listnener_start : %d\n", name, ret); + return ret; + } + + return 0; +} + +static void spec_test_one(int type) +{ + sensor_h sensor; + sensor_listener_h listener; + int ret = create_sensor_listener(type, &sensor, &listener, false); + if (ret < 0) + return; + + running = true; + loop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(loop); + + printf("=====================================\n"); + printf("test result\n"); + printf("=====================================\n"); + + double rate = (double) (called_num[type] - miss[type]) / called_num[type] * 100; + printf("%s : %d / %d \n", sensor_infos[type].name, called_num[type] - miss[type], called_num[type]); + + if (rate >= PASS) + printf("PASS %.2lf%%\n", rate); + else + printf("FAIL %.2lf%%\n", rate); +} + +static void spec_test_all(void) +{ + sensor_h sensor[SENSOR_NUM]; + sensor_listener_h listener[SENSOR_NUM]; + int usable = 0; + + for (int i = 1; i < SENSOR_NUM; ++i) { + called_num[i] = 0; + miss[i] = 0; + if (create_sensor_listener(i, &sensor[i], &listener[i], true)) { + turned_on[i] = false; + } + else { + turned_on[i] = true; + ++usable; + } + } + + if (usable == 0) { + printf("There is no supported sensor.\n"); + return; + } + + printf("testing... "); + + running = true; + loop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(loop); + + printf("=====================================\n"); + printf("test result\n"); + printf("=====================================\n"); + + int total_miss = 0; + double rate = 0; + for (int i = 1; i < SENSOR_NUM; ++i) { + if (turned_on[i]) { + if (called_num[i]) { + rate = (double) (called_num[i] - miss[i]) / called_num[i] * 100; + printf("%s : %d / %d \n", sensor_infos[i].name, called_num[i] - miss[i], called_num[i]); + + if (rate >= PASS) + printf("PASS %.2lf%%\n", rate); + else + printf("FAIL %.2lf%%\n", rate); + } + else { + printf("%s value change was not occurred.\n", sensor_infos[i].name); + } + } + total_miss += miss[i]; + } + + printf("total : %d / %d \n", callback_count - total_miss, callback_count); + rate = (double) (callback_count - total_miss) / callback_count * 100; + if (rate >= PASS) + printf("PASS %.2lf%%\n", rate); + else + printf("FAIL %.2lf%%\n", rate); + + printf("=====================================\n"); + printf("Not supported sensors list\n"); + printf("=====================================\n"); + + for (int i = 1; i < SENSOR_NUM; ++i) { + if (turned_on[i] == false) + printf("%s\n", sensor_infos[i].name); + } +} + +void spec_test(int type) +{ + printf("=====================================\n"); + printf("Sensor spec test (%s)\n", sensor_infos[type].name); + printf("=====================================\n"); + + if (type == 0) + spec_test_all(); + else + spec_test_one(type); +} diff --git a/tests/stress_test/spec_test.h b/tests/stress_test/spec_test.h new file mode 100644 index 0000000..b63dc23 --- /dev/null +++ b/tests/stress_test/spec_test.h @@ -0,0 +1,20 @@ +/* + * sensor-test + * + * Copyright (c) 2022 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. + * + */ + +void spec_test(int type); diff --git a/tests/stress_test/stress_test.c b/tests/stress_test/stress_test.c new file mode 100644 index 0000000..bc83564 --- /dev/null +++ b/tests/stress_test/stress_test.c @@ -0,0 +1,114 @@ +/* + * sensor-test + * + * Copyright (c) 2022 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 "stress_test.h" +#include "sensor_info.h" + +void sensor_events_callback(sensor_h sensor, sensor_event_s events[], int events_count, void *user_data) +{ +} + +void sensor_listener_set_accuracy_callback(sensor_h sensor, unsigned long long timestamp, sensor_data_accuracy_e accuracy, void *data) +{ +} + +void stress_test(int type) +{ + printf("=====================================\n"); + printf("Sensor stress test (%s)\n", sensor_infos[type].name); + printf("=====================================\n"); + printf("Testing... Check sensord memory. (e.g. memps -s )\n"); + printf("If you need, additional execution of this stress test binary in another shell can add more stress to the sensord.\n."); + + sensor_h sh; + sensor_listener_h lh; + sensor_event_s* events; + int ret, count; + while (1) { + ret = sensor_get_default_sensor(sensor_infos[type].type, &sh); + if (ret < 0) { + printf("fail \"get_default_sensor\": %d \n", ret); + break; + } + + ret = sensor_create_listener(sh, &lh); + if (ret < 0) { + printf("fail \"create_listener\": %d\n", ret); + break; + } + + ret = sensor_listener_start(lh); + if (ret < 0) + printf("fail \"listener_start\": %d\n", ret); + + ret = sensor_listener_set_events_cb(lh, sensor_events_callback, NULL); + if (ret < 0) + printf("fail \"listener_set_events_cb\": %d\n", ret); + + ret = sensor_listener_unset_event_cb(lh); + if (ret < 0) + printf("fail \"listener_unset_event_cb\": %d\n", ret); + + ret = sensor_listener_set_accuracy_cb(lh, sensor_listener_set_accuracy_callback, NULL); + if (ret < 0) + printf("fail \"listener_set_accuracy_cb\": %d\n", ret); + + ret = sensor_listener_unset_accuracy_cb(lh); + if (ret < 0) + printf("fail \"listener_unset_accuracy_cb\": %d\n", ret); + + ret = sensor_listener_read_data_list(lh, &events, &count); + if (ret == SENSOR_ERROR_OPERATION_FAILED) + printf("fail \"listener_read_data\". There is no data to read.\n"); + else if (ret < 0) + printf("fail \"listener_read_data\": %d\n", ret); + else + free(events); + + ret = sensor_listener_set_interval(lh, 10); + if (ret < 0) + printf("fail \"listener_set_interval\": %d\n", ret); + + ret = sensor_listener_set_max_batch_latency(lh, 10); + if (ret < 0 && ret != SENSOR_ERROR_NOT_SUPPORTED) + printf("fail \"listener_set_max_batch_latency\": %d\n", ret); + + ret = sensor_listener_set_attribute_int(lh, SENSOR_ATTRIBUTE_AXIS_ORIENTATION, 1); + if (ret < 0) + printf("fail \"listener_set_attribute_int\": %d\n", ret); + + ret = sensor_listener_set_option(lh, SENSOR_OPTION_ALWAYS_ON); + if (ret < 0) + printf("fail \"listener_set_option\": %d\n", ret); + + ret = sensor_listener_stop(lh); + if (ret < 0) + printf("fail \"listener_stop\": %d\n", ret); + + ret = sensor_destroy_listener(lh); + if (ret < 0) + printf("fail \"destroy_listener\": %d\n", ret); + } + + printf("Test was terminated with error.\n"); +} \ No newline at end of file diff --git a/tests/stress_test/stress_test.h b/tests/stress_test/stress_test.h new file mode 100644 index 0000000..e0b7702 --- /dev/null +++ b/tests/stress_test/stress_test.h @@ -0,0 +1,20 @@ +/* + * sensor-test + * + * Copyright (c) 2022 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. + * + */ + +void stress_test(int type); -- 2.7.4