EXSWHTEC-65 - Implement additional Initialization and Version tests (#2972)

- Separate hipRuntimeGetVersion and hipDeviceGetUuid tests into positive and negative tests
 - Split Unit_hipDeviceGetUuid into Unit_hipDeviceGetUuid_Positive and Unit_hipDeviceGetUuid_Negative
 - Split Unit_hipRuntimeGetVersion_NegAndValTst into Unit_hipRuntimeGetVersion_Positive and Unit_hipRuntimeGetVersion_Negative
- Modify tests to use hipDevice_t instead of integer for devices in hipDeviceGetUuid negative test
- Implement additional Initialization and Version tests
 - Expand hipDeviceComputeCapability negative test with case when device is invalid
 - Expand hipDeviceGetP2PAttribute negative test with case when src and dst devices are the same
 - Expand hipDeviceGetP2PAttribute negative test with case when device is out of bound
 - Modify hipDeviceTotalMem negative test with case when device is invalid
 - Implement Unit_hipDeviceGetPCIBusId_PartialFill test which validates partial filling the bus id into a char array
- Fix minor formatting issues and change hipDeviceGetPCIBusId partial fill test into negative
- Modify negative tests to use integer device values
- Disable hipDeviceGetPCIBusId negative test on AMD

[ROCm/hip-tests commit: d7fafa8696]
Αυτή η υποβολή περιλαμβάνεται σε:
nives-vukovic
2022-11-04 14:59:26 +01:00
υποβλήθηκε από GitHub
γονέας 47050658dc
υποβολή fcdbcd743a
10 αρχεία άλλαξαν με 119 προσθήκες και 32 διαγραφές
@@ -2,7 +2,8 @@
"DisabledTests":
[
"Unit_hipStreamPerThread_DeviceReset_1",
"Unit_hipMallocManaged_OverSubscription"
"Unit_hipMallocManaged_OverSubscription",
"Unit_hipDeviceGetPCIBusId_Negative_PartialFill"
]
}
@@ -6,6 +6,7 @@
"Unit_hipDeviceGetCacheConfig_Positive_Basic",
"Unit_hipDeviceGetCacheConfig_Positive_Threaded",
"Unit_hipGetDeviceFlags_Positive_Context",
"Unit_hipIpcCloseMemHandle_Negative_Close_In_Originating_Process"
"Unit_hipIpcCloseMemHandle_Negative_Close_In_Originating_Process",
"Unit_hipDeviceGetPCIBusId_Negative_PartialFill"
]
}
@@ -88,6 +88,7 @@
"Unit_hipStreamValue_Wait64_Blocking_NoMask_Gte",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_Eq",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_And",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_Nor"
"Unit_hipStreamValue_Wait64_Blocking_NoMask_Nor",
"Unit_hipDeviceGetPCIBusId_Negative_PartialFill"
]
}
@@ -99,6 +99,7 @@
"Unit_hipStreamValue_Wait64_Blocking_NoMask_And",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_Nor",
"Unit_hipGetDeviceFlags_Positive_Context",
"Unit_hipIpcCloseMemHandle_Negative_Close_In_Originating_Process"
"Unit_hipIpcCloseMemHandle_Negative_Close_In_Originating_Process",
"Unit_hipDeviceGetPCIBusId_Negative_PartialFill"
]
}
@@ -16,6 +16,12 @@ LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/*
Testcase Scenarios :
Unit_hipDeviceComputeCapability_ValidateVersion - Check if hipDeviceComputeCapability api returns valid Major and Minor versions
Unit_hipDeviceComputeCapability_Negative - Test unsuccessful execution of hipDeviceComputeCapability when nullptr
or invalid device is set as input parameter
*/
/*
* Conformance test for checking functionality of
@@ -24,14 +30,13 @@ THE SOFTWARE.
#include <hip_test_common.hh>
/**
* hipDeviceComputeCapability tests
* hipDeviceComputeCapability negative tests
* Scenario1: Validates if &major = nullptr returns error code
* Scenario2: Validates if &minor = nullptr returns error code
* Scenario3: Check if Major and Minor Versions are valid
* Scenario3: Validates if device is -1
* Scenario4: Validates if device is out of bounds
*/
// Scenario 1 and 2
TEST_CASE("Unit_hipDeviceComputeCapability_NegTst") {
TEST_CASE("Unit_hipDeviceComputeCapability_Negative") {
int major, minor, numDevices;
hipDevice_t device;
@@ -51,12 +56,22 @@ TEST_CASE("Unit_hipDeviceComputeCapability_NegTst") {
REQUIRE_FALSE(hipDeviceComputeCapability(&major, nullptr, device)
== hipSuccess);
}
// Scenario3
SECTION("device is -1") {
REQUIRE_FALSE(hipDeviceComputeCapability(&major, &minor, -1)
== hipSuccess);
}
// Scenario4
SECTION("device is out of bounds") {
REQUIRE_FALSE(hipDeviceComputeCapability(&major, &minor, numDevices)
== hipSuccess);
}
} else {
WARN("Test skipped as no gpu devices available");
}
}
// Scenario 3 : Check whether major and minor version value is valid.
// Scenario 5 : Check whether major and minor version value is valid.
TEST_CASE("Unit_hipDeviceComputeCapability_ValidateVersion") {
int major, minor;
hipDevice_t device;
@@ -96,7 +96,7 @@ TEST_CASE("Unit_hipDeviceGetP2PAttribute_Negative") {
hipErrorInvalidValue);
}
SECTION("Invalid device") {
SECTION("Device is -1") {
int invalidDevice = -1;
HIP_CHECK_ERROR(hipDeviceGetP2PAttribute(&value, validAttr, invalidDevice, validDstDevice),
hipErrorInvalidDevice);
@@ -104,6 +104,22 @@ TEST_CASE("Unit_hipDeviceGetP2PAttribute_Negative") {
hipErrorInvalidDevice);
}
SECTION("Device is out of bounds") {
int deviceCount = 0;
HIP_CHECK(hipGetDeviceCount(&deviceCount));
REQUIRE_FALSE(deviceCount == 0);
HIP_CHECK_ERROR(hipDeviceGetP2PAttribute(&value, validAttr, deviceCount, validDstDevice),
hipErrorInvalidDevice);
HIP_CHECK_ERROR(hipDeviceGetP2PAttribute(&value, validAttr, validSrcDevice, deviceCount),
hipErrorInvalidDevice);
}
SECTION("Source and destination devices are the same") {
HIP_CHECK_ERROR(hipDeviceGetP2PAttribute(&value, validAttr, validSrcDevice, validSrcDevice),
hipErrorInvalidDevice);
}
/* https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#env-vars */
SECTION("Hidden devices using environment variables") {
REQUIRE(hip::SpawnProc("hipDeviceGetP2PAttribute").run("") == hipSuccess);
@@ -71,6 +71,30 @@ TEST_CASE("Unit_hipDeviceGetPCIBusId_Check_PciBusID_WithAttr") {
" hipDeviceGetAttribute matched for all gpus\n");
}
TEST_CASE("Unit_hipDeviceGetPCIBusId_Negative_PartialFill") {
std::array<char, MAX_DEVICE_LENGTH> busID;
const int device = GENERATE(range(0, HipTest::getDeviceCount()));
HIP_CHECK(hipDeviceGetPCIBusId(busID.data(), busID.size(), device));
auto start = std::begin(busID);
auto end = std::end(busID);
const auto len = std::distance(start, std::find(start, end, 0));
// fill up only half of the length
const auto fillLen = len / 2;
constexpr char fillValue = 1;
std::fill(start, end, fillValue);
REQUIRE_FALSE(hipDeviceGetPCIBusId(busID.data(), fillLen, device) == hipSuccess);
const auto strEnd = start + fillLen - 1;
REQUIRE(std::all_of(start, strEnd, [](char& c) { return c != 0; }));
REQUIRE(*strEnd == 0);
REQUIRE(std::all_of(strEnd+1, end, [](char& c) { return c == fillValue; }));
}
/**
* Validates negative scenarios for hipDeviceGetPCIBusId
@@ -107,7 +131,7 @@ TEST_CASE("Unit_hipDeviceGetPCIBusId_NegTst") {
== hipSuccess);
}
// device = Non Existing Device
SECTION("device is -1") {
SECTION("device is out of bounds") {
int deviceCount = 0;
HIP_CHECK(hipGetDeviceCount(&deviceCount));
REQUIRE_FALSE(deviceCount == 0);
@@ -16,7 +16,12 @@ LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/*
Testcase Scenarios :
Unit_hipDeviceGetUuid_Positive - Check if hipDeviceGetUuid api returns valid UUID
Unit_hipDeviceGetUuid_Negative - Test unsuccessful execution of hipDeviceGetUuid when nullptr
or invalid device is set as input parameter
*/
/*
* Conformance test for checking functionality of
* hipError_t hipDeviceGetUuid(hipUUID* uuid, hipDevice_t device);
@@ -26,26 +31,40 @@ THE SOFTWARE.
#include <cstdio>
/**
* hipDeviceGetUuid tests
* hipDeviceGetUuid positive test
* Scenario1: Validates the returned UUID
* Scenario2: Validates returned error code for UUID = nullptr
* Scenario3 & 4: Validates returned error code for invalid device
*/
TEST_CASE("Unit_hipDeviceGetUuid") {
TEST_CASE("Unit_hipDeviceGetUuid_Positive") {
hipDevice_t device;
hipUUID uuid;
const int deviceId = GENERATE(range(0, HipTest::getDeviceCount()));
HIP_CHECK(hipDeviceGet(&device, deviceId));
// Scenario 1
HIP_CHECK(hipDeviceGetUuid(&uuid, device));
REQUIRE(strcmp(uuid.bytes, "") != 0);
}
/**
* hipDeviceGetUuid negative tests
* Scenario2: Validates returned error code for UUID = nullptr
* Scenario3: Validates returned error code if device is -1
* Scenario4: Validates returned error code if device is out of bounds
*/
TEST_CASE("Unit_hipDeviceGetUuid_Negative") {
int numDevices = 0;
hipDevice_t device;
hipUUID uuid;
HIP_CHECK(hipGetDeviceCount(&numDevices));
for (int i = 0; i < numDevices; i++) {
HIP_CHECK(hipDeviceGet(&device, i));
// Scenario 1
HIP_CHECK(hipDeviceGetUuid(&uuid, device));
REQUIRE_FALSE(!strcmp(uuid.bytes, ""));
if (numDevices > 0) {
HIP_CHECK(hipDeviceGet(&device, 0));
// Scenario 2
REQUIRE_FALSE(hipSuccess == hipDeviceGetUuid(nullptr, device));
// Scenario 3
REQUIRE_FALSE(hipSuccess == hipDeviceGetUuid(&uuid, -1));
// Scenario 4
REQUIRE_FALSE(hipSuccess == hipDeviceGetUuid(&uuid, numDevices));
}
// Scenario 3
REQUIRE_FALSE(hipSuccess == hipDeviceGetUuid(&uuid, -1));
// Scenario 4
REQUIRE_FALSE(hipSuccess == hipDeviceGetUuid(&uuid, numDevices));
}
@@ -35,22 +35,21 @@ TEST_CASE("Unit_hipDeviceTotalMem_NegTst") {
#if HT_NVIDIA
HIP_CHECK(hipInit(0));
#endif
size_t totMem;
// Scenario 1
SECTION("bytes is nullptr") {
HIP_CHECK_ERROR(hipDeviceTotalMem(nullptr, 0), hipErrorInvalidValue);
}
size_t totMem;
// Scenario 2
SECTION("device is -1") {
HIP_CHECK_ERROR(hipDeviceTotalMem(&totMem, -1), hipErrorInvalidDevice);
}
// Scenario 3
SECTION("pi is nullptr") {
SECTION("device is out of bounds") {
int numDevices;
HIP_CHECK(hipGetDeviceCount(&numDevices));
size_t totMem;
HIP_CHECK_ERROR(hipDeviceTotalMem(&totMem, numDevices), hipErrorInvalidDevice);
}
}
@@ -16,6 +16,11 @@ LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/*
Testcase Scenarios :
Unit_hipRuntimeGetVersion_Positive - Test simple reading of HIP runtime version with hipRuntimeGetVersion api
Unit_hipRuntimeGetVersion_Negative - Test unsuccessful execution of hipRuntimeGetVersion when nullptr is set as input parameter
*/
/*
* Conformance test for checking functionality of
@@ -26,9 +31,14 @@ THE SOFTWARE.
*/
#include <hip_test_common.hh>
TEST_CASE("Unit_hipRuntimeGetVersion_NegAndValTst") {
TEST_CASE("Unit_hipRuntimeGetVersion_Positive") {
int runtimeVersion = -1;
CHECK_FALSE(hipRuntimeGetVersion(nullptr) == hipSuccess);
HIP_CHECK(hipRuntimeGetVersion(&runtimeVersion));
CHECK_FALSE(runtimeVersion <= 0);
REQUIRE(runtimeVersion > 0);
INFO("Runtime version " << runtimeVersion);
}
TEST_CASE("Unit_hipRuntimeGetVersion_Negative") {
// If initialization is attempted with nullptr, error shall be reported
CHECK_FALSE(hipRuntimeGetVersion(nullptr) == hipSuccess);
}