From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id EE5F93945C2B for ; Wed, 26 May 2021 17:21:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EE5F93945C2B Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-538-CXA7HYqtOG-G9vvfVHDOzw-1; Wed, 26 May 2021 13:21:22 -0400 X-MC-Unique: CXA7HYqtOG-G9vvfVHDOzw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 32DB1800D55; Wed, 26 May 2021 17:21:21 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-113-228.ams2.redhat.com [10.36.113.228]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5637060875; Wed, 26 May 2021 17:21:20 +0000 (UTC) From: Florian Weimer To: Adhemerval Zanella via Libc-alpha Subject: Re: [PATCH 04/11] nptl: Add pthread_attr_setaffinity_np failure test References: <20210526165728.1772546-1-adhemerval.zanella@linaro.org> <20210526165728.1772546-5-adhemerval.zanella@linaro.org> Date: Wed, 26 May 2021 19:21:18 +0200 In-Reply-To: <20210526165728.1772546-5-adhemerval.zanella@linaro.org> (Adhemerval Zanella via Libc-alpha's message of "Wed, 26 May 2021 13:57:21 -0300") Message-ID: <87k0nlqult.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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:21:27 -0000 * 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); > + 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. Thanks, Florian