diff --git a/tests/Makefile.am b/tests/Makefile.am index c9187e45..e1f4ba5f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -83,6 +83,7 @@ check_PROGRAMS = \ test_dm_e2e \ test_dm_media \ test_dm_worker \ + test_attachment \ test_call \ test_call_headless \ test_radio \ @@ -191,6 +192,8 @@ test_reality_config_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/transport_l test_reality_config_LDADD = $(LIBUTUN) $(CRYPTO_LIBS) $(COMMON_LIBS) test_dm_SOURCES = test_dm.c +test_attachment_SOURCES = test_attachment.c +test_attachment_LDADD = $(LIBUTUN) $(CRYPTO_LIBS) $(COMMON_LIBS) test_dm_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/transport_layer -I$(top_srcdir)/lib test_dm_LDADD = $(LIBUTUN) $(CRYPTO_LIBS) $(COMMON_LIBS) diff --git a/tests/test_dm_worker.c b/tests/test_dm_worker.c index b9c28486..4f08d7b8 100644 --- a/tests/test_dm_worker.c +++ b/tests/test_dm_worker.c @@ -82,6 +82,13 @@ static void heartbeat(void* arg) { if (!t->heartbeat) { DEBUG_ERROR(DEBUG_CATEGORY_DM, "heartbeat allocation failed"); uasync_stop(t->ua); } } +struct cancellation_test { int worked, calls, error; }; +static void cancellation_work(void* arg) { ((struct cancellation_test*)arg)->worked = 1; } +static void cancellation_done(void* arg, int error) { + struct cancellation_test* test = arg; + test->calls++; test->error = error; +} + int main(void) { debug_config_init(); debug_set_level(DEBUG_LEVEL_ERROR); struct worker_test t = {0}; @@ -93,7 +100,14 @@ int main(void) { if (!t.completed) uasync_mainloop(t.ua); if (t.heartbeat) uasync_cancel_timeout(t.ua, t.heartbeat); int ok = t.completed && !t.result && t.beats >= 10; - media_async_destroy(t.ma); uasync_destroy(t.ua, 0); + media_async_destroy(t.ma); + struct cancellation_test cancellation = {0}; + t.ma = media_async_create(); + media_async_submit(t.ma, t.ua, cancellation_work, &cancellation, cancellation_done, &cancellation); + media_async_destroy(t.ma); /* Join worker и отмена уже posted completion до poll. */ + uasync_poll(t.ua, 0); + ok = ok && cancellation.worked && cancellation.calls == 1 && cancellation.error == MEDIA_ASYNC_CANCELLED; + uasync_destroy(t.ua, 0); printf("test_dm_worker: 8MiB encrypt/decrypt, runs=%u heartbeat=%u max_gap=%.1fms %s\n", t.encryptions, t.beats, t.max_gap / 10.0, ok ? "PASS" : "FAIL"); return !ok;