diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2020-08-06 17:31:17 +0300 |
---|---|---|
committer | Denis Shienkov <denis.shienkov@gmail.com> | 2020-08-07 15:50:11 +0000 |
commit | 95e1b0a2bb301b75315100e3cb252a25e6e0ce05 (patch) | |
tree | b197ac58e2bb360d869c1228eda962cb4aa116f4 | |
parent | 3c6ae1f54008ffba6a1e1d47f929d706df744729 (diff) | |
download | qbs-95e1b0a2bb301b75315100e3cb252a25e6e0ce05.tar.gz |
baremetal: Add new 'generate-linker-map-file' test
This test checks the cpp.generateLinkerMapFile property,
which enables or disables generation for the linker map
file.
Take into account, that currently not all toolchains completely
supports or implements this feature, and this test skips such
toolchains.
Change-Id: I5ba90116ab0481bb65ff866cf02f8a1963cf00a9
Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
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: }; |