From patchwork Wed Dec 3 15:19:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taras Kondratiuk X-Patchwork-Id: 41856 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 CBA7825E66 for ; Wed, 3 Dec 2014 15:19:36 +0000 (UTC) Received: by mail-la0-f71.google.com with SMTP id s18sf9688201lam.10 for ; Wed, 03 Dec 2014 07:19:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references: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=CUvdk/GbVEo4h7dvXx/6Vz4cIYq4ISMO1sLIRaLuDYo=; b=FUMKcN3y2dagSG7lo4Idt2uzTVSCu9/ZxF3C2Mrb4k+nltRofUUz1lkGu/b7VEX5Fv 8T7GdkJfZraeau6oenWE75WlodraTCeM5Tiqn6bECvOgATOVV+w/LgU/epylEJC5pa/A UbUd4KGtRKQMaWtiGnlxNX9a7dM0kzRLPiK4en1WEPp7wbMTMytjp56ANrXxOHRueu7a yCb3BRY0w96xFNOoXnVuoUj0hx/Il26l5EO6JPIsu6CCyuw7bjGyVjrFX4VdUvNhc3u8 /rYiIV8hEYh+GNfoxBtgz/NOqzxQ5hRI8bdU5YSXTnrieFYjZmHiEhnwHWKtsQbrhyMq AkiQ== X-Gm-Message-State: ALoCoQnkF2kwUj05WnGvlpMxZchABPBvfLH0H8VB3+aR8ar6e3LBN5upDZewcbp6yl7eft1eJGHL X-Received: by 10.112.43.65 with SMTP id u1mr344739lbl.16.1417619975661; Wed, 03 Dec 2014 07:19:35 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.116.48 with SMTP id jt16ls168449lab.44.gmail; Wed, 03 Dec 2014 07:19:35 -0800 (PST) X-Received: by 10.152.6.97 with SMTP id z1mr4929901laz.4.1417619975457; Wed, 03 Dec 2014 07:19:35 -0800 (PST) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id pm1si9440773lbb.52.2014.12.03.07.19.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Dec 2014 07:19:35 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by mail-lb0-f172.google.com with SMTP id u10so12519597lbd.17 for ; Wed, 03 Dec 2014 07:19:35 -0800 (PST) X-Received: by 10.152.43.12 with SMTP id s12mr4606956lal.67.1417619975337; Wed, 03 Dec 2014 07:19:35 -0800 (PST) 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.184.201 with SMTP id ew9csp682692lbc; Wed, 3 Dec 2014 07:19:34 -0800 (PST) X-Received: by 10.140.19.9 with SMTP id 9mr8603696qgg.98.1417619973513; Wed, 03 Dec 2014 07:19:33 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id 98si4036552qgc.95.2014.12.03.07.19.32 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 03 Dec 2014 07:19:33 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XwBiF-0006dH-SD; Wed, 03 Dec 2014 15:19:31 +0000 Received: from mail-wg0-f53.google.com ([74.125.82.53]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XwBi6-0006cp-6O for lng-odp@lists.linaro.org; Wed, 03 Dec 2014 15:19:22 +0000 Received: by mail-wg0-f53.google.com with SMTP id l18so19831435wgh.26 for ; Wed, 03 Dec 2014 07:19:16 -0800 (PST) X-Received: by 10.180.77.79 with SMTP id q15mr101012337wiw.8.1417619956538; Wed, 03 Dec 2014 07:19:16 -0800 (PST) Received: from uglx0153363.synapse.com ([195.238.92.128]) by mx.google.com with ESMTPSA id h8sm37509940wiy.17.2014.12.03.07.19.15 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Dec 2014 07:19:15 -0800 (PST) From: Taras Kondratiuk To: lng-odp@lists.linaro.org Date: Wed, 3 Dec 2014 17:19:01 +0200 Message-Id: <1417619942-14233-2-git-send-email-taras.kondratiuk@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1417619942-14233-1-git-send-email-taras.kondratiuk@linaro.org> References: <1417619942-14233-1-git-send-email-taras.kondratiuk@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv5 1/2] platform: debug: replace fprintf() with odp_override_log() X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 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-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: taras.kondratiuk@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.217.172 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 ODP application may want to override default ODP logging behaviour and use custom logging function. Add a weak odp_override_log() function for this purpose instead of default fprintf(). Signed-off-by: Taras Kondratiuk Reviewed-by: Bill Fischofer Reviewed-by: Mike Holmes --- platform/linux-generic/Makefile.am | 3 +- platform/linux-generic/include/api/odp_debug.h | 44 +++++++++++++++++------- platform/linux-generic/odp_weak.c | 23 +++++++++++++ 3 files changed, 56 insertions(+), 14 deletions(-) create mode 100644 platform/linux-generic/odp_weak.c diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index e709700..cc78de3 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -75,4 +75,5 @@ __LIB__libodp_la_SOURCES = \ odp_thread.c \ odp_ticketlock.c \ odp_time.c \ - odp_timer.c + odp_timer.c \ + odp_weak.c diff --git a/platform/linux-generic/include/api/odp_debug.h b/platform/linux-generic/include/api/odp_debug.h index e853be4..aa99e29 100644 --- a/platform/linux-generic/include/api/odp_debug.h +++ b/platform/linux-generic/include/api/odp_debug.h @@ -14,6 +14,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { @@ -81,61 +82,78 @@ typedef enum odp_log_level { } odp_log_level_e; /** - * ODP default LOG macro. + * ODP log function + * + * Instead of direct prints to stdout/stderr all logging in ODP implementation + * should be done via this function or its wrappers. + * ODP platform MUST provide a default *weak* implementation of this function. + * Application MAY override the function if needed by providing a strong + * function. + * + * @param[in] level Log level + * @param[in] fmt printf-style message format + * + * @return The number of characters logged if succeeded. Otherwise returns + * a negative number. + */ +extern int odp_override_log(odp_log_level_e level, const char *fmt, ...); + +/** + * ODP LOG macro. */ #define ODP_LOG(level, fmt, ...) \ do { \ switch (level) { \ case ODP_LOG_ERR: \ - fprintf(stderr, "%s:%d:%s():" fmt, __FILE__, \ + odp_override_log(level, "%s:%d:%s():" fmt, __FILE__, \ __LINE__, __func__, ##__VA_ARGS__); \ break; \ case ODP_LOG_DBG: \ if (ODP_DEBUG_PRINT == 1) \ - fprintf(stderr, "%s:%d:%s():" fmt, __FILE__, \ + odp_override_log(level, "%s:%d:%s():" fmt, __FILE__, \ __LINE__, __func__, ##__VA_ARGS__); \ break; \ case ODP_LOG_PRINT: \ - fprintf(stdout, " " fmt, ##__VA_ARGS__); \ + odp_override_log(level, " " fmt, ##__VA_ARGS__); \ break; \ case ODP_LOG_ABORT: \ - fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \ + odp_override_log(level, "%s:%d:%s(): " fmt, __FILE__, \ __LINE__, __func__, ##__VA_ARGS__); \ abort(); \ break; \ case ODP_LOG_UNIMPLEMENTED: \ - fprintf(stderr, \ + odp_override_log(level, \ "%s:%d:The function %s() is not implemented\n" \ fmt, __FILE__, __LINE__, __func__, ##__VA_ARGS__); \ break; \ default: \ - fprintf(stderr, "Unknown LOG level"); \ + odp_override_log(level, "Unknown LOG level"); \ break;\ } \ } while (0) /** - * Printing macro, which prints output when the application - * calls one of the ODP APIs specifically for dumping internal data. + * Log print message when the application calls one of the ODP APIs + * specifically for dumping internal data. */ #define ODP_PRINT(fmt, ...) \ ODP_LOG(ODP_LOG_PRINT, fmt, ##__VA_ARGS__) /** - * Debug printing macro, which prints output when DEBUG flag is set. + * Log debug message if ODP_DEBUG_PRINT flag is set. */ #define ODP_DBG(fmt, ...) \ ODP_LOG(ODP_LOG_DBG, fmt, ##__VA_ARGS__) /** - * Print output to stderr (file, line and function). + * Log error message. */ #define ODP_ERR(fmt, ...) \ ODP_LOG(ODP_LOG_ERR, fmt, ##__VA_ARGS__) /** - * Print output to stderr (file, line and function), - * then abort. + * Log abort message and then stop execution (by default call abort()). + * This function should not return. */ #define ODP_ABORT(fmt, ...) \ ODP_LOG(ODP_LOG_ABORT, fmt, ##__VA_ARGS__) diff --git a/platform/linux-generic/odp_weak.c b/platform/linux-generic/odp_weak.c new file mode 100644 index 0000000..fccbc3f --- /dev/null +++ b/platform/linux-generic/odp_weak.c @@ -0,0 +1,23 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include +#include + +ODP_WEAK_SYMBOL int odp_override_log(odp_log_level_e level ODP_UNUSED, + const char *fmt, ...) +{ + va_list args; + int r; + + va_start(args, fmt); + r = vfprintf(stderr, fmt, args); + va_end(args); + + return r; +}