-
Notifications
You must be signed in to change notification settings - Fork 250
/
loopback_audio_linux_test.go
152 lines (131 loc) · 4.27 KB
/
loopback_audio_linux_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//go:build linux
package main
import (
"fmt"
"strings"
"testing"
"github.com/mcuadros/go-defaults"
)
func TestLoopbackAudio(t *testing.T) {
setup(t)
devicePaths := []string{
fmt.Sprintf("/dev/snd/controlC%d", config.LoopbackAudioDeviceNumber),
fmt.Sprintf("/dev/snd/pcmC%dD0c", config.LoopbackAudioDeviceNumber),
fmt.Sprintf("/dev/snd/pcmC%dD0p", config.LoopbackAudioDeviceNumber),
fmt.Sprintf("/dev/snd/pcmC%dD1c", config.LoopbackAudioDeviceNumber),
fmt.Sprintf("/dev/snd/pcmC%dD1p", config.LoopbackAudioDeviceNumber),
}
payload := GenericWorkerPayload{
Command: [][]string{
{"ls", "-l", devicePaths[0]},
{"ls", "-l", devicePaths[1]},
{"ls", "-l", devicePaths[2]},
{"ls", "-l", devicePaths[3]},
{"ls", "-l", devicePaths[4]},
},
MaxRunTime: 30,
Features: FeatureFlags{
LoopbackAudio: true,
},
}
defaults.SetDefaults(&payload)
td := testTask(t)
td.Scopes = append(td.Scopes, "generic-worker:loopback-audio")
_ = submitAndAssert(t, td, payload, "completed", "completed")
logText := LogText(t)
if !strings.Contains(logText, "crw-rw----") {
t.Fatalf("Expected log to contain 'crw-rw----', but it didn't\n%s", logText)
}
}
func TestIncorrectLoopbackAudioScopes(t *testing.T) {
setup(t)
payload := GenericWorkerPayload{
Command: returnExitCode(0),
MaxRunTime: 30,
Features: FeatureFlags{
LoopbackAudio: true,
},
}
defaults.SetDefaults(&payload)
td := testTask(t)
// don't set any scopes
_ = submitAndAssert(t, td, payload, "exception", "malformed-payload")
logtext := LogText(t)
if !strings.Contains(logtext, "generic-worker:loopback-audio:"+td.ProvisionerID+"/"+td.WorkerType) || !strings.Contains(logtext, "generic-worker:loopback-audio") {
t.Fatalf("Expected log file to contain missing scopes, but it didn't\n%s", logtext)
}
}
func TestLoopbackAudioNotOwnedByTaskUser(t *testing.T) {
setup(t)
devicePaths := []string{
fmt.Sprintf("/dev/snd/controlC%d", config.LoopbackAudioDeviceNumber),
fmt.Sprintf("/dev/snd/pcmC%dD0c", config.LoopbackAudioDeviceNumber),
fmt.Sprintf("/dev/snd/pcmC%dD0p", config.LoopbackAudioDeviceNumber),
fmt.Sprintf("/dev/snd/pcmC%dD1c", config.LoopbackAudioDeviceNumber),
fmt.Sprintf("/dev/snd/pcmC%dD1p", config.LoopbackAudioDeviceNumber),
}
payload := GenericWorkerPayload{
Command: [][]string{
{"ls", "-l", devicePaths[0]},
},
MaxRunTime: 30,
Features: FeatureFlags{
// run once with loopback audio feature enabled,
// so that we can ensure tbe device has been created
// on the host
LoopbackAudio: true,
},
}
defaults.SetDefaults(&payload)
td := testTask(t)
td.Scopes = append(td.Scopes, "generic-worker:loopback-audio")
_ = submitAndAssert(t, td, payload, "completed", "completed")
payload = GenericWorkerPayload{
Command: [][]string{
{"ls", "-l", devicePaths[0]},
},
MaxRunTime: 30,
Features: FeatureFlags{
// run a second time with the feature disabled
// to test that the device is not owned by the
// task user
LoopbackAudio: false,
},
}
defaults.SetDefaults(&payload)
td = testTask(t)
td.Scopes = append(td.Scopes, "generic-worker:loopback-audio")
_ = submitAndAssert(t, td, payload, "completed", "completed")
logtext := LogText(t)
if strings.Contains(logtext, "task_") {
t.Fatalf("Was not expecting `ls` on device %s to be owned by task user, but it was", devicePaths[0])
}
}
func TestLoopbackAudioInvalidDeviceNumber(t *testing.T) {
setup(t)
config.LoopbackAudioDeviceNumber = 32
devicePaths := []string{
fmt.Sprintf("/dev/snd/controlC%d", config.LoopbackAudioDeviceNumber),
fmt.Sprintf("/dev/snd/pcmC%dD0c", config.LoopbackAudioDeviceNumber),
fmt.Sprintf("/dev/snd/pcmC%dD0p", config.LoopbackAudioDeviceNumber),
fmt.Sprintf("/dev/snd/pcmC%dD1c", config.LoopbackAudioDeviceNumber),
fmt.Sprintf("/dev/snd/pcmC%dD1p", config.LoopbackAudioDeviceNumber),
}
payload := GenericWorkerPayload{
Command: [][]string{
{"ls", "-l", devicePaths[0]},
{"ls", "-l", devicePaths[1]},
{"ls", "-l", devicePaths[2]},
{"ls", "-l", devicePaths[3]},
{"ls", "-l", devicePaths[4]},
},
MaxRunTime: 30,
Features: FeatureFlags{
LoopbackAudio: true,
},
}
defaults.SetDefaults(&payload)
td := testTask(t)
td.Scopes = append(td.Scopes, "generic-worker:loopback-audio")
_ = submitAndAssert(t, td, payload, "exception", "internal-error")
}