Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/audio Improve KASSERT messages.
details: https://anonhg.NetBSD.org/src/rev/5e31e124a607
branches: trunk
changeset: 745047:5e31e124a607
user: isaki <isaki%NetBSD.org@localhost>
date: Sat Feb 22 06:58:39 2020 +0000
description:
Improve KASSERT messages.
diffstat:
sys/dev/audio/audio.c | 108 ++++++++++++++++++++++++++--------------------
sys/dev/audio/audiodef.h | 15 ++++--
2 files changed, 72 insertions(+), 51 deletions(-)
diffs (294 lines):
diff -r 692558d277d6 -r 5e31e124a607 sys/dev/audio/audio.c
--- a/sys/dev/audio/audio.c Sat Feb 22 06:36:07 2020 +0000
+++ b/sys/dev/audio/audio.c Sat Feb 22 06:58:39 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: audio.c,v 1.46 2020/02/22 06:36:07 isaki Exp $ */
+/* $NetBSD: audio.c,v 1.47 2020/02/22 06:58:39 isaki Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.46 2020/02/22 06:36:07 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.47 2020/02/22 06:58:39 isaki Exp $");
#ifdef _KERNEL_OPT
#include "audio.h"
@@ -2062,7 +2062,7 @@
*bellfile = af;
} else {
error = fd_clone(fp, fd, flags, &audio_fileops, af);
- KASSERT(error == EMOVEFD);
+ KASSERTMSG(error == EMOVEFD, "error=%d", error);
}
TRACEF(3, af, "done");
@@ -3060,7 +3060,7 @@
/* Not necessary to insert sc_files. */
error = fd_clone(fp, fd, flags, &audio_fileops, af);
- KASSERT(error == EMOVEFD);
+ KASSERTMSG(error == EMOVEFD, "error=%d", error);
return error;
}
@@ -3213,9 +3213,12 @@
u_int channels;
DIAGNOSTIC_filter_arg(arg);
- KASSERT(arg->srcfmt->channels == arg->dstfmt->channels);
+ KASSERTMSG(arg->srcfmt->channels == arg->dstfmt->channels,
+ "arg->srcfmt->channels=%d, arg->dstfmt->channels=%d",
+ arg->srcfmt->channels, arg->dstfmt->channels);
KASSERT(arg->context != NULL);
- KASSERT(arg->srcfmt->channels <= AUDIO_MAX_CHANNELS);
+ KASSERTMSG(arg->srcfmt->channels <= AUDIO_MAX_CHANNELS,
+ "arg->srcfmt->channels=%d", arg->srcfmt->channels);
s = arg->src;
d = arg->dst;
@@ -3373,8 +3376,12 @@
DIAGNOSTIC_ring(dst);
DIAGNOSTIC_ring(src);
KASSERT(src->used > 0);
- KASSERT(src->fmt.channels == dst->fmt.channels);
- KASSERT(src->head % track->mixer->frames_per_block == 0);
+ KASSERTMSG(src->fmt.channels == dst->fmt.channels,
+ "src->fmt.channels=%d dst->fmt.channels=%d",
+ src->fmt.channels, dst->fmt.channels);
+ KASSERTMSG(src->head % track->mixer->frames_per_block == 0,
+ "src->head=%d track->mixer->frames_per_block=%d",
+ src->head, track->mixer->frames_per_block);
s = arg->src;
d = arg->dst;
@@ -3499,9 +3506,11 @@
DIAGNOSTIC_ring(dst);
DIAGNOSTIC_ring(src);
KASSERT(src->used > 0);
- KASSERT(src->fmt.channels == dst->fmt.channels);
+ KASSERTMSG(src->fmt.channels == dst->fmt.channels,
+ "src->fmt.channels=%d dst->fmt.channels=%d",
+ src->fmt.channels, dst->fmt.channels);
KASSERTMSG(src->head % track->mixer->frames_per_block == 0,
- "src->head=%d fpb=%d",
+ "src->head=%d track->mixer->frames_per_block=%d",
src->head, track->mixer->frames_per_block);
s0 = arg->src;
@@ -4192,7 +4201,9 @@
n = (ring->capacity - ring->used) % fpb;
- KASSERT(auring_get_contig_free(ring) >= n);
+ KASSERTMSG(auring_get_contig_free(ring) >= n,
+ "auring_get_contig_free(ring)=%d n=%d",
+ auring_get_contig_free(ring), n);
memset(auring_tailptr_aint(ring), 0,
n * ring->fmt.channels * sizeof(aint_t));
@@ -4225,7 +4236,7 @@
dstcount = auring_get_contig_free(stage->dst);
if (isfreq) {
- KASSERTMSG(srccount > 0, "freq but srccount == %d", srccount);
+ KASSERTMSG(srccount > 0, "freq but srccount=%d", srccount);
count = uimin(dstcount, track->mixer->frames_per_block);
} else {
count = uimin(srccount, dstcount);
@@ -4310,7 +4321,8 @@
int bytes2;
bytes1 = auring_get_contig_used(usrbuf);
- KASSERT(bytes1 % framesize == 0);
+ KASSERTMSG(bytes1 % framesize == 0,
+ "bytes1=%d framesize=%d", bytes1, framesize);
memcpy((uint8_t *)input->mem + auring_tail(input) * framesize,
(uint8_t *)usrbuf->mem + usrbuf->head,
bytes1);
@@ -4473,7 +4485,8 @@
int bytes2;
bytes1 = auring_get_contig_free(usrbuf);
- KASSERT(bytes1 % framesize == 0);
+ KASSERTMSG(bytes1 % framesize == 0,
+ "bytes1=%d framesize=%d", bytes1, framesize);
memcpy((uint8_t *)usrbuf->mem + auring_tail(usrbuf),
(uint8_t *)outbuf->mem + outbuf->head * framesize,
bytes1);
@@ -4869,7 +4882,9 @@
mixer = sc->sc_pmixer;
frame_count = mixer->frames_per_block;
- KASSERT(auring_get_contig_free(&mixer->hwbuf) >= frame_count);
+ KASSERTMSG(auring_get_contig_free(&mixer->hwbuf) >= frame_count,
+ "auring_get_contig_free()=%d frame_count=%d",
+ auring_get_contig_free(&mixer->hwbuf), frame_count);
sample_count = frame_count * mixer->mixfmt.channels;
mixer->mixseq++;
@@ -5160,7 +5175,9 @@
TRACE(4, "pbusy=%d hwbuf=%d/%d/%d",
sc->sc_pbusy,
mixer->hwbuf.head, mixer->hwbuf.used, mixer->hwbuf.capacity);
- KASSERT(mixer->hwbuf.used >= mixer->frames_per_block);
+ KASSERTMSG(mixer->hwbuf.used >= mixer->frames_per_block,
+ "mixer->hwbuf.used=%d mixer->frames_per_block=%d",
+ mixer->hwbuf.used, mixer->frames_per_block);
blksize = frametobyte(&mixer->hwbuf.fmt, mixer->frames_per_block);
@@ -5398,7 +5415,9 @@
input->head, input->used, input->capacity);
auring_take(input, drops);
}
- KASSERT(input->used % mixer->frames_per_block == 0);
+ KASSERTMSG(input->used % mixer->frames_per_block == 0,
+ "input->used=%d mixer->frames_per_block=%d",
+ input->used, mixer->frames_per_block);
memcpy(auring_tailptr_aint(input),
auring_headptr_aint(mixersrc),
@@ -6039,8 +6058,7 @@
KASSERT(mutex_owned(sc->sc_lock));
mode = *modep;
- KASSERTMSG((mode & (AUMODE_PLAY | AUMODE_RECORD)) != 0,
- "invalid mode = %x", mode);
+ KASSERTMSG((mode & (AUMODE_PLAY | AUMODE_RECORD)) != 0, "mode=0x%x", mode);
if (is_indep) {
int errorp = 0, errorr = 0;
@@ -7535,62 +7553,60 @@
#ifdef DIAGNOSTIC
void
-audio_diagnostic_format2(const char *func, const audio_format2_t *fmt)
-{
-
- KASSERTMSG(fmt, "%s: fmt == NULL", func);
+audio_diagnostic_format2(const char *where, const audio_format2_t *fmt)
+{
+
+ KASSERTMSG(fmt, "called from %s", where);
/* XXX MSM6258 vs(4) only has 4bit stride format. */
if (fmt->encoding == AUDIO_ENCODING_ADPCM) {
KASSERTMSG(fmt->stride == 4 || fmt->stride == 8,
- "%s: stride(%d) is invalid", func, fmt->stride);
+ "called from %s: fmt->stride=%d", where, fmt->stride);
} else {
KASSERTMSG(fmt->stride % NBBY == 0,
- "%s: stride(%d) is invalid", func, fmt->stride);
+ "called from %s: fmt->stride=%d", where, fmt->stride);
}
KASSERTMSG(fmt->precision <= fmt->stride,
- "%s: precision(%d) <= stride(%d)",
- func, fmt->precision, fmt->stride);
+ "called from %s: fmt->precision=%d fmt->stride=%d",
+ where, fmt->precision, fmt->stride);
KASSERTMSG(1 <= fmt->channels && fmt->channels <= AUDIO_MAX_CHANNELS,
- "%s: channels(%d) is out of range",
- func, fmt->channels);
+ "called from %s: fmt->channels=%d", where, fmt->channels);
/* XXX No check for encodings? */
}
void
-audio_diagnostic_filter_arg(const char *func, const audio_filter_arg_t *arg)
+audio_diagnostic_filter_arg(const char *where, const audio_filter_arg_t *arg)
{
KASSERT(arg != NULL);
KASSERT(arg->src != NULL);
KASSERT(arg->dst != NULL);
- DIAGNOSTIC_format2(arg->srcfmt);
- DIAGNOSTIC_format2(arg->dstfmt);
- KASSERTMSG(arg->count > 0,
- "%s: count(%d) is out of range", func, arg->count);
+ audio_diagnostic_format2(where, arg->srcfmt);
+ audio_diagnostic_format2(where, arg->dstfmt);
+ KASSERT(arg->count > 0);
}
void
-audio_diagnostic_ring(const char *func, const audio_ring_t *ring)
-{
-
- KASSERTMSG(ring, "%s: ring == NULL", func);
- DIAGNOSTIC_format2(&ring->fmt);
+audio_diagnostic_ring(const char *where, const audio_ring_t *ring)
+{
+
+ KASSERTMSG(ring, "called from %s", where);
+ audio_diagnostic_format2(where, &ring->fmt);
KASSERTMSG(0 <= ring->capacity && ring->capacity < INT_MAX / 2,
- "%s: capacity(%d) is out of range", func, ring->capacity);
+ "called from %s: ring->capacity=%d", where, ring->capacity);
KASSERTMSG(0 <= ring->used && ring->used <= ring->capacity,
- "%s: used(%d) is out of range (capacity:%d)",
- func, ring->used, ring->capacity);
+ "called from %s: ring->used=%d ring->capacity=%d",
+ where, ring->used, ring->capacity);
if (ring->capacity == 0) {
KASSERTMSG(ring->mem == NULL,
- "%s: capacity == 0 but mem != NULL", func);
+ "called from %s: capacity == 0 but mem != NULL", where);
} else {
KASSERTMSG(ring->mem != NULL,
- "%s: capacity != 0 but mem == NULL", func);
+ "called from %s: capacity != 0 but mem == NULL", where);
KASSERTMSG(0 <= ring->head && ring->head < ring->capacity,
- "%s: head(%d) is out of range (capacity:%d)",
- func, ring->head, ring->capacity);
+ "called from %s: ring->head=%d ring->capacity=%d",
+ where, ring->head, ring->capacity);
}
}
#endif /* DIAGNOSTIC */
diff -r 692558d277d6 -r 5e31e124a607 sys/dev/audio/audiodef.h
--- a/sys/dev/audio/audiodef.h Sat Feb 22 06:36:07 2020 +0000
+++ b/sys/dev/audio/audiodef.h Sat Feb 22 06:58:39 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: audiodef.h,v 1.8 2020/01/25 12:15:35 jmcneill Exp $ */
+/* $NetBSD: audiodef.h,v 1.9 2020/02/22 06:58:39 isaki Exp $ */
/*
* Copyright (C) 2017 Tetsuya Isaki. All rights reserved.
@@ -296,8 +296,9 @@
auring_round(const audio_ring_t *ring, int idx)
{
DIAGNOSTIC_ring(ring);
- KASSERT(idx >= 0);
- KASSERT(idx < ring->capacity * 2);
+ KASSERTMSG(idx >= 0, "idx=%d", idx);
+ KASSERTMSG(idx < ring->capacity * 2,
+ "idx=%d ring->capacity=%d", idx, ring->capacity);
if (idx < ring->capacity) {
return idx;
@@ -324,7 +325,9 @@
static __inline aint_t *
auring_headptr_aint(const audio_ring_t *ring)
{
- KASSERT(ring->fmt.stride == sizeof(aint_t) * NBBY);
+ KASSERTMSG(ring->fmt.stride == sizeof(aint_t) * NBBY,
+ "ring->fmt.stride=%d sizeof(aint_t)*NBBY=%zd",
+ ring->fmt.stride, sizeof(aint_t) * NBBY);
return (aint_t *)ring->mem + ring->head * ring->fmt.channels;
}
@@ -337,7 +340,9 @@
static __inline aint_t *
auring_tailptr_aint(const audio_ring_t *ring)
{
- KASSERT(ring->fmt.stride == sizeof(aint_t) * NBBY);
+ KASSERTMSG(ring->fmt.stride == sizeof(aint_t) * NBBY,
+ "ring->fmt.stride=%d sizeof(aint_t)*NBBY=%zd",
+ ring->fmt.stride, sizeof(aint_t) * NBBY);
return (aint_t *)ring->mem + auring_tail(ring) * ring->fmt.channels;
}
Home |
Main Index |
Thread Index |
Old Index