Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp18159279rwd; Tue, 27 Jun 2023 12:32:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5AOZ/0B0tjhM4uMK3lEACriCRXqGm3GwZTxKXyy4rzp2FWQlsydwDPDWy1Vy8NJ+UWIX7G X-Received: by 2002:a17:906:974c:b0:989:4952:bf9f with SMTP id o12-20020a170906974c00b009894952bf9fmr19186727ejy.26.1687894345302; Tue, 27 Jun 2023 12:32:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687894345; cv=none; d=google.com; s=arc-20160816; b=HDILD+iEBZ1xVnDVOeDzc9lxr3aN1GBjOfX2N0YiCtKBgFUBL3jTNhMpeHRyUf3bks Klm4FBzL70i+7sqxJp0dhsGeQGRCLRIglVjTNoqxwatLFtSyuCTGw4W8qKNDtlp36MeY ceJ1NL6E52RODTp2kuqUbcoeQHIKIvq7xwsKO67JnIp4aP9i94hjqlYRnNA/xgIDTMyQ 2qbHNp68CiUsxPa0gMdhQsaE8N7pXt3PJPoOwtmVY9E330jjeSTFOJ7yIMmF5di86RQ6 tURKpuPAooAOPPqjtWgbiPCPEoPioFIxM0B7ziCW1U/LQJQQ4XriUwYhVcq5o42WhuyL d/tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=Fxj4Nb9zghmFnFjW1tIGOjCk7rvk6MLVKBR3V8U1MWk=; fh=5iY8m5e4io2XFUkPx4NkRnwN86OcJ3KV3oSQ63Wsrr8=; b=IOkwpwGqlwr4IMBlOGOyDXdSIbt62JpF2b2niUqlmm5xMijoBSxHDOvZc8OKv59Vpt esdh9pU3w+TUqCiulAaeMxzlVGVRNxMiaP4n89xyASq6M6Ta7X7BcAB7nJJJ9Bc/4ka8 io+n2S7+Z9tRv5oD1zWgDIyBFRrbO1dy4fbTVvcD6fBlb18sEiVbc5uQ3TJ9RfEyRscp 2pgbwGu8rY9eHhcp3aat5zTpO/dVN0zxtCCiRKYXvcci+sJ1xDQGxjYUTzYDCaY9MLIP 6CwXpD9ssifSKtlyyZ7XlbsQKH2FLgqCxDc2/VZmcu/8v50+jE1EyHp6MMluEeKcc8iZ BsWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="MGkS/O5M"; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qx9-20020a170906fcc900b0098874379199si4438208ejb.163.2023.06.27.12.32.00; Tue, 27 Jun 2023 12:32:25 -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=@collabora.com header.s=mail header.b="MGkS/O5M"; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230002AbjF0TJB (ORCPT + 99 others); Tue, 27 Jun 2023 15:09:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbjF0TI7 (ORCPT ); Tue, 27 Jun 2023 15:08:59 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BFEBFD; Tue, 27 Jun 2023 12:08:57 -0700 (PDT) Received: from [192.168.10.54] (unknown [182.179.162.32]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: usama.anjum) by madras.collabora.co.uk (Postfix) with ESMTPSA id AA24F6607165; Tue, 27 Jun 2023 20:08:54 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687892936; bh=NQDlzaX3MiB53zJheAaS4x+ijWekgq2JrH0gJe+g+tc=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=MGkS/O5MaDzDXDi24ojsh+0nLwUS1FFIP0HARhsRWv40RYMsAhdqkSu0BCKbbttyS U2aMqaxhXPj6Hny+J4aOnpFr+Po3mFJ0o9ndgF8VqJrJTN1B9En2hFzrABgndyAJAu CX25FxiC8yYP7uhgry/1hWHzkB/lS3cmrsEW4JGE5VxkGXxe1+Nlq7RQUPy745EYjW fswes+9Lvo2GCTA27O86sFCGPUbErILPWIArgLE09a1G3WeqynZ8pIX77s0XXQcXe4 tHwalPURKzgrd4s66FqDcSEKU5x5VD1mHWf3UuxGsGs+iqBZtahxRW3iGqErsd+9DW T/O9S9unz+EtQ== Message-ID: <732c535d-97cd-429f-3c1d-eda7a57df001@collabora.com> Date: Wed, 28 Jun 2023 00:08:50 +0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Cc: Muhammad Usama Anjum , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH v2] selftests: prctl: Add new prctl test for PR_SET_NAME Content-Language: en-US To: Osama Muhammad , shuah@kernel.org References: <20230607153600.15816-1-osmtendev@gmail.com> From: Muhammad Usama Anjum In-Reply-To: <20230607153600.15816-1-osmtendev@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,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: X-Mailing-List: linux-kernel@vger.kernel.org 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 /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 Reviewed-by: Muhammad Usama Anjum Tested-by: Muhammad Usama Anjum > > --- > 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 > +#include > +#include > + > +#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 -- BR, Muhammad Usama Anjum