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)
if( ECM_FOUND )
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()
find_package( KF5 COMPONENTS CoreAddons Crash )

View File

@ -105,6 +105,19 @@ install( TARGETS calamares
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
# lib/calamares can be used as module path for the Python interpreter.
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
}
bool
logLevelEnabled(unsigned int level)
{
return level < s_threshold;
}
unsigned int
logLevel()
{
return s_threshold > 0 ? s_threshold - 1 : 0;
}
static void
log( const char* msg, unsigned int debugLevel, bool toDisk = true )
{

View File

@ -89,6 +89,12 @@ namespace Logger
*/
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.
*

View File

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

View File

@ -20,10 +20,7 @@ if ( KPMcore_FOUND )
SHARED_LIB
)
if( ECM_FOUND )
find_package( Qt5 COMPONENTS Test REQUIRED )
include( ECMAddTests )
if( ECM_FOUND AND BUILD_TESTING )
ecm_add_test(
Tests.cpp
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
# to have a debugging-friendly timezone widget, debug logging,
# and no intrusive timezone-setting while clicking around.

View File

@ -509,17 +509,8 @@ PartitionCoreModule::jobs() const
lst << info->jobs;
devices << info->device.data();
}
cDebug() << "Creating FillGlobalStorageJob with bootLoader path" << 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;
}

View File

@ -20,6 +20,8 @@
#include "jobs/CreatePartitionTableJob.h"
#include "core/PartitionIterator.h"
#include "utils/Logger.h"
// 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
CreatePartitionTableJob::exec()
{
@ -73,7 +83,13 @@ CreatePartitionTableJob::exec()
PartitionTable* table = m_device->partitionTable();
cDebug() << "Creating new partition table of type" << table->typeName()
<< ", uncommitted yet:\n" << table;
<< ", uncommitted yet:";
if ( Logger::logLevelEnabled( Logger::LOGDEBUG ) )
{
for ( auto it = PartitionIterator::begin( table );
it != PartitionIterator::end( table ); ++it )
cDebug() << *it;
QProcess lsblk;
lsblk.setProgram( "lsblk" );
@ -88,6 +104,7 @@ CreatePartitionTableJob::exec()
mount.start();
mount.waitForFinished();
cDebug() << "mount:\n" << mount.readAllStandardOutput();
}
CreatePartitionTableOperation op(*m_device, table);
op.setStatus(Operation::StatusRunning);

View File

@ -56,9 +56,12 @@ findPartitionUuids( QList < Device* > devices )
QString path = p->partitionPath();
QString uuid = p->fileSystem().readUUID( p->partitionPath() );
hash.insert( path, uuid );
cDebug() << ".. added path=" << path << "UUID=" << uuid;
}
}
cDebug() << hash;
if ( hash.isEmpty() )
cDebug() << ".. no UUIDs found.";
return hash;
}
@ -90,10 +93,16 @@ mapForPartition( Partition* partition, const QString& uuid )
dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS() )
map[ "fs" ] = dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS()->name();
map[ "uuid" ] = uuid;
cDebug() << partition->partitionPath()
<< "mtpoint:" << PartitionInfo::mountPoint( partition )
<< "fs:" << map[ "fs" ] << '(' << map[ "fsName" ] << ')'
<< uuid;
// Debugging for inside the loop in createPartitionList(),
// so indent a bit
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 ) )
{
@ -104,7 +113,7 @@ mapForPartition( Partition* partition, const QString& uuid )
map[ "luksMapperName" ] = luksFs->mapperName().split( "/" ).last();
map[ "luksUuid" ] = getLuksUuid( partition->partitionPath() );
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\"]";
for ( auto device : m_devices )
{
cDebug() << ".. partitions on" << device->deviceNode();
for ( auto it = PartitionIterator::begin( device );
it != PartitionIterator::end( device ); ++it )
{
// Debug-logging is done when creating the map
lst << mapForPartition( *it, hash.value( ( *it )->partitionPath() ) );
}
}

View File

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

View File

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

View File

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