Merge branch 'partition-logging'

This commit is contained in:
Adriaan de Groot 2018-10-05 09:41:53 -04:00
commit 1b570477de
15 changed files with 195 additions and 65 deletions

View File

@ -237,6 +237,11 @@ set_package_properties(
find_package(ECM ${ECM_VERSION} NO_MODULE) find_package(ECM ${ECM_VERSION} NO_MODULE)
if( ECM_FOUND ) if( ECM_FOUND )
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_MODULE_PATH}) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_MODULE_PATH})
if ( BUILD_TESTING )
# ECM implies that we can build the tests, too
find_package( Qt5 COMPONENTS Test REQUIRED )
include( ECMAddTests )
endif()
endif() endif()
find_package( KF5 COMPONENTS CoreAddons Crash ) find_package( KF5 COMPONENTS CoreAddons Crash )

View File

@ -105,6 +105,19 @@ install( TARGETS calamares
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
) )
if ( ECM_FOUND AND BUILD_TESTING )
ecm_add_test(
Tests.cpp
TEST_NAME
libcalamarestest
LINK_LIBRARIES
calamares
Qt5::Core
Qt5::Test
)
set_target_properties( libcalamarestest PROPERTIES AUTOMOC TRUE )
endif()
# Make symlink lib/calamares/libcalamares.so to lib/libcalamares.so.VERSION so # Make symlink lib/calamares/libcalamares.so to lib/libcalamares.so.VERSION so
# lib/calamares can be used as module path for the Python interpreter. # lib/calamares can be used as module path for the Python interpreter.
install( CODE " install( CODE "

View File

@ -0,0 +1,59 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2018, Adriaan de Groot <groot@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "Tests.h"
#include "utils/Logger.h"
#include <QtTest/QtTest>
QTEST_GUILESS_MAIN( LibCalamaresTests )
LibCalamaresTests::LibCalamaresTests()
{
}
LibCalamaresTests::~LibCalamaresTests()
{
}
void
LibCalamaresTests::initTestCase()
{
}
void
LibCalamaresTests::testDebugLevels()
{
Logger::setupLogLevel( Logger::LOG_DISABLE );
QCOMPARE( Logger::logLevel(), Logger::LOG_DISABLE );
for ( unsigned int level = 0; level <= Logger::LOGVERBOSE ; ++level )
{
Logger::setupLogLevel( level );
QCOMPARE( Logger::logLevel(), level );
QVERIFY( Logger::logLevelEnabled( level ) );
for ( unsigned int xlevel = 0; xlevel <= Logger::LOGVERBOSE; ++xlevel )
{
QCOMPARE( Logger::logLevelEnabled( xlevel ), xlevel <= level );
}
}
}

36
src/libcalamares/Tests.h Normal file
View File

@ -0,0 +1,36 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2018, Adriaan de Groot <groot@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef TESTS_H
#define TESTS_H
#include <QObject>
class LibCalamaresTests : public QObject
{
Q_OBJECT
public:
LibCalamaresTests();
~LibCalamaresTests() override;
private Q_SLOTS:
void initTestCase();
void testDebugLevels();
};
#endif

View File

@ -55,6 +55,18 @@ setupLogLevel(unsigned int level)
s_threshold = level + 1; // Comparison is < in log() function s_threshold = level + 1; // Comparison is < in log() function
} }
bool
logLevelEnabled(unsigned int level)
{
return level < s_threshold;
}
unsigned int
logLevel()
{
return s_threshold > 0 ? s_threshold - 1 : 0;
}
static void static void
log( const char* msg, unsigned int debugLevel, bool toDisk = true ) log( const char* msg, unsigned int debugLevel, bool toDisk = true )
{ {

View File

@ -89,6 +89,12 @@ namespace Logger
*/ */
DLLEXPORT void setupLogLevel( unsigned int level ); DLLEXPORT void setupLogLevel( unsigned int level );
/** @brief Return the configured log-level. */
DLLEXPORT unsigned int logLevel();
/** @brief Would the given @p level really be logged? */
DLLEXPORT bool logLevelEnabled( unsigned int level );
/** /**
* @brief Row-oriented formatted logging. * @brief Row-oriented formatted logging.
* *

View File

@ -8,10 +8,7 @@ calamares_add_plugin( contextualprocess
SHARED_LIB SHARED_LIB
) )
if( ECM_FOUND ) if( ECM_FOUND AND BUILD_TESTING )
find_package( Qt5 COMPONENTS Test REQUIRED )
include( ECMAddTests )
ecm_add_test( ecm_add_test(
Tests.cpp Tests.cpp
ContextualProcessJob.cpp # Builds it a second time ContextualProcessJob.cpp # Builds it a second time

View File

@ -20,10 +20,7 @@ if ( KPMcore_FOUND )
SHARED_LIB SHARED_LIB
) )
if( ECM_FOUND ) if( ECM_FOUND AND BUILD_TESTING )
find_package( Qt5 COMPONENTS Test REQUIRED )
include( ECMAddTests )
ecm_add_test( ecm_add_test(
Tests.cpp Tests.cpp
TEST_NAME TEST_NAME

View File

@ -1,9 +1,3 @@
find_package(ECM ${ECM_VERSION} NO_MODULE)
if( ECM_FOUND AND BUILD_TESTING )
include( ECMAddTests )
find_package( Qt5 COMPONENTS Core Test REQUIRED )
endif()
# When debugging the timezone widget, add this debugging definition # When debugging the timezone widget, add this debugging definition
# to have a debugging-friendly timezone widget, debug logging, # to have a debugging-friendly timezone widget, debug logging,
# and no intrusive timezone-setting while clicking around. # and no intrusive timezone-setting while clicking around.

View File

@ -509,17 +509,8 @@ PartitionCoreModule::jobs() const
lst << info->jobs; lst << info->jobs;
devices << info->device.data(); devices << info->device.data();
} }
cDebug() << "Creating FillGlobalStorageJob with bootLoader path" << m_bootLoaderInstallPath;
lst << Calamares::job_ptr( new FillGlobalStorageJob( devices, m_bootLoaderInstallPath ) ); lst << Calamares::job_ptr( new FillGlobalStorageJob( devices, m_bootLoaderInstallPath ) );
QStringList jobsDebug;
foreach ( auto job, lst )
jobsDebug.append( job->prettyName() );
cDebug() << "PartitionCodeModule has been asked for jobs. About to return:"
<< jobsDebug.join( "\n" );
return lst; return lst;
} }

View File

@ -20,6 +20,8 @@
#include "jobs/CreatePartitionTableJob.h" #include "jobs/CreatePartitionTableJob.h"
#include "core/PartitionIterator.h"
#include "utils/Logger.h" #include "utils/Logger.h"
// KPMcore // KPMcore
@ -65,6 +67,14 @@ CreatePartitionTableJob::prettyStatusMessage() const
} }
static inline QDebug&
operator <<( QDebug& s, PartitionIterator& it )
{
s << ( ( *it ) ? ( *it )->deviceNode() : QString( "<null device>" ) );
return s;
}
Calamares::JobResult Calamares::JobResult
CreatePartitionTableJob::exec() CreatePartitionTableJob::exec()
{ {
@ -73,21 +83,28 @@ CreatePartitionTableJob::exec()
PartitionTable* table = m_device->partitionTable(); PartitionTable* table = m_device->partitionTable();
cDebug() << "Creating new partition table of type" << table->typeName() cDebug() << "Creating new partition table of type" << table->typeName()
<< ", uncommitted yet:\n" << table; << ", uncommitted yet:";
QProcess lsblk; if ( Logger::logLevelEnabled( Logger::LOGDEBUG ) )
lsblk.setProgram( "lsblk" ); {
lsblk.setProcessChannelMode( QProcess::MergedChannels ); for ( auto it = PartitionIterator::begin( table );
lsblk.start(); it != PartitionIterator::end( table ); ++it )
lsblk.waitForFinished(); cDebug() << *it;
cDebug() << "lsblk:\n" << lsblk.readAllStandardOutput();
QProcess mount; QProcess lsblk;
mount.setProgram( "mount" ); lsblk.setProgram( "lsblk" );
mount.setProcessChannelMode( QProcess::MergedChannels ); lsblk.setProcessChannelMode( QProcess::MergedChannels );
mount.start(); lsblk.start();
mount.waitForFinished(); lsblk.waitForFinished();
cDebug() << "mount:\n" << mount.readAllStandardOutput(); cDebug() << "lsblk:\n" << lsblk.readAllStandardOutput();
QProcess mount;
mount.setProgram( "mount" );
mount.setProcessChannelMode( QProcess::MergedChannels );
mount.start();
mount.waitForFinished();
cDebug() << "mount:\n" << mount.readAllStandardOutput();
}
CreatePartitionTableOperation op(*m_device, table); CreatePartitionTableOperation op(*m_device, table);
op.setStatus(Operation::StatusRunning); op.setStatus(Operation::StatusRunning);

View File

@ -56,9 +56,12 @@ findPartitionUuids( QList < Device* > devices )
QString path = p->partitionPath(); QString path = p->partitionPath();
QString uuid = p->fileSystem().readUUID( p->partitionPath() ); QString uuid = p->fileSystem().readUUID( p->partitionPath() );
hash.insert( path, uuid ); hash.insert( path, uuid );
cDebug() << ".. added path=" << path << "UUID=" << uuid;
} }
} }
cDebug() << hash;
if ( hash.isEmpty() )
cDebug() << ".. no UUIDs found.";
return hash; return hash;
} }
@ -90,10 +93,16 @@ mapForPartition( Partition* partition, const QString& uuid )
dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS() ) dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS() )
map[ "fs" ] = dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS()->name(); map[ "fs" ] = dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS()->name();
map[ "uuid" ] = uuid; map[ "uuid" ] = uuid;
cDebug() << partition->partitionPath()
<< "mtpoint:" << PartitionInfo::mountPoint( partition ) // Debugging for inside the loop in createPartitionList(),
<< "fs:" << map[ "fs" ] << '(' << map[ "fsName" ] << ')' // so indent a bit
<< uuid; Logger::CLog deb = cDebug();
using TR = Logger::DebugRow<const char *const, const QString&>;
deb << " .. mapping for" << partition->partitionPath() << partition->deviceNode()
<< TR( "mtpoint:", PartitionInfo::mountPoint( partition ) )
<< TR( "fs:", map[ "fs" ].toString() )
<< TR( "fsname", map[ "fsName" ].toString() )
<< TR( "uuid", uuid );
if ( partition->roles().has( PartitionRole::Luks ) ) if ( partition->roles().has( PartitionRole::Luks ) )
{ {
@ -104,7 +113,7 @@ mapForPartition( Partition* partition, const QString& uuid )
map[ "luksMapperName" ] = luksFs->mapperName().split( "/" ).last(); map[ "luksMapperName" ] = luksFs->mapperName().split( "/" ).last();
map[ "luksUuid" ] = getLuksUuid( partition->partitionPath() ); map[ "luksUuid" ] = getLuksUuid( partition->partitionPath() );
map[ "luksPassphrase" ] = luksFs->passphrase(); map[ "luksPassphrase" ] = luksFs->passphrase();
cDebug() << "luksMapperName:" << map[ "luksMapperName" ]; deb << TR( "luksMapperName:", map[ "luksMapperName" ].toString() );
} }
} }
@ -215,9 +224,11 @@ FillGlobalStorageJob::createPartitionList() const
cDebug() << "Writing to GlobalStorage[\"partitions\"]"; cDebug() << "Writing to GlobalStorage[\"partitions\"]";
for ( auto device : m_devices ) for ( auto device : m_devices )
{ {
cDebug() << ".. partitions on" << device->deviceNode();
for ( auto it = PartitionIterator::begin( device ); for ( auto it = PartitionIterator::begin( device );
it != PartitionIterator::end( device ); ++it ) it != PartitionIterator::end( device ); ++it )
{ {
// Debug-logging is done when creating the map
lst << mapForPartition( *it, hash.value( ( *it )->partitionPath() ) ); lst << mapForPartition( *it, hash.value( ( *it )->partitionPath() ) );
} }
} }

View File

@ -1,6 +1,4 @@
find_package( Qt5 COMPONENTS Gui Test REQUIRED ) find_package( Qt5 COMPONENTS Gui REQUIRED )
include( ECMAddTests )
set( PartitionModule_SOURCE_DIR .. ) set( PartitionModule_SOURCE_DIR .. )
@ -23,13 +21,15 @@ include_directories(
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
) )
ecm_add_test( ${partitionjobtests_SRCS} if( ECM_FOUND AND BUILD_TESTING )
TEST_NAME partitionjobtests ecm_add_test( ${partitionjobtests_SRCS}
LINK_LIBRARIES TEST_NAME partitionjobtests
${CALAMARES_LIBRARIES} LINK_LIBRARIES
kpmcore ${CALAMARES_LIBRARIES}
Qt5::Core kpmcore
Qt5::Test Qt5::Core
) Qt5::Test
)
set_target_properties( partitionjobtests PROPERTIES AUTOMOC TRUE ) set_target_properties( partitionjobtests PROPERTIES AUTOMOC TRUE )
endif()

View File

@ -8,10 +8,7 @@ calamares_add_plugin( shellprocess
SHARED_LIB SHARED_LIB
) )
if( ECM_FOUND ) if( ECM_FOUND AND BUILD_TESTING )
find_package( Qt5 COMPONENTS Test REQUIRED )
include( ECMAddTests )
ecm_add_test( ecm_add_test(
Tests.cpp Tests.cpp
TEST_NAME TEST_NAME

View File

@ -1,9 +1,4 @@
find_package(ECM ${ECM_VERSION} NO_MODULE) find_package( Qt5 COMPONENTS Core REQUIRED )
if( ECM_FOUND )
include( ECMAddTests )
endif()
find_package( Qt5 COMPONENTS Core Test REQUIRED )
find_package( Crypt REQUIRED ) find_package( Crypt REQUIRED )
# Add optional libraries here # Add optional libraries here
@ -44,7 +39,7 @@ calamares_add_plugin( users
SHARED_LIB SHARED_LIB
) )
if( ECM_FOUND ) if( ECM_FOUND AND BUILD_TESTING )
ecm_add_test( ecm_add_test(
PasswordTests.cpp PasswordTests.cpp
SetPasswordJob.cpp SetPasswordJob.cpp