Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved unit tests for FFmpegRunner #1364

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1642a26
Improved unit tests for FFmpegRunner to not take over display, be dep…
tombogle Nov 8, 2024
dba4714
Merge branch 'master' into improve-tests
tombogle Nov 14, 2024
cf3c597
Added CI build step to install ffprobe and ffmpeg before running tests.
tombogle Nov 16, 2024
43cbcd6
add a line to debug ffmpeg path
hahn-kev Nov 18, 2024
6d7fb90
search the path for ffmpeg
hahn-kev Nov 18, 2024
c82cea2
Removed inaccurate comments
tombogle Nov 18, 2024
6baf806
Merge branch 'master' into improve-tests
tombogle Nov 19, 2024
4fabb1a
+semver:minor Added FFmpegRunner.FfmpegMinimumVersion static property
tombogle Nov 19, 2024
590ffc1
Merge branch 'master' into improve-tests
tombogle Nov 19, 2024
02b8bfb
Added not in CHANGELOG.md about enhanced FFmpegRunner functionality: …
tombogle Nov 19, 2024
4901250
Allow (the only non-ignored test in) AudioPlayerTests to run on CI build
tombogle Nov 19, 2024
568c08b
Attempt to enable tests that use audio devices on CI build
tombogle Nov 19, 2024
b7e5120
Upgraded irrKlang DLLs to version 1.6
tombogle Nov 19, 2024
77ea045
Added specific NUnit cataegories for RequiresAudioOutputDevice and Re…
tombogle Nov 21, 2024
c0e0ce0
Added FFmpeg to path in build.yml
tombogle Nov 21, 2024
99e9bc4
removed `add-path` step from build.yml since that command is disabled…
tombogle Nov 21, 2024
10d0165
+semver:major Made MediaInfo look for the FFprobe exe in the same loc…
tombogle Nov 22, 2024
a77c5d9
Added installation of ffmpeg to Appveyor build and excluded tests tha…
tombogle Nov 22, 2024
2e5e58c
Try installing ab-audio-cable to see if that simulates presence of au…
tombogle Nov 22, 2024
269b695
Merge branch 'master' into improve-tests
tombogle Dec 3, 2024
c1e1801
Since vb-audio-cable doesn't have a choco installer, try downloading …
tombogle Dec 3, 2024
9b9df3a
Removed silent switch from VB Cable installer so I see if it is maybe…
tombogle Dec 5, 2024
f36c07d
Run VB Cable installer with elevated privileges and verify installation
tombogle Dec 5, 2024
bd14972
Gave up on installing a virtual audio input driver on Github build ag…
tombogle Dec 6, 2024
7ec02ef
See if explicitly creating SLDR cache folder will enable test setup t…
tombogle Dec 6, 2024
9b61be8
Revert "See if explicitly creating SLDR cache folder will enable test…
tombogle Dec 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ jobs:

- name: Get Path to Tests
run: echo "TEST_PATH=$(dotnet msbuild SIL.Core.Tests/ --getProperty:OutputPath -p:TargetFramework=${{ matrix.framework }} -p:Configuration=Release)" >> $GITHUB_ENV

- name: Install FFmpeg
uses: FedericoCarboni/setup-ffmpeg@v3
id: setup-ffmpeg
with:
ffmpeg-version: release
- run: echo ffmpeg path ${{ steps.setup-ffmpeg.outputs.ffmpeg-path }}

# there are cases where this will fail and we want to know about it
# so we don't use continue-on-error, but we still want to publish the results
Expand Down
9 changes: 1 addition & 8 deletions SIL.Media.Tests/AudioPlayerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@

namespace SIL.Media.Tests
{
/// <summary>
/// All these tests are skipped on TeamCity (even if you remove this category) because SIL.Media.Tests compiles to an exe,
/// and the project that builds libpalaso on TeamCity (build/Palaso.proj, task Test) invokes RunNUnitTC which
/// selects the test assemblies using Include="$(RootDir)/output/$(Configuration)/*.Tests.dll" which excludes exes.
/// I have not tried to verify that all of these tests would actually have problems on TeamCity, but it seemed
/// helpful to document in the usual way that they are not, in fact, run there.
/// </summary>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it is still worth a comment explaining why we are skipping these tests in CI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this file never explained its dependency. Turns out that with that one test ignored, the only remaining test in the fixture runs just fine without any sound device enabled. So I'll remove the SkipOnTeamCity category. I'm now thinkingnthat doing something like this is the real answer:https://github.com/NathanCheshire/CyderUtils/actions/runs/9733272570/workflow. Then all these tests could run in the CI build.

[Category("SkipOnTeamCity")]
[TestFixture]
public class AudioPlayerTests
Expand All @@ -33,7 +26,7 @@ public void LoadFile_ThenDispose_FileCanBeDeleted()
}

/// <summary>
/// This test shows what caused hearthis to abandon the naudio; previous to a change to this class in 2/2012, it is believed that all was ok.
/// This test shows what caused HearThis to abandon NAudio; previous to a change to this class in 2/2012, it is believed that all was ok.
/// </summary>
[Test, Ignore("Known to Fail (hangs forever")]
public void PlayFile_ThenDispose_FileCanBeDeleted()
Expand Down
9 changes: 3 additions & 6 deletions SIL.Media.Tests/AudioSessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,7 @@ public RecordingSession(int millisecondsToRecordBeforeStopping)
_recorder.StopRecordingAndSaveAsWav();
}

public ISimpleAudioSession Recorder
{
get { return _recorder; }
}
public ISimpleAudioSession Recorder => _recorder;

public void Dispose()
{
Expand Down Expand Up @@ -451,8 +448,8 @@ public void Record_LongRecording()
{
using (var folder = new TemporaryFolder("Record_LongRecording"))
{
string fpath = Path.Combine(folder.Path, "long.wav");
using (var x = AudioFactory.CreateAudioSession(fpath))
string fPath = Path.Combine(folder.Path, "long.wav");
using (var x = AudioFactory.CreateAudioSession(fPath))
{
SystemSounds.Beep.Play();
Assert.DoesNotThrow(() => x.StartRecording());
Expand Down
67 changes: 50 additions & 17 deletions SIL.Media.Tests/FFmpegRunnerTests.cs
hahn-kev marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
using System;
using System.IO;
using FFMpegCore;
using NUnit.Framework;
using SIL.IO;
using SIL.Media.Tests.Properties;
using SIL.Progress;

namespace SIL.Media.Tests
{
/// <summary>
/// All these tests are skipped on TeamCity (even if you remove this category) because SIL.Media.Tests compiles to an exe,
/// and the project that builds libpalaso on TeamCity (build/Palaso.proj, task Test) invokes RunNUnitTC which
/// selects the test assemblies using Include="$(RootDir)/output/$(Configuration)/*.Tests.dll" which excludes exes.
/// I have not tried to verify that all of these tests would actually have problems on TeamCity, but it seemed
/// helpful to document in the usual way that they are not, in fact, run there.
/// </summary>
[Category("SkipOnTeamCity")]
[Category("RequiresFfmpeg")]
[TestFixture]
public class FFmpegRunnerTests
{
[OneTimeSetUp]
public void CheckRequirements()
{
if (!FFmpegRunner.HaveNecessaryComponents)
Assert.Ignore("These tests require ffmpeg to be installed.");
{
if (Environment.GetEnvironmentVariable("CI") == null)
Assert.Ignore("These tests require ffmpeg to be installed.");
else
Assert.Fail("On CI build using GHA, FFMpeg should have been installed before running tests.");
hahn-kev marked this conversation as resolved.
Show resolved Hide resolved
}
}

[Test]
[Category("RequiresFfmpeg")]
public void HaveNecessaryComponents_ReturnsTrue()
{
Assert.IsTrue(FFmpegRunner.HaveNecessaryComponents);
}

[Test]
[Category("RequiresFfmpeg")]
public void ExtractMp3Audio_CreatesFile()
{
using (var file = TempFile.FromResource(Resources.tiny, ".wmv"))
Expand All @@ -44,7 +42,6 @@ public void ExtractMp3Audio_CreatesFile()
}

[Test]
[Category("RequiresFfmpeg")]
public void ExtractOggAudio_CreatesFile()
{
using (var file = TempFile.FromResource(Resources.tiny, ".wmv"))
Expand All @@ -56,7 +53,6 @@ public void ExtractOggAudio_CreatesFile()
}

[Test]
[Category("RequiresFfmpeg")]
public void ChangeNumberOfAudioChannels_CreatesFile()
{
using (var file = TempFile.FromResource(Resources._2Channel, ".wav"))
Expand All @@ -68,7 +64,6 @@ public void ChangeNumberOfAudioChannels_CreatesFile()
}

[Test]
[Category("RequiresFfmpeg")]
public void MakeLowQualityCompressedAudio_CreatesFile()
{
using (var file = TempFile.FromResource(Resources.tiny, ".wmv"))
Expand All @@ -79,20 +74,58 @@ public void MakeLowQualityCompressedAudio_CreatesFile()
var outputPath = originalAudioPath.Replace("mp3", "low.mp3");
FFmpegRunner.MakeLowQualityCompressedAudio(originalAudioPath, outputPath, new ConsoleProgress());
Assert.IsTrue(File.Exists(outputPath));
System.Diagnostics.Process.Start(outputPath);

var mediaInfoOrig = FFProbe.Analyse(file.Path);
var mediaInfo = FFProbe.Analyse(outputPath);

// Validate resolution and bit rate
Assert.That(mediaInfo.PrimaryVideoStream, Is.Null);
Assert.That(mediaInfo.PrimaryAudioStream, Is.Not.Null);
Assert.That(mediaInfo.AudioStreams.Count, Is.EqualTo(1));
Assert.That(mediaInfo.PrimaryAudioStream.Channels, Is.EqualTo(1));
Assert.That(mediaInfo.Format.BitRate, Is.LessThan(mediaInfoOrig.Format.BitRate));
Assert.That(mediaInfo.PrimaryAudioStream.SampleRateHz, Is.EqualTo(8000));
try
{
RobustFile.Delete(outputPath);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}

[Test]
[Category("RequiresFfmpeg")]
public void MakeLowQualitySmallVideo_CreatesFile()
{
using (var file = TempFile.FromResource(Resources.tiny, ".wmv"))
{
var outputPath = file.Path.Replace("wmv", "low.wmv");
FFmpegRunner.MakeLowQualitySmallVideo(file.Path, outputPath, 0, new ConsoleProgress());
Assert.IsTrue(File.Exists(outputPath));
System.Diagnostics.Process.Start(outputPath);

var mediaInfoOrig = FFProbe.Analyse(file.Path);
var mediaInfo = FFProbe.Analyse(outputPath);

// Validate resolution and bit rate
Assert.That(mediaInfo.PrimaryVideoStream, Is.Not.Null);
Assert.That(mediaInfo.VideoStreams.Count, Is.EqualTo(1));
Assert.That(mediaInfo.PrimaryAudioStream, Is.Not.Null);
Assert.That(mediaInfo.AudioStreams.Count, Is.EqualTo(1));
Assert.That(mediaInfo.PrimaryVideoStream.Width, Is.EqualTo(160));
Assert.That(mediaInfo.PrimaryVideoStream.Height, Is.EqualTo(120));
Assert.That(mediaInfo.Format.BitRate, Is.LessThan(mediaInfoOrig.Format.BitRate));
try
{
// When running the by-hand test, the default media player might leave this
// locked, so this cleanup will fail.
RobustFile.Delete(outputPath);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
}
Expand Down
29 changes: 8 additions & 21 deletions SIL.Media.Tests/MediaInfoTests.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
using System;
using NUnit.Framework;
using SIL.IO;
using SIL.Media.Tests.Properties;

namespace SIL.Media.Tests
{
/// <summary>
/// All these tests are skipped on TeamCity (even if you remove this category) because SIL.Media.Tests compiles to an exe,
/// and the project that builds libpalaso on TeamCity (build/Palaso.proj, task Test) invokes RunNUnitTC which
/// selects the test assemblies using Include="$(RootDir)/output/$(Configuration)/*.Tests.dll" which excludes exes.
/// I have not tried to verify that all of these tests would actually have problems on TeamCity, but it seemed
/// helpful to document in the usual way that they are not, in fact, run there.
/// </summary>
[Category("SkipOnTeamCity")]
[Category("RequiresFFprobe")]
[TestFixture]
public class MediaInfoTests
{
[OneTimeSetUp]
public void CheckRequirements()
{
if (!MediaInfo.HaveNecessaryComponents)
Assert.Ignore(MediaInfo.MissingComponentMessage);
{
if (Environment.GetEnvironmentVariable("CI") == null)
Assert.Ignore(MediaInfo.MissingComponentMessage);
else
Assert.Fail("On CI build using GHA, FFMpeg should have been installed before running tests.");
}
}

[Test]
[Category("RequiresFFprobe")]
public void HaveNecessaryComponents_ReturnsTrue()
{
Assert.IsTrue(MediaInfo.HaveNecessaryComponents);
}

[Test]
[Category("RequiresFFprobe")]
public void VideoInfo_Duration_Correct()
{
using (var file = TempFile.FromResource(Resources.tiny, ".wmv"))
Expand All @@ -43,7 +40,6 @@ public void VideoInfo_Duration_Correct()
}

[Test]
[Category("RequiresFFprobe")]
public void VideoInfo_Encoding_Correct()
{
using (var file = TempFile.FromResource(Resources.tiny, ".wmv"))
Expand All @@ -54,7 +50,6 @@ public void VideoInfo_Encoding_Correct()
}

[Test]
[Category("RequiresFFprobe")]
public void VideoInfo_Resolution_Correct()
{
using (var file = TempFile.FromResource(Resources.tiny, ".wmv"))
Expand All @@ -65,7 +60,6 @@ public void VideoInfo_Resolution_Correct()
}

[Test]
[Category("RequiresFFprobe")]
public void VideoInfo_FramesPerSecond_Correct()
{
using (var file = TempFile.FromResource(Resources.tiny, ".wmv"))
Expand All @@ -77,7 +71,6 @@ public void VideoInfo_FramesPerSecond_Correct()
}

[Test]
[Category("RequiresFFprobe")]
public void AudioInfo_Duration_Correct()
{
using (var file = TempFile.FromResource(Resources.finished, ".wav"))
Expand All @@ -89,7 +82,6 @@ public void AudioInfo_Duration_Correct()


[Test]
[Category("RequiresFFprobe")]
public void AudioInfo_SampleFrequency_Correct()
{
using (var file = TempFile.FromResource(Resources.finished, ".wav"))
Expand All @@ -100,7 +92,6 @@ public void AudioInfo_SampleFrequency_Correct()
}

[Test]
[Category("RequiresFFprobe")]
public void AudioInfo_Channels_Correct()
{
using (var file = TempFile.FromResource(Resources.finished, ".wav"))
Expand All @@ -111,7 +102,6 @@ public void AudioInfo_Channels_Correct()
}

[Test]
[Category("RequiresFFprobe")]
public void AudioInfo_BitDepth_Correct()
{
using (var file = TempFile.FromResource(Resources.finished, ".wav"))
Expand All @@ -122,7 +112,6 @@ public void AudioInfo_BitDepth_Correct()
}

[Test]
[Category("RequiresFFprobe")]
public void AudioInfo_H4N24BitStereoBitDepth_Correct()
{
using (var file = TempFile.FromResource(Resources._24bitH4NSample, ".wav"))
Expand All @@ -133,14 +122,12 @@ public void AudioInfo_H4N24BitStereoBitDepth_Correct()
}

[Test]
[Category("RequiresFFprobe")]
public void GetMediaInfo_AudioFile_VideoInfoAndImageInfoAreNull()
{
using (var file = TempFile.FromResource(Resources.finished,".wav"))
{
var info =MediaInfo.GetInfo(file.Path);
Assert.IsNull(info.Video);
//Assert.IsNull(info.Image);
}
}

Expand Down
Loading
Loading