Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding windows test driver fix #293

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

kreuzberger
Copy link

@kreuzberger kreuzberger commented Apr 8, 2024

Summary

Fix #292

Details

Different QtTestDriver Implemenation to ensure no resource lock on windows.
Issue with undefined output format for qExec, add explicitly ".txt" extension

Motivation and Context

Fix #292

How Has This Been Tested?

Running internal tests with/without changes on ubuntu 22.04 and win10 vs2019

Types of changes

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).

Checklist:

  • It is my own work, its copyright is implicitly assigned to the project and no substantial part of it has been copied from other sources (including Stack Overflow). In rare occasions this is acceptable, like in CMake modules where the original copyright information should be kept.
  • I'm using the same code standards as the existing code (indentation, spacing, variable naming, ...).
  • I've added tests for my code.
  • I have verified whether my change requires changes to the documentation
  • My change either requires no documentation change or I've updated the documentation accordingly.
  • My branch has been rebased to main, keeping only relevant commits.

Copy link
Contributor

@ursfassler ursfassler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

I see the problem and how you solve it. Please fix and adjust your changes according my input (or discuss it when you see it different 🙂 ).

Please also add the test in the CI. This helps me to see the problem and protects us from similar problems in the future.

src/drivers/QtTestDriver.cpp Outdated Show resolved Hide resolved
src/drivers/QtTestDriver.cpp Outdated Show resolved Hide resolved
src/drivers/QtTestDriver.cpp Outdated Show resolved Hide resolved
src/drivers/QtTestDriver.cpp Outdated Show resolved Hide resolved
src/drivers/QtTestDriver.cpp Outdated Show resolved Hide resolved
@kreuzberger
Copy link
Author

kreuzberger commented Apr 10, 2024

Due to the checks: Could you provide a clang-format file (.clang-format) or what should be used for clang-format as default style? Assume clang-format without any further options?

@ursfassler
Copy link
Contributor

Due to the checks: Could you provide a clang-format file (.clang-format) or what should be used for clang-format as default style? Assume clang-format without any further options?

The format file is checked in: https://github.com/cucumber/cucumber-cpp/blob/main/.clang-format
Clang-format may produce slightly different out depending on the version. It usually is no problem.

@kreuzberger
Copy link
Author

kreuzberger commented Apr 11, 2024

Current Status

TLDR: Windows Tests integration, would only merge after some clarifications

  • Tried to integrate the issues from the reviews
    • Qt5 and Qt6 differ in QTemporaryFile Name generation if its template based. Added applicationame and pid in a reproducable way (hope so 😄)
    • Enabled file removal. Might be an issue to change.
    • Suggested early exit handling due to readability
    • clang formating
  • Fixed run-linux.sh issue to use Qt6 and disable Qt5 if both are found
  • Refactored run-windows powershell script to
    • Build Release configuration only (Could Ninja be used? works, but do not know status on test vm)
    • Run cmake tests
    • Add install step like for linux
    • Build examples and run example test executables for GTest
    • Build examples and run example test executables for QtTest (if qmake found in path, better solution for getting the Qt Runtime Path for windows would be acceptable.)
    • Sometimes (often) failing windows Tests with QtTestDriver
  • Integrate the suggested QTemporayFileWrapper

Open Issues

On Windows the QtTestDriver failes sometimes. Reason is that in one test the Text Error messages are compared.
Due to the nature of the default QtTest output the diff test fails cause the Test execution time differs.
This could also occur on linux, but seems not so often there (currently im running windows in VM)

+ Totals: 2 passed, 1 failed, 0 skipped, 0 blacklisted, 2ms
+ ********* Finished testing of cucumber::internal::QtTestObject *********
- Totals: 2 passed, 1 failed, 0 skipped, 0 blacklisted, 1ms
- ********* Finished testing of cucumber::internal::QtTestObject *********

Dont know how to fix.

For the QtTests to work which are not part of ctest the Qt Runtime Path (bin on Windows) must be in PATH.
Do currently not know HOW to get this in the CI. Workarounded by having it in the PATH env of the caller.
This could be fixed running these Tests in CMake with the runtime Path determined like for the other ctests and let the test code (starting and waiting for the processes) be run with os dependent scripts.

@kreuzberger
Copy link
Author

Hi! Would it be possible to let the checks run on commit, so i can see open issues and fix them?

Copy link
Contributor

@ursfassler ursfassler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked through the changes shortly to see if I can run the tests, i.e. that no bad things are in there 😄

I haven't really understood the problem with Qt, Windows and tests, hence I have troubles to understand if the patch is good or not. Sorry for that, a bit short on time on my end.

run-linux.sh Outdated Show resolved Hide resolved
run-windows.ps1 Outdated Show resolved Hide resolved
run-windows.ps1 Outdated Show resolved Hide resolved
run-windows.ps1 Outdated Show resolved Hide resolved
run-windows.ps1 Outdated Show resolved Hide resolved
run-windows.ps1 Outdated Show resolved Hide resolved
src/drivers/QtTestDriver.cpp Show resolved Hide resolved
tests/CMakeLists.txt Outdated Show resolved Hide resolved
@ursfassler
Copy link
Contributor

On Windows the QtTestDriver failes sometimes. Reason is that in one test the Text Error messages are compared.
Due to the nature of the default QtTest output the diff test fails cause the Test execution time differs.

😲 That would be a bad tests, timings shouldn't be compared in the tests. What test is it?

@ursfassler
Copy link
Contributor

Fixed run-linux.sh issue to use Qt6 and disable Qt5 if both are found

Idea is that only the Qt version you specified is searched for.

@kreuzberger
Copy link
Author

kreuzberger commented Apr 15, 2024

On Windows the QtTestDriver failes sometimes. Reason is that in one test the Text Error messages are compared.
Due to the nature of the default QtTest output the diff test fails cause the Test execution time differs.

😲 That would be a bad tests, timings shouldn't be compared in the tests. What test is it?

QtTestDriverTest, see open issues from above

@ursfassler ursfassler mentioned this pull request Apr 29, 2024
9 tasks
@ursfassler
Copy link
Contributor

@kreuzberger please see my PR #296 to fix the flaky test.

I also investigated if it is possible to capture the test log without needing the file. Unfortunately it seems not to be possible (without too much hacking). Meaning that this PR is quite relevant.

@kreuzberger
Copy link
Author

kreuzberger commented May 2, 2024

@kreuzberger please see my PR #296 to fix the flaky test.

I also investigated if it is possible to capture the test log without needing the file. Unfortunately it seems not to be possible (without too much hacking). Meaning that this PR is quite relevant.

Commented your PR #296.

@ursfassler
Copy link
Contributor

@kreuzberger unfortunetaly the Windows build has a problem with gtest.

@cwellm did you also had this problem? Could you also help out with reviewing the windows code?

Copy link
Contributor

@ursfassler ursfassler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kreuzberger I think we get closer on your fix but still have troubles with the CI. I'd suggest that you split your changes to a small fix for the temporary file on Windows and we add the tests in a separate PR. This way you have the changes that you need integrated.

If you agree, I'd suggest that you open a second PR with the Windows-tests and only keep the functional changes here. Please also cleanup the history in order to only have relevant commits in it.

CMakeLists.txt Show resolved Hide resolved
Comment on lines +12 to +13
// wraps the QTemporaryFile creation
// on Windows the file could not be written as long as QTemporaryFile owner of the file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling, I'd suggest (but I'm not a native speaker):

// Wraps the QTemporaryFile creation.
// Needed because on Windows, the file can not be written from QtTest as long as we keep it open.

src/drivers/QtTestDriver.cpp Show resolved Hide resolved
Comment on lines +66 to +81
const auto file = TemporaryFileWrapper::create();
if (!file.exists()) {
return InvokeResult::failure("Unable to open temporary file needed for this test");
}
file.close();

QtTestObject testObject(this);
int returnValue = QTest::qExec(
&testObject,
QStringList() << "test"
<< "-o" << file.fileName()
<< "-o" << file.name()
);

if (returnValue == 0) {
return InvokeResult::success();
} else {
file.open();
QTextStream ts(&file);
return InvokeResult::failure(ts.readAll().toLocal8Bit());
return InvokeResult::failure(file.read().toLocal8Bit());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

Comment on lines +14 to +37
function(cuke_set_environment environment)
set(options)
set(oneValueArgs )
set(multiValueArgs RUNPATH)

cmake_parse_arguments(CUKE_ENV "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if(NOT "${CUKE_ENV_UNPARSED_ARGUMENTS}" STREQUAL "")
message(
FATAL_ERROR
"unparsed arguments in call to cuke_set_environment: ${CUKE_ENV_UNPARSED_ARGUMENTS} from ${CMAKE_CURRENT_LIST_FILE}"
)
endif()

if( NOT "${CUKE_ENV_RUNPATH}" STREQUAL "")
if(WIN32)
string(REPLACE ";" "\;" CUKE_ENV_RUNPATH "${CUKE_ENV_RUNPATH}")
endif()
set(RUNPATH "$<IF:$<PLATFORM_ID:Windows>,PATH,LD_LIBRARY_PATH>")
list(APPEND environment "$<IF:$<PLATFORM_ID:Windows>,PATH,LD_LIBRARY_PATH>=path_list_prepend:$<SHELL_PATH:${CUKE_ENV_RUNPATH}>")
endif()
set(${environment} ${${environment}} PARENT_SCOPE)
endfunction()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a lot of code to just support Windows. Is it possible to move this to run-windows.ps1 (if it makes sense).

@cwellm any ideas from your side?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QTestDriver Implementation not working on Windows
2 participants