File indexing completed on 2024-04-28 05:41:06
0001 /* 0002 Copyright (C) 2015 Volker Krause <vkrause@kde.org> 0003 0004 This program is free software; you can redistribute it and/or modify it 0005 under the terms of the GNU Library General Public License as published by 0006 the Free Software Foundation; either version 2 of the License, or (at your 0007 option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, but WITHOUT 0010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 0012 License for more details. 0013 0014 You should have received a copy of the GNU General Public License 0015 along with this program. If not, see <https://www.gnu.org/licenses/>. 0016 */ 0017 0018 #include <elf/elffile.h> 0019 #include <elf/elfnotesection.h> 0020 #include <elf/elfnoteentry.h> 0021 0022 #include <QtTest/qtest.h> 0023 #include <QObject> 0024 0025 #include <elf.h> 0026 0027 class ElfNoteSectionTest : public QObject 0028 { 0029 Q_OBJECT 0030 0031 void checkLinuxABISection(const ElfFile& f) 0032 { 0033 const auto index = f.indexOfSection(".note.ABI-tag"); 0034 QVERIFY(index > 0); 0035 0036 ElfNoteSection *section = f.section<ElfNoteSection>(index); 0037 QVERIFY(section); 0038 0039 QCOMPARE(section->entryCount(), 1); 0040 const auto entry = section->entry(0); 0041 0042 QVERIFY(entry); 0043 QCOMPARE(entry->section(), section); 0044 QCOMPARE(entry->size(), section->size()); 0045 QCOMPARE(entry->type(), (uint64_t)NT_GNU_ABI_TAG); 0046 QCOMPARE(entry->name(), "GNU"); 0047 QVERIFY(entry->isGNUVendorNote()); 0048 QCOMPARE(entry->descriptionSize(), (uint64_t)16); 0049 } 0050 0051 void checkFreeBSDABISection(const ElfFile& f) 0052 { 0053 const auto index = f.indexOfSection(".note.tag"); 0054 QVERIFY(index > 0); 0055 0056 ElfNoteSection *section = f.section<ElfNoteSection>(index); 0057 QVERIFY(section); 0058 0059 QVERIFY(section->entryCount() > 0); 0060 const auto entry = section->entry(0); 0061 0062 QVERIFY(entry); 0063 QCOMPARE(entry->section(), section); 0064 QVERIFY(entry->size() <= section->size()); 0065 QCOMPARE(entry->type(), (uint64_t)NT_GNU_ABI_TAG); 0066 QCOMPARE(entry->name(), "FreeBSD"); 0067 QVERIFY(!entry->isGNUVendorNote()); 0068 QCOMPARE(entry->descriptionSize(), (uint64_t)4); 0069 } 0070 0071 private slots: 0072 void testABISection() 0073 { 0074 ElfFile f(QStringLiteral(BINDIR "single-executable")); 0075 QVERIFY(f.open(QFile::ReadOnly)); 0076 QCOMPARE(f.isValid(), true); 0077 0078 #ifdef Q_OS_FREEBSD 0079 checkFreeBSDABISection(f); 0080 #else 0081 checkLinuxABISection(f); 0082 #endif 0083 } 0084 }; 0085 0086 QTEST_MAIN(ElfNoteSectionTest) 0087 0088 #include "elfnotesectiontest.moc"