From: Neil Roberts <bpeeluk-at-yahoo.co.uk@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 2/2] avformat/tests: Add a test for avio_check with the pipe protocol
Date: Mon, 29 Aug 2022 16:43:20 +0200
Message-ID: <20220829144320.330685-2-bpeeluk@yahoo.co.uk> (raw)
In-Reply-To: <20220829144320.330685-1-bpeeluk@yahoo.co.uk>
Creates a UNIX pipe and then verifies that avio_check returns the right
access flags for the two ends of the pipe.
Signed-off-by: Neil Roberts <bpeeluk@yahoo.co.uk>
---
libavformat/Makefile | 1 +
libavformat/tests/.gitignore | 1 +
libavformat/tests/pipe.c | 101 +++++++++++++++++++++++++++++++++++
tests/fate/libavformat.mak | 5 ++
4 files changed, 108 insertions(+)
create mode 100644 libavformat/tests/pipe.c
diff --git a/libavformat/Makefile b/libavformat/Makefile
index f67a99f839..9c681c58c5 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -732,6 +732,7 @@ TESTPROGS-$(CONFIG_MOV_MUXER) += movenc
TESTPROGS-$(CONFIG_NETWORK) += noproxy
TESTPROGS-$(CONFIG_SRTP) += srtp
TESTPROGS-$(CONFIG_IMF_DEMUXER) += imf
+TESTPROGS-$(CONFIG_PIPE_PROTOCOL) += pipe
TOOLS = aviocat \
ismindex \
diff --git a/libavformat/tests/.gitignore b/libavformat/tests/.gitignore
index cdd0cce061..567d6f9e40 100644
--- a/libavformat/tests/.gitignore
+++ b/libavformat/tests/.gitignore
@@ -7,3 +7,4 @@
/srtp
/url
/seek_utils
+/pipe
diff --git a/libavformat/tests/pipe.c b/libavformat/tests/pipe.c
new file mode 100644
index 0000000000..68540c1a8c
--- /dev/null
+++ b/libavformat/tests/pipe.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2022 Neil Roberts
+ *
+ * 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 <string.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include "libavformat/avio.h"
+#include "libavutil/error.h"
+
+static int check_pipe(const char *url, int mask, int expected)
+{
+ int flags = avio_check(url, mask);
+
+ if (flags < 0) {
+ fprintf(stderr,
+ "avio_check for %s with mask 0x%x failed: %s\n",
+ url,
+ mask,
+ av_err2str(flags));
+ return 0;
+ }
+
+ if (flags != expected) {
+ fprintf(stderr,
+ "Wrong result returned from avio_check for %s with mask 0x%x. "
+ "Expected 0x%x but received 0x%x\n",
+ url,
+ mask,
+ flags,
+ expected);
+ return 0;
+ }
+
+ return 1;
+}
+
+int main(int argc, char **argv)
+{
+ int ret = 0;
+ int pipe_fds[2];
+ char read_url[20], write_url[20];
+ int check_invalid_ret;
+
+ if (pipe(pipe_fds) == -1) {
+ fprintf(stderr, "error creating pipe: %s\n", strerror(errno));
+ return 1;
+ }
+
+ snprintf(read_url, sizeof(read_url), "pipe:%d", pipe_fds[0]);
+ snprintf(write_url, sizeof(write_url), "pipe:%d", pipe_fds[1]);
+
+ if (!check_pipe(read_url,
+ AVIO_FLAG_READ | AVIO_FLAG_WRITE,
+ AVIO_FLAG_READ))
+ ret = 1;
+
+ if (!check_pipe(write_url,
+ AVIO_FLAG_READ | AVIO_FLAG_WRITE,
+ AVIO_FLAG_WRITE))
+ ret = 1;
+
+ /* Ensure that we don't get flags that we didn't ask for */
+ if (!check_pipe(read_url, AVIO_FLAG_WRITE, 0))
+ ret = 1;
+
+ close(pipe_fds[0]);
+ close(pipe_fds[1]);
+
+ /* An invalid fd should return EBADF */
+ check_invalid_ret = avio_check(read_url, AVIO_FLAG_READ);
+
+ if (check_invalid_ret != AVERROR(EBADF)) {
+ fprintf(stderr,
+ "avio_check on invalid FD expected to return %i "
+ "but %i was received\n",
+ AVERROR(EBADF),
+ check_invalid_ret);
+ ret = 1;
+ }
+
+ return ret;
+}
diff --git a/tests/fate/libavformat.mak b/tests/fate/libavformat.mak
index d2acb4c9e0..7a22f54c04 100644
--- a/tests/fate/libavformat.mak
+++ b/tests/fate/libavformat.mak
@@ -26,6 +26,11 @@ FATE_LIBAVFORMAT-$(CONFIG_IMF_DEMUXER) += fate-imf
fate-imf: libavformat/tests/imf$(EXESUF)
fate-imf: CMD = run libavformat/tests/imf$(EXESUF)
+FATE_LIBAVFORMAT-$(CONFIG_PIPE_PROTOCOL) += fate-pipe
+fate-pipe: libavformat/tests/pipe$(EXESUF)
+fate-pipe: CMD = run libavformat/tests/pipe$(EXESUF)
+fate-pipe: CMP = null
+
FATE_LIBAVFORMAT += fate-seek_utils
fate-seek_utils: libavformat/tests/seek_utils$(EXESUF)
fate-seek_utils: CMD = run libavformat/tests/seek_utils$(EXESUF)
--
2.37.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-08-29 14:43 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20220829144320.330685-1-bpeeluk.ref@yahoo.co.uk>
2022-08-29 14:43 ` [FFmpeg-devel] [PATCH 1/2] avformat/file: Add a specialized url_check callback for " Neil Roberts
2022-08-29 14:43 ` Neil Roberts [this message]
2022-08-29 21:54 ` Michael Niedermayer
2022-08-30 12:09 ` [FFmpeg-devel] [PATCH v2 " Neil Roberts
2022-08-30 12:09 ` [FFmpeg-devel] [PATCH v2 2/2] avformat/tests: Add a test for avio_check with the " Neil Roberts
2022-11-09 14:31 ` [FFmpeg-devel] [PATCH v2 1/2] avformat/file: Add a specialized url_check callback for " Neil Roberts
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220829144320.330685-2-bpeeluk@yahoo.co.uk \
--to=bpeeluk-at-yahoo.co.uk@ffmpeg.org \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git