From patchwork Wed Apr 17 06:05:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1086801 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44kWvN3NwDz9s71 for ; Wed, 17 Apr 2019 16:06:08 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 9B8AD3EB021 for ; Wed, 17 Apr 2019 08:06:05 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) by picard.linux.it (Postfix) with ESMTP id B5FAE3EA02D for ; Wed, 17 Apr 2019 08:06:03 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-5.smtp.seeweb.it (Postfix) with ESMTP id DF94160158E for ; Wed, 17 Apr 2019 08:06:01 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.60,360,1549900800"; d="scan'208";a="59506136" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 17 Apr 2019 14:05:57 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 9661B4CD84CA; Wed, 17 Apr 2019 14:05:54 +0800 (CST) Received: from localhost.localdomain (10.167.215.35) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 17 Apr 2019 14:05:55 +0800 From: Yang Xu To: Date: Wed, 17 Apr 2019 14:05:01 +0800 Message-ID: <1555481102-4158-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <20190412114632.GD28648@haruka.lan> References: <20190412114632.GD28648@haruka.lan> MIME-Version: 1.0 X-Originating-IP: [10.167.215.35] X-yoursite-MailScanner-ID: 9661B4CD84CA.AD172 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.0 required=7.0 tests=none autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-5.smtp.seeweb.it Cc: ltp@lists.linux.it Subject: [LTP] [PATCH v2 1/2] syscalls/sched_getaffinity: Cleanup && Convert to new API 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+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Convert test to new library. It also fixes a rare compile error for getcpu01.c on some old distros that use ltp CPU_ALLOC(report cleanup undefined error). Signed-off-by: Yang Xu --- include/lapi/cpuset.h | 4 +- .../sched_getaffinity/sched_getaffinity01.c | 151 ++++-------------- 2 files changed, 32 insertions(+), 123 deletions(-) diff --git a/include/lapi/cpuset.h b/include/lapi/cpuset.h index b94665022..d7ca39f9f 100644 --- a/include/lapi/cpuset.h +++ b/include/lapi/cpuset.h @@ -35,8 +35,8 @@ #ifndef CPU_ALLOC #define CPU_ALLOC(ncpus) malloc(sizeof(cpu_set_t)); \ if (ncpus > CPU_SETSIZE) { \ - tst_brkm(TCONF, cleanup, \ - "Your libc does not support masks with %ld cpus", ncpus); \ + tst_brk(TCONF, \ + "Your libc does not support masks with %d cpus", ncpus); \ } #endif diff --git a/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c b/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c index 02f04b909..1c149fe40 100644 --- a/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c +++ b/testcases/kernel/syscalls/sched_getaffinity/sched_getaffinity01.c @@ -1,92 +1,26 @@ -/******************************************************************************/ -/* Copyright (c) Crackerjack Project., 2007 */ -/* */ -/* This program is free software; you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation; either version 2 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ -/* the GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software */ -/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* */ -/******************************************************************************/ -/******************************************************************************/ -/* */ -/* File: sched_getaffinity01.c */ -/* */ -/* Description: This tests the sched_getaffinity() syscall */ -/* */ -/* Usage: */ -/* sched_getaffinity01 [-c n] [-e][-i n] [-I x] [-p x] [-t] */ -/* where, -c n : Run n copies concurrently. */ -/* -e : Turn on errno logging. */ -/* -i n : Execute test n times. */ -/* -I x : Execute test for x seconds. */ -/* -P x : Pause for x seconds between iterations. */ -/* -t : Turn on syscall timing. */ -/* */ -/* Total Tests: 1 */ -/* */ -/* Test Name: sched_getaffinity01 */ -/* History: Porting from Crackerjack to LTP is done by */ -/* Manas Kumar Nayak maknayak@in.ibm.com> */ -/******************************************************************************/ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) Crackerjack Project., 2007 + * Description: This case tests the sched_getaffinity() syscall + * History: Porting from Crackerjack to LTP is done by + * Manas Kumar Nayak maknayak@in.ibm.com> + */ #define _GNU_SOURCE -#define __USE_GNU -#include #include -#include #include -#include -#include #include #include -#include - -#include "test.h" -#include "safe_macros.h" -#include "lapi/syscalls.h" - -char *TCID = "sched_getaffinity01"; -int TST_TOTAL = 1; - -static long num; -static void do_test(void); -static void setup(void); -static void cleanup(void); +#include "tst_test.h" +#include "tst_safe_macros.h" +#include "lapi/cpuset.h" #define QUICK_TEST(t) \ do { \ TEST(t); \ - tst_resm((TEST_RETURN == -1 ? TPASS : TFAIL) | TTERRNO, #t); \ + tst_res((TST_RET == -1 ? TPASS : TFAIL) | TTERRNO, #t); \ } while (0) -#if !(__GLIBC_PREREQ(2, 7)) -#define CPU_FREE(ptr) free(ptr) -#endif - -int main(int ac, char **av) -{ - int lc; - - tst_parse_opts(ac, av, NULL, NULL); - setup(); - - for (lc = 0; TEST_LOOPING(lc); ++lc) { - tst_count = 0; - - do_test(); - } - - cleanup(); - tst_exit(); -} +static long num; static void do_test(void) { @@ -96,78 +30,53 @@ static void do_test(void) pid_t unused_pid; unsigned len; -#if __GLIBC_PREREQ(2, 7) realloc: mask = CPU_ALLOC(nrcpus); -#else - mask = malloc(sizeof(cpu_set_t)); -#endif - if (mask == NULL) - tst_brkm(TFAIL | TTERRNO, cleanup, "fail to get enough memory"); -#if __GLIBC_PREREQ(2, 7) + if (!mask) + tst_brk(TBROK | TERRNO, "CPU_ALLOC()"); + len = CPU_ALLOC_SIZE(nrcpus); CPU_ZERO_S(len, mask); -#else - len = sizeof(cpu_set_t); - CPU_ZERO(mask); -#endif + /* positive test */ TEST(sched_getaffinity(0, len, mask)); - if (TEST_RETURN == -1) { + if (TST_RET == -1) { CPU_FREE(mask); -#if __GLIBC_PREREQ(2, 7) if (errno == EINVAL && nrcpus < (1024 << 8)) { nrcpus = nrcpus << 2; goto realloc; } -#else - if (errno == EINVAL) - tst_resm(TFAIL, "NR_CPUS > 1024, we'd better use a " - "newer glibc(>= 2.7)"); - else -#endif - tst_resm(TFAIL | TTERRNO, "fail to get cpu affinity"); - cleanup(); + tst_res(TFAIL | TTERRNO, "fail to get cpu affinity"); } else { - tst_resm(TINFO, "cpusetsize is %d", len); - tst_resm(TINFO, "mask.__bits[0] = %lu ", mask->__bits[0]); + tst_res(TINFO, "cpusetsize is %d", len); + tst_res(TINFO, "mask.__bits[0] = %lu ", mask->__bits[0]); for (i = 0; i < num; i++) { -#if __GLIBC_PREREQ(2, 7) TEST(CPU_ISSET_S(i, len, mask)); -#else - TEST(CPU_ISSET(i, mask)); -#endif - if (TEST_RETURN != -1) - tst_resm(TPASS, "sched_getaffinity() succeed, " + if (TST_RET != -1) + tst_res(TPASS, "sched_getaffinity() succeed, " "this process %d is running " "processor: %d", getpid(), i); } } -#if __GLIBC_PREREQ(2, 7) CPU_ZERO_S(len, mask); -#else - CPU_ZERO(mask); -#endif + /* negative tests */ QUICK_TEST(sched_getaffinity(0, len, (cpu_set_t *) - 1)); QUICK_TEST(sched_getaffinity(0, 0, mask)); - unused_pid = tst_get_unused_pid(cleanup); + unused_pid = tst_get_unused_pid(); QUICK_TEST(sched_getaffinity(unused_pid, len, mask)); CPU_FREE(mask); } static void setup(void) { - TEST_PAUSE; - tst_tmpdir(); - - num = SAFE_SYSCONF(NULL, _SC_NPROCESSORS_CONF); - tst_resm(TINFO, "system has %ld processor(s).", num); + num = SAFE_SYSCONF(_SC_NPROCESSORS_CONF); + tst_res(TINFO, "system has %ld processor(s).", num); } -static void cleanup(void) -{ - tst_rmdir(); -} +static struct tst_test test = { + .setup = setup, + .test_all = do_test, +}; From patchwork Wed Apr 17 06:05:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1086802 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44kWvW09l8z9s71 for ; Wed, 17 Apr 2019 16:06:14 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 7FFD03EB014 for ; Wed, 17 Apr 2019 08:06:12 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) by picard.linux.it (Postfix) with ESMTP id B19FB294AC2 for ; Wed, 17 Apr 2019 08:06:09 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-5.smtp.seeweb.it (Postfix) with ESMTP id 98ABF601596 for ; Wed, 17 Apr 2019 08:06:06 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.60,360,1549900800"; d="scan'208";a="59506152" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 17 Apr 2019 14:06:04 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 1CF904CD84CD; Wed, 17 Apr 2019 14:06:01 +0800 (CST) Received: from localhost.localdomain (10.167.215.35) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 17 Apr 2019 14:06:01 +0800 From: Yang Xu To: Date: Wed, 17 Apr 2019 14:05:02 +0800 Message-ID: <1555481102-4158-2-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1555481102-4158-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> References: <20190412114632.GD28648@haruka.lan> <1555481102-4158-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.215.35] X-yoursite-MailScanner-ID: 1CF904CD84CD.AD92A X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.0 required=7.0 tests=none autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-5.smtp.seeweb.it Cc: ltp@lists.linux.it Subject: [LTP] [PATCH v2 2/2] syscalls/getcpu:Add libc sched_getcpu() detection &&fix compiler errors 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+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" sched_getcpu() isn't defined on some old distros, so we can add dection and fix compiler error. Signed-off-by: Yang Xu Acked-by: Petr Vorel --- configure.ac | 1 + testcases/kernel/syscalls/getcpu/getcpu01.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index fad8f8396..53ad784d7 100644 --- a/configure.ac +++ b/configure.ac @@ -77,6 +77,7 @@ AC_CHECK_FUNCS([ \ readlinkat \ renameat \ renameat2 \ + sched_getcpu \ sigpending \ splice \ stime \ diff --git a/testcases/kernel/syscalls/getcpu/getcpu01.c b/testcases/kernel/syscalls/getcpu/getcpu01.c index eb6ded8ab..fcc273e29 100644 --- a/testcases/kernel/syscalls/getcpu/getcpu01.c +++ b/testcases/kernel/syscalls/getcpu/getcpu01.c @@ -18,13 +18,14 @@ #include "lapi/syscalls.h" #include "lapi/cpuset.h" #include "tst_test.h" +#include "config.h" static inline int get_cpu(unsigned *cpu_id, unsigned *node_id LTP_ATTRIBUTE_UNUSED, void *cache_struct LTP_ATTRIBUTE_UNUSED) { -#if defined(__i386__) - return syscall(__NR_getcpu, cpu_id, node_id, cache_struct); +#ifndef HAVE_SCHED_GETCPU + return tst_syscall(__NR_getcpu, cpu_id, node_id, cache_struct); #else *cpu_id = sched_getcpu(); #endif