]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
dma-buf/selftests: drop the mock_wait implementation
authorChristian König <christian.koenig@amd.com>
Wed, 10 Dec 2025 13:47:36 +0000 (14:47 +0100)
committerChristian König <christian.koenig@amd.com>
Wed, 17 Dec 2025 14:00:57 +0000 (15:00 +0100)
Actually test the documented expectation of dma_fence_wait() instead of
comming up with a mock_wait implementation which uses undocumented
and non standard return codes and behavior.

Additional to that increase the timeout to one second, otherwise the
test case is a bit unreliable.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Link: https://lore.kernel.org/r/346e3df8-5f3a-4394-9d90-4ba107294161@ursulin.net
drivers/dma-buf/st-dma-fence.c

index 4dbe39c58bfba4d7b00d8200ef31147551a5a0a9..73ed6fd48a13fb4a2d0c5e9bf71c34b67c93d5d1 100644 (file)
@@ -33,50 +33,9 @@ static void mock_fence_release(struct dma_fence *f)
        kmem_cache_free(slab_fences, to_mock_fence(f));
 }
 
-struct wait_cb {
-       struct dma_fence_cb cb;
-       struct task_struct *task;
-};
-
-static void mock_wakeup(struct dma_fence *f, struct dma_fence_cb *cb)
-{
-       wake_up_process(container_of(cb, struct wait_cb, cb)->task);
-}
-
-static long mock_wait(struct dma_fence *f, bool intr, long timeout)
-{
-       const int state = intr ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE;
-       struct wait_cb cb = { .task = current };
-
-       if (dma_fence_add_callback(f, &cb.cb, mock_wakeup))
-               return timeout;
-
-       while (timeout) {
-               set_current_state(state);
-
-               if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &f->flags))
-                       break;
-
-               if (signal_pending_state(state, current))
-                       break;
-
-               timeout = schedule_timeout(timeout);
-       }
-       __set_current_state(TASK_RUNNING);
-
-       if (!dma_fence_remove_callback(f, &cb.cb))
-               return timeout;
-
-       if (signal_pending_state(state, current))
-               return -ERESTARTSYS;
-
-       return -ETIME;
-}
-
 static const struct dma_fence_ops mock_ops = {
        .get_driver_name = mock_name,
        .get_timeline_name = mock_name,
-       .wait = mock_wait,
        .release = mock_fence_release,
 };
 
@@ -349,14 +308,14 @@ static int test_wait(void *arg)
 
        dma_fence_enable_sw_signaling(f);
 
-       if (dma_fence_wait_timeout(f, false, 0) != -ETIME) {
+       if (dma_fence_wait_timeout(f, false, 0) != 0) {
                pr_err("Wait reported complete before being signaled\n");
                goto err_free;
        }
 
        dma_fence_signal(f);
 
-       if (dma_fence_wait_timeout(f, false, 0) != 0) {
+       if (dma_fence_wait_timeout(f, false, 0) != 1) {
                pr_err("Wait reported incomplete after being signaled\n");
                goto err_free;
        }
@@ -393,16 +352,16 @@ static int test_wait_timeout(void *arg)
 
        dma_fence_enable_sw_signaling(wt.f);
 
-       if (dma_fence_wait_timeout(wt.f, false, 1) != -ETIME) {
+       if (dma_fence_wait_timeout(wt.f, false, 1) != 0) {
                pr_err("Wait reported complete before being signaled\n");
                goto err_free;
        }
 
        mod_timer(&wt.timer, jiffies + 1);
 
-       if (dma_fence_wait_timeout(wt.f, false, 2) == -ETIME) {
+       if (dma_fence_wait_timeout(wt.f, false, HZ) == 0) {
                if (timer_pending(&wt.timer)) {
-                       pr_notice("Timer did not fire within the jiffy!\n");
+                       pr_notice("Timer did not fire within one HZ!\n");
                        err = 0; /* not our fault! */
                } else {
                        pr_err("Wait reported incomplete after timeout\n");