|
| 1 | +//===-- ExpressionTest.cpp ------------------------------------------------===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#include "gmock/gmock.h" |
| 10 | +#include "gtest/gtest.h" |
| 11 | + |
| 12 | +#include "TestingSupport/TestUtilities.h" |
| 13 | +#include "lldb/Expression/Expression.h" |
| 14 | +#include "llvm/Testing/Support/Error.h" |
| 15 | + |
| 16 | +using namespace lldb_private; |
| 17 | + |
| 18 | +struct LabelTestCase { |
| 19 | + llvm::StringRef encoded; |
| 20 | + FunctionCallLabel label; |
| 21 | + llvm::SmallVector<llvm::StringRef> error_pattern; |
| 22 | +}; |
| 23 | + |
| 24 | +static LabelTestCase g_label_test_cases[] = { |
| 25 | + // Failure modes |
| 26 | + {"0x0:0x0:_Z3foov", |
| 27 | + {}, |
| 28 | + {"failed to split function call label '0x0:0x0:_Z3foov'", |
| 29 | + "expected function call label prefix not found."}}, |
| 30 | + {"$__lldb_func0x0:0x0:_Z3foov", |
| 31 | + {}, |
| 32 | + {"failed to split function call label '$__lldb_func0x0:0x0:_Z3foov'", |
| 33 | + "expected ':' as the first character after prefix."}}, |
| 34 | + {"$__lldb_func:", |
| 35 | + {}, |
| 36 | + {"failed to split function call label '$__lldb_func:'", |
| 37 | + "no ':' separator found."}}, |
| 38 | + {"$__lldb_func:0x0:0x0", |
| 39 | + {}, |
| 40 | + {"failed to split function call label '$__lldb_func:0x0:0x0'", |
| 41 | + "only single ':' separator found."}}, |
| 42 | + {"$__lldb_func:abc:0x0:_Z3foov", |
| 43 | + {}, |
| 44 | + {"failed to parse module ID from 'abc'."}}, |
| 45 | + {"$__lldb_func:-1:0x0:_Z3foov", |
| 46 | + {}, |
| 47 | + {"failed to parse module ID from '-1'."}}, |
| 48 | + {"$__lldb_func:0x0:abc:_Z3foov", |
| 49 | + {}, |
| 50 | + {"failed to parse symbol ID from 'abc'."}}, |
| 51 | + {"$__lldb_func:0x5:-1:_Z3foov", |
| 52 | + {}, |
| 53 | + {"failed to parse symbol ID from '-1'."}}, |
| 54 | + {"$__lldb_func:0x0:0x0:_Z3foov", |
| 55 | + { |
| 56 | + /*.module_id=*/0x0, |
| 57 | + /*.symbol_id=*/0x0, |
| 58 | + /*.lookup_name=*/"_Z3foov", |
| 59 | + }, |
| 60 | + {}}, |
| 61 | + {"$__lldb_func:0x0:0x0:abc:def:::a", |
| 62 | + { |
| 63 | + /*.module_id=*/0x0, |
| 64 | + /*.symbol_id=*/0x0, |
| 65 | + /*.lookup_name=*/"abc:def:::a", |
| 66 | + }, |
| 67 | + {}}, |
| 68 | + {"$__lldb_func:0xd2:0xf0:$__lldb_func", |
| 69 | + { |
| 70 | + /*.module_id=*/0xd2, |
| 71 | + /*.symbol_id=*/0xf0, |
| 72 | + /*.lookup_name=*/"$__lldb_func", |
| 73 | + }, |
| 74 | + {}}, |
| 75 | +}; |
| 76 | + |
| 77 | +struct ExpressionTestFixture : public testing::TestWithParam<LabelTestCase> {}; |
| 78 | + |
| 79 | +TEST_P(ExpressionTestFixture, FunctionCallLabel) { |
| 80 | + const auto &[encoded, label, errors] = GetParam(); |
| 81 | + |
| 82 | + auto decoded_or_err = FunctionCallLabel::fromString(encoded); |
| 83 | + if (!errors.empty()) { |
| 84 | + EXPECT_THAT_EXPECTED( |
| 85 | + decoded_or_err, |
| 86 | + llvm::FailedWithMessageArray(testing::ElementsAreArray(errors))); |
| 87 | + return; |
| 88 | + } |
| 89 | + |
| 90 | + EXPECT_THAT_EXPECTED(decoded_or_err, llvm::Succeeded()); |
| 91 | + |
| 92 | + auto label_str = label.toString(); |
| 93 | + EXPECT_EQ(decoded_or_err->toString(), encoded); |
| 94 | + EXPECT_EQ(label_str, encoded); |
| 95 | + |
| 96 | + EXPECT_EQ(decoded_or_err->module_id, label.module_id); |
| 97 | + EXPECT_EQ(decoded_or_err->symbol_id, label.symbol_id); |
| 98 | + EXPECT_EQ(decoded_or_err->lookup_name, label.lookup_name); |
| 99 | + |
| 100 | + auto roundtrip_or_err = FunctionCallLabel::fromString(label_str); |
| 101 | + EXPECT_THAT_EXPECTED(roundtrip_or_err, llvm::Succeeded()); |
| 102 | + |
| 103 | + EXPECT_EQ(roundtrip_or_err->module_id, label.module_id); |
| 104 | + EXPECT_EQ(roundtrip_or_err->symbol_id, label.symbol_id); |
| 105 | + EXPECT_EQ(roundtrip_or_err->lookup_name, label.lookup_name); |
| 106 | +} |
| 107 | + |
| 108 | +INSTANTIATE_TEST_SUITE_P(FunctionCallLabelTest, ExpressionTestFixture, |
| 109 | + testing::ValuesIn(g_label_test_cases)); |
0 commit comments