• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20  * IN THE SOFTWARE.
21  */
22 
23 #include <errno.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <dlfcn.h>
27 #include <algorithm>
28 #include <fstream>
29 #include <iostream>
30 #include <unistd.h>
31 #include <sys/mman.h>
32 #include <pthread.h>
33 #include <gtest/gtest.h>
34 
35 #include "hook.h"
36 
37 using namespace testing::ext;
38 using namespace std;
39 
40 extern "C"{
41 }
42 
43 namespace OHOS {
44 namespace {
45 
46 class PthreadGettidNpTest : public testing::Test {
47 public:
48     static void TearDownTestCase(void);
49 };
50 
TearDownTestCase(void)51 void PthreadGettidNpTest::TearDownTestCase(void)
52 {
53 }
54 
thread_fun(void * arg)55 void *thread_fun(void *arg)
56 {
57     return NULL;
58 }
59 
60 /**
61  * @tc.name: PthreadGettidNpTest_001
62  * @tc.desc: pthread_t doesn't exist
63  * @tc.type: FUNC
64  */
65 HWTEST_F(PthreadGettidNpTest, PthreadGettidNpTest_001, TestSize.Level0)
66 {
67     pthread_t t1;
68     pthread_create(&t1, NULL, thread_fun, NULL);
69     pthread_t t2;
70     pthread_create(&t2, NULL, thread_fun, NULL);
71     pthread_t t3;
72 
73     pthread_create(&t3, NULL, thread_fun, NULL);
74     pthread_join(t3, NULL);
75 
76     pthread_t t4;
77     pthread_create(&t4, NULL, thread_fun, NULL);
78 
79     pid_t recv_result = pthread_gettid_np(t3);
80     pthread_join(t1, NULL);
81     pthread_join(t2, NULL);
82     pthread_join(t4, NULL);
83 
84     EXPECT_EQ(recv_result, -1);
85 }
86 
87 }   // namespace
88 }   // namespace OHOS