Received: by 10.213.65.68 with SMTP id h4csp808657imn; Tue, 27 Mar 2018 09:08:45 -0700 (PDT) X-Google-Smtp-Source: AG47ELvQmSB1+k+C1XC+wFoJHXqEwkwxIV+mVrqSFv78xUx9+nblMaTSThT/dHwVgy6C6mQGujLt X-Received: by 2002:a17:902:6103:: with SMTP id t3-v6mr45779719plj.76.1522166925776; Tue, 27 Mar 2018 09:08:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522166925; cv=none; d=google.com; s=arc-20160816; b=zVrwBWR+BI0wN91MhRl9oLMKowebp2xv6F0mjBtWG28e/q54ahploHwNVqc0Y2ZN6H btqk9OxNj35q89XG7vTBxBLxrnnzNH1ivVprgRsPaptaTwOiaVApHoi1uoqG4AVsl0pi sUhG0XT0MN9v2PdkBUiQWCeBnV2dNXRy6mVNn6yOUjgPyHgy5y/qRiShXEDQUq6XphJ4 c0yD9IVsfax0Mru3dDJT29lRnSxMp/VIzXGH26QpomK+ySGmqV2wvM+tUFA0X4OlBABt GvE0f121BuFWo25AaOIdHZjRDB3uTNU08m4KWVNG6ZXeXtf8T9Ldc3v6cER3AwfVnMWm CHOQ== 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=vcjHHvuOqqSdyhPLiiafWxIP/+TYlVCSP8Bx3Q0RCJ8JL8brabPc/Jgx8I00wyaPQa QRRKLUJTcentU2N4EeDXXW2uO+8ysrrMVDz7oDQB7imWroQEfGNTEWAwfUxzT6RYBof2 gYm2MfWiuU6DEGBaUr+lDUak4+v6w2shll9o1tCRXarU2+qGOZzL8uFk9vJMby97z/Gc WyrPL6K9ykI1m07SvZliUYkf/avN7VH3DFvt0p3JpQmgsX3OwhnqFVx51kKoJTOzsxiA u0pqWQ/IkKfvMoUEUTUf/7D8JEeb7ih311zzgvoLowHlLmOlDeEN33rF7ii8ERCvNN08 e0GA== 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 q14-v6si1476501pll.181.2018.03.27.09.08.28; Tue, 27 Mar 2018 09:08:45 -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 S1752844AbeC0QG2 (ORCPT + 99 others); Tue, 27 Mar 2018 12:06:28 -0400 Received: from mail.efficios.com ([167.114.142.138]:51472 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752784AbeC0QGY (ORCPT ); Tue, 27 Mar 2018 12:06:24 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 870B61A51E2; Tue, 27 Mar 2018 12:06:23 -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 dzIYDxg_Ys1S; Tue, 27 Mar 2018 12:06:23 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id F3FDF1A51CE; Tue, 27 Mar 2018 12:06:22 -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 XAAXF8yk4dpn; Tue, 27 Mar 2018 12:06:22 -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 8D8751A51B6; Tue, 27 Mar 2018 12:06:22 -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.17 18/21] rseq: selftests: Provide basic test Date: Tue, 27 Mar 2018 12:05:39 -0400 Message-Id: <20180327160542.28457-19-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180327160542.28457-1-mathieu.desnoyers@efficios.com> References: <20180327160542.28457-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