Message ID | 20230607153600.15816-1-osmtendev@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp301320vqr; Wed, 7 Jun 2023 08:57:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4u1aPmizFnQG+wBsoLZIxRMUMHfC1K1GR5T+6OLlYTx/zsNjL6AGD17zkZqtQ+x8KeB1PH X-Received: by 2002:a17:902:ea11:b0:1b2:e0c:a408 with SMTP id s17-20020a170902ea1100b001b20e0ca408mr3504467plg.31.1686153477177; Wed, 07 Jun 2023 08:57:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686153477; cv=none; d=google.com; s=arc-20160816; b=ZQzy11SZmWp7hJ4Og5n04D9pRHWGFGa8qgfkYIeQzd8HBErJ/bBpgVBY5EMboPF3bM uf2RLUJmkl7YislHhqaicTey7HFqN3jabe/kKVSjZmTumcgtYVjDuogPdbkZlLWw2PuT pCflBrvDEbzbJXDC5XCS48VD8YoU4fYzXdCBFQAWs5L7DceVlVNblj/LVGMaGEV6sMF1 SHo7VDHAPumZw1A50A3aoACDblQz2LYT3Z8JdAPJGvHLA8s9fMdceaLseU4AkkvEPiqI TWyNfJnHxQkJwTwIhbP86tKJz702y3HQDe5F3fpOjU03kpaoFX8dhEwczTFShLpyLG5o pfQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Yw8NnBB2eVrIeNQ76jclUnfMKFC0ZCvSsvCVA2pp0w8=; b=wCvj6d5wgx/x3iP4276wd1FV6Vf4R7CBhhtRxfPqZ95PvGnWP6m22c2x2Isn72JoAp 0vTalXFXXTqet5HIMYWt0z7mQuowlLRrtmER4UFpTEX7Y8wtvtUccSvJHpBAtgOkuWoh sO+N/jOKofmNghbnoq2MdywaZGS7yqeaWgFoyhHY9YbRStFyWRsigdjm2A5uUSK3JugZ PwY2vEDNsris6EiBfUiB9WCZH1STxhHgaEPXn411fGYgoNcr15yoMENLobiBM0G/XZJQ 1iOD8orLCEzKRn5/NQ88EX0Mri3f3UsWdYbvFb6b0WgvRRTmTdVBgMp5zMhefOAY3z+A aydQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=r+lieSHx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y12-20020a170903010c00b001b024ab08fbsi8851040plc.59.2023.06.07.08.57.42; Wed, 07 Jun 2023 08:57:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=r+lieSHx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241087AbjFGPge (ORCPT <rfc822;literming00@gmail.com> + 99 others); Wed, 7 Jun 2023 11:36:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240598AbjFGPgb (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 7 Jun 2023 11:36:31 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD6558E; Wed, 7 Jun 2023 08:36:29 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-977e7d6945aso560211066b.2; Wed, 07 Jun 2023 08:36:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686152188; x=1688744188; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Yw8NnBB2eVrIeNQ76jclUnfMKFC0ZCvSsvCVA2pp0w8=; b=r+lieSHxxcxOsum/U4sQs6DxlvivqcGA1Qi7YMCYD0+6yMmaBhxQ2ijmuSOcC7Sfgo JoHN/K+5zkj2h4tBDBr2p93HRjLvTbNd2jwyRGLGoezeE4EALPmA5Rajd8+gyh+m4hGh UdfW3ccM2D7UJoXvv9LzRyLHdyr2ZhmcUG7yhhoa6s+0Yx/h1tZ5gavYMKbBIlZWHCVx Wikgl/6evBRKD2ZAQ+2wtud6CP0QRoJgPkTiYXbjyMBXcuaFhFQ5c6HNwjmDmmmIx5VX /802K+cKYLt7E6nbzAEbuVZ+gWENIdcYdQEnDLwF55PSd5Ep9m3dWrEK7eobb6qYrnaF mWBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686152188; x=1688744188; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Yw8NnBB2eVrIeNQ76jclUnfMKFC0ZCvSsvCVA2pp0w8=; b=YJuwaC3YJHo5mOFO+A04QlQTz0mOUDqOpxKvF0Hd+q9B0FaBZ1nXYip57ElmwpXCm7 6pQNAUppOifgWxUCca/FpMvi1T57TTxVepMftymYkGv8h6BAipse9dCa7jyaQpNObCvI 57jWAVgkEEdUbIyJ3EwmyKfeIXUSscPfJHWAIPGA53CMw+zsRcLSq0Wy+Ti5H3IGB+Ne WQ6SL9x0u6gev4qnf04fautnAwpSJCkPEYFJC+KJCIRNJXEXK46i9Bj2AFLBiRvrLINv OylZDSlBEYSnnbzL+t92kgTUHMgLN6oNQ05hLlvlof7pTPZ+B3tfouxXVbSMiweYcuHv mONg== X-Gm-Message-State: AC+VfDxevl3dRQjYB3YxDkBtdl7guJOJSYZf88TUU/FknOIYjSGMP3ak fle8S12jP+0oRABCZ6X4mj4BMIYdgbM= X-Received: by 2002:a17:907:6d98:b0:96f:ea85:3ef6 with SMTP id sb24-20020a1709076d9800b0096fea853ef6mr6869464ejc.62.1686152187484; Wed, 07 Jun 2023 08:36:27 -0700 (PDT) Received: from Osmten.. ([103.84.150.92]) by smtp.gmail.com with ESMTPSA id p22-20020a170906499600b0097866bc5119sm2398069eju.200.2023.06.07.08.36.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 08:36:27 -0700 (PDT) From: Osama Muhammad <osmtendev@gmail.com> To: shuah@kernel.org Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Osama Muhammad <osmtendev@gmail.com> Subject: [PATCH v2] selftests: prctl: Add new prctl test for PR_SET_NAME Date: Wed, 7 Jun 2023 20:36:00 +0500 Message-Id: <20230607153600.15816-1-osmtendev@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768060068592429198?= X-GMAIL-MSGID: =?utf-8?q?1768060068592429198?= |
Series |
[v2] selftests: prctl: Add new prctl test for PR_SET_NAME
|
|
Commit Message
Osama Muhammad
June 7, 2023, 3:36 p.m. UTC
This patch will add the new test, which covers the prctl call
PR_SET_NAME command. The test tries to give a name using the PR_SET_NAME
call and then confirm it that it changed correctly by using PR_GET_NAME.
It also tries to rename it with empty name.In the test PR_GET_NAME is
tested by passing null pointer to it and check its behaviour.
Signed-off-by: Osama Muhammad <osmtendev@gmail.com>
---
changes since v1:
-Used TASK_COMM_LEN instead of using numerical value 16.
---
tools/testing/selftests/prctl/Makefile | 2 +-
.../selftests/prctl/set-process-name.c | 62 +++++++++++++++++++
2 files changed, 63 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/selftests/prctl/set-process-name.c
Comments
On 6/7/23 09:36, Osama Muhammad wrote: > This patch will add the new test, which covers the prctl call > PR_SET_NAME command. The test tries to give a name using the PR_SET_NAME > call and then confirm it that it changed correctly by using PR_GET_NAME. > It also tries to rename it with empty name.In the test PR_GET_NAME is > tested by passing null pointer to it and check its behaviour. > > Signed-off-by: Osama Muhammad <osmtendev@gmail.com> > > --- > changes since v1: > -Used TASK_COMM_LEN instead of using numerical value 16. Please add linux/sched.h here as an include to pull this. It is good to add an explicit include as opposed taking a chance on it being included from another include. thanks, -- Shuah
Hi all, I looked into it and tried to use TASK_COMM_LEN in the test. Even though I included "linux/sched.h '', I was not able to compile the test because it couldn't find it in the header file. I dived deep into the issue and turns out header file mapped in /usr/include/linux/sched.h is actually mapped to /include/uapi/linux/sched.h[1] in linux source, where TASK_COMM_LEN is not even defined. Instead TASK_COMM_LEN is defined in /include/linux/sched.h which is not mapped to any header files in userspace(/(/usr/include/linux). I also tried to find the TASK_COM_LEN in /usr/include/linux/ but I couldn't find it. Following are the search results. grep -rnw '/usr/include/linux/' -e 'TASK_COMM_LEN" RESULTS OF COMMAND :- /usr/include/linux/taskstats.h:38:#define TS_COMM_LEN 32 /* should be >= TASK_COMM_LEN Based on this information, I have two questions: 1. Would this require a fix to move 'TASK_COMM_LEN' macro from /include/linux/sched.h to UAPI headers /include/uapi/linux/sched.h. 2. Is there any other way to access TASK_COMM_LEN in the selftest that I'm not aware of? [1]:-https://elixir.bootlin.com/linux/v5.15.116/source/include/uapi/linux/sched.h Thanks, Osama On Sat, 10 Jun 2023 at 02:43, Shuah Khan <skhan@linuxfoundation.org> wrote: > > On 6/7/23 09:36, Osama Muhammad wrote: > > This patch will add the new test, which covers the prctl call > > PR_SET_NAME command. The test tries to give a name using the PR_SET_NAME > > call and then confirm it that it changed correctly by using PR_GET_NAME. > > It also tries to rename it with empty name.In the test PR_GET_NAME is > > tested by passing null pointer to it and check its behaviour. > > > > Signed-off-by: Osama Muhammad <osmtendev@gmail.com> > > > > --- > > changes since v1: > > -Used TASK_COMM_LEN instead of using numerical value 16. > > Please add linux/sched.h here as an include to pull this. > It is good to add an explicit include as opposed taking > a chance on it being included from another include. > > thanks, > -- Shuah
On 6/10/23 07:01, Osama Muhammad wrote: > Hi all, > > I looked into it and tried to use TASK_COMM_LEN in the test. Even > though I included "linux/sched.h '', I was not able to compile the > test because it couldn't find it in the header file. > I dived deep into the issue and turns out header file mapped in > /usr/include/linux/sched.h is actually mapped to > /include/uapi/linux/sched.h[1] in linux source, > where TASK_COMM_LEN is not even defined. Instead TASK_COMM_LEN is > defined in /include/linux/sched.h which is not mapped to any header > files in > userspace(/(/usr/include/linux). > I also tried to find the TASK_COM_LEN in /usr/include/linux/ but I > couldn't find it. Following are the search results. > grep -rnw '/usr/include/linux/' -e 'TASK_COMM_LEN" > RESULTS OF COMMAND :- /usr/include/linux/taskstats.h:38:#define > TS_COMM_LEN 32 /* should be >= TASK_COMM_LEN > Based on this information, I have two questions: > 1. Would this require a fix to move 'TASK_COMM_LEN' macro from > /include/linux/sched.h to UAPI headers /include/uapi/linux/sched.h. > 2. Is there any other way to access TASK_COMM_LEN in the selftest that > I'm not aware of? > > [1]:-https://elixir.bootlin.com/linux/v5.15.116/source/include/uapi/linux/sched.h > The best source is Linux mainline. Take a look at test files that include linux/sched.h arm64/abi/tpidr2.c is one of them. Did you install headers before compiling the test? make headers_install thanks, -- Shuah
Hi, Yes, I did install the latest kernel headers and TASK_COMM_LEN is not accessible in userspace. I looked into the test which uses TASK_COMM_LEN but the test defines it in its own header file. Example: https://elixir.bootlin.com/linux/latest/source/tools/testing/selftests/bpf/progs/pyperf.h#L13 TASK_COMM_LEN is defined in include/linux/sched.h, but this header file is not exposed to userspace. TASK_COMM_LEN is not defined in /include/uapi/linux/sched.h which is exposed to userspace kernel headers. Please find the link to the header file exposed to user space :- -https://elixir.bootlin.com/linux/v5.15.116/source/include/uapi/linux/sched.h As for arm64/abi/tpidr2.c It includes linux/sched.h which will be /include/uapi/linux/sched.h because the user space program is including it. So it also cannot use TASK_COMM_LEN directly. Regards, Osama On Tue, 13 Jun 2023 at 02:56, Shuah Khan <skhan@linuxfoundation.org> wrote: > > On 6/10/23 07:01, Osama Muhammad wrote: > > Hi all, > > > > I looked into it and tried to use TASK_COMM_LEN in the test. Even > > though I included "linux/sched.h '', I was not able to compile the > > test because it couldn't find it in the header file. > > I dived deep into the issue and turns out header file mapped in > > /usr/include/linux/sched.h is actually mapped to > > /include/uapi/linux/sched.h[1] in linux source, > > where TASK_COMM_LEN is not even defined. Instead TASK_COMM_LEN is > > defined in /include/linux/sched.h which is not mapped to any header > > files in > > userspace(/(/usr/include/linux). > > I also tried to find the TASK_COM_LEN in /usr/include/linux/ but I > > couldn't find it. Following are the search results. > > grep -rnw '/usr/include/linux/' -e 'TASK_COMM_LEN" > > RESULTS OF COMMAND :- /usr/include/linux/taskstats.h:38:#define > > TS_COMM_LEN 32 /* should be >= TASK_COMM_LEN > > Based on this information, I have two questions: > > 1. Would this require a fix to move 'TASK_COMM_LEN' macro from > > /include/linux/sched.h to UAPI headers /include/uapi/linux/sched.h. > > 2. Is there any other way to access TASK_COMM_LEN in the selftest that > > I'm not aware of? > > > > [1]:-https://elixir.bootlin.com/linux/v5.15.116/source/include/uapi/linux/sched.h > > > > The best source is Linux mainline. > > Take a look at test files that include linux/sched.h > > arm64/abi/tpidr2.c is one of them. > > Did you install headers before compiling the test? > make headers_install > > thanks, > -- Shuah > >
Hi Shuah, Any feedback on this patch?. Thanks, Osama On Sat, 17 Jun 2023 at 18:01, Osama Muhammad <osmtendev@gmail.com> wrote: > > Hi, > > Yes, I did install the latest kernel headers and TASK_COMM_LEN is not > accessible in userspace. > > I looked into the test which uses TASK_COMM_LEN but the test defines > it in its own header file. > > Example: https://elixir.bootlin.com/linux/latest/source/tools/testing/selftests/bpf/progs/pyperf.h#L13 > > TASK_COMM_LEN is defined in include/linux/sched.h, but this header > file is not exposed to userspace. > > TASK_COMM_LEN is not defined in /include/uapi/linux/sched.h which is > exposed to userspace kernel headers. > Please find the link to the header file exposed to user space :- > -https://elixir.bootlin.com/linux/v5.15.116/source/include/uapi/linux/sched.h > > As for arm64/abi/tpidr2.c It includes linux/sched.h which will be > /include/uapi/linux/sched.h because the user space program is > including it. > So it also cannot use TASK_COMM_LEN directly. > > Regards, > Osama > > On Tue, 13 Jun 2023 at 02:56, Shuah Khan <skhan@linuxfoundation.org> wrote: > > > > On 6/10/23 07:01, Osama Muhammad wrote: > > > Hi all, > > > > > > I looked into it and tried to use TASK_COMM_LEN in the test. Even > > > though I included "linux/sched.h '', I was not able to compile the > > > test because it couldn't find it in the header file. > > > I dived deep into the issue and turns out header file mapped in > > > /usr/include/linux/sched.h is actually mapped to > > > /include/uapi/linux/sched.h[1] in linux source, > > > where TASK_COMM_LEN is not even defined. Instead TASK_COMM_LEN is > > > defined in /include/linux/sched.h which is not mapped to any header > > > files in > > > userspace(/(/usr/include/linux). > > > I also tried to find the TASK_COM_LEN in /usr/include/linux/ but I > > > couldn't find it. Following are the search results. > > > grep -rnw '/usr/include/linux/' -e 'TASK_COMM_LEN" > > > RESULTS OF COMMAND :- /usr/include/linux/taskstats.h:38:#define > > > TS_COMM_LEN 32 /* should be >= TASK_COMM_LEN > > > Based on this information, I have two questions: > > > 1. Would this require a fix to move 'TASK_COMM_LEN' macro from > > > /include/linux/sched.h to UAPI headers /include/uapi/linux/sched.h. > > > 2. Is there any other way to access TASK_COMM_LEN in the selftest that > > > I'm not aware of? > > > > > > [1]:-https://elixir.bootlin.com/linux/v5.15.116/source/include/uapi/linux/sched.h > > > > > > > The best source is Linux mainline. > > > > Take a look at test files that include linux/sched.h > > > > arm64/abi/tpidr2.c is one of them. > > > > Did you install headers before compiling the test? > > make headers_install > > > > thanks, > > -- Shuah > > > >
On 6/10/23 2:43 AM, Shuah Khan wrote: > On 6/7/23 09:36, Osama Muhammad wrote: >> This patch will add the new test, which covers the prctl call >> PR_SET_NAME command. The test tries to give a name using the PR_SET_NAME >> call and then confirm it that it changed correctly by using PR_GET_NAME. >> It also tries to rename it with empty name.In the test PR_GET_NAME is >> tested by passing null pointer to it and check its behaviour. >> >> Signed-off-by: Osama Muhammad <osmtendev@gmail.com> >> >> --- >> changes since v1: >> -Used TASK_COMM_LEN instead of using numerical value 16. > > Please add linux/sched.h here as an include to pull this. > It is good to add an explicit include as opposed taking > a chance on it being included from another include. TASK_COMM_LEN is defined in include/linux/sched.h. It is only to be used by the kernel. If we look at include/uapi/linux/sched.h, TASK_COMM_LEN isn't defined. So this test looks good to me. > > thanks, > -- Shuah
Hi, Thank you for the patch. This patch cleanly applies on next-20230627. Unrelated to this patch: I'm not sure if this patch was written against linux next. Always try to send patches against latest next tag from following repo: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git On 6/26/23 11:36 PM, Osama Muhammad wrote: > Hi Shuah, > > Any feedback on this patch?. > > Thanks, > Osama > > > On Sat, 17 Jun 2023 at 18:01, Osama Muhammad <osmtendev@gmail.com> wrote: >> >> Hi, >> >> Yes, I did install the latest kernel headers and TASK_COMM_LEN is not >> accessible in userspace. >> >> I looked into the test which uses TASK_COMM_LEN but the test defines >> it in its own header file. >> >> Example: https://elixir.bootlin.com/linux/latest/source/tools/testing/selftests/bpf/progs/pyperf.h#L13 >> >> TASK_COMM_LEN is defined in include/linux/sched.h, but this header >> file is not exposed to userspace. >> >> TASK_COMM_LEN is not defined in /include/uapi/linux/sched.h which is >> exposed to userspace kernel headers. >> Please find the link to the header file exposed to user space :- >> -https://elixir.bootlin.com/linux/v5.15.116/source/include/uapi/linux/sched.h >> >> As for arm64/abi/tpidr2.c It includes linux/sched.h which will be >> /include/uapi/linux/sched.h because the user space program is >> including it. >> So it also cannot use TASK_COMM_LEN directly. >> >> Regards, >> Osama >> >> On Tue, 13 Jun 2023 at 02:56, Shuah Khan <skhan@linuxfoundation.org> wrote: >>> >>> On 6/10/23 07:01, Osama Muhammad wrote: >>>> Hi all, >>>> >>>> I looked into it and tried to use TASK_COMM_LEN in the test. Even >>>> though I included "linux/sched.h '', I was not able to compile the >>>> test because it couldn't find it in the header file. >>>> I dived deep into the issue and turns out header file mapped in >>>> /usr/include/linux/sched.h is actually mapped to >>>> /include/uapi/linux/sched.h[1] in linux source, >>>> where TASK_COMM_LEN is not even defined. Instead TASK_COMM_LEN is >>>> defined in /include/linux/sched.h which is not mapped to any header >>>> files in >>>> userspace(/(/usr/include/linux). >>>> I also tried to find the TASK_COM_LEN in /usr/include/linux/ but I >>>> couldn't find it. Following are the search results. >>>> grep -rnw '/usr/include/linux/' -e 'TASK_COMM_LEN" >>>> RESULTS OF COMMAND :- /usr/include/linux/taskstats.h:38:#define >>>> TS_COMM_LEN 32 /* should be >= TASK_COMM_LEN >>>> Based on this information, I have two questions: >>>> 1. Would this require a fix to move 'TASK_COMM_LEN' macro from >>>> /include/linux/sched.h to UAPI headers /include/uapi/linux/sched.h. >>>> 2. Is there any other way to access TASK_COMM_LEN in the selftest that >>>> I'm not aware of? >>>> >>>> [1]:-https://elixir.bootlin.com/linux/v5.15.116/source/include/uapi/linux/sched.h >>>> >>> >>> The best source is Linux mainline. >>> >>> Take a look at test files that include linux/sched.h >>> >>> arm64/abi/tpidr2.c is one of them. >>> >>> Did you install headers before compiling the test? >>> make headers_install >>> >>> thanks, >>> -- Shuah >>> >>>
Unrelated to this patch: You can build the user header files by running `make headers` in a kernel repository to process the kernel header files. They are generated in <kernel_source>/include/uapi Then run `make -C tools/testing/selftests/prctl` to build the test etc. On 6/7/23 8:36 PM, Osama Muhammad wrote: > This patch will add the new test, which covers the prctl call > PR_SET_NAME command. The test tries to give a name using the PR_SET_NAME > call and then confirm it that it changed correctly by using PR_GET_NAME. > It also tries to rename it with empty name.In the test PR_GET_NAME is > tested by passing null pointer to it and check its behaviour. > > Signed-off-by: Osama Muhammad <osmtendev@gmail.com> Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com> Tested-by: Muhammad Usama Anjum <usama.anjum@collabora.com> > > --- > changes since v1: > -Used TASK_COMM_LEN instead of using numerical value 16. > > --- > tools/testing/selftests/prctl/Makefile | 2 +- > .../selftests/prctl/set-process-name.c | 62 +++++++++++++++++++ > 2 files changed, 63 insertions(+), 1 deletion(-) > create mode 100644 tools/testing/selftests/prctl/set-process-name.c > > diff --git a/tools/testing/selftests/prctl/Makefile b/tools/testing/selftests/prctl/Makefile > index c058b81ee..cfc35d29f 100644 > --- a/tools/testing/selftests/prctl/Makefile > +++ b/tools/testing/selftests/prctl/Makefile > @@ -5,7 +5,7 @@ ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/) > > ifeq ($(ARCH),x86) > TEST_PROGS := disable-tsc-ctxt-sw-stress-test disable-tsc-on-off-stress-test \ > - disable-tsc-test set-anon-vma-name-test > + disable-tsc-test set-anon-vma-name-test set-process-name > all: $(TEST_PROGS) > > include ../lib.mk > diff --git a/tools/testing/selftests/prctl/set-process-name.c b/tools/testing/selftests/prctl/set-process-name.c > new file mode 100644 > index 000000000..3bc5e0e09 > --- /dev/null > +++ b/tools/testing/selftests/prctl/set-process-name.c > @@ -0,0 +1,62 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * This test covers the PR_SET_NAME functionality of prctl calls > + */ > + > +#include <errno.h> > +#include <sys/prctl.h> > +#include <string.h> > + > +#include "../kselftest_harness.h" > + > +#define CHANGE_NAME "changename" > +#define EMPTY_NAME "" > +#define TASK_COMM_LEN 16 > + > +int set_name(char *name) > +{ > + int res; > + > + res = prctl(PR_SET_NAME, name, NULL, NULL, NULL); > + > + if (res < 0) > + return -errno; > + return res; > +} > + > +int check_is_name_correct(char *check_name) > +{ > + char name[TASK_COMM_LEN]; > + int res; > + > + res = prctl(PR_GET_NAME, name, NULL, NULL, NULL); > + > + if (res < 0) > + return -errno; > + > + return !strcmp(name, check_name); > +} > + > +int check_null_pointer(char *check_name) > +{ > + char *name = NULL; > + int res; > + > + res = prctl(PR_GET_NAME, name, NULL, NULL, NULL); > + > + return res; > +} > + > +TEST(rename_process) { > + > + EXPECT_GE(set_name(CHANGE_NAME), 0); > + EXPECT_TRUE(check_is_name_correct(CHANGE_NAME)); > + > + EXPECT_GE(set_name(EMPTY_NAME), 0); > + EXPECT_TRUE(check_is_name_correct(EMPTY_NAME)); > + > + EXPECT_GE(set_name(CHANGE_NAME), 0); > + EXPECT_LT(check_null_pointer(CHANGE_NAME), 0); > +} > + > +TEST_HARNESS_MAIN
On 6/26/23 12:36, Osama Muhammad wrote: > Hi Shuah, > > Any feedback on this patch?. > > Thanks, > Osama > > Please don't top post when you are responding on kernel mailing lists. It gets very difficult to follow the comments in the email thread. > On Sat, 17 Jun 2023 at 18:01, Osama Muhammad <osmtendev@gmail.com> wrote: >> >> Hi, >> >> Yes, I did install the latest kernel headers and TASK_COMM_LEN is not >> accessible in userspace. >> >> I looked into the test which uses TASK_COMM_LEN but the test defines >> it in its own header file. >> >> Example: https://elixir.bootlin.com/linux/latest/source/tools/testing/selftests/bpf/progs/pyperf.h#L13 bfp test does things differently because its dependencies on run-time environment. >> >> TASK_COMM_LEN is defined in include/linux/sched.h, but this header >> file is not exposed to userspace. Correct. you can include linux/sched.h like other tests do Take a look at tools/testing/selftests/clone3 thanks, -- Shuah
On 7/14/23 10:21, Shuah Khan wrote: > On 6/26/23 12:36, Osama Muhammad wrote: >> Hi Shuah, >> >> Any feedback on this patch?. >> >> Thanks, >> Osama >> >> > > Please don't top post when you are responding on kernel > mailing lists. It gets very difficult to follow the > comments in the email thread. > >> On Sat, 17 Jun 2023 at 18:01, Osama Muhammad <osmtendev@gmail.com> wrote: >>> >>> Hi, >>> >>> Yes, I did install the latest kernel headers and TASK_COMM_LEN is not >>> accessible in userspace. >>> >>> I looked into the test which uses TASK_COMM_LEN but the test defines >>> it in its own header file. >>> >>> Example: https://elixir.bootlin.com/linux/latest/source/tools/testing/selftests/bpf/progs/pyperf.h#L13 > > bfp test does things differently because its dependencies > on run-time environment. > >>> >>> TASK_COMM_LEN is defined in include/linux/sched.h, but this header >>> file is not exposed to userspace. > > Correct. you can include linux/sched.h like other tests do > Take a look at tools/testing/selftests/clone3 > You are right about TASK_COMM_LEN not visible to user-space. This patch has been applied to linux-kselftest next for 6.6-rc1 thanks, -- Shuah
diff --git a/tools/testing/selftests/prctl/Makefile b/tools/testing/selftests/prctl/Makefile index c058b81ee..cfc35d29f 100644 --- a/tools/testing/selftests/prctl/Makefile +++ b/tools/testing/selftests/prctl/Makefile @@ -5,7 +5,7 @@ ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/) ifeq ($(ARCH),x86) TEST_PROGS := disable-tsc-ctxt-sw-stress-test disable-tsc-on-off-stress-test \ - disable-tsc-test set-anon-vma-name-test + disable-tsc-test set-anon-vma-name-test set-process-name all: $(TEST_PROGS) include ../lib.mk diff --git a/tools/testing/selftests/prctl/set-process-name.c b/tools/testing/selftests/prctl/set-process-name.c new file mode 100644 index 000000000..3bc5e0e09 --- /dev/null +++ b/tools/testing/selftests/prctl/set-process-name.c @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * This test covers the PR_SET_NAME functionality of prctl calls + */ + +#include <errno.h> +#include <sys/prctl.h> +#include <string.h> + +#include "../kselftest_harness.h" + +#define CHANGE_NAME "changename" +#define EMPTY_NAME "" +#define TASK_COMM_LEN 16 + +int set_name(char *name) +{ + int res; + + res = prctl(PR_SET_NAME, name, NULL, NULL, NULL); + + if (res < 0) + return -errno; + return res; +} + +int check_is_name_correct(char *check_name) +{ + char name[TASK_COMM_LEN]; + int res; + + res = prctl(PR_GET_NAME, name, NULL, NULL, NULL); + + if (res < 0) + return -errno; + + return !strcmp(name, check_name); +} + +int check_null_pointer(char *check_name) +{ + char *name = NULL; + int res; + + res = prctl(PR_GET_NAME, name, NULL, NULL, NULL); + + return res; +} + +TEST(rename_process) { + + EXPECT_GE(set_name(CHANGE_NAME), 0); + EXPECT_TRUE(check_is_name_correct(CHANGE_NAME)); + + EXPECT_GE(set_name(EMPTY_NAME), 0); + EXPECT_TRUE(check_is_name_correct(EMPTY_NAME)); + + EXPECT_GE(set_name(CHANGE_NAME), 0); + EXPECT_LT(check_null_pointer(CHANGE_NAME), 0); +} + +TEST_HARNESS_MAIN