From e2cc16ef9c45bdc64d42e4fef4dda46a3077cb35 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 9 Jan 2024 02:38:43 +0100 Subject: [PATCH] Fix test suite on Linux/s390x and maybe other architectures We can't rely on file /sys/power/state always existing, so just skip the test (with a warning) instead of failing it if it does not exist, as is the case at least under s390x and seemingly other non-desktop platforms. Closes #24197. Co-authored-by: Cliff Zhao --- tests/file/filetest.cpp | 7 ++++++- tests/filename/filenametest.cpp | 6 ++++++ tests/textfile/textfiletest.cpp | 8 +++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/file/filetest.cpp b/tests/file/filetest.cpp index c2483b9afe..88b3a895ac 100644 --- a/tests/file/filetest.cpp +++ b/tests/file/filetest.cpp @@ -150,8 +150,13 @@ TEST_CASE("wxFile::Special", "[file][linux][special-file]") const long pageSize = sysconf(_SC_PAGESIZE); wxFile fileSys("/sys/power/state"); + if ( !fileSys.IsOpened() ) + { + WARN("/sys/power/state can't be opened, skipping test"); + return; + } + CHECK( fileSys.Length() == pageSize ); - CHECK( fileSys.IsOpened() ); CHECK( fileSys.ReadAll(&s) ); CHECK( !s.empty() ); CHECK( s.length() < static_cast(pageSize) ); diff --git a/tests/filename/filenametest.cpp b/tests/filename/filenametest.cpp index bee7bb10b9..01bbc9a77c 100644 --- a/tests/filename/filenametest.cpp +++ b/tests/filename/filenametest.cpp @@ -1040,6 +1040,12 @@ TEST_CASE("wxFileName::GetSizeSpecial", "[filename][linux][special-file]") INFO( "size of /proc/kcore=" << size ); CHECK( size > 0 ); + if ( !wxFile::Exists("/sys/power/state") ) + { + WARN("/sys/power/state doesn't exist, skipping test"); + return; + } + // All files in /sys are one page in size, irrespectively of the size of // their actual contents. CHECK( wxFileName::GetSize("/sys/power/state") == sysconf(_SC_PAGESIZE) ); diff --git a/tests/textfile/textfiletest.cpp b/tests/textfile/textfiletest.cpp index 8c29aab496..646d6818c9 100644 --- a/tests/textfile/textfiletest.cpp +++ b/tests/textfile/textfiletest.cpp @@ -336,12 +336,18 @@ TEST_CASE("wxTextFile::Special", "[textfile][linux][special-file]") SECTION("/proc") { wxTextFile f; - CHECK( f.Open("/proc/cpuinfo") ); + REQUIRE( f.Open("/proc/cpuinfo") ); CHECK( f.GetLineCount() > 1 ); } SECTION("/sys") { + if ( wxFile::Exists("/sys/power/state") ) + { + WARN("/sys/power/state doesn't exist, skipping test"); + return; + } + wxTextFile f; CHECK( f.Open("/sys/power/state") ); REQUIRE( f.GetLineCount() == 1 );