sensorctl test
[platform/core/system/sensord.git] / src / sensorctl / tester_manager.cpp
1 /*
2  * sensorctl
3  *
4  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19
20 #include <stdio.h>
21 #include <string.h>
22 #include <sensor_internal.h>
23 #include <sensorctl_log.h>
24 #include "tester.h"
25 #include "tester_manager.h"
26 #include "tester_sensor.h"
27
28 #define NAME_MAX_TEST 32
29 #define ARGC_BASE 3 /* e.g. {sensorctl, test, accelerometer} */
30
31 bool tester_manager::process(int argc, char *argv[])
32 {
33         int option_count;
34         char *options[8];
35         sensor_type_t type;
36         int i;
37
38         if (argc == 2) {
39                 usage();
40                 return false;
41         }
42
43         /* 1. get sensor type */
44         type = get_sensor_type(argv[2]);
45         if (type == UNKNOWN_SENSOR) {
46                 _E("ERROR : failed to process injector\n");
47                 return false;
48         }
49
50         /* 2. set up injector */
51         tester_interface *tester = new tester_sensor();
52         tester->init();
53
54         /* 3. test sensor with options */
55         option_count = argc - ARGC_BASE;
56         for (i = 0; i < option_count; ++i) {
57                 options[i] = new char[NAME_MAX_TEST];
58                 strcpy(options[i], argv[ARGC_BASE+i]);
59         }
60
61         tester->test(type, option_count, options);
62
63         return true;
64 }
65
66 void tester_manager::usage(void)
67 {
68         PRINT("usage: sensorctl test <sensor_type> [interval] [event_count] [test_count]\n\n");
69
70         usage_sensors();
71
72         PRINT("interval_ms:\n");
73         PRINT("  interval. default value is 100ms.\n");
74         PRINT("event count(n):\n");
75         PRINT("  test sensor until it gets n event. default is 999999(infinitly).\n");
76         PRINT("test count(n):\n");
77         PRINT("  test sensor in n times repetitively, default is 1.\n\n");
78 }
79