From cca067a34d56cc829e06c772adbc587c05d9bf25 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 22 Apr 2020 15:38:42 +0200 Subject: [PATCH 1/5] [libcalamares] Add a bogus test showing flag names --- src/libcalamares/CMakeLists.txt | 18 +++++-- src/libcalamares/partition/KPMTests.cpp | 65 +++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 src/libcalamares/partition/KPMTests.cpp diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index 91dce96cd..904511ce7 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -226,6 +226,14 @@ calamares_add_test( partition/Tests.cpp ) +if( KPMcore_FOUND ) + calamares_add_test( + libcalamarespartitionkpmtest + SOURCES + partition/KPMTests.cpp + ) +endif() + calamares_add_test( libcalamareslocaletest SOURCES @@ -244,8 +252,8 @@ calamares_add_test( modulesystem/Tests.cpp ) -if( BUILD_TESTING ) - add_executable( test_geoip geoip/test_geoip.cpp ${geoip_src} ) - target_link_libraries( test_geoip calamares Qt5::Network yamlcpp ) - calamares_automoc( test_geoip ) -endif() +# This is not an actual test, it's a test / demo application +# for experimenting with GeoIP. +add_executable( test_geoip geoip/test_geoip.cpp ${geoip_src} ) +target_link_libraries( test_geoip calamares Qt5::Network yamlcpp ) +calamares_automoc( test_geoip ) diff --git a/src/libcalamares/partition/KPMTests.cpp b/src/libcalamares/partition/KPMTests.cpp new file mode 100644 index 000000000..425393d9d --- /dev/null +++ b/src/libcalamares/partition/KPMTests.cpp @@ -0,0 +1,65 @@ +/* === This file is part of Calamares - === + * + * Copyright 2019, Adriaan de Groot + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "utils/Logger.h" + +#include + +#include + +class KPMTests +{ + Q_OBJECT +public: + KPMTests(); + ~KPMTests() overr; +private Q_SLOTS: + void initTestCase(); + + void testFlagNames(); +}; + +KPMTests::KPMTests() {} + +KPMTests::~KPMTests() {} + +void +KPMTests::initTestCase() +{ + Logger::setupLogLevel( Logger::LOGDEBUG ); +} + +void +KPMTests::testFlagNames() +{ + int f = 1; + QStringList names; + QString s; + while ( !( s = PartitionTable::flagName( static_cast< PartitionTable::Flag >( f ) ) ).isEmpty() ) + { + cDebug() << f << s; + names.append( s ); + } +} + + +QTEST_GUILESS_MAIN( KPMTests ) + +#include "moc-warnings.h" + +#include "KPMTests.moc" From 43c5e1fc9695d32010f08d5e97a50a912d3e375b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 23 Apr 2020 11:45:12 +0200 Subject: [PATCH 2/5] [libcalamares] Fix build of tests - Typed in on FreeBSD, where it doesn't get built --- src/libcalamares/CMakeLists.txt | 2 ++ src/libcalamares/partition/KPMTests.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index 904511ce7..dd6f01fb1 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -231,6 +231,8 @@ if( KPMcore_FOUND ) libcalamarespartitionkpmtest SOURCES partition/KPMTests.cpp + LIBRARIES + ${OPTIONAL_PRIVATE_LIBRARIES} ) endif() diff --git a/src/libcalamares/partition/KPMTests.cpp b/src/libcalamares/partition/KPMTests.cpp index 425393d9d..edf7edf61 100644 --- a/src/libcalamares/partition/KPMTests.cpp +++ b/src/libcalamares/partition/KPMTests.cpp @@ -22,12 +22,12 @@ #include -class KPMTests +class KPMTests : public QObject { Q_OBJECT public: KPMTests(); - ~KPMTests() overr; + ~KPMTests() override; private Q_SLOTS: void initTestCase(); @@ -54,6 +54,8 @@ KPMTests::testFlagNames() { cDebug() << f << s; names.append( s ); + + f <<= 1; } } From 3f4e167acacdcccde1a1b385c7f6a4d68f615bc6 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 23 Apr 2020 12:16:30 +0200 Subject: [PATCH 3/5] [libcalamares] Expand kpm test with API 3/4 differences - fix build - KPMCore 3 distinguishes esp and boot - KPMCore 4 does not --- src/libcalamares/partition/KPMTests.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libcalamares/partition/KPMTests.cpp b/src/libcalamares/partition/KPMTests.cpp index edf7edf61..c84d70c99 100644 --- a/src/libcalamares/partition/KPMTests.cpp +++ b/src/libcalamares/partition/KPMTests.cpp @@ -57,11 +57,21 @@ KPMTests::testFlagNames() f <<= 1; } + +#ifdef WITH_KPMCORE4API + // KPMCore 4 unifies the flags and handles them internally + QVERIFY( names.contains( QStringLiteral( "boot" ) ) ); + QVERIFY( !names.contains( QStringLiteral( "esp" ) ) ); +#else + // KPMCore 3 has separate flags + QVERIFY( names.contains( QStringLiteral( "boot" ) ) ); + QVERIFY( names.contains( QStringLiteral( "esp" ) ) ); +#endif } QTEST_GUILESS_MAIN( KPMTests ) -#include "moc-warnings.h" +#include "utils/moc-warnings.h" #include "KPMTests.moc" From 79e8c447b93ae4d97b948bd3f2c8bb7e90189846 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 23 Apr 2020 13:46:09 +0200 Subject: [PATCH 4/5] [libcalamares] Test some specific KPM partition flags --- src/libcalamares/partition/KPMTests.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libcalamares/partition/KPMTests.cpp b/src/libcalamares/partition/KPMTests.cpp index c84d70c99..7468d3938 100644 --- a/src/libcalamares/partition/KPMTests.cpp +++ b/src/libcalamares/partition/KPMTests.cpp @@ -58,12 +58,17 @@ KPMTests::testFlagNames() f <<= 1; } + QCOMPARE( PartitionTable::flagName( static_cast< PartitionTable::Flag >( 1 ) ), QStringLiteral( "boot" ) ); + #ifdef WITH_KPMCORE4API // KPMCore 4 unifies the flags and handles them internally + QCOMPARE( PartitionTable::flagName( PartitionTable::Flag::Boot ), QStringLiteral( "boot" ) ); QVERIFY( names.contains( QStringLiteral( "boot" ) ) ); QVERIFY( !names.contains( QStringLiteral( "esp" ) ) ); #else // KPMCore 3 has separate flags + QCOMPARE( PartitionTable::flagName( PartitionTable::FlagBoot ), QStringLiteral( "boot" ) ); + QCOMPARE( PartitionTable::flagName( PartitionTable::FlagEsp ), QStringLiteral( "esp" ) ); QVERIFY( names.contains( QStringLiteral( "boot" ) ) ); QVERIFY( names.contains( QStringLiteral( "esp" ) ) ); #endif From 479b467bb64ff67d9d114427d4ee4cfee0b9a0c8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 23 Apr 2020 13:53:30 +0200 Subject: [PATCH 5/5] [partition] Substitute in the right flag name - This uses "esp" in KPMCore 3 and "boot" in KPMCore 4 --- src/modules/partition/gui/PartitionViewStep.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index ed35fafa4..f568d766a 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -417,6 +417,12 @@ PartitionViewStep::onLeave() { QString espMountPoint = Calamares::JobQueue::instance()->globalStorage()->value( "efiSystemPartition" ).toString(); +#ifdef WITH_KPMCORE4API + auto espFlag = PartitionTable::Flag::Boot; +#else + auto espFlag = PartitionTable::FlagEsp; +#endif + QString espFlagName = PartitionTable::flagName( espFlag ); Partition* esp = m_core->findPartitionByMountPoint( espMountPoint ); QString message; @@ -428,12 +434,12 @@ PartitionViewStep::onLeave() "

" "To configure an EFI system partition, go back and " "select or create a FAT32 filesystem with the " - "esp flag enabled and mount point " + "%3 flag enabled and mount point " "%2.

" "You can continue without setting up an EFI system " "partition but your system may fail to start." ) .arg( *Calamares::Branding::ShortProductName ) - .arg( espMountPoint ); + .arg( espMountPoint, espFlagName ); } else if ( esp && !PartUtils::isEfiBootable( esp ) ) { @@ -441,14 +447,14 @@ PartitionViewStep::onLeave() description = tr( "An EFI system partition is necessary to start %1." "

" "A partition was configured with mount point " - "%2 but its esp " + "%2 but its %3 " "flag is not set.
" "To set the flag, go back and edit the partition." "

" "You can continue without setting the flag but your " "system may fail to start." ) .arg( *Calamares::Branding::ShortProductName ) - .arg( espMountPoint ); + .arg( espMountPoint, espFlagName ); } if ( !message.isEmpty() )