[nginx-tests] Tests: mp4 tests with directio and open_file_cache.

Maxim Dounin mdounin at mdounin.ru
Sun May 25 21:03:16 UTC 2025


details:   http://freenginx.org/hg/nginx-tests/rev/ba4f76b3b823
branches:  
changeset: 2008:ba4f76b3b823
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Mon May 26 00:02:51 2025 +0300
description:
Tests: mp4 tests with directio and open_file_cache.

diffstat:

 mp4_directio.t |  78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 78 insertions(+), 0 deletions(-)

diffs (83 lines):

diff --git a/mp4_directio.t b/mp4_directio.t
new file mode 100644
--- /dev/null
+++ b/mp4_directio.t
@@ -0,0 +1,78 @@
+#!/usr/bin/perl
+
+# (C) Maxim Dounin
+
+# Test for directio support in mp4 module.
+
+###############################################################################
+
+use warnings;
+use strict;
+
+use Test::More;
+
+BEGIN { use FindBin; chdir($FindBin::Bin); }
+
+use lib 'lib';
+use Test::Nginx;
+
+###############################################################################
+
+select STDERR; $| = 1;
+select STDOUT; $| = 1;
+
+my $t = Test::Nginx->new()->has(qw/http mp4/)->has_daemon('ffmpeg')
+	->write_file_expand('nginx.conf', <<'EOF');
+
+%%TEST_GLOBALS%%
+
+daemon off;
+
+events {
+}
+
+http {
+    %%TEST_GLOBALS_HTTP%%
+
+    server {
+        listen       127.0.0.1:8080;
+        server_name  localhost;
+
+        location / {
+            mp4;
+            open_file_cache max=10;
+            directio 0;
+        }
+    }
+}
+
+EOF
+
+plan(skip_all => 'no lavfi')
+	unless grep /lavfi/, `ffmpeg -loglevel quiet -formats`;
+plan(skip_all => 'no libx264 or libopenh264')
+	unless grep /libx264|libopenh264/, `ffmpeg -loglevel quiet -encoders`;
+system('ffmpeg -nostdin -loglevel quiet -y '
+	. '-f lavfi -i testsrc=duration=10:size=320x200:rate=15 '
+	. '-g 15 -c:v h264 '
+	. "${\($t->testdir())}/test.mp4") == 0
+	or die "Can't create mp4 file: $!";
+
+$t->run()->plan(2);
+
+###############################################################################
+
+# mp4 module uses unaligned reads while parsing mp4 file, though
+# failed to disable directio if a file with directio enabled was
+# returned from open file cache
+
+like(http_get('/test.mp4?start=1.0'), qr/ 200 /, 'mp4 directio first');
+
+TODO: {
+local $TODO = 'not yet' unless $t->has_version('1.29.0') or $^O ne 'linux';
+
+like(http_get('/test.mp4?start=1.0'), qr/ 200 /, 'mp4 directio cached');
+
+}
+
+###############################################################################


More information about the nginx-devel mailing list