Skip to content

Commit e0606da

Browse files
osmtenshuahkh
authored andcommitted
selftests: prctl: Add new prctl test for PR_SET_NAME
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> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 6eaae19 commit e0606da

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

tools/testing/selftests/prctl/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
55

66
ifeq ($(ARCH),x86)
77
TEST_PROGS := disable-tsc-ctxt-sw-stress-test disable-tsc-on-off-stress-test \
8-
disable-tsc-test set-anon-vma-name-test
8+
disable-tsc-test set-anon-vma-name-test set-process-name
99
all: $(TEST_PROGS)
1010

1111
include ../lib.mk
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* This test covers the PR_SET_NAME functionality of prctl calls
4+
*/
5+
6+
#include <errno.h>
7+
#include <sys/prctl.h>
8+
#include <string.h>
9+
10+
#include "../kselftest_harness.h"
11+
12+
#define CHANGE_NAME "changename"
13+
#define EMPTY_NAME ""
14+
#define TASK_COMM_LEN 16
15+
16+
int set_name(char *name)
17+
{
18+
int res;
19+
20+
res = prctl(PR_SET_NAME, name, NULL, NULL, NULL);
21+
22+
if (res < 0)
23+
return -errno;
24+
return res;
25+
}
26+
27+
int check_is_name_correct(char *check_name)
28+
{
29+
char name[TASK_COMM_LEN];
30+
int res;
31+
32+
res = prctl(PR_GET_NAME, name, NULL, NULL, NULL);
33+
34+
if (res < 0)
35+
return -errno;
36+
37+
return !strcmp(name, check_name);
38+
}
39+
40+
int check_null_pointer(char *check_name)
41+
{
42+
char *name = NULL;
43+
int res;
44+
45+
res = prctl(PR_GET_NAME, name, NULL, NULL, NULL);
46+
47+
return res;
48+
}
49+
50+
TEST(rename_process) {
51+
52+
EXPECT_GE(set_name(CHANGE_NAME), 0);
53+
EXPECT_TRUE(check_is_name_correct(CHANGE_NAME));
54+
55+
EXPECT_GE(set_name(EMPTY_NAME), 0);
56+
EXPECT_TRUE(check_is_name_correct(EMPTY_NAME));
57+
58+
EXPECT_GE(set_name(CHANGE_NAME), 0);
59+
EXPECT_LT(check_null_pointer(CHANGE_NAME), 0);
60+
}
61+
62+
TEST_HARNESS_MAIN

0 commit comments

Comments
 (0)