linked_test.go (1741B)
1 //go:build linux && cgo 2 3 package test 4 5 import ( 6 "bytes" 7 "testing" 8 9 "git.sr.ht/~jackmordaunt/nativeaudio" 10 ) 11 12 // TestLinkedMatchesSubprocess compares the linked backend against the 13 // ffmpeg binary installed on the same machine. 14 // 15 // The reference PCM checked into this directory ages: it was produced by 16 // one ffmpeg, and a later one decodes the same file to a different amount 17 // of trailing silence. This comparison cannot age, because both sides 18 // come from the same install and move together. It is also the only 19 // check that would notice the linked backend drifting away from the tool 20 // it is meant to be equivalent to, which a frozen reference stops being 21 // able to see once the two have diverged for unrelated reasons. 22 func TestLinkedMatchesSubprocess(t *testing.T) { 23 for _, name := range []string{"compressed.m4a", "mixkit-game-level-music-689.wav"} { 24 t.Run(name, func(t *testing.T) { 25 reference, rf, err := nativeaudio.FFmpegLoad(name) 26 if err != nil { 27 t.Fatalf("decoding with the ffmpeg binary: %v", err) 28 } 29 linked, lf, err := newDecoder(t).DecodeFile(name) 30 if err != nil { 31 t.Fatalf("decoding with the linked backend: %v", err) 32 } 33 if lf != rf { 34 t.Fatalf("format mismatch: linked %+v, ffmpeg %+v", lf, rf) 35 } 36 // Worth reporting but not worth failing over: the binary is 37 // free to apply defaults the library API does not, so the two 38 // are held to the same tolerance as any other pair of decoders. 39 t.Logf("byte-identical: %v (linked %d bytes, ffmpeg %d bytes)", 40 bytes.Equal(linked, reference), len(linked), len(reference)) 41 if !equal(t, linked, reference, lf.Channels*lf.BytesPerSample) { 42 t.Fatalf("the linked backend disagrees with the ffmpeg binary") 43 } 44 }) 45 } 46 }