1 /*
2 * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "utilities_test.h"
17
18 #include <chrono>
19 #include <thread>
20 #include "utilities.h"
21
22 using namespace testing::ext;
23 using namespace std;
24 using namespace OHOS::HiviewDFX;
25 namespace OHOS {
26 namespace Developtools {
27 namespace NativeDaemon {
28 class UtilitiesTest : public testing::Test {
29 public:
30 static void SetUpTestCase(void);
31 static void TearDownTestCase(void);
32 void SetUp();
33 void TearDown();
34 void TestThread();
35 void StartThreads(const size_t count);
36 void ExitThreads();
37 bool exitThreads_ = true;
38 std::vector<pid_t> tids_;
39 std::vector<std::thread> threads_;
40 const int sleepTime_ = {500};
41 };
42
SetUpTestCase()43 void UtilitiesTest::SetUpTestCase() {}
44
TearDownTestCase()45 void UtilitiesTest::TearDownTestCase() {}
46
SetUp()47 void UtilitiesTest::SetUp() {}
48
TearDown()49 void UtilitiesTest::TearDown() {}
50
TestThread()51 void UtilitiesTest::TestThread()
52 {
53 printf("threads %ld create\n", static_cast<long>(gettid()));
54 int ret = fflush(nullptr);
55 if (ret == EOF) {
56 printf("fflush() error\n");
57 }
58
59 tids_.emplace_back(gettid());
60 while (!exitThreads_) {
61 std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime_));
62 }
63 printf("threads %ld exited\n", static_cast<long>(gettid()));
64 ret = fflush(nullptr);
65 if (ret == EOF) {
66 printf("fflush() error\n");
67 }
68 }
69
StartThreads(const size_t count)70 void UtilitiesTest::StartThreads(const size_t count)
71 {
72 printf("create %zu threads\n", count);
73 int ret = fflush(nullptr);
74 if (ret == EOF) {
75 printf("fflush() error\n");
76 }
77
78 exitThreads_ = false;
79 size_t created = 0;
80 while (created < count) {
81 threads_.emplace_back(std::thread(&UtilitiesTest::TestThread, this));
82 created++;
83 }
84 while (tids_.size() < count) {
85 std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime_));
86 }
87 printf("all threads created\n");
88 ret = fflush(nullptr);
89 if (ret == EOF) {
90 printf("fflush() error\n");
91 }
92 }
93
ExitThreads()94 void UtilitiesTest::ExitThreads()
95 {
96 printf("wait all threads exit\n");
97 exitThreads_ = true;
98 for (std::thread &t : this->threads_) {
99 t.join();
100 }
101 tids_.clear();
102 printf("all threads exited\n");
103 }
104
105 /**
106 * @tc.name: StringReplace
107 * @tc.desc:
108 * @tc.type: FUNC
109 */
110 HWTEST_F(UtilitiesTest, StringReplace, TestSize.Level1)
111 {
112 const std::string testString = "1234567890";
113 EXPECT_EQ(StringReplace(testString, "1", ""), "234567890");
114 EXPECT_EQ(StringReplace(testString, "2", ""), "134567890");
115 EXPECT_EQ(StringReplace(testString, "0", ""), "123456789");
116 EXPECT_EQ(StringReplace(testString, "1", "0"), "0234567890");
117 EXPECT_EQ(StringReplace(testString, "0", "1"), "1234567891");
118 EXPECT_EQ(StringReplace(testString, "123", "1"), "14567890");
119 EXPECT_EQ(StringReplace(testString, "890", "1"), "12345671");
120 EXPECT_EQ(StringReplace(testString, "456", "1"), "12317890");
121 EXPECT_EQ(StringReplace(testString, "123", "321"), "3214567890");
122 EXPECT_EQ(StringReplace(testString, "890", "098"), "1234567098");
123 }
124
125 /**
126 * @tc.name: StringSplit
127 * @tc.desc:
128 * @tc.type: FUNC
129 */
130 HWTEST_F(UtilitiesTest, StringSplit, TestSize.Level1)
131 {
132 std::string testString = "1,23,456,7890,";
133 size_t testSize = testString.size();
134 EXPECT_EQ(StringSplit(testString, "1").size(), 1u);
135 EXPECT_EQ(StringSplit(testString, "2").size(), 2u);
136 EXPECT_EQ(StringSplit(testString, ",").size(), 4u);
137 EXPECT_EQ(StringSplit(testString, "456").size(), 2u);
138 EXPECT_EQ(StringSplit(testString, "000").size(), 1u);
139 EXPECT_EQ(StringSplit(testString, "").size(), 1u);
140 // dont change the input string
141 EXPECT_EQ(testString.size(), testSize);
142
143 EXPECT_EQ(StringSplit(testString = "").size(), 0u);
144 EXPECT_EQ(StringSplit(testString = "1,2,3").size(), 3u);
145 EXPECT_EQ(StringSplit(testString = "1,2,3,,,").size(), 3u);
146 }
147
148 /**
149 * @tc.name: SubStringCount
150 * @tc.desc:
151 * @tc.type: FUNC
152 */
153 HWTEST_F(UtilitiesTest, SubStringCount, TestSize.Level1)
154 {
155 std::string testString = "1,22,333,4444,";
156 EXPECT_EQ(SubStringCount(testString, ""), testString.size());
157 EXPECT_EQ(SubStringCount(testString, "1"), 1u);
158 EXPECT_EQ(SubStringCount(testString, "2"), 2u);
159 EXPECT_EQ(SubStringCount(testString, "3"), 3u);
160 EXPECT_EQ(SubStringCount(testString, "4"), 4u);
161
162 EXPECT_EQ(SubStringCount(testString, "22"), 1u);
163 EXPECT_EQ(SubStringCount(testString, "33"), 1u);
164 EXPECT_EQ(SubStringCount(testString, "333"), 1u);
165 EXPECT_EQ(SubStringCount(testString, "4444"), 1u);
166 EXPECT_EQ(SubStringCount(testString, "444"), 1u);
167 EXPECT_EQ(SubStringCount(testString, "44"), 2u);
168 }
169
170 /**
171 * @tc.name: StringEndsWith
172 * @tc.desc:
173 * @tc.type: FUNC
174 */
175 HWTEST_F(UtilitiesTest, StringEndsWith, TestSize.Level1)
176 {
177 std::string testString = "1,22,333,4444,";
178 EXPECT_EQ(StringEndsWith(testString, ""), true);
179 EXPECT_EQ(StringEndsWith(testString, "1"), false);
180 EXPECT_EQ(StringEndsWith(testString, ","), true);
181
182 EXPECT_EQ(StringEndsWith("", ""), true);
183 EXPECT_EQ(StringEndsWith("", "1"), false);
184 EXPECT_EQ(StringEndsWith("", ","), false);
185 }
186
187 /**
188 * @tc.name: StringStartsWith
189 * @tc.desc:
190 * @tc.type: FUNC
191 */
192 HWTEST_F(UtilitiesTest, StringStartsWith, TestSize.Level1)
193 {
194 std::string testString = "1,22,333,4444,";
195 EXPECT_EQ(StringStartsWith(testString, ""), true);
196 EXPECT_EQ(StringStartsWith(testString, "1"), true);
197 EXPECT_EQ(StringStartsWith(testString, ","), false);
198
199 EXPECT_EQ(StringStartsWith("", ""), true);
200 EXPECT_EQ(StringStartsWith("", "1"), false);
201 EXPECT_EQ(StringStartsWith("", ","), false);
202 }
203
204 /**
205 * @tc.name: VectorToString
206 * @tc.desc:
207 * @tc.type: FUNC
208 */
209 HWTEST_F(UtilitiesTest, VectorToString, TestSize.Level1)
210 {
211 EXPECT_EQ(VectorToString<std::string>(
212 {}), "<empty>");
213 EXPECT_EQ(VectorToString<std::string>(
214 {"a", "b", "c"}), "a,b,c");
215 EXPECT_EQ(VectorToString<std::string>(
216 {"a"}), "a");
217 EXPECT_EQ(VectorToString<std::vector<std::string>>(
218 { {} }), "[<empty>]");
219 EXPECT_EQ(VectorToString<std::vector<std::string>>(
220 { { "a", "b", "c" }, }), "[a,b,c]");
221 EXPECT_EQ(VectorToString<std::vector<std::string>>(
222 {
223 {"a", "b", "c"},
224 {"a", "b", "c"},
225 {"a", "b", "c"},
226 }),
227 "[a,b,c],[a,b,c],[a,b,c]");
228
229 EXPECT_EQ(VectorToString<int>(
230 {}), "<empty>");
231 EXPECT_EQ(VectorToString<int>(
232 {1}), "1");
233 EXPECT_EQ(VectorToString<int>(
234 {1, 2, 3}), "1,2,3");
235
236 EXPECT_EQ(VectorToString<float>(
237 {}), "<empty>");
238 EXPECT_EQ(VectorToString<float>(
239 {1.0, 2.0, 3.0}), "1.000000,2.000000,3.000000");
240 }
241
242 /**
243 * @tc.name: BufferToHexString
244 * @tc.desc:
245 * @tc.type: FUNC
246 */
247 HWTEST_F(UtilitiesTest, BufferToHexString, TestSize.Level1)
248 {
249 const unsigned char buf[] = "12345678";
250
251 EXPECT_STREQ(BufferToHexString(buf, 0).c_str(), "0:");
252 EXPECT_STREQ(BufferToHexString(buf, 1).c_str(), "1: 0x31");
253 EXPECT_STREQ(BufferToHexString(buf, 4).c_str(), "4: 0x31 0x32 0x33 0x34");
254 EXPECT_STREQ(BufferToHexString(buf, 5).c_str(), "5: 0x31 0x32 0x33 0x34 0x35");
255 EXPECT_STREQ(BufferToHexString(buf, 8).c_str(), "8: 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38");
256
257 const std::vector<unsigned char> vbuf(buf, buf + sizeof(buf) - 1u);
258
259 EXPECT_STREQ(BufferToHexString(vbuf).c_str(), "8: 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38");
260
261 const unsigned char buf2[] = "1234567812345678";
262 EXPECT_STREQ(BufferToHexString(buf2, 0).c_str(), "0:");
263 EXPECT_STREQ(BufferToHexString(buf2, 1).c_str(), "1: 0x31");
264 EXPECT_STREQ(BufferToHexString(buf2, 4).c_str(), "4: 0x31 0x32 0x33 0x34");
265 EXPECT_STREQ(BufferToHexString(buf2, 5).c_str(), "5: 0x31 0x32 0x33 0x34 0x35");
266 EXPECT_STREQ(BufferToHexString(buf2, 8).c_str(), "8: 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38");
267 EXPECT_STREQ(BufferToHexString(buf2, 9).c_str(),
268 "9: 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x31");
269 EXPECT_STREQ(
270 BufferToHexString(buf2, 16).c_str(),
271 "16: 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38");
272
273 const std::vector<unsigned char> vbuf2(buf2, buf2 + sizeof(buf2) - 1u);
274 EXPECT_STREQ(
275 BufferToHexString(vbuf2).c_str(),
276 "16: 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38");
277 }
278
279 /**
280 * @tc.name: HexDump
281 * @tc.desc:
282 * @tc.type: FUNC
283 */
284 HWTEST_F(UtilitiesTest, HexDump, TestSize.Level1)
285 {
286 const unsigned char buf[] = "12345678";
287 ScopeDebugLevel tempLogLevel(LEVEL_MUCH, true);
288
289 StdoutRecord stdoutRecord;
290 stdoutRecord.Start();
291 HexDump(buf, 0);
292 HexDump(buf, 1);
293 HexDump(buf, 4);
294 HexDump(buf, 5);
295 HexDump(buf, 8);
296 stdoutRecord.Stop();
297 }
298
299 /**
300 * @tc.name: StringTrim
301 * @tc.desc:
302 * @tc.type: FUNC
303 */
304 HWTEST_F(UtilitiesTest, StringTrim, TestSize.Level1)
305 {
306 std::string test;
307 EXPECT_STREQ(StringTrim(test = " a ").c_str(), "a");
308 EXPECT_STREQ(StringTrim(test = " a").c_str(), "a");
309 EXPECT_STREQ(StringTrim(test = "a ").c_str(), "a");
310 EXPECT_STREQ(StringTrim(test = " a1a ").c_str(), "a1a");
311 EXPECT_STREQ(StringTrim(test = " a1a").c_str(), "a1a");
312 EXPECT_STREQ(StringTrim(test = "a1a ").c_str(), "a1a");
313 EXPECT_STREQ(StringTrim(test = " a1a ").c_str(), "a1a");
314 EXPECT_STREQ(StringTrim(test = " a1a").c_str(), "a1a");
315 EXPECT_STREQ(StringTrim(test = "a1a ").c_str(), "a1a");
316 }
317
318 /**
319 * @tc.name: RecordStdout
320 * @tc.desc:
321 * @tc.type: FUNC
322 */
323 HWTEST_F(UtilitiesTest, RecordStdout, TestSize.Level1)
324 {
325 StdoutRecord stdoutRecord;
326
327 ASSERT_EQ(stdoutRecord.Start(), true);
328 printf("line1: abc\n");
329 printf("line2: def\n");
330 printf("line3: ghi\n");
331 printf("\n");
332 std::string out = stdoutRecord.Stop();
333
334 printf("stdoutRecord:\n%s", out.c_str());
335 EXPECT_EQ(out.empty(), false);
336 EXPECT_NE(out.find("line1:"), std::string::npos);
337 EXPECT_NE(out.find("line2:"), std::string::npos);
338 EXPECT_NE(out.find("line3:"), std::string::npos);
339 EXPECT_EQ(out.find("line4:"), std::string::npos);
340 }
341
342 /**
343 * @tc.name: IsDigits
344 * @tc.desc:
345 * @tc.type: FUNC
346 */
347 HWTEST_F(UtilitiesTest, IsDigits, TestSize.Level1)
348 {
349 EXPECT_EQ(IsDigits(""), false);
350 EXPECT_EQ(IsDigits("1"), true);
351 EXPECT_EQ(IsDigits("12"), true);
352 EXPECT_EQ(IsDigits("1a"), false);
353 EXPECT_EQ(IsDigits("a1"), false);
354 EXPECT_EQ(IsDigits("1a2"), false);
355 EXPECT_EQ(IsDigits("a1b"), false);
356 EXPECT_EQ(IsDigits("_1"), false);
357 EXPECT_EQ(IsDigits("1_"), false);
358 }
359
360 /**
361 * @tc.name: IsHexxDigits
362 * @tc.desc:
363 * @tc.type: FUNC
364 */
365 HWTEST_F(UtilitiesTest, IsHexxDigits, TestSize.Level1)
366 {
367 EXPECT_EQ(IsHexDigits(""), false);
368 EXPECT_EQ(IsHexDigits("1"), true);
369 EXPECT_EQ(IsHexDigits("12"), true);
370 EXPECT_EQ(IsHexDigits("1a"), true);
371 EXPECT_EQ(IsHexDigits("f1"), true);
372 EXPECT_EQ(IsHexDigits("1f2"), true);
373 EXPECT_EQ(IsHexDigits("a1f"), true);
374 EXPECT_EQ(IsHexDigits("g1"), false);
375 EXPECT_EQ(IsHexDigits("1g"), false);
376 EXPECT_EQ(IsHexDigits("_1"), false);
377 EXPECT_EQ(IsHexDigits("1_"), false);
378 }
379
380 /**
381 * @tc.name: IsSameCommand
382 * @tc.desc:
383 * @tc.type: FUNC
384 */
385 HWTEST_F(UtilitiesTest, IsSameCommand, TestSize.Level1)
386 {
387 EXPECT_EQ(IsSameCommand("", ""), false);
388 EXPECT_EQ(IsSameCommand("a", ""), false);
389 EXPECT_EQ(IsSameCommand("", "b"), false);
390 EXPECT_EQ(IsSameCommand("1", "2"), false);
391 EXPECT_EQ(IsSameCommand("2", "1"), false);
392 EXPECT_EQ(IsSameCommand("1", "1"), true);
393 EXPECT_EQ(IsSameCommand("a", "a"), true);
394 EXPECT_EQ(IsSameCommand("a:1", "a:2"), false);
395 }
396
397 /**
398 * @tc.name: CompressFile
399 * @tc.desc:
400 * @tc.type: FUNC
401 */
402 HWTEST_F(UtilitiesTest, CompressFile, TestSize.Level1)
403 {
404 std::string srcPath = "./resource/testdata/elf_test_stripped_broken";
405 std::string destPath = "./test.gz";
406 EXPECT_EQ(CompressFile(srcPath, destPath), true);
407 srcPath = "";
408 EXPECT_EQ(CompressFile(srcPath, destPath), false);
409 srcPath = "./resource/testdata/elf_test_stripped_broken";
410 destPath = "";
411 EXPECT_EQ(CompressFile(srcPath, destPath), false);
412 }
413
414 /**
415 * @tc.name: UncompressFile
416 * @tc.desc:
417 * @tc.type: FUNC
418 */
419 HWTEST_F(UtilitiesTest, UncompressFile, TestSize.Level1)
420 {
421 std::string gzipPath = "./test.gz";
422 std::string dataPath = "./test";
423 EXPECT_EQ(UncompressFile(gzipPath, dataPath), true);
424 gzipPath = "./test.gz";
425 dataPath = "";
426 EXPECT_EQ(UncompressFile(gzipPath, dataPath), false);
427 gzipPath = "";
428 dataPath = "./resource/testdata/elf_test_stripped_broken";
429 EXPECT_EQ(UncompressFile(gzipPath, dataPath), false);
430 }
431
432 /**
433 * @tc.name: StringPrintf
434 * @tc.desc:
435 * @tc.type: FUNC
436 */
437 HWTEST_F(UtilitiesTest, StringPrintf, TestSize.Level1)
438 {
439 EXPECT_STREQ(StringPrintf("").c_str(), "");
440 EXPECT_STREQ(StringPrintf("123").c_str(), "123");
441 EXPECT_STREQ(StringPrintf("%d%s%c", 1, "2", 'c').c_str(), "12c");
442 EXPECT_STREQ(StringPrintf("%d%s%c\t\n", 1, "2", 'c').c_str(), "12c\t\n");
443
444 char format[PATH_MAX + 1];
445 std::fill(format, format + PATH_MAX, ' ');
446 format[PATH_MAX] = 0;
447 EXPECT_STRNE(StringPrintf(format).c_str(), format);
448 format[PATH_MAX - 1] = 0;
449 EXPECT_STREQ(StringPrintf(format).c_str(), format);
450 EXPECT_STREQ(StringPrintf(nullptr).c_str(), "");
451 }
452
453 /**
454 * @tc.name: GetEntriesInDir
455 * @tc.desc:
456 * @tc.type: FUNC
457 */
458 HWTEST_F(UtilitiesTest, GetEntriesInDir, TestSize.Level1)
459 {
460 std::vector<std::string> dirFileInfo;
461 dirFileInfo = GetEntriesInDir("./");
462 EXPECT_GE(dirFileInfo.size(), 0u);
463 }
464
465 /**
466 * @tc.name: GetSubDirs
467 * @tc.desc:
468 * @tc.type: FUNC
469 */
470 HWTEST_F(UtilitiesTest, GetSubDirs, TestSize.Level1)
471 {
472 std::vector<std::string> subDirFileInfo;
473 subDirFileInfo = GetSubDirs("../");
474 EXPECT_GE(subDirFileInfo.size(), 0u);
475 }
476
477 /**
478 * @tc.name: IsDir
479 * @tc.desc:
480 * @tc.type: FUNC
481 */
482 HWTEST_F(UtilitiesTest, IsDir, TestSize.Level1)
483 {
484 bool ret = IsDir("../");
485 EXPECT_EQ(ret, true);
486 }
487
488 /**
489 * @tc.name: IsPath
490 * @tc.desc:
491 * @tc.type: FUNC
492 */
493 HWTEST_F(UtilitiesTest, IsPath, TestSize.Level1)
494 {
495 bool ret = IsPath("./");
496 EXPECT_EQ(ret, true);
497 }
498
499 /**
500 * @tc.name: PlatformPathConvert
501 * @tc.desc:
502 * @tc.type: FUNC
503 */
504 HWTEST_F(UtilitiesTest, PlatformPathConvert, TestSize.Level1)
505 {
506 EXPECT_GE(PlatformPathConvert("./").length(), 0u);
507 }
508
509 /**
510 * @tc.name: ToHex
511 * @tc.desc:
512 * @tc.type: FUNC
513 */
514 HWTEST_F(UtilitiesTest, ToHex, TestSize.Level1)
515 {
516 unsigned char hVal = 'G';
517 EXPECT_STREQ(ToHex(hVal, 1, true).c_str(), "0x47");
518 }
519
520 /**
521 * @tc.name: ToHex
522 * @tc.desc:
523 * @tc.type: FUNC
524 */
525 HWTEST_F(UtilitiesTest, CopyFromBufferAndMove, TestSize.Level1)
526 {
527 unsigned char *buffer = new unsigned char[4];
528 buffer[0] = '1';
529 buffer[1] = '2';
530 buffer[2] = '3';
531 buffer[3] = '4';
532 int *dest = new int;
533 const unsigned char *srcStr = buffer;
534 EXPECT_EQ(CopyFromBufferAndMove(srcStr, dest, 4), 4u);
535 }
536
537 /**
538 * @tc.name: ReadIntFromProcFile
539 * @tc.desc:
540 * @tc.type: FUNC
541 */
542 HWTEST_F(UtilitiesTest, ReadIntFromProcFile, TestSize.Level1)
543 {
544 std::string strPath = "/proc/sys/kernel/perf_cpu_time_max_percent";
545 int strLen = 0;
546 EXPECT_EQ(ReadIntFromProcFile(strPath, strLen), true);
547 }
548
549 /**
550 * @tc.name: WriteIntToProcFile
551 * @tc.desc:
552 * @tc.type: FUNC
553 */
554 HWTEST_F(UtilitiesTest, WriteIntToProcFile, TestSize.Level1)
555 {
556 std::string strPath = "./hiperf_log.txt";
557 int strVal = 0;
558 EXPECT_EQ(WriteIntToProcFile(strPath, strVal), true);
559 }
560
561 /**
562 * @tc.name: ReadFileToString
563 * @tc.desc:
564 * @tc.type: FUNC
565 */
566 HWTEST_F(UtilitiesTest, ReadFileToString, TestSize.Level1)
567 {
568 std::string strPath = "./hiperf_log.txt";
569 EXPECT_NE(ReadFileToString(strPath).length(), 0u);
570 }
571
572 /**
573 * @tc.name: WriteStringToFile
574 * @tc.desc:
575 * @tc.type: FUNC
576 */
577 HWTEST_F(UtilitiesTest, WriteStringToFile, TestSize.Level1)
578 {
579 std::string strPath = "./hiperf_log.txt";
580 std::string content = "0";
581 EXPECT_EQ(WriteStringToFile(strPath, content), true);
582 }
583
584 /**
585 * @tc.name: Percentage
586 * @tc.desc:
587 * @tc.type: FUNC
588 */
589 HWTEST_F(UtilitiesTest, Percentage, TestSize.Level1)
590 {
591 EXPECT_EQ(Percentage(99, 100), 99);
592 }
593
594 /**
595 * @tc.name: IsRoot
596 * @tc.desc:
597 * @tc.type: FUNC
598 */
599 HWTEST_F(UtilitiesTest, IsRoot, TestSize.Level1)
600 {
601 bool isRoot = true;
602 #if is_linux || is_ohos
603 isRoot = (getuid() == 0);
604 #endif
605 EXPECT_EQ(IsRoot(), isRoot);
606 }
607
608 /**
609 * @tc.name: PowerOfTwo
610 * @tc.desc:
611 * @tc.type: FUNC
612 */
613 HWTEST_F(UtilitiesTest, PowerOfTwo, TestSize.Level1)
614 {
615 EXPECT_EQ(PowerOfTwo(1), true);
616 }
617
618 /**
619 * @tc.name: GetSubthreadIDs
620 * @tc.desc:
621 * @tc.type: FUNC
622 */
623 HWTEST_F(UtilitiesTest, GetSubthreadIDs, TestSize.Level1)
624 {
625 StartThreads(1);
626 std::vector<pid_t> tids = GetSubthreadIDs(getpid());
627 EXPECT_EQ(tids.size(), tids_.size());
628 if (!HasFailure()) {
629 for (pid_t tid : tids) {
630 EXPECT_NE(find(tids_.begin(), tids_.end(), tid), tids_.end());
631 }
632 }
633 ExitThreads();
634 }
635 } // namespace NativeDaemon
636 } // namespace Developtools
637 } // namespace OHOS