From patchwork Thu Sep 27 22:09:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafael David Tinoco X-Patchwork-Id: 147744 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp2550343lji; Thu, 27 Sep 2018 15:09:54 -0700 (PDT) X-Google-Smtp-Source: ACcGV606Aff/qto//aNxz9nx+6/gdoGgA5zGpKc/ITtPYbzt33adPiuBI6crB3kp/Z+VWh9Ra9FD X-Received: by 2002:adf:8103:: with SMTP id 3-v6mr10096884wrm.213.1538086193965; Thu, 27 Sep 2018 15:09:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538086193; cv=none; d=google.com; s=arc-20160816; b=PpiDb9FfN7HIN86K8jpfmyEBn2qGiPaTJwX0cqnXXCPfyfhsVc2GebjOStUPnCZogU RO8waW6mQ6e21+zjrBSsvWClXchU4UGVSICRESMze7sjzuYz3aw3hvkuS0wdDWv2IZZq GPXBf6zQZlBogB+xa1bCw3AQWm7LkVmjtxq4h6XfE6t0yyM7+35Ci8vmygp5ftAC8T0C kL+E/+00GMLm50EBNDAUnNtjVjIz/nqtlgIqK/S7MxuF/XaF0wwamZghQr3LYt8CSXKB 2bREvVBttCXex3tEK2J8w2w04IcA2491cDS2d7IHivtX6pIRkW5aw+wjsX2WTzl9hPL9 2wTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:message-id:date:to:from:dkim-signature:delivered-to; bh=3fXJ/gp0iyZZDPJC1rtly3FBwB3ZrEIv/Km1f3QpNII=; b=YDnwUhzE3Ffg0IwykWXFH1AKAYhLIWIp1EliDBaCVBycn/Wg2RG+/rMzwVSNqXHHV4 UR4g6j2+cLJcSPqL0xEDcN6NGqzQqSF+kaptJs/7uvD/lRlWeK+8dw6Qaq/GbaMg4Jqx AJqw30UYtNcvtDZEkDSYZmOs/buf5pWWTdTgyJK2uhxMxQrOAxleGIyywDtRuakLLKDe sf6A6oa1sya8QF9SgqSiuKw9p8HcxSAsu2Ok1yLB0XXzIeXTFcki5m0QALCssGLQcv9h 35Zm28EkWK0TE2D9YBrobPMRYVy9QrKKYHaGw+xE3FWO3tIceIiLvJsp6ei3OielYARJ cv7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=LQoMcJqs; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from picard.linux.it (picard.linux.it. [213.254.12.146]) by mx.google.com with ESMTPS id z11-v6si2770999wrp.355.2018.09.27.15.09.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 15:09:53 -0700 (PDT) Received-SPF: pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) client-ip=213.254.12.146; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=LQoMcJqs; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 7A5E33E66DA for ; Fri, 28 Sep 2018 00:09:53 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) by picard.linux.it (Postfix) with ESMTP id 33D3C3E6649 for ; Fri, 28 Sep 2018 00:09:48 +0200 (CEST) Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 37FC2601929 for ; Fri, 28 Sep 2018 00:09:47 +0200 (CEST) Received: by mail-qt1-x842.google.com with SMTP id k38-v6so4534053qtk.11 for ; Thu, 27 Sep 2018 15:09:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=iFX+ZD1sFOw6Vd4ybxgKC5TMrq2ummXGRRYWhj+VSbQ=; b=LQoMcJqsOart0hbi2ZhUBJ7gh7DRutgCtZXL6KS9orqmFmlW/guPRdsIQIVCHQ7aLB NCEZZ1/Of2g+Wx/x/94jmIbEkTgSyfb3YmTCoKQylRFFOFGZtUd+RnT7lCiCPg9PbwdS hL0AJokZTo5ama2vC1LHhKf/Xmuv+AsDsMP3A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=iFX+ZD1sFOw6Vd4ybxgKC5TMrq2ummXGRRYWhj+VSbQ=; b=qX4VqOLKFR/uBJdRlGvaruQbaWeZrqdrXssQTdTcbbBD/v6aaM6ohFg63h0h37MpIp k3hMmdZX2kf988poBm6luwGEZb9HMIPvNX/s42by39gIpu+PEJgDH4teA47gSG8cZ2KD 9F2hJn/61NS6ppdm7P/atSN3NoX5PWdieBgutEnrFPjGeec+eoyNRSFCK+9Oe8NyW000 8CwbtfKAzExje5Vm5rw/GxV4d+yLD2DhXoofnPFZXJ93ER4cdmGPKVWocQpI0mdp4OM9 TngUlRpGhyznXc1UMEyiZNMCqm4UcOI44c93OPjVZ7Q1xkr9qOX/0UFt0T54eiY4sFnC BBAg== X-Gm-Message-State: ABuFfogcPKL3/6RKRTAm8xibvbNmginIm/j3VyCLjSeRkpUsMYsQctFj bOrbU+OIIEwifNH4me5/M0hNVikV/U8= X-Received: by 2002:ac8:110c:: with SMTP id c12-v6mr10232479qtj.269.1538086185617; Thu, 27 Sep 2018 15:09:45 -0700 (PDT) Received: from workstation.celeiro.br ([168.194.163.66]) by smtp.gmail.com with ESMTPSA id f13-v6sm1616990qth.62.2018.09.27.15.09.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 15:09:45 -0700 (PDT) From: Rafael David Tinoco To: ltp@lists.linux.it Date: Thu, 27 Sep 2018 19:09:41 -0300 Message-Id: <20180927220941.19783-1-rafael.tinoco@linaro.org> X-Mailer: git-send-email 2.19.0.rc2 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Cc: rafael.tinoco@linaro.org Subject: [LTP] [PATCH] syscalls/membarrier: Add membarrier() initial test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+patch=linaro.org@lists.linux.it Sender: "ltp" Fixes: #265 Initial test for membarrier() syscall. It tests all existing membarrier "commands" (or features), including the need (or not) for previous registration for the call to work. Some features did not exist in older kernels and that is covered by skipping some calls, flagging test as skipped & okay, and forcing others, making sure that return codes and errno are set right in those cases. Signed-off-by: Rafael David Tinoco Signed-off-by: Rafael David Tinoco <rafael.tinoco@linaro.org>
--- runtest/syscalls | 2 + .../kernel/syscalls/membarrier/.gitignore | 1 + testcases/kernel/syscalls/membarrier/Makefile | 8 + .../kernel/syscalls/membarrier/membarrier01.c | 337 ++++++++++++++++++ 4 files changed, 348 insertions(+) create mode 100644 testcases/kernel/syscalls/membarrier/.gitignore create mode 100644 testcases/kernel/syscalls/membarrier/Makefile create mode 100644 testcases/kernel/syscalls/membarrier/membarrier01.c diff --git a/runtest/syscalls b/runtest/syscalls index 0d0be7713..19be14098 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1504,3 +1504,5 @@ statx02 statx02 statx03 statx03 statx04 statx04 statx05 statx05 + +membarrier01 membarrier01 diff --git a/testcases/kernel/syscalls/membarrier/.gitignore b/testcases/kernel/syscalls/membarrier/.gitignore new file mode 100644 index 000000000..eec8058b9 --- /dev/null +++ b/testcases/kernel/syscalls/membarrier/.gitignore @@ -0,0 +1 @@ +/membarrier01 diff --git a/testcases/kernel/syscalls/membarrier/Makefile b/testcases/kernel/syscalls/membarrier/Makefile new file mode 100644 index 000000000..f71e4fc25 --- /dev/null +++ b/testcases/kernel/syscalls/membarrier/Makefile @@ -0,0 +1,8 @@ +# Copyright (c) 2018 - Linaro Limited. All rights reserved. +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk \ No newline at end of file diff --git a/testcases/kernel/syscalls/membarrier/membarrier01.c b/testcases/kernel/syscalls/membarrier/membarrier01.c new file mode 100644 index 000000000..fdc6c4204 --- /dev/null +++ b/testcases/kernel/syscalls/membarrier/membarrier01.c @@ -0,0 +1,337 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018 Linaro Limited. All rights reserved. + * Author: Rafael David Tinoco + */ + +/* + * Basic tests for membarrier(2) syscall. Tests bellow are responsible for + * testing the membarrier(2) interface only, without checking if the barrier was + * successful or not. + * + * There are 11 test cases: + * + * 00) invalid cmd: + * - enabled by default + * - should always fail with EINVAL + * 01) invalid flags: + * - enabled by default + * - should always fail with EINVAL + * ---- + * 02) global barrier: + * - ALWAYS enabled by CMD_QUERY + * - should always succeed + * ---- + * commit 22e4ebb975 (v4.14-rc1) added following feature: + * + * 03) private expedited barrier with no registrations: + * - should fail with errno=EPERM due to no registrations + * - or be skipped if unsupported by running kernel + * 04) register private expedited + * - should succeed when supported by running kernel + * - or fail with errno=EINVAL if unsupported and forced + * 05) private expedited barrier with registration + * - should succeed due to existing registration (case 04) + * - or fail with errno=EINVAL if unsupported and forced + * - NOTE: if unsupported, and forced, on < 4.10, errno is EINVAL + * ---- + * commit 70216e18e5 (v4.16-rc1) added following feature: + * + * 06) private expedited sync core barrier with no registrations + * - should fail with errno=EPERM due to no registrations + * - or be skipped if unsupported by running kernel + * 07) register private expedited sync core + * - should succeed when supported by running kernel + * - or fail with errno=EINVAL if unsupported and forced + * 08) private expedited sync core barrier with registration + * - should succeed due to existing registration (case 07) + * - or fail with errno=EINVAL if unsupported and forced + * ---- + * commit c5f58bd58f4 (v4.16-rc1) added following feature: + * + * 09) global expedited barrier with no registrations + * - should never fail due to no registrations + * - or be skipped if unsupported by running kernel + * 10) register global expedited + * - should succeed when supported by running kernel + * - or fail with errno=EINVAL if unsupported and forced + * 11) global expedited barrier with registration + * - should succeed due to existing registration (case 10) or not + * - or fail with errno=EINVAL if unsupported and forced + * ---- + * OBSERVATION: + * + * Linux kernel does not provide a way to unregister (mm->membarrier_state) the + * process intent of being affected by the membarrier(2) call. + */ + +#include "config.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "tst_test.h" + +#define passed_ok(_test) \ + do { \ + tst_res(TPASS, "membarrier(2): %s passed", _test.testname); \ + return; \ + } while (0) + +#define passed_unexpectedly(_test) \ + do { \ + tst_res(TFAIL, "membarrier(2): %s passed unexpectedly. " \ + "ret = %ld with errno %d were expected. (force: %d)", \ + _test.testname, _test.exp_ret, _test.exp_errno, \ + _test.force); \ + return; \ + } while (0) + +#define failed_ok(_test) \ + do { \ + tst_res(TPASS, "membarrier(2): %s failed as expected", \ + _test.testname); \ + return; \ + } while (0) + +#define failed_ok_unsupported(_test) \ + do { \ + tst_res(TPASS, "membarrier(2): %s failed as expected " \ + "(unsupported)", _test.testname); \ + return; \ + } while (0) + +#define failed_not_ok(_test, _gotret, _goterr) \ + do { \ + tst_res(TFAIL, "membarrier(2): %s failed as expected. " \ + "ret = %ld when expected was %ld. " \ + "errno = %d when expected was %d. (force: %d)", \ + _test.testname, _gotret, _test.exp_ret, _goterr, \ + _test.exp_errno, _test.force); \ + return; \ + } while (0) + +#define failed_unexpectedly(_test, _gotret, _goterr) \ + do { \ + tst_res(TFAIL, "membarrier(2): %s failed unexpectedly. " \ + "Got ret = %ld with errno %d. (force: %d)", \ + _test.testname, _gotret, _goterr, _test.force); \ + return; \ + } while (0) + +#define skipped(_test) \ + do { \ + tst_res(TPASS, "membarrier(2): %s skipped (unsupported)", \ + _test.testname); \ + return; \ + } while (0) + +#define skipped_fail(_test) \ + do { \ + tst_res(TFAIL, "membarrier(2): %s reported as not supported", \ + _test.testname); \ + return; \ + } while (0) + +static int sys_membarrier(int cmd, int flags) +{ + return syscall(__NR_membarrier, cmd, flags); +} + +struct test_case { + char testname[80]; + int command; /* membarrier cmd */ + int flags; /* flags for given cmd */ + long exp_ret; /* expected return code for given cmd */ + int exp_errno; /* expected errno for given cmd */ + int enabled; /* enabled despite results from CMD_QUERY */ + int always; /* CMD_QUERY should always enable this test */ + int force; /* force if CMD_QUERY says is not enabled */ + int force_exp_errno; /* expected errno after error for forced cmd */ +}; + +struct test_case tc[] = { + { + /* case 00 */ + .testname = "cmd_fail\0", + .command = -1, + .exp_ret = -1, + .exp_errno = EINVAL, + .enabled = 1, + }, + { + /* case 01 */ + .testname = "cmd_flags_fail\0", + .command = MEMBARRIER_CMD_QUERY, + .flags = 1, + .exp_ret = -1, + .exp_errno = EINVAL, + .enabled = 1, + }, + { + /* case 02 */ + .testname = "cmd_global_success\0", + .command = MEMBARRIER_CMD_GLOBAL, + .flags = 0, + .exp_ret = 0, + .always = 1, + }, + { + /* case 03 */ + .testname = "cmd_private_expedited_fail\0", + .command = MEMBARRIER_CMD_PRIVATE_EXPEDITED, + .flags = 0, + .exp_ret = -1, + .exp_errno = EPERM, + }, + { + /* case 04 */ + .testname = "cmd_private_expedited_register_success\0", + .command = MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED, + .flags = 0, + .exp_ret = 0, + .force = 1, + .force_exp_errno = EINVAL, + }, + { + /* case 05 */ + .testname = "cmd_private_expedited_success\0", + .command = MEMBARRIER_CMD_PRIVATE_EXPEDITED, + .flags = 0, + .exp_ret = 0, + .force = 1, + .force_exp_errno = EINVAL, + }, + { + /* case 06 */ + .testname = "cmd_private_expedited_sync_core_fail\0", + .command = MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE, + .flags = 0, + .exp_ret = -1, + .exp_errno = EPERM, + }, + { + /* case 07 */ + .testname = "cmd_private_expedited_sync_core_register_success\0", + .command = MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE, + .flags = 0, + .exp_ret = 0, + .force = 1, + .force_exp_errno = EINVAL, + }, + { + /* case 08 */ + .testname = "cmd_private_expedited_sync_core_success\0", + .command = MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE, + .flags = 0, + .exp_ret = 0, + .force = 1, + .force_exp_errno = EINVAL, + }, + { + /* case 09 */ + .testname = "cmd_global_expedited_success\0", + .command = MEMBARRIER_CMD_GLOBAL_EXPEDITED, + .flags = 0, + .exp_ret = 0, + }, + { + /* case 10 */ + .testname = "cmd_global_expedited_register_success\0", + .command = MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED, + .flags = 0, + .exp_ret = 0, + .force = 1, + .force_exp_errno = EINVAL, + }, + { + /* case 11 */ + .testname = "cmd_global_expedited_success\0", + .command = MEMBARRIER_CMD_GLOBAL_EXPEDITED, + .flags = 0, + .exp_ret = 0, + .force = 1, + .force_exp_errno = EINVAL, + }, +}; + +static void verify_membarrier(unsigned int i) +{ + /* skips tests depending on supportability */ + + if (tc[i].enabled != 1 && tc[i].force != 1) { + if (tc[i].always == 0) + skipped(tc[i]); + + skipped_fail(tc[i]); + } + + TEST(sys_membarrier(tc[i].command, tc[i].flags)); + + /* cmd passes */ + + if (tc[i].exp_ret == TST_RET) { + + if (TST_RET >= 0) + passed_ok(tc[i]); + else { + if (tc[i].enabled == 1 && tc[i].force != 1) { + if (tc[i].exp_errno != TST_ERR) + failed_not_ok(tc[i], TST_RET, TST_ERR); + else + failed_ok(tc[i]); + } else { + if (tc[i].force_exp_errno != TST_ERR) + failed_not_ok(tc[i], TST_RET, TST_ERR); + else + failed_ok_unsupported(tc[i]); + } + } + + /* cmd fails */ + + } else { + if (tc[i].enabled == 1 && tc[i].force != 1) { + if (TST_RET >= 0) + passed_unexpectedly(tc[i]); + else + failed_unexpectedly(tc[i], TST_RET, TST_ERR); + } else { + if (tc[i].force_exp_errno == TST_ERR) + failed_ok_unsupported(tc[i]); + else + failed_not_ok(tc[i], TST_RET, TST_ERR); + } + } +} + +static void setup(void) +{ + size_t i; + int ret; + + ret = sys_membarrier(MEMBARRIER_CMD_QUERY, 0); + if (ret < 0) { + if (errno == ENOSYS) + tst_brk(TCONF, "sys_membarrier(2) not supported"); + } + + for (i = 0; i < ARRAY_SIZE(tc); i++) { + if ((tc[i].command > 0) && (ret & tc[i].command)) + tc[i].enabled = 1; + } +} + +static struct tst_test test = { + .setup = setup, + .test = verify_membarrier, + .tcnt = ARRAY_SIZE(tc), +};