This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit 0629ebb5ffda39add5f1fbce524bbc989ba5d6c6
Author:     Andreas Rheinhardt <[email protected]>
AuthorDate: Sun Dec 7 10:50:39 2025 +0100
Commit:     Andreas Rheinhardt <[email protected]>
CommitDate: Sun Jan 4 15:49:30 2026 +0100

    tests/checkasm: Add CRC test
    
    Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 tests/checkasm/Makefile   |   1 +
 tests/checkasm/checkasm.c |   1 +
 tests/checkasm/checkasm.h |   1 +
 tests/checkasm/crc.c      | 112 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/fate/checkasm.mak   |   1 +
 5 files changed, 116 insertions(+)

diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index 9e675ce189..48f358d40d 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -91,6 +91,7 @@ CHECKASMOBJS-$(CONFIG_SWSCALE)  += $(SWSCALEOBJS)
 # libavutil tests
 AVUTILOBJS                              += aes.o
 AVUTILOBJS                              += av_tx.o
+AVUTILOBJS                              += crc.o
 AVUTILOBJS                              += fixed_dsp.o
 AVUTILOBJS                              += float_dsp.o
 AVUTILOBJS                              += lls.o
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 12712a111d..16d980e220 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -344,6 +344,7 @@ static const struct {
 #endif
 #if CONFIG_AVUTIL
         { "aes",       checkasm_check_aes },
+        { "crc",       checkasm_check_crc },
         { "fixed_dsp", checkasm_check_fixed_dsp },
         { "float_dsp", checkasm_check_float_dsp },
         { "lls",       checkasm_check_lls },
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index 7d4fc086c6..f288320069 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -93,6 +93,7 @@ void checkasm_check_bswapdsp(void);
 void checkasm_check_cavsdsp(void);
 void checkasm_check_colordetect(void);
 void checkasm_check_colorspace(void);
+void checkasm_check_crc(void);
 void checkasm_check_dcadsp(void);
 void checkasm_check_diracdsp(void);
 void checkasm_check_exrdsp(void);
diff --git a/tests/checkasm/crc.c b/tests/checkasm/crc.c
new file mode 100644
index 0000000000..60d9ef6018
--- /dev/null
+++ b/tests/checkasm/crc.c
@@ -0,0 +1,112 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <assert.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "checkasm.h"
+#include "libavutil/attributes.h"
+// Undefine av_pure so that calls to av_crc are not optimized away.
+#undef av_pure
+#define av_pure
+#include "libavutil/avassert.h"
+#include "libavutil/crc.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/macros.h"
+#include "libavutil/mem_internal.h"
+
+
+static void check_crc(const AVCRC *table_new, const char *name, unsigned idx)
+{
+    declare_func(uint32_t, const AVCRC *ctx, uint32_t crc,
+                 const uint8_t *buffer, size_t length);
+    const AVCRC *table_ref = check_key((AVCRC*)table_new, "crc_%s", name);
+
+    if (!table_ref)
+        return;
+
+    DECLARE_ALIGNED(4, uint8_t, buf)[8192];
+    size_t offset = rnd() & 31;
+    static size_t sizes[AV_CRC_MAX + 1];
+    static unsigned sizes_initialized = 0;
+    uint32_t prev_crc = rnd();
+
+    if (!(sizes_initialized & (1 << idx))) {
+        sizes_initialized |= 1 << idx;
+        sizes[idx] = rnd() % (sizeof(buf) - 1 - offset);
+    }
+
+    size_t size = sizes[idx];
+
+    for (size_t j = 0; j < sizeof(buf); j += 4)
+        AV_WN32A(buf + j, rnd());
+
+    uint32_t crc_ref = checkasm_call        (av_crc, table_ref, prev_crc, buf 
+ offset, size);
+    uint32_t crc_new = checkasm_call_checked(av_crc, table_new, prev_crc, buf 
+ offset, size);
+
+    if (crc_ref != crc_new)
+        fail();
+
+    bench(av_crc, table_new, prev_crc, buf + offset, size);
+}
+
+void checkasm_check_crc(void)
+{
+    static const char *const tests[] = {
+#define TEST(CRC) [AV_CRC_ ## CRC] = #CRC
+        TEST(8_ATM),   TEST(8_EBU),
+        TEST(16_ANSI), TEST(16_ANSI_LE), TEST(16_CCITT),
+        TEST(24_IEEE), TEST(32_IEEE_LE), TEST(32_IEEE),
+    };
+    static_assert(FF_ARRAY_ELEMS(tests) == AV_CRC_MAX, "test needs to be 
added");
+
+    for (unsigned i = 0; i < AV_CRC_MAX; ++i)
+        check_crc(av_crc_get_table(i), tests[i], i);
+
+    static struct CustomTest {
+        struct CustomTest *prev;
+        AVCRC ctx[1024];
+    } *ctx = NULL;
+    struct CustomTest *new = malloc(sizeof(*new));
+    static int le, bits;
+    static uint32_t poly;
+
+    if (!new)
+        fail();
+
+    memset(new, 0, sizeof(*new));
+
+    if (!ctx) {
+        le   = rnd() & 1;
+        bits = 8 + rnd() % 25; // av_crc_init() accepts between 8 and 32 bits
+        poly = rnd() >> (32 - bits);
+    }
+    av_assert0(av_crc_init(new->ctx, le, bits, poly, sizeof(new->ctx)) >= 0);
+    if (ctx && !memcmp(ctx->ctx, new->ctx, sizeof(new->ctx))) {
+        free(new);
+    } else {
+        new->prev = ctx;
+        ctx = new;
+    }
+
+    check_crc(ctx->ctx, "custom_polynomial", AV_CRC_MAX);
+    report("crc");
+}
diff --git a/tests/fate/checkasm.mak b/tests/fate/checkasm.mak
index 6b4e83dcf2..b08c1947cd 100644
--- a/tests/fate/checkasm.mak
+++ b/tests/fate/checkasm.mak
@@ -10,6 +10,7 @@ FATE_CHECKASM = fate-checkasm-aacencdsp                       
          \
                 fate-checkasm-blockdsp                                  \
                 fate-checkasm-bswapdsp                                  \
                 fate-checkasm-cavsdsp                                   \
+                fate-checkasm-crc                                       \
                 fate-checkasm-dcadsp                                    \
                 fate-checkasm-diracdsp                                  \
                 fate-checkasm-exrdsp                                    \

_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to