--- /dev/null
+/*
+ * feedbackd auto-test
+ *
+ * Copyright (c) 2018 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 requhapticed 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 "test.h"
+
+#define METHOD_HAPTIC_GETCOUNT "GetCount"
+#define METHOD_HAPTIC_OPENDEVICE "OpenDevice"
+#define METHOD_HAPTIC_CLOSEDEVICE "CloseDevice"
+#define METHOD_HAPTIC_STOPDEVICE "StopDevice"
+#define METHOD_HAPTIC_VIBRATEMONOTONE "VibrateMonotone"
+#define METHOD_HAPTIC_VIBRATEEFFECT "VibrateEffect"
+#define METHOD_HAPTIC_GETSTATE "GetState"
+#define METHOD_HAPTIC_SHOWHANDLELIST "ShowHandleList"
+#define METHOD_HAPTIC_ISSUPPORTED "IsSupported"
+
+static bool request_haptic_method(const char *method, GVariant *param)
+{
+ GVariant *msg;
+ int val;
+ bool ret = FALSE;
+
+ msg = dbus_method_sync_with_reply_var(VIBRATOR_BUS_NAME,
+ VIBRATOR_PATH_HAPTIC,
+ VIBRATOR_INTERFACE_HAPTIC,
+ method, param);
+
+ if (!msg) {
+ _E("fail (%s): no reply", method);
+ return ret;
+ }
+
+ if (!dh_get_param_from_var(msg, "(i)", &val))
+ _E("fail (%s): no message", method);
+ else {
+ if ((val == -ENOTSUP) || (val == -ENOSYS)) {
+ _I("Not supported feature! (%s): %d", method, val);
+ ret = TRUE;
+ } else if (val == -ENODEV) {
+ _E("fail (%s): device open fail (%d)", method, val);
+ } else if (val < 0) {
+ _E("fail (%s): returned fail (%d)", method, val);
+ } else {
+ _I("success (%s): %d", method, val);
+ ret = TRUE;
+ }
+ }
+
+ g_variant_unref(msg);
+ return ret;
+}
+
+static bool haptic_getcount()
+{
+ _D("----------------------------------------------------------------------------------");
+ return request_haptic_method(METHOD_HAPTIC_GETCOUNT, NULL);
+}
+
+static bool haptic_opendevice(int index)
+{
+ _D("----------------------------------------------------------------------------------");
+ return request_haptic_method(METHOD_HAPTIC_OPENDEVICE, g_variant_new("(i)", index));
+}
+
+static bool haptic_closedevice()
+{
+ GVariant *msg;
+ int handle;
+ bool ret = FALSE;
+
+ _D("----------------------------------------------------------------------------------");
+ msg = dbus_method_sync_with_reply_var(VIBRATOR_BUS_NAME,
+ VIBRATOR_PATH_HAPTIC,
+ VIBRATOR_INTERFACE_HAPTIC,
+ METHOD_HAPTIC_OPENDEVICE,
+ g_variant_new("(i)", 0));
+
+ if (!msg) {
+ _E("fail (%s): no reply", METHOD_HAPTIC_OPENDEVICE);
+ return ret;
+ }
+
+ if (!dh_get_param_from_var(msg, "(i)", &handle)) {
+ _E("fail (%s): no message", METHOD_HAPTIC_OPENDEVICE);
+ return ret;
+ }
+ g_variant_unref(msg);
+
+ return request_haptic_method(METHOD_HAPTIC_CLOSEDEVICE, g_variant_new("(u)", handle));
+}
+
+static bool haptic_vibratemonotone(int duration, int level, int priority)
+{
+ GVariant *msg;
+ int handle;
+ bool ret = FALSE;
+
+ _D("----------------------------------------------------------------------------------");
+ msg = dbus_method_sync_with_reply_var(VIBRATOR_BUS_NAME,
+ VIBRATOR_PATH_HAPTIC,
+ VIBRATOR_INTERFACE_HAPTIC,
+ METHOD_HAPTIC_OPENDEVICE,
+ g_variant_new("(i)", 0));
+
+ if (!msg) {
+ _E("fail (%s): no reply", METHOD_HAPTIC_OPENDEVICE);
+ return ret;
+ }
+
+ if (!dh_get_param_from_var(msg, "(i)", &handle)) {
+ _E("fail (%s): no message", METHOD_HAPTIC_OPENDEVICE);
+ return ret;
+ }
+ g_variant_unref(msg);
+
+ return request_haptic_method(METHOD_HAPTIC_VIBRATEMONOTONE, g_variant_new("(uiii)", handle, duration, level, priority));
+}
+
+static bool haptic_vibrateeffect(char *pattern, int level, int priority)
+{
+ GVariant *msg;
+ int handle;
+ bool ret = FALSE;
+
+ _D("----------------------------------------------------------------------------------");
+ msg = dbus_method_sync_with_reply_var(VIBRATOR_BUS_NAME,
+ VIBRATOR_PATH_HAPTIC,
+ VIBRATOR_INTERFACE_HAPTIC,
+ METHOD_HAPTIC_OPENDEVICE,
+ g_variant_new("(i)", 0));
+
+ if (!msg) {
+ _E("fail (%s): no reply", METHOD_HAPTIC_OPENDEVICE);
+ return ret;
+ }
+
+ if (!dh_get_param_from_var(msg, "(i)", &handle)) {
+ _E("fail (%s): no message", METHOD_HAPTIC_OPENDEVICE);
+ return ret;
+ }
+ g_variant_unref(msg);
+
+ return request_haptic_method(METHOD_HAPTIC_VIBRATEEFFECT, g_variant_new("(usii)", handle, pattern, level, priority));
+}
+
+static bool haptic_stopdevice()
+{
+ struct timespec time = {0,};
+ GVariant *msg;
+ int handle;
+ bool ret = FALSE;
+
+ _D("----------------------------------------------------------------------------------");
+ msg = dbus_method_sync_with_reply_var(VIBRATOR_BUS_NAME,
+ VIBRATOR_PATH_HAPTIC,
+ VIBRATOR_INTERFACE_HAPTIC,
+ METHOD_HAPTIC_OPENDEVICE,
+ g_variant_new("(i)", 0));
+
+ if (!msg) {
+ _E("fail (%s): no reply", METHOD_HAPTIC_OPENDEVICE);
+ return ret;
+ }
+
+ if (!dh_get_param_from_var(msg, "(i)", &handle)) {
+ _E("fail (%s): no message", METHOD_HAPTIC_OPENDEVICE);
+ return ret;
+ }
+ g_variant_unref(msg);
+
+ msg = dbus_method_sync_with_reply_var(VIBRATOR_BUS_NAME,
+ VIBRATOR_PATH_HAPTIC,
+ VIBRATOR_INTERFACE_HAPTIC,
+ METHOD_HAPTIC_VIBRATEMONOTONE,
+ g_variant_new("(uiii)", handle, 1000, 100, 0));
+
+ if (!msg) {
+ _E("fail (%s): no reply", METHOD_HAPTIC_VIBRATEMONOTONE);
+ return ret;
+ }
+
+ _D("sleep 300ms");
+ time.tv_nsec = 300 * NANO_SECOND_MULTIPLIER;
+ nanosleep(&time, NULL);
+ _D("wakeup");
+
+ return request_haptic_method(METHOD_HAPTIC_STOPDEVICE, g_variant_new("(u)", handle));
+}
+
+static bool haptic_getstate(int index)
+{
+ _D("----------------------------------------------------------------------------------");
+ return request_haptic_method(METHOD_HAPTIC_GETSTATE, g_variant_new("(i)", index));
+}
+
+static bool haptic_showhandlelist()
+{
+ GVariant *msg;
+
+ _D("----------------------------------------------------------------------------------");
+ msg = dbus_method_sync_with_reply_var(VIBRATOR_BUS_NAME,
+ VIBRATOR_PATH_HAPTIC,
+ VIBRATOR_INTERFACE_HAPTIC,
+ METHOD_HAPTIC_SHOWHANDLELIST,
+ NULL);
+
+ if (!msg) {
+ _E("fail (%s): no reply", METHOD_HAPTIC_OPENDEVICE);
+ return FALSE;
+ }
+ g_variant_unref(msg);
+ return TRUE;
+}
+
+static bool haptic_issupported(char *pattern)
+{
+ _D("----------------------------------------------------------------------------------");
+ return request_haptic_method(METHOD_HAPTIC_ISSUPPORTED, g_variant_new("(s)", pattern));
+}
+
+void haptic_test_all(int *success, int *fail)
+{
+ struct timespec time = {0,};
+ int s = 0;
+ int f = 0;
+
+ time.tv_sec = 1;
+
+ (haptic_getcount()) ? s++ : f++;
+ (haptic_opendevice(0)) ? s++ : f++;
+ (haptic_closedevice()) ? s++ : f++;
+ (haptic_stopdevice()) ? s++ : f++;
+ nanosleep(&time, NULL);
+ (haptic_vibratemonotone(300, 100, 0)) ? s++ : f++;
+ nanosleep(&time, NULL);
+ (haptic_vibrateeffect("FEEDBACK_PATTERN_SIP", 100, 0)) ? s++ : f++;
+ nanosleep(&time, NULL);
+ (haptic_getstate(0)) ? s++ : f++;
+ (haptic_showhandlelist()) ? s++ : f++;
+ (haptic_issupported("FEEDBACK_PATTERN_SIP")) ? s++ : f++;
+
+
+ if (NULL != success) *success = s;
+ if (NULL != fail) *fail = f;
+}
+
+static void haptic_init(void *data)
+{
+ int success = 0;
+ int fail = 0;
+
+ _I("start test");
+
+ haptic_test_all(&success, &fail);
+
+ _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
+}
+
+static void haptic_exit(void *data)
+{
+ _I("end test");
+}
+
+static int haptic_unit(int argc, char **argv)
+{
+ struct timespec time = {0,};
+
+ if (argc < 2) {
+ int success = 0;
+ int fail = 0;
+
+ _I("start test");
+ haptic_test_all(&success, &fail);
+ _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
+ } else if (0 == strcasecmp(argv[1], METHOD_HAPTIC_GETCOUNT)) {
+ haptic_getcount();
+ } else if (0 == strcasecmp(argv[1], METHOD_HAPTIC_OPENDEVICE)) {
+ haptic_opendevice(atoi(argv[2]));
+ } else if (0 == strcasecmp(argv[1], METHOD_HAPTIC_CLOSEDEVICE)) {
+ haptic_closedevice();
+ } else if (0 == strcasecmp(argv[1], METHOD_HAPTIC_STOPDEVICE)) {
+ time.tv_sec = 1;
+ haptic_stopdevice();
+ nanosleep(&time, NULL);
+ } else if (0 == strcasecmp(argv[1], METHOD_HAPTIC_VIBRATEMONOTONE)) {
+ haptic_vibratemonotone(atoi(argv[2]), atoi(argv[3]), atoi(argv[4]));
+ time.tv_sec = 1 + (atoi(argv[2]) / 1000);
+ nanosleep(&time, NULL);
+ } else if (0 == strcasecmp(argv[1], METHOD_HAPTIC_VIBRATEEFFECT)) {
+ haptic_vibrateeffect(argv[2], atoi(argv[3]), atoi(argv[4]));
+ time.tv_sec = 2;
+ nanosleep(&time, NULL);
+ } else if (0 == strcasecmp(argv[1], METHOD_HAPTIC_GETSTATE)) {
+ haptic_getstate(atoi(argv[2]));
+ } else if (0 == strcasecmp(argv[1], METHOD_HAPTIC_SHOWHANDLELIST)) {
+ haptic_showhandlelist();
+ } else if (0 == strcasecmp(argv[1], METHOD_HAPTIC_ISSUPPORTED)) {
+ haptic_issupported(argv[2]);
+ } else {
+ _E("Unknown test case!!!");
+ }
+
+ return 0;
+}
+
+static const struct test_ops haptic_test_ops = {
+ .priority = TEST_PRIORITY_NORMAL,
+ .name = "haptic",
+ .init = haptic_init,
+ .exit = haptic_exit,
+ .unit = haptic_unit,
+};
+
+TEST_OPS_REGISTER(&haptic_test_ops)
--- /dev/null
+/*
+ * feedbackd auto-test
+ *
+ * Copyright (c) 2018 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 "test.h"
+
+static void test_main(int argc, char **argv)
+{
+ _I("auto test all");
+ test_init((void *)NULL);
+ test_exit((void *)NULL);
+}
+
+static void unit_test(int argc, char **argv)
+{
+ const struct test_ops *ops;
+
+ ops = find_test("haptic");
+ if (!ops) {
+ _E("there is no test ops : haptic");
+ return;
+ }
+ ops->unit(argc, argv);
+}
+
+void show_usage()
+{
+ printf("Usage: deviced-auto-test [UNIT-METHOD] [OPTS]\n\n");
+ printf("Optional arguments\nIf you don't give any optional arguments, all supported modules will be tested.\n");
+ printf("All module list is as below.\nAs per profile, supported modules are different.\n");
+ printf("[UNIT-METHOD] [OPTS]\n");
+ printf("GetCount 0\n");
+ printf("OpenDevice 0\n");
+ printf("CloseDevice 0\n");
+ printf("StopDevice 0\n");
+ printf("VibrateMonotone duration, level, priority\n");
+ printf("VibrateEffect pattern string, level, priority\n");
+ printf("GetState 0\n");
+ printf("ShowHandleList 0\n");
+ printf("IsSupported pattern string\n");
+}
+
+int main(int argc, char **argv)
+{
+ if (argc == 2) {
+ if (!strncmp(argv[1], "help", strlen("help") + 1)) {
+ show_usage();
+ return 0;
+ }
+ }
+
+ if (argc >= 2)
+ unit_test(argc, argv);
+ else
+ test_main(argc, argv);
+
+
+ return 0;
+}
+