]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests: ublk: replace assert() with ublk_assert()
authorMing Lei <ming.lei@redhat.com>
Fri, 16 Jan 2026 14:18:49 +0000 (22:18 +0800)
committerJens Axboe <axboe@kernel.dk>
Fri, 23 Jan 2026 03:05:41 +0000 (20:05 -0700)
Replace assert() with ublk_assert() since it is often triggered in daemon,
and we may get nothing shown in terminal.

Add ublk_assert(), so we can log something to syslog when assert() is
triggered.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
tools/testing/selftests/ublk/common.c
tools/testing/selftests/ublk/file_backed.c
tools/testing/selftests/ublk/kublk.c
tools/testing/selftests/ublk/kublk.h
tools/testing/selftests/ublk/stripe.c
tools/testing/selftests/ublk/utils.h

index d9873d4d50d0dd3827e0633d742b764a89f65444..530f9877c9ddee5e8936fe25d3cdc40ebaec81bd 100644 (file)
@@ -16,7 +16,7 @@ int backing_file_tgt_init(struct ublk_dev *dev, unsigned int nr_direct)
 {
        int fd, i;
 
-       assert(dev->nr_fds == 1);
+       ublk_assert(dev->nr_fds == 1);
 
        for (i = 0; i < dev->tgt.nr_backing_files; i++) {
                char *file = dev->tgt.backing_file[i];
index c3ce5ff72422265b40c44bda3432de8ab310bdbc..889047bd8fa3719723593b52f3decebe42956764 100644 (file)
@@ -10,7 +10,7 @@ static enum io_uring_op ublk_to_uring_op(const struct ublksrv_io_desc *iod, int
                return zc ? IORING_OP_READ_FIXED : IORING_OP_READ;
        else if (ublk_op == UBLK_IO_OP_WRITE)
                return zc ? IORING_OP_WRITE_FIXED : IORING_OP_WRITE;
-       assert(0);
+       ublk_assert(0);
 }
 
 static int loop_queue_flush_io(struct ublk_thread *t, struct ublk_queue *q,
index 3472ce7426ba86e1f67c39dac083f1d70a076f49..e98999bea9b1470343b3805e28acc7a2cc82ac27 100644 (file)
@@ -825,7 +825,7 @@ static void ublk_handle_uring_cmd(struct ublk_thread *t,
        }
 
        if (cqe->res == UBLK_IO_RES_OK) {
-               assert(tag < q->q_depth);
+               ublk_assert(tag < q->q_depth);
 
                if (ublk_queue_use_user_copy(q))
                        ublk_user_copy(io, UBLK_IO_OP_WRITE);
index 69fd5794f3008a61c273039873c3d64175c0a32f..48634d29c084f81fa032ce6dfcd9b8b6b095557e 100644 (file)
@@ -260,7 +260,7 @@ static inline __u64 build_user_data(unsigned tag, unsigned op,
 {
        /* we only have 7 bits to encode q_id */
        _Static_assert(UBLK_MAX_QUEUES_SHIFT <= 7);
-       assert(!(tag >> 16) && !(op >> 8) && !(tgt_data >> 16) && !(q_id >> 7));
+       ublk_assert(!(tag >> 16) && !(op >> 8) && !(tgt_data >> 16) && !(q_id >> 7));
 
        return tag | ((__u64)op << 16) | ((__u64)tgt_data << 24) |
                (__u64)q_id << 56 | (__u64)is_target_io << 63;
index 2be1c36438e7811d1887235c0d01374cc87adc42..b967447fe5913db1ccc931f5edac218e7e9dcc63 100644 (file)
@@ -96,12 +96,12 @@ static void calculate_stripe_array(const struct stripe_conf *conf,
                        this->seq = seq;
                        s->nr += 1;
                } else {
-                       assert(seq == this->seq);
-                       assert(this->start + this->nr_sects == stripe_off);
+                       ublk_assert(seq == this->seq);
+                       ublk_assert(this->start + this->nr_sects == stripe_off);
                        this->nr_sects += nr_sects;
                }
 
-               assert(this->nr_vec < this->cap);
+               ublk_assert(this->nr_vec < this->cap);
                this->vec[this->nr_vec].iov_base = (void *)(base + done);
                this->vec[this->nr_vec++].iov_len = nr_sects << 9;
 
@@ -120,7 +120,7 @@ static inline enum io_uring_op stripe_to_uring_op(
                return zc ? IORING_OP_READV_FIXED : IORING_OP_READV;
        else if (ublk_op == UBLK_IO_OP_WRITE)
                return zc ? IORING_OP_WRITEV_FIXED : IORING_OP_WRITEV;
-       assert(0);
+       ublk_assert(0);
 }
 
 static int stripe_queue_tgt_rw_io(struct ublk_thread *t, struct ublk_queue *q,
@@ -322,7 +322,7 @@ static int ublk_stripe_tgt_init(const struct dev_ctx *ctx, struct ublk_dev *dev)
        if (!dev->tgt.nr_backing_files || dev->tgt.nr_backing_files > NR_STRIPE)
                return -EINVAL;
 
-       assert(dev->nr_fds == dev->tgt.nr_backing_files + 1);
+       ublk_assert(dev->nr_fds == dev->tgt.nr_backing_files + 1);
 
        for (i = 0; i < dev->tgt.nr_backing_files; i++)
                dev->tgt.backing_file_size[i] &= ~((1 << chunk_shift) - 1);
index a852e0b7153e2d2b59b5ac641363345f5b11a5b5..17eefed73690879cc0a26fcf447c51dcfcc5de19 100644 (file)
@@ -43,6 +43,7 @@ static inline void ublk_err(const char *fmt, ...)
 
        va_start(ap, fmt);
        vfprintf(stderr, fmt, ap);
+       va_end(ap);
 }
 
 static inline void ublk_log(const char *fmt, ...)
@@ -52,6 +53,7 @@ static inline void ublk_log(const char *fmt, ...)
 
                va_start(ap, fmt);
                vfprintf(stdout, fmt, ap);
+               va_end(ap);
        }
 }
 
@@ -62,7 +64,15 @@ static inline void ublk_dbg(int level, const char *fmt, ...)
 
                va_start(ap, fmt);
                vfprintf(stdout, fmt, ap);
+               va_end(ap);
        }
 }
 
+#define ublk_assert(x)  do { \
+       if (!(x)) {     \
+               ublk_err("%s %d: assert!\n", __func__, __LINE__); \
+               assert(x);      \
+       }       \
+} while (0)
+
 #endif