# HG changeset patch # User Maxim Dounin <mdou...@mdounin.ru> # Date 1747275653 -10800 # Thu May 15 05:20:53 2025 +0300 # Node ID c5566713e4bed939c0f2bc4de443fbe49ae212c4 # Parent 0a913a10945b996bcdac073467bf7bc957ef716e Tests: mp4 tests with directio and open_file_cache.
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'); + +} + +###############################################################################