--- /dev/null
+/*
+ * storaged 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 requblocked 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_BLOCK_SHOWDEVICELIST "ShowDeviceList"
+#define METHOD_BLOCK_GETDEVICELIST "GetDeviceList"
+#define METHOD_BLOCK_GETDEVICELIST2 "GetDeviceList2"
+#define METHOD_BLOCK_MOUNT "Mount"
+#define METHOD_BLOCK_UNMOUNT "Unmount"
+#define METHOD_BLOCK_FORMAT "Format"
+#define METHOD_BLOCK_FORMATWITHTYPE "FormatwithType"
+#define METHOD_BLOCK_GETDEVICEINFO "GetDeviceInfo"
+#define METHOD_BLOCK_GETMMCPRIMARY "GetMmcPrimary"
+#define METHOD_BLOCK_PRIVATEMOUNT "PrivateMount"
+#define METHOD_BLOCK_PRIVATEUNMOUNT "PrivateUnmount"
+#define METHOD_BLOCK_CHECKSPEED "CheckSpeed"
+#define METHOD_BLOCK_CONTROL "Control"
+#define METHOD_BLOCK_GETCONTROL "GetControl"
+
+#define DBUS_DEFAULT_TIMEOUT (-1)
+
+static bool request_block_method(const char *method, GVariant *param, int timeout)
+{
+ GVariant *msg;
+ int val;
+ bool ret = FALSE;
+
+ msg = dbus_method_sync_with_reply_var_timeout(STORAGED_BUS_NAME,
+ STORAGED_PATH_BLOCK_MANAGER,
+ STORAGED_INTERFACE_BLOCK_MANAGER,
+ method, param, timeout);
+
+ 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 int get_id()
+{
+ GVariant *msg;
+ int val;
+ int ret = -1;
+
+ msg = dbus_method_sync_with_reply_var(STORAGED_BUS_NAME,
+ STORAGED_PATH_BLOCK_MANAGER,
+ STORAGED_INTERFACE_BLOCK_MANAGER,
+ METHOD_BLOCK_GETMMCPRIMARY,
+ NULL);
+
+ if (!msg) {
+ _E("fail (%s): no reply", METHOD_BLOCK_GETMMCPRIMARY);
+ return ret;
+ }
+
+ if (!dh_get_param_from_var(msg, "(issssssisibii)",
+ NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, &val))
+ _E("fail (%s): no message", METHOD_BLOCK_GETMMCPRIMARY);
+ else
+ ret = val;
+
+ _D("id: %d", ret);
+ g_variant_unref(msg);
+ return ret;
+}
+
+static bool block_showdevicelist()
+{
+ GVariant *msg;
+ int ret = FALSE;
+
+ _D("----------------------------------------------------------------------------------");
+
+ msg = dbus_method_sync_with_reply_var(STORAGED_BUS_NAME,
+ STORAGED_PATH_BLOCK_MANAGER,
+ STORAGED_INTERFACE_BLOCK_MANAGER,
+ METHOD_BLOCK_SHOWDEVICELIST,
+ NULL);
+
+ if (!msg) {
+ _E("fail (%s): no reply", METHOD_BLOCK_SHOWDEVICELIST);
+ return ret;
+ }
+
+ _I("success (%s)", METHOD_BLOCK_SHOWDEVICELIST);
+ g_variant_unref(msg);
+ return TRUE;
+}
+
+static bool block_getdevicelist(char *type)
+{
+ GVariant *msg;
+ GVariantIter *iter;
+ int val;
+ int ret = FALSE;
+
+ _D("----------------------------------------------------------------------------------");
+ msg = dbus_method_sync_with_reply_var(STORAGED_BUS_NAME,
+ STORAGED_PATH_BLOCK_MANAGER,
+ STORAGED_INTERFACE_BLOCK_MANAGER,
+ METHOD_BLOCK_GETDEVICELIST,
+ g_variant_new("(s)", type));
+
+ if (!msg) {
+ _E("fail (%s): no reply", METHOD_BLOCK_GETMMCPRIMARY);
+ return ret;
+ }
+
+ g_variant_get(msg, "(a(issssssisibii))", &iter);
+ while (g_variant_iter_loop(iter, "(issssssisibii)",
+ NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, &val)) {
+ _D("id: %d", val);
+ ret = TRUE;
+ }
+
+ _I("success (%s): %d", METHOD_BLOCK_GETDEVICELIST, ret);
+ return ret;
+}
+
+static bool block_getdevicelist2(char *type)
+{
+ GVariant *msg;
+ GVariantIter *iter;
+ char *val;
+ int ret = FALSE;
+
+ _D("----------------------------------------------------------------------------------");
+ msg = dbus_method_sync_with_reply_var(STORAGED_BUS_NAME,
+ STORAGED_PATH_BLOCK_MANAGER,
+ STORAGED_INTERFACE_BLOCK_MANAGER,
+ METHOD_BLOCK_GETDEVICELIST2,
+ g_variant_new("(s)", type));
+
+ if (!msg) {
+ _E("fail (%s): no reply", METHOD_BLOCK_GETMMCPRIMARY);
+ return ret;
+ }
+
+ g_variant_get(msg, "(a(issssssisibi))", &iter);
+ while (g_variant_iter_loop(iter, "(issssssisibi)",
+ NULL, &val, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL)) {
+ _D("devnode: %s", val);
+ ret = TRUE;
+ }
+
+ _I("success (%s): %d", METHOD_BLOCK_GETDEVICELIST2, ret);
+ return ret;
+}
+
+static bool block_mount(int id, char *mount_point)
+{
+ _D("----------------------------------------------------------------------------------");
+ return request_block_method(METHOD_BLOCK_MOUNT, g_variant_new("(is)", id, mount_point), DBUS_DEFAULT_TIMEOUT);
+}
+
+static bool block_unmount(int id, int option)
+{
+ _D("----------------------------------------------------------------------------------");
+ return request_block_method(METHOD_BLOCK_UNMOUNT, g_variant_new("(ii)", id, option), DBUS_DEFAULT_TIMEOUT);
+}
+
+static bool block_format(int id, int option)
+{
+ _D("----------------------------------------------------------------------------------");
+ return request_block_method(METHOD_BLOCK_FORMAT, g_variant_new("(ii)", id, option), G_MAXINT);
+}
+
+static bool block_formatwithtype(int id, int option, char *type)
+{
+ _D("----------------------------------------------------------------------------------");
+ return request_block_method(METHOD_BLOCK_FORMATWITHTYPE, g_variant_new("(iis)", id, option, type), G_MAXINT);
+}
+
+static bool block_getdeviceinfo(int id)
+{
+ GVariant *msg;
+ int val = -1;
+ int ret = FALSE;
+
+ _D("----------------------------------------------------------------------------------");
+ msg = dbus_method_sync_with_reply_var(STORAGED_BUS_NAME,
+ STORAGED_PATH_BLOCK_MANAGER,
+ STORAGED_INTERFACE_BLOCK_MANAGER,
+ METHOD_BLOCK_GETDEVICEINFO,
+ g_variant_new("(i)", id));
+
+ if (!msg) {
+ _E("fail (%s): no reply", METHOD_BLOCK_GETMMCPRIMARY);
+ return ret;
+ }
+
+ if (!dh_get_param_from_var(msg, "(issssssisibii)",
+ NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, &val))
+ _E("fail (%s): no message", METHOD_BLOCK_GETMMCPRIMARY);
+ else
+ ret = TRUE;
+
+ if (val != id) {
+ ret = FALSE;
+ _E("fail (%s)", METHOD_BLOCK_GETMMCPRIMARY);
+ }
+
+ _I("success (%s): %d", METHOD_BLOCK_GETDEVICEINFO, ret);
+ return ret;
+}
+
+static bool block_getmmcprimary()
+{
+ GVariant *msg;
+ int val = -1;
+ int ret = FALSE;
+
+ _D("----------------------------------------------------------------------------------");
+ msg = dbus_method_sync_with_reply_var(STORAGED_BUS_NAME,
+ STORAGED_PATH_BLOCK_MANAGER,
+ STORAGED_INTERFACE_BLOCK_MANAGER,
+ METHOD_BLOCK_GETMMCPRIMARY,
+ NULL);
+
+ if (!msg) {
+ _E("fail (%s): no reply", METHOD_BLOCK_GETMMCPRIMARY);
+ return ret;
+ }
+
+ if (!dh_get_param_from_var(msg, "(issssssisibii)",
+ NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL, &val))
+ _E("fail (%s): no message", METHOD_BLOCK_GETMMCPRIMARY);
+ else
+ ret = TRUE;
+
+ _D("id: %d", val);
+ _I("success (%s): %d", METHOD_BLOCK_GETMMCPRIMARY, ret);
+ return ret;
+}
+
+static bool block_privatemount(int id, char *mount_point)
+{
+ _D("----------------------------------------------------------------------------------");
+ return request_block_method(METHOD_BLOCK_PRIVATEMOUNT, g_variant_new("(is)", id, mount_point), DBUS_DEFAULT_TIMEOUT);
+}
+
+static bool block_privateunmount(int id, int option)
+{
+ _D("----------------------------------------------------------------------------------");
+ return request_block_method(METHOD_BLOCK_PRIVATEUNMOUNT, g_variant_new("(ii)", id, option), DBUS_DEFAULT_TIMEOUT);
+}
+
+static bool block_checkspeed(int id)
+{
+ _D("----------------------------------------------------------------------------------");
+ return request_block_method(METHOD_BLOCK_CHECKSPEED, g_variant_new("(i)", id), G_MAXINT);
+}
+
+static bool block_control(int enable)
+{
+ _D("----------------------------------------------------------------------------------");
+ return request_block_method(METHOD_BLOCK_CONTROL, g_variant_new("(i)", enable), DBUS_DEFAULT_TIMEOUT);
+}
+
+static bool block_getcontrol()
+{
+ _D("----------------------------------------------------------------------------------");
+ return request_block_method(METHOD_BLOCK_GETCONTROL, NULL, DBUS_DEFAULT_TIMEOUT);
+}
+
+void block_test_all(int *success, int *fail)
+{
+ int s = 0;
+ int f = 0;
+ int id = 0;
+
+ id = get_id();
+
+ _D("------------------- Precondition start --------------------");
+ block_unmount(id, 1);
+ _D("------------------- Precondition end ----------------------");
+ (block_checkspeed(id)) ? s++ : f++;
+ (block_format(id, 1)) ? s++ : f++;
+ (block_formatwithtype(id, 1, "vfat")) ? s++ : f++;
+ (block_showdevicelist()) ? s++ : f++;
+ (block_getdevicelist("all")) ? s++ : f++;
+ (block_getdevicelist2("all")) ? s++ : f++;
+ (block_mount(id, "")) ? s++ : f++;
+ (block_unmount(id, 1)) ? s++ : f++;
+ (block_getdeviceinfo(id)) ? s++ : f++;
+ (block_getmmcprimary()) ? s++ : f++;
+ (block_privatemount(id, "")) ? s++ : f++;
+ (block_privateunmount(id, 1)) ? s++ : f++;
+ block_mount(id, "");
+ (block_control(0)) ? s++ : f++;
+ request_block_method(METHOD_BLOCK_CONTROL, g_variant_new("(i)", 1), DBUS_DEFAULT_TIMEOUT);
+ (block_getcontrol()) ? s++ : f++;
+ _D("----------------------------------------------------------------------------------");
+
+ if (NULL != success) *success = s;
+ if (NULL != fail) *fail = f;
+}
+
+static void block_init(void *data)
+{
+ int success = 0;
+ int fail = 0;
+
+ _I("start test");
+
+ block_test_all(&success, &fail);
+
+ _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
+}
+
+static void block_exit(void *data)
+{
+ _I("end test");
+}
+
+static int block_unit(int argc, char **argv)
+{
+ int id = 0;
+
+ id = get_id();
+
+ if (argc < 3) {
+ int success = 0;
+ int fail = 0;
+
+ _I("start test");
+ block_test_all(&success, &fail);
+ _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
+ } else if (0 == strcasecmp(argv[2], METHOD_BLOCK_SHOWDEVICELIST)) {
+ block_showdevicelist();
+ } else if (0 == strcasecmp(argv[2], METHOD_BLOCK_GETDEVICELIST)) {
+ block_getdevicelist(argv[3]);
+ } else if (0 == strcasecmp(argv[2], METHOD_BLOCK_GETDEVICELIST2)) {
+ block_getdevicelist2(argv[3]);
+ } else if (0 == strcasecmp(argv[2], METHOD_BLOCK_MOUNT)) {
+ block_mount(id, argv[3]);
+ } else if (0 == strcasecmp(argv[2], METHOD_BLOCK_UNMOUNT)) {
+ block_unmount(id, atoi(argv[3]));
+ } else if (0 == strcasecmp(argv[2], METHOD_BLOCK_FORMAT)) {
+ block_format(id, atoi(argv[3]));
+ } else if (0 == strcasecmp(argv[2], METHOD_BLOCK_FORMATWITHTYPE)) {
+ block_formatwithtype(id, atoi(argv[3]), argv[4]);
+ } else if (0 == strcasecmp(argv[2], METHOD_BLOCK_GETDEVICEINFO)) {
+ block_getdeviceinfo(id);
+ } else if (0 == strcasecmp(argv[2], METHOD_BLOCK_GETMMCPRIMARY)) {
+ block_getmmcprimary();
+ } else if (0 == strcasecmp(argv[2], METHOD_BLOCK_PRIVATEMOUNT)) {
+ _D("------------------- Private operation test precondition start --------------------");
+ block_unmount(id, 1);
+ _D("------------------- Private operation test precondition end--------------------");
+ block_privatemount(id, argv[3]);
+ } else if (0 == strcasecmp(argv[2], METHOD_BLOCK_PRIVATEUNMOUNT)) {
+ _D("------------------- Private operation test precondition start --------------------");
+ block_unmount(id, 1);
+ block_privatemount(id, "");
+ _D("------------------- Private operation test precondition end--------------------");
+ block_privateunmount(id, atoi(argv[3]));
+ } else if (0 == strcasecmp(argv[2], METHOD_BLOCK_CHECKSPEED)) {
+ block_checkspeed(id);
+ } else if (0 == strcasecmp(argv[2], METHOD_BLOCK_CONTROL)) {
+ block_control(atoi(argv[3]));
+ request_block_method(METHOD_BLOCK_CONTROL, g_variant_new("(i)", 1), DBUS_DEFAULT_TIMEOUT);
+ } else if (0 == strcasecmp(argv[2], METHOD_BLOCK_GETCONTROL)) {
+ block_getcontrol();
+ } else {
+ _E("Unknown test case!!!");
+ }
+ _D("----------------------------------------------------------------------------------");
+
+ return 0;
+}
+
+static const struct test_ops block_test_ops = {
+ .priority = TEST_PRIORITY_NORMAL,
+ .name = "block",
+ .init = block_init,
+ .exit = block_exit,
+ .unit = block_unit,
+};
+
+TEST_OPS_REGISTER(&block_test_ops)
--- /dev/null
+/*
+ * storaged 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 requstorageed 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_STORAGE_GETSTORAGE "getstorage"
+#define METHOD_STORAGE_GETSTATUS "GetStatus"
+
+static bool request_storage_method(const char *method, GVariant *param)
+{
+ GVariant *msg;
+ unsigned long long val1, val2;
+ bool ret = FALSE;
+
+ msg = dbus_method_sync_with_reply_var(STORAGED_BUS_NAME,
+ STORAGED_PATH_STORAGE,
+ STORAGED_INTERFACE_STORAGE,
+ method, param);
+
+ if (!msg) {
+ _E("fail (%s): no reply", method);
+ return ret;
+ }
+
+ if (!dh_get_param_from_var(msg, "(tt)", &val1, &val2))
+ _E("fail (%s): no message", method);
+ else {
+ if (val1 <= 0) {
+ _E("fail (%s): returned total storage (%d)", method, val1);
+ } else {
+ _I("success (%s): Total: %4.0llu Avail: %4.0llu", method, val1, val2);
+ ret = TRUE;
+ }
+ }
+
+ g_variant_unref(msg);
+ return ret;
+}
+
+static bool storage_getstorage()
+{
+ _D("----------------------------------------------------------------------------------");
+ return request_storage_method(METHOD_STORAGE_GETSTORAGE, NULL);
+}
+
+static bool storage_getstatus(char *path)
+{
+ _D("----------------------------------------------------------------------------------");
+ return request_storage_method(METHOD_STORAGE_GETSTATUS, g_variant_new("(s)", path));
+}
+
+void storage_test_all(int *success, int *fail)
+{
+ int s = 0;
+ int f = 0;
+
+ (storage_getstorage()) ? s++ : f++;
+ (storage_getstatus("/opt/usr/home")) ? s++ : f++;
+ _D("----------------------------------------------------------------------------------");
+
+ if (NULL != success) *success = s;
+ if (NULL != fail) *fail = f;
+}
+
+static void storage_init(void *data)
+{
+ int success = 0;
+ int fail = 0;
+
+ _I("start test");
+
+ storage_test_all(&success, &fail);
+
+ _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
+}
+
+static void storage_exit(void *data)
+{
+ _I("end test");
+}
+
+static int storage_unit(int argc, char **argv)
+{
+ if (argc < 3) {
+ int success = 0;
+ int fail = 0;
+
+ _I("start test");
+ storage_test_all(&success, &fail);
+ _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail);
+ } else if (0 == strcasecmp(argv[2], METHOD_STORAGE_GETSTORAGE)) {
+ storage_getstorage();
+ } else if (0 == strcasecmp(argv[2], METHOD_STORAGE_GETSTATUS)) {
+ storage_getstatus(argv[3]);
+ } else {
+ _E("Unknown test case!!!");
+ }
+ _D("----------------------------------------------------------------------------------");
+
+ return 0;
+}
+
+static const struct test_ops storage_test_ops = {
+ .priority = TEST_PRIORITY_NORMAL,
+ .name = "storage",
+ .init = storage_init,
+ .exit = storage_exit,
+ .unit = storage_unit,
+};
+
+TEST_OPS_REGISTER(&storage_test_ops)