Add --output option 43/212043/12
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 25 Jul 2019 06:50:37 +0000 (08:50 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Fri, 20 Sep 2019 08:43:43 +0000 (10:43 +0200)
This option allows to specify the custom output directory for reports

Change-Id: I7a49d958f268f73f346b7f5b692cf3ce56808f37

packaging/crash-worker_system-tests.spec
src/crash-manager/crash-manager.c
tests/system/CMakeLists.txt
tests/system/output_param/output_param.sh.template [new file with mode: 0755]

index cc33e03..3fea883 100644 (file)
@@ -78,6 +78,7 @@ cd tests/system
 %{_libdir}/crash-worker_system-tests/utils/minicore-utils.sh
 %{_libdir}/crash-worker_system-tests/wait_for_opt_usr/wait_for_opt_usr.sh
 %{_libdir}/crash-worker_system-tests/without_core/without_core.sh
+%{_libdir}/crash-worker_system-tests/output_param/output_param.sh
 %if %{with livedumper}
 %{_libdir}/crash-worker_system-tests/livedumper/livedumper.sh
 %endif
index 5f70610..7d30c92 100644 (file)
@@ -105,6 +105,7 @@ struct crash_info {
        char *log_path;
        char appid[APPID_MAX];
        char pkgid[PKGNAME_MAX];
+       char *output_path;
        bool livedump;
        bool kill;
        bool print_result_path;
@@ -205,6 +206,15 @@ static int prepare_paths(struct crash_info* cinfo)
        int tmp_len;
        const char *crash_subdir = cinfo->livedump ? LIVE_PATH_SUBDIR : CRASH_PATH_SUBDIR;
 
+       if (cinfo->output_path) {
+               free(config.crash_root_path);
+               config.crash_root_path = strdup(cinfo->output_path);
+               if (!config.crash_root_path) {
+                       _E("strdup() error: %m");
+                       return 0;
+               }
+       }
+
        tmp_len = strlen(config.crash_root_path) + strlen(crash_subdir);
        crash_dump_path = (char*)malloc(tmp_len + 1);
        if (crash_dump_path == NULL) {
@@ -342,6 +352,7 @@ static void print_help(const char *name)
               "    -l  --live              get coredump of running process\n"
               "    -k  --kill-after-dump   kill after dump (only with --live option)\n"
               "    -r  --print             print report path to stdout\n"
+              "    -o  --output            output directory\n"
               "    -h  --help              this message\n"
               "\n"
               "for --live option only --pid is required\n"
@@ -377,10 +388,11 @@ static bool parse_args(struct crash_info *cinfo, int argc, char *argv[])
                {"live",                  no_argument, NULL, 'l'},
                {"kill-after-dump",       no_argument, NULL, 'k'},
                {"print",                 no_argument, NULL, 'r'},
+               {"output",          required_argument, NULL, 'o'},
                {"help",                  no_argument, NULL, 'h'},
        };
 
-       while ((opt = getopt_long(argc, argv, "p:u:g:i:s:t:hlkr", long_options, NULL)) != -1) {
+       while ((opt = getopt_long(argc, argv, "p:u:g:i:s:t:hlkro:", long_options, NULL)) != -1) {
                switch (opt) {
                case 'p':
                        GET_NUMBER(pid)
@@ -413,6 +425,10 @@ static bool parse_args(struct crash_info *cinfo, int argc, char *argv[])
                case 'r':
                        cinfo->print_result_path = true;
                        break;
+               case 'o':
+                       cinfo->output_path = optarg;
+                       _D("output path: %s\n", optarg);
+                       break;
                case 'h':
                default:
                        print_help(argv[0]);
@@ -1236,6 +1252,7 @@ static void crash_info_init(struct crash_info *cinfo)
        cinfo->print_result_path = false;
        cinfo->tid_info = -1;
        cinfo->time_info = 0;
+       cinfo->output_path = NULL;
 }
 
 static bool run(struct crash_info *cinfo)
index 7db25e2..309e572 100644 (file)
@@ -39,6 +39,7 @@ configure_test("dump_systemstate_extras")
 configure_test("livedumper")
 configure_test("extra_script")
 configure_test("dbus_notify")
+configure_test("output_param")
 
 get_property(TESTS_LIST GLOBAL PROPERTY TMP_TESTS_LIST)
 
diff --git a/tests/system/output_param/output_param.sh.template b/tests/system/output_param/output_param.sh.template
new file mode 100755 (executable)
index 0000000..7379009
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+# Test --output parameter
+
+if [ -z "${CRASH_WORKER_SYSTEM_TESTS}" ]; then
+    CRASH_WORKER_SYSTEM_TESTS="@CRASH_SYSTEM_TESTS_PATH@"
+fi
+
+. ${CRASH_WORKER_SYSTEM_TESTS}/utils/minicore-utils.sh
+
+OUTPUT=/tmp/output_dir/
+mkdir -p ${OUTPUT}
+
+save_core_pattern
+trap restore_core_pattern 0
+
+echo "|/usr/bin/crash-manager -p %p -u %u -g %g -s %s -t %t --output ${OUTPUT}" > /proc/sys/kernel/core_pattern
+
+{
+    ${CRASH_WORKER_SYSTEM_TESTS}/utils/kenny 10 &
+    sleep 1
+    killall -6 kenny
+} 1> /dev/null 2>&1
+
+sleep 2
+
+wait_for_file ${OUTPUT}/dump/*zip
+rm -rf ${OUTPUT}
+
+exit_ok
+