From patchwork Sat May 2 13:11:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Holmes X-Patchwork-Id: 47915 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 63DCC20553 for ; Sat, 2 May 2015 13:11:33 +0000 (UTC) Received: by wixv7 with SMTP id v7sf24609509wix.0 for ; Sat, 02 May 2015 06:11:32 -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: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=4yP+2jMp6iG8WDPBCTgFayggKEtPBfOryQkHEnCKq0s=; b=FWQvdBMAyQTkuwK5a4JXdN69ufEs2beeJDkNZeJBZdd2QnrFoqgiDt5w46YUfyRGkF fWB9EIemaq217iw71Qo0e8x5r3kJQoisAV6RYIk2wccCizKc9OYemK6m51twp7m7/8qp reIVDe7cDZg0s12MTRV43Er9/w3Grov2nU0XkuAJXdHSFjITmm26+XBjZ03s/gFFxHO1 xApd9tN04lfYMJiMiSlRPNHrawGViZqjlqfCxBATyL9ZsAHxc958ubeLFgIDEeeU9YAD kTbMoVx4P5ZAuYLkLloFo5pFovcTNSMFl4m0rVvgWJNMwnuYGpn5q1HamuNzEk99SWVV uf3Q== X-Gm-Message-State: ALoCoQnkVES9ejks/ERUjLi94jbm98zj67VEhwYEzxGiJaO6s5+/t5ZyxzrrkWgXAqQ64Lq+CLHN X-Received: by 10.112.142.170 with SMTP id rx10mr12233040lbb.12.1430572292647; Sat, 02 May 2015 06:11:32 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.2.9 with SMTP id 9ls679796laq.89.gmail; Sat, 02 May 2015 06:11:32 -0700 (PDT) X-Received: by 10.112.220.34 with SMTP id pt2mr12167753lbc.81.1430572292494; Sat, 02 May 2015 06:11:32 -0700 (PDT) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id uh8si6041055lac.136.2015.05.02.06.11.32 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 May 2015 06:11:32 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by labbd9 with SMTP id bd9so78943857lab.2 for ; Sat, 02 May 2015 06:11:32 -0700 (PDT) X-Received: by 10.112.204.72 with SMTP id kw8mr12176751lbc.88.1430572292311; Sat, 02 May 2015 06:11:32 -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.67.65 with SMTP id l1csp781003lbt; Sat, 2 May 2015 06:11:31 -0700 (PDT) X-Received: by 10.140.147.143 with SMTP id 137mr17541625qht.7.1430572290669; Sat, 02 May 2015 06:11:30 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id k39si7638976qgd.40.2015.05.02.06.11.29; Sat, 02 May 2015 06:11:30 -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 531DA61FD5; Sat, 2 May 2015 13:11:29 +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=-0.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,URIBL_BLACK,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 9376E61F5E; Sat, 2 May 2015 13:11:22 +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 4E92161FD0; Sat, 2 May 2015 13:11:15 +0000 (UTC) Received: from mail-qc0-f176.google.com (mail-qc0-f176.google.com [209.85.216.176]) by lists.linaro.org (Postfix) with ESMTPS id 2753761F5E for ; Sat, 2 May 2015 13:11:14 +0000 (UTC) Received: by qcbgu10 with SMTP id gu10so13551655qcb.2 for ; Sat, 02 May 2015 06:11:14 -0700 (PDT) X-Received: by 10.55.21.221 with SMTP id 90mr27816672qkv.44.1430572273947; Sat, 02 May 2015 06:11:13 -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 i137sm16554779qhc.49.2015.05.02.06.11.13 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 02 May 2015 06:11:13 -0700 (PDT) From: Mike Holmes To: lng-odp@lists.linaro.org Date: Sat, 2 May 2015 09:11:07 -0400 Message-Id: <1430572267-929-1-git-send-email-mike.holmes@linaro.org> X-Mailer: git-send-email 2.1.4 X-Topics: patch Subject: [lng-odp] [PATCH v2] 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.46 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 --- v2 alphabetic list order configure.ac | 19 +++++++++-- test/Makefile.am | 5 ++- test/helper/.gitignore | 4 +++ test/helper/Makefile.am | 25 ++++++++++++++ test/helper/odp_process.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++ test/helper/odp_thread.c | 79 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 214 insertions(+), 3 deletions(-) create mode 100644 test/helper/.gitignore create mode 100644 test/helper/Makefile.am create mode 100644 test/helper/odp_process.c create mode 100644 test/helper/odp_thread.c diff --git a/configure.ac b/configure.ac index d20bad2..e4a088f 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 test/helper], + [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 @@ -280,11 +294,12 @@ AC_CONFIG_FILES([Makefile pkgconfig/libodp.pc platform/Makefile platform/linux-generic/Makefile - test/Makefile test/api_test/Makefile + test/helper/Makefile + test/Makefile + test/miscellaneous/Makefile test/performance/Makefile test/validation/Makefile - test/miscellaneous/Makefile ]) AC_SEARCH_LIBS([timer_create],[rt posix4]) diff --git a/test/Makefile.am b/test/Makefile.am index 2ba8008..ba7b907 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,4 +1,7 @@ -SUBDIRS = api_test performance miscellaneous +SUBDIRS = api_test \ + helper \ + performance \ + miscellaneous if cunit_support SUBDIRS += validation diff --git a/test/helper/.gitignore b/test/helper/.gitignore new file mode 100644 index 0000000..fe65f30 --- /dev/null +++ b/test/helper/.gitignore @@ -0,0 +1,4 @@ +*.trs +*.log +odp_process +odp_thread diff --git a/test/helper/Makefile.am b/test/helper/Makefile.am new file mode 100644 index 0000000..f330533 --- /dev/null +++ b/test/helper/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/test/helper/odp_process.c b/test/helper/odp_process.c new file mode 100644 index 0000000..3483549 --- /dev/null +++ b/test/helper/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/test/helper/odp_thread.c b/test/helper/odp_thread.c new file mode 100644 index 0000000..04c6b1e --- /dev/null +++ b/test/helper/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; +}