2022-02-11 13:51:42 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2022 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2022-02-15 11:18:56 +01:00
|
|
|
#include "unittest.h"
|
2022-03-01 22:35:33 +01:00
|
|
|
#include "armgcc_nxp_1050_json.h"
|
|
|
|
|
#include "armgcc_nxp_1064_json.h"
|
|
|
|
|
#include "armgcc_stm32f769i_freertos_json.h"
|
|
|
|
|
#include "armgcc_stm32h750b_metal_json.h"
|
|
|
|
|
#include "iar_stm32f469i_metal_json.h"
|
2022-02-16 16:48:28 +01:00
|
|
|
#include "mcukitmanager.h"
|
2022-03-01 22:35:33 +01:00
|
|
|
#include "mcusupportconstants.h"
|
|
|
|
|
#include "mcusupportsdk.h"
|
|
|
|
|
#include "mcutargetdescription.h"
|
2022-02-11 13:51:42 +01:00
|
|
|
#include "utils/filepath.h"
|
2022-03-01 22:35:33 +01:00
|
|
|
|
2022-02-11 13:51:42 +01:00
|
|
|
#include <cmakeprojectmanager/cmakeconfigitem.h>
|
|
|
|
|
#include <cmakeprojectmanager/cmakekitinformation.h>
|
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
|
#include <QJsonArray>
|
|
|
|
|
#include <QJsonDocument>
|
2022-03-01 22:35:33 +01:00
|
|
|
#include <qtestcase.h>
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <ciso646>
|
2022-02-11 13:51:42 +01:00
|
|
|
|
|
|
|
|
namespace McuSupport::Internal::Test {
|
|
|
|
|
|
2022-03-01 22:35:33 +01:00
|
|
|
static const QString nxp1050FreeRtosEnvVar{"IMXRT1050_FREERTOS_DIR"};
|
|
|
|
|
static const QString nxp1064FreeRtosEnvVar{"IMXRT1064_FREERTOS_DIR"};
|
|
|
|
|
static const QString nxp1170FreeRtosEnvVar{"EVK_MIMXRT1170_FREERTOS_PATH"};
|
|
|
|
|
static const QString stm32f7FreeRtosEnvVar{"STM32F7_FREERTOS_DIR"};
|
|
|
|
|
static const QString stm32f7{"STM32F7"};
|
|
|
|
|
static const QString nxp1170{"EVK_MIMXRT1170"};
|
|
|
|
|
static const QString nxp1050{"IMXRT1050"};
|
|
|
|
|
static const QString nxp1064{"IMXRT1064"};
|
|
|
|
|
|
|
|
|
|
static const QStringList jsonFiles{armgcc_nxp_1050_json, armgcc_nxp_1064_json};
|
|
|
|
|
|
2022-02-11 13:51:42 +01:00
|
|
|
using CMakeProjectManager::CMakeConfigItem;
|
|
|
|
|
using CMakeProjectManager::CMakeConfigurationKitAspect;
|
|
|
|
|
using ProjectExplorer::EnvironmentKitAspect;
|
|
|
|
|
using ProjectExplorer::KitManager;
|
|
|
|
|
using testing::Return;
|
|
|
|
|
using testing::ReturnRef;
|
|
|
|
|
using Utils::FilePath;
|
|
|
|
|
|
|
|
|
|
void McuSupportTest::initTestCase()
|
|
|
|
|
{
|
|
|
|
|
EXPECT_CALL(freeRtosPackage, environmentVariableName()).WillRepeatedly(ReturnRef(freeRtosEnvVar));
|
2022-02-21 15:24:46 +01:00
|
|
|
EXPECT_CALL(freeRtosPackage, isValidStatus()).WillRepeatedly(Return(true));
|
2022-02-11 13:51:42 +01:00
|
|
|
EXPECT_CALL(freeRtosPackage, path())
|
|
|
|
|
.WillRepeatedly(Return(FilePath::fromString(defaultfreeRtosPath)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void McuSupportTest::test_parseBasicInfoFromJson()
|
|
|
|
|
{
|
2022-03-01 22:35:33 +01:00
|
|
|
const auto description = Sdk::parseDescriptionJson(armgcc_nxp_1064_json);
|
2022-02-11 13:51:42 +01:00
|
|
|
|
2022-02-21 11:12:06 +01:00
|
|
|
QVERIFY(!description.freeRTOS.envVar.isEmpty());
|
2022-02-11 13:51:42 +01:00
|
|
|
QVERIFY(description.freeRTOS.boardSdkSubDir.isEmpty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void McuSupportTest::test_addNewKit()
|
|
|
|
|
{
|
|
|
|
|
auto &kitManager{*KitManager::instance()};
|
|
|
|
|
|
|
|
|
|
QSignalSpy kitAddedSpy(&kitManager, &KitManager::kitAdded);
|
|
|
|
|
|
2022-02-14 18:01:04 +01:00
|
|
|
auto *newKit{McuKitManager::newKit(&mcuTarget, &freeRtosPackage)};
|
2022-02-11 13:51:42 +01:00
|
|
|
QVERIFY(newKit != nullptr);
|
|
|
|
|
|
|
|
|
|
QCOMPARE(kitAddedSpy.count(), 1);
|
|
|
|
|
QList<QVariant> arguments = kitAddedSpy.takeFirst();
|
|
|
|
|
auto *createdKit = qvariant_cast<Kit *>(arguments.at(0));
|
|
|
|
|
QVERIFY(createdKit != nullptr);
|
|
|
|
|
QCOMPARE(createdKit, newKit);
|
|
|
|
|
|
|
|
|
|
auto cmakeAspect{CMakeConfigurationKitAspect{}};
|
|
|
|
|
QVERIFY(createdKit->hasValue(cmakeAspect.id()));
|
|
|
|
|
QVERIFY(createdKit->value(cmakeAspect.id(), freeRtosCmakeVar).isValid());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void McuSupportTest::test_addFreeRtosCmakeVarToKit()
|
|
|
|
|
{
|
2022-02-28 16:35:54 +01:00
|
|
|
McuKitManager::updateKitEnvironment(&kit, &mcuTarget);
|
2022-02-11 13:51:42 +01:00
|
|
|
|
|
|
|
|
QVERIFY(kit.hasValue(EnvironmentKitAspect::id()));
|
|
|
|
|
QVERIFY(kit.isValid());
|
2022-02-21 11:12:06 +01:00
|
|
|
QVERIFY(!kit.allKeys().empty());
|
2022-02-11 13:51:42 +01:00
|
|
|
|
|
|
|
|
const auto &cmakeConfig{CMakeConfigurationKitAspect::configuration(&kit)};
|
|
|
|
|
QCOMPARE(cmakeConfig.size(), 1);
|
|
|
|
|
|
2022-03-01 22:35:33 +01:00
|
|
|
CMakeConfigItem
|
|
|
|
|
expectedCmakeVar{freeRtosCmakeVar.toLocal8Bit(),
|
|
|
|
|
FilePath::fromString(defaultfreeRtosPath).toUserOutput().toLocal8Bit()};
|
2022-02-11 13:51:42 +01:00
|
|
|
QVERIFY(cmakeConfig.contains(expectedCmakeVar));
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-01 22:35:33 +01:00
|
|
|
void McuSupportTest::test_createPackagesWithCorrespondingSettings_data()
|
|
|
|
|
{
|
|
|
|
|
QTest::addColumn<QString>("json");
|
|
|
|
|
QTest::addColumn<QSet<QString>>("expectedSettings");
|
|
|
|
|
|
|
|
|
|
QSet<QString> commonSettings{{"CypressAutoFlashUtil"},
|
|
|
|
|
{"GHSArmToolchain"},
|
|
|
|
|
{"GHSToolchain"},
|
|
|
|
|
{"GNUArmEmbeddedToolchain"},
|
|
|
|
|
{"IARToolchain"},
|
|
|
|
|
{"MCUXpressoIDE"},
|
|
|
|
|
{"RenesasFlashProgrammer"},
|
|
|
|
|
{"Stm32CubeProgrammer"}};
|
|
|
|
|
|
|
|
|
|
QTest::newRow("nxp1064") << armgcc_nxp_1064_json
|
|
|
|
|
<< QSet<QString>{{"EVK_MIMXRT1064_SDK_PATH"},
|
|
|
|
|
{QString{Constants::SETTINGS_KEY_FREERTOS_PREFIX}
|
|
|
|
|
.append("IMXRT1064")}}
|
|
|
|
|
.unite(commonSettings);
|
|
|
|
|
QTest::newRow("nxp1050") << armgcc_nxp_1050_json
|
|
|
|
|
<< QSet<QString>{{"EVKB_IMXRT1050_SDK_PATH"},
|
|
|
|
|
{QString{Constants::SETTINGS_KEY_FREERTOS_PREFIX}
|
|
|
|
|
.append("IMXRT1050")}}
|
|
|
|
|
.unite(commonSettings);
|
|
|
|
|
|
|
|
|
|
QTest::newRow("stm32h750b") << armgcc_stm32h750b_metal_json
|
|
|
|
|
<< QSet<QString>{{"STM32Cube_FW_H7_SDK_PATH"}}.unite(commonSettings);
|
|
|
|
|
|
|
|
|
|
QTest::newRow("stm32f769i") << armgcc_stm32f769i_freertos_json
|
|
|
|
|
<< QSet<QString>{{"STM32Cube_FW_F7_SDK_PATH"}}.unite(commonSettings);
|
|
|
|
|
|
|
|
|
|
QTest::newRow("stm32f469i") << iar_stm32f469i_metal_json
|
|
|
|
|
<< QSet<QString>{{"STM32Cube_FW_F4_SDK_PATH"}}.unite(commonSettings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void McuSupportTest::test_createPackagesWithCorrespondingSettings()
|
|
|
|
|
{
|
|
|
|
|
QFETCH(QString, json);
|
|
|
|
|
const auto description = Sdk::parseDescriptionJson(json.toLocal8Bit());
|
|
|
|
|
QVector<McuAbstractPackage *> packages;
|
|
|
|
|
const auto targets = Sdk::targetsFromDescriptions({description}, &packages);
|
|
|
|
|
|
|
|
|
|
QSet<QString> settings;
|
|
|
|
|
std::transform(packages.begin(),
|
|
|
|
|
packages.end(),
|
|
|
|
|
std::inserter(settings, settings.end()),
|
|
|
|
|
[](const auto &package) { return package->settingsKey(); });
|
|
|
|
|
|
|
|
|
|
QFETCH(QSet<QString>, expectedSettings);
|
|
|
|
|
QVERIFY(settings.contains(expectedSettings));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TODO(piotr.mucko): Enable when mcutargetfactory is delivered.
|
|
|
|
|
void McuSupportTest::test_createFreeRtosPackageWithCorrectSetting()
|
|
|
|
|
{
|
|
|
|
|
// Sdk::targetsAndPackages(jsonFile, &mcuSdkRepo);
|
|
|
|
|
//
|
|
|
|
|
// QVector<Package *> mcuPackages;
|
|
|
|
|
// auto mcuTargets = Sdk::targetsFromDescriptions({description}, &mcuPackages);
|
|
|
|
|
// QVERIFY(mcuPackages contains freertos package)
|
|
|
|
|
// QVERIFY(freertos package is not empty & has proper value)
|
|
|
|
|
|
|
|
|
|
// McuSupportOptions mcuSuportOptions{};
|
|
|
|
|
// mcuSuportOptions.createAutomaticKits();
|
|
|
|
|
|
|
|
|
|
QFETCH(QString, freeRtosEnvVar);
|
|
|
|
|
QFETCH(QString, expectedSettingsKey);
|
|
|
|
|
|
|
|
|
|
auto *package{Sdk::createFreeRTOSSourcesPackage(freeRtosEnvVar, FilePath{}, QString{})};
|
|
|
|
|
QVERIFY(package != nullptr);
|
|
|
|
|
|
|
|
|
|
QCOMPARE(package->settingsKey(), expectedSettingsKey);
|
|
|
|
|
|
|
|
|
|
// QVERIFY(freertos package is not empty & has proper value)
|
|
|
|
|
// static McuPackage *createFreeRTOSSourcesPackage(const QString &envVar,
|
|
|
|
|
// const FilePath &boardSdkDir,
|
|
|
|
|
// const QString &freeRTOSBoardSdkSubDir)
|
|
|
|
|
// createFreeRtosPackage
|
|
|
|
|
// verify that package's setting is Package_FreeRTOSSourcePackage_IMXRT1064.
|
|
|
|
|
//TODO(me): write settings
|
|
|
|
|
// auto *freeRtosPackage
|
|
|
|
|
// = new McuPackage;
|
|
|
|
|
// freeRtosPackage->writeToSettings();
|
|
|
|
|
//TODO(me): verify that setting is the same as in 2.0.0
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-11 13:51:42 +01:00
|
|
|
} // namespace McuSupport::Internal::Test
|