tests/fate/libavutil: add FATE test for tdrdi

Test av_tdrdi_alloc with 1 and 3 displays, and the inline
av_tdrdi_get_display accessor. Verifies that the returned
pointer matches entries_offset + idx * entry_size, tests
write/read-back of display width exponent/mantissa and view ID
fields, and OOM paths via av_max_alloc.

Coverage for libavutil/tdrdi.c: 0.00% -> 100.00%
This commit is contained in:
marcos ashton
2026-04-09 15:32:33 +01:00
committed by michaelni
parent 215799e369
commit 9b47495dee
5 changed files with 113 additions and 0 deletions
+2
View File
@@ -234,10 +234,12 @@ doc/.* @GyanD
tests/checkasm/riscv/.* @Courmisch
libavutil/tests/buffer.* @MarcosAsh
libavutil/tests/hdr_dynamic_vivid_metadata.* @MarcosAsh
libavutil/tests/tdrdi.* @MarcosAsh
tests/ref/.*drawvg.* @ayosec
tests/ref/fate/buffer @MarcosAsh
tests/ref/fate/hdr_dynamic_vivid_metadata @MarcosAsh
tests/ref/fate/sub-mcc.* @programmerjake
tests/ref/fate/tdrdi @MarcosAsh
# Forgejo
# =======
+1
View File
@@ -309,6 +309,7 @@ TESTPROGS = adler32 \
softfloat \
spherical \
stereo3d \
tdrdi \
timecode \
tree \
twofish \
+92
View File
@@ -0,0 +1,92 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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 <limits.h>
#include <stdint.h>
#include <stdio.h>
#include "libavutil/mem.h"
#include "libavutil/tdrdi.h"
int main(void)
{
AV3DReferenceDisplaysInfo *tdrdi;
AV3DReferenceDisplay *display;
size_t size;
/* av_tdrdi_alloc with 1 display */
printf("Testing av_tdrdi_alloc()\n");
tdrdi = av_tdrdi_alloc(1, &size);
if (tdrdi) {
printf("alloc 1: size>0=%s, num_ref_displays=%u\n",
size > 0 ? "yes" : "no", tdrdi->num_ref_displays);
display = av_tdrdi_get_display(tdrdi, 0);
/* pointer consistency check */
if ((uint8_t *)display != (uint8_t *)tdrdi + tdrdi->entries_offset)
printf("display 0: pointer inconsistent with entries_offset\n");
/* write and read back */
display->exponent_ref_display_width = 3;
display->mantissa_ref_display_width = 100;
display->left_view_id = 0;
display->right_view_id = 1;
display = av_tdrdi_get_display(tdrdi, 0);
printf("display 0: width_exp=%u width_man=%u left=%u right=%u\n",
display->exponent_ref_display_width,
display->mantissa_ref_display_width,
display->left_view_id, display->right_view_id);
av_free(tdrdi);
}
/* alloc with multiple displays */
printf("\nTesting multiple displays\n");
tdrdi = av_tdrdi_alloc(3, &size);
if (tdrdi) {
printf("alloc 3: num_ref_displays=%u\n", tdrdi->num_ref_displays);
for (int i = 0; i < 3; i++) {
display = av_tdrdi_get_display(tdrdi, i);
/* verify stride consistency */
if ((uint8_t *)display != (uint8_t *)tdrdi + tdrdi->entries_offset +
(size_t)i * tdrdi->entry_size)
printf("display %d: pointer inconsistent\n", i);
display->exponent_ref_display_width = i + 1;
}
for (int i = 0; i < 3; i++) {
display = av_tdrdi_get_display(tdrdi, i);
printf("display %d: width_exp=%u\n", i,
display->exponent_ref_display_width);
}
av_free(tdrdi);
}
/* alloc with NULL size */
tdrdi = av_tdrdi_alloc(1, NULL);
printf("\nalloc (no size): %s\n", tdrdi ? "OK" : "FAIL");
av_free(tdrdi);
/* OOM paths via av_max_alloc */
printf("\nTesting OOM paths\n");
av_max_alloc(1);
tdrdi = av_tdrdi_alloc(1, &size);
printf("alloc OOM: %s\n", tdrdi ? "FAIL" : "OK");
av_free(tdrdi);
av_max_alloc(INT_MAX);
return 0;
}
+4
View File
@@ -188,6 +188,10 @@ FATE_LIBAVUTIL += fate-stereo3d
fate-stereo3d: libavutil/tests/stereo3d$(EXESUF)
fate-stereo3d: CMD = run libavutil/tests/stereo3d$(EXESUF)
FATE_LIBAVUTIL += fate-tdrdi
fate-tdrdi: libavutil/tests/tdrdi$(EXESUF)
fate-tdrdi: CMD = run libavutil/tests/tdrdi$(EXESUF)
FATE_LIBAVUTIL += fate-tree
fate-tree: libavutil/tests/tree$(EXESUF)
fate-tree: CMD = run libavutil/tests/tree$(EXESUF)
+14
View File
@@ -0,0 +1,14 @@
Testing av_tdrdi_alloc()
alloc 1: size>0=yes, num_ref_displays=1
display 0: width_exp=3 width_man=100 left=0 right=1
Testing multiple displays
alloc 3: num_ref_displays=3
display 0: width_exp=1
display 1: width_exp=2
display 2: width_exp=3
alloc (no size): OK
Testing OOM paths
alloc OOM: OK