CXXFLAGS = -std=c++2a -Wall -g `pkg-config --cflags dbus-1`
LDLIBS = -pthread `pkg-config --libs dbus-1`
-all: libdbus-p2p-client libdbus-p2p-server
+all: libdbus-p2p-client libdbus-p2p-server libdbus-p2p-common
gcc $(CFLAGS) -pg -o benchmark/pipe $(DFTSRC) benchmark/pipe.c $(LDFLAGS)
gcc $(CFLAGS) -o benchmark/socket $(DFTSRC) benchmark/socket.c $(LDFLAGS)
gcc $(CFLAGS) -o benchmark/sharedmem $(DFTSRC) benchmark/sharedmem.c $(LDFLAGS)
libdbus-p2p-server: benchmark/libdbus-p2p-server.cpp
$(CXX) $(CXXFLAGS) $^ $(LDLIBS) -o benchmark/$@
+libdbus-p2p-common: benchmark/libdbus-p2p-common.cpp benchmark/libdbus-p2p-client.cpp benchmark/libdbus-p2p-server.cpp
+ $(CXX) $(CXXFLAGS) -DLIBDBUS_P2P_COMMON $^ $(LDLIBS) -o benchmark/$@
+
install:
make -C policychecker install
mkdir -p $(DESTDIR)/usr/bin
cp benchmark/p2p-gdbus $(DESTDIR)/usr/bin/p2p-gdbus
cp benchmark/libdbus-p2p-server $(DESTDIR)/usr/bin/libdbus-p2p-server
cp benchmark/libdbus-p2p-client $(DESTDIR)/usr/bin/libdbus-p2p-client
+ cp benchmark/libdbus-p2p-common $(DESTDIR)/usr/bin/libdbus-p2p-common
cp benchmark/libdbus $(DESTDIR)/usr/bin/libdbus
cp benchmark/dbus-tools-batch-tests.sh $(DESTDIR)/usr/bin/dbus-tools-batch-tests.sh
static constexpr const char * TEST_NAME = "org.test";
static constexpr const char * TEST_METHOD = "Perf";
-struct run_opts {
+struct client_run_opts {
bool show_help = false;
/* The value is mostly conforming to other test's default,
std::string sock_path = "/tmp/test";
};
-run_opts get_opt (int argc, char ** argv)
+static client_run_opts get_opt (int argc, char ** argv)
{
- run_opts ret;
+ client_run_opts ret;
int opt;
while ((opt = getopt(argc, argv, "d:m:t:p:h")) != -1)
return ret;
}
-void show_help (const char * argv0)
+static void show_help (const char * argv0)
{
std::cout << "Usage: " << argv0
<< " [-m message_size] "
;
}
-int main (int argc, char ** argv)
+int main_client (int argc, char ** argv)
{
- run_opts opt = get_opt (argc, argv);
+ client_run_opts opt = get_opt (argc, argv);
if (opt.show_help) {
show_help (argv[0]);
return EXIT_SUCCESS;
}
+
+#ifndef LIBDBUS_P2P_COMMON
+int main(int argc, char ** argv) { return main_client(argc, argv); }
+#endif
--- /dev/null
+/* MIT License
+ *
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is furnished
+ * to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE. */
+
+#include <unistd.h>
+
+#include <chrono>
+#include <cstring>
+#include <iostream>
+#include <thread>
+
+using namespace std::chrono_literals;
+
+extern int main_server(int, char **);
+extern int main_client(int, char **);
+
+int main(int argc, char ** argv)
+{
+ /* Runs the server and the client from the same binary via fork.
+ * This is in an attempt to make the test behave more like the
+ * other tests which work that way. See the server and the client
+ * for their argument format and other implementation details. */
+
+ int separator = 0;
+ while (strcmp(argv[separator], "--") && separator < argc)
+ ++separator;
+ if (separator == argc) {
+ std::cerr << "Usage: " << argv[0] << " serverargs -- clientargs" << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ int child_pid = fork ();
+ if (child_pid == -1) {
+ std::cerr << "fork failed! " << errno << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ if (child_pid == 0) {
+ argc = separator;
+ argv[separator] = nullptr;
+
+ return main_server (argc, argv);
+ } else {
+ /* Let the server set up,
+ * even under heavy load. */
+ std::this_thread::sleep_for (10s);
+
+ /* NB: argv[0] stays (program name), while
+ * argv[argc] is still part of the array. */
+ for (int i = 1; i <= argc - separator; ++i)
+ argv[i] = argv[i + separator];
+ return main_client (argc - separator, argv);
+ }
+}
static constexpr const char * TEST_PATH = "/org/test";
-struct run_opts {
+struct server_run_opts {
bool show_help = false;
/* With the default client settings, this is 5 seconds' worth of
std::optional <std::string> raw_data_path = std::nullopt;
};
-run_opts get_opt (int argc, char ** argv)
+static server_run_opts get_opt (int argc, char ** argv)
{
- run_opts ret;
+ server_run_opts ret;
int opt;
while ((opt = getopt(argc, argv, ":ihp:r:t:w")) != -1)
static DBusObjectPathVTable vtable;
- conn_with_metadata (const run_opts & ro, DBusConnection * c)
+ conn_with_metadata (const server_run_opts & ro, DBusConnection * c)
: total_time (0)
, total_count (0)
, min_time (std::numeric_limits <uint64_t> :: max ())
, nullptr
};
-void show_help (const char * argv0)
+static void show_help (const char * argv0)
{
std::cout << "Usage: " << argv0
<< " [-t warmup_tries]"
;
}
-void dispatch_connection (conn_with_metadata & cwm, bool busy_wait)
+static void dispatch_connection (conn_with_metadata & cwm, bool busy_wait)
{
if (dbus_connection_read_write_dispatch (cwm.conn.get(), busy_wait ? 0 : -1))
return;
}
};
-void read_from_watch (DBusWatch * watch, bool wait_infinitely)
+static void read_from_watch (DBusWatch * watch, bool wait_infinitely)
{
struct pollfd pfd;
pfd.events = POLLIN;
std::exit (EXIT_SUCCESS);
}
-int main (int argc, char ** argv)
+int main_server (int argc, char ** argv)
{
std::signal (SIGINT , sig_handler);
std::signal (SIGTERM, sig_handler);
- run_opts opt = get_opt (argc, argv);
+ server_run_opts opt = get_opt (argc, argv);
if (opt.show_help) {
show_help (argv[0]);
return EXIT_SUCCESS;
}
+#ifndef LIBDBUS_P2P_COMMON
+int main(int argc, char ** argv) { return main_server(argc, argv); }
+#endif
%{_bindir}/libdbus
%{_bindir}/libdbus-p2p-server
%{_bindir}/libdbus-p2p-client
+%{_bindir}/libdbus-p2p-common
%{_bindir}/p2p-gdbus
%{_bindir}/dbus-tools-batch-tests.sh