1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
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 <gtest/gtest.h>
17 #include "ffrt_inner.h"
18 #include "util.h"
19 #include "dfx/log/ffrt_log_api.h"
20 #include "func_pool.h"
21 #include "internal_inc/osal.h"
22 #include "../common.h"
23 
24 using namespace std;
25 using namespace ffrt;
26 using namespace testing;
27 #ifdef HWTEST_TESTING_EXT_ENABLE
28 using namespace testing::ext;
29 #endif
30 
31 class MemTest : public testing::Test {
32 protected:
SetUpTestCase()33     static void SetUpTestCase()
34     {
35     }
36 
TearDownTestCase()37     static void TearDownTestCase()
38     {
39     }
40 
SetUp()41     virtual void SetUp()
42     {
43     }
44 
TearDown()45     virtual void TearDown()
46     {
47     }
48 };
49 
50 HWTEST_F(MemTest, mem_leakage_test_try_times_min, TestSize.Level1)
51 {
52     uint32_t count = 10;
53     uint32_t try_times_max = 5;
54     uint32_t try_times = 0;
55     uint32_t pid = GetPid();
56     uint32_t start_mem;
57     uint32_t end_mem;
58     uint32_t mem_inc = 512; // KB
59 
60     while (try_times < try_times_max) {
61         try_times++;
62         start_mem = get_proc_memory(pid);
63         NestedWhile(count);
64         end_mem = get_proc_memory(pid);
65         if (end_mem < start_mem + mem_inc) {
66             break;
67         }
68     }
69 
70     printf("mem_leakage_test_try_times_min try_times:%u start_mem:%uKB end_mem:%uKB\n", try_times, start_mem, end_mem);
71     EXPECT_LT(try_times, try_times_max);
72 }