From fa3d20072baa57a9811ff18ffc58a811686af1f6 Mon Sep 17 00:00:00 2001 From: marcos ashton Date: Thu, 9 Apr 2026 15:37:47 +0100 Subject: [PATCH] tests/fate/libavutil: add FATE test for timestamp Test av_ts_make_string with NOPTS, zero, positive, negative, and INT64 boundary values, av_ts2str macro, av_ts_make_time_string2 with various timebases, and av_ts_make_time_string pointer variant. Coverage for libavutil/timestamp.c: 0.00% -> 100.00% --- .forgejo/CODEOWNERS | 2 + libavutil/Makefile | 1 + libavutil/tests/timestamp.c | 75 +++++++++++++++++++++++++++++++++++++ tests/fate/libavutil.mak | 4 ++ tests/ref/fate/timestamp | 23 ++++++++++++ 5 files changed, 105 insertions(+) create mode 100644 libavutil/tests/timestamp.c create mode 100644 tests/ref/fate/timestamp diff --git a/.forgejo/CODEOWNERS b/.forgejo/CODEOWNERS index cd5fd87aa9..a1febd9856 100644 --- a/.forgejo/CODEOWNERS +++ b/.forgejo/CODEOWNERS @@ -235,11 +235,13 @@ tests/checkasm/riscv/.* @Courmisch libavutil/tests/buffer.* @MarcosAsh libavutil/tests/hdr_dynamic_vivid_metadata.* @MarcosAsh libavutil/tests/tdrdi.* @MarcosAsh +libavutil/tests/timestamp.* @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 +tests/ref/fate/timestamp @MarcosAsh # Forgejo # ======= diff --git a/libavutil/Makefile b/libavutil/Makefile index 83ca133d04..b7d6e4906f 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -311,6 +311,7 @@ TESTPROGS = adler32 \ stereo3d \ tdrdi \ timecode \ + timestamp \ tree \ twofish \ utf8 \ diff --git a/libavutil/tests/timestamp.c b/libavutil/tests/timestamp.c new file mode 100644 index 0000000000..1edc0a4000 --- /dev/null +++ b/libavutil/tests/timestamp.c @@ -0,0 +1,75 @@ +/* + * 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 +#include + +#include "libavutil/avutil.h" +#include "libavutil/macros.h" +#include "libavutil/rational.h" +#include "libavutil/timestamp.h" + +int main(void) +{ + char buf[AV_TS_MAX_STRING_SIZE]; + static const struct { const char *label; int64_t ts; } ts_vals[] = { + { "NOPTS", AV_NOPTS_VALUE }, + { "0", 0 }, + { "90000", 90000 }, + { "-1", -1 }, + { "INT64_MAX", INT64_MAX }, + { "INT64_MIN+1", INT64_MIN + 1 }, + }; + static const struct { const char *label; int64_t ts; AVRational tb; } time_vals[] = { + { "NOPTS", AV_NOPTS_VALUE, {1, 90000} }, + { "90000 at 1/90000", 90000, {1, 90000} }, + { "0 at 1/1000", 0, {1, 1000} }, + { "48000 at 1/48000", 48000, {1, 48000} }, + { "44100 at 1/44100", 44100, {1, 44100} }, + { "-90000 at 1/90000", -90000, {1, 90000} }, + }; + + /* av_ts_make_string */ + printf("Testing av_ts_make_string()\n"); + for (int i = 0; i < FF_ARRAY_ELEMS(ts_vals); i++) + printf("%s: %s\n", ts_vals[i].label, + av_ts_make_string(buf, ts_vals[i].ts)); + + /* av_ts2str macro */ + printf("\nTesting av_ts2str()\n"); + printf("NOPTS: %s\n", av_ts2str(AV_NOPTS_VALUE)); + printf("48000: %s\n", av_ts2str(48000)); + + /* av_ts_make_time_string2 */ + printf("\nTesting av_ts_make_time_string2()\n"); + for (int i = 0; i < FF_ARRAY_ELEMS(time_vals); i++) + printf("%s: %s\n", time_vals[i].label, + av_ts_make_time_string2(buf, time_vals[i].ts, time_vals[i].tb)); + + /* av_ts_make_time_string (AVRational pointer version) */ + printf("\nTesting av_ts_make_time_string()\n"); + { + AVRational tb = {1, 1000}; + printf("5000 at 1/1000: %s\n", + av_ts_make_time_string(buf, 5000, &tb)); + printf("NOPTS: %s\n", + av_ts_make_time_string(buf, AV_NOPTS_VALUE, &tb)); + } + + return 0; +} diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak index a83539a58f..e814ee884c 100644 --- a/tests/fate/libavutil.mak +++ b/tests/fate/libavutil.mak @@ -232,6 +232,10 @@ FATE_LIBAVUTIL += fate-timecode fate-timecode: libavutil/tests/timecode$(EXESUF) fate-timecode: CMD = run libavutil/tests/timecode$(EXESUF) +FATE_LIBAVUTIL += fate-timestamp +fate-timestamp: libavutil/tests/timestamp$(EXESUF) +fate-timestamp: CMD = run libavutil/tests/timestamp$(EXESUF) + FATE_LIBAVUTIL += $(FATE_LIBAVUTIL-yes) FATE-$(CONFIG_AVUTIL) += $(FATE_LIBAVUTIL) fate-libavutil: $(FATE_LIBAVUTIL) diff --git a/tests/ref/fate/timestamp b/tests/ref/fate/timestamp new file mode 100644 index 0000000000..c7b55dada3 --- /dev/null +++ b/tests/ref/fate/timestamp @@ -0,0 +1,23 @@ +Testing av_ts_make_string() +NOPTS: NOPTS +0: 0 +90000: 90000 +-1: -1 +INT64_MAX: 9223372036854775807 +INT64_MIN+1: -9223372036854775807 + +Testing av_ts2str() +NOPTS: NOPTS +48000: 48000 + +Testing av_ts_make_time_string2() +NOPTS: NOPTS +90000 at 1/90000: 1 +0 at 1/1000: 0 +48000 at 1/48000: 1 +44100 at 1/44100: 1 +-90000 at 1/90000: -1 + +Testing av_ts_make_time_string() +5000 at 1/1000: 5 +NOPTS: NOPTS