]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udevadm-test: introduce -v/--verbose option to show verbose log messages
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 12 Jan 2025 20:09:15 +0000 (05:09 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 17 Jan 2025 19:19:52 +0000 (04:19 +0900)
Currently this does not show any extra log messages. In later commits,
more verbose log messages will be added.

man/udevadm.xml
shell-completion/bash/udevadm
shell-completion/zsh/_udevadm
src/udev/udev-event.h
src/udev/udevadm-test.c
test/units/TEST-17-UDEV.10.sh

index 13cf106d876056037916c25956d4d1bc2c9eefd5..07169f2e504a1a69affbc7a71574ab606dd8573a 100644 (file)
             <xi:include href="version-info.xml" xpointer="v209"/>
           </listitem>
         </varlistentry>
+        <varlistentry>
+          <term><option>-v</option></term>
+          <term><option>--verbose</option></term>
+          <listitem>
+            <para>Shows verbose logs in processing udev rules.</para>
+
+            <xi:include href="version-info.xml" xpointer="v258"/>
+          </listitem>
+        </varlistentry>
 
         <xi:include href="standard-options.xml" xpointer="help" />
       </variablelist>
index e5626c9301ac2f0b1dbdbb040a224194a802db32..c4aea7039c620633ede9e76847479c2095b6e6af 100644 (file)
@@ -69,7 +69,8 @@ _udevadm() {
         [CONTROL_ARG]='-l --log-priority -p --property -m --children-max -t --timeout'
         [MONITOR_STANDALONE]='-k --kernel -u --udev -p --property'
         [MONITOR_ARG]='-s --subsystem-match -t --tag-match'
-        [TEST]='-a --action -N --resolve-names'
+        [TEST_STANDALONE]='-v --verbose'
+        [TEST_ARG]='-a --action -N --resolve-names'
         [TEST_BUILTIN]='-a --action'
         [VERIFY]='-N --resolve-names --root --no-summary --no-style'
         [WAIT]='-t --timeout --initialized=no --removed --settle'
@@ -216,7 +217,7 @@ _udevadm() {
             ;;
 
         'test')
-            if __contains_word "$prev" ${OPTS[TEST]}; then
+            if __contains_word "$prev" ${OPTS[TEST_ARG]}; then
                 case $prev in
                     -a|--action)
                         comps=$( udevadm test --action help )
@@ -225,12 +226,8 @@ _udevadm() {
                         comps='early late never'
                         ;;
                 esac
-                COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
-                return 0
-            fi
-
-            if [[ $cur = -* ]]; then
-                comps="${OPTS[COMMON]} ${OPTS[TEST]}"
+            elif [[ $cur = -* ]]; then
+                comps="${OPTS[COMMON]} ${OPTS[TEST_ARG]} ${OPTS[TEST_STANDALONE]}"
             else
                 comps=$( __get_all_devices )
                 local IFS=$'\n'
index 5f5761cbfa3d5debb0869dcaaa78b66f022fa0af..c0141e5cd381a787ad0df68fe91ba171fa7e9ee4 100644 (file)
@@ -88,6 +88,7 @@ _udevadm_test(){
         '(-)'{-V,--version}'[Show package version]' \
         '--action=[The action string.]:actions:(add change remove move online offline bind unbind)' \
         '--subsystem=[The subsystem string.]' \
+        '(-v --verbose)'{-v,--verbose}'[Show verbose logs.]' \
         '*::devpath:_files -P /sys/ -W /sys'
 }
 
index b1ad2bf0c2f7f8079dd1c63074a7289ae8b1aba1..11e2c700e63505f589abdb99941b2807211f936a 100644 (file)
@@ -48,6 +48,7 @@ typedef struct UdevEvent {
         bool name_final;
         bool devlink_final;
         bool run_final;
+        bool trace;
         bool log_level_was_debug;
         int default_log_level;
         EventMode event_mode;
index 5db991b8a6a5ae6c14d2a6cae5c973eb515f5a9c..088522b915f57e133917bf95252805cdad37f56a 100644 (file)
@@ -34,6 +34,7 @@
 static sd_device_action_t arg_action = SD_DEVICE_ADD;
 static ResolveNameTiming arg_resolve_name_timing = RESOLVE_NAME_EARLY;
 static const char *arg_syspath = NULL;
+static bool arg_verbose = false;
 
 static int help(void) {
 
@@ -42,7 +43,8 @@ static int help(void) {
                "  -h --help                            Show this help\n"
                "  -V --version                         Show package version\n"
                "  -a --action=ACTION|help              Set action string\n"
-               "  -N --resolve-names=early|late|never  When to resolve names\n",
+               "  -N --resolve-names=early|late|never  When to resolve names\n"
+               "  -v --verbose                         Show verbose logs\n",
                program_invocation_short_name);
 
         return 0;
@@ -52,6 +54,7 @@ static int parse_argv(int argc, char *argv[]) {
         static const struct option options[] = {
                 { "action",        required_argument, NULL, 'a' },
                 { "resolve-names", required_argument, NULL, 'N' },
+                { "verbose",       no_argument,       NULL, 'v' },
                 { "version",       no_argument,       NULL, 'V' },
                 { "help",          no_argument,       NULL, 'h' },
                 {}
@@ -59,7 +62,7 @@ static int parse_argv(int argc, char *argv[]) {
 
         int r, c;
 
-        while ((c = getopt_long(argc, argv, "a:N:Vh", options, NULL)) >= 0)
+        while ((c = getopt_long(argc, argv, "a:N:vVh", options, NULL)) >= 0)
                 switch (c) {
                 case 'a':
                         r = parse_device_action(optarg, &arg_action);
@@ -74,6 +77,9 @@ static int parse_argv(int argc, char *argv[]) {
                                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
                                                        "--resolve-names= must be early, late or never");
                         break;
+                case 'v':
+                        arg_verbose = true;
+                        break;
                 case 'V':
                         return print_version();
                 case 'h':
@@ -105,20 +111,23 @@ int test_main(int argc, char *argv[], void *userdata) {
         if (r <= 0)
                 return r;
 
-        printf("This program is for debugging only, it does not run any program\n"
-               "specified by a RUN key. It may show incorrect results, because\n"
-               "some values may be different, or not available at a simulation run.\n"
-               "\n");
+        puts("This program is for debugging only, it does not run any program\n"
+             "specified by a RUN key. It may show incorrect results, because\n"
+             "some values may be different, or not available at a simulation run.");
 
         assert_se(sigprocmask(SIG_SETMASK, NULL, &sigmask_orig) >= 0);
 
+        puts("\nLoading builtins...");
         udev_builtin_init();
+        puts("Loading builtins done.");
 
+        puts("\nLoading udev rules files...");
         r = udev_rules_load(&rules, arg_resolve_name_timing);
         if (r < 0) {
                 log_error_errno(r, "Failed to read udev rules: %m");
                 goto out;
         }
+        puts("Loading udev rules files done.");
 
         r = find_device_with_action(arg_syspath, arg_action, &dev);
         if (r < 0) {
@@ -134,12 +143,16 @@ int test_main(int argc, char *argv[], void *userdata) {
                 log_oom();
                 goto out;
         }
+        event->trace = arg_verbose;
 
         assert_se(sigfillset(&mask) >= 0);
         assert_se(sigprocmask(SIG_SETMASK, &mask, &sigmask_orig) >= 0);
 
+        printf("\nProcessing udev rules%s...\n", arg_verbose ? "" : " (verbose logs can be shown by -v/--verbose)");
         udev_event_execute_rules(event, rules);
+        puts("Processing udev rules done.");
 
+        puts("");
         printf("%sProperties:%s\n", ansi_highlight(), ansi_normal());
         FOREACH_DEVICE_PROPERTY(dev, key, value)
                 printf("  %s=%s\n", key, value);
index e38291bdde8e7b3c6bd2ae850faebb7b0f21adec..5ee1cd3e429fc9e93795dc92272c018d3c64768f 100755 (executable)
@@ -141,6 +141,7 @@ udevadm test -N early /sys/class/net/$netdev
 udevadm test -N late /sys/class/net/$netdev
 udevadm test --resolve-names never /sys/class/net/$netdev
 (! udevadm test -N hello /sys/class/net/$netdev)
+udevadm test -v /sys/class/net/$netdev
 udevadm test -h
 
 # udevadm test-builtin path_id "$loopdev"