From 0902c7480984f194683e306255c9fad4eb4b0f3f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 3 Aug 2020 10:01:52 +0200 Subject: [PATCH 1/3] [hostinfo] Editorialize on the tests - the implementation understands Intel and AMD, but the test was written for my desktop machine (which fails elsewhere). SEE #1471 --- src/modules/hostinfo/Tests.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/modules/hostinfo/Tests.cpp b/src/modules/hostinfo/Tests.cpp index 8241ef022..8182da365 100644 --- a/src/modules/hostinfo/Tests.cpp +++ b/src/modules/hostinfo/Tests.cpp @@ -59,7 +59,12 @@ HostInfoTests::testHostOS() QCOMPARE( expect, hostOS() ); QCOMPARE( expect, hostOSName() ); // Might be the same - QCOMPARE( QStringLiteral( "Intel" ), hostCPU() ); // On all my developer machines + + // This is a lousy test, too: the implementation reads /proc/cpuinfo + // and that's the only way we could use, too, to find what the "right" + // answer is. + QStringList cpunames{ QStringLiteral( "Intel" ), QStringLiteral( "AMD" ) }; + QVERIFY( cpunames.contains( hostCPU() ) ); } From 272cf099becd232cc72b105497eea2b92f73e7a1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 5 Aug 2020 14:07:39 +0200 Subject: [PATCH 2/3] [hostinfo] Try to recognize ARM as well - /proc/cpuinfo is a terrible information source; it contains very different information on x86 from arm (testen on rpi4 and rock64). --- src/modules/hostinfo/HostInfoJob.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/modules/hostinfo/HostInfoJob.cpp b/src/modules/hostinfo/HostInfoJob.cpp index c2959fb6b..1d4676f65 100644 --- a/src/modules/hostinfo/HostInfoJob.cpp +++ b/src/modules/hostinfo/HostInfoJob.cpp @@ -91,6 +91,17 @@ hostCPUmatch( const QString& s ) return QString(); } +static QString +hostCPUmatchARM( const QString& s ) +{ + // Both Rock64 and Raspberry pi mention 0x41 + if ( s.contains( ": 0x41" ) ) + { + return QStringLiteral( "ARM" ); + } + return QString(); +} + #if defined( Q_OS_FREEBSD ) QString hostCPU_FreeBSD() @@ -127,6 +138,10 @@ hostCPU_Linux() { return hostCPUmatch( line ); } + if ( line.startsWith( "CPU implementer" ) ) + { + return hostCPUmatchARM( line ); + } } } return QString(); // Not open, or not found From 082770032f6262014920e7c0392dd621df330c95 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 5 Aug 2020 14:24:28 +0200 Subject: [PATCH 3/3] [hostinfo] Massage test to handle ARM - there **is** another source of information about the CPU, so in the test use that to cross-check what hostCPU() says. NB: it's probably a good idea to fall back on the same file in hostCPU() for better accuracy. --- src/modules/hostinfo/Tests.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/modules/hostinfo/Tests.cpp b/src/modules/hostinfo/Tests.cpp index 8182da365..7ab797ed4 100644 --- a/src/modules/hostinfo/Tests.cpp +++ b/src/modules/hostinfo/Tests.cpp @@ -63,8 +63,29 @@ HostInfoTests::testHostOS() // This is a lousy test, too: the implementation reads /proc/cpuinfo // and that's the only way we could use, too, to find what the "right" // answer is. - QStringList cpunames{ QStringLiteral( "Intel" ), QStringLiteral( "AMD" ) }; - QVERIFY( cpunames.contains( hostCPU() ) ); + QStringList x86cpunames{ QStringLiteral( "Intel" ), QStringLiteral( "AMD" ) }; + QStringList armcpunames{ QStringLiteral( "ARM" ) }; + const QString cpu = hostCPU(); + QVERIFY( x86cpunames.contains( cpu ) || armcpunames.contains( cpu ) ); + + // Try to detect family in a different way + QFile modalias( "/sys/devices/system/cpu/modalias" ); + if ( modalias.open( QIODevice::ReadOnly ) ) + { + QString cpumodalias = modalias.readLine(); + if ( cpumodalias.contains( "type:x86" ) ) + { + QVERIFY( x86cpunames.contains( cpu ) ); + } + else if ( cpumodalias.contains( "type:aarch64" ) ) + { + QVERIFY( armcpunames.contains( cpu ) ); + } + else + { + QCOMPARE( cpu, QString( "Unknown CPU modalias '%1'" ).arg(cpumodalias) ); + } + } }