aboutsummaryrefslogtreecommitdiff
path: root/tests/run_inference_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/run_inference_test.cpp')
-rw-r--r--tests/run_inference_test.cpp48
1 files changed, 37 insertions, 11 deletions
diff --git a/tests/run_inference_test.cpp b/tests/run_inference_test.cpp
index 6b17ac2..512a2a0 100644
--- a/tests/run_inference_test.cpp
+++ b/tests/run_inference_test.cpp
@@ -111,10 +111,7 @@ void testNetworkInfoNotExistentIndex(const Device &device) {
void testNetworkInfoBuffer(const Device &device) {
try {
- std::shared_ptr<Buffer> buffer = std::make_shared<Buffer>(device, sizeof(networkModelData));
- std::memcpy(buffer->data(), networkModelData, sizeof(networkModelData));
- Network network(device, buffer);
-
+ Network network(device, networkModelData, sizeof(networkModelData));
TEST_ASSERT(network.getIfmDims().size() == 1);
TEST_ASSERT(network.getOfmDims().size() == 1);
} catch (std::exception &e) { throw TestFailureException("NetworkInfo buffer test: ", e.what()); }
@@ -122,11 +119,8 @@ void testNetworkInfoBuffer(const Device &device) {
void testNetworkInfoUnparsableBuffer(const Device &device) {
try {
- auto buffer = std::make_shared<Buffer>(device, sizeof(networkModelData) / 4);
- std::memcpy(buffer->data(), networkModelData + sizeof(networkModelData) / 4, sizeof(networkModelData) / 4);
-
try {
- Network network(device, buffer);
+ Network network(device, networkModelData + sizeof(networkModelData) / 4, sizeof(networkModelData) / 4);
FAIL();
} catch (Exception) {
// good, it should have thrown!
@@ -148,11 +142,41 @@ void testNetworkInvalidType(const Device &device) {
} catch (std::exception &e) { throw TestFailureException("NetworkCreate invalid type test: ", e.what()); }
}
+void testNetworkInvalidDataPtr(const Device &device) {
+ const std::string expected_error =
+ std::string("IOCTL cmd=") + std::to_string(ETHOSU_IOCTL_NETWORK_CREATE) + " failed: " + std::strerror(EINVAL);
+ struct ethosu_uapi_network_create net_req = {};
+ net_req.type = ETHOSU_UAPI_NETWORK_USER_BUFFER;
+ net_req.network.data_ptr = 0U;
+ net_req.network.size = 128U;
+ try {
+ int r = device.ioctl(ETHOSU_IOCTL_NETWORK_CREATE, &net_req);
+ FAIL();
+ } catch (Exception &e) {
+ // The call is expected to throw
+ TEST_ASSERT(expected_error.compare(e.what()) == 0);
+ } catch (std::exception &e) { throw TestFailureException("NetworkCreate invalid data ptr: ", e.what()); }
+}
+
+void testNetworkInvalidDataSize(const Device &device) {
+ const std::string expected_error =
+ std::string("IOCTL cmd=") + std::to_string(ETHOSU_IOCTL_NETWORK_CREATE) + " failed: " + std::strerror(EINVAL);
+ struct ethosu_uapi_network_create net_req = {};
+ net_req.type = ETHOSU_UAPI_NETWORK_USER_BUFFER;
+ net_req.network.data_ptr = reinterpret_cast<uintptr_t>(networkModelData);
+ net_req.network.size = 0U;
+ try {
+ int r = device.ioctl(ETHOSU_IOCTL_NETWORK_CREATE, &net_req);
+ FAIL();
+ } catch (Exception &e) {
+ // The call is expected to throw
+ TEST_ASSERT(expected_error.compare(e.what()) == 0);
+ } catch (std::exception &e) { throw TestFailureException("NetworkCreate invalid data size: ", e.what()); }
+}
+
void testRunInferenceBuffer(const Device &device) {
try {
- auto networkBuffer = std::make_shared<Buffer>(device, sizeof(networkModelData));
- std::memcpy(networkBuffer->data(), networkModelData, sizeof(networkModelData));
- auto network = std::make_shared<Network>(device, networkBuffer);
+ auto network = std::make_shared<Network>(device, networkModelData, sizeof(networkModelData));
std::vector<std::shared_ptr<Buffer>> inputBuffers;
std::vector<std::shared_ptr<Buffer>> outputBuffers;
@@ -197,6 +221,8 @@ int main() {
testCapabilties(device);
testBufferSeek(device);
testNetworkInvalidType(device);
+ testNetworkInvalidDataPtr(device);
+ testNetworkInvalidDataSize(device);
testNetworkInfoNotExistentIndex(device);
testNetworkInfoBuffer(device);
testNetworkInfoUnparsableBuffer(device);