Skip to content

Commit 594e7b1

Browse files
committed
Fix sysex handling
1 parent b381797 commit 594e7b1

31 files changed

+690
-366
lines changed

.github/workflows/test-mmedia.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103
enabled: 'true'
104104

105105
- name: Run unit tests
106-
continue-on-error: false
106+
continue-on-error: false
107107
shell: pwsh
108108
run: |
109109
dotnet test DryWetMidi.Tests/Melanchall.DryWetMidi.Tests.csproj --blame --blame-hang --blame-hang-timeout 5m --blame-hang-dump-type full --no-build --configuration ${{ vars.TEST_BUILD_CONFIGURATION || 'Release' }} --filter "(FullyQualifiedName~.Multimedia)" --framework ${{ steps.framework.outputs.tfm }} --verbosity normal --diag diagnostic.log --logger "console;verbosity=detailed" -p:SolutionDir="${{ github.workspace }}/"
@@ -116,8 +116,18 @@ jobs:
116116

117117
- name: Upload PlaybackTraces
118118
if: failure()
119+
continue-on-error: true
119120
uses: actions/upload-artifact@v4
120121
with:
121122
name: PlaybackTraces_${{ matrix.os }}_${{ matrix.framework }}_Attempt${{ github.run_attempt }}
122123
path: ${{ github.workspace }}/PlaybackTraces
124+
if-no-files-found: ignore
125+
126+
- name: Upload SysExTraces
127+
if: failure()
128+
continue-on-error: true
129+
uses: actions/upload-artifact@v4
130+
with:
131+
name: SysExTraces_${{ matrix.os }}_${{ matrix.framework }}_Attempt${{ github.run_attempt }}
132+
path: ${{ github.workspace }}/SysExTraces
123133
if-no-files-found: ignore

DryWetMidi.Tests/Multimedia/Clock/TickGenerator/Session/TickGeneratorSessionTests.cs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@ public sealed class TickGeneratorSessionTests
2323

2424
#if TEST
2525
[Test]
26-
public void CheckTickGeneratorSession_DisposeManually()
26+
public void CheckTickGeneratorSession_DisposeManually([Values(0, 50, 5000)] int waitAfterSessionCreatedMs)
2727
{
2828
var checkpoints = new TestCheckpoints();
2929

30-
TickGeneratorSessionApi.Api_OpenSession(
31-
out var rawHandle,
32-
out var errorCode);
33-
30+
var rawHandle = CreateTickGeneratorSessionHandle(waitAfterSessionCreatedMs);
3431
var handle = new TickGeneratorSessionHandle(rawHandle);
3532
handle.TestCheckpoints = checkpoints;
3633

@@ -48,29 +45,27 @@ public void CheckTickGeneratorSession_DisposeManually()
4845
}
4946

5047
[Test]
51-
public void CheckTickGeneratorSession_AbandonAndWaitForFinalizer()
48+
public void CheckTickGeneratorSession_AbandonAndWaitForFinalizer([Values(0, 50, 5000)] int waitAfterSessionCreatedMs)
5249
{
5350
var checkpoints = new TestCheckpoints();
5451

55-
CreateAndAbandonTickGeneratorSession(checkpoints);
52+
CreateAndAbandonTickGeneratorSession(checkpoints, waitAfterSessionCreatedMs);
5653

5754
GC.Collect();
5855
GC.WaitForPendingFinalizers();
5956
GC.Collect();
6057

6158
checkpoints.CheckCheckpointsReached(
62-
MidiDevicesSessionCheckpointNames.HandleFinalizerEntered,
63-
MidiDevicesSessionCheckpointNames.SessionClosedInHandleFinalizer);
59+
MidiDevicesSessionCheckpointNames.ReleaseHandleEntered,
60+
MidiDevicesSessionCheckpointNames.CloseSessionInReleaseHandle);
6461
}
6562

6663
[Test]
67-
public void CheckTickGeneratorSession_CloseViaApi()
64+
public void CheckTickGeneratorSession_CloseViaApi([Values(0, 50, 5000)] int waitAfterSessionCreatedMs)
6865
{
69-
TickGeneratorSessionApi.Api_OpenSession(
70-
out var sessionHandle,
71-
out var errorCode);
66+
var sessionHandle = CreateTickGeneratorSessionHandle(waitAfterSessionCreatedMs);
7267

73-
var result = TickGeneratorSessionApi.Api_CloseSession(sessionHandle, out errorCode);
68+
var result = TickGeneratorSessionApi.Api_CloseSession(sessionHandle, out var errorCode);
7469
ClassicAssert.AreEqual(
7570
TickGeneratorSessionApi.TGSESSION_CLOSERESULT.TGSESSION_CLOSERESULT_OK,
7671
result,
@@ -85,18 +80,34 @@ public void CheckTickGeneratorSession_CloseViaApi()
8580
#if TEST
8681
[MethodImpl(MethodImplOptions.NoInlining)]
8782
private void CreateAndAbandonTickGeneratorSession(
88-
TestCheckpoints checkpoints)
83+
TestCheckpoints checkpoints,
84+
int waitAfterSessionCreatedMs)
8985
{
90-
TickGeneratorSessionApi.Api_OpenSession(
91-
out var rawHandle,
92-
out var errorCode);
93-
86+
var rawHandle = CreateTickGeneratorSessionHandle(waitAfterSessionCreatedMs);
9487
var handle = new TickGeneratorSessionHandle(rawHandle);
9588
handle.TestCheckpoints = checkpoints;
9689

9790
// Don't dispose - let it go out of scope
9891
// Finalizer will run eventually
9992
}
93+
94+
private IntPtr CreateTickGeneratorSessionHandle(
95+
int waitAfterSessionCreatedMs)
96+
{
97+
var result = TickGeneratorSessionApi.Api_OpenSession(
98+
out var rawHandle,
99+
out var errorCode);
100+
101+
ClassicAssert.AreEqual(
102+
TickGeneratorSessionApi.TGSESSION_OPENRESULT.TGSESSION_OPENRESULT_OK,
103+
result,
104+
"Session was not opened successfully.");
105+
106+
if (waitAfterSessionCreatedMs > 0)
107+
WaitOperations.Wait(waitAfterSessionCreatedMs);
108+
109+
return rawHandle;
110+
}
100111
#endif
101112

102113
#endregion

DryWetMidi.Tests/Multimedia/InputDevice/InputDeviceTests.Common.cs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,20 @@ public void InputDeviceIsReleasedByDispose()
179179
ClassicAssert.DoesNotThrow(() => inputDevice.StartEventsListening());
180180

181181
checkpoints.CheckCheckpointsAreNotReached(
182-
InputDeviceCheckpointsNames.HandleFinalizerEntered,
183-
InputDeviceCheckpointsNames.DeviceDisconnectedInHandleFinalizer,
184-
InputDeviceCheckpointsNames.DeviceClosedInHandleFinalizer);
182+
InputDeviceCheckpointsNames.ReleaseHandleEntered,
183+
InputDeviceCheckpointsNames.DisconnectDeviceExecutedInReleaseHandle,
184+
InputDeviceCheckpointsNames.DisconnectDeviceSuccessInReleaseHandle,
185+
InputDeviceCheckpointsNames.CloseDeviceExecutedInReleaseHandle,
186+
InputDeviceCheckpointsNames.CloseDeviceSuccessInReleaseHandle);
185187

186188
inputDevice.Dispose();
187189

188190
checkpoints.CheckCheckpointsReached(
189-
InputDeviceCheckpointsNames.HandleFinalizerEntered,
190-
InputDeviceCheckpointsNames.DeviceDisconnectedInHandleFinalizer,
191-
InputDeviceCheckpointsNames.DeviceClosedInHandleFinalizer);
191+
InputDeviceCheckpointsNames.ReleaseHandleEntered,
192+
InputDeviceCheckpointsNames.DisconnectDeviceExecutedInReleaseHandle,
193+
InputDeviceCheckpointsNames.DisconnectDeviceSuccessInReleaseHandle,
194+
InputDeviceCheckpointsNames.CloseDeviceExecutedInReleaseHandle,
195+
InputDeviceCheckpointsNames.CloseDeviceSuccessInReleaseHandle);
192196
}
193197
}
194198

@@ -216,9 +220,11 @@ public void InputDeviceIsReleasedByFinalizer()
216220
var checkpoints = new TestCheckpoints();
217221

218222
checkpoints.CheckCheckpointsAreNotReached(
219-
InputDeviceCheckpointsNames.HandleFinalizerEntered,
220-
InputDeviceCheckpointsNames.DeviceDisconnectedInHandleFinalizer,
221-
InputDeviceCheckpointsNames.DeviceClosedInHandleFinalizer);
223+
InputDeviceCheckpointsNames.ReleaseHandleEntered,
224+
InputDeviceCheckpointsNames.DisconnectDeviceExecutedInReleaseHandle,
225+
InputDeviceCheckpointsNames.DisconnectDeviceSuccessInReleaseHandle,
226+
InputDeviceCheckpointsNames.CloseDeviceExecutedInReleaseHandle,
227+
InputDeviceCheckpointsNames.CloseDeviceSuccessInReleaseHandle);
222228

223229
ClassicAssert.IsTrue(openDevice(checkpoints), $"Can't open device on iteration {i}.");
224230

@@ -227,9 +233,11 @@ public void InputDeviceIsReleasedByFinalizer()
227233
GC.Collect();
228234

229235
checkpoints.CheckCheckpointsReached(
230-
InputDeviceCheckpointsNames.HandleFinalizerEntered,
231-
InputDeviceCheckpointsNames.DeviceDisconnectedInHandleFinalizer,
232-
InputDeviceCheckpointsNames.DeviceClosedInHandleFinalizer);
236+
InputDeviceCheckpointsNames.ReleaseHandleEntered,
237+
InputDeviceCheckpointsNames.DisconnectDeviceExecutedInReleaseHandle,
238+
InputDeviceCheckpointsNames.DisconnectDeviceSuccessInReleaseHandle,
239+
InputDeviceCheckpointsNames.CloseDeviceExecutedInReleaseHandle,
240+
InputDeviceCheckpointsNames.CloseDeviceSuccessInReleaseHandle);
233241
}
234242
}
235243
#endif

0 commit comments

Comments
 (0)