Skip to content

Commit

Permalink
tests/liquid-crypto: add framework
Browse files Browse the repository at this point in the history
Add framework for tests.

Signed-off-by: Anoob Joseph <anoobj@marvell.com>
Change-Id: Ide7761ebae84e29e4e32bf4a2a3cabf8fcadf746
Reviewed-by: Akhil Goyal <gakhil@marvell.com>
Reviewed-on: https://sj1git1.cavium.com/c/IP/SW/dataplane/dpu-offload/+/147762
Tested-by: sa_ip-toolkits-Jenkins <sa_ip-toolkits-jenkins@marvell.com>
Reviewed-by: Jerin Jacob <jerinj@marvell.com>
  • Loading branch information
anoobj authored and jerinjacobk committed Mar 7, 2025
1 parent 5bdc69f commit f645a70
Show file tree
Hide file tree
Showing 6 changed files with 448 additions and 36 deletions.
41 changes: 6 additions & 35 deletions tests/liquid-crypto-autotest/lc_autotest.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@
#include <inttypes.h>
#include <string.h>

#include <rte_cycles.h>
#include <rte_eal.h>

#include <dao_liquid_crypto.h>

#include "lc_autotest.h"
#include "lc_test_generic.h"
#include "test.h"

int
main(int argc, char **argv)
{
uint64_t timeout, op_cookie = 0xdeadbeef;
struct dao_lc_qp_conf conf;
struct dao_lc_res res[1];
struct dao_lc_info info;
uint16_t qp_id;
uint8_t dev_id;
Expand Down Expand Up @@ -68,6 +67,9 @@ main(int argc, char **argv)
dev_id = 0;
qp_id = 0;

glb_params.dev_id = dev_id;
glb_params.qp_id = qp_id;

ret = dao_liquid_crypto_dev_create(dev_id, 1);
if (ret < 0) {
TEST_LC_ERR("Could not create liquid crypto device");
Expand All @@ -92,39 +94,8 @@ main(int argc, char **argv)
goto dev_destroy;
}

ret = dao_liquid_crypto_enqueue_op_passthrough(dev_id, qp_id, op_cookie);
if (ret < 0) {
TEST_LC_ERR("Could not enqueue passthrough operation");
goto dev_stop;
}

/* Set a timeout of 1 second. */
timeout = rte_get_timer_cycles() + rte_get_timer_hz();

TEST_LC_INFO("Enqueued passthrough operation with cookie 0x%" PRIx64, op_cookie);

do {
ret = dao_liquid_crypto_dequeue_burst(dev_id, qp_id, res, 1);
if (ret == 1) {
TEST_LC_INFO("Operation completed successfully");
break;
}

if (rte_get_timer_cycles() > timeout) {
ret = -ETIMEDOUT;
TEST_LC_ERR("Operation timed out");
goto dev_stop;
}
} while (ret == 0);

if (ret != 1) {
TEST_LC_ERR("Could not dequeue operation");
goto dev_stop;
}

ret = 0;
unit_test_suite_runner(&lc_testsuite_generic);

dev_stop:
dao_liquid_crypto_dev_stop(dev_id);

dev_destroy:
Expand Down
101 changes: 101 additions & 0 deletions tests/liquid-crypto-autotest/lc_test_generic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/* SPDX-License-Identifier: Marvell-MIT
* Copyright (c) 2025 Marvell.
*/

#include <stdlib.h>

#include <dao_liquid_crypto.h>

#include <rte_cycles.h>

#include "lc_autotest.h"
#include "lc_test_generic.h"
#include "test.h"

struct global_params glb_params;

int
testsuite_setup(void)
{
return 0;
}

void
testsuite_teardown(void)
{
}

int
ut_setup(void)
{
return 0;
}

void
ut_teardown(void)
{
}

int
op_dequeue(uint8_t dev_id, uint16_t qp_id, struct dao_lc_res *res)
{
uint64_t timeout;
int ret;

/* Set a timeout of 1 second. */
timeout = rte_get_timer_cycles() + rte_get_timer_hz();

do {
ret = dao_liquid_crypto_dequeue_burst(dev_id, qp_id, res, 1);
if (ret == 1)
break;

if (rte_get_timer_cycles() > timeout) {
TEST_LC_ERR("Operation timed out");
break;
}
} while (ret == 0);

if (ret != 1) {
TEST_LC_ERR("Could not dequeue operation");
return -1;
}

return 0;
}

static int
ut_passthrough(void)
{
uint8_t dev_id = glb_params.dev_id;
uint16_t qp_id = glb_params.qp_id;
uint64_t op_cookie = 0xdeadbeef;
struct dao_lc_res res;
int ret;

ret = dao_liquid_crypto_enqueue_op_passthrough(dev_id, qp_id, op_cookie);
if (ret < 0) {
TEST_LC_ERR("Could not enqueue passthrough operation");
return TEST_FAILED;
}

ret = op_dequeue(dev_id, qp_id, &res);
if (ret < 0) {
TEST_LC_ERR("Could not dequeue passthrough operation");
return TEST_FAILED;
}

TEST_ASSERT(res.op_cookie == op_cookie, "Invalid operation cookie");

return TEST_SUCCESS;
}

struct unit_test_suite lc_testsuite_generic = {
.suite_name = "Liquid Crypto Generic Test Suite",
.setup = testsuite_setup,
.teardown = testsuite_teardown,
.unit_test_cases = {
TEST_CASE_NAMED_ST("Passthrough Operation", ut_setup, ut_teardown, ut_passthrough),
TEST_CASES_END() /**< NULL terminate unit test array */
}
};
27 changes: 27 additions & 0 deletions tests/liquid-crypto-autotest/lc_test_generic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* SPDX-License-Identifier: Marvell-MIT
* Copyright (c) 2025 Marvell.
*/

#ifndef __LC_TEST_GENERIC__
#define __LC_TEST_GENERIC__

#include <stdint.h>

#include <dao_liquid_crypto.h>

struct global_params {
uint8_t dev_id;
uint16_t qp_id;
};

int testsuite_setup(void);
void testsuite_teardown(void);
int ut_setup(void);
void ut_teardown(void);

extern struct unit_test_suite lc_testsuite_generic;
extern struct global_params glb_params;

int op_dequeue(uint8_t dev_id, uint16_t qp_id, struct dao_lc_res *res);

#endif /* __LC_TEST_GENERIC__ */
4 changes: 3 additions & 1 deletion tests/liquid-crypto-autotest/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# Copyright (c) 2025 Marvell.

sources = files(
'lc_autotest.c'
'lc_autotest.c',
'lc_test_generic.c',
'test.c'
)

deps += ['liquid_crypto']
Loading

0 comments on commit f645a70

Please sign in to comment.