Received: by 10.192.165.156 with SMTP id m28csp2354067imm; Thu, 12 Apr 2018 12:53:31 -0700 (PDT) X-Google-Smtp-Source: AIpwx49loE74raeucHoZ5ENHWWb8TswUdpEODQ7ZVy9gY9FsPL+UeHORXK4sOMeikta+NCbUuykP X-Received: by 2002:a17:902:864c:: with SMTP id y12-v6mr2368916plt.293.1523562811365; Thu, 12 Apr 2018 12:53:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523562811; cv=none; d=google.com; s=arc-20160816; b=bmHDJ90piWch2sR5FzlZkv+vTt3nuS5ls+LXAOzurArKh5y3UDF6JFgOaCCqTV3JGR gaIV2fr0ZNXRanLnsG1DKcAOzuz8Umvr5chgBNLeexbX14TK8MmbRACetA5nsjUi1kmM dKBdS8RoMa0EKQOJzdCYPF5PWSZGct7ldXRZlVa2kH9I4+nFinuWE3b7KNJicztxJS46 N4aRhMpYpfOukQ6qwHAHpmEgBVCCKo6tK6V87jVEVgsCJC7SIhVCgCTHRMUSE8ICbNad U1akJPRgsC5puIYOX3AqbJf0bca370TfgTaRlboXtZJiiIcfoNSwZwTZuv6/wH/HRr/6 ldSA== 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=fb5VJzQfZVL4ucrs5YsF1j+QYufoCxW4aIbV62NKo8Y=; b=VXH99rasW/cSAmMSwSPwc501UzPI44BCE/tGF4UbliM5mwuvzExKFXzjmFoClhbrHZ GCKR/htRsoiJgPWgWOT4XS9eiLGfEwHbdjuHG4RScTdvda/XstcqgJuP+9oQonpvLlnQ hZwqr+UGPlB/zIDo9WYCXCro6zDQA3IRA5pp0hSPbB4cgyoBt/9WfWTawoTIWltNTTSt N/whNEjX3ok+u0tWrJ/WYVelnw2qTis4aAdsSNvM0og5W7FMIfFB/z5w9jYC8DnuSsek YIrU4PjT+SyNsNdmXIsnzRYTHykvJXzPPhYjbEVWfHHMzPUUY6gaiGSr1AfQwr3WzY62 aVFg== 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 t18si3172247pfj.217.2018.04.12.12.53.15; Thu, 12 Apr 2018 12:53: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 S1753612AbeDLT2b (ORCPT + 99 others); Thu, 12 Apr 2018 15:28:31 -0400 Received: from mail.efficios.com ([167.114.142.138]:45804 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753510AbeDLT22 (ORCPT ); Thu, 12 Apr 2018 15:28:28 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 82A8E1B07AB; Thu, 12 Apr 2018 15:28:27 -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 ygYwpn8odaMp; Thu, 12 Apr 2018 15:28:27 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 188AB1B079D; Thu, 12 Apr 2018 15:28:27 -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 M3YMIHgTwNk5; Thu, 12 Apr 2018 15:28:27 -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 AAC0C1B0790; Thu, 12 Apr 2018 15:28:26 -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 , Mathieu Desnoyers , Shuah Khan , linux-kselftest@vger.kernel.org Subject: [RFC PATCH for 4.18 20/23] rseq: selftests: Provide basic test Date: Thu, 12 Apr 2018 15:27:57 -0400 Message-Id: <20180412192800.15708-21-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180412192800.15708-1-mathieu.desnoyers@efficios.com> References: <20180412192800.15708-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 | 55 +++++++++++++++++++++++++++++++ 1 file changed, 55 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..e2086b3885d7 --- /dev/null +++ b/tools/testing/selftests/rseq/basic_test.c @@ -0,0 +1,55 @@ +/* + * 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