From patchwork Mon Jun 29 11:12:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 50407 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 89BE8218E4 for ; Mon, 29 Jun 2015 11:12:47 +0000 (UTC) Received: by laar3 with SMTP id r3sf44627520laa.1 for ; Mon, 29 Jun 2015 04:12:46 -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=UXvpyRb6tHuWVKqZzy360KjBpNXdloy5I5lUhDHQR3M=; b=BTWC++IBYW2mwmf3xXeQjdwfmfik6mAieOmS1V2hd1oRoBejDTHmiotyAsBFufyA+f WwN1AJfIeRnDuwanwC/XRCAItA2a4c7we8jmKkd/9BhW/a2q+6CbcFf1PxixxWk07tUr KScj19bqDPH4+MF/2yo4igirB0xxTKCkUUyxceWVthJTDJHtvysurb1VgPNj1jK/v7mM JuVdWHUpZVp7tUkIQDgLq/2u4iqudoYDcMHADZJPPTrz/ldg8AAUf4gKrH0ur2fBntcJ wi/X6ak4WAJtPu6MMDaGrVJrDHqtvhRbjAB3q8eovHrtrXku+5uiFV+nLHmZbEQ0pHC1 ZveA== X-Gm-Message-State: ALoCoQk6p8Z6Z48N/NATtVdOPwjg2wxzrb1vNkBZgbaQw811z8IWruDmO20PXoAWvzSOP9JbBhVN X-Received: by 10.152.120.69 with SMTP id la5mr9930759lab.7.1435576366153; Mon, 29 Jun 2015 04:12:46 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.129 with SMTP id s1ls825441las.89.gmail; Mon, 29 Jun 2015 04:12:45 -0700 (PDT) X-Received: by 10.112.185.100 with SMTP id fb4mr13684871lbc.79.1435576365868; Mon, 29 Jun 2015 04:12:45 -0700 (PDT) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com. [209.85.215.41]) by mx.google.com with ESMTPS id o5si34771730lae.1.2015.06.29.04.12.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Jun 2015 04:12:45 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by lagh6 with SMTP id h6so49237064lag.2 for ; Mon, 29 Jun 2015 04:12:45 -0700 (PDT) X-Received: by 10.112.220.7 with SMTP id ps7mr13517239lbc.72.1435576365725; Mon, 29 Jun 2015 04:12:45 -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 hn6csp1628706lbb; Mon, 29 Jun 2015 04:12:44 -0700 (PDT) X-Received: by 10.55.33.203 with SMTP id f72mr30103347qki.52.1435576364338; Mon, 29 Jun 2015 04:12:44 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id b9si31831383qkh.16.2015.06.29.04.12.43; Mon, 29 Jun 2015 04:12:44 -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 6767661DBD; Mon, 29 Jun 2015 11:12:43 +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_H3, RCVD_IN_MSPIKE_WL, 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 CA80B61B67; Mon, 29 Jun 2015 11:12:37 +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 0D48F61B68; Mon, 29 Jun 2015 11:12:36 +0000 (UTC) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com [209.85.215.43]) by lists.linaro.org (Postfix) with ESMTPS id BB86161B62 for ; Mon, 29 Jun 2015 11:12:34 +0000 (UTC) Received: by lagc2 with SMTP id c2so5415244lag.3 for ; Mon, 29 Jun 2015 04:12:33 -0700 (PDT) X-Received: by 10.112.144.69 with SMTP id sk5mr13598903lbb.6.1435576353470; Mon, 29 Jun 2015 04:12:33 -0700 (PDT) Received: from erachmi-VirtualBox.ki.sw.ericsson.se (c-83-233-90-46.cust.bredband2.com. [83.233.90.46]) by mx.google.com with ESMTPSA id xl7sm10700494lbb.42.2015.06.29.04.12.31 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 29 Jun 2015 04:12:32 -0700 (PDT) From: Christophe Milard To: anders.roxell@linaro.org, mike.holmes@linaro.org, stuart.haslam@linaro.org, maxim.uvarov@linaro.org Date: Mon, 29 Jun 2015 13:12:21 +0200 Message-Id: <1435576341-29930-1-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 1.9.1 X-Topics: patch Cc: lng-odp@lists.linaro.org Subject: [lng-odp] [PATCHv2] validation: new functions to register hooks 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: christophe.milard@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.41 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 Two new functions are introduced in odp_cunit_common.c: odp_cunit_register_global_init() is to be used to register test executable init function (overloading the default ODP init performed). odp_cunit_register_global_term() is to be used to register test executable terminason function (overloading the default ODP term). These two functions should be used instead of overloading the default weak symbol. Overloading the weak symbol still works, but is planned for removal. The usage of these register functions enables the init/term functions to be part of the library for the tested module. Signed-off-by: Christophe Milard Reviewed-by: Stuart Haslam --- since v1: Changes according to Stuart review test/validation/common/odp_cunit_common.c | 37 +++++++++++++++++++++++++++++-- test/validation/common/odp_cunit_common.h | 24 +++++++++++--------- 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/test/validation/common/odp_cunit_common.c b/test/validation/common/odp_cunit_common.c index 2b83ae6..67938f2 100644 --- a/test/validation/common/odp_cunit_common.c +++ b/test/validation/common/odp_cunit_common.c @@ -11,6 +11,15 @@ /* Globals */ static odph_linux_pthread_t thread_tbl[MAX_WORKERS]; +/* + * global init/term functions which may be registered + * defaults to functions performing odp init/term. + */ +static struct { + int (*global_init_ptr)(void); + int (*global_term_ptr)(void); +} global_init_term = {tests_global_init, tests_global_term}; + /** create test thread */ int odp_cunit_thread_create(void *func_ptr(void *), pthrd_arg *arg) { @@ -62,6 +71,26 @@ ODP_WEAK_SYMBOL int tests_global_term(void) return 0; } +/* + * register tests_global_init and tests_global_term functions. + * If some of these functions are not registered, the defaults functions + * (tests_global_init() and tests_global_term()) defined above are used. + * One should use these register functions when defining these hooks. + * (overloading the weak symbol above is obsolete and will be removed in + * the future). + * Note that passing NULL as function pointer is valid and will simply + * prevent the default (odp init/term) to be done. + */ +void odp_cunit_register_global_init(int (*func_init_ptr)(void)) +{ + global_init_term.global_init_ptr = func_init_ptr; +} + +void odp_cunit_register_global_term(int (*func_term_ptr)(void)) +{ + global_init_term.global_term_ptr = func_term_ptr; +} + int odp_cunit_run(CU_SuiteInfo testsuites[]) { int ret; @@ -69,7 +98,9 @@ int odp_cunit_run(CU_SuiteInfo testsuites[]) printf("\tODP API version: %s\n", odp_version_api_str()); printf("\tODP implementation version: %s\n", odp_version_impl_str()); - if (0 != tests_global_init()) + /* call test executable init hook, if any */ + if (global_init_term.global_init_ptr && + ((*global_init_term.global_init_ptr)() != 0)) return -1; CU_set_error_action(CUEA_ABORT); @@ -83,7 +114,9 @@ int odp_cunit_run(CU_SuiteInfo testsuites[]) CU_cleanup_registry(); - if (0 != tests_global_term()) + /* call test executable terminason hook, if any */ + if (global_init_term.global_term_ptr && + ((*global_init_term.global_term_ptr)() != 0)) return -1; return (ret) ? -1 : 0; diff --git a/test/validation/common/odp_cunit_common.h b/test/validation/common/odp_cunit_common.h index 3b4d9fb..bfb4cbf 100644 --- a/test/validation/common/odp_cunit_common.h +++ b/test/validation/common/odp_cunit_common.h @@ -43,21 +43,25 @@ typedef struct { /** create thread fro start_routine function */ extern int odp_cunit_thread_create(void *func_ptr(void *), pthrd_arg *arg); extern int odp_cunit_thread_exit(pthrd_arg *); + /** - * Global tests initialization. - * - * Initialize global resources needed by all testsuites. Default weak definition - * do nothing. Test application can override it by defining a strong version. - * The function is called by the common main() just after ODP global/local - * initialization. + * Global tests initialization/termination. * - * @note: This function is a workaround for Crypto test and other applications - * should try not to use it, because it will complicate migration to a - * single test application in future. Normally each testsuite have to - * prepare its environment in its own init function. + * Initialize global resources needed by the test executable. Default + * definition does ODP init / term (both global and local). + * Test executables can override it by calling one of the register function + * below (or by defining a strong version, but this is deprecated). + * The functions are called at the very beginning and very end of the test + * execution. Passing NULL to odp_cunit_register_global_init() and/or + * odp_cunit_register_global_term() is legal and will simply prevent the + * default (ODP init/term) to be done. */ extern int tests_global_init(void); extern int tests_global_term(void); +void odp_cunit_register_global_init(int (*func_init_ptr)(void)); + +void odp_cunit_register_global_term(int (*func_term_ptr)(void)); + #endif /* ODP_CUNICT_COMMON_H */