[Accel-config] [PATCH v1 3/5] accel-config/test: add test_noop function to replace the test in main

Tony Zhu <tony.zhu at intel.com> Tue, 30 Nov 2021 18:51:30 +0800
Newsgroups dev.linux.lists.accel-config
Message-ID <[email protected]>
Noop opcode test doesn't need the device initialization, it is different
from other opcodes. Add test_noop to make main clean.

Signed-off-by: Tony Zhu <tony.zhu(a)intel.com>
---
 test/dsa_test.c | 55 ++++++++++++++++++++++++++++---------------------
 1 file changed, 32 insertions(+), 23 deletions(-)

diff --git a/test/dsa_test.c b/test/dsa_test.c
index 1009785..61c8ba2 100644
--- a/test/dsa_test.c
+++ b/test/dsa_test.c
@@ -100,6 +100,36 @@ static int test_batch(struct dsa_context *ctx, size_t buf_size,
 	return rc;
 }
 
+static int test_noop(struct dsa_context *ctx, int tflags)
+{
+	struct task *tsk;
+	int rc;
+
+	info("noop: tflags %#x\n", tflags);
+
+	ctx->is_batch = 0;
+
+	rc = alloc_task(ctx);
+	if (rc != DSA_STATUS_OK) {
+		err("noop: alloc task failed, rc=%d\n", rc);
+		return rc;
+	}
+
+	tsk = ctx->single_task;
+
+	rc = dsa_noop(ctx);
+	if (rc != DSA_STATUS_OK) {
+		err("noop failed stat %d\n", rc);
+		return rc;
+	}
+
+	rc = task_result_verify(tsk, 0);
+	if (rc != DSA_STATUS_OK)
+		return rc;
+
+	return rc;
+}
+
 int main(int argc, char *argv[])
 {
 	struct dsa_context *dsa;
@@ -173,32 +203,11 @@ int main(int argc, char *argv[])
 	}
 
 	switch (opcode) {
-	case DSA_OPCODE_NOOP: {
-		struct task *tsk;
-
-		info("noop: len %#lx tflags %#x\n", buf_size, tflags);
-
-		rc = alloc_task(dsa);
-		if (rc != DSA_STATUS_OK) {
-			err("noop: alloc task failed, rc=%d\n", rc);
-			goto error;
-		}
-
-		tsk = dsa->single_task;
-
-		rc = dsa_noop(dsa);
-		if (rc != DSA_STATUS_OK) {
-			err("noop failed stat %d\n", rc);
-			rc = -ENXIO;
-			break;
-		}
-
-		rc = task_result_verify(tsk, 0);
+	case DSA_OPCODE_NOOP:
+		rc = test_noop(dsa, tflags);
 		if (rc != DSA_STATUS_OK)
 			goto error;
-
 		break;
-	}
 
 	case DSA_OPCODE_BATCH:
 		if (bsize > dsa->max_batch_size || bsize < 2) {
-- 
2.27.0