Skip to content

reduced usage of mutable Settings objects in tests - #4798

Merged
danmar merged 18 commits into
cppcheck-opensource:mainfrom
firewave:settings
May 2, 2023
Merged

reduced usage of mutable Settings objects in tests#4798
danmar merged 18 commits into
cppcheck-opensource:mainfrom
firewave:settings

Conversation

@firewave

Copy link
Copy Markdown
Collaborator

Currently the Settings objects in the tests are all mutable. This might cause some tests to modify the settings as they also contain run-time information which will be used by subsequent tests using the same object.

We should make sure that they are const if possible. Otherwise we need to make sure the tests will always be run on a a fixed configuration.

@firewave

Copy link
Copy Markdown
CollaboratorAuthor

This is to gain initial feedback on the approach. I will adjust all test then. I also have other PRs which need to be merged first to avoid conflicts.

@firewave
firewaveforce-pushed the settings branch 2 times, most recently from 6ca74d2 to ab0b8d0CompareFebruary 16, 2023 13:41
@firewavefirewave changed the title reduce usage of mutable Settings objects in testsreduced usage of mutable Settings objects in testsFeb 16, 2023
@firewave
firewaveforce-pushed the settings branch 2 times, most recently from 7555687 to 9575e90CompareFebruary 16, 2023 22:42
@firewave

Copy link
Copy Markdown
CollaboratorAuthor

This needs many other PRs merge first and we also need to adapt #4785 as a const Settings object still appears to be mutable since a lot of tests fail when I make those static. I wouldn't rule out some const_cast occurrences either.

@firewave

Copy link
Copy Markdown
CollaboratorAuthor

Turns out they are not mutable. I accidentally made objects static which should not.

@firewave
firewaveforce-pushed the settings branch 4 times, most recently from 348cb67 to 24c5953CompareFebruary 19, 2023 14:04
@firewave
firewave marked this pull request as ready for review February 19, 2023 14:53
@firewave
firewaveforce-pushed the settings branch 2 times, most recently from ed69e1c to e7a8c98CompareMarch 2, 2023 20:37
@firewave
firewaveforce-pushed the settings branch 3 times, most recently from 761c51b to 28ad381CompareMarch 7, 2023 12:21
@firewave
firewaveforce-pushed the settings branch 3 times, most recently from 7bc59be to edb0174CompareMarch 12, 2023 16:25
Comment threadtest/fixture.cpp Outdated
@danmar

Copy link
Copy Markdown
Collaborator

you are making various Settings objects static. Why?

@firewave

Copy link
Copy Markdown
CollaboratorAuthor

you are making various Settings objects static. Why?

So they are not instantiated on each test case but only once. Especially if library loading (or copying) is involved that is consuming unnecessary CPU.

@danmar

danmar commented Mar 13, 2023

Copy link
Copy Markdown
Collaborator

I would not make local objects static just to save a few cpu cycles. Can we please stop with all these micro optimisations that only saves a few cpu cycles. It's more important with readability.

Also these objects will then use some mutexes to make these objects threadsafe that has a penalty also.

@danmar

Copy link
Copy Markdown
Collaborator

Could you show some stats. With static or without static. I wonder if you can test that:

time ./testrunner TestOther

@firewave

Copy link
Copy Markdown
CollaboratorAuthor

Could you show some stats. With static or without static. I wonder if you can test that:

time ./testrunner TestOther

I will give it a spin. It is quite possible this PR is not showing the gains yet and is even showing a slight regression since I introduced several copies which weren't there before and won't be removed until I have applied all changes. I could add the follow-up changes to this PR as well but I would prefer not to make this even bigger than it already is.

There's also some general change to the way we provide the settings to the common check() wrapper which I haven't done yet which might also improve things and get rid of the need of inline/non-static configurations. It's quite incremental and at the end things will be much cleaner and more explicit.

@firewave

Copy link
Copy Markdown
CollaboratorAuthor

Doing tests I am getting some inconsistent results which is strange. So I will drop the static for now so this can proceed and will do some profiling again after I am done with all changes.

@danmar

Copy link
Copy Markdown
Collaborator

Doing tests I am getting some inconsistent results which is strange. So I will drop the static for now so this can proceed and will do some profiling again after I am done with all changes.

ok thanks as far as I remember that was my biggest concern. There is now some conflict..

@danmar
danmar merged commit 2935c85 into cppcheck-opensource:mainMay 2, 2023
@firewave
firewave deleted the settings branch May 2, 2023 09:55
Sign up for freeto 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.

2 participants

@firewave@danmar