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