auto-test: Add auto-test for storaged 67/170667/7
authorpr.jung <pr.jung@samsung.com>
Tue, 20 Feb 2018 05:50:02 +0000 (14:50 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Mon, 26 Feb 2018 11:26:30 +0000 (11:26 +0000)
Change-Id: I272e1c869628569663da76aa377892a58a5042ba
Signed-off-by: pr.jung <pr.jung@samsung.com>
Signed-off-by: Hyotaek Shim <hyotaek.shim@samsung.com>
13 files changed:
CMakeLists.txt
packaging/storaged.spec
scripts/storaged.conf
src/auto-test/CMakeLists.txt [new file with mode: 0644]
src/auto-test/block.c [new file with mode: 0755]
src/auto-test/main.c [new file with mode: 0644]
src/auto-test/result.c [new file with mode: 0644]
src/auto-test/storage.c [new file with mode: 0755]
src/auto-test/test.c [new file with mode: 0644]
src/auto-test/test.h [new file with mode: 0644]
src/block/utils.h
src/shared/dbus.c
src/shared/dbus.h

index 8b3f953..cd7094b 100755 (executable)
@@ -58,3 +58,5 @@ ENDIF()
 IF(STORAGE_MODULE STREQUAL on)
        ADD_SUBDIRECTORY(src/storage)
 ENDIF()
+
+ADD_SUBDIRECTORY(src/auto-test)
index c7e3d0c..1b2122c 100644 (file)
@@ -66,6 +66,13 @@ Requires: %{name} = %{version}-%{release}
 %description org.tizen.extended-sd
 App to setup sdcard
 
+%package auto-test
+Summary:  Storaged auto test tool
+Group:    System/Utilities
+%description auto-test
+Storaged helper programs.
+This package can be installed optional for auto dbus test.
+
 %prep
 %setup -q
 %if %{with emulator}
@@ -151,3 +158,8 @@ systemctl daemon-reload
 %{TZ_SYS_RO_APP}/org.tizen.extended-sd/res/*
 %{TZ_SYS_RO_PACKAGES}/org.tizen.extended-sd.xml
 %{TZ_SYS_RO_APP}/org.tizen.extended-sd/res/edje/extended-sd.edj
+
+%files auto-test
+%license LICENSE.Apache-2.0
+%manifest %{name}.manifest
+%{_bindir}/storaged-auto-test
index b6f7967..ecd3199 100644 (file)
@@ -1,9 +1,17 @@
 <!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
  "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
 <busconfig>
+    <policy user="root">
+        <allow own="org.tizen.system.storage"/>
+        <allow send_destination="org.tizen.system.storage"/>
+    </policy>
+
     <policy context="default">
-        <deny send_destination="org.tizen.system.storage"/>
-        <allow send_destination="org.tizen.system.storage" send_type="signal"/>
+        <allow send_destination="org.tizen.system.storage"/>
+
+        <deny send_destination="org.tizen.system.storage"
+                send_interface="org.tizen.system.storage.storage"/>
+
         <check send_destination="org.tizen.system.storage"
                 send_interface="org.tizen.system.storage.storage"
                 privilege="http://tizen.org/privilege/externalstorage"/>
diff --git a/src/auto-test/CMakeLists.txt b/src/auto-test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e61607b
--- /dev/null
@@ -0,0 +1,37 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(storaged-auto-test C)
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src)
+
+SET(SRCS
+       test.c
+       main.c
+       result.c
+       ../shared/dbus.c
+       block.c
+       storage.c
+)
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/shared)
+
+SET(PKG_MODULES
+       dlog
+       glib-2.0
+)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED ${PKG_MODULES})
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Werror")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -lrt -fPIE")
+SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")
+
+ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} "-ldl" "-lm")
+
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
diff --git a/src/auto-test/block.c b/src/auto-test/block.c
new file mode 100755 (executable)
index 0000000..bc2a7b2
--- /dev/null
@@ -0,0 +1,420 @@
+/*
+ * 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)
diff --git a/src/auto-test/main.c b/src/auto-test/main.c
new file mode 100644 (file)
index 0000000..055a556
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * 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 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(argv[1]);
+       if (!ops) {
+               _E("there is no test ops : %s", argv[1]);
+               return;
+       }
+       ops->unit(argc, argv);
+}
+
+void show_usage()
+{
+       printf("Usage: storaged-auto-test [MODULE] [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("[MODULE]        [UNIT-METHOD]           [OPTS]\n");
+       printf("block           ShowDeviceList          N/A\n");
+       printf("block           GetDeviceList           scsi/mmc/all\n");
+       printf("block           GetDeviceList2          scsi/mmc/all\n");
+       printf("block           Mount                   mount path\n");
+       printf("block           Unmount                 option: 0(normal)/1(force)\n");
+       printf("block           Format                  option: 0(normal)/1(force)\n");
+       printf("block           FormatwithType          filesystem: vfat/ext4, option: 0/1\n");
+       printf("block           GetDeviceInfo           N/A\n");
+       printf("block           GetMmcPrimary           N/A\n");
+       printf("block           PrivateMount            mount path\n");
+       printf("block           PrivateUnmount          option: 0(normal)/1(force)\n");
+       printf("block           CheckSpeed              N/A\n");
+       printf("block           Control                 option: 0(disable)/1(enable)\n");
+       printf("block           GetControl              N/A\n");
+       printf("storage         getstorage              N/A\n");
+       printf("storage         GetStatus               path\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;
+}
+
diff --git a/src/auto-test/result.c b/src/auto-test/result.c
new file mode 100644 (file)
index 0000000..83bad1a
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * 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 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 <stdio.h>
+
+#include "shared/log.h"
+
+#define BUF_MAX 256
+
+void _R(const char *format, ...)
+{
+       va_list args;
+       char buf[BUF_MAX];
+
+       va_start(args, format);
+       vsnprintf(buf, BUF_MAX, format, args);
+       va_end(args);
+
+       _D("%s", buf);
+}
diff --git a/src/auto-test/storage.c b/src/auto-test/storage.c
new file mode 100755 (executable)
index 0000000..e800027
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ * 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)
diff --git a/src/auto-test/test.c b/src/auto-test/test.c
new file mode 100644 (file)
index 0000000..d59cf6f
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * 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 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 dd_list *dd_head;
+
+void add_test(const struct test_ops *d)
+{
+       if (d->priority == TEST_PRIORITY_HIGH)
+               DD_LIST_PREPEND(dd_head, d);
+       else
+               DD_LIST_APPEND(dd_head, d);
+}
+
+void remove_test(const struct test_ops *d)
+{
+       DD_LIST_REMOVE(dd_head, d);
+}
+
+const struct test_ops *find_test(const char *name)
+{
+       dd_list *elem;
+       const struct test_ops *d;
+
+       DD_LIST_FOREACH(dd_head, elem, d) {
+               if (!strcasecmp(d->name, name))
+                       return d;
+       }
+       return NULL;
+}
+
+void test_init(void *data)
+{
+       dd_list *elem;
+       const struct test_ops *d;
+
+       _D("test module count(%d)", DD_LIST_LENGTH(dd_head));
+       DD_LIST_FOREACH(dd_head, elem, d) {
+               _D("[%s] initialize", d->name);
+               if (d->init)
+                       d->init(data);
+       }
+}
+
+void test_exit(void *data)
+{
+       dd_list *elem;
+       const struct test_ops *d;
+
+       DD_LIST_FOREACH(dd_head, elem, d) {
+               _D("[%s] deinitialize", d->name);
+               if (d->exit)
+                       d->exit(data);
+       }
+}
diff --git a/src/auto-test/test.h b/src/auto-test/test.h
new file mode 100644 (file)
index 0000000..3d04127
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * 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 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 __TEST_H__
+#define __TEST_H__
+#include <stdio.h>
+#include <errno.h>
+
+#include "list.h"
+#include "log.h"
+#include "dbus.h"
+#include "storaged_common.h"
+
+#ifdef ENABLE_TEST_DLOG
+#define ENABLE_DLOG
+#endif
+
+enum test_priority {
+       TEST_PRIORITY_NORMAL = 0,
+       TEST_PRIORITY_HIGH,
+};
+
+struct test_ops {
+       enum test_priority priority;
+       char *name;
+       void (*init) (void *data);
+       void (*exit) (void *data);
+       int (*start) (void);
+       int (*stop) (void);
+       int (*status) (void);
+       int (*unit) (int argc, char **argv);
+};
+
+enum test_ops_status {
+       TEST_OPS_STATUS_UNINIT,
+       TEST_OPS_STATUS_START,
+       TEST_OPS_STATUS_STOP,
+       TEST_OPS_STATUS_MAX,
+};
+
+void test_init(void *data);
+void test_exit(void *data);
+
+static inline int test_start(const struct test_ops *c)
+{
+       if (c && c->start)
+               return c->start();
+
+       return -EINVAL;
+}
+
+static inline int test_stop(const struct test_ops *c)
+{
+       if (c && c->stop)
+               return c->stop();
+
+       return -EINVAL;
+}
+
+static inline int test_get_status(const struct test_ops *c)
+{
+       if (c && c->status)
+               return c->status();
+
+       return -EINVAL;
+}
+
+#define TEST_OPS_REGISTER(c)   \
+static void __CONSTRUCTOR__ module_init(void)  \
+{      \
+       add_test(c);    \
+}      \
+static void __DESTRUCTOR__ module_exit(void)   \
+{      \
+       remove_test(c); \
+}
+void add_test(const struct test_ops *c);
+void remove_test(const struct test_ops *c);
+const struct test_ops *find_test(const char *name);
+void _R(const char *format, ...);
+#endif
index 8bf2a9b..23d058a 100644 (file)
@@ -21,7 +21,7 @@
 
 #include <stdbool.h>
 #include "log.h"
-#include "common.h"
+#include "storaged_common.h"
 
 int print_open_files(const char *mount_point);
 int terminate_process(const char *partition, bool force);
index 2778d25..bf7c396 100644 (file)
@@ -22,7 +22,7 @@
 #include <stdint.h>
 #include <errno.h>
 
-#include "common.h"
+#include "storaged_common.h"
 #include "log.h"
 #include "dbus.h"
 
@@ -1684,6 +1684,44 @@ GVariant *dbus_method_sync_with_reply_var(const char *dest, const char *path,
        return ret;
 }
 
+GVariant *dbus_method_sync_with_reply_var_timeout(const char *dest, const char *path,
+       const char *iface, const char *method, GVariant *var, int timeout)
+{
+       GError *err = NULL;
+       GVariant * ret = NULL;
+       dbus_handle_s *dh = NULL;
+
+       if (!dest || !path || !iface || !method) {
+               _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method);
+               if (var)
+                       g_variant_unref(var);
+               return NULL;
+       }
+
+       dh = _dbus_handle_get_default_connection();
+       if (!dh) {
+               _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type());
+               if (var)
+                       g_variant_unref(var);
+               return NULL;
+       }
+
+       ret = g_dbus_connection_call_sync(dh->conn,
+                                                                               dest, path, iface, method,
+                                                                               var, NULL, G_DBUS_CALL_FLAGS_NONE, timeout, NULL, &err);
+       if (!ret || err) {
+               if (err) {
+                       _E("failed to g_dbus_connection_call_sync:%s", err->message);
+                       g_error_free(err);
+               } else {
+                       _E("failed to g_dbus_connection_call_sync");
+               }
+               return NULL;
+       }
+
+       return ret;
+}
+
 gint* dbus_handle_get_unix_fd_list(GDBusMethodInvocation *invocation, int *size)
 {
        GUnixFDList *fd_list = NULL;
index 7225546..d70ef19 100644 (file)
@@ -49,6 +49,8 @@ GVariant *dbus_method_sync_with_reply(const char *dest, const char *path,
 
 GVariant *dbus_method_sync_with_reply_var(const char *dest, const char *path, const char *iface, const char *method, GVariant *var);
 
+GVariant *dbus_method_sync_with_reply_var_timeout(const char *dest, const char *path, const char *iface, const char *method, GVariant *var, int timeout);
+
 /* fd */
 gint* dbus_handle_get_unix_fd_list(GDBusMethodInvocation *invocation, int *size);