Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp307205rbb; Sat, 24 Feb 2024 01:07:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW+xq/Fjb3RbaeGG3eVy1kLaNZdXPFb7/Qs0qgOTG3aLWI1/UNnfsLKuJZFHRV2DOKoefb6fUXEkgnJJ6O1TkD6GnaTsNa0oCeX1pLEVg== X-Google-Smtp-Source: AGHT+IE6PYrcQ+GJEcVHvjCC364ZFxJNPPKBD5irmd2f+YCulY0za9fDAdLXdkSN7wTzElgiIiAV X-Received: by 2002:aa7:cb45:0:b0:565:14dc:a503 with SMTP id w5-20020aa7cb45000000b0056514dca503mr1146038edt.32.1708765626489; Sat, 24 Feb 2024 01:07:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708765626; cv=pass; d=google.com; s=arc-20160816; b=afTfjuL8BaIWGDRS8xQ2ltCfLlaMzSOCrNMVUxneyoawY2mJLIIBC68iuZZm1Str9K bAZxf4jhI8+JegBE83p6gILfKUjECOMEfxv3EgxHcPIZDZG+C32vE2xhpqjV8gre3HnY NWcNTIquZ4YnZPXVwdNpamFveFf0BG2U8DYEy/SS8++wYpStaNZt59IUPKieRKMCcUgG 2HMz6Ds5cSUBjU4EevgNmVjOaYGcr31f+4MyWtrjhymA+vFgn97JRCP6SY3dtWkK0gaK WswfJKRYBPA41O64fpsD1afsM1Fjn7cMA1TDNNuIo4rK0b5zlN5ml09E0mrOIR6tBYuk gdYg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=FuTwnbzDtMh7F3yHVkzWlgR2wGNYW8RXz1s/mbtmpWk=; fh=5ZApQpEvPBzc36na8XKtcd00ZWt0TPgZNVM+eaj5G78=; b=YediTsG5CfXrSZm8XK4GYsxyf19Uf0ax5JqNhiq5R6AXcj2ztLBARr1tSoEdLwOML2 IdAjTRknlIrqI1+TFbH7T31ETyUEFMOh5tYeDgUiJuh0iIeVh+wdlo5UiVfTUqhToISq 5ZQJs5mpCmzh2f8l9KBI1q96lpJt3lztHaX7Zg752XViNPkGpgN5q8AaLaADnudjxvlp UlhosapcucNiPJneEAzBeDUxIQ5IE7k85al9sc849ffJMo0LMauIeeXNu5xSr60K81b/ yugdWNyha27UWFNxcazj+OMD4AKwgcGpXz7wnJQQQFEK6DYuz3nvCCmfof+wDer086m7 wZQQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=Jx4GLIgY; arc=pass (i=1 spf=pass spfdomain=arista.com dkim=pass dkdomain=arista.com dmarc=pass fromdomain=arista.com); spf=pass (google.com: domain of linux-kernel+bounces-79527-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79527-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id m4-20020a056402430400b00565a8de3833si273840edc.204.2024.02.24.01.07.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 01:07:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79527-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=Jx4GLIgY; arc=pass (i=1 spf=pass spfdomain=arista.com dkim=pass dkdomain=arista.com dmarc=pass fromdomain=arista.com); spf=pass (google.com: domain of linux-kernel+bounces-79527-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79527-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 17A0F1F21142 for ; Sat, 24 Feb 2024 09:07:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 31DFD3F8E0; Sat, 24 Feb 2024 09:04:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=arista.com header.i=@arista.com header.b="Jx4GLIgY" Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 820661B81F for ; Sat, 24 Feb 2024 09:04:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708765497; cv=none; b=iY3hSKM0soP88+Z+FfW4YCApAwFpYTiExX6+iv7MVv3JO7mI9dTxpAyO9M4LQp9o5QVtYeVVD0bZPmemEGs7rDRt9wwnUcZGJtgXY6jT+BgbbxDnqQF0sqxv9i9qAfxVxt7YDuR7ObyHzIzPqCt6zNl8nAwUhXy+OYGo01Ay4tY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708765497; c=relaxed/simple; bh=ekmIBLlaWKu+GWzGOa6EvRs4/d/ZpqSM2Pqyjmg1O/Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kbJmZE6LSTdu7pdFROGl7Tes1MwJN8D01j/RJRuvZAAMwUeq/dD3p7hM5koB1qLiNwrCf1GKus56oYMm9lAIZfkpHk0trllvZl/hltxmgIL2daN8SMCxgjizc7ddhI2Lh4VIxHqHw8u4mHX3B389pm55UDarmv/z6a2NNqPKp/Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=arista.com; spf=pass smtp.mailfrom=arista.com; dkim=pass (2048-bit key) header.d=arista.com header.i=@arista.com header.b=Jx4GLIgY; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=arista.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arista.com Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4129f28a09fso349795e9.3 for ; Sat, 24 Feb 2024 01:04:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1708765494; x=1709370294; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FuTwnbzDtMh7F3yHVkzWlgR2wGNYW8RXz1s/mbtmpWk=; b=Jx4GLIgYHXyqmSu+OLh3pBMYkyFh05gOApUjpjYqiq3SMBmdZtwStujpVvwYpgXj46 vTJ1XNFWAKUTxLG7ObcnOkUHrOKGNQ+WNNnRF1xRm2u3kl1l1u0L0wwt2nsQgyA0yl4X 8QF4JLmr+zmywRCPfaybQw8sa+D9vdHV0EzaIjc6AV4nV/EStm2BikHDa2V4DO0UWKP2 V6P3MOnQMF6kTZLdr4szK6JuRVknVxNNRVTvzUbpYqmsg1d9M0fCjZVoJFtUIYYY0UIX XY5CT7iO22ZBDCkwooaiH8Hvooz2geCtZPfAQIl1U2IknKg/v2U5Lmt+UtGb3D+Bv+gs MbEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708765494; x=1709370294; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FuTwnbzDtMh7F3yHVkzWlgR2wGNYW8RXz1s/mbtmpWk=; b=X8v+TLn7ywcokbNzi9hMveo51mzFJu/R5389s4YzYcG13kEmJVTGwaJyBXefaDZyG2 gl03EKVX+CGiCrwzEJISSns5pq6+SPF69wfV5BlSTrlbKlJHCNEMv5emrYtCDaAiVJye NE/5gyV3h7Q61mkjNRWxW7oh4gHrhlwzX4DrqxTlobMNac8kL95+d3vFr3zWj87YQJwy CZIuP0jxeMZM1FvxSfWUj2ICWaC8I0u7eNmlze8XQ2mwpkFGHVNfdONlqCvV5rgYz2cW zmjg9SPupjUJ8sWv5NW4iRmrRcAcepMbb3ziONCD8Jmmi9kIyQS4RKufCxnOTkbnGQbB cMSA== X-Forwarded-Encrypted: i=1; AJvYcCVtUOUUDhE94IZMS5WXc0JNBHus2mpKcsNwCW+5+bmY3tlKWzRMU6vbH2kMuQwzdKHmVCQNBQR+wIyxKLpaqCSypLS75ygt+fKdwx/U X-Gm-Message-State: AOJu0Yw0Ohw/qBTV7uwvV6M39aI2lBc1gvrtM6TbZ+2hvbAFIIQYvlz0 BWkFK29ZYqRFcPp/PJRFd7M6bvd9sTdK8MjbIFTT4MfgJt9IT7S0QHuGs5Wn7A== X-Received: by 2002:a05:600c:3b90:b0:412:6488:bbff with SMTP id n16-20020a05600c3b9000b004126488bbffmr1332546wms.30.1708765494014; Sat, 24 Feb 2024 01:04:54 -0800 (PST) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id m6-20020a7bce06000000b00410bca333b7sm5320593wmc.27.2024.02.24.01.04.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 01:04:53 -0800 (PST) From: Dmitry Safonov To: Eric Dumazet , "David S. Miller" , Jakub Kicinski , Paolo Abeni , David Ahern , Shuah Khan , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers Cc: Dmitry Safonov , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Dmitry Safonov <0x7f454c46@gmail.com> Subject: [PATCH net-next 07/10] selftests/net: Provide test_snprintf() helper Date: Sat, 24 Feb 2024 09:04:15 +0000 Message-ID: <20240224-tcp-ao-tracepoints-v1-7-15f31b7f30a7@arista.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240224-tcp-ao-tracepoints-v1-0-15f31b7f30a7@arista.com> References: <20240224-tcp-ao-tracepoints-v1-0-15f31b7f30a7@arista.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.13-dev-b6b4b X-Developer-Signature: v=1; a=ed25519-sha256; t=1708765347; l=1992; i=dima@arista.com; s=20231212; h=from:subject:message-id; bh=ekmIBLlaWKu+GWzGOa6EvRs4/d/ZpqSM2Pqyjmg1O/Q=; b=SGrLpjSzyoyJAX0/GI418io3uNbysLNAQ/zBPgtrgvHzRmp5sbt/Fl6o4nB0s9pLOE0EsixHB WIzmgkJA7qtATuXNnV7O0XD+Jk0vg11taa5p18BPXzBk167YiCxddP+ X-Developer-Key: i=dima@arista.com; a=ed25519; pk=hXINUhX25b0D/zWBKvd6zkvH7W2rcwh/CH6cjEa3OTk= Content-Transfer-Encoding: 8bit Re-invented std::stringstream :-) No need for buffer array - malloc() it. It's going to be helpful of path concat printings. Signed-off-by: Dmitry Safonov --- tools/testing/selftests/net/tcp_ao/lib/aolib.h | 56 ++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/net/tcp_ao/lib/aolib.h b/tools/testing/selftests/net/tcp_ao/lib/aolib.h index fbc7f6111815..fdf44d176e0b 100644 --- a/tools/testing/selftests/net/tcp_ao/lib/aolib.h +++ b/tools/testing/selftests/net/tcp_ao/lib/aolib.h @@ -37,17 +37,59 @@ extern void __test_xfail(const char *buf); extern void __test_error(const char *buf); extern void __test_skip(const char *buf); +static inline char *test_snprintf(const char *fmt, va_list vargs) +{ + char *ret = NULL; + size_t size = 0; + va_list tmp; + int n = 0; + + va_copy(tmp, vargs); + n = vsnprintf(ret, size, fmt, tmp); + if (n < 0) + return NULL; + + size = (size_t) n + 1; + ret = malloc(size); + if (ret == NULL) + return NULL; + + n = vsnprintf(ret, size, fmt, vargs); + if (n < 0 || n > size - 1) { + free(ret); + return NULL; + } + return ret; +} + +__attribute__((__format__(__printf__, 1, 2))) +static inline char *test_sprintf(const char *fmt, ...) +{ + va_list vargs; + char *ret; + + va_start(vargs, fmt); + ret = test_snprintf(fmt, vargs); + va_end(vargs); + + return ret; +} + __attribute__((__format__(__printf__, 2, 3))) static inline void __test_print(void (*fn)(const char *), const char *fmt, ...) { -#define TEST_MSG_BUFFER_SIZE 4096 - char buf[TEST_MSG_BUFFER_SIZE]; - va_list arg; + va_list vargs; + char *msg; - va_start(arg, fmt); - vsnprintf(buf, sizeof(buf), fmt, arg); - va_end(arg); - fn(buf); + va_start(vargs, fmt); + msg = test_snprintf(fmt, vargs); + va_end(vargs); + + if (!msg) + return; + + fn(msg); + free(msg); } #define test_print(fmt, ...) \ -- 2.43.0