Skip to content

Commit

Permalink
Centralize finding objdump binary
Browse files Browse the repository at this point in the history
Skip whole test if it isn't found
  • Loading branch information
milianw committed Oct 21, 2023
1 parent 99cafd6 commit fc96bf0
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions tests/modeltests/tst_disassemblyoutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ private slots:
void initTestCase()
{
qRegisterMetaType<Data::Symbol>();

mObjdumpBinary = QStandardPaths::findExecutable(QStringLiteral("objdump"));
if (mObjdumpBinary.isEmpty())
QSKIP("cannot use disassembly without objdump binary");
}

void testSymbol_data()
Expand Down Expand Up @@ -68,7 +72,7 @@ private slots:
QTextStream disassemblyStream(&actual);

const auto disassemblyOutput =
DisassemblyOutput::disassemble(QStringLiteral("objdump"), QStringLiteral("x86_64"), {}, {}, {}, {}, symbol);
DisassemblyOutput::disassemble(mObjdumpBinary, QStringLiteral("x86_64"), {}, {}, {}, {}, symbol);
for (const auto& disassemblyLine : disassemblyOutput.disassemblyLines) {
disassemblyStream << Qt::hex << disassemblyLine.addr << '\t' << disassemblyLine.disassembly << '\n';
}
Expand Down Expand Up @@ -140,24 +144,18 @@ private slots:

void testCustomDebugPath()
{
const QString objdump = QStandardPaths::findExecutable(QStringLiteral("objdump"));

if (objdump.isEmpty()) {
QSKIP("objdump not found");
}

const Data::Symbol symbol = {QStringLiteral("fib(int)"), 4361, 67, QStringLiteral("libfib.so")};

auto result = DisassemblyOutput::disassemble(objdump, {}, {}, {}, {}, {}, symbol);
auto result = DisassemblyOutput::disassemble(mObjdumpBinary, {}, {}, {}, {}, {}, symbol);
QVERIFY(!result.errorMessage.isEmpty());
QVERIFY(result.errorMessage.contains(QLatin1String("Could not find libfib.so")));

QFETCH(QStringList, searchPath);

result = DisassemblyOutput::disassemble(objdump, {}, QStringList(searchPath), {}, {}, {}, symbol);
result = DisassemblyOutput::disassemble(mObjdumpBinary, {}, QStringList(searchPath), {}, {}, {}, symbol);
QVERIFY(result.errorMessage.isEmpty());

result = DisassemblyOutput::disassemble(objdump, {}, {}, QStringList(searchPath), {}, {}, symbol);
result = DisassemblyOutput::disassemble(mObjdumpBinary, {}, {}, QStringList(searchPath), {}, {}, symbol);
QVERIFY(result.errorMessage.isEmpty());
}

Expand Down Expand Up @@ -204,10 +202,8 @@ private slots:

const auto symbol = Data::Symbol {QStringLiteral("fib(int)"), address, size, QStringLiteral("libfib.so")};

const QString objdump = QStandardPaths::findExecutable(QStringLiteral("objdump"));
QVERIFY(!objdump.isEmpty());
const auto result =
DisassemblyOutput::disassemble(objdump, {}, QStringList {lib.absolutePath()}, {}, {}, {}, symbol);
DisassemblyOutput::disassemble(mObjdumpBinary, {}, QStringList {lib.absolutePath()}, {}, {}, {}, symbol);
QVERIFY(result.errorMessage.isEmpty());

auto isValidVisualisationCharacter = [](QChar character) {
Expand Down Expand Up @@ -275,26 +271,20 @@ private slots:
return {address, size};
}

static bool supportsVisualizeJumps()
bool supportsVisualizeJumps()
{
const QString objdump = QStandardPaths::findExecutable(QStringLiteral("objdump"));
VERIFY_OR_THROW(!objdump.isEmpty());

if (objdump.isEmpty()) {
qWarning() << "objdump not found";
return false;
}

QProcess process;
process.setProcessChannelMode(QProcess::ForwardedErrorChannel);
process.start(objdump, {QStringLiteral("-H")});
process.start(mObjdumpBinary, {QStringLiteral("-H")});
if (!process.waitForFinished(1000)) {
qWarning() << "failed to query objdump output";
return false;
}
const auto help = process.readAllStandardOutput();
return help.contains("--visualize-jumps");
}

QString mObjdumpBinary;
};

QTEST_GUILESS_MAIN(TestDisassemblyOutput)
Expand Down

0 comments on commit fc96bf0

Please sign in to comment.