From patchwork Tue Jun 6 17:55:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Osama Muhammad X-Patchwork-Id: 104020 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3585692vqr; Tue, 6 Jun 2023 11:16:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ52vtuxKL6S3vpdYsw9xYutiOm74rT6iAXay+wOYiSYk3GoiOqO4Lr8MIL72j9WoOS7m/uw X-Received: by 2002:a05:6a00:1a05:b0:659:4b77:51e8 with SMTP id g5-20020a056a001a0500b006594b7751e8mr3777638pfv.15.1686075385922; Tue, 06 Jun 2023 11:16:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686075385; cv=none; d=google.com; s=arc-20160816; b=CzUJJKTwnZBC+ibJkPPaNHr/lr0PwIVifxBufTt8m3lwl+enpn6THztxwib43EzL6C zrkHodjk3SOieQCutSmp56p+ZPRt0QY7C/EKAMfbOXoN79lW6Bll3scAEOr0iDotrxg8 3+69cGWNIXY7p73mTpQTR4NwFfOCudgnBCxFBJfamTnI71U9qEKV5H+qe9nf/Pp06mjw lRhOf3oOGxy9gFcoJknj/NdYwLLnQgpY5NtRcX1B3R5Xh8K2xjuSYyobuxBayoFpOvXG c5CZMTr98UoTLbI31x519QVY5Yk5muQrYqazsgRQwxMWyh+kesATiPEuqVJKL9P6dPna KlUg== 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=7V43niT3bFuzcXVb3owqhMz6/rSNqxbUJG0mdfeT+pM=; b=OM9OwY8C7Sd2F3ewPyUqFmP+N5CQIA4DbdrN4ZNZBdJiiVxOnF9KDjHCZjUr86LbxZ Ev5RV1GTorx9AyE8/4qcZ8cEtj6NXll3t8aLT/1nRffxlUXyc4NGzzGJUjpuufU+052Y lggc5Jmh07VZBdp2HKVpn6FtT8Tgdh78DfCgOkEUeXd94Vg6JXGwOyVHx/joZrizxKrn d3iwRCpYAcekDrn+GTZ9Ehkj/SSfKAf3Iqig1VnsT7iGiNhwKytUpuUeqpM8BryQJaCl sFV0VKbVp2+mbVa+S/uMu2drRply0cqYYdtZirwrHL6rQp0GP6dYl3PQ+BS6io7bct+2 Upvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=j6sD2SnD; 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 w4-20020a656944000000b0053ef547263bsi7473581pgq.165.2023.06.06.11.16.13; Tue, 06 Jun 2023 11:16: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=@gmail.com header.s=20221208 header.b=j6sD2SnD; 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 S238168AbjFFR4I (ORCPT + 99 others); Tue, 6 Jun 2023 13:56:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233000AbjFFR4F (ORCPT ); Tue, 6 Jun 2023 13:56:05 -0400 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C7EBE47; Tue, 6 Jun 2023 10:56:03 -0700 (PDT) Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2b1ac373c9eso61864451fa.0; Tue, 06 Jun 2023 10:56:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686074162; x=1688666162; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=7V43niT3bFuzcXVb3owqhMz6/rSNqxbUJG0mdfeT+pM=; b=j6sD2SnD9ZobF4KFq0rNVOUnr9PigavlPpCS0RKJelwFZOncbRQbPqXbppk3E8bwMv VbXO4i61rpW2enpq8P5ywFpxth5rLOO37QxF4i5DpeFGFg1VvfLHIFjevempn8PPq4zr 4ZIFNQKVJcRy3hsHlS6uxHFPjc2upAjZZWV7dt/1XAmVP/R4rT0Z8myheU4K7yZuKZwt BwMrmSKCyRjah5zoJNskAuRtTObMy4qTEv15JlI7o7xWCJTXB+X6FwG74uKxTJlY+OzQ FruvtptPFkRT+raByoLx4drv8zBKIijVtLwjqEMf8JLNuug01OqbtZuNZic0YMsvjk4O 9cng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686074162; x=1688666162; 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=7V43niT3bFuzcXVb3owqhMz6/rSNqxbUJG0mdfeT+pM=; b=QIpNLZ2fZ4Z3Dkc4hUOTVDtRaFsTJfc+rBuCaxcAUpUhfQIu2X5j0G2qoJvetjCxUP 2d7zWwKXYhbMSFP8WyF6uN7sbh1Rh3WoenHXnDijXMIyRXk4zXoul7EmJMVdLRC7ynsZ SWfMmUGoc6tuZ5uK1C11fpgRsw3w/UJg/4B07OvwJhMrJc6ZhFxHGPvk9YsDDuSJrUAx DjkWrQ4ltnolxlzFIaD8UYUp4e1CfUCUhUbHHxE7L//gGGdjA8dcKEpl0SZqKOkcjVeC Ntdj3OoAK5vO94CmXAkqTX+MiiX9BNs46kTT0rS1W/nhaYDhSRISJyttJDiIdpOdb9bq x6OQ== X-Gm-Message-State: AC+VfDw1nMqQubRUx4WrtJz/iU1VwXyJnxC4hxalnPO5iO1npMZ2L0Wv x2icCJzcD/kGG0SAo0+61LEw7Hp1ow8= X-Received: by 2002:a2e:9215:0:b0:2b1:a810:e442 with SMTP id k21-20020a2e9215000000b002b1a810e442mr1354865ljg.49.1686074161246; Tue, 06 Jun 2023 10:56:01 -0700 (PDT) Received: from Osmten.. ([103.84.150.69]) by smtp.gmail.com with ESMTPSA id y4-20020a05651c020400b002ab1536377fsm1892439ljn.105.2023.06.06.10.55.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 10:56:00 -0700 (PDT) From: Osama Muhammad To: shuah@kernel.org Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, ivan.orlov0322@gmail.com, Osama Muhammad Subject: [PATCH] selftests: prctl: Add new prctl test for PR_SET_NAME Date: Tue, 6 Jun 2023 22:55:15 +0500 Message-Id: <20230606175515.12855-1-osmtendev@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767978183966808588?= X-GMAIL-MSGID: =?utf-8?q?1767978183966808588?= 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 --- tools/testing/selftests/prctl/Makefile | 2 +- .../selftests/prctl/set-process-name.c | 61 +++++++++++++++++++ 2 files changed, 62 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..12c5ed9a5 --- /dev/null +++ b/tools/testing/selftests/prctl/set-process-name.c @@ -0,0 +1,61 @@ +// 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 "" + +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[16]; + 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