Skip to contentSkip to conversation

selftests: ALSA: Cover userspace-driven timers with test

bug report Dan Carpenter 1 participant 1 message Jan 17, 2025 Kselftest

lore
Share & tools
lore
#0 lore raw

Hello Ivan Orlov,

Commit 1026392d10af ("selftests: ALSA: Cover userspace-driven timers with test") from Aug 13, 2024 (linux-next), leads to the following Smatch static checker warning:

tools/testing/selftests/alsa/utimer-test.c:135 timer_f_utimer()
error: uninitialized symbol 'ticking_thread'.

tools/testing/selftests/alsa/utimer-test.c
106 TEST_F(timer_f, utimer) {

   107          char command[64];
   108          pthread_t ticking_thread;
   109          int total_ticks = 0;
   110          FILE *rfp;
   111          char *buf = malloc(TIMER_OUTPUT_BUF_LEN);
   112  
   113          ASSERT_NE(buf, NULL);
   114  
   115          /* The timeout should be the ticks interval * count of ticks + some delta */
   116          sprintf(command, "./global-timer %d %d %d", SNDRV_TIMER_GLOBAL_UDRIVEN,
   117                  self->utimer_info->id, TICKS_COUNT * TIMER_FREQ_SEC + TICKS_RECORDING_DELTA);
   118  
   119          rfp = popen(command, "r");
   120          while (fgets(buf, TIMER_OUTPUT_BUF_LEN, rfp)) {
   121                  buf[TIMER_OUTPUT_BUF_LEN - 1] = 0;
   122                  switch (parse_timer_output(buf)) {
   123                  case TIMER_APP_STARTED:
   124                          /* global-timer waits for timer to trigger, so start the ticking thread */
   125                          pthread_create(&ticking_thread, NULL, ticking_func,
                                                ^^^^^^^^^^^^^^

ticking_thread is only initialized here, not on other paths.

126 &self->utimer_info->fd);
127 break;
128 case TIMER_APP_RESULT:
129 total_ticks = parse_timer_result(buf);
130 break;
131 case TIMER_NO_EVENT:
132 break;
133 }
134 }

   135          pthread_join(ticking_thread, NULL);
                             ^^^^^^^^^^^^^^

uninitialized.

   136          ASSERT_EQ(total_ticks, TICKS_COUNT);
   137          pclose(rfp);
   138  }

regards,
dan carpenter