tevent: Test tevent_immediate performance
authorVolker Lendecke <vl@samba.org>
Wed, 27 Jul 2016 11:27:44 +0000 (13:27 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 17 May 2018 07:52:27 +0000 (09:52 +0200)
I found no way to add this to "skip" as a subtest of local.event, so I created
a separate suite.

Signed-off-by: Volker Lendecke <vl@samba.org>
lib/tevent/testsuite.c
selftest/skip
source4/torture/local/local.c

index 763afeb2891d934aaaa1ae0cace79f3bd7791faf..4c4d4700b1aebd95e3240b3cf2e3b7cdcd57f842 100644 (file)
@@ -699,6 +699,88 @@ static bool test_event_fd2(struct torture_context *tctx,
        return true;
 }
 
+struct immediate_perf_state {
+       pthread_mutex_t mutex;
+       struct timeval start;
+       uint64_t count;
+       bool done;
+};
+
+static void immediate_perf_handler(struct tevent_context *ev,
+                                  struct tevent_immediate *im,
+                                  void *private_data)
+{
+       struct immediate_perf_state *state = private_data;
+       int ret;
+
+#if 1
+       ret = pthread_mutex_lock(&state->mutex);
+       if (ret != 0) {
+               abort();
+       }
+
+       state->count += 1;
+
+       ret = pthread_mutex_unlock(&state->mutex);
+       if (ret != 0) {
+               abort();
+       }
+#else
+       state->count += 1;
+#endif
+       if ((state->count % 1000) == 0) {
+               struct timeval now = tevent_timeval_current();
+               struct timeval diff;
+               diff = tevent_timeval_until(&state->start, &now);
+
+               if (diff.tv_sec > 9) {
+                       state->done = true;
+                       return;
+               }
+       }
+
+       tevent_schedule_immediate(im, ev, immediate_perf_handler, state);
+}
+
+static bool test_event_context_immediate_perf(struct torture_context *test,
+                                             const void *test_data)
+{
+       const char *backend = test_data;
+       struct tevent_context *ev;
+       struct tevent_immediate *im;
+       struct immediate_perf_state state = {
+               .start = tevent_timeval_current()
+       };
+       int ret;
+
+       ret = pthread_mutex_init(&state.mutex, NULL);
+       torture_assert(test, ret == 0, "pthread_mutex_init failed");
+
+       ev = tevent_context_init_byname(test, backend);
+       if (ev == NULL) {
+               torture_comment(test, "event backend '%s' not supported\n",
+                               backend);
+               return true;
+       }
+
+       torture_comment(test, "backend '%s' - %s\n", backend, __FUNCTION__);
+
+       im = tevent_create_immediate(ev);
+       torture_assert(test, im != NULL, "tevent_create_immediate failed");
+
+       tevent_schedule_immediate(im, ev, immediate_perf_handler, &state);
+
+       while (!state.done) {
+               ret = tevent_loop_once(ev);
+               torture_assert(test, ret == 0, "tevent_loop_once failed");
+       }
+
+       torture_comment(test, "count=%"PRIu64"\n", state.count);
+
+       TALLOC_FREE(ev);
+       return true;
+}
+
 #ifdef HAVE_PTHREAD
 
 static pthread_mutex_t threaded_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -1569,3 +1651,15 @@ struct torture_suite *torture_local_event(TALLOC_CTX *mem_ctx)
 
        return suite;
 }
+
+struct torture_suite *torture_local_event_perf(TALLOC_CTX *mem_ctx)
+{
+       struct torture_suite *suite = torture_suite_create(
+               mem_ctx, "event_perf");
+
+       torture_suite_add_simple_tcase_const(suite, "immediate_perf",
+                                            test_event_context_immediate_perf,
+                                            NULL);
+
+       return suite;
+}
index dd60ab5a1fbe7eef44eff387d534d6a618c4265d..aac9851f49885cc46e59bde7496a4611982f6f05 100644 (file)
@@ -70,6 +70,7 @@
 ^samba3.smb2.scan                       # No tests
 ^samba3.smb2.oplock.levelii501         # No test yet
 ^samba3.rpc.samr.passwords.lockout\(ad_dc\) # No point running this version, it just waits 12 times longer the samba4 version of this test, covering the same code
+^samba4.local.event_perf
 ^samba4.base.iometer
 ^samba4.base.casetable
 ^samba4.base.nttrans
index d1c523bdc1f64411e18bcf93687622c88d5f6bdf..77ff291d0162d984c57e1166e1486752e3cd5975 100644 (file)
@@ -64,6 +64,7 @@
        torture_local_string_case,
        torture_local_compression,
        torture_local_event, 
+       torture_local_event_perf,
        torture_local_torture,
        torture_local_dbspeed, 
        torture_local_credentials,