From c5aaf8cbb2b6bbbac2420636f41cba98d8ccc336 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 4 Aug 2017 00:37:13 +0900 Subject: [PATCH 01/16] sensord: ternimate sensord instantly when signal is received Change-Id: I1993404cf85cf92427ccaf69a28dbe88a461134d Signed-off-by: kibak.yoon --- src/server/server.cpp | 2 +- src/shared/event_loop.cpp | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/server/server.cpp b/src/server/server.cpp index 237f658..a411340 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -96,8 +96,8 @@ bool server::init(void) void server::deinit(void) { - m_manager->deinit(); m_server->close(); + m_manager->deinit(); delete m_server; m_server = NULL; diff --git a/src/shared/event_loop.cpp b/src/shared/event_loop.cpp index 1b569a1..c3a698b 100644 --- a/src/shared/event_loop.cpp +++ b/src/shared/event_loop.cpp @@ -238,12 +238,7 @@ void event_loop::stop(void) { ret_if(!is_running() || m_terminating.load()); - uint64_t term = 1; - ssize_t size; - m_terminating.store(true); - size = write(m_term_fd, &term, sizeof(uint64_t)); - - retm_if(size != sizeof(ssize_t), "Failed to write[%d]", m_term_fd); + terminate(); } void event_loop::terminate(void) -- 2.7.4 From b0d9ce9e1eabd744274000bdd2934a2d4f5fb04c Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 4 Aug 2017 00:38:29 +0900 Subject: [PATCH 02/16] sensord: fix bug with incorrect bit operation Change-Id: I29c35c9b923d572fbe0b39aa7fe5913386f77bb2 Signed-off-by: kibak.yoon --- src/shared/event_loop.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/event_loop.cpp b/src/shared/event_loop.cpp index c3a698b..4f9e7ed 100644 --- a/src/shared/event_loop.cpp +++ b/src/shared/event_loop.cpp @@ -43,7 +43,7 @@ static gboolean g_io_handler(GIOChannel *ch, GIOCondition condition, gpointer da cond = (unsigned int)condition; if (cond & (G_IO_HUP)) - cond &= ~(G_IO_IN & G_IO_OUT); + cond &= ~(G_IO_IN | G_IO_OUT); handler_info *info = (handler_info *)data; id = info->id; -- 2.7.4 From 59055558123e4d54d1407c48fa11a80575121092 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 4 Aug 2017 10:34:49 +0900 Subject: [PATCH 03/16] sensord: add null check after malloc Change-Id: I6f01e8f46be1e08999bc0f35871fc675ba7ebeb8 Signed-off-by: kibak.yoon --- src/sensor/pedometer/pedometer_sensor.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sensor/pedometer/pedometer_sensor.cpp b/src/sensor/pedometer/pedometer_sensor.cpp index bbd9b67..d16bdcc 100644 --- a/src/sensor/pedometer/pedometer_sensor.cpp +++ b/src/sensor/pedometer/pedometer_sensor.cpp @@ -103,6 +103,7 @@ int pedometer_sensor::get_data(sensor_data_t **data, int *len) { sensor_data_t *sensor_data; sensor_data = (sensor_data_t *)malloc(sizeof(sensor_data_t)); + retvm_if(!sensor_data, -ENOMEM, "Failed to allocate memory"); sensor_data->accuracy = SENSOR_ACCURACY_GOOD; sensor_data->timestamp = m_time; -- 2.7.4 From 27411362d91803c8c0ab6e8d3688592b141e8037 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Fri, 4 Aug 2017 10:09:34 +0900 Subject: [PATCH 04/16] sensord: version 4.0.2 Change-Id: Id1c588dda1ae5d446f158afeea96b7d94bfff82e Signed-off-by: kibak.yoon --- packaging/sensord.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/sensord.spec b/packaging/sensord.spec index d081956..b96b6fe 100644 --- a/packaging/sensord.spec +++ b/packaging/sensord.spec @@ -1,6 +1,6 @@ Name: sensord Summary: Sensor daemon -Version: 4.0.1 +Version: 4.0.2 Release: 1 Group: System/Sensor Framework License: Apache-2.0 -- 2.7.4 From 7c9813c0be7c00cf1feaf1718f01ecfde399892a Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 9 Aug 2017 19:39:52 +0900 Subject: [PATCH 05/16] sensord: fix double-free issue - If the server is terminated unexpectedly, sensor library releases the memory of channel automatically. At that time, if client calls disconnect(), double-free problem is invoked. - Because it is right situation to call disconnect() explicitly, the auto-release code should be removed. Change-Id: I31894354eb2d11549dbe0382ce865de6beea89d4 Signed-off-by: kibak.yoon --- src/shared/channel_event_handler.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/shared/channel_event_handler.cpp b/src/shared/channel_event_handler.cpp index 6ca1e25..cc8a2bb 100644 --- a/src/shared/channel_event_handler.cpp +++ b/src/shared/channel_event_handler.cpp @@ -46,14 +46,12 @@ bool channel_event_handler::handle(int fd, event_condition condition) if (condition & (EVENT_HUP)) { m_ch->disconnect(); - delete m_ch; m_ch = NULL; return false; } if (!m_ch->read_sync(msg, false)) { m_ch->disconnect(); - delete m_ch; m_ch = NULL; return false; } -- 2.7.4 From ff891178a7a8147538ff5de57fb2987555440689 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 10 Aug 2017 19:23:25 +0900 Subject: [PATCH 06/16] sensorctl: clean up log macros of sensorctl Change-Id: I7aff53066afae3659700f37ac32a536d39c53c62 Signed-off-by: kibak.yoon --- src/sensorctl/log.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/sensorctl/log.h b/src/sensorctl/log.h index 00cefbd..6bb1130 100644 --- a/src/sensorctl/log.h +++ b/src/sensorctl/log.h @@ -39,12 +39,17 @@ do { \ #define _E(fmt, args...) \ do { \ - g_print("\x1B[31m" fmt "\033[0m", ##args); \ + g_print(_RED fmt _RST, ##args); \ } while (0) #define _I(fmt, args...) \ do { \ - g_print("\x1B[32m" fmt "\033[0m", ##args); \ + g_print(_GRN fmt _RST, ##args); \ +} while (0) + +#define _W(fmt, args...) \ +do { \ + g_print(_YEL fmt _RST, ##args); \ } while (0) #define WARN_IF(expr, fmt, arg...) \ -- 2.7.4 From d42f20dc2e7180d49944d2dd4a894e7e35828881 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 10 Aug 2017 19:26:11 +0900 Subject: [PATCH 07/16] sensorctl: remove unnecessary keyword/macro * change parameter name Change-Id: Iee63054bcf0b752fa0acf29ad087d210056ed606 Signed-off-by: kibak.yoon --- src/sensorctl/injector.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/sensorctl/injector.h b/src/sensorctl/injector.h index ca942fc..b487c91 100644 --- a/src/sensorctl/injector.h +++ b/src/sensorctl/injector.h @@ -25,7 +25,6 @@ #include "sensor_manager.h" -#define NAME_MAX_TEST 32 #define INJECTOR_ARGC 4 /* e.g. {sensorctl, inject, wristup, conf} */ #define REGISTER_INJECTOR(sensor_type, event_name, injector_type) \ @@ -51,9 +50,8 @@ private: class injector_manager : public sensor_manager { public: - static void register_injector(injector *injector); + static void register_injector(injector *inject); -public: injector_manager(); virtual ~injector_manager(); -- 2.7.4 From 669c659b33ab8f417abdde207c1864d481c62d4a Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 10 Aug 2017 19:33:32 +0900 Subject: [PATCH 08/16] sensorctl: remove assert macro - [TODO] replace "adapter" with "adaptor" Change-Id: I0f86d2de013616c598b296b014e7331254e6d5ec Signed-off-by: kibak.yoon --- src/sensorctl/sensor_adapter.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sensorctl/sensor_adapter.cpp b/src/sensorctl/sensor_adapter.cpp index 82a54a2..13bc4e5 100644 --- a/src/sensorctl/sensor_adapter.cpp +++ b/src/sensorctl/sensor_adapter.cpp @@ -30,12 +30,12 @@ bool sensor_adapter::is_supported(sensor_type_t type) { sensor_t sensor; - int ret; - ret = sensord_get_default_sensor(type, &sensor); - ASSERT_TRUE(ret); + int ret = sensord_get_default_sensor(type, &sensor); + if (ret == 0) + return true; - return true; + return false; } int sensor_adapter::get_count(sensor_type_t type) -- 2.7.4 From e3eeb813d01784a008761e130cb82b400c99fbf0 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 10 Aug 2017 19:44:11 +0900 Subject: [PATCH 09/16] sensorctl: add options/features for usability This patch supports the below options and features. [SYNOPSIS] - sensorctl test auto [--help] [--list] [--filter=] [--verbose] [--shuffle] [--repeat] [--output] - sensorctl test [--interval=NUMBER] [--batch_latency=NUMBER] [--powersave=TYPE] [--repeat=NUMBER] [--output=FILE_PATH] [--help] [--verbose] [Options] -f PATTERN, --filter= Run a subset of the tests for debugging or quickly verifying a change. Sensorctl will only run the tests whose full names match the filter. This can be used to specify multiple search patterns. -l, --list Prints the testcase list by following command. -h, --help Prints the synopsis and a list of the most commonly used commands. -v, --verbose Prints the log message fully while testcases are running. -s, --shuffle Run the testcase randomly. -r NUMBER, --repeat=NUMBER Run the testcase a given number of times. Change-Id: I30dec0ef2896e12c956be294c2677cb785335ec0 Signed-off-by: kibak.yoon --- src/sensorctl/test_bench.cpp | 232 +++++++++++++++++++++++++++++++------------ src/sensorctl/test_bench.h | 49 +++++---- 2 files changed, 200 insertions(+), 81 deletions(-) diff --git a/src/sensorctl/test_bench.cpp b/src/sensorctl/test_bench.cpp index 3b9cd51..db0b974 100644 --- a/src/sensorctl/test_bench.cpp +++ b/src/sensorctl/test_bench.cpp @@ -17,32 +17,108 @@ * */ -#include "log.h" #include "test_bench.h" +#include +#include + +#include "log.h" + /* * Implementation of test_option */ -bool test_option::full_log = false; -std::string test_option::group = ""; - -void test_option::show_full_log(bool show) +bool test_option::verbose = false; +bool test_option::shuffle = false; +bool test_option::show_list = false; +int test_option::repeat = 1; +std::string test_option::filter = ""; +std::string test_option::output = ""; +int test_option::interval = -1; +int test_option::latency = -1; +int test_option::powersave = -1; + +bool test_option::set_options(int argc, char *argv[]) { - full_log = show; -} - -void test_option::set_group(const char *gname) -{ - group = gname; -} + int c; + + while (1) { + static struct option options[] = { + {"list", no_argument, 0, 'l'}, + {"filter", required_argument, 0, 'f'}, + {"verbose", no_argument, 0, 'v'}, + {"shuffle", no_argument, 0, 's'}, + {"repeat", required_argument, 0, 'r'}, + {"output", required_argument, 0, 'o'}, + + /* For manual test*/ + {"interval", required_argument, 0, 'i'}, + {"batch_latency", required_argument, 0, 'b'}, + {"powersave", required_argument, 0, 'p'}, + + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0} + }; + + int option_index = 0; + c = getopt_long(argc, argv, "lfvsroibph:", options, &option_index); + if (c == -1) + return true; + + switch (c) { + case 0: + break; + case 'l': + _I("== Testcase List ==\n"); + test_bench::show_testcases(); + test_option::show_list = true; + break; + case 'f': + _I("Filter : %s\n", optarg); + if (!optarg) break; + test_option::filter = optarg; + break; + case 'v': + _I("Verbose is on\n"); + test_option::verbose = true; + break; + case 's': + _I("Shuffle is on(Default seed)\n"); + test_option::shuffle = true; + break; + case 'r': + _I("Repeat : %s\n", optarg); + if (!optarg) break; + test_option::repeat = atoi(optarg); + break; + case 'o': + /* [TODO] */ + _W("File output is not supported yet, use $sensorctl > out : %s\n", optarg); + if (!optarg) break; + test_option::output = optarg; + break; + case 'i': + _I("Interval : %s\n", optarg); + if (!optarg) break; + test_option::interval = atoi(optarg); + break; + case 'b': + _I("Batch latency : %s\n", optarg); + if (!optarg) break; + test_option::latency = atoi(optarg); + break; + case 'p': + _I("Power save : %s\n", optarg); + if (!optarg) break; + test_option::powersave = atoi(optarg); + break; + case 'h': + case '?': + default: + return false; + } + } -void test_option::set_options(int argc, char *argv[]) -{ - /* TODO: use getopt() */ - if (argc > 3) - set_group(argv[3]); - if (argc > 4) - show_full_log(atoi(argv[4])); + return true; } /* @@ -51,6 +127,7 @@ void test_option::set_options(int argc, char *argv[]) test_case::test_case(const std::string &group, const std::string &name) : m_group(group) , m_name(name) +, m_fullname(group + "." + m_name) , m_func(NULL) { test_bench::register_testcase(group, this); @@ -58,25 +135,17 @@ test_case::test_case(const std::string &group, const std::string &name) void test_case::started(void) { - _I("[----------]\n"); _I("[ RUN ] "); - _N("%s.%s\n", m_group.c_str(), m_name.c_str()); -} - -void test_case::stopped(void) -{ - _I("[ OK ] "); - _N("%s.%s\n", m_group.c_str(), m_name.c_str()); - _I("[----------]\n"); + _N("%s\n", m_fullname.c_str()); } -void test_case::show(bool result) +void test_case::stopped(bool result) { if (result) - _I("[ PASSED ] "); + _I("[ OK ] "); else _E("[ FAILED ] "); - _N("%s.%s\n", m_group.c_str(), m_name.c_str()); + _N("%s\n", m_fullname.c_str()); } void test_case::run_testcase(void) @@ -85,8 +154,7 @@ void test_case::run_testcase(void) started(); result = (this->*m_func)(); - stopped(); - show(result); + stopped(result); } void test_case::register_func(test_func func) @@ -103,6 +171,11 @@ test_bench& test_bench::instance() return bench; } +void test_bench::show_testcases(void) +{ + instance().show(); +} + void test_bench::register_testcase(const std::string &group, test_case *testcase) { instance().add_testcase(group, testcase); @@ -113,12 +186,15 @@ void test_bench::push_failure(const std::string &function, long line, const std: instance().add_failure(function, line, msg); } -void test_bench::run_all_testcase(void) +void test_bench::run_all_testcases(void) { + if (test_option::show_list) + return; + instance().run(); } -void test_bench::stop_all_testcase(void) +void test_bench::stop_all_testcases(void) { instance().stop(); } @@ -140,13 +216,36 @@ void test_bench::add_failure(const std::string &function, long line, const std:: void test_bench::started(void) { _I("[==========] "); - _N("Running %d testcases\n", count(test_option::group)); + _N("Running %d testcases\n", count()); } void test_bench::stopped(void) { _I("[==========] "); - _N("%d testcases ran\n", count(test_option::group)); + _N("%d testcases ran\n", count()); +} + +void test_bench::show(void) +{ + /* + * [group1] + * [tc name1] + * [tc name2] + * [group2] + * [tc name1] + */ + + for (auto it = testcases.begin(); it != testcases.end(); + it = testcases.upper_bound(it->first)) { + + auto range = testcases.equal_range(it->first); + _I("[%s]\n", it->first.c_str()); + + for (auto testcase = range.first; testcase != range.second; ++testcase) + _N(" * %s\n", testcase->second->name().c_str()); + } + + _I("Testcase Count : %u\n", count()); } void test_bench::show_failures(void) @@ -154,7 +253,8 @@ void test_bench::show_failures(void) _N("================================\n"); if (m_failure_count == 0) { - _N("there was no fail case\n"); + _I("[ PASSED ] "); + _N("%d tests\n", count() - m_failure_count); return; } @@ -166,28 +266,44 @@ void test_bench::show_failures(void) } } +bool test_bench::filter(const std::string &name) +{ + static std::regex filter(test_option::filter.c_str(), std::regex::optimize); + if (!std::regex_match(name, filter)) { + //_W("Not Matched : %s(%s)\n", name.c_str(), test_option::filter.c_str()); + return false; + } + + //_I("Matched : %s(%s)\n", name.c_str(), test_option::filter.c_str()); + return true; +} + void test_bench::run(void) { - std::size_t found; m_failure_count = 0; started(); - for (auto it = testcases.begin(); it != testcases.end(); ++it) { - if (m_stop) - break; + /* For group */ + for (auto it = testcases.begin(); it != testcases.end(); + it = testcases.upper_bound(it->first)) { + if (m_stop) break; + if (!filter(it->second->fullname())) continue; - found = it->first.find("skip"); + auto range = testcases.equal_range(it->first); - if (test_option::group.empty() && found != std::string::npos) - continue; + /* Time measurement for test group */ + clock_t start = clock(); - found = it->first.find(test_option::group); + _I("[----------] %d tests from %s\n", testcases.count(it->first), it->first.c_str()); + for (auto testcase = range.first; testcase != range.second; ++testcase) { + if (m_stop) break; + testcase->second->run_testcase(); + } - if (!test_option::group.empty() && found == std::string::npos) - continue; - - it->second->run_testcase(); + _I("[----------] %d tests from %s (%.4f sec)\n", + testcases.count(it->first), it->first.c_str(), + (double)(clock() - start)/ CLOCKS_PER_SEC); } stopped(); @@ -199,23 +315,15 @@ void test_bench::stop(void) m_stop = true; } -unsigned int test_bench::count(std::string &group) -{ - if (group.empty()) - return testcases.size() - count_by_key("skip"); - - return count_by_key(group.c_str()); -} - -unsigned int test_bench::count_by_key(const char *key) +unsigned int test_bench::count(void) { int count = 0; for (auto it = testcases.begin(); it != testcases.end(); ++it) { - std::size_t found = it->first.find(key); + if (!filter(it->second->fullname())) + continue; - if (found != std::string::npos) - count++; + count++; } return count; diff --git a/src/sensorctl/test_bench.h b/src/sensorctl/test_bench.h index 8525e39..f70fdeb 100644 --- a/src/sensorctl/test_bench.h +++ b/src/sensorctl/test_bench.h @@ -38,7 +38,7 @@ do { \ #define PASS(left, comp, right) \ do { \ - if (test_option::full_log) { \ + if (test_option::verbose) { \ _I("[ PASS ] "); \ std::ostringstream os; \ os << __FUNCTION__ << "(" << __LINE__ << ") : " \ @@ -96,32 +96,37 @@ do { \ } while (0) #define TESTCASE(group, name) \ -class test_case_##group_##name : public test_case { \ +class test_case_##group##_##name : public test_case { \ public: \ - test_case_##group_##name() \ + test_case_##group##_##name() \ : test_case(#group, #name) \ { \ - register_func(static_cast(&test_case_##group_##name::test)); \ + register_func(static_cast(&test_case_##group##_##name::test)); \ } \ bool test(void); \ -} test_case_##group_##name##_instance; \ -bool test_case_##group_##name::test(void) +} test_case_##group##_##name##_instance; \ +bool test_case_##group##_##name::test(void) /* * Declaration of test_option */ class test_option { public: - static bool full_log; - static std::string group; - - static void show_full_log(bool show); - static void set_group(const char *gname); - static void set_options(int argc, char *argv[]); + static bool verbose; + static bool shuffle; /* TODO */ + static bool show_list; + static int repeat; /* TODO */ + static std::string filter; + static std::string output; /* TODO */ + static int interval; + static int latency; + static int powersave; + + static bool set_options(int argc, char *argv[]); }; /* - * Decloaration of test_result + * Declaration of test_result */ class test_result { public: @@ -146,18 +151,19 @@ public: const std::string& group() const { return m_group; } const std::string& name() const { return m_name; } + const std::string& fullname() const { return m_fullname; } protected: typedef bool (test_case::*test_func)(); void started(void); - void stopped(void); - void show(bool result); + void stopped(bool result); void register_func(test_func func); private: const std::string m_group; const std::string m_name; + const std::string m_fullname; test_func m_func; }; @@ -171,10 +177,12 @@ public: , m_stop(false) {} + static void show_testcases(void); + static void register_testcase(const std::string &group, test_case *testcase); - static void run_all_testcase(void); - static void stop_all_testcase(void); + static void run_all_testcases(void); + static void stop_all_testcases(void); static void push_failure(const std::string &function, long line, const std::string &msg); @@ -188,11 +196,14 @@ private: void show_failures(void); void add_testcase(const std::string &group, test_case *testcase); + + bool filter(const std::string &name); void run(void); void stop(void); - unsigned int count(std::string &group); - unsigned int count_by_key(const char *key); + void show(void); + + unsigned int count(void); std::multimap testcases; std::vector results; -- 2.7.4 From 122cf1cbb2140acd69e25e9f8228112a1f87832d Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 10 Aug 2017 20:18:08 +0900 Subject: [PATCH 10/16] sensorctl: seperate auto test and manual test - sensorctl test auto - sensorctl test Change-Id: Id30e09ff8380981699a9c7651af675fd7a370da5 Signed-off-by: kibak.yoon --- src/sensorctl/tester.cpp | 161 +++++++++++----------------------------- src/sensorctl/tester.h | 28 ++++++- src/sensorctl/tester_auto.cpp | 87 ++++++++++++++++++++++ src/sensorctl/tester_manual.cpp | 152 +++++++++++++++++++++++++++++++++++++ 4 files changed, 307 insertions(+), 121 deletions(-) create mode 100644 src/sensorctl/tester_auto.cpp create mode 100644 src/sensorctl/tester_manual.cpp diff --git a/src/sensorctl/tester.cpp b/src/sensorctl/tester.cpp index 4ac906f..e756337 100644 --- a/src/sensorctl/tester.cpp +++ b/src/sensorctl/tester.cpp @@ -27,23 +27,14 @@ #include "log.h" #include "macro.h" #include "mainloop.h" -#include "test_bench.h" -#include "sensor_adapter.h" -#define TESTER_ARGC 3 /* e.g. {sensorctl, test, accelerometer} */ +std::vector tester_manager::testers; -#define MAX_COUNT 999999 -#define TEST_DEFAULT_INTERVAL 100 -#define TEST_DEFAULT_LATENCY 0 -#define TEST_DEFAULT_POWERSAVE_OPTION SENSOR_OPTION_ALWAYS_ON - -static sensor_type_t type; -static int interval; -static int latency; -static int powersave; -static int repeat; - -static int event_count = 0; +tester::tester(const char *name) +: m_name(name) +{ + tester_manager::register_tester(this); +} tester_manager::tester_manager() { @@ -53,64 +44,53 @@ tester_manager::~tester_manager() { } +void tester_manager::register_tester(tester *test) +{ + testers.push_back(test); +} + bool tester_manager::run(int argc, char *argv[]) { - if (argc < TESTER_ARGC) { - usage(); - return false; - } + bool ret; + sensor_type_t type = ACCELEROMETER_SENSOR; - if (!setup(argc, argv)) { + if (argc < TESTER_ARGC) { usage(); return false; } - test_bench::run_all_testcase(); + if (strncmp(argv[2], "auto", 4) != 0) + type = get_sensor_type(argv[2]); - return true; -} + tester *_tester = get_tester(argv[2]); + RETVM_IF(!_tester, false, "Cannot find matched tester\n"); -bool tester_manager::setup(int argc, char *argv[]) -{ - if (strncmp(argv[2], "auto", 4) == 0) - return setup_auto(argc, argv); + ret = _tester->setup(type, argc, argv); + RETVM_IF(!ret, false, "Failed to setup injector\n"); - return setup_manual(argc, argv); -} + ret = _tester->run(argc, argv); + RETVM_IF(!ret, false, "Failed to run tester\n"); -bool tester_manager::setup_auto(int argc, char *argv[]) -{ - if (argc > 5) - repeat = atoi(argv[5]); - - test_option::show_full_log(true); - test_option::set_options(argc, argv); + ret = _tester->teardown(); + RETVM_IF(!ret, false, "Failed to tear down tester\n"); return true; } -bool tester_manager::setup_manual(int argc, char *argv[]) +tester *tester_manager::get_tester(const char *name) { - type = get_sensor_type(argv[2]); - RETVM_IF(type == UNKNOWN_SENSOR, false, "Invalid argument\n"); - - interval = TEST_DEFAULT_INTERVAL; - latency = TEST_DEFAULT_LATENCY; - powersave = TEST_DEFAULT_POWERSAVE_OPTION; - event_count = 0; - - if (argc >= TESTER_ARGC + 1) - interval = atoi(argv[TESTER_ARGC]); - if (argc >= TESTER_ARGC + 2) - latency = atoi(argv[TESTER_ARGC + 1]); - if (argc >= TESTER_ARGC + 3) - powersave = atoi(argv[TESTER_ARGC + 2]); - - test_option::show_full_log(true); - test_option::set_group("skip_manual"); - /* test_option::set_options(argc, argv); */ - - return true; + int count = testers.size(); + + for (int i = 0; i < count; ++i) { + if (strncmp(name, "auto", 4) == 0) { + if (testers[i]->name() == "auto") + return testers[i]; + } else { + if (testers[i]->name() == "manual") + return testers[i]; + } + } + return NULL; } void tester_manager::stop(void) @@ -121,69 +101,16 @@ void tester_manager::stop(void) void tester_manager::usage(void) { - _N("usage: sensorctl test auto [group] [log]\n"); - _N("usage: sensorctl test [interval] [batch_latency] [event_count] [test_count]\n"); + _N("usage: sensorctl test auto [options] [--help]\n"); + _N("usage: sensorctl test [--help]\n"); usage_sensors(); _N("auto:\n"); - _N(" test sensors automatically.\n"); - _N("group:\n"); - _N(" a group name(or a specific word contained in the group name).\n"); - _N("log:\n"); - _N(" enable(1) or disable(0). default value is 1.\n"); - _N("sensor_type: specific sensor\n"); - _N(" test specific sensor manually.\n"); - _N("interval_ms:\n"); - _N(" interval. default value is 100ms.\n"); - _N("batch_latency_ms:\n"); - _N(" batch_latency. default value is 1000ms.\n"); - _N("event count(n):\n"); - _N(" test sensor until it gets n event. default is 999999(infinitly).\n"); - _N("test count(n):\n"); - _N(" test sensor in n times repetitively, default is 1.\n\n"); -} - -/* manual test case */ -static void test_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) -{ - if (event_count >= MAX_COUNT) { - mainloop::stop(); - return; - } - - _N("%llu ", data->timestamp); - for (int i = 0; i < data->value_count; ++i) - _N(" %10f", data->values[i]); - _N("\n"); -} - -TESTCASE(skip_manual, sensor_test) -{ - int handle; - bool ret; - int index = 0; - sensor_data_t data; - - if (sensor_adapter::get_count(type) > 1) { - _N("There are more than 2 sensors. please enter the index : "); - if (scanf("%d", &index) != 1) - return false; - } - - sensor_info info(type, index, interval, latency, powersave, test_cb, NULL); - - ret = sensor_adapter::start(info, handle); - ASSERT_TRUE(ret); - - ret = sensor_adapter::get_data(handle, type, data); - EXPECT_TRUE(ret); - - mainloop::run(); - - ret = sensor_adapter::stop(info, handle); - ASSERT_TRUE(ret); - - return true; + _N(" Run all testcases automatically.\n"); + _N("sensor_type:\n"); + _N(" Run the specific sensor manually.\n"); + _N("help: \n"); + _N(" Prints the synopsis and a list of options.\n"); } diff --git a/src/sensorctl/tester.h b/src/sensorctl/tester.h index 148a402..b22b8ae 100644 --- a/src/sensorctl/tester.h +++ b/src/sensorctl/tester.h @@ -25,8 +25,30 @@ #include "sensor_manager.h" +#define TESTER_ARGC 3 /* e.g. {sensorctl, test, accelerometer} */ + +#define REGISTER_TESTER(name, tester_type) \ +static tester_type tester(name); + +class tester { +public: + tester(const char *name); + virtual ~tester() {} + + virtual bool setup(sensor_type_t type, int argc, char *argv[]) { return true; } + virtual bool teardown(void) { return true; } + virtual bool run(int argc, char *argv[]) = 0; + + const std::string& name() const { return m_name; } + +private: + std::string m_name; +}; + class tester_manager : public sensor_manager { public: + static void register_tester(tester *test); + tester_manager(); virtual ~tester_manager(); @@ -34,10 +56,8 @@ public: void stop(void); private: - bool setup(int argc, char *argv[]); - bool setup_auto(int argc, char *argv[]); - bool setup_manual(int argc, char *argv[]); + static std::vector testers; + tester *get_tester(const char *type); void usage(void); }; - diff --git a/src/sensorctl/tester_auto.cpp b/src/sensorctl/tester_auto.cpp new file mode 100644 index 0000000..2d4b534 --- /dev/null +++ b/src/sensorctl/tester_auto.cpp @@ -0,0 +1,87 @@ +/* + * sensorctl + * + * Copyright (c) 2017 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 "log.h" +#include "tester.h" +#include "test_bench.h" + +#define TEST_AUTO "auto" + +class tester_auto : public tester { +public: + tester_auto(const char *name); + virtual ~tester_auto(); + + bool setup(sensor_type_t type, int argc, char *argv[]); + bool teardown(void); + + bool run(int argc, char *argv[]); + void usage(void); +}; + +tester_auto::tester_auto(const char *name) +: tester(name) +{ +} + +tester_auto::~tester_auto() +{ +} + +bool tester_auto::setup(sensor_type_t type, int argc, char *argv[]) +{ + test_option::filter = "(?!manual|skip)[\\w\\.]+"; + + if (!test_option::set_options(argc, argv)) { + usage(); + return false; + } + + return true; +} + +bool tester_auto::teardown(void) +{ + return true; +} + +bool tester_auto::run(int argc, char *argv[]) +{ + test_bench::run_all_testcases(); + return true; +} + +void tester_auto::usage(void) +{ + _N("Usage : sensorctl test auto [--help] [--list] [--filter=]\n"); + _N(" [--verbose] [--shuffle] [--repeat]\n"); + _N(" [--output]\n"); + + _N("Examples:\n"); + _N(" sensorctl test auto --list\n"); + _N(" sensorctl test auto --filter=accelerometer.interval*\n"); + _N(" sensorctl test auto --filter=accelerometer.start\n"); + _N(" sensorctl test auto --filter=accelerometer.verify\n"); + _N(" sensorctl test auto --filter=ipc.socket*\n"); + _N(" sensorctl test auto --shuffle\n"); + _N(" sensorctl test auto --verbose\n"); + _N(" sensorctl test auto --output=results.log\n"); +} + +REGISTER_TESTER(TEST_AUTO, tester_auto); diff --git a/src/sensorctl/tester_manual.cpp b/src/sensorctl/tester_manual.cpp new file mode 100644 index 0000000..f2270eb --- /dev/null +++ b/src/sensorctl/tester_manual.cpp @@ -0,0 +1,152 @@ +/* + * sensorctl + * + * Copyright (c) 2017 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 "tester.h" +#include "mainloop.h" +#include "log.h" +#include "test_bench.h" +#include "sensor_adapter.h" + +#define MAX_COUNT 999999 +#define TEST_DEFAULT_INTERVAL 100 +#define TEST_DEFAULT_LATENCY 0 +#define TEST_DEFAULT_POWERSAVE_OPTION SENSOR_OPTION_ALWAYS_ON + +#define TEST_MANUAL "manual" + +static sensor_type_t type; +static int interval; +static int latency; +static int powersave; +//static int repeat; + +class tester_manual : public tester { +public: + tester_manual(const char *name); + virtual ~tester_manual(); + + bool setup(sensor_type_t type, int argc, char *argv[]); + bool teardown(void); + + bool run(int argc, char *argv[]); + void usage(void); +}; + +tester_manual::tester_manual(const char *name) +: tester(name) +{ +} + +tester_manual::~tester_manual() +{ +} + +bool tester_manual::setup(sensor_type_t type, int argc, char *argv[]) +{ + interval = TEST_DEFAULT_INTERVAL; + latency = TEST_DEFAULT_LATENCY; + powersave = TEST_DEFAULT_POWERSAVE_OPTION; + + if (!test_option::set_options(argc, argv)) { + usage(); + return false; + } + + interval = test_option::interval; + latency = test_option::latency; + powersave = test_option::powersave; + + if (interval == -1) + interval = TEST_DEFAULT_INTERVAL; + if (latency == -1) + latency = TEST_DEFAULT_LATENCY; + if (powersave == -1) + powersave = TEST_DEFAULT_POWERSAVE_OPTION; + + return true; +} + +bool tester_manual::teardown(void) +{ + return true; +} + +bool tester_manual::run(int argc, char *argv[]) +{ + test_option::filter = "^manual[\\w\\.]+"; + test_bench::run_all_testcases(); + + return true; +} + +void tester_manual::usage(void) +{ + _N("Usage : sensorctl test \n"); + _N(" [--interval=NUMBER] [--batch_latency=NUMBER] [--powersave=TYPE]\n"); + _N(" [--repeat=NUMBER] [--output=FILE_PATH] [--help] [--verbose]\n"); + + _N("Examples:\n"); + _N(" sensorctl test accelerometer\n"); + _N(" sensorctl test accelerometer --interval=100 --batch_latency=1000\n"); + _N(" sensorctl test accelerometer --i 100 --b 1000 --p 0\n"); + _N(" sensorctl test accelerometer --i 100 --shuffle\n"); + _N(" sensorctl test accelerometer --i 100 --verbose\n"); + _N(" sensorctl test accelerometer --i 100 --output=results.log\n"); +} + +static void test_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) +{ + _N("%llu ", data->timestamp); + for (int i = 0; i < data->value_count; ++i) + _N(" %10f", data->values[i]); + _N("\n"); +} + +TESTCASE(manual_test, sensor) +{ + int handle; + bool ret; + int index = 0; + sensor_data_t data; + + if (sensor_adapter::get_count(type) > 1) { + _N("There are more than 2 sensors. please enter the index : "); + if (scanf("%d", &index) != 1) + return false; + } + + sensor_info info(type, index, interval, latency, powersave, test_cb, NULL); + + ret = sensor_adapter::start(info, handle); + ASSERT_TRUE(ret); + + ret = sensor_adapter::get_data(handle, type, data); + EXPECT_TRUE(ret); + + mainloop::run(); + + ret = sensor_adapter::stop(info, handle); + ASSERT_TRUE(ret); + + return true; +} + +REGISTER_TESTER(TEST_MANUAL, tester_manual); -- 2.7.4 From 096cf070533dd0de883b73df21a27ae82e7bbc7d Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 10 Aug 2017 20:21:03 +0900 Subject: [PATCH 11/16] sensorctl: clean up testcases Change-Id: I853f84296e788da1646483b3eb2197bd47e0229e Signed-off-by: kibak.yoon --- ...{accelerometer.cpp => sensor_accelerometer.cpp} | 86 +++++--------- src/sensorctl/testcase/sensor_basic.cpp | 128 ++++----------------- src/sensorctl/testcase/sensor_interval.cpp | 94 ++++++++++++++- .../{unit_client.cpp => sensor_listener.cpp} | 104 ++++++++++++++++- .../{unit_provider.cpp => sensor_provider.cpp} | 50 ++++---- src/sensorctl/testcase/unit_ipc.cpp | 24 ++-- src/sensorctl/testcase/unit_socket.cpp | 15 +-- 7 files changed, 284 insertions(+), 217 deletions(-) rename src/sensorctl/testcase/{accelerometer.cpp => sensor_accelerometer.cpp} (60%) rename src/sensorctl/testcase/{unit_client.cpp => sensor_listener.cpp} (54%) rename src/sensorctl/testcase/{unit_provider.cpp => sensor_provider.cpp} (94%) diff --git a/src/sensorctl/testcase/accelerometer.cpp b/src/sensorctl/testcase/sensor_accelerometer.cpp similarity index 60% rename from src/sensorctl/testcase/accelerometer.cpp rename to src/sensorctl/testcase/sensor_accelerometer.cpp index ed526c3..6f83619 100644 --- a/src/sensorctl/testcase/accelerometer.cpp +++ b/src/sensorctl/testcase/sensor_accelerometer.cpp @@ -24,7 +24,7 @@ #include "test_bench.h" #include "sensor_adapter.h" -static void basic_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) +static void test_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) { EXPECT_GT(data->timestamp, 0); EXPECT_NEAR(data->values[0], 0, 19.6); @@ -34,13 +34,16 @@ static void basic_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *da mainloop::stop(); } -TESTCASE(accelerometer_basic, start_stop_p) +TESTCASE(accelerometer_test, start_stop_p) { bool ret; int handle; + if (!sensor_adapter::is_supported(ACCELEROMETER_SENSOR)) + return true; /* Not Supported */ + sensor_info info(ACCELEROMETER_SENSOR, 0, - 100, 1000, SENSOR_OPTION_ALWAYS_ON, basic_cb, NULL); + 100, 1000, SENSOR_OPTION_ALWAYS_ON, test_cb, NULL); ret = sensor_adapter::start(info, handle); ASSERT_TRUE(ret); @@ -58,12 +61,15 @@ static void get_data_cb(sensor_t sensor, unsigned int event_type, sensor_data_t mainloop::stop(); } -TESTCASE(accelerometer_basic, get_data_p) +TESTCASE(accelerometer_test, get_data_p) { bool ret; int handle; sensor_data_t data; + if (!sensor_adapter::is_supported(ACCELEROMETER_SENSOR)) + return true; /* Not Supported */ + sensor_info info(ACCELEROMETER_SENSOR, 0, 100, 1000, SENSOR_OPTION_ALWAYS_ON, get_data_cb, NULL); @@ -81,80 +87,40 @@ TESTCASE(accelerometer_basic, get_data_p) return true; } -static unsigned long long prev_prev_ts; -static unsigned long long prev_ts; +static unsigned long long time_first; +static unsigned long long time_last; static int event_count; -static void accel_regular_interval_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) +static void accel_interval_100ms_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) { - int prev_gap; - int current_gap; - if (prev_prev_ts == 0) { - prev_prev_ts = data->timestamp; + if (event_count == 0) { + time_first = data->timestamp; + event_count++; return; } - if (prev_ts == 0) { - prev_ts = data->timestamp; - return; - } - - prev_gap = prev_ts - prev_prev_ts; - current_gap = data->timestamp - prev_ts; - - EXPECT_NEAR(current_gap, prev_gap, 10000); - prev_prev_ts = prev_ts; - prev_ts = data->timestamp; - - if (event_count++ > 3) + if (event_count == 10) { + /* 100ms + 20ms(error) */ + EXPECT_LE((data->timestamp - time_first) / 10, 120000); mainloop::stop(); -} - -TESTCASE(accelerometer_interval, regular_interval_p) -{ - bool ret; - int handle; - prev_prev_ts = 0; - prev_ts = 0; - event_count = 0; - - sensor_info info(ACCELEROMETER_SENSOR, 0, - 100, 1000, SENSOR_OPTION_ALWAYS_ON, accel_regular_interval_cb, NULL); - - ret = sensor_adapter::start(info, handle); - ASSERT_TRUE(ret); - - mainloop::run(); - - ret = sensor_adapter::stop(info, handle); - ASSERT_TRUE(ret); - - return true; -} - -static void accel_interval_100ms_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) -{ - if (prev_ts == 0) { - prev_ts = data->timestamp; return; } - /* 100ms + 20ms(error) */ - EXPECT_LE(data->timestamp - prev_ts, 120000); - prev_ts = data->timestamp; - - if (event_count++ > 3) - mainloop::stop(); + event_count++; } -TESTCASE(accelerometer_interval, 100ms_interval_p) +TESTCASE(accelscope_test, 100ms_interval_p) { bool ret; int handle; - prev_ts = 0; + time_first = 0; + time_last = 0; event_count = 0; + if (!sensor_adapter::is_supported(ACCELEROMETER_SENSOR)) + return true; /* Not Supported */ + sensor_info info(ACCELEROMETER_SENSOR, 0, 100, 1000, SENSOR_OPTION_ALWAYS_ON, accel_interval_100ms_cb, NULL); diff --git a/src/sensorctl/testcase/sensor_basic.cpp b/src/sensorctl/testcase/sensor_basic.cpp index cc56dec..ef6b139 100644 --- a/src/sensorctl/testcase/sensor_basic.cpp +++ b/src/sensorctl/testcase/sensor_basic.cpp @@ -18,6 +18,7 @@ */ #include +#include #include #include "log.h" @@ -25,19 +26,30 @@ #include "test_bench.h" #include "sensor_adapter.h" +/* exception list */ +#define SAMSUNG_PEDOMETER "http://samsung.com/sensor/healthinfo/pedometer/samsung_pedometer" + static void basic_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) { EXPECT_GT(data->timestamp, 0); - //_N("[ DATA ] %f\n", data->values[0]); + _N(_WHT "[ DATA ] %f\n" _RST, data->values[0]); mainloop::stop(); } -TESTCASE(all_sensor_test, scenario_basic_p) +static bool skip_sensor(sensor_t sensor) +{ + const char *uri = sensord_get_uri(sensor); + + if (strncmp(uri, SAMSUNG_PEDOMETER, sizeof(SAMSUNG_PEDOMETER)) == 0) + return true; + + return false; +} + +TESTCASE(sensor_basic, all_sensor_p) { - int err; + int err, count, handle; bool ret; - int count; - int handle; sensor_t *sensors; sensor_type_t type; @@ -45,10 +57,12 @@ TESTCASE(all_sensor_test, scenario_basic_p) ASSERT_EQ(err, 0); for (int i = 0; i < count; ++i) { - sensord_get_type(sensors[i], &type); - /* TODO */ - _N("[ TYPE ] %s\n", "UNKNOWN_SENSOR"); + if (skip_sensor(sensors[i])) + continue; + + _W("[ SENSOR %d ] %s\n", i, sensord_get_uri(sensors[i])); + sensord_get_type(sensors[i], &type); sensor_info info(type, 0, 100, 1000, SENSOR_OPTION_ALWAYS_ON, basic_cb, NULL); ret = sensor_adapter::start(info, handle); @@ -64,101 +78,3 @@ TESTCASE(all_sensor_test, scenario_basic_p) return true; } - -typedef bool (*process_func_t)(const char *msg, int size, int count); - -static pid_t run_process(process_func_t func, const char *msg, int size, int count) -{ - pid_t pid = fork(); - if (pid < 0) - return -1; - - if (pid == 0) { - if (!func(msg, size, count)) - _E("Failed to run process\n"); - exit(0); - } - - return pid; -} - -static bool run_echo_command_test(const char *str, int size, int cout) -{ - bool ret = true; - int handle; - char buf[4096] = {'1', '1', '1', }; - - sensor_info info(ACCELEROMETER_SENSOR, 0, - 100, 1000, SENSOR_OPTION_ALWAYS_ON, basic_cb, NULL); - sensor_adapter::get_handle(info, handle); - - for (int i = 0; i < 1024; ++i) - ret &= sensor_adapter::set_attribute(handle, SENSOR_ATTR_ACCELEROMETER_INJECTION, buf, 4096); - ASSERT_TRUE(ret); - - return true; -} - -TESTCASE(echo_command_test, echo_command_p) -{ - pid_t pid; - - for (int i = 0; i < 100; ++i) { - pid = run_process(run_echo_command_test, NULL, 0, 0); - EXPECT_GE(pid, 0); - } - - pid = run_process(run_echo_command_test, NULL, 0, 0); - EXPECT_GE(pid, 0); - - ASSERT_TRUE(true); - - return true; -} - -#if 0 -TESTCASE(gyroscope_value_p) -{ - scenario_basic_p(GYROSCOPE_SENSOR); -} - -TESTCASE(gravitye_value_p) -{ - scenario_basic_p(GRAVITY_SENSOR); -} - -TESTCASE(linear_accel_value_p) -{ - scenario_basic_p(LINEAR_ACCEL_SENSOR); -} - -TESTCASE(proximity_value_p) -{ - scenario_basic_p(PROXIMITY_SENSOR); -} - -TESTCASE(pressure_value_p) -{ - scenario_basic_p(PRESSURE_SENSOR); -} - -TESTCASE(hrm_value_p) -{ - scenario_basic_p(HRM_SENSOR); -} - -TESTCASE(hrm_raw_value_p) -{ - scenario_basic_p(HRM_RAW_SENSOR); -} - -TESTCASE(hrm_led_green_value_p) -{ - scenario_basic_p(HRM_LED_GREEN_SENSOR); -} - -TESTCASE(wrist_up_value_p) -{ - scenario_basic_p(GESTURE_WRIST_UP_SENSOR); -} -#endif diff --git a/src/sensorctl/testcase/sensor_interval.cpp b/src/sensorctl/testcase/sensor_interval.cpp index 8318fd5..7a1e254 100644 --- a/src/sensorctl/testcase/sensor_interval.cpp +++ b/src/sensorctl/testcase/sensor_interval.cpp @@ -17,10 +17,100 @@ * */ +#include +#include + +#include "log.h" +#include "mainloop.h" #include "test_bench.h" +#include "sensor_adapter.h" -TESTCASE(sensor_interval, all_sensor_interval_10ms_p) +static void basic_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) { - /* TODO: test 10ms interval */ + EXPECT_GT(data->timestamp, 0); + mainloop::stop(); +} + +TESTCASE(interval_test, 20ms_p) +{ + int err, count, handle; + bool ret; + sensor_t *sensors; + sensor_type_t type; + + err = sensord_get_sensors(ACCELEROMETER_SENSOR, &sensors, &count); + ASSERT_EQ(err, 0); + + for (int i = 0; i < count; ++i) { + sensord_get_type(sensors[i], &type); + sensor_info info(type, 0, 20, 1000, SENSOR_OPTION_ALWAYS_ON, basic_cb, NULL); + + ret = sensor_adapter::start(info, handle); + EXPECT_TRUE(ret); + + mainloop::run(); + + ret = sensor_adapter::stop(info, handle); + EXPECT_TRUE(ret); + } + + free(sensors); + + return true; +} + +TESTCASE(interval_test, 100ms_p) +{ + int err, count, handle; + bool ret; + sensor_t *sensors; + sensor_type_t type; + + err = sensord_get_sensors(ACCELEROMETER_SENSOR, &sensors, &count); + ASSERT_EQ(err, 0); + + for (int i = 0; i < count; ++i) { + sensord_get_type(sensors[i], &type); + sensor_info info(type, 0, 100, 1000, SENSOR_OPTION_ALWAYS_ON, basic_cb, NULL); + + ret = sensor_adapter::start(info, handle); + EXPECT_TRUE(ret); + + mainloop::run(); + + ret = sensor_adapter::stop(info, handle); + EXPECT_TRUE(ret); + } + + free(sensors); + + return true; +} + +TESTCASE(interval_test, 200ms_p) +{ + int err, count, handle; + bool ret; + sensor_t *sensors; + sensor_type_t type; + + err = sensord_get_sensors(ACCELEROMETER_SENSOR, &sensors, &count); + ASSERT_EQ(err, 0); + + for (int i = 0; i < count; ++i) { + sensord_get_type(sensors[i], &type); + sensor_info info(type, 0, 200, 1000, SENSOR_OPTION_ALWAYS_ON, basic_cb, NULL); + + ret = sensor_adapter::start(info, handle); + EXPECT_TRUE(ret); + + mainloop::run(); + + ret = sensor_adapter::stop(info, handle); + EXPECT_TRUE(ret); + } + + free(sensors); + return true; } diff --git a/src/sensorctl/testcase/unit_client.cpp b/src/sensorctl/testcase/sensor_listener.cpp similarity index 54% rename from src/sensorctl/testcase/unit_client.cpp rename to src/sensorctl/testcase/sensor_listener.cpp index 16c5f1d..f92d33a 100644 --- a/src/sensorctl/testcase/unit_client.cpp +++ b/src/sensorctl/testcase/sensor_listener.cpp @@ -30,13 +30,17 @@ #include "test_bench.h" static bool called = false; +static int count = 0; static void event_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) { _I("[%llu] %f %f %f\n", data->timestamp, data->values[0], data->values[1], data->values[2]); + + if (count++ > 3) + mainloop::stop(); } -TESTCASE(sensor_api_get_default_sensor, get_sensor_p_1) +TESTCASE(sensor_listener, get_default_sensor_p_1) { int err; sensor_t sensor; @@ -47,7 +51,7 @@ TESTCASE(sensor_api_get_default_sensor, get_sensor_p_1) return true; } -TESTCASE(sensor_api_get_sensors, get_sensor_p_2) +TESTCASE(sensor_listener, get_sensors_p_1) { int err; int count; @@ -62,7 +66,7 @@ TESTCASE(sensor_api_get_sensors, get_sensor_p_2) return true; } -TESTCASE(sensor_api_connect, connect_p_1) +TESTCASE(sensor_listener, connect_p_1) { int err; int handle; @@ -80,7 +84,7 @@ TESTCASE(sensor_api_connect, connect_p_1) return true; } -TESTCASE(sensor_api_all, all_p_1) +TESTCASE(sensor_listener, all_api_p_1) { int err; bool ret; @@ -127,3 +131,95 @@ TESTCASE(sensor_api_all, all_p_1) return true; } + +TESTCASE(sensor_listener, bad_unregister_stop_order_p_1) +{ + int err; + bool ret; + int handle; + sensor_t sensor; + + called = false; + + err = sensord_get_default_sensor(ACCELEROMETER_SENSOR, &sensor); + ASSERT_EQ(err, 0); + + handle = sensord_connect(sensor); + ret = sensord_register_event(handle, 1, 100, 100, event_cb, NULL); + ret = sensord_start(handle, 0); + ret = sensord_change_event_interval(handle, 0, 100); + + mainloop::run(); + + /* [TEST] Unregister event before stop */ + ret = sensord_unregister_event(handle, 1); + ASSERT_TRUE(ret); + + ret = sensord_stop(handle); + ASSERT_TRUE(ret); + + ret = sensord_disconnect(handle); + ASSERT_TRUE(ret); + + return true; +} + +TESTCASE(sensor_listener, bad_disconnect_p_1) +{ + int err; + bool ret; + int handle; + sensor_t sensor; + + called = false; + + err = sensord_get_default_sensor(ACCELEROMETER_SENSOR, &sensor); + ASSERT_EQ(err, 0); + + handle = sensord_connect(sensor); + ret = sensord_register_event(handle, 1, 100, 100, event_cb, NULL); + ret = sensord_start(handle, 0); + ret = sensord_change_event_interval(handle, 0, 100); + + mainloop::run(); + + /* [TEST] Unregistering event is not called */ + + ret = sensord_stop(handle); + ASSERT_TRUE(ret); + + ret = sensord_disconnect(handle); + ASSERT_TRUE(ret); + + return true; +} + +TESTCASE(sensor_listener, bad_disconnect_p_2) +{ + int err; + bool ret; + int handle; + sensor_t sensor; + + called = false; + + err = sensord_get_default_sensor(ACCELEROMETER_SENSOR, &sensor); + ASSERT_EQ(err, 0); + + handle = sensord_connect(sensor); + ret = sensord_register_event(handle, 1, 100, 100, event_cb, NULL); + ret = sensord_start(handle, 0); + ret = sensord_change_event_interval(handle, 0, 100); + + mainloop::run(); + + ret = sensord_unregister_event(handle, 1); + ASSERT_TRUE(ret); + + /* [TEST] stopping sensor is not called */ + + ret = sensord_disconnect(handle); + ASSERT_TRUE(ret); + + return true; +} diff --git a/src/sensorctl/testcase/unit_provider.cpp b/src/sensorctl/testcase/sensor_provider.cpp similarity index 94% rename from src/sensorctl/testcase/unit_provider.cpp rename to src/sensorctl/testcase/sensor_provider.cpp index 0c61862..9c76c21 100644 --- a/src/sensorctl/testcase/unit_provider.cpp +++ b/src/sensorctl/testcase/sensor_provider.cpp @@ -36,9 +36,6 @@ static bool called = false; static void event_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) { - if (test_option::full_log == false) { - while (true) {} - } _I("[%llu] %f %f %f\n", data->timestamp, data->values[0], data->values[1], data->values[2]); } @@ -107,7 +104,7 @@ static void removed_cb(const char *uri, void *user_data) mainloop::stop(); } -TESTCASE(sensor_api_provider_uri, provider_check_uri) +TESTCASE(sensor_provider, check_uri) { int err; sensord_provider_h provider; @@ -139,7 +136,27 @@ TESTCASE(sensor_api_provider_uri, provider_check_uri) } /* TODO: change it from manual test to auto-test */ -TESTCASE(sensor_api_provider_mysensor, provider_p_1) +TESTCASE(skip_sensor_provider, mysensor_added_removed_cb_p_1) +{ + int ret = sensord_add_sensor_added_cb(added_cb, NULL); + ASSERT_EQ(ret, 0); + ret = sensord_add_sensor_removed_cb(removed_cb, NULL); + ASSERT_EQ(ret, 0); + + add_mysensor(); + + mainloop::run(); + + ret = sensord_remove_sensor_added_cb(added_cb); + ASSERT_EQ(ret, 0); + ret = sensord_remove_sensor_removed_cb(removed_cb); + ASSERT_EQ(ret, 0); + + return true; +} + +/* TODO: change it from manual test to auto-test */ +TESTCASE(skip_sensor_provider, mysensor_p) { int err = 0; sensor_t sensor; @@ -181,7 +198,8 @@ TESTCASE(sensor_api_provider_mysensor, provider_p_1) return true; } -TESTCASE(sensor_api_listener_mysensor, listener_p_1) +/* TODO: change it from manual test to auto-test */ +TESTCASE(skip_sensor_provider, mysensor_with_listener_p_1) { int err; bool ret; @@ -219,23 +237,3 @@ TESTCASE(sensor_api_listener_mysensor, listener_p_1) return true; } -TESTCASE(sensor_api_provider_cb, mysensor_cb_p_1) -{ - int ret; - - ret = sensord_add_sensor_added_cb(added_cb, NULL); - ASSERT_EQ(ret, 0); - ret = sensord_add_sensor_removed_cb(removed_cb, NULL); - ASSERT_EQ(ret, 0); - - add_mysensor(); - - mainloop::run(); - - ret = sensord_remove_sensor_added_cb(added_cb); - ASSERT_EQ(ret, 0); - ret = sensord_remove_sensor_removed_cb(removed_cb); - ASSERT_EQ(ret, 0); - - return true; -} diff --git a/src/sensorctl/testcase/unit_ipc.cpp b/src/sensorctl/testcase/unit_ipc.cpp index d820707..799924a 100644 --- a/src/sensorctl/testcase/unit_ipc.cpp +++ b/src/sensorctl/testcase/unit_ipc.cpp @@ -102,7 +102,7 @@ public: }; /* IPC Client Sleep Test(4096Kb * 1024) */ -static bool run_ipc_client_sleep_10s(const char *str, int size, int count) +static bool run_ipc_client_sleep_1s(const char *str, int size, int count) { ipc_client client(TEST_PATH); test_client_handler_30_1M client_handler; @@ -355,9 +355,9 @@ static bool run_ipc_client(const char *str, int size, int count) } /** - * @brief Test 3 client + 1 client which sleeps 10 seconds + * @brief Test 3 client + 1 client which sleeps 1 seconds */ -TESTCASE(sensor_ipc_client_sleep_1s, sleep_1s_p) +TESTCASE(sensor_ipc, 3_client_with_1s_sleep_client_p) { pid_t pid = run_process(run_ipc_server_echo, NULL, 0, 0); EXPECT_GE(pid, 0); @@ -369,7 +369,7 @@ TESTCASE(sensor_ipc_client_sleep_1s, sleep_1s_p) EXPECT_GE(pid, 0); } - bool ret = run_ipc_client_sleep_10s(NULL, 0, 0); + bool ret = run_ipc_client_sleep_1s(NULL, 0, 0); ASSERT_TRUE(ret); SLEEP_1S; @@ -378,9 +378,9 @@ TESTCASE(sensor_ipc_client_sleep_1s, sleep_1s_p) } /** - * @brief Test 3 client + 1 client which has small recv buffer + * @brief Test 3 client + 1 client which has small recv buffer(2240) */ -TESTCASE(sensor_ipc_client_small_2240, ipc_client_small_2240_p) +TESTCASE(sensor_ipc, 3_client_with_small_buffer_client_p) { pid_t pid = run_process(run_ipc_server_echo, NULL, 0, 0); EXPECT_GE(pid, 0); @@ -403,7 +403,7 @@ TESTCASE(sensor_ipc_client_small_2240, ipc_client_small_2240_p) /** * @brief Test 30 ipc_client with 1M message */ -TESTCASE(sensor_ipc_30_client_1M, ipc_client_p_30_1M) +TESTCASE(sensor_ipc, 30_client_with_1M_message_p) { pid_t pid = run_process(run_ipc_server_echo, NULL, 0, 0); EXPECT_GE(pid, 0); @@ -426,7 +426,7 @@ TESTCASE(sensor_ipc_30_client_1M, ipc_client_p_30_1M) /** * @brief Test 2 channel of 1 client with message */ -TESTCASE(sensor_ipc_client_2_channel_message, 2_channel_message_p) +TESTCASE(sensor_ipc, 1_client_with_2_channel_message_p) { pid_t pid = run_process(run_ipc_server, NULL, 0, 0); EXPECT_GE(pid, 0); @@ -444,7 +444,7 @@ TESTCASE(sensor_ipc_client_2_channel_message, 2_channel_message_p) /** * @brief Test 2 channel of 1 client */ -TESTCASE(sensor_ipc_client_2_channel, 2_channel_p) +TESTCASE(sensor_ipc, 1_client_2_channel_simple_p) { pid_t pid = run_process(run_ipc_server, NULL, 0, 0); EXPECT_GE(pid, 0); @@ -462,7 +462,7 @@ TESTCASE(sensor_ipc_client_2_channel, 2_channel_p) /** * @brief Test 100 ipc_client */ -TESTCASE(sensor_ipc_100_client, ipc_client_p_100) +TESTCASE(sensor_ipc, 100_client_p) { pid_t pid = run_process(run_ipc_server, NULL, 0, 0); EXPECT_GE(pid, 0); @@ -485,7 +485,7 @@ TESTCASE(sensor_ipc_100_client, ipc_client_p_100) /** * @brief Test 2 ipc_client */ -TESTCASE(sensor_ipc_2_client, ipc_client_p_2) +TESTCASE(sensor_ipc, 2_client_p) { pid_t pid = run_process(run_ipc_server, NULL, 0, 0); EXPECT_GE(pid, 0); @@ -509,7 +509,7 @@ TESTCASE(sensor_ipc_2_client, ipc_client_p_2) * 2. send "TEST" message from client to server * 3. check that message in server handler */ -TESTCASE(sensor_ipc_client_0, ipc_client_p_0) +TESTCASE(sensor_ipc, server_client_basic_p) { pid_t pid = run_process(run_ipc_server, NULL, 0, 0); EXPECT_GE(pid, 0); diff --git a/src/sensorctl/testcase/unit_socket.cpp b/src/sensorctl/testcase/unit_socket.cpp index 261976f..1407cfc 100644 --- a/src/sensorctl/testcase/unit_socket.cpp +++ b/src/sensorctl/testcase/unit_socket.cpp @@ -27,11 +27,11 @@ #include "log.h" #include "test_bench.h" -using namespace ipc; - #define MAX_BUF_SIZE 4096 #define TEST_PATH "/run/.sensord_test.socket" +using namespace ipc; + typedef bool (*process_func_t)(const char *msg, int size, int count); static pid_t run_process(process_func_t func, const char *msg, int size, int count) @@ -67,7 +67,9 @@ static bool run_socket_echo_server(const char *msg, int size, int count) accept_sock.set_blocking_mode(true); accept_sock.bind(); accept_sock.listen(10); - accept_sock.accept(client_sock); + + while (!ret) + ret = accept_sock.accept(client_sock); /* receive message */ while (recv_count++ < count) { @@ -129,7 +131,6 @@ static bool run_socket_client(const char *msg, int size, int count) ASSERT_EQ(ret, 0); sock.close(); - return true; } @@ -140,7 +141,7 @@ static bool run_socket_client(const char *msg, int size, int count) * 3. check "TEST" message * @remarks we can test only regular socket, not systemd-based socket. */ -TESTCASE(sensor_ipc_socket, socket_p_0) +TESTCASE(ipc_socket, socket_simple_message_p) { const char *msg = "TEST"; int size = 4; @@ -162,7 +163,7 @@ TESTCASE(sensor_ipc_socket, socket_p_0) * 3. check total size * @remarks we can test only regular socket, not systemd-based socket. */ -TESTCASE(sensor_ipc_socket, socket_p_10) +TESTCASE(ipc_socket, socket_40K_message_p) { const char msg[MAX_BUF_SIZE] = {1, }; int size = MAX_BUF_SIZE; @@ -184,7 +185,7 @@ TESTCASE(sensor_ipc_socket, socket_p_10) * 3. check total size * @remarks we can test only regular socket, not systemd-based socket. */ -TESTCASE(sensor_ipc_socket, socket_p_1000) +TESTCASE(ipc_socket, socket_4M_message_p) { const char msg[MAX_BUF_SIZE] = {1, }; int size = MAX_BUF_SIZE; -- 2.7.4 From 4b702eda5df00c72a28b6dc913decd696eb3fdf6 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 10 Aug 2017 20:21:18 +0900 Subject: [PATCH 12/16] sensorctl: add gyroscope testcases Change-Id: Id5ef5188d07ba827db7add4c690782ae1c408722 Signed-off-by: kibak.yoon --- src/sensorctl/testcase/sensor_gyroscope.cpp | 136 ++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 src/sensorctl/testcase/sensor_gyroscope.cpp diff --git a/src/sensorctl/testcase/sensor_gyroscope.cpp b/src/sensorctl/testcase/sensor_gyroscope.cpp new file mode 100644 index 0000000..f4328e2 --- /dev/null +++ b/src/sensorctl/testcase/sensor_gyroscope.cpp @@ -0,0 +1,136 @@ +/* + * sensorctl + * + * Copyright (c) 2017 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 "log.h" +#include "mainloop.h" +#include "test_bench.h" +#include "sensor_adapter.h" + +static void test_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) +{ + EXPECT_GT(data->timestamp, 0); + EXPECT_NEAR(data->values[0], 0, 576.0); + EXPECT_NEAR(data->values[1], 0, 576.0); + EXPECT_NEAR(data->values[2], 0, 576.0); + + mainloop::stop(); +} + +TESTCASE(gyroscope_test, start_stop_p) +{ + bool ret; + int handle; + + if (!sensor_adapter::is_supported(GYROSCOPE_SENSOR)) + return true; /* Not Supported */ + + sensor_info info(GYROSCOPE_SENSOR, 0, + 100, 1000, SENSOR_OPTION_ALWAYS_ON, test_cb, NULL); + + ret = sensor_adapter::start(info, handle); + ASSERT_TRUE(ret); + + mainloop::run(); + + ret = sensor_adapter::stop(info, handle); + ASSERT_TRUE(ret); + + return true; +} + +static void get_data_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) +{ + mainloop::stop(); +} + +TESTCASE(gyroscope_test, get_data_p) +{ + bool ret; + int handle; + sensor_data_t data; + + if (!sensor_adapter::is_supported(GYROSCOPE_SENSOR)) + return true; /* Not Supported */ + + sensor_info info(GYROSCOPE_SENSOR, 0, + 100, 1000, SENSOR_OPTION_ALWAYS_ON, get_data_cb, NULL); + + ret = sensor_adapter::start(info, handle); + ASSERT_TRUE(ret); + + mainloop::run(); + + ret = sensor_adapter::get_data(handle, info.type, data); + ASSERT_TRUE(ret); + + ret = sensor_adapter::stop(info, handle); + ASSERT_TRUE(ret); + + return true; +} + +static unsigned long long time_first; +static unsigned long long time_last; +static int event_count; + +static void gyro_interval_100ms_cb(sensor_t sensor, unsigned int event_type, sensor_data_t *data, void *user_data) +{ + if (event_count == 0) { + time_first = data->timestamp; + event_count++; + return; + } + + if (event_count == 10) { + /* 100ms + 20ms(error) */ + EXPECT_LE((data->timestamp - time_first) / 10, 120000); + mainloop::stop(); + return; + } + + event_count++; +} + +TESTCASE(gyroscope_test, 100ms_interval_p) +{ + bool ret; + int handle; + + time_first = 0; + time_last = 0; + event_count = 0; + + if (!sensor_adapter::is_supported(GYROSCOPE_SENSOR)) + return true; /* Not Supported */ + + sensor_info info(GYROSCOPE_SENSOR, 0, + 100, 1000, SENSOR_OPTION_ALWAYS_ON, gyro_interval_100ms_cb, NULL); + + ret = sensor_adapter::start(info, handle); + ASSERT_TRUE(ret); + + mainloop::run(); + + ret = sensor_adapter::stop(info, handle); + ASSERT_TRUE(ret); + + return true; +} -- 2.7.4 From e3fe4e63b3db7dc22a828e39229ca45e64acd934 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Thu, 10 Aug 2017 22:14:18 +0900 Subject: [PATCH 13/16] sensord: add log messages Change-Id: I384547eae5fd809f8db433ac97c33831a6d840e9 Signed-off-by: kibak.yoon --- src/client/sensor_listener.cpp | 25 ++++++++++++++++++++++--- src/client/sensor_manager.cpp | 6 ++++++ src/server/application_sensor_handler.cpp | 6 ++++++ src/server/external_sensor_handler.cpp | 6 ++++++ src/server/fusion_sensor_handler.cpp | 6 ++++++ src/server/physical_sensor_handler.cpp | 6 ++++++ src/server/sensor_listener_proxy.cpp | 15 +++++++++++++-- src/server/server_channel_handler.cpp | 22 ++++++++++++++-------- 8 files changed, 79 insertions(+), 13 deletions(-) diff --git a/src/client/sensor_listener.cpp b/src/client/sensor_listener.cpp index 9eedd6d..7c62ea1 100644 --- a/src/client/sensor_listener.cpp +++ b/src/client/sensor_listener.cpp @@ -36,6 +36,7 @@ public: void connected(ipc::channel *ch) {} void disconnected(ipc::channel *ch) { + _D("Disconnected"); /* If channel->disconnect() is not explicitly called, * listener will be restored */ m_listener->restore(); @@ -172,7 +173,7 @@ bool sensor_listener::connect(void) m_evt_channel->bind(); - _D("Listener ID[%d]", get_id()); + _I("Connected listener[%d] with sensor[%s]", get_id(), m_sensor->get_uri().c_str()); return true; } @@ -245,11 +246,15 @@ int sensor_listener::start(void) m_cmd_channel->send_sync(&msg); m_cmd_channel->read_sync(reply); - if (reply.header()->err < 0) + if (reply.header()->err < 0) { + _E("Failed to start listener[%d], sensor[%s]", get_id(), m_sensor->get_uri().c_str()); return reply.header()->err; + } m_started.store(true); + _I("Listener[%d] started", get_id()); + return OP_SUCCESS; } @@ -269,11 +274,15 @@ int sensor_listener::stop(void) m_cmd_channel->send_sync(&msg); m_cmd_channel->read_sync(reply); - if (reply.header()->err < 0) + if (reply.header()->err < 0) { + _E("Failed to stop listener[%d], sensor[%s]", get_id(), m_sensor->get_uri().c_str()); return reply.header()->err; + } m_started.store(false); + _I("Listener[%d] stopped", get_id()); + return OP_SUCCESS; } @@ -321,21 +330,29 @@ int sensor_listener::set_interval(unsigned int interval) else _interval = interval; + _I("Listener[%d] set interval[%u]", get_id(), _interval); + return set_attribute(SENSORD_ATTRIBUTE_INTERVAL, _interval); } int sensor_listener::set_max_batch_latency(unsigned int max_batch_latency) { + _I("Listener[%d] set max batch latency[%u]", get_id(), max_batch_latency); + return set_attribute(SENSORD_ATTRIBUTE_MAX_BATCH_LATENCY, max_batch_latency); } int sensor_listener::set_passive_mode(bool passive) { + _I("Listener[%d] set passive mode[%d]", get_id(), passive); + return set_attribute(SENSORD_ATTRIBUTE_PASSIVE_MODE, passive); } int sensor_listener::flush(void) { + _I("Listener[%d] flushes", get_id()); + return set_attribute(SENSORD_ATTRIBUTE_FLUSH, 1); } @@ -413,6 +430,8 @@ int sensor_listener::get_sensor_data(sensor_data_t *data) memcpy(data, &buf.data, buf.len); + _D("Listener[%d] read sensor data", get_id()); + return OP_SUCCESS; } diff --git a/src/client/sensor_manager.cpp b/src/client/sensor_manager.cpp index 101b833..2769668 100644 --- a/src/client/sensor_manager.cpp +++ b/src/client/sensor_manager.cpp @@ -119,6 +119,8 @@ int sensor_manager::add_sensor(sensor_info &info) m_sensors.push_back(info); + _I("Added sensor[%s]", info.get_uri().c_str()); + return OP_SUCCESS; } @@ -133,6 +135,8 @@ int sensor_manager::remove_sensor(const char *uri) for (auto it = m_sensors.begin(); it != m_sensors.end(); ++it) { if ((*it).get_uri() == uri) { m_sensors.erase(it); + _I("Removed sensor[%s]", (*it).get_uri().c_str()); + return OP_SUCCESS; } } @@ -321,6 +325,8 @@ bool sensor_manager::has_privilege(std::string &uri) if (reply.header()->err == OP_SUCCESS) return true; + _W("This client doesn't have the privilege for sensor[%s]", uri.c_str()); + return false; } diff --git a/src/server/application_sensor_handler.cpp b/src/server/application_sensor_handler.cpp index 4e4b96b..a5f9c0f 100644 --- a/src/server/application_sensor_handler.cpp +++ b/src/server/application_sensor_handler.cpp @@ -61,6 +61,8 @@ int application_sensor_handler::start(sensor_observer *ob) m_ch->send_sync(&msg); m_started.store(true); + _I("Started[%s]", m_info.get_uri().c_str()); + return OP_SUCCESS; } @@ -76,6 +78,8 @@ int application_sensor_handler::stop(sensor_observer *ob) m_ch->send_sync(&msg); m_started.store(false); + _I("Stopped[%s]", m_info.get_uri().c_str()); + return OP_SUCCESS; } @@ -119,6 +123,8 @@ int application_sensor_handler::set_interval(sensor_observer *ob, int32_t interv m_prev_interval = cur_interval; + _I("Set interval[%d] to sensor[%s]", cur_interval, m_info.get_uri().c_str()); + return OP_SUCCESS; } diff --git a/src/server/external_sensor_handler.cpp b/src/server/external_sensor_handler.cpp index 7b3e7da..474f764 100644 --- a/src/server/external_sensor_handler.cpp +++ b/src/server/external_sensor_handler.cpp @@ -100,6 +100,8 @@ int external_sensor_handler::start(sensor_observer *ob) add_observer(ob); + _I("Started[%s]", m_info.get_uri().c_str()); + return OP_SUCCESS; } @@ -112,6 +114,8 @@ int external_sensor_handler::stop(sensor_observer *ob) remove_observer(ob); + _I("Stopped[%s]", m_info.get_uri().c_str()); + return OP_SUCCESS; } @@ -153,6 +157,8 @@ int external_sensor_handler::set_interval(sensor_observer *ob, int32_t interval) return m_sensor->set_interval(ob, _interval); } + _I("Set interval[%d] to sensor[%s]", _interval, m_info.get_uri().c_str()); + return OP_SUCCESS; } diff --git a/src/server/fusion_sensor_handler.cpp b/src/server/fusion_sensor_handler.cpp index 3215051..6cbc692 100644 --- a/src/server/fusion_sensor_handler.cpp +++ b/src/server/fusion_sensor_handler.cpp @@ -83,6 +83,8 @@ int fusion_sensor_handler::start(sensor_observer *ob) return OP_SUCCESS; } + _I("Started[%s]", m_info.get_uri().c_str()); + return start_internal(); } @@ -102,6 +104,8 @@ int fusion_sensor_handler::stop(sensor_observer *ob) return OP_SUCCESS; /* already started */ } + _I("Stopped[%s]", m_info.get_uri().c_str()); + return stop_internal(); } @@ -140,6 +144,8 @@ int fusion_sensor_handler::set_interval(sensor_observer *ob, int32_t interval) if (policy == OP_DEFAULT) _interval = get_min_interval(); + _I("Set interval[%d] to sensor[%s]", _interval, m_info.get_uri().c_str()); + return set_interval_internal(_interval); } diff --git a/src/server/physical_sensor_handler.cpp b/src/server/physical_sensor_handler.cpp index bdc53b3..f73ee5d 100644 --- a/src/server/physical_sensor_handler.cpp +++ b/src/server/physical_sensor_handler.cpp @@ -104,6 +104,8 @@ int physical_sensor_handler::start(sensor_observer *ob) return OP_SUCCESS; /* already started */ } + _I("Started[%s]", m_info.get_uri().c_str()); + return m_device->enable(m_hal_id); } @@ -125,6 +127,8 @@ int physical_sensor_handler::stop(sensor_observer *ob) return OP_SUCCESS; /* already stopped */ } + _I("Stopped[%s]", m_info.get_uri().c_str()); + return m_device->disable(m_hal_id); } @@ -172,6 +176,8 @@ int physical_sensor_handler::set_interval(sensor_observer *ob, int32_t interval) m_prev_interval = cur_interval; + _I("Set interval[%d] to sensor[%s]", cur_interval, m_info.get_uri().c_str()); + return (ret ? OP_SUCCESS : OP_ERROR); } diff --git a/src/server/sensor_listener_proxy.cpp b/src/server/sensor_listener_proxy.cpp index 51b38a9..a850018 100644 --- a/src/server/sensor_listener_proxy.cpp +++ b/src/server/sensor_listener_proxy.cpp @@ -98,6 +98,8 @@ int sensor_listener_proxy::start(void) sensor_handler *sensor = m_manager->get_sensor(m_uri); retv_if(!sensor, -EINVAL); + _D("Listener[%d] try to start", get_id()); + /* TODO: listen pause policy */ return sensor->start(this); } @@ -108,9 +110,10 @@ int sensor_listener_proxy::stop(void) retv_if(!sensor, -EINVAL); /* TODO: listen pause policy */ - int ret; - ret = sensor->stop(this); + _D("Listener[%d] try to stop", get_id()); + + int ret = sensor->stop(this); retv_if(ret < 0, OP_ERROR); /* unset attributes */ @@ -125,6 +128,8 @@ int sensor_listener_proxy::set_interval(unsigned int interval) sensor_handler *sensor = m_manager->get_sensor(m_uri); retv_if(!sensor, -EINVAL); + _D("Listener[%d] try to set interval[%d]", get_id(), interval); + return sensor->set_interval(this, interval); } @@ -133,6 +138,8 @@ int sensor_listener_proxy::set_max_batch_latency(unsigned int max_batch_latency) sensor_handler *sensor = m_manager->get_sensor(m_uri); retv_if(!sensor, -EINVAL); + _D("Listener[%d] try to set max batch latency[%d]", get_id(), max_batch_latency); + return sensor->set_batch_latency(this, max_batch_latency); } @@ -148,6 +155,8 @@ int sensor_listener_proxy::set_attribute(int attribute, int value) sensor_handler *sensor = m_manager->get_sensor(m_uri); retv_if(!sensor, -EINVAL); + _D("Listener[%d] try to set attribute[%d, %d]", get_id(), attribute, value); + if (attribute == SENSORD_ATTRIBUTE_PAUSE_POLICY) { m_pause_policy = value; return OP_SUCCESS; @@ -164,6 +173,8 @@ int sensor_listener_proxy::set_attribute(int attribute, const char *value, int l sensor_handler *sensor = m_manager->get_sensor(m_uri); retv_if(!sensor, -EINVAL); + _D("Listener[%d] try to set attribute[%d, %s]", get_id(), attribute, value); + return sensor->set_attribute(this, attribute, value, len); } diff --git a/src/server/server_channel_handler.cpp b/src/server/server_channel_handler.cpp index fbcb6cb..2188c61 100644 --- a/src/server/server_channel_handler.cpp +++ b/src/server/server_channel_handler.cpp @@ -146,7 +146,8 @@ int server_channel_handler::listener_connect(channel *ch, message &msg) buf.sensor, m_manager, ch); retvm_if(!listener, OP_ERROR, "Failed to allocate memory"); retvm_if(!has_privileges(ch->get_fd(), listener->get_required_privileges()), - -EACCES, "Permission denied"); + -EACCES, "Permission denied[%d, %s]", + listener_id, m_listeners[listener_id]->get_required_privileges().c_str()); buf.listener_id = listener_id; @@ -174,10 +175,11 @@ int server_channel_handler::listener_start(channel *ch, message &msg) auto it = m_listeners.find(id); retv_if(it == m_listeners.end(), -EINVAL); retvm_if(!has_privileges(ch->get_fd(), m_listeners[id]->get_required_privileges()), - -EACCES, "Permission denied"); + -EACCES, "Permission denied[%d, %s]", + id, m_listeners[id]->get_required_privileges().c_str()); int ret = m_listeners[id]->start(); - retv_if(ret < 0, ret); + retvm_if(ret < 0, ret, "Failed to start listener[%d]", id); return send_reply(ch, OP_SUCCESS); } @@ -191,10 +193,11 @@ int server_channel_handler::listener_stop(channel *ch, message &msg) auto it = m_listeners.find(id); retv_if(it == m_listeners.end(), -EINVAL); retvm_if(!has_privileges(ch->get_fd(), m_listeners[id]->get_required_privileges()), - -EACCES, "Permission denied"); + -EACCES, "Permission denied[%d, %s]", + id, m_listeners[id]->get_required_privileges().c_str()); int ret = m_listeners[id]->stop(); - retv_if(ret < 0, ret); + retvm_if(ret < 0, ret, "Failed to stop listener[%d]", id); return send_reply(ch, OP_SUCCESS); } @@ -210,7 +213,8 @@ int server_channel_handler::listener_attr_int(channel *ch, message &msg) auto it = m_listeners.find(id); retv_if(it == m_listeners.end(), -EINVAL); retvm_if(!has_privileges(ch->get_fd(), m_listeners[id]->get_required_privileges()), - -EACCES, "Permission denied"); + -EACCES, "Permission denied[%d, %s]", + id, m_listeners[id]->get_required_privileges().c_str()); switch (buf.attribute) { case SENSORD_ATTRIBUTE_INTERVAL: @@ -240,7 +244,8 @@ int server_channel_handler::listener_attr_str(channel *ch, message &msg) auto it = m_listeners.find(id); retv_if(it == m_listeners.end(), -EINVAL); retvm_if(!has_privileges(ch->get_fd(), m_listeners[id]->get_required_privileges()), - -EACCES, "Permission denied"); + -EACCES, "Permission denied[%d, %s]", + id, m_listeners[id]->get_required_privileges().c_str()); int ret = m_listeners[id]->set_attribute(buf.attribute, buf.value, buf.len); retv_if(ret < 0, ret); @@ -262,7 +267,8 @@ int server_channel_handler::listener_get_data(channel *ch, message &msg) auto it = m_listeners.find(id); retv_if(it == m_listeners.end(), -EINVAL); retvm_if(!has_privileges(ch->get_fd(), m_listeners[id]->get_required_privileges()), - -EACCES, "Permission denied"); + -EACCES, "Permission denied[%d, %s]", + id, m_listeners[id]->get_required_privileges().c_str()); int ret = m_listeners[id]->get_data(&data, &len); retv_if(ret < 0, ret); -- 2.7.4 From ffddb3be7c4e0fb0935a8a52e0bd9f0f8736a3be Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Wed, 16 Aug 2017 10:52:20 +0900 Subject: [PATCH 14/16] sensorctl: apply ASLR to sensorctl Change-Id: I92770df7a1e80753b618a380f775385d47763571 Signed-off-by: kibak.yoon --- src/sensorctl/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sensorctl/CMakeLists.txt b/src/sensorctl/CMakeLists.txt index 7b44303..cfbc071 100644 --- a/src/sensorctl/CMakeLists.txt +++ b/src/sensorctl/CMakeLists.txt @@ -19,7 +19,8 @@ FOREACH(flag ${PKGS_CFLAGS}) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}") ENDFOREACH(flag) -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -fPIE") +SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie") # Installing files FILE(GLOB_RECURSE SRCS *.cpp) -- 2.7.4 From 7c79a93dbf8d32d91820ea00aaf2640cc2708544 Mon Sep 17 00:00:00 2001 From: Marcin Masternak Date: Fri, 8 Sep 2017 20:16:22 +0200 Subject: [PATCH 15/16] sensord: samsung pedometer sensor for fused location fix/update. Change-Id: I007bf4564c426e897ab273824231782fa65054ee Signed-off-by: Marcin Masternak --- src/sensor/pedometer/pedometer.cpp | 46 +++++++----- src/sensor/pedometer/pedometer.h | 8 ++- src/sensor/pedometer/pedometer_sensor.cpp | 6 +- .../pedometer/sensor_frequency_compensator.cpp | 83 ++++++++++++++++++++++ .../pedometer/sensor_frequency_compensator.h | 68 ++++++++++++++++++ src/sensor/pedometer/step_detection.cpp | 14 ++-- 6 files changed, 199 insertions(+), 26 deletions(-) create mode 100644 src/sensor/pedometer/sensor_frequency_compensator.cpp create mode 100644 src/sensor/pedometer/sensor_frequency_compensator.h diff --git a/src/sensor/pedometer/pedometer.cpp b/src/sensor/pedometer/pedometer.cpp index b642746..f076c16 100644 --- a/src/sensor/pedometer/pedometer.cpp +++ b/src/sensor/pedometer/pedometer.cpp @@ -19,12 +19,16 @@ #include +/** Desired sensors rate. Currently 33ms. */ +#define DESIRED_RATE ((1000 / 30) * 1000000) + pedometer::pedometer() : m_step_detection() , m_total_length(0) , m_step_count(0) , m_pedometer_filter() , m_some_speed(false) +, m_acceleration_compensator(DESIRED_RATE) { } @@ -44,30 +48,40 @@ void pedometer::reset(void) m_step_detection.reset(); m_pedometer_filter.reset(); m_some_speed = false; + m_acceleration_compensator.reset(); } -bool pedometer::get_pedometer(timestamp_t timestamp, double acc, pedometer_info *info) +bool pedometer::get_pedometer(pedometer_info *info, timestamp_t timestamp, double acc[]) { bool result = false; + m_acceleration_compensator.add(timestamp, acc); step_event event; - if (m_step_detection.get_step(timestamp, acc, &event)) { - if (event.m_timestamp != UNKNOWN_TIMESTAMP) { - m_step_count++; - m_total_length += event.m_step_length; - m_pedometer_filter.get_step(timestamp, event.m_step_length); - double speed = m_pedometer_filter.get_speed(timestamp); - info->timestamp = timestamp; - info->is_step_detected = true; - info->step_count = m_step_count; - info->step_length = event.m_step_length; - info->total_step_length = m_total_length; - info->step_speed = speed; - result = true; - m_some_speed = speed != 0; + while (m_acceleration_compensator.has_next()) { + double acceleration[3]; + m_acceleration_compensator.get_next(acceleration); + if (m_step_detection.get_step(timestamp, + sqrt(acceleration[0] * acceleration[0] + + acceleration[1] * acceleration[1] + + acceleration[2] * acceleration[2]), + &event)) { + if (event.m_timestamp != UNKNOWN_TIMESTAMP) { + m_step_count++; + m_total_length += event.m_step_length; + m_pedometer_filter.get_step(timestamp, event.m_step_length); + double speed = m_pedometer_filter.get_speed(timestamp); + info->timestamp = timestamp; + info->is_step_detected = true; + info->step_count = m_step_count; + info->step_length = event.m_step_length; + info->total_step_length = m_total_length; + info->step_speed = speed; + result = true; + m_some_speed = speed != 0; + } } } - if (m_some_speed) { + if ((!result) && m_some_speed) { double speed = m_pedometer_filter.get_speed(timestamp); if (speed == 0) { m_some_speed = false; diff --git a/src/sensor/pedometer/pedometer.h b/src/sensor/pedometer/pedometer.h index 3f904d7..edf3638 100644 --- a/src/sensor/pedometer/pedometer.h +++ b/src/sensor/pedometer/pedometer.h @@ -21,6 +21,7 @@ #include "step_detection.h" #include "pedometer_info.h" #include "pedometer_speed_filter.h" +#include "sensor_frequency_compensator.h" /************************************************************************ * stores pedometer engine state. @@ -48,12 +49,12 @@ public: * @param timestamp * timestamp of acceleration event in ns. * @param acc - * vertical component of global acceleration. + * global acceleration. * * @result * true if new step event was detected. */ - bool get_pedometer(timestamp_t timestamp, double acc, pedometer_info *info); + bool get_pedometer(pedometer_info *info, timestamp_t timestamp, double acc[]); private: /** detects step and estimates step length. */ @@ -70,6 +71,9 @@ private: /** some non zero speed was detected. */ bool m_some_speed; + + sensor_frequency_compensator m_acceleration_compensator; + }; #endif /* __PEDOMETER_H__ */ diff --git a/src/sensor/pedometer/pedometer_sensor.cpp b/src/sensor/pedometer/pedometer_sensor.cpp index d16bdcc..e60ec43 100644 --- a/src/sensor/pedometer/pedometer_sensor.cpp +++ b/src/sensor/pedometer/pedometer_sensor.cpp @@ -28,8 +28,6 @@ #define SRC_ID_ACC 0x1 #define SRC_STR_ACC "http://tizen.org/sensor/general/accelerometer" -#define NORM(x, y, z) sqrt((x)*(x) + (y)*(y) + (z)*(z)) - #define US_TO_NS(x) (x * 1000) /* Sensor information */ @@ -82,9 +80,9 @@ int pedometer_sensor::get_required_sensors(const required_sensor_s **sensors) int pedometer_sensor::update(uint32_t id, sensor_data_t *data, int len) { pedometer_info info; - double acc = NORM(data->values[0], data->values[1], data->values[2]); + double acc[] = {data->values[0], data->values[1], data->values[2]}; - if (!m_pedometer.get_pedometer(US_TO_NS(data->timestamp), acc, &info)) + if (!m_pedometer.get_pedometer(&info, US_TO_NS(data->timestamp), acc)) return OP_ERROR; m_step_count = info.step_count; diff --git a/src/sensor/pedometer/sensor_frequency_compensator.cpp b/src/sensor/pedometer/sensor_frequency_compensator.cpp new file mode 100644 index 0000000..9475bdc --- /dev/null +++ b/src/sensor/pedometer/sensor_frequency_compensator.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2016-2017 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 "sensor_frequency_compensator.h" + +#include +#include +#include + +/************************************************************************ + */ +sensor_frequency_compensator::sensor_frequency_compensator(double desired_rate) +: m_desired_frequency(desired_rate) +, m_t1(0) +, m_v1{0.0, 0.0, 0.0} +, m_t2(0) +, m_v2{0.0, 0.0, 0.0} +, m_timestamp(0) +{ +} + +/************************************************************************ + */ +sensor_frequency_compensator::~sensor_frequency_compensator() +{ +} + +/************************************************************************ + */ +void sensor_frequency_compensator::reset() { + m_t1 = UNKNOWN_TIMESTAMP; + m_t2 = UNKNOWN_TIMESTAMP; + m_timestamp = UNKNOWN_TIMESTAMP; +} + +/************************************************************************ + */ +void sensor_frequency_compensator::add(timestamp_t t, double *v) { + if (m_timestamp == UNKNOWN_TIMESTAMP) { + m_timestamp = t; + } + m_t1 = m_t2; + memcpy(m_v1, m_v2, sizeof(m_v1)); + m_t2 = t; + memcpy(m_v2, v, sizeof(m_v2)); +} + +/************************************************************************ + */ +bool sensor_frequency_compensator::has_next() { + if (m_t1 == UNKNOWN_TIMESTAMP || m_t2 == UNKNOWN_TIMESTAMP) { + return false; + } + return m_timestamp + m_desired_frequency < m_t2; +} + +/************************************************************************ + */ +void sensor_frequency_compensator::get_next(double *v) { + timestamp_t t3 = m_timestamp; + if (t3 < m_t1) { + t3 = m_t1; + } + m_timestamp += m_desired_frequency; + double t = (t3 - m_t1) / ((double) (m_t2 - m_t1)); + int i; + for (i = 0; i < 3; i++) { + v[i] = (1.0 - t) * m_v1[i] + t * m_v2[i]; + } +} diff --git a/src/sensor/pedometer/sensor_frequency_compensator.h b/src/sensor/pedometer/sensor_frequency_compensator.h new file mode 100644 index 0000000..664fedb --- /dev/null +++ b/src/sensor/pedometer/sensor_frequency_compensator.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2016-2017 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. + */ + +#ifndef __SENSOR_FREQUENCY_COMPENSATOR_H_ +#define __SENSOR_FREQUENCY_COMPENSATOR_H_ + +#include "common.h" + +#include + +/************************************************************************ + * Stores frequency compensator state. + */ +class sensor_frequency_compensator { +public: + sensor_frequency_compensator(double desired_rate); + ~sensor_frequency_compensator(); + + /************************************************************************ + * Resets frequency compensator to initial state. + */ + void reset(); + + /************************************************************************ + * Filters input data. + * + * @param value + * Data to filter. + * @result Filtered data. + */ + void add(timestamp_t t, double *value); + + /************************************************************************ + */ + bool has_next(); + + /************************************************************************ + */ + void get_next(double *value); + +private: + long long m_desired_frequency; + + timestamp_t m_t1; + + double m_v1[3]; + + timestamp_t m_t2; + + double m_v2[3]; + + timestamp_t m_timestamp; +}; + +#endif /* __SENSOR_FREQUENCY_COMPENSATOR_H_ */ diff --git a/src/sensor/pedometer/step_detection.cpp b/src/sensor/pedometer/step_detection.cpp index afabc84..ad977f2 100644 --- a/src/sensor/pedometer/step_detection.cpp +++ b/src/sensor/pedometer/step_detection.cpp @@ -189,6 +189,7 @@ bool step_detection::add_acc_sensor_values_savitzky( timestamp_t timestamp, double acc, step_event* step) { double acceleration = m_zc_filter.filter(acc - m_average_gfilter.filter(acc)); + double amplitude = 0; bool n_zero_up = m_zero_crossing_up.detect_step(timestamp, acceleration); bool n_zero_down = m_zero_crossing_down.detect_step(timestamp, acceleration); @@ -217,6 +218,7 @@ bool step_detection::add_acc_sensor_values_savitzky( bool zup = m_zero_crossing_up.m_time_sum / 1E9 > 1.2; if (n_zero_down) { is_step_detected = false; + amplitude = abs(m_maximum_acceleration - m_minimum_acceleration); if ((m_maximum_acceleration > 0.6 && m_minimum_acceleration < -0.852) @@ -251,11 +253,15 @@ bool step_detection::add_acc_sensor_values_savitzky( double time = (timestamp - m_last_step_timestamp) / 1E9; m_last_step_timestamp = timestamp; + if (time > 1.0 || amplitude < 3) { + is_step_detected = false; + } m_zero_crossing_up.m_time_sum = 0; - step->m_timestamp = timestamp; - step->m_step_length = cal_step_length(time, sqrt4peak_valley_diff); - - return true; + if (is_step_detected) { + step->m_timestamp = timestamp; + step->m_step_length = cal_step_length(time, sqrt4peak_valley_diff); + return true; + } } return false; -- 2.7.4 From f3d5bac2ce31553cecd88eb6aff0860241484584 Mon Sep 17 00:00:00 2001 From: "kibak.yoon" Date: Mon, 11 Sep 2017 21:37:20 +0900 Subject: [PATCH 16/16] sensord: fix coding rule violations Change-Id: I19591605e855fdbd1b44aae8fed8fe9ded23ee16 Signed-off-by: kibak.yoon --- src/sensor/gesture/face_down_alg_impl.h | 1 - src/sensor/pedometer/pedometer.h | 1 - src/sensor/rotation_vector/fusion_base.cpp | 1 - src/sensor/rotation_vector/fusion_utils/matrix.cpp | 8 +++----- src/sensor/rotation_vector/fusion_utils/vector.cpp | 8 +++----- src/sensorctl/loopback.cpp | 4 ++-- src/sensorctl/test_bench.cpp | 1 - src/sensorctl/testcase/unit_ipc.cpp | 6 +++--- 8 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/sensor/gesture/face_down_alg_impl.h b/src/sensor/gesture/face_down_alg_impl.h index 4afa3bb..997719d 100644 --- a/src/sensor/gesture/face_down_alg_impl.h +++ b/src/sensor/gesture/face_down_alg_impl.h @@ -38,7 +38,6 @@ private: void remove_old_up_time(void); unsigned long long is_facing_down(); unsigned long long was_facing_up(); - }; #endif /* __FACE_DOWN_ALG_IMPL_H__ */ diff --git a/src/sensor/pedometer/pedometer.h b/src/sensor/pedometer/pedometer.h index edf3638..f80c315 100644 --- a/src/sensor/pedometer/pedometer.h +++ b/src/sensor/pedometer/pedometer.h @@ -73,7 +73,6 @@ private: bool m_some_speed; sensor_frequency_compensator m_acceleration_compensator; - }; #endif /* __PEDOMETER_H__ */ diff --git a/src/sensor/rotation_vector/fusion_base.cpp b/src/sensor/rotation_vector/fusion_base.cpp index ad92d2a..fbd887d 100644 --- a/src/sensor/rotation_vector/fusion_base.cpp +++ b/src/sensor/rotation_vector/fusion_base.cpp @@ -80,7 +80,6 @@ void fusion_base::push_mag(sensor_data_t &data) m_enable_magnetic = true; if (get_orientation()) store_orientation(); - } bool fusion_base::get_rv(unsigned long long ×tamp, float &x, float &y, float &z, float &w) diff --git a/src/sensor/rotation_vector/fusion_utils/matrix.cpp b/src/sensor/rotation_vector/fusion_utils/matrix.cpp index 62f0555..2b1c177 100644 --- a/src/sensor/rotation_vector/fusion_utils/matrix.cpp +++ b/src/sensor/rotation_vector/fusion_utils/matrix.cpp @@ -156,17 +156,15 @@ T_R_C matrix operator /(const matrix m1, const T val) T_R1_C1_R2_C2 bool operator ==(const matrix m1, const matrix m2) { - if ((R1 == R2) && (C1 == C2)) - { + if ((R1 == R2) && (C1 == C2)) { for (int i = 0; i < R1; i++) for (int j = 0; j < C2; j++) if (m1.m_mat[i][j] != m2.m_mat[i][j]) return false; + return true; } - else - return false; - return true; + return false; } T_R1_C1_R2_C2 bool operator !=(const matrix m1, const matrix m2) diff --git a/src/sensor/rotation_vector/fusion_utils/vector.cpp b/src/sensor/rotation_vector/fusion_utils/vector.cpp index 432cb66..d06ad7d 100644 --- a/src/sensor/rotation_vector/fusion_utils/vector.cpp +++ b/src/sensor/rotation_vector/fusion_utils/vector.cpp @@ -155,16 +155,14 @@ T_S vect operator /(const vect v, const T val) T_S1_S2 bool operator ==(const vect v1, const vect v2) { - if (S1 == S2) - { + if (S1 == S2) { for (int i = 0; i < S1; i++) if (v1.m_vec[i] != v2.m_vec[i]) return false; + return true; } - else - return false; - return true; + return false; } T_S1_S2 bool operator !=(const vect v1, const vect v2) diff --git a/src/sensorctl/loopback.cpp b/src/sensorctl/loopback.cpp index ee177b8..b890f47 100644 --- a/src/sensorctl/loopback.cpp +++ b/src/sensorctl/loopback.cpp @@ -58,7 +58,7 @@ bool loopback_manager::run(int argc, char *argv[]) * sensorhub (bytes) command [0~1] delaytime [2~5] data[6~83] * shell (argv) command [0~2] delaytime [3] data[4~81] */ - char test_data[MAX_DATA_SIZE] = {SHUB_INST_LIB_ADD, SHUB_LOOP_BACK_LIB,}; + char test_data[MAX_DATA_SIZE] = {SHUB_INST_LIB_ADD, SHUB_LOOP_BACK_LIB, }; int_to_bytes(atoi(argv[3]), sizeof(int), &(test_data[2])); for (int i = 4; i < argc; i++) @@ -75,7 +75,7 @@ bool loopback_manager::run(int argc, char *argv[]) sensor = sensord_get_sensor(CONTEXT_SENSOR); handle = sensord_connect(sensor); - char test_data[4] = {SHUB_INST_LIB_REMOVE, SHUB_LOOP_BACK_LIB,}; + char test_data[4] = {SHUB_INST_LIB_REMOVE, SHUB_LOOP_BACK_LIB, }; sensord_set_attribute_str(handle, 0, test_data, sizeof(test_data)); sensord_disconnect(handle); diff --git a/src/sensorctl/test_bench.cpp b/src/sensorctl/test_bench.cpp index db0b974..8e5b5d8 100644 --- a/src/sensorctl/test_bench.cpp +++ b/src/sensorctl/test_bench.cpp @@ -237,7 +237,6 @@ void test_bench::show(void) for (auto it = testcases.begin(); it != testcases.end(); it = testcases.upper_bound(it->first)) { - auto range = testcases.equal_range(it->first); _I("[%s]\n", it->first.c_str()); diff --git a/src/sensorctl/testcase/unit_ipc.cpp b/src/sensorctl/testcase/unit_ipc.cpp index 799924a..c11d439 100644 --- a/src/sensorctl/testcase/unit_ipc.cpp +++ b/src/sensorctl/testcase/unit_ipc.cpp @@ -112,7 +112,7 @@ static bool run_ipc_client_sleep_1s(const char *str, int size, int count) message msg; message reply; - char buf[MAX_BUF_SIZE] = {'1', '1', '1',}; + char buf[MAX_BUF_SIZE] = {'1', '1', '1', }; msg.enclose(buf, MAX_BUF_SIZE); @@ -147,7 +147,7 @@ static bool run_ipc_client_small_buffer(const char *str, int size, int count) int ret; message msg; message reply; - char buf[MAX_BUF_SIZE] = {'1', '1', '1',}; + char buf[MAX_BUF_SIZE] = {'1', '1', '1', }; msg.enclose(buf, MAX_BUF_SIZE); @@ -190,7 +190,7 @@ static bool run_ipc_client_1M(const char *str, int size, int count) int ret; message msg; message reply; - char buf[MAX_BUF_SIZE] = {'1', '1', '1',}; + char buf[MAX_BUF_SIZE] = {'1', '1', '1', }; msg.enclose(buf, MAX_BUF_SIZE); -- 2.7.4