• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <gtest/gtest.h>
2 #include <stdio.h>
3 #include <sys/prctl.h>
4 
5 using namespace testing::ext;
6 
7 class LinuxPrctlTest : public testing::Test {
SetUp()8     void SetUp() override {}
TearDown()9     void TearDown() override {}
10 };
11 
12 /**
13  * @tc.name: prctl_001
14  * @tc.desc: This test verifies that after calling the prctl function to set the thread name, the thread name is
15  *           obtained by calling the prctl function and compared with the set thread name to ensure that the function of
16  *           setting the thread name works properly.
17  * @tc.type: FUNC
18  */
19 HWTEST_F(LinuxPrctlTest, prctl_001, TestSize.Level1)
20 {
21     const char* threadName = "ThreadName";
22     int setResult = prctl(PR_SET_NAME, static_cast<const void*>(threadName));
23     EXPECT_EQ(0, setResult);
24     char buffer[BUFSIZ];
25     memset(buffer, 0, sizeof(buffer));
26     int getResult = prctl(PR_GET_NAME, static_cast<void*>(buffer));
27     EXPECT_EQ(0, getResult);
28     EXPECT_STREQ(threadName, buffer);
29 }
30