4 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
26 #include "test_bench.h"
27 #include "sensor_adapter.h"
29 #define MAX_COUNT 999999
30 #define TEST_DEFAULT_INTERVAL 100
31 #define TEST_DEFAULT_LATENCY 0
32 #define TEST_DEFAULT_POWERSAVE_OPTION SENSOR_OPTION_ALWAYS_ON
34 #define TEST_MANUAL "manual"
36 static sensor_type_t stype;
42 class tester_manual : public tester {
44 tester_manual(const char *name);
45 virtual ~tester_manual();
47 bool setup(sensor_type_t type, int argc, char *argv[]);
50 bool run(int argc, char *argv[]);
54 tester_manual::tester_manual(const char *name)
59 tester_manual::~tester_manual()
63 bool tester_manual::setup(sensor_type_t type, int argc, char *argv[])
66 interval = TEST_DEFAULT_INTERVAL;
67 latency = TEST_DEFAULT_LATENCY;
68 powersave = TEST_DEFAULT_POWERSAVE_OPTION;
70 if (!test_option::set_options(argc, argv)) {
75 interval = test_option::interval;
76 latency = test_option::latency;
77 powersave = test_option::powersave;
80 interval = TEST_DEFAULT_INTERVAL;
82 latency = TEST_DEFAULT_LATENCY;
84 powersave = TEST_DEFAULT_POWERSAVE_OPTION;
89 bool tester_manual::teardown(void)
94 bool tester_manual::run(int argc, char *argv[])
96 test_option::filter = "^manual[\\w\\.]+";
97 test_bench::run_all_testcases();
102 void tester_manual::usage(void)
104 _N("Usage : sensorctl test <sensor_type>\n");
105 _N(" [--interval=NUMBER] [--batch_latency=NUMBER] [--powersave=TYPE]\n");
106 _N(" [--repeat=NUMBER] [--output=FILE_PATH] [--help] [--verbose]\n");
109 _N(" sensorctl test accelerometer\n");
110 _N(" sensorctl test accelerometer --interval=100 --batch_latency=1000\n");
111 _N(" sensorctl test accelerometer --i 100 --b 1000 --p 0\n");
112 _N(" sensorctl test accelerometer --i 100 --shuffle\n");
113 _N(" sensorctl test accelerometer --i 100 --verbose\n");
114 _N(" sensorctl test accelerometer --i 100 --output=results.log\n");
117 static void test_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data)
119 _N("%llu ", data->timestamp);
120 for (int i = 0; i < data->value_count; ++i)
121 _N(" %10f", data->values[i]);
125 TESTCASE(manual_test, sensor)
132 if (sensor_adapter::get_count(stype) > 1) {
133 _N("There are more than 2 sensors. please enter the index : ");
137 sensor_info info(stype, index, interval, latency, powersave, test_cb, NULL);
139 ret = sensor_adapter::start(info, handle);
142 ret = sensor_adapter::get_data(handle, stype, data);
147 ret = sensor_adapter::stop(info, handle);
153 REGISTER_TESTER(TEST_MANUAL, tester_manual);