Received: by 10.192.165.148 with SMTP id m20csp4294824imm; Mon, 30 Apr 2018 15:47:31 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrOkzNf85G33PJE59h3GGTlth8X6OsIv0eOEhok1NxIzv+Tn60MZyroyvHWMa7fjOaWpoww X-Received: by 2002:a17:902:8f82:: with SMTP id z2-v6mr10730052plo.350.1525128451594; Mon, 30 Apr 2018 15:47:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525128451; cv=none; d=google.com; s=arc-20160816; b=zooXs+LbqXjjwLlYMa8LaLUocFtbBwVRqrSmDoW6SGg4UFPhA5uBq0t34rhEEdx55U Ba6Nti6T1+dIQg8Wptnq/uFxwfw53/TWyiJCDKkOH3r1BUfltd09fHJmgnXwfIekGu89 NRnRN6tCjTN25Twjz37tA8Xsop+98ixolph2sObDrkimnRfYMtruFb0RhsYnFpfslF9d DDwgpC5Zjtxa9IF4MjNUF++qcnALA+BNiF7D1kXrBQnnjn/Loev8GzZN+0KZ5G19f39i fDoLUFBEPcuSG3frPynNtm2bHsg7FGoHIT9mSB9nt4Uhx/hW3gZASH1aez/iCgajuGA/ tbOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=LvTftDF/+wqqADUcSaAUEIudT/5PFxmbRb/5jyI9NGI=; b=ne6LCLurHKJ36TlFhWShUsQ32ZOFD3ZHQHYHJsgWbH3sOXBcTsbKhOveSWMIRGHoku +QhGapaZ3KLms1LfSpMEsDfLuev0pkEMOfrnw/HeIy9NqV5CYYSrHAmlsA/TjbJAgIkL OkJOs8hWmA4yMpIcxnssZyzBAIZ6wxjQnyvQYQlBrluOTd+kr0Oy6QbXfCxLDCRR8Q/1 l/fizZPvNAu6DHO27SvsNoVTi+JpF4f/3P10lsrMVZbe+G5/2yWhK7xcBasdU0712Vqy 3GWP8GAXrX0Cf5Wv26grOkedeILJN7OjFoKLEfG+GDcBjbAJ9idKodstSsEcGyF+fXBP 7yzg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h34-v6si2318667pld.108.2018.04.30.15.47.17; Mon, 30 Apr 2018 15:47:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755821AbeD3WqZ (ORCPT + 99 others); Mon, 30 Apr 2018 18:46:25 -0400 Received: from mail.efficios.com ([167.114.142.138]:53208 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755454AbeD3Wor (ORCPT ); Mon, 30 Apr 2018 18:44:47 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 2B3FC1A6346; Mon, 30 Apr 2018 18:44:47 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail02.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id MymPMdx0rHos; Mon, 30 Apr 2018 18:44:46 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id BB1741A6335; Mon, 30 Apr 2018 18:44:46 -0400 (EDT) X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail02.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id sQCJxd0kDiqY; Mon, 30 Apr 2018 18:44:46 -0400 (EDT) Received: from thinkos.internal.efficios.com (192-222-157-41.qc.cable.ebox.net [192.222.157.41]) by mail.efficios.com (Postfix) with ESMTPSA id 567C21A631D; Mon, 30 Apr 2018 18:44:46 -0400 (EDT) From: Mathieu Desnoyers To: Peter Zijlstra , "Paul E . McKenney" , Boqun Feng , Andy Lutomirski , Dave Watson Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Paul Turner , Andrew Morton , Russell King , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Andrew Hunter , Andi Kleen , Chris Lameter , Ben Maurer , Steven Rostedt , Josh Triplett , Linus Torvalds , Catalin Marinas , Will Deacon , Michael Kerrisk , Joel Fernandes , Mathieu Desnoyers , Shuah Khan , linux-kselftest@vger.kernel.org Subject: [PATCH 11/14] rseq: selftests: Provide basic test Date: Mon, 30 Apr 2018 18:44:30 -0400 Message-Id: <20180430224433.17407-12-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180430224433.17407-1-mathieu.desnoyers@efficios.com> References: <20180430224433.17407-1-mathieu.desnoyers@efficios.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "basic_test" only asserts that RSEQ works moderately correctly. E.g. that the CPUID pointer works. Signed-off-by: Mathieu Desnoyers CC: Shuah Khan CC: Russell King CC: Catalin Marinas CC: Will Deacon CC: Thomas Gleixner CC: Paul Turner CC: Andrew Hunter CC: Peter Zijlstra CC: Andy Lutomirski CC: Andi Kleen CC: Dave Watson CC: Chris Lameter CC: Ingo Molnar CC: "H. Peter Anvin" CC: Ben Maurer CC: Steven Rostedt CC: "Paul E. McKenney" CC: Josh Triplett CC: Linus Torvalds CC: Andrew Morton CC: Boqun Feng CC: linux-kselftest@vger.kernel.org CC: linux-api@vger.kernel.org --- tools/testing/selftests/rseq/basic_test.c | 56 +++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tools/testing/selftests/rseq/basic_test.c diff --git a/tools/testing/selftests/rseq/basic_test.c b/tools/testing/selftests/rseq/basic_test.c new file mode 100644 index 000000000000..d8efbfb89193 --- /dev/null +++ b/tools/testing/selftests/rseq/basic_test.c @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: LGPL-2.1 +/* + * Basic test coverage for critical regions and rseq_current_cpu(). + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include + +#include "rseq.h" + +void test_cpu_pointer(void) +{ + cpu_set_t affinity, test_affinity; + int i; + + sched_getaffinity(0, sizeof(affinity), &affinity); + CPU_ZERO(&test_affinity); + for (i = 0; i < CPU_SETSIZE; i++) { + if (CPU_ISSET(i, &affinity)) { + CPU_SET(i, &test_affinity); + sched_setaffinity(0, sizeof(test_affinity), + &test_affinity); + assert(sched_getcpu() == i); + assert(rseq_current_cpu() == i); + assert(rseq_current_cpu_raw() == i); + assert(rseq_cpu_start() == i); + CPU_CLR(i, &test_affinity); + } + } + sched_setaffinity(0, sizeof(affinity), &affinity); +} + +int main(int argc, char **argv) +{ + if (rseq_register_current_thread()) { + fprintf(stderr, "Error: rseq_register_current_thread(...) failed(%d): %s\n", + errno, strerror(errno)); + goto init_thread_error; + } + printf("testing current cpu\n"); + test_cpu_pointer(); + if (rseq_unregister_current_thread()) { + fprintf(stderr, "Error: rseq_unregister_current_thread(...) failed(%d): %s\n", + errno, strerror(errno)); + goto init_thread_error; + } + return 0; + +init_thread_error: + return -1; +} -- 2.11.0