[offload] add parameters to the tests#5
Conversation
42efb66 to
8955f05
Compare
311Volt
left a comment
There was a problem hiding this comment.
minor readability concerns, tests look ok to me
| #include "Fixtures.hpp" | ||
| #include "OffloadAPI.h" | ||
|
|
||
| constexpr size_t MAX_DEVICE_INFO_BYTES = 8; |
| constexpr char zeroArray[MAX_DEVICE_INFO_BYTES] = {}; | ||
|
|
||
| template <typename T> using PropertiesVec = std::vector<T>; | ||
| template <typename T> using PropertyTuple = std::tuple<size_t, T>; |
There was a problem hiding this comment.
template<typename T> struct SizedProperty {
size_t size;
T prop;
};
would be more readable & remove the need for getSize()/getProp()
|
|
||
| template <typename T> using PropertiesSet = std::set<T>; | ||
| template <typename T> | ||
| using PropertiesTypes = std::unordered_map<T, PropertyTuple<T>>; |
There was a problem hiding this comment.
all of these type aliases are fairly trivial (and their names do not carry additional semantics), so they mostly serve to hide the real type from the reader - I would remove them
There was a problem hiding this comment.
I wouldn't remove all of the aliasing, since in case of a change, it's easier to modify the content hidden behind the alias rather than replace all occurrences of the previous type. Instead, I have reduced the amount of aliasing and made selected names more generalized. Let me know if you have any remaining concerns about the naming convention or aliasing.
| OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE_WITH_PARAM( | ||
| olMemAllocAlignedTypesTest, AllocTypes, | ||
| defaultPrinterWithParam<ol_alloc_type_t>); | ||
|
|
||
| constexpr size_t DefaultAlignment = 16; | ||
| constexpr size_t TestAllocsNum = 1000; | ||
|
|
||
| TEST_P(olMemAllocAlignedTest, SuccessAllocMany) { | ||
| std::vector<void *> Allocs; | ||
| Allocs.reserve(1000); |
| DeviceInfoProp PropCapabilitiesFlags{OL_DEVICE_INFO_SINGLE_FP_CONFIG, | ||
| OL_DEVICE_INFO_HALF_FP_CONFIG, | ||
| OL_DEVICE_INFO_DOUBLE_FP_CONFIG}; | ||
| // sizeof(ol_device_fp_capability_flags_t) == sizegof(uint32_t) |
There was a problem hiding this comment.
siegof?.
maybe static assert if you need check like this
There was a problem hiding this comment.
It's not needed, I have thought that an informative reminder in a comment would be useful
c8734f1 to
b261bd6
Compare
aabb1d4 to
450a391
Compare
| @@ -38,12 +29,9 @@ TEST_P(olMemAllocTest, SuccessAllocMany) { | |||
| std::vector<void *> Allocs; | |||
| Allocs.reserve(1000); | |||
There was a problem hiding this comment.
num of allocs not extracted to constant (inconsistent with olMemAllocAlignedTypesTest)
There was a problem hiding this comment.
Good catch :) I have moved the definition of TestAllocsNum to the common header file
|
|
||
| inline constexpr size_t MAX_DEVICE_INFO_BYTES = 8; | ||
|
|
||
| constexpr char zeroArray[MAX_DEVICE_INFO_BYTES] = {}; |
| #include "Fixtures.hpp" | ||
| #include "OffloadAPI.h" | ||
|
|
||
| inline constexpr size_t MAX_DEVICE_INFO_BYTES = 8; |
There was a problem hiding this comment.
MACRO_CASE should be reserved for macros
There was a problem hiding this comment.
at least LLVM coding standards imply as much, but I can see that e.g. liboffload enumerators are all MACRO_CASE anyway sooo ¯\_(ツ)_/¯
There was a problem hiding this comment.
I see... I would leave it as it is, for the sake of liboffload spelling convention consistency.
| } | ||
|
|
||
| TEST_P(olMemAllocAlignedTest, SuccessAllocHostDifferentAlignments) { | ||
| TEST_P(olMemAllocAlignedTypesTest, SuccessAllocDifferentAlignments) { | ||
| void *Alloc = nullptr; | ||
| size_t NumAlignments = 6; |
There was a problem hiding this comment.
can be replaced with sizeof(Alignments)/sizeof(Alignments[0]) to avoid surprises in the future, or use std::array
| } | ||
|
|
||
| TEST_P(olMemAllocAlignedTest, SuccessAllocHostDifferentAlignments) { | ||
| TEST_P(olMemAllocAlignedTypesTest, SuccessAllocDifferentAlignments) { | ||
| void *Alloc = nullptr; | ||
| size_t NumAlignments = 6; | ||
| size_t Alignments[] = {8, 16, 32, 64, 128, 256}; |
There was a problem hiding this comment.
are all plugins specified to support this set of values? imo ErrorCode::UNSUPPORTED should not be a fail
There was a problem hiding this comment.
this is pre-existing, may be outside the scope of this PR
There was a problem hiding this comment.
That's a good question, but I'll leave it for another discussion
| // Moreover, it allows for modifying only one version of the fixture, without | ||
| // the need to also change the other version: either parameterized or | ||
| // unparameterized. | ||
| using OffloadDeviceTest = OffloadDeviceTestWithParam<int>; |
There was a problem hiding this comment.
maybe std::monostate or struct UnusedTestParam {}; could be used here to reduce risk of confusion? (nitpick bc it's mostly opaque to users of INSTANTIATE macros)
There was a problem hiding this comment.
I'm curious about what your vision is of how the proposed structures should be used here. It's also been a long time since I've worked with std::variant, so I would rely on your expertise. However, even if that might be a "cleaner" approach, I'm not sure whether this would add complexity to the code or whether it is just a matter of preference.
…es; Macros are also Substituted with helpers
450a391 to
9600346
Compare
Split into several commits In order to enable comparing different versions.
=== Commit love letter ===
This patch adds:
Moreover, selected existing tests are modified and parametrized in order to make the code less repetitive and more concise. Tests with up to two possible parameters are not parameterized.
Previously, the tests were already parameterized with
TestEnvironment::Device. However, this patch combinesTestEnvironment::Devicewith an additional parameter withinOffloadParam = std::tuple<TestEnvironment::Device, T>.OffloadParam<T>is handled by a new fixtureOffloadDeviceTestWithParam<T>, which provides thegetTestParam()method for the parameter extraction. Other functionalities, such as access to theHostand to theDevice, are identical to the previous version ofOffloadDeviceTest.In order to avoid code duplication, the unparameterized versions of fixtures are aliases for parameterized fixtures, with
inttype chosen arbitrarily as an ignored parameter type, for example:using OffloadDeviceTest = OffloadDeviceTestWithParam<int>;. The single mock parameter of value0is combined with the devices in the provided macros, yielding tuples of typestd::tuple<TestEnvironment::Device, int>. The hiddenintparameter is not used, but it enables users to instantiate unparameterized tests without knowledge about the implementation details. Moreover, it allows for modifying only one version of the fixture (the one being aliased), without the need to also change the other version: either parameterized or unparameterized.The following macros are added in this patch:
OFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE_WITH_PARAM(FIXTURE, VALUES, PRINTER): instantiatesFIXTUREwith parameters stored in the provided containerVALUES(a C-style array or an STL-style container) and with the given printer. The used devices do not include the host.OFFLOAD_TESTS_INSTANTIATE_HOST_DEVICE_FIXTURE_WITH_PARAM(FIXTURE, VALUES, PRINTER): similar toOFFLOAD_TESTS_INSTANTIATE_DEVICE_FIXTURE_WITH_PARAM, but includes theHostin the tested devices.OFFLOAD_TESTS_INSTANTIATE_HOST_DEVICE_FIXTURE(FIXTURE): instantiatesFIXTUREwithout additional parameters, but also includes theHostin the used devices.OFFLOAD_TESTS_INSTANTIATE_WITH_DEVICES(FIXTURE, DEVICES): instantiatesFIXTUREwith the provided devices, internally using a mock parameter. It is not intended for direct use and acts as a helper macro for the instantiation of unparameterized tests.OFFLOAD_TESTS_INSTANTIATE_WITH_DEVICES_WITH_PARAM(FIXTURE, VALUES, DEVICES, PRINTER): instantiatesFIXTUREwith the provided devices, parameters and the given printer. It is not intended for direct use and acts as a helper macro for the instantiation of parameterized tests.Since the new macros enable testing the
Hostas part of the used devices,offload/unittests/OffloadAPI/device/olGetHostInfo.cppis deleted and its tests have been moved tooffload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp.The new helper header
offload/unittests/OffloadAPI/common/Properties.hppwith its implementationoffload/unittests/OffloadAPI/common/Properties.cpp:offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp