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

Added simple unit test sample for demonstration #4154

Merged
merged 7 commits into from
Feb 6, 2020
Merged

Added simple unit test sample for demonstration #4154

merged 7 commits into from
Feb 6, 2020

Conversation

burrima
Copy link
Contributor

@burrima burrima commented Jan 20, 2020

  • based on cmocka (https://cmocka.org) - thus, it needs to be installed before building. On Ubuntu 18.04: "apt install libcmocka-dev"
  • build darktable with option -DBUILD_TESTING=On
  • then run 'make test' in the build directory

Pull request contains 2 commits that were made earlier by @cryptomilk - thank you very much for your help!

Copy link
Contributor

@cryptomilk cryptomilk left a comment

Choose a reason for hiding this comment

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

Please split the patches into smaller ones, the test itself looks fine for me.

cmake/modules/AddMockedTest.cmake Outdated Show resolved Hide resolved
src/CMakeLists.txt Outdated Show resolved Hide resolved
src/common/darktable.h Outdated Show resolved Hide resolved
@aurelienpierre
Copy link
Member

Thanks a lot for this, that was so so so much needed ! I will let @cryptomilk do the review.

@cryptomilk
Copy link
Contributor

FYI: I will give a talk about cmocka at devconf.cz this weekend. I guess it is recorded and will be available next week.

@TurboGit
Copy link
Member

That's a wonderful step forward! Thanks a lot, for sure this will help dt to avoid regressions and will make big refactoring less scary! Looking forward to have this in action !

@TurboGit TurboGit added this to the 3.2 milestone Jan 23, 2020
@TurboGit TurboGit added difficulty: average some changes across different parts of the code base priority: high core features are broken and not usable at all, software crashes scope: codebase making darktable source code easier to manage wip pull request in making, tests and feedback needed labels Jan 23, 2020
src/tests/unittests/CMakeLists.txt Outdated Show resolved Hide resolved
src/tests/unittests/test_filmicrgb.c Outdated Show resolved Hide resolved
src/tests/unittests/test_filmicrgb.c Show resolved Hide resolved
src/tests/unittests/test_filmicrgb.c Outdated Show resolved Hide resolved
@cryptomilk
Copy link
Contributor

I've checked what the issue is and it is rawspeed which uses BUILD_TESTING. So it is turned off for rawspeed but this turns it off globally.

@burrima
Copy link
Contributor Author

burrima commented Jan 24, 2020

I've checked what the issue is and it is rawspeed which uses BUILD_TESTING. So it is turned off for rawspeed but this turns it off globally.

Not sure if you are right. My code is listening to BUILD_TESTS and not BUILD_TESTING. But I just realized that it works when I include cmocka in the base CMakeLists.txt.

@cryptomilk
Copy link
Contributor

See https://cmake.org/cmake/help/latest/command/enable_testing.html

BUILD_TESTING is forced to OFF.

@burrima
Copy link
Contributor Author

burrima commented Jan 25, 2020

See https://cmake.org/cmake/help/latest/command/enable_testing.html

BUILD_TESTING is forced to OFF.

I see. To me, cmake is still very new. Do you have any suggestion on how to fix this issue? Current state of this PR is working fine but I think it only works by chance and it is not a proper solution (cmake should probably be included in ./src/CMakeLists.txt and not in ./CMakeLists.txt, right?).

@cryptomilk
Copy link
Contributor

We need to change the variable in rawspeed to BUILD_RS_TESTING first. It shouldn't use BUILD_TESTING.

@burrima
Copy link
Contributor Author

burrima commented Jan 26, 2020

Ok, I think I understand now. I gave it a try and made a pull request for rawspeed: darktable-org/rawspeed#223
In this pull request here, I still need to update the rawspeed submodule ref as soon as above PR has merged.

@LebedevRI
Copy link
Member

Please, please. When writing a commit message, don't just state "we need to do XYZ".
That may be FUD. State what the problem is, and why the particular solution may be the right fix.

@burrima
Copy link
Contributor Author

burrima commented Jan 26, 2020

Thank you, @LebedevRI, your comment made me re-think again. As far as I understand now, the BUILD_TESTING is set to Off for rawspeed - or more precisely: set to Off by the darktable build system in src/external/CMakeLists.txt. But it is done "hidden" - i.e. the original value of BUILD_TESTING is stored at the beginning and reverted at the end. Thus, I think the pull request in rawspeed is not needed.

Also, I found out that my first commit (fixing the include of ThreadSafetyAnalysis.h) is not needed anymore with the current implementation.

My current code is working fine on my machine (retried both cases with/without tests and deleted the buld dir each time before). I will update this PR. @cryptomilk could you please have a look again? Does it make sense to you as well?

@LebedevRI
Copy link
Member

As far as I understand now, the BUILD_TESTING is set to Off by rawspeed - or more precisely: in src/external/CMakeLists.txt

Note that it is darktable's file, not rawspeed's.

But it is done "hidden" - i.e. the original value of BUILD_TESTING is stored at the beginning and reverted at the end.

Yep, at least that is the intent.

@burrima
Copy link
Contributor Author

burrima commented Jan 26, 2020

Note that it is darktable's file, not rawspeed's.

Yep, updated my above comment

@cryptomilk
Copy link
Contributor

Ok, it looks like BUILD_TESTING is not a problem. I'm on the train home and finally tracked it down.

See here: https://github.com/cryptomilk/darktable/tree/master-fix

$ make test
Running tests...
Test project /home/asn/workspace/projects/darktable/obj
    Start 1: test_sample
1/2 Test #1: test_sample ......................   Passed    0.00 sec
    Start 2: test_test_filmicrgb
2/2 Test #2: test_test_filmicrgb ..............   Passed    0.05 sec

100% tests passed, 0 tests failed out of 2

Total Test time (real) =   0.05 sec

@cryptomilk
Copy link
Contributor

@burrima Do you want to push my branch here?

@burrima
Copy link
Contributor Author

burrima commented Jan 26, 2020

@cryptomilk yes sure, thank you very much for your support.

Honestly I cannot follow what issue you are addressing with the extra commits. On my PC I get (almost) exactly the same output (without your fix):

burrima@vulcano:~/src/darktable/build$ make test
Running tests...
Test project /home/burrima/src/darktable/build
    Start 1: test_simplesample
1/2 Test #1: test_simplesample ................   Passed    0.00 sec
    Start 2: test_filmicrgb
2/2 Test #2: test_filmicrgb ...................   Passed    0.02 sec

100% tests passed, 0 tests failed out of 2

Total Test time (real) =   0.03 sec

Why do you get "test_test_filmicrgb" (note the double-"test_")?

@cryptomilk
Copy link
Contributor

cryptomilk commented Jan 26, 2020

I've already fixed that (double test_). I've split the code a bit more and include(CTest) needs to be included in the main CMakeLists.txt else it doesn't work.

@burrima
Copy link
Contributor Author

burrima commented Jan 26, 2020

Did you get my latest code updates to this branch? - I already have the CTest included in the topmost CMakeLists.txt. The reason why I am asking is because I see that you still have an old state of test_fimlicrgb.c in your branch. I re-formatted it with clang and removed the ugly looking /*******... lines. Thus, just taking your branch is maybe not the best idea from my perspective.

I could include your 2 fixing commits before my commits if you wish so (though maybe a separate pull request for them would be more clever since I think the code is not related). But at the end, your voice has more power since you are in this project way longer than me :-)

BTW: how was your presentation? I looked through your slides on the devconf.cz site and found them very informative.

@cryptomilk
Copy link
Contributor

Can you merge my work into yours? :-)

@burrima
Copy link
Contributor Author

burrima commented Jan 26, 2020

Yes, I'll do that. Sounds like the best strategy for me as well :-) Please give me some time since I'm going for dinner now.

@burrima
Copy link
Contributor Author

burrima commented Jan 26, 2020

Ok, done.

BTW: your branch master-fix does not build since there is still a test_ too much in src/cmake/modules/AddCMockaMockTest.cmake ;-)

@cryptomilk
Copy link
Contributor

@burrima Could you add cryptomilk@c19aba4

@cryptomilk
Copy link
Contributor

Please rebase on master and repush tomorrow. New docker images with cmocka should be available then ...

@burrima
Copy link
Contributor Author

burrima commented Jan 31, 2020

Ran docker on my ubuntu 18.04 pc. Then built dt inside the docker image. Tests then were running fine...
What I did in particular:
export SD=/home/burrima/src/darktable
sudo docker run -it --volume $SD:$SD:rw --workdir $SD darktable/darktable bash
cd build
export CC=/usr/bin/gcc-9
export CXX=/usr/bin/g++-9
cmake .. -DBUILD_TESTING=ON
cmake --build . -- -j6
ctest

@cryptomilk
Copy link
Contributor

@LebedevRI Roman, I'm not really familiar with TravisCI, do you have an idea why the tests fail with "Permission denied"?

@burrima Maybe also print:

tail -100 /var/log/messages
tail -100 /var/log/secure
tail -100 /var/log/audit/audit.log

@cryptomilk
Copy link
Contributor

@burrima Try with cryptomilk@7447782

@cryptomilk
Copy link
Contributor

cryptomilk and others added 7 commits February 1, 2020 12:07
This will work once we just allow to run darktable in the build dir.
Dave is working on this.
- based on cmocka (https://cmocka.org) - thus, it needs to be installed
  before building. On Ubuntu 18.04: "apt install libcmocka-dev"
- build darktable with option -DBUILD_TESTING=ON
- then run `make test`

Signed-off-by: Martin Burri <[email protected]>
This commit integrates function mocking with cmocka.

The code is still very empty and I will continue to work on this.

Signed-off-by: Martin Burri <[email protected]>
@cryptomilk
Copy link
Contributor

@TurboGit This is good to go!

@TurboGit
Copy link
Member

TurboGit commented Feb 1, 2020

@burrima @cryptomilk : Maybe I expected something else so I'm not sure to understand what is provided here. Is that only unit test on the code ?

What I thought was worked on was a way to give a source image, some actions like an XMP apply it and check that the output is consistent what what is expected (fuzzy comparison with the target image). Is that covered here ?

Whatever the answer to the question above I think we want a README in the test directory explaining how to add a test ? I did not find the high level description about this and I do feel this very important as adding tests is something we want to see encouraged as much as possible.

@TurboGit TurboGit self-requested a review February 1, 2020 15:11
@burrima
Copy link
Contributor Author

burrima commented Feb 1, 2020

@TurboGit This is code for function unit testing of the darktable code. I will add methods to create very simple test images in a next pull request. Thus, process() methods of modules can be tested. But unit-tested. So, no function testing as you described it.

A README is underway as well. Together with already implemented tests.

@burrima
Copy link
Contributor Author

burrima commented Feb 1, 2020

@TurboGit feel free to look at my work in progress. But please be gentle, it's really still under progress :-)

https://github.com/burrima/darktable/tree/test_filmicrgb

@cryptomilk
Copy link
Contributor

@TurboGit Pascal, what you expected is called integration test, this is unit testing :-) Martin already found bugs in filmic rgb writing unit tests for it :-)

@burrima
Copy link
Contributor Author

burrima commented Feb 4, 2020

Hi @TurboGit, may I kindly ask what makes you hold back this pull request? Besides of documentation (which I promised to deliver in my next pull request) what else is missing or making you struggle? - Or do you just need more time to review? I'm not in a hurry at all though it would be a great satisfaction to me to see my first real contribution to darktable going in. Best regards, Martin

@TurboGit
Copy link
Member

TurboGit commented Feb 4, 2020

@burrima : Just time and priorities. I've been working on integrating the new iop-order and working on big performance degradation. This PR is certainly a nice contribution, I just need more time to review and merge.

@burrima
Copy link
Contributor Author

burrima commented Feb 4, 2020

Sure, no problem, take your time. I was just wondering if you are expecting more from my side.

@TurboGit TurboGit removed the wip pull request in making, tests and feedback needed label Feb 6, 2020
@TurboGit
Copy link
Member

TurboGit commented Feb 6, 2020

@burrima : I had a look and the code as-is is ok to me. I'm not really sure how easy or feasible it will be to create serious test. BTW, is that to test only iop code or also the other parts of dt ? And in this case how all this will interact with the database (many routines are doing SQL) ? The pixel-pipe ? Are all those parts covered here ?

If it is only iop I think it is "simpler" and still just for this it will be nice to have in.

I have then nothing against merging this, still please give me some feedback regarding my questions above. Thanks.

@burrima
Copy link
Contributor Author

burrima commented Feb 6, 2020

@TurboGit thank you very much for the review and your feedback. From my side, I will focus on the iop for a good while. But there is generally nothing against writing unit tests for other parts. The nice thing about cmocka is that you can "mock" (https://en.wikipedia.org/wiki/Mock_object) functions, meaning that you can "overwrite" functions that are called by the function-under-test to mimic different behavior. Thus, you can break dependencies (e.g. to the database etc.).

Unit tests are in my eyes just a start - there is definitely the need for more automated testing (e.g. when it comes to GUI interaction).

@TurboGit
Copy link
Member

TurboGit commented Feb 6, 2020

Ok, so let's move on ! I'm eager to see unit test be added :) Thanks for the work!

@TurboGit TurboGit merged commit 1a7019e into darktable-org:master Feb 6, 2020
@burrima burrima deleted the mockasample branch February 6, 2020 19:33
@burrima
Copy link
Contributor Author

burrima commented Feb 6, 2020

@TurboGit cool, thank you very much! Unit tests are in the pipe :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: average some changes across different parts of the code base priority: high core features are broken and not usable at all, software crashes scope: codebase making darktable source code easier to manage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants