From patchwork Sat Feb 24 09:04:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 13570326 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 DD2FF2CCA0 for ; Sat, 24 Feb 2024 09:04:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708765498; cv=none; b=R5C07huxYQifV4QvAbiLurdN+RIKGgZN1n5OyRRwfxUDSYLPAOeP7nXBR0Oy39wQYwMIRSmIZHqeP54jA0Ui4XOoZgtgczi1z1u0mF2TpTbFj8WLl90Rc55gBzf2fnSZyrzt/q4clionKRYea3sdM1m7/UwtA9J5rzmHH3ecPrk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708765498; c=relaxed/simple; bh=4jErwg55G7DEzjwCRCrWJtVME975m5guzjG380jeS9k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JxAiknRUd8Cw+u3M44qBfKZP6v3hUFeH7kaukI4T8Q2YblW8QEvSb10SgiN4jJEYXX2WRpnUp31EnsNke5eqXcj4UftXmkGUDPWbOxfbFMgIkJSUeve8nCMg9wB8eHUKNo+LDu9qWN6MhsvScdpBO89TKeqV2V1yQAb4Zbb99sg= 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=A9oEuHl6; arc=none smtp.client-ip=209.85.128.49 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=arista.com header.i=@arista.com header.b="A9oEuHl6" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4128fe4b8c8so11978345e9.1 for ; Sat, 24 Feb 2024 01:04:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; t=1708765495; x=1709370295; 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=rRIDgmvdBuy4FEMojsFBGRvXRNCtma2xryE9RPsDnfQ=; b=A9oEuHl6sjxlDeml6V8i/R62ztS4OWgUMKsJepuxR51nisyApnBYf9G+8kVEGU2pOf azqCend3/dTMws3379Zkgt7K7Ww0akbyABF5XffOUo0S1vxgC69JTSEaDqormuRexh5e XD3azSuERnJoLlWKygy3aVWyDxpFvlLHzEnAK1H9UoUmtXa6P1oKXwESPpWD5JiikbMQ GPMpjCtTNoVzmkNDfNwNv/gPvaq+mXhs92AI1cIoXqU745hLpqi1vdzagH6D5QkO3dcJ cnTpa5IqoytEWpJnUGoEhiU5UoHMBIWCQBW/QLQtqMGG7MhpHaOTIimtK4d3n4mOYzOc qLag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708765495; x=1709370295; 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=rRIDgmvdBuy4FEMojsFBGRvXRNCtma2xryE9RPsDnfQ=; b=I3aVlcTqC3uBHn1oB2TNdgOl0w3sms0hoyOpTXSTJ3fdsyFWvpalVfJgq4CJz0uFSQ updVLYMUyTCnRqA94cESQZDjRPbGLD8RiR73ODp54iyCz6BGMiinEM6z+Bv/qk2RdLe3 vknChfpTLufFmVIG7/cm9aqJd7CBTDUvQeD2N0lGzaQHFSM7AqFcwzf21sZcOa5gm5cn KV7BFOI9cChPiLPrNRFRP4T/2dI4XUYC5c+uoW9W+BwOPTKvd/NtaBMWbZ7bKAz+DXCp oAmpLvicP7DdZYla49Gq3rNa7x79qcKWqW9Q6A2YfRRMrj+vYonAavKCpVyIDrdoUCVp kGog== X-Forwarded-Encrypted: i=1; AJvYcCWeixQ/HMqjMoRaHQ7gxvZ5k6wMXTsgyX40N0uNXkTB/uMyrSAYM/tmcGAuvHOvKwrdBtVnJbFEaxMMobqGj1Wp5YvSgxPZ X-Gm-Message-State: AOJu0YxPnKY7YwKS0r7wYhIW7SViB91NgjAfp8DsiA7c4kAAy31vUNXc C8IYr6480HRE30d6GILsEirpPgU2TNFE5wUR/w6rxxOJB312T3WJZnx12ocwzQ== X-Google-Smtp-Source: AGHT+IFSjDUOo1EgIt8K5PVSqhLCRMxukx8XXQRsDPkwIrrfKNDL4fqMJiZ+mpwLKC5uDF/T8yNpUg== X-Received: by 2002:a05:600c:2e04:b0:410:a039:ed5d with SMTP id o4-20020a05600c2e0400b00410a039ed5dmr1673611wmf.33.1708765495316; Sat, 24 Feb 2024 01:04:55 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 01:04:54 -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 08/10] selftests/net: Be consistnat in kconfig checks Date: Sat, 24 Feb 2024 09:04:16 +0000 Message-ID: <20240224-tcp-ao-tracepoints-v1-8-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: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.13-dev-b6b4b X-Developer-Signature: v=1; a=ed25519-sha256; t=1708765347; l=2695; i=dima@arista.com; s=20231212; h=from:subject:message-id; bh=4jErwg55G7DEzjwCRCrWJtVME975m5guzjG380jeS9k=; b=afMpsCOt6xNpXARvG8bjI9wO61Dv76Tvjx05gMcpY6lZY365igt8bIUOsSzqko7QzMKAYLvny 2rTLQQQC9xyAQ3Viq8xdsZkk+BnMO5EjWEgG53r6fqakvaQFtEiZlQz X-Developer-Key: i=dima@arista.com; a=ed25519; pk=hXINUhX25b0D/zWBKvd6zkvH7W2rcwh/CH6cjEa3OTk= X-Patchwork-Delegate: kuba@kernel.org Most of the functions in tcp-ao lib/ return negative errno or -1 in case of a failure. That creates inconsistencies in lib/kconfig, which saves what was the error code. As well as the uninitialized kconfig value is -1, which also may be the result of a check. Define KCONFIG_UNKNOWN and save negative return code, rather than libc-style errno. Signed-off-by: Dmitry Safonov --- tools/testing/selftests/net/tcp_ao/lib/kconfig.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/net/tcp_ao/lib/kconfig.c b/tools/testing/selftests/net/tcp_ao/lib/kconfig.c index f279ffc3843b..3bf4a7e4b3c9 100644 --- a/tools/testing/selftests/net/tcp_ao/lib/kconfig.c +++ b/tools/testing/selftests/net/tcp_ao/lib/kconfig.c @@ -6,7 +6,7 @@ #include "aolib.h" struct kconfig_t { - int _errno; /* the returned error if not supported */ + int _error; /* negative errno if not supported */ int (*check_kconfig)(int *error); }; @@ -62,7 +62,7 @@ static int has_tcp_ao(int *err) memcpy(&tmp.addr, &addr, sizeof(addr)); *err = 0; if (setsockopt(sk, IPPROTO_TCP, TCP_AO_ADD_KEY, &tmp, sizeof(tmp)) < 0) { - *err = errno; + *err = -errno; if (errno != ENOPROTOOPT) ret = -errno; } @@ -87,7 +87,7 @@ static int has_tcp_md5(int *err) */ *err = 0; if (test_set_md5(sk, addr_any, 0, -1, DEFAULT_TEST_PASSWORD)) { - *err = errno; + *err = -errno; if (errno != ENOPROTOOPT && errno == ENOMEM) { test_print("setsockopt(TCP_MD5SIG_EXT): %m"); ret = -errno; @@ -116,13 +116,14 @@ static int has_vrfs(int *err) return ret; } +#define KCONFIG_UNKNOWN 1 static pthread_mutex_t kconfig_lock = PTHREAD_MUTEX_INITIALIZER; static struct kconfig_t kconfig[__KCONFIG_LAST__] = { - { -1, has_net_ns }, - { -1, has_veth }, - { -1, has_tcp_ao }, - { -1, has_tcp_md5 }, - { -1, has_vrfs }, + { KCONFIG_UNKNOWN, has_net_ns }, + { KCONFIG_UNKNOWN, has_veth }, + { KCONFIG_UNKNOWN, has_tcp_ao }, + { KCONFIG_UNKNOWN, has_tcp_md5 }, + { KCONFIG_UNKNOWN, has_vrfs }, }; const char *tests_skip_reason[__KCONFIG_LAST__] = { @@ -138,11 +139,11 @@ bool kernel_config_has(enum test_needs_kconfig k) bool ret; pthread_mutex_lock(&kconfig_lock); - if (kconfig[k]._errno == -1) { - if (kconfig[k].check_kconfig(&kconfig[k]._errno)) + if (kconfig[k]._error == KCONFIG_UNKNOWN) { + if (kconfig[k].check_kconfig(&kconfig[k]._error)) test_error("Failed to initialize kconfig %u", k); } - ret = kconfig[k]._errno == 0; + ret = kconfig[k]._error == 0; pthread_mutex_unlock(&kconfig_lock); return ret; }