-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Missing Unit Tests #4330
Comments
testing is mostly done via fishtest, https://tests.stockfishchess.org/tests and our github ci and your local compiler (lols) |
additionally you could compile in debug mode to see if you hit any asserts |
This seems to be an integration test. Integration tests and unit tests are not the same. An integration test cannot replace unit tests and unit tests cannot replace integration tests. And manual debugging is very error prone. One change can affect other parts which you didn't expect and without unit tests, refactoring is getting really hard which may result into not refactoring code. That is, the technical debt increases. |
Yea, I was just refering to testing in general. |
@StefanoD Can you give a concrete example of a unit test that would be useful in the context of a chess engine? IMHO the difficulty is that it is not clear what constitutes a bug in a chess engine. For example in normal software, access to the hash table (a shared resource) should be protected by locks. In a chess engine however race conditions are tolerated while accessing the hash table as testing has shown that the overall effect on Elo is positive. |
@vdbergh I. e. finding best moves, finding legal moves. In context of hash table: Testing for low collisions, testing for performance. This is all relevant, when you change code. In short: The idea of unit tests are to test (almost) every function, such that regressions can be found instantly and without much pain. |
verifiying move legality on a number of different test positions could be a unit test, or repetition testing ? |
these are things I would say are good candidates to test on fishtest. |
The mentioned And next sprintf never causes memory violation once the buffer exists in memory. I don't know what reasons you're thinking about, but mostly |
@StefanoD Legal move generation is typically tested with perft. Your other examples in the first paragraph are not convincing. One doesn't care about best moves in individual positions in chess engines (such a thing isn't even properly defined), only overall Elo counts (which is determined by testing on Fishtest). And the number of collisions in SF's hash table is quite high as testing has again shown that the overall Elo effect is positive. I am not against unit testing but I think that in SF's context it might not be as useful as you think it is. Something that would be suitable for unit testing is the table base code. But what would be really useful is a documentation of the file format. |
@vdbergh I think you tagged the wrong person, I think you meant me? |
No, if the buffer is too small or a string not null-terminated, you'll get an access violation. If I really have to convince you that not having unit tests, is bad, then I guess you have to deal with more regressions and less contributors. |
@Disservin No @StefanoD also gave legal move generation as an example. I don't quite know what I guess a unit test could consist of running perft on a number positions with known perft values (the starting position might not be sufficient for obscure corner cases). |
|
Have you checked the previous lines? I agree with introducing unit tests btw, but you should provide a detailed list of scopes of which we need to test. |
@Disservin Ok. Perhaps |
nope, there are |
Yes, I have and the function As I said: Unit tests are also for testing regressions in case of refactorings.
As you know, I am absolutely no expert in this project. Thus, I thought you could name more scopes than me. But, if a project doesn't have unit tests then, for me, there is something not optimal. In my opinion, every project must absolutely have unit tests. Of course, it's good that you have integration tests! |
I tend to agree with @vdbergh and others. Every project should not have unit tests per se, this is just way too dogmatic. It depends on the case. But anyway, if some more good examples are found for where unit tests add value, you might convince me :) |
Fishtest tests for both nonregression of elo and gain of elo. In fact I'm tempted to say that your pull request, which I'm generally in favor of, should be put thru a nonregression test on fishtest just to be sure that it is sane. |
How long do |
Stockfish/src (master)$ time ../tests/perft.sh
perft testing started
perft testing OK
real 0m2.313s
user 0m0.016s
sys 0m0.020s |
Fishtest is a distributed testing framework testing locally isnt the purpose of it. Perft tests finish in under 1 minute. Anyone can create a fishtest account btw |
|
@TheDarkKnightRise @Disservin I know but I thought that it is sufficient to check that the hash move is pseudo legal. |
Since Stefano has a very clear idea of the kind of unit tests he/she would like, but has not proposed any unit code in the last six months, I'll close the issue as not urgent :-) |
You can add unit tests for known bugs, like #4877. It's a good practice to add a failing unit test for every defect, and then make sure the test passes after the bugfix. The point is that the developers can demonstrate that they isolated what is wrong with the code, proved that it is wrong, fixed it, proved that the fix is correct. |
Well with some bugs like the one you mentioned is a basically impossible to unit test it. It depends a lot on what is currently done in search and what not. In theory these things should be caught in the CI and writing an unit test for undefined behavior is not really possible anyway… code can have undefined behavior but happen to give the right result when you are running the unit test. |
upd: ok, chatgpt proposes wild solutions for mocking std functions, so let me agree that it's not that straightforward to unit test the bug that happens because of undefined behavior in C++ standard library. |
tldr; unit testing search is not as straight forward as one might think
Well "unit testing" undefined behavior is not pretty standard to my knowledge. The closest thing which you can do is run the program with
i'm not
std::clamp is a function from the standard, so we cant change the underlying implemention (though my libcxx has an assertion in place
this is easier said than done, search changes all time. So each new functional patch would be required to find a special state in which certain conditions are met which trigger the problematic behaviour or everything in search needs to be split up into dedicated functions which are then in turn unit testable. Though there are many parts which rely on some (global) state to trigger the exact behaviour. |
Your answer only explains why there are no unit tests and why the discussion reached a dead end. Now back to stockfish: This is a 100% software project and you are writing about the impossible task of writing sane unit tests. Sorry, but I'm shocked. I hope, I could give you some inspirations... |
@StefanoD Unit tests are great... I don't disagree with that. But I find it ridiculous to test a function for undefined behaviour because it's not reliable that this will actually make the unit test fail or even creating an abstraction around std::clamp, should we create another layer of abstraction for all functions from the standard which may lead to UB?
When did I say this? My conclusion was simply
I said that. All I wanted to express that with the current state it's not that simple to add a unit test for the bug encountered in #4877, sure create a function called |
Also if we move into the direction of #4626 there should probably be unit tests, no doubt. |
Describe the issue
Am I something missing or are unit tests missing?
I was considering to do more pull requests, but without unit tests, I am afraid to break something. Further, how are we supposed to note regressions without unit tests?
Expected behavior
I would have expected a folder with unit tests with a modern frame work like Google Test and there would be a compile option to compile the project without unit tests.
Steps to reproduce
Open the project, go to the test folder and be aware there are no unit tests.
Anything else?
No response
Operating system
All
Stockfish version
9fe9ff0
The text was updated successfully, but these errors were encountered: