diff options
6 files changed, 89 insertions, 3 deletions
diff --git a/tests/auto/blackbox/testdata-baremetal/do-not-generate-linker-map/do-not-generate-linker-map.qbs b/tests/auto/blackbox/testdata-baremetal/do-not-generate-linker-map/do-not-generate-linker-map.qbs new file mode 100644 index 000000000..f0095a4a6 --- /dev/null +++ b/tests/auto/blackbox/testdata-baremetal/do-not-generate-linker-map/do-not-generate-linker-map.qbs @@ -0,0 +1,16 @@ +import "../BareMetalApplication.qbs" as BareMetalApplication + +BareMetalApplication { + condition: { + if (qbs.toolchainType === "sdcc") { + console.info("unsupported toolset: %%" + + qbs.toolchainType + "%%, %%" + qbs.architecture + "%%"); + return false; + } + console.info("current toolset: %%" + + qbs.toolchainType + "%%, %%" + qbs.architecture + "%%"); + return true; + } + cpp.generateLinkerMapFile: false + files: ["main.c"] +} diff --git a/tests/auto/blackbox/testdata-baremetal/do-not-generate-linker-map/main.c b/tests/auto/blackbox/testdata-baremetal/do-not-generate-linker-map/main.c new file mode 100644 index 000000000..58fe69254 --- /dev/null +++ b/tests/auto/blackbox/testdata-baremetal/do-not-generate-linker-map/main.c @@ -0,0 +1,4 @@ +int main(void) +{ + return 0; +} diff --git a/tests/auto/blackbox/testdata-baremetal/generate-linker-map/generate-linker-map.qbs b/tests/auto/blackbox/testdata-baremetal/generate-linker-map/generate-linker-map.qbs new file mode 100644 index 000000000..854391abb --- /dev/null +++ b/tests/auto/blackbox/testdata-baremetal/generate-linker-map/generate-linker-map.qbs @@ -0,0 +1,16 @@ +import "../BareMetalApplication.qbs" as BareMetalApplication + +BareMetalApplication { + condition: { + if (qbs.toolchainType === "sdcc") { + console.info("unsupported toolset: %%" + + qbs.toolchainType + "%%, %%" + qbs.architecture + "%%"); + return false; + } + console.info("current toolset: %%" + + qbs.toolchainType + "%%, %%" + qbs.architecture + "%%"); + return true; + } + cpp.generateLinkerMapFile: true + files: ["main.c"] +} diff --git a/tests/auto/blackbox/testdata-baremetal/generate-linker-map/main.c b/tests/auto/blackbox/testdata-baremetal/generate-linker-map/main.c new file mode 100644 index 000000000..58fe69254 --- /dev/null +++ b/tests/auto/blackbox/testdata-baremetal/generate-linker-map/main.c @@ -0,0 +1,4 @@ +int main(void) +{ + return 0; +} diff --git a/tests/auto/blackbox/tst_blackboxbaremetal.cpp b/tests/auto/blackbox/tst_blackboxbaremetal.cpp index 9dc8bbab3..50be987a2 100644 --- a/tests/auto/blackbox/tst_blackboxbaremetal.cpp +++ b/tests/auto/blackbox/tst_blackboxbaremetal.cpp @@ -34,8 +34,8 @@ #include <QtCore/qregularexpression.h> -static bool extractUnsupportedToolset(const QByteArray &output, - QByteArray &toolchain, QByteArray &architecture) +static bool extractToolset(const QByteArray &output, + QByteArray &toolchain, QByteArray &architecture) { const QRegularExpression re("%%(\\w+)%%, %%(\\w+)%%"); QRegularExpressionMatchIterator it = re.globalMatch(output); @@ -51,11 +51,22 @@ static QByteArray unsupportedToolsetMessage(const QByteArray &output) { QByteArray toolchain; QByteArray architecture; - extractUnsupportedToolset(output, toolchain, architecture); + extractToolset(output, toolchain, architecture); return "Unsupported toolchain '" + toolchain + "' for architecture '" + architecture + "'"; } +static QString linkerMapFileExtension(const QByteArray &toolchain, const QByteArray &architecture) +{ + if (toolchain == "keil") { + if (architecture == "mcs51" || architecture == "mcs251") + return QStringLiteral(".m51"); + if (architecture == "c166") + return QStringLiteral(".m66"); + } + return QStringLiteral(".map"); +} + TestBlackboxBareMetal::TestBlackboxBareMetal() : TestBlackboxBase (SRCDIR "/testdata-baremetal", "blackbox-baremetal") { @@ -172,4 +183,36 @@ void TestBlackboxBareMetal::compilerListingFiles() QCOMPARE(regularFileExists(fooListing), generateListing); } +void TestBlackboxBareMetal::linkerMapFile_data() +{ + QTest::addColumn<QString>("testPath"); + QTest::addColumn<bool>("generateMap"); + QTest::newRow("do-not-generate-linker-map") << "/do-not-generate-linker-map" << false; + QTest::newRow("generate-linker-map") << "/generate-linker-map" << true; +} + +void TestBlackboxBareMetal::linkerMapFile() +{ + QFETCH(QString, testPath); + QFETCH(bool, generateMap); + QDir::setCurrent(testDataDir + testPath); + QCOMPARE(runQbs(QbsRunParameters("resolve", QStringList("-n"))), 0); + if (m_qbsStdout.contains("unsupported toolset:")) + QSKIP(unsupportedToolsetMessage(m_qbsStdout)); + if (!m_qbsStdout.contains("current toolset:")) + QFAIL("No current toolset pattern exists"); + + QByteArray toolchain; + QByteArray architecture; + if (!extractToolset(m_qbsStdout, toolchain, architecture)) + QFAIL("Unable to extract current toolset"); + + QCOMPARE(runQbs(), 0); + const QString productName = testPath.mid(1); + const QString productBuildDir = relativeProductBuildDir(productName); + const auto extension = linkerMapFileExtension(toolchain, architecture); + const QString linkerMap = productBuildDir + "/" + productName + extension; + QCOMPARE(regularFileExists(linkerMap), generateMap); +} + QTEST_MAIN(TestBlackboxBareMetal) diff --git a/tests/auto/blackbox/tst_blackboxbaremetal.h b/tests/auto/blackbox/tst_blackboxbaremetal.h index 2838e9474..3695cb1c3 100644 --- a/tests/auto/blackbox/tst_blackboxbaremetal.h +++ b/tests/auto/blackbox/tst_blackboxbaremetal.h @@ -60,6 +60,9 @@ private slots: void compilerListingFiles_data(); void compilerListingFiles(); + void linkerMapFile_data(); + void linkerMapFile(); + private: }; |