Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2015-03

FPCUnit - parallel test suite execution

17 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

As per good unit test guidelines, tests should be independent of each other and not rely on results from earlier tests. The perfect candidate for parallelism. So what about the idea of running x amount of test suites in parallel? It should at least give our multi-core CPU's something to do and maybe complete 2000+ tests in a shorter period. ;-)

Thoughts?

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 7 lines
As per good unit test guidelines, tests should be independent of each other and not rely on results from earlier tests. The perfect candidate for parallelism. So what about the idea of running x amount of test suites in parallel? It should at least give our multi-core CPU's something to do and maybe complete 2000+ tests in a shorter period. ;-) Thoughts?

In theory, I am not against.

But: Not all tests can be run in parallel. DB code is for instance not thread safe.

Then:
Given the nature of decorators, it will require extensive checking to make sure that tests that rely on the same decorator will be run in the same thread anyway.

Just some random thoughts.

Michael.

Reply by email

leledumbo
to Graeme Geldenhuys: As per good unit test guidelines, tests should be independent of each other and not rely…
Show quoted text 5 lines
So what about the idea of running x amount of test suites in parallel? It should at least give our multi-core CPU's something to do and maybe complete 2000+ tests in a shorter period. ;-) Thoughts?

I haven't got as many tests as that yet, but surely a parallel execution will make a good use of my multicore processor.

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/FPCUnit-parallel-test-suite-execution-tp5721391p5721396.html Sent from the Free Pascal - General mailing list .

Reply by email

Marcos Douglas
to Graeme Geldenhuys: As per good unit test guidelines, tests should be independent of each other and not rely…
Graeme Geldenhuys wrote 7 lines
As per good unit test guidelines, tests should be independent of each other and not rely on results from earlier tests. The perfect candidate for parallelism. So what about the idea of running x amount of test suites in parallel? It should at least give our multi-core CPU's something to do and maybe complete 2000+ tests in a shorter period. ;-) Thoughts?

Maybe a new class named TTestCaseAsync, ie, all test cases that inherit it will run in parallel.

Marcos Douglas

Reply by email

Michael Van Canneyt
to Marcos Douglas
Marcos Douglas wrote 12 lines
On Wed, Mar 18, 2015 at 2:04 PM, Graeme Geldenhuys wrote: > As per good unit test guidelines, tests should be independent of each > other and not rely on results from earlier tests. The perfect candidate > for parallelism. So what about the idea of running x amount of test > suites in parallel? It should at least give our multi-core CPU's > something to do and maybe complete 2000+ tests in a shorter period. ;-) > > Thoughts? Maybe a new class named TTestCaseAsync, ie, all test cases that inherit it will run in parallel.

I think this is maybe the best approach.

Michael.

Reply by email

Mark Morgan Lloyd
to Graeme Geldenhuys: As per good unit test guidelines, tests should be independent of each other and not rely…
Graeme Geldenhuys wrote 7 lines
As per good unit test guidelines, tests should be independent of each other and not rely on results from earlier tests. The perfect candidate for parallelism. So what about the idea of running x amount of test suites in parallel? It should at least give our multi-core CPU's something to do and maybe complete 2000+ tests in a shorter period. ;-) Thoughts?

In any event the output would need to be presented in a reproducible sequence.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Michael Van Canneyt
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 12 lines
Graeme Geldenhuys wrote: > As per good unit test guidelines, tests should be independent of each > other and not rely on results from earlier tests. The perfect candidate > for parallelism. So what about the idea of running x amount of test > suites in parallel? It should at least give our multi-core CPU's > something to do and maybe complete 2000+ tests in a shorter period. ;-) > > Thoughts? In any event the output would need to be presented in a reproducible sequence.

Indeed, and this would require a huge change to the current output formatters. (at least the text output formatter)

Michael.

Reply by email

Graeme Geldenhuys
to Mark Morgan Lloyd: In any event the output would need to be presented in a reproducible sequence. Mark…
Mark Morgan Lloyd wrote
In any event the output would need to be presented in a reproducible sequence.

A good point, but thinking about it I don't think it would be that hard. The text output might be a bit more tricky, but not impossible.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

Graeme Geldenhuys
to Marcos Douglas: On Wed, Mar 18, 2015 at 2:04 PM, Graeme Geldenhuys Maybe a new class named…
Marcos Douglas wrote
Maybe a new class named TTestCaseAsync, ie, all test cases that inherit it will run in parallel.

That could work.

Does FPC 2.6.4 and later already support the attributes language feature? If so, that could be a possible option too.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt: In theory, I am not against. But: Not all tests can be run in parallel. DB code is for…
Michael Van Canneyt wrote
Just some random thoughts.

Thanks for raising some good points.

At this stage I'm just thinking of possibilities on improving FPCUnit. As a testing framework, it is seriously lacking behind others. But, I'm not just all talk, I've submitted my first patch set last night to Mantis. There are more in the works if those go through.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 9 lines
On 2015-03-18 21:52, Michael Van Canneyt wrote: > Just some random thoughts. Thanks for raising some good points. At this stage I'm just thinking of possibilities on improving FPCUnit. As a testing framework, it is seriously lacking behind others. But, I'm not just all talk, I've submitted my first patch set last night to Mantis. There are more in the works if those go through.

I have seen the patch, and will look at it monday or tuesday.

As always: improvements are welcome.

And therein lies the catch: it's not always clear what constitutes an improvement ;)

Michael.

Reply by email

Mark Morgan Lloyd
to Graeme Geldenhuys: A good point, but thinking about it I don't think it would be that hard. The text output…
Graeme Geldenhuys wrote 6 lines
On 2015-03-19 08:10, Mark Morgan Lloyd wrote: > In any event the output would need to be presented in a reproducible > sequence. A good point, but thinking about it I don't think it would be that hard. The text output might be a bit more tricky, but not impossible.

Blue-sky thought if there's to be /any/ modification. It would be useful to have something comparable with a Merkle tree here, so that there's a single overall fingerprint indicating that the entire run is OK (irrespective of the order of the tests), subsignatures indicating that the first and last halves are OK, and so on.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt: I have seen the patch, and will look at it monday or tuesday. As always: improvements are…
Michael Van Canneyt wrote
And therein lies the catch: it's not always clear what constitutes an improvement ;)

Ah, that's an easy one. Whatever helps speeds up the developer's (end-user) work. :-)

After using DUnit2 for so long I have gotten very used to the useful test output it gives and the many features in the GUI Test Runner. eg: A test Error (the unexpected one) in FPCUnit gave no hint as to where the error actually occurred. So you have to run it via the IDE and debugger just to find the location (could be many units deep), then go from there to fix it. With DUnit2 and with the latest patches for FPCUnit, it now tells you the exact unit and line number for Errors and Failures.

The next step would be to improve the GUI Test Runner in LCL.
- scroll treeview to first error or failure [done]
- improved keyboard shorcuts [done]
- save state of selected tests
- option to uncheck all passed tests so the next testrun only runs the previous failed ones
- double click on failed tests and let the IDE open the related unit and jump to the exactl line number in question.
- improved overview of failed tests

and many more others...

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

Jonas Maebe
to Graeme Geldenhuys: A good point, but thinking about it I don't think it would be that hard. The text output…

Graeme Geldenhuys wrote on Thu, 19 Mar 2015:

Show quoted text 6 lines
On 2015-03-19 08:10, Mark Morgan Lloyd wrote: > In any event the output would need to be presented in a reproducible > sequence. A good point, but thinking about it I don't think it would be that hard. The text output might be a bit more tricky, but not impossible.

The easiest, most maintainable, least invasive (and in case you don't need/want the threads to interact, often also the best performing) way to introduce parallelism is to do it as coarse-grained as possible. I.e., simply run multiple self-contained unit-test programs in parallel, rather than trying to parallelise the execution of unit tests within a single program. Since the tests by definition are supposed to be independent, introducing dependencies by adding threading is a step backwards in several ways (performance, maintainability, debugability, ..).

This, of course, requires the availability of as sufficient number of test programs to actually execute in parallel (which definitely can be a problem if you're used to putting all unit tests into a single program). But if you do have that amount of independent work available, you'll generally get much better performance because you won't need any locking anywhere (even the overhead of the OS starting a program can easily be lower than the one caused by work queue maintenance and contention over a bunch of locks in a program, especially if you have very fine-grained work units such as a single function call to evaluate and test). You'll also have much better productivity because you'll have to spend much less time on writing, optimising and debugging the actual testing framework (and on taking into account all possible threading hazards when extending it).

An extreme example of this is the FPC testsuite: on an IBM Power8 system with 10 cores that each can run 16 threads, the entire testsuite of 4000-5000 test programs finishes in about 30 seconds (including running fpmake install on the rtl and packages directories). The parallelism, in this case, is handled via make -j 160, but it could just as well be a Pascal program that fires up threads and launches programs from within those threads. Every parallel invocation of the test runner (dotest) executes 10 to 20 tests sequentially and the results are all written to separate files. At the very end, all of those text files are concatenated in the right order, so the output is deterministic.

Most OS kernels have a lot of smp optimisations, probably way better than any of us could every write (or even would want to bother to write and maintain for something like a testing harness). I very much doubt a multi-threaded implementation of the dotest program, apart from the work this would entail, could outperform the current approach without several weeks or even months of work.

Jonas

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys: Ah, that's an easy one. Whatever helps speeds up the developer's (end-user) work. :-)…
Graeme Geldenhuys wrote 14 lines
On 2015-03-19 10:22, Michael Van Canneyt wrote: > And therein lies the catch: it's not always clear what constitutes an > improvement ;) Ah, that's an easy one. Whatever helps speeds up the developer's (end-user) work. :-) After using DUnit2 for so long I have gotten very used to the useful test output it gives and the many features in the GUI Test Runner. eg: A test Error (the unexpected one) in FPCUnit gave no hint as to where the error actually occurred. So you have to run it via the IDE and debugger just to find the location (could be many units deep), then go from there to fix it. With DUnit2 and with the latest patches for FPCUnit, it now tells you the exact unit and line number for Errors and Failures.

Absolutely

Show quoted text 12 lines
The next step would be to improve the GUI Test Runner in LCL. - scroll treeview to first error or failure [done] - improved keyboard shorcuts [done] - save state of selected tests - option to uncheck all passed tests so the next testrun only runs the previous failed ones - double click on failed tests and let the IDE open the related unit and jump to the exactl line number in question. - improved overview of failed tests and many more others...

The above ones: clearly an improvement, though I fear some will need changes in the fpcunit core code.

And: 'double click and let IDE open...': yes please !! :)

Michael.

Reply by email

Michael Van Canneyt
to Jonas Maebe: Graeme Geldenhuys wrote on Thu, 19 Mar 2015: The easiest, most maintainable, least…
Jonas Maebe wrote 17 lines
Graeme Geldenhuys wrote on Thu, 19 Mar 2015: > On 2015-03-19 08:10, Mark Morgan Lloyd wrote: >> In any event the output would need to be presented in a reproducible >> sequence. > > A good point, but thinking about it I don't think it would be that hard. > The text output might be a bit more tricky, but not impossible. Most OS kernels have a lot of smp optimisations, probably way better than any of us could every write (or even would want to bother to write and maintain for something like a testing harness). I very much doubt a multi-threaded implementation of the dotest program, apart from the work this would entail, could outperform the current approach without several weeks or even months of work.

While all what you say is correct, writing a test program per test is simply not an option. For e.g. database tests the performance hit alone would be prohibitive.

Michael.

Reply by email

Graeme Geldenhuys
to Jonas Maebe: Graeme Geldenhuys wrote on Thu, 19 Mar 2015: The easiest, most maintainable, least…

Hi,

Many thanks for your comments.

Jonas Maebe wrote
I.e., simply run multiple self-contained unit-test programs in parallel,

Based on the projects I work on that has unit testing, that doesn't seem like a feasible option. It would require a lot of work, not only splitting the test suites, but also compiling all of them etc. Plus the fact that Lazarus IDE still doesn't support Project Groups, it makes working with multiple related projects very tedious.

tests sequentially and the results are all written to separate files. At the very end, all of those text files are concatenated in the right order, so the output is deterministic.

This is actually what I had in mind for a single test program. Test suites that run in parallel will return a TTestResult object. The main program will then collect all those results at the end of the complete run and present it in some good manner. Sounds simple enough. ;-)

DUnit2 and FPTest (my Free Pascal fork of DUnit2) already support an interface for repeating tests. Creating parallel tests could be handled in a similar fashion. I'll have to review the FPCUnit code a bit more to see what would be needed.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email