From patchwork Tue May 12 21:32:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Holmes X-Patchwork-Id: 48415 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 599532121F for ; Tue, 12 May 2015 21:32:37 +0000 (UTC) Received: by wiz9 with SMTP id 9sf6060919wiz.3 for ; Tue, 12 May 2015 14:32:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:delivered-to:from:to:date :message-id:cc:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list; bh=Xjsv47L4rzzd+sdn41/YLezNSsVMAQBQq0Jbu/wgXzM=; b=ihEPv5rCnrDy7F/FWNjjBOgN7AlQDyjks6g88WHWOC5+dSfdKvYDeSZnGam+2iyg9x MV7DgNrfiVv2oUwcxQNSQo3vKqjt176G0Hi9Xn7hzGCKhRSUaNFIbJXq6OwNFm/tGvFv i7dYmxvIwaxKBtBm0ky9vS5OQep8x5+k0Ak3OwdBzZM9BMpWFge513RvOkghit5X00cx pIWK8HlYddesFt643hvgycOso75Mxj/R7IR/kSEkiGuOiHg4AWj8TtkBhBUO6JmLir7m uvs5lpTudw//AWPBmlbicEjyRfJ3qcthCvsBgfLqwsC7ykynIF8f7Ocg8MiwjmmxsdNw trNg== X-Gm-Message-State: ALoCoQnBUINYYVhabA+SnvV8F+i8E3JZn7365IQw7nRKhnxthEZQvQuPLK2gjbQbtniWw4NgqwIa X-Received: by 10.112.160.197 with SMTP id xm5mr11866949lbb.15.1431466356678; Tue, 12 May 2015 14:32:36 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.41 with SMTP id t9ls98982lal.82.gmail; Tue, 12 May 2015 14:32:36 -0700 (PDT) X-Received: by 10.112.124.166 with SMTP id mj6mr13642801lbb.104.1431466356366; Tue, 12 May 2015 14:32:36 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id g1si11100446lbs.32.2015.05.12.14.32.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 May 2015 14:32:36 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by laat2 with SMTP id t2so15914095laa.1 for ; Tue, 12 May 2015 14:32:36 -0700 (PDT) X-Received: by 10.112.182.4 with SMTP id ea4mr13816089lbc.35.1431466356221; Tue, 12 May 2015 14:32:36 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp161163lbb; Tue, 12 May 2015 14:32:35 -0700 (PDT) X-Received: by 10.55.27.42 with SMTP id b42mr37352540qkb.53.1431466354449; Tue, 12 May 2015 14:32:34 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id f199si14683579qhc.20.2015.05.12.14.32.33; Tue, 12 May 2015 14:32:34 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Received: by lists.linaro.org (Postfix, from userid 109) id 5947A61E88; Tue, 12 May 2015 21:32:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from ip-10-142-244-252.ec2.internal (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id D05D761E77; Tue, 12 May 2015 21:32:30 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 1425561E81; Tue, 12 May 2015 21:32:21 +0000 (UTC) Received: from mail-qg0-f45.google.com (mail-qg0-f45.google.com [209.85.192.45]) by lists.linaro.org (Postfix) with ESMTPS id F03F761E7D for ; Tue, 12 May 2015 21:32:18 +0000 (UTC) Received: by qgdy78 with SMTP id y78so11837962qgd.0 for ; Tue, 12 May 2015 14:32:18 -0700 (PDT) X-Received: by 10.140.44.69 with SMTP id f63mr22184539qga.88.1431466338683; Tue, 12 May 2015 14:32:18 -0700 (PDT) Received: from mike-desktop.?.holmesfamily.ws (c-98-221-136-245.hsd1.nj.comcast.net. [98.221.136.245]) by mx.google.com with ESMTPSA id o65sm14263512qge.34.2015.05.12.14.32.17 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 May 2015 14:32:17 -0700 (PDT) From: Mike Holmes To: christophe.milard@linaro.org Date: Tue, 12 May 2015 17:32:11 -0400 Message-Id: <1431466331-16931-1-git-send-email-mike.holmes@linaro.org> X-Mailer: git-send-email 2.1.4 X-Topics: patch Cc: lng-odp@lists.linaro.org Subject: [lng-odp] [PATCH] test: helper: add process and thread tests X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: mike.holmes@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 The helpers need to be tested independently from the ODP API, create a folder to contain helper tests, adding tests for process and thread creation. Signed-off-by: Mike Holmes Reviewed-by: Christophe Milard --- Makefile.am | 2 +- configure.ac | 16 +++++++++ helper/Makefile.am | 1 + helper/test/.gitignore | 4 +++ helper/test/Makefile.am | 25 ++++++++++++++ helper/test/odp_process.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++ helper/test/odp_thread.c | 79 +++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 helper/Makefile.am create mode 100644 helper/test/.gitignore create mode 100644 helper/test/Makefile.am create mode 100644 helper/test/odp_process.c create mode 100644 helper/test/odp_thread.c diff --git a/Makefile.am b/Makefile.am index 3f80a2a..cff83f7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ ACLOCAL_AMFLAGS=-I m4 AUTOMAKE_OPTIONS = foreign -SUBDIRS = doc platform example test +SUBDIRS = doc platform example test helper include $(top_srcdir)/aminclude.am diff --git a/configure.ac b/configure.ac index d20bad2..4146b20 100644 --- a/configure.ac +++ b/configure.ac @@ -138,6 +138,20 @@ AC_ARG_ENABLE([test-perf], AM_CONDITIONAL([test_perf], [test x$test_perf = xyes ]) ########################################################################## +# Enable/disable test-helper +########################################################################## +test_helper=no +AC_ARG_ENABLE([test-helper], + [ --enable-test-helper run test in helper/test], + [if test "x$enableval" = "xyes"; then + test_helper=yes + fi]) + +AM_CONDITIONAL([test_helper], [test x$test_helper = xyes ]) + +########################################################################## + +########################################################################## # Enable/disable test-cpp ########################################################################## test_cpp=no @@ -277,6 +291,8 @@ AC_CONFIG_FILES([Makefile example/ipsec/Makefile example/packet/Makefile example/timer/Makefile + helper/Makefile + helper/test/Makefile pkgconfig/libodp.pc platform/Makefile platform/linux-generic/Makefile diff --git a/helper/Makefile.am b/helper/Makefile.am new file mode 100644 index 0000000..02af5b3 --- /dev/null +++ b/helper/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = test diff --git a/helper/test/.gitignore b/helper/test/.gitignore new file mode 100644 index 0000000..fe65f30 --- /dev/null +++ b/helper/test/.gitignore @@ -0,0 +1,4 @@ +*.trs +*.log +odp_process +odp_thread diff --git a/helper/test/Makefile.am b/helper/test/Makefile.am new file mode 100644 index 0000000..f330533 --- /dev/null +++ b/helper/test/Makefile.am @@ -0,0 +1,25 @@ +include $(top_srcdir)/test/Makefile.inc + +AM_CFLAGS += -I$(srcdir)/common +AM_LDFLAGS += -static + +TESTS_ENVIRONMENT = ODP_PLATFORM=${with_platform} TEST_DIR=${builddir} + +EXECUTABLES = odp_thread \ + odp_process + +COMPILE_ONLY = + +TESTSCRIPTS = + +if test_helper +TESTS = $(EXECUTABLES) $(TESTSCRIPTS) +endif + +dist_bin_SCRIPTS = + +bin_PROGRAMS = $(EXECUTABLES) $(COMPILE_ONLY) + + +dist_odp_thread_SOURCES = odp_thread.c +dist_odp_process_SOURCES = odp_process.c diff --git a/helper/test/odp_process.c b/helper/test/odp_process.c new file mode 100644 index 0000000..3483549 --- /dev/null +++ b/helper/test/odp_process.c @@ -0,0 +1,85 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include + +#define NUMBER_WORKERS 16 /* 0 = max */ + +static void *worker_fn(void *arg TEST_UNUSED) +{ + /* depend on the odp helper to call odp_init_local */ + printf("Worker thread on CPU %d\n", odp_cpu_id()); + + return 0; +} + +/* Create additional dataplane processes */ +int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED) +{ + odp_cpumask_t cpu_mask; + int num_workers; + int cpu; + char cpumaskstr[ODP_CPUMASK_STR_SIZE]; + int ret; + odph_linux_process_t proc[NUMBER_WORKERS]; + + if (odp_init_global(NULL, NULL)) { + LOG_ERR("Error: ODP global init failed.\n"); + exit(EXIT_FAILURE); + } + + if (odp_init_local()) { + LOG_ERR("Error: ODP local init failed.\n"); + exit(EXIT_FAILURE); + } + + /* discover how many processes this system can support */ + num_workers = odph_linux_cpumask_default(&cpu_mask, NUMBER_WORKERS); + if (num_workers < NUMBER_WORKERS) { + printf("System can only support %d processes and not the %d requested\n", + num_workers, NUMBER_WORKERS); + } + + /* generate a summary for the user */ + (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, sizeof(cpumaskstr)); + printf("default cpu mask: %s\n", cpumaskstr); + printf("default num worker processes: %i\n", num_workers); + + cpu = odp_cpumask_first(&cpu_mask); + printf("the first CPU: %i\n", cpu); + + /* reserve cpu 0 for the control plane so remove it from the default mask */ + odp_cpumask_clr(&cpu_mask, 0); + num_workers = odp_cpumask_count(&cpu_mask); + (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, sizeof(cpumaskstr)); + printf("new cpu mask: %s\n", cpumaskstr); + printf("new num worker processes: %i\n\n", num_workers); + + /* Fork worker processes */ + ret = odph_linux_process_fork_n(proc, &cpu_mask); + + if (ret < 0) { + LOG_ERR("Fork workers failed %i\n", ret); + return -1; + } + + if (ret == 0) { + /* Child process */ + worker_fn(NULL); + } else { + /* Parent process */ + odph_linux_process_wait_n(proc, num_workers); + + if (odp_term_global()) { + LOG_ERR("Error: ODP global term failed.\n"); + exit(EXIT_FAILURE); + } + } + + return 0; +} diff --git a/helper/test/odp_thread.c b/helper/test/odp_thread.c new file mode 100644 index 0000000..04c6b1e --- /dev/null +++ b/helper/test/odp_thread.c @@ -0,0 +1,79 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include + +#define NUMBER_WORKERS 16 +static void *worker_fn(void *arg TEST_UNUSED) +{ + /* depend on the odp helper to call odp_init_local */ + + printf("Worker thread on CPU %d\n", odp_cpu_id()); + + /* depend on the odp helper to call odp_term_local */ + + return 0; +} + +/* Create additional dataplane threads */ +int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED) +{ + odph_linux_pthread_t thread_tbl[NUMBER_WORKERS]; + odp_cpumask_t cpu_mask; + int num_workers; + int cpu; + char cpumaskstr[ODP_CPUMASK_STR_SIZE]; + + if (odp_init_global(NULL, NULL)) { + LOG_ERR("Error: ODP global init failed.\n"); + exit(EXIT_FAILURE); + } + + if (odp_init_local()) { + LOG_ERR("Error: ODP local init failed.\n"); + exit(EXIT_FAILURE); + } + + /* discover how many threads this system can support */ + num_workers = odph_linux_cpumask_default(&cpu_mask, NUMBER_WORKERS); + if (num_workers < NUMBER_WORKERS) { + printf("System can only support %d threads and not the %d requested\n", + num_workers, NUMBER_WORKERS); + } + + /* generate a summary for the user */ + (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, sizeof(cpumaskstr)); + printf("default cpu mask: %s\n", cpumaskstr); + printf("default num worker threads: %i\n", num_workers); + + cpu = odp_cpumask_first(&cpu_mask); + printf("the first CPU: %i\n", cpu); + + /* reserve cpu 0 for the control plane so remove it from the default mask */ + odp_cpumask_clr(&cpu_mask, 0); + num_workers = odp_cpumask_count(&cpu_mask); + (void)odp_cpumask_to_str(&cpu_mask, cpumaskstr, sizeof(cpumaskstr)); + printf("new cpu mask: %s\n", cpumaskstr); + printf("new num worker threads: %i\n\n", num_workers); + + odph_linux_pthread_create(&thread_tbl[0], &cpu_mask, worker_fn, NULL); + + odph_linux_pthread_join(thread_tbl, num_workers); + + if (odp_term_local()) { + LOG_ERR("Error: ODP local term failed.\n"); + exit(EXIT_FAILURE); + } + + if (odp_term_global()) { + LOG_ERR("Error: ODP global term failed.\n"); + exit(EXIT_FAILURE); + } + + return 0; +}