From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by sourceware.org (Postfix) with ESMTPS id 368B8394741A for ; Wed, 26 May 2021 17:30:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 368B8394741A Received: by mail-qk1-x72e.google.com with SMTP id j184so1786500qkd.6 for ; Wed, 26 May 2021 10:30:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=O+5DMQjDJQE+DnziQCHxl/ADlv8INvHpkQp3es40EqM=; b=gTXuMVsw1oXC5Zbwc8JRkxzHD1uN8OwWYinpQiFUTifThdcj5pJ8knGsTDUOZ1ZSN1 OMRA8lp81soBLV4VcDx82OrOISwXNI49zHdme1vsEuz12E5B2GSH+oE6lGmd5+Z6iTsk XXkVvWDcueH9esxKoaG+05gQCKOicoPqoPM9oG0X+IvXM/nglQSmxmIjZB76WGrNnqwl dlzZWWftNsZpvI9vdobgH6qHGYHxCBvBqHQ59dfeeBRcsmTl+5GPlb6fFLVtfViDPNFk 3twK7K3pTgauz6VmCQa88HNLjlhkdJlwdo2KGI+rIlfnttm1RgvwCSXagq6CeMUuJCQp 4mCw== X-Gm-Message-State: AOAM530icQGJD/hpWn9Wqh4EOKPZbpf4+5RgCEFmDTWYACa9r7idikOo MyWtoeNocztPOYVo9MeF7+kGu/Oxc7ZPkg== X-Google-Smtp-Source: ABdhPJzjZF/3Z5cUHie7wvbIZ31CUOx+xFE1T/4M5mZslXZu65NFs8ExV0Xsj+m21rO4Ah6i8YEokg== X-Received: by 2002:a37:2f01:: with SMTP id v1mr39852316qkh.351.1622050216604; Wed, 26 May 2021 10:30:16 -0700 (PDT) Received: from [192.168.1.4] ([177.194.37.86]) by smtp.gmail.com with ESMTPSA id a24sm1854996qtp.39.2021.05.26.10.30.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 26 May 2021 10:30:16 -0700 (PDT) Subject: Re: [PATCH 04/11] nptl: Add pthread_attr_setaffinity_np failure test To: Florian Weimer , Adhemerval Zanella via Libc-alpha References: <20210526165728.1772546-1-adhemerval.zanella@linaro.org> <20210526165728.1772546-5-adhemerval.zanella@linaro.org> <87k0nlqult.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella Message-ID: <47ee641e-90d9-c803-b0f4-e4238d480fd3@linaro.org> Date: Wed, 26 May 2021 14:30:14 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <87k0nlqult.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 May 2021 17:30:18 -0000 On 26/05/2021 14:21, Florian Weimer wrote: > * Adhemerval Zanella via Libc-alpha: > >> It checks whether an invalid affinity mask does return an error, >> similar to what sysdeps/pthread/tst-bad-schedattr.c does for >> pthread_attr_setschedparam. >> >> Checked on x86_64-linux-gnu. >> --- >> nptl/Makefile | 1 + >> nptl/tst-pthread-attr-affinity-fail.c | 54 +++++++++++++++++++++++++++ >> 2 files changed, 55 insertions(+) >> create mode 100644 nptl/tst-pthread-attr-affinity-fail.c >> >> diff --git a/nptl/Makefile b/nptl/Makefile >> index 16eaf58948..9a5628b751 100644 >> --- a/nptl/Makefile >> +++ b/nptl/Makefile >> @@ -286,6 +286,7 @@ tests = tst-attr2 tst-attr3 tst-default-attr \ >> tst-exec4 tst-exec5 \ >> tst-stack2 tst-stack3 tst-stack4 \ >> tst-pthread-attr-affinity \ >> + tst-pthread-attr-affinity-fail \ >> tst-dlsym1 \ >> tst-context1 \ >> tst-sched1 \ >> diff --git a/nptl/tst-pthread-attr-affinity-fail.c b/nptl/tst-pthread-attr-affinity-fail.c >> new file mode 100644 >> index 0000000000..41a87ea8cb >> --- /dev/null >> +++ b/nptl/tst-pthread-attr-affinity-fail.c >> @@ -0,0 +1,54 @@ >> +/* Check if invalid pthread_attr_getaffinity_np does not run any code >> + in the thread function. >> + Copyright (C) 2021 Free Software Foundation, Inc. >> + This file is part of the GNU C Library. >> + >> + The GNU C Library is free software; you can redistribute it and/or >> + modify it under the terms of the GNU Lesser General Public >> + License as published by the Free Software Foundation; either >> + version 2.1 of the License, or (at your option) any later version. >> + >> + The GNU C Library 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 >> + Lesser General Public License for more details. >> + >> + You should have received a copy of the GNU Lesser General Public >> + License along with the GNU C Library; if not, see >> + . */ >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +static void * >> +thr_func (void *arg) >> +{ >> + abort (); >> + return NULL; >> +} >> + >> +static int >> +do_test (void) >> +{ >> + int max_cpu = xsysconf (_SC_NPROCESSORS_CONF) + 1; >> + /* Set a affinaty mask with an invalid CPU. */ >> + cpu_set_t *cpuset = CPU_ALLOC (max_cpu); > > Perhaps: > > TEST_VERIFY_EXIT (cpuset != NULL); Ack. > >> + size_t cpusetsize = CPU_ALLOC_SIZE (max_cpu); >> + CPU_ZERO_S (cpusetsize, cpuset); >> + CPU_SET_S (max_cpu, cpusetsize, cpuset); > > You could check that sched_setaffinity with that mask fails. Like this: > > TEST_COMPARE (sched_setaffinity (0, cpusetsize, cpuset), -1); > TEST_COMPARE (errno, EINVAL); > > But feel free to push this without this change. I will integrate your suggestions.