[v2,1/5] app/test-mp: add multiprocess test
Checks
Commit Message
This commit adds a test scenario that initiates multiple processes
concurrently. These processes attach to the same shared heap, with an
automatic detection mechanism to identify the primary process.
Signed-off-by: Artemy Kovalyov <artemyko@nvidia.com>
---
app/meson.build | 1 +
app/test-mp/main.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
app/test-mp/meson.build | 8 ++++++++
app/test-mp/run.sh | 40 +++++++++++++++++++++++++++++++++++++
4 files changed, 101 insertions(+)
create mode 100644 app/test-mp/main.c
create mode 100644 app/test-mp/meson.build
create mode 100755 app/test-mp/run.sh
Comments
On 3/7/2024 8:01 AM, Artemy Kovalyov wrote:
> This commit adds a test scenario that initiates multiple processes
> concurrently. These processes attach to the same shared heap, with an
> automatic detection mechanism to identify the primary process.
>
> Signed-off-by: Artemy Kovalyov <artemyko@nvidia.com>
> ---
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
@@ -30,6 +30,7 @@ apps = [
'test-flow-perf',
'test-gpudev',
'test-mldev',
+ 'test-mp',
'test-pipeline',
'test-pmd',
'test-regex',
new file mode 100644
@@ -0,0 +1,52 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <rte_malloc.h>
+#include <rte_launch.h>
+#include <rte_eal.h>
+#include <rte_cycles.h>
+#include <rte_test.h>
+
+static rte_atomic32_t g_count;
+
+static int
+done(const struct rte_mp_msg *msg __rte_unused, const void *arg __rte_unused)
+{
+ rte_atomic32_dec(&g_count);
+ return 0;
+}
+
+int
+main(int argc, char **argv)
+{
+ void *p;
+ int ret;
+
+ ret = rte_eal_init(argc, argv);
+ RTE_TEST_ASSERT(ret >= 0, "init failed\n");
+
+ rte_atomic32_set(&g_count, atoi(argv[++ret]));
+
+ if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+ ret = rte_mp_action_register("done", done);
+ RTE_TEST_ASSERT_SUCCESS(ret, "register action failed\n");
+ }
+
+ p = rte_malloc(NULL, 0x1000000, 0x1000);
+ RTE_TEST_ASSERT_NOT_NULL(p, "allocation failed\n");
+
+ if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+ uint64_t timeout = rte_rdtsc() + 5 * rte_get_tsc_hz();
+
+ while (rte_atomic32_read(&g_count) > 0)
+ RTE_TEST_ASSERT(rte_rdtsc() < timeout, "timeout\n");
+ } else {
+ struct rte_mp_msg msg = { .name = "done" };
+
+ rte_mp_sendmsg(&msg);
+ }
+
+ rte_eal_cleanup();
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,8 @@
+if is_windows
+ build = false
+ reason = 'not supported on Windows'
+ subdir_done()
+endif
+
+sources = files('main.c')
+deps = ['eal']
new file mode 100755
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+logdir=/tmp/dpdk_test_mp
+repeat=1
+lastcore=$(($(nproc) - 1))
+log=1
+
+while getopts p:r:lL:d op; do case $op in
+ p) lastcore=$OPTARG ;;
+ r) repeat=$OPTARG ;;
+ L) logdir=$OPTARG ;;
+ l) log=0 ;;
+ d) debug=1 ;;
+esac done
+shift $((OPTIND-1))
+
+test=$1
+logpath=$logdir/$(date +%y%m%d-%H%M%S)
+
+rm -f core.*
+pkill dpdk-test-mp
+
+for j in $(seq $repeat) ; do
+ [ $log ] && mkdir -p $logpath/$j
+ pids=()
+ for i in $(seq 0 $lastcore) ; do
+ args="-l $i --file-prefix=dpdk1 --proc-type=auto"
+ if [ $debug ] ; then
+ args="$args --log-level=lib.eal:8"
+ fi
+ if [ $log ] ; then
+ $test $args $lastcore >$logpath/$j/$i.log 2>&1 &
+ else
+ $test $args $lastcore &
+ fi
+ pids+=($!)
+ done
+ wait ${pids[@]} || { echo iteration $j failed ; break ; }
+ echo iteration $j passed
+done