aboutsummaryrefslogtreecommitdiff
path: root/tests/run_inference_test.cpp
diff options
context:
space:
mode:
authorMikael Olsson <mikael.olsson@arm.com>2023-10-30 11:10:56 +0100
committerMikael Olsson <mikael.olsson@arm.com>2023-11-06 09:36:00 +0100
commitc081e5954cd92165b139488e76bdfef1402acee6 (patch)
tree32bc237c124e21f12287150cba040c87c8e8b7e3 /tests/run_inference_test.cpp
parent9c999fdd40c0bf2ae420f6f3bfe013dc6baa73c1 (diff)
downloadethos-u-linux-driver-stack-c081e5954cd92165b139488e76bdfef1402acee6.tar.gz
Change create network UAPI to take a user buffer
To not allow the buffer for a network instance to be changed after creation, the create network UAPI will now take the network model data as a user buffer. The content of the user buffer is copied into an internally allocated DMA buffer that cannot be accessed by the user. This breaks the current API so the Linux kernel NPU driver version and the driver library version have been given major version bumps. All the tests, documentation and other applications affected by the changes have been updated accordingly. Change-Id: I25c785d75a24794c3db632e4abe5cfbb1c7ac190 Signed-off-by: Mikael Olsson <mikael.olsson@arm.com>
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);