• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2 // -*- mode: C++ -*-
3 //
4 // Copyright 2023 Google LLC
5 //
6 // Licensed under the Apache License v2.0 with LLVM Exceptions (the
7 // "License"); you may not use this file except in compliance with the
8 // License.  You may obtain a copy of the License at
9 //
10 //     https://llvm.org/LICENSE.txt
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 //
18 // Author: Aleksei Vetrov
19 
20 #include <string_view>
21 
22 #include <catch2/catch.hpp>
23 #include "elf_loader.h"
24 #include "elf_reader.h"
25 #include "graph.h"
26 
27 namespace Test {
28 
29 using SymbolTable = stg::elf::internal::SymbolTable;
30 using SymbolTableEntry = stg::elf::SymbolTableEntry;
31 
MakeSymbol(std::string_view name)32 SymbolTableEntry MakeSymbol(std::string_view name) {
33   return {
34     .name = name,
35     .value = 0,
36     .size = 0,
37     .symbol_type = SymbolTableEntry::SymbolType::OBJECT,
38     .binding = SymbolTableEntry::Binding::GLOBAL,
39     .visibility = SymbolTableEntry::Visibility::DEFAULT,
40     .section_index = 0,
41     .value_type = SymbolTableEntry::ValueType::RELATIVE_TO_SECTION,
42   };
43 }
44 
45 
46 TEST_CASE("GetKsymtabSymbols") {
47   const SymbolTable all_symbols = {
48     MakeSymbol("foo"),
49     MakeSymbol("__ksymtab_foo"),
50     MakeSymbol("bar"),
51   };
52   const auto ksymtab = stg::elf::internal::GetKsymtabSymbols(all_symbols);
53   REQUIRE(ksymtab.size() == 1);
54   CHECK(*ksymtab.begin() == "foo");
55 }
56 
57 }  // namespace Test
58