test: add a helper to wait until a stable state

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2020-08-18 14:26:43 +10:00
parent a5ea7a6dd0
commit d65c678239
4 changed files with 39 additions and 21 deletions

View file

@ -214,10 +214,11 @@ peck_handle_eis_added(struct peck *peck, struct eis_event *e)
}
}
void
bool
peck_dispatch_eis(struct peck *peck)
{
struct eis *eis = peck->eis;
bool had_event = false;
log_debug(peck, "EIS Dispatch\n");
@ -255,6 +256,8 @@ peck_dispatch_eis(struct peck *peck)
if (!tristate_is_yes(process_event))
break;
had_event = true;
/* manual unref, _cleanup_ will take care of the real event */
eis_event_unref(e);
e = eis_get_event(eis);
@ -279,6 +282,8 @@ peck_dispatch_eis(struct peck *peck)
break;
}
}
return had_event;
}
static inline tristate
@ -301,10 +306,11 @@ peck_check_ei_added(struct peck *peck, struct ei_event *e)
return tristate_unset;
}
void
bool
peck_dispatch_ei(struct peck *peck)
{
struct ei *ei = peck->ei;
bool had_event = false;
log_debug(peck, "ei is dispatching\n");
@ -336,6 +342,8 @@ peck_dispatch_ei(struct peck *peck)
if (!tristate_is_yes(process_event))
break;
had_event = true;
/* manual unref, _cleanup_ will take care of the real event */
ei_event_unref(e);
e = ei_get_event(ei);
@ -352,6 +360,23 @@ peck_dispatch_ei(struct peck *peck)
break;
}
}
return had_event;
}
void
peck_dispatch_until_event(struct peck *peck)
{
bool eis, ei;
log_debug(peck, "dispatching until stable state >>>>>\n");
do {
eis = peck_dispatch_eis(peck);
ei = peck_dispatch_ei(peck);
} while (ei || eis);
log_debug(peck, "<<<<<\n");
}
void

View file

@ -102,10 +102,10 @@ peck_get_ei(struct peck *peck);
struct eis *
peck_get_eis(struct peck *peck);
void
bool
peck_dispatch_eis(struct peck *peck);
void
bool
peck_dispatch_ei(struct peck *peck);
struct peck *
@ -114,6 +114,9 @@ peck_unref(struct peck *peck);
DEFINE_TRIVIAL_CLEANUP_FUNC(struct peck*, peck_unref);
#define _cleanup_peck_ _cleanup_(peck_unrefp)
void
peck_dispatch_until_event(struct peck *peck);
void
peck_drain_eis(struct eis *eis);

View file

@ -33,8 +33,7 @@ test_ei_reject(const MunitParameter params[], void *user_data)
/* Client is immediately rejected */
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_REJECT_CLIENT);
peck_dispatch_ei(peck);
peck_dispatch_eis(peck);
peck_dispatch_until_event(peck);
/* Expect the client to get a disconnect event */
with_client(peck) {
@ -53,7 +52,7 @@ test_ei_reject_after_connect(const MunitParameter params[], void *user_data)
_cleanup_peck_ struct peck *peck = peck_new();
_cleanup_eis_client_ struct eis_client *client = NULL;
peck_dispatch_ei(peck);
peck_dispatch_until_event(peck);
with_server(peck) {
eis_dispatch(eis);
@ -92,8 +91,7 @@ test_ei_device_basics(const MunitParameter params[], void *user_data)
_cleanup_ei_device_ struct ei_device *device = NULL;
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_ACCEPT_ALL);
peck_dispatch_eis(peck);
peck_dispatch_ei(peck);
peck_dispatch_until_event(peck);
/* device creation and getters/setters test */
with_client(peck) {
@ -156,8 +154,7 @@ test_ei_device_add(const MunitParameter params[], void *user_data)
ei_device_add(device);
}
peck_dispatch_eis(peck);
peck_dispatch_ei(peck);
peck_dispatch_until_event(peck);
with_client(peck) {
_cleanup_ei_event_ struct ei_event *event = ei_get_event(ei);
@ -181,10 +178,7 @@ test_ei_device_add_drop_caps(const MunitParameter params[], void *user_data)
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_ACCEPT_ALL);
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_DROP_POINTER);
peck_dispatch_eis(peck);
peck_dispatch_ei(peck);
peck_dispatch_eis(peck);
peck_dispatch_ei(peck);
peck_dispatch_until_event(peck);
_cleanup_ei_device_ struct ei_device *device = NULL;
@ -224,10 +218,7 @@ test_ei_device_add_zero_caps(const MunitParameter params[], void *user_data)
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_ACCEPT_ALL);
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_DROP_POINTER);
peck_dispatch_eis(peck);
peck_dispatch_ei(peck);
peck_dispatch_eis(peck);
peck_dispatch_ei(peck);
peck_dispatch_until_event(peck);
_cleanup_ei_device_ struct ei_device *device = NULL;

View file

@ -62,8 +62,7 @@ eistest_name(const MunitParameter params[], void *user_data)
ei_configure_name(ei, "this name should not be used");
}
peck_dispatch_ei(peck);
peck_dispatch_eis(peck);
peck_dispatch_until_event(peck);
with_server(peck) {
_cleanup_eis_event_ struct eis_event *event = eis_get_event(eis);