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

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

Loading…
Cancel
Save