sensorctl: seperate auto test and manual test
[platform/core/system/sensord.git] / src / sensorctl / tester.h
1 /*
2  * sensorctl
3  *
4  * Copyright (c) 2016 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 #pragma once /* __TESTER_H__ */
21
22 #include <sensor_internal.h>
23 #include <string>
24 #include <vector>
25
26 #include "sensor_manager.h"
27
28 #define TESTER_ARGC 3 /* e.g. {sensorctl, test, accelerometer} */
29
30 #define REGISTER_TESTER(name, tester_type) \
31 static tester_type tester(name);
32
33 class tester {
34 public:
35         tester(const char *name);
36         virtual ~tester() {}
37
38         virtual bool setup(sensor_type_t type, int argc, char *argv[]) { return true; }
39         virtual bool teardown(void) { return true; }
40         virtual bool run(int argc, char *argv[]) = 0;
41
42         const std::string& name() const { return m_name; }
43
44 private:
45         std::string m_name;
46 };
47
48 class tester_manager : public sensor_manager {
49 public:
50         static void register_tester(tester *test);
51
52         tester_manager();
53         virtual ~tester_manager();
54
55         bool run(int argc, char *argv[]);
56         void stop(void);
57
58 private:
59         static std::vector<tester *> testers;
60
61         tester *get_tester(const char *type);
62         void usage(void);
63 };