Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Feb 2025 12:17:30 GMT
From:      Christos Margiolis <christos@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 47a067308ec9 - stable/14 - sound tests: Fix downshift calculation in pcm_read_write test
Message-ID:  <202502251217.51PCHUwq008005@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by christos:

URL: https://cgit.FreeBSD.org/src/commit/?id=47a067308ec97358ef07b7a5fb660e2d5fcc023e

commit 47a067308ec97358ef07b7a5fb660e2d5fcc023e
Author:     Florian Walpen <dev@submerge.ch>
AuthorDate: 2025-02-18 19:35:54 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2025-02-25 12:17:14 +0000

    sound tests: Fix downshift calculation in pcm_read_write test
    
    In some situations the feeders in the sound module lower the pcm sample
    resolution through a downshift of the sample value. The pcm_read_write
    test implements this operation with an arithmetic division to avoid
    implementation defined or architecture specific behavior. Due to
    different rounding, the test produced marginally different sample
    values, which made the test fail on 32 bit architectures. Correct this.
    
    Reported by:    CI
    Fixes:          27ef5d48c729 ("sound: Unit test the pcm sample read and write macros")
    MFC after:      1 week
    Reviewed by:    christos, markj
    Differential revision:  https://reviews.freebsd.org/D48926
    
    (cherry picked from commit 6672831bda883756d7f4598bb4b119f99eb1e7d2)
---
 tests/sys/sound/pcm_read_write.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/tests/sys/sound/pcm_read_write.c b/tests/sys/sound/pcm_read_write.c
index 7ef310a35c25..cfd89eec7c19 100644
--- a/tests/sys/sound/pcm_read_write.c
+++ b/tests/sys/sound/pcm_read_write.c
@@ -81,13 +81,21 @@ static struct afmt_test_data {
 static intpcm_t
 local_normalize(intpcm_t value, int val_bits, int norm_bits)
 {
+	int32_t divisor;
+	intpcm_t remainder;
+
 	/* Avoid undefined or implementation defined behavior. */
 	if (val_bits < norm_bits)
 		/* Multiply instead of left shift (value may be negative). */
 		return (value * (1 << (norm_bits - val_bits)));
-	else if (val_bits > norm_bits)
+	else if (val_bits > norm_bits) {
+		divisor = (1 << (val_bits - norm_bits));
+		/* Positive remainder, to discard lowest bits from value. */
+		remainder = value % divisor;
+		remainder = (remainder + divisor) % divisor;
 		/* Divide instead of right shift (value may be negative). */
-		return (value / (1 << (val_bits - norm_bits)));
+		return ((value - remainder) / divisor);
+	}
 	return value;
 }
 
@@ -103,8 +111,7 @@ local_calc_limit(intpcm_t value, int val_bits)
 	 * behavior here.
 	 */
 	if (sizeof(intpcm32_t) == (32 / 8) && val_bits == 32)
-		/* Divide instead of right shift (value may be negative). */
-		return (value / (1 << 8));
+		return (local_normalize(value, 32, 24));
 	return value;
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202502251217.51PCHUwq008005>