[vector] tests with data providers
Paul Sandoz
paul.sandoz at oracle.com
Mon Mar 12 16:46:05 UTC 2018
> On Mar 12, 2018, at 9:04 AM, Halimi, Jean-Philippe <jean-philippe.halimi at intel.com> wrote:
>
> Hi Paul,
>
> Thanks for the fast follow-up patch! :-)
>
> I like the new design a lot. I have to admit I am a bit confused on the data initializer part:
>
> - Where is BOOLEAN_GENERATOR_PAIRS defined?
It’s not needed, because there is only one mask value passed as an argument to a test method.
> - I am having trouble understanding how initializer functions defined in BYTE_GENERATORS are selected.
>
> For instance, in this code:
>
> + // Create combinations of pairs
> + // @@@ Might be sensitive to order e.g. div by 0
> + static final List<List<IntFunction<byte[]>>> BYTE_GENERATOR_PAIRS =
> + Stream.of(BYTE_GENERATORS.get(0)).
> + flatMap(fa -> BYTE_GENERATORS.stream().skip(1).map(fb -> List.of(fa, fb))).
> + collect(Collectors.toList());
>
> Could you elaborate how this code selects the appropriate method?
>
There is no test method selection going on here, that happens later on. All this does is set up pairs of array generators to be provided to binary operations with and without a mask. e.g. i envisaged having multiple data input to operations, we can represent that as a list, for input to a unary operation, and then for the binary operation pairs from that list can be generated, but we may need to be careful on the order of values in those pairs if any operation would result in say an arithmetic exception (which we are not testing for, at least not yet!).
The pairs are exposed as a provider via the following method:
@DataProvider
public Object[][] byteBinaryOpProvider() {
return BYTE_GENERATOR_PAIRS.stream().map(List::toArray).
toArray(Object[][]::new);
}
The provide is literally saying “here is the list of list of arguments”. Then a test method says that it uses that provider whose parameter types conform to the values in the inner lists:
@Test(dataProvider = "byteBinaryOpProvider", invocationCount = 10)
static void addByte64VectorTests(IntFunction<byte[]> fa, IntFunction<byte[]> fb) {
So it’s the test method that selects the data provider.
For a binary operation that uses a mask, we cross product each mask with each pair. When you run the tests this should become clearer, i made sure there are nice toString implementations for the data e.g.:
test Short64VectorTests.andShort64VectorTests(short[i * 5], short[i + 1], mask[i % 2]): success
test Short64VectorTests.andShort64VectorTests(short[i * 5], short[i + 1], mask[true]): success
test Short64VectorTests.andShort64VectorTests(short[i * 5], short[i + 1], mask[false]): success
We can easily refine how the data is provided, it’s contents, and in what combinations. The most important thing is a stable contract between the test and the data provider, so we can easily do the former.
Hth,
Paul.
> Jp
>
> -----Original Message-----
> From: panama-dev [mailto:panama-dev-bounces at openjdk.java.net] On Behalf Of Paul Sandoz
> Sent: Friday, March 9, 2018 5:12 PM
> To: panama-dev at openjdk.java.net
> Subject: [vector] tests with data providers
>
> Hi,
>
> Please review this patch to covert the vector tests to use TestNG data providers:
>
> http://cr.openjdk.java.net/~psandoz/panama/tests-with-data-providers/webrev/ <http://cr.openjdk.java.net/~psandoz/panama/tests-with-data-providers/webrev/>
>
> For now i took the simplest route placing them in the concrete tests rather than in a super class for a type shared across the shapes (in effect much in the header.template can be moved over to such a super class).
>
> Paul.
More information about the panama-dev
mailing list