pull/22796/head
deanlee 4 years ago
parent 6b87276f93
commit 2f7992db28
  1. 10
      selfdrive/ui/soundd.cc

@ -99,12 +99,15 @@ public:
SubMaster sm;
};
const int test_loop_cnt = 2;
void test_sound() {
PubMaster pm({"controlsState"});
const int DT_CTRL = 10; // ms
for (int i = 0; i < test_loop_cnt; ++i) {
for (auto &[alert, fn, loops] : sound_list) {
printf("testing %s\n", qPrintable(fn));
for (int i = 0; i < 1000 / DT_CTRL; ++i) {
for (int j = 0; j < 1000 / DT_CTRL; ++j) {
MessageBuilder msg;
auto cs = msg.initEvent().initControlsState();
cs.setAlertSound(alert);
@ -113,13 +116,14 @@ void test_sound() {
QThread::msleep(DT_CTRL);
}
}
}
QThread::currentThread()->quit();
}
void run_test(Sound *sound) {
static QMap<AudibleAlert, int> stats;
for (auto i = sound->sounds.constBegin(); i != sound->sounds.constEnd(); ++i) {
QObject::connect(i.value().first, &QSoundEffect::playingChanged, [s=i.value().first, a = i.key()]() {
QObject::connect(i.value().first, &QSoundEffect::playingChanged, [s = i.value().first, a = i.key()]() {
if (s->isPlaying()) {
stats[a]++;
}
@ -130,7 +134,7 @@ void run_test(Sound *sound) {
QObject::connect(t, &QThread::started, [=]() { test_sound(); });
QObject::connect(t, &QThread::finished, [&]() {
for (int n : stats) {
assert(n == 1);
assert(n == test_loop_cnt);
}
qApp->quit();
});

Loading…
Cancel
Save