aboutsummaryrefslogtreecommitdiff
path: root/test/regress_main.c
diff options
context:
space:
mode:
authorCy Schubert <cy@FreeBSD.org>2023-11-14 23:02:42 +0000
committerCy Schubert <cy@FreeBSD.org>2023-11-14 23:02:42 +0000
commit5223d1d95fddcef6f9a36e264a5800bd907ade8b (patch)
tree818b1eba912c588e39058586485699385c3179fe /test/regress_main.c
parentcbc620a473ce23d882ba3e9f91ec0c6c12dcd239 (diff)
Diffstat (limited to 'test/regress_main.c')
-rw-r--r--test/regress_main.c68
1 files changed, 66 insertions, 2 deletions
diff --git a/test/regress_main.c b/test/regress_main.c
index 44e291119a3d..266561214b8e 100644
--- a/test/regress_main.c
+++ b/test/regress_main.c
@@ -33,6 +33,14 @@
#include <fcntl.h>
#endif
+/* move_pthread_to_realtime_scheduling_class() */
+#ifdef EVENT__HAVE_MACH_MACH_H
+#include <mach/mach.h>
+#endif
+#ifdef EVENT__HAVE_MACH_MACH_TIME_H
+#include <mach/mach_time.h>
+#endif
+
#if defined(__APPLE__) && defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
#if (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1060 && \
__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1070)
@@ -81,10 +89,12 @@
#include "event2/event-config.h"
#include "regress.h"
+#include "regress_thread.h"
#include "tinytest.h"
#include "tinytest_macros.h"
#include "../iocp-internal.h"
#include "../event-internal.h"
+#include "../evthread-internal.h"
struct evutil_weakrand_state test_weakrand_state;
@@ -186,18 +196,65 @@ ignore_log_cb(int s, const char *msg)
{
}
-static void *
+/**
+ * Put into the real time scheduling class for better timers latency.
+ * https://developer.apple.com/library/archive/technotes/tn2169/_index.html#//apple_ref/doc/uid/DTS40013172-CH1-TNTAG6000
+ */
+#if defined(__APPLE__)
+static void move_pthread_to_realtime_scheduling_class(pthread_t pthread)
+{
+ mach_timebase_info_data_t info;
+ mach_timebase_info(&info);
+
+ const uint64_t NANOS_PER_MSEC = 1000000ULL;
+ double clock2abs =
+ ((double)info.denom / (double)info.numer) * NANOS_PER_MSEC;
+
+ thread_time_constraint_policy_data_t policy;
+ policy.period = 0;
+ policy.computation = (uint32_t)(5 * clock2abs); // 5 ms of work
+ policy.constraint = (uint32_t)(10 * clock2abs);
+ policy.preemptible = FALSE;
+
+ int kr = thread_policy_set(pthread_mach_thread_np(pthread),
+ THREAD_TIME_CONSTRAINT_POLICY,
+ (thread_policy_t)&policy,
+ THREAD_TIME_CONSTRAINT_POLICY_COUNT);
+ if (kr != KERN_SUCCESS) {
+ mach_error("thread_policy_set:", kr);
+ exit(1);
+ }
+}
+
+void thread_setup(THREAD_T pthread)
+{
+ move_pthread_to_realtime_scheduling_class(pthread);
+}
+#else /** \__APPLE__ */
+void thread_setup(THREAD_T pthread) {}
+#endif /** \!__APPLE__ */
+
+
+void *
basic_test_setup(const struct testcase_t *testcase)
{
struct event_base *base = NULL;
evutil_socket_t spair[2] = { -1, -1 };
struct basic_test_data *data = NULL;
+ thread_setup(THREAD_SELF());
+
#ifndef _WIN32
if (testcase->flags & TT_ENABLE_IOCP_FLAG)
return (void*)TT_SKIP;
#endif
+ if (testcase->flags & TT_ENABLE_DEBUG_MODE &&
+ !libevent_tests_running_in_debug_mode) {
+ event_enable_debug_mode();
+ libevent_tests_running_in_debug_mode = 1;
+ }
+
if (testcase->flags & TT_NEED_THREADS) {
if (!(testcase->flags & TT_FORK))
return NULL;
@@ -262,7 +319,7 @@ basic_test_setup(const struct testcase_t *testcase)
return data;
}
-static int
+int
basic_test_cleanup(const struct testcase_t *testcase, void *ptr)
{
struct basic_test_data *data = ptr;
@@ -384,6 +441,7 @@ struct testgroup_t testgroups[] = {
{ "iocp/", iocp_testcases },
{ "iocp/bufferevent/", bufferevent_iocp_testcases },
{ "iocp/listener/", listener_iocp_testcases },
+ { "iocp/http/", http_iocp_testcases },
#endif
#ifdef EVENT__HAVE_OPENSSL
{ "ssl/", ssl_testcases },
@@ -435,6 +493,7 @@ main(int argc, const char **argv)
#ifdef _WIN32
tinytest_skip(testgroups, "http/connection_retry");
tinytest_skip(testgroups, "http/https_connection_retry");
+ tinytest_skip(testgroups, "http/read_on_write_error");
#endif
#ifndef EVENT__DISABLE_THREAD_SUPPORT
@@ -454,6 +513,11 @@ main(int argc, const char **argv)
evutil_weakrand_seed_(&test_weakrand_state, 0);
+ if (getenv("EVENT_NO_FILE_BUFFERING")) {
+ setbuf(stdout, NULL);
+ setbuf(stderr, NULL);
+ }
+
if (tinytest_main(argc,argv,testgroups))
return 1;