1 /*
2 * Copyright (c) 2025 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 "ecmascript/platform/backtrace.h"
17 #include "ecmascript/tests/test_helper.h"
18
19 using namespace panda::ecmascript;
20
21 namespace panda::test {
22 class BacktraceTest : public ::testing::Test {
23 public:
SetUpTestCase()24 static void SetUpTestCase()
25 {
26 GTEST_LOG_(INFO) << "SetUpTestCase";
27 }
28
TearDownTestCase()29 static void TearDownTestCase()
30 {
31 GTEST_LOG_(INFO) << "TearDownCase";
32 }
33
SetUp()34 void SetUp() override
35 {
36 TestHelper::CreateEcmaVMWithScope(instance, thread, scope);
37 instance->SetEnableForceGC(false);
38 }
39
TearDown()40 void TearDown() override
41 {
42 TestHelper::DestroyEcmaVMWithScope(instance, scope);
43 }
44
45 EcmaVM *instance{nullptr};
46 EcmaHandleScope *scope{nullptr};
47 JSThread *thread{nullptr};
48 };
49
HWTEST_F_L0(BacktraceTest,BacktraceTest1)50 HWTEST_F_L0(BacktraceTest, BacktraceTest1)
51 {
52 std::ostringstream stack;
53 bool enableCache = true;
54 Backtrace(stack, enableCache);
55 EXPECT_TRUE(!stack.str().empty());
56 }
57
HWTEST_F_L0(BacktraceTest,BacktraceTest2)58 HWTEST_F_L0(BacktraceTest, BacktraceTest2)
59 {
60 std::ostringstream stack;
61 Backtrace(stack);
62 EXPECT_TRUE(!stack.str().empty());
63 }
64 }