LCOV - code coverage report
Current view: top level - app/test-mldev - test_model_ops.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 165 0.0 %
Date: 2025-01-02 22:41:34 Functions: 0 14 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright (c) 2022 Marvell.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <unistd.h>
       6                 :            : 
       7                 :            : #include <rte_common.h>
       8                 :            : #include <rte_malloc.h>
       9                 :            : #include <rte_mldev.h>
      10                 :            : 
      11                 :            : #include "test_model_ops.h"
      12                 :            : #include "test_stats.h"
      13                 :            : 
      14                 :            : static bool
      15                 :          0 : test_model_ops_cap_check(struct ml_options *opt)
      16                 :            : {
      17                 :          0 :         if (!ml_test_cap_check(opt))
      18                 :          0 :                 return false;
      19                 :            : 
      20                 :            :         return true;
      21                 :            : }
      22                 :            : 
      23                 :            : static int
      24                 :          0 : test_model_ops_opt_check(struct ml_options *opt)
      25                 :            : {
      26                 :            :         uint32_t i;
      27                 :            :         int ret;
      28                 :            : 
      29                 :            :         /* check common opts */
      30                 :          0 :         ret = ml_test_opt_check(opt);
      31                 :          0 :         if (ret != 0)
      32                 :            :                 return ret;
      33                 :            : 
      34                 :            :         /* check for at least one model */
      35                 :          0 :         if (opt->nb_filelist == 0) {
      36                 :          0 :                 ml_err("Models list empty, need at least one model to run the test\n");
      37                 :          0 :                 return -EINVAL;
      38                 :            :         }
      39                 :            : 
      40                 :            :         /* check model file availability */
      41                 :          0 :         for (i = 0; i < opt->nb_filelist; i++) {
      42                 :          0 :                 if (access(opt->filelist[i].model, F_OK) == -1) {
      43                 :          0 :                         ml_err("Model file not available: id = %u, file = %s", i,
      44                 :            :                                opt->filelist[i].model);
      45                 :          0 :                         return -ENOENT;
      46                 :            :                 }
      47                 :            :         }
      48                 :            : 
      49                 :            :         return 0;
      50                 :            : }
      51                 :            : 
      52                 :            : static void
      53                 :          0 : test_model_ops_opt_dump(struct ml_options *opt)
      54                 :            : {
      55                 :            :         uint32_t i;
      56                 :            : 
      57                 :            :         /* dump common opts */
      58                 :          0 :         ml_test_opt_dump(opt);
      59                 :            : 
      60                 :            :         /* dump test specific opts */
      61                 :            :         ml_dump_begin("models");
      62                 :          0 :         for (i = 0; i < opt->nb_filelist; i++)
      63                 :          0 :                 ml_dump_list("model", i, opt->filelist[i].model);
      64                 :            :         ml_dump_end;
      65                 :          0 : }
      66                 :            : 
      67                 :            : static int
      68                 :          0 : test_model_ops_setup(struct ml_test *test, struct ml_options *opt)
      69                 :            : {
      70                 :            :         struct test_model_ops *t;
      71                 :            :         void *test_model_ops;
      72                 :            :         int ret = 0;
      73                 :            :         uint32_t i;
      74                 :            : 
      75                 :            :         /* allocate model ops test structure */
      76                 :          0 :         test_model_ops = rte_zmalloc_socket(test->name, sizeof(struct test_model_ops),
      77                 :            :                                             RTE_CACHE_LINE_SIZE, opt->socket_id);
      78                 :          0 :         if (test_model_ops == NULL) {
      79                 :          0 :                 ml_err("Failed to allocate memory for test_model");
      80                 :            :                 ret = -ENOMEM;
      81                 :          0 :                 goto error;
      82                 :            :         }
      83                 :          0 :         test->test_priv = test_model_ops;
      84                 :            :         t = ml_test_priv(test);
      85                 :            : 
      86                 :          0 :         t->cmn.result = ML_TEST_FAILED;
      87                 :          0 :         t->cmn.opt = opt;
      88                 :            : 
      89                 :            :         /* get device info */
      90                 :          0 :         ret = rte_ml_dev_info_get(opt->dev_id, &t->cmn.dev_info);
      91                 :          0 :         if (ret < 0) {
      92                 :          0 :                 ml_err("Failed to get device info");
      93                 :          0 :                 goto error;
      94                 :            :         }
      95                 :            : 
      96                 :            :         /* set model initial state */
      97                 :          0 :         for (i = 0; i < opt->nb_filelist; i++)
      98                 :          0 :                 t->model[i].state = MODEL_INITIAL;
      99                 :            : 
     100                 :            :         return 0;
     101                 :            : 
     102                 :          0 : error:
     103                 :          0 :         rte_free(test_model_ops);
     104                 :            : 
     105                 :          0 :         return ret;
     106                 :            : }
     107                 :            : 
     108                 :            : static void
     109                 :          0 : test_model_ops_destroy(struct ml_test *test, struct ml_options *opt)
     110                 :            : {
     111                 :            :         struct test_model_ops *t;
     112                 :            : 
     113                 :            :         RTE_SET_USED(opt);
     114                 :            : 
     115                 :            :         t = ml_test_priv(test);
     116                 :          0 :         rte_free(t);
     117                 :          0 : }
     118                 :            : 
     119                 :            : static int
     120                 :          0 : test_model_ops_mldev_setup(struct ml_test *test, struct ml_options *opt)
     121                 :            : {
     122                 :            :         int ret;
     123                 :            : 
     124                 :          0 :         ret = ml_test_device_configure(test, opt);
     125                 :          0 :         if (ret != 0)
     126                 :            :                 return ret;
     127                 :            : 
     128                 :          0 :         ret = ml_test_device_start(test, opt);
     129                 :          0 :         if (ret != 0)
     130                 :          0 :                 goto error;
     131                 :            : 
     132                 :            :         return 0;
     133                 :            : 
     134                 :            : error:
     135                 :          0 :         ml_test_device_close(test, opt);
     136                 :            : 
     137                 :          0 :         return ret;
     138                 :            : }
     139                 :            : 
     140                 :            : static int
     141                 :          0 : test_model_ops_mldev_destroy(struct ml_test *test, struct ml_options *opt)
     142                 :            : {
     143                 :            :         int ret;
     144                 :            : 
     145                 :          0 :         ret = ml_test_device_stop(test, opt);
     146                 :          0 :         if (ret != 0)
     147                 :          0 :                 goto error;
     148                 :            : 
     149                 :          0 :         ret = ml_test_device_close(test, opt);
     150                 :          0 :         if (ret != 0)
     151                 :          0 :                 return ret;
     152                 :            : 
     153                 :            :         return 0;
     154                 :            : 
     155                 :            : error:
     156                 :          0 :         ml_test_device_close(test, opt);
     157                 :            : 
     158                 :          0 :         return ret;
     159                 :            : }
     160                 :            : 
     161                 :            : /* Sub-test A: (load -> start -> stop -> unload) x n */
     162                 :            : static int
     163                 :          0 : test_model_ops_subtest_a(struct ml_test *test, struct ml_options *opt)
     164                 :            : {
     165                 :            :         struct test_model_ops *t;
     166                 :            :         int ret = 0;
     167                 :            :         uint32_t i;
     168                 :            : 
     169                 :            :         t = ml_test_priv(test);
     170                 :            : 
     171                 :            :         /* load + start + stop + unload */
     172                 :          0 :         for (i = 0; i < opt->nb_filelist; i++) {
     173                 :          0 :                 ret = ml_model_load(test, opt, &t->model[i], i);
     174                 :          0 :                 if (ret != 0)
     175                 :          0 :                         goto error;
     176                 :            : 
     177                 :          0 :                 ret = ml_model_start(test, opt, &t->model[i], i);
     178                 :          0 :                 if (ret != 0)
     179                 :          0 :                         goto error;
     180                 :            : 
     181                 :          0 :                 ret = ml_model_stop(test, opt, &t->model[i], i);
     182                 :          0 :                 if (ret != 0)
     183                 :          0 :                         goto error;
     184                 :            : 
     185                 :          0 :                 ret = ml_model_unload(test, opt, &t->model[i], i);
     186                 :          0 :                 if (ret != 0)
     187                 :          0 :                         goto error;
     188                 :            :         }
     189                 :            : 
     190                 :          0 : error:
     191                 :          0 :         for (i = 0; i < opt->nb_filelist; i++)
     192                 :          0 :                 ml_model_stop(test, opt, &t->model[i], i);
     193                 :            : 
     194                 :          0 :         for (i = 0; i < opt->nb_filelist; i++)
     195                 :          0 :                 ml_model_unload(test, opt, &t->model[i], i);
     196                 :            : 
     197                 :          0 :         return ret;
     198                 :            : }
     199                 :            : 
     200                 :            : /* Sub-test B: load x n -> start x n -> stop x n -> unload x n */
     201                 :            : static int
     202                 :          0 : test_model_ops_subtest_b(struct ml_test *test, struct ml_options *opt)
     203                 :            : {
     204                 :            :         struct test_model_ops *t;
     205                 :            :         int ret = 0;
     206                 :            :         uint32_t i;
     207                 :            : 
     208                 :            :         t = ml_test_priv(test);
     209                 :            : 
     210                 :            :         /* load */
     211                 :          0 :         for (i = 0; i < opt->nb_filelist; i++) {
     212                 :          0 :                 ret = ml_model_load(test, opt, &t->model[i], i);
     213                 :          0 :                 if (ret != 0)
     214                 :          0 :                         goto error;
     215                 :            :         }
     216                 :            : 
     217                 :            :         /* start */
     218                 :          0 :         for (i = 0; i < opt->nb_filelist; i++) {
     219                 :          0 :                 ret = ml_model_start(test, opt, &t->model[i], i);
     220                 :          0 :                 if (ret != 0)
     221                 :          0 :                         goto error;
     222                 :            :         }
     223                 :            : 
     224                 :            :         /* stop */
     225                 :          0 :         for (i = 0; i < opt->nb_filelist; i++) {
     226                 :          0 :                 ret = ml_model_stop(test, opt, &t->model[i], i);
     227                 :          0 :                 if (ret != 0)
     228                 :          0 :                         goto error;
     229                 :            :         }
     230                 :            : 
     231                 :            :         /* unload */
     232                 :          0 :         for (i = 0; i < opt->nb_filelist; i++) {
     233                 :          0 :                 ret = ml_model_unload(test, opt, &t->model[i], i);
     234                 :          0 :                 if (ret != 0)
     235                 :          0 :                         goto error;
     236                 :            :         }
     237                 :            : 
     238                 :            :         return 0;
     239                 :            : 
     240                 :          0 : error:
     241                 :          0 :         for (i = 0; i < opt->nb_filelist; i++)
     242                 :          0 :                 ml_model_stop(test, opt, &t->model[i], i);
     243                 :            : 
     244                 :          0 :         for (i = 0; i < opt->nb_filelist; i++)
     245                 :          0 :                 ml_model_unload(test, opt, &t->model[i], i);
     246                 :            : 
     247                 :            :         return ret;
     248                 :            : }
     249                 :            : 
     250                 :            : /* Sub-test C: load x n + (start  + stop) x n + unload x n */
     251                 :            : static int
     252                 :          0 : test_model_ops_subtest_c(struct ml_test *test, struct ml_options *opt)
     253                 :            : {
     254                 :            :         struct test_model_ops *t;
     255                 :            :         int ret = 0;
     256                 :            :         uint32_t i;
     257                 :            : 
     258                 :            :         t = ml_test_priv(test);
     259                 :            : 
     260                 :            :         /* load */
     261                 :          0 :         for (i = 0; i < opt->nb_filelist; i++) {
     262                 :          0 :                 ret = ml_model_load(test, opt, &t->model[i], i);
     263                 :          0 :                 if (ret != 0)
     264                 :          0 :                         goto error;
     265                 :            :         }
     266                 :            : 
     267                 :            :         /* start + stop */
     268                 :          0 :         for (i = 0; i < opt->nb_filelist; i++) {
     269                 :          0 :                 ret = ml_model_start(test, opt, &t->model[i], i);
     270                 :          0 :                 if (ret != 0)
     271                 :          0 :                         goto error;
     272                 :            : 
     273                 :          0 :                 ret = ml_model_stop(test, opt, &t->model[i], i);
     274                 :          0 :                 if (ret != 0)
     275                 :          0 :                         goto error;
     276                 :            :         }
     277                 :            : 
     278                 :            :         /* unload */
     279                 :          0 :         for (i = 0; i < opt->nb_filelist; i++) {
     280                 :          0 :                 ret = ml_model_unload(test, opt, &t->model[i], i);
     281                 :          0 :                 if (ret != 0)
     282                 :          0 :                         goto error;
     283                 :            :         }
     284                 :            : 
     285                 :            :         return 0;
     286                 :            : 
     287                 :          0 : error:
     288                 :          0 :         for (i = 0; i < opt->nb_filelist; i++)
     289                 :          0 :                 ml_model_stop(test, opt, &t->model[i], i);
     290                 :            : 
     291                 :          0 :         for (i = 0; i < opt->nb_filelist; i++)
     292                 :          0 :                 ml_model_unload(test, opt, &t->model[i], i);
     293                 :            : 
     294                 :            :         return ret;
     295                 :            : }
     296                 :            : 
     297                 :            : /* Sub-test D: (load + start) x n -> (stop + unload) x n */
     298                 :            : static int
     299                 :          0 : test_model_ops_subtest_d(struct ml_test *test, struct ml_options *opt)
     300                 :            : {
     301                 :            :         struct test_model_ops *t;
     302                 :            :         int ret = 0;
     303                 :            :         uint32_t i;
     304                 :            : 
     305                 :            :         t = ml_test_priv(test);
     306                 :            : 
     307                 :            :         /* load + start */
     308                 :          0 :         for (i = 0; i < opt->nb_filelist; i++) {
     309                 :          0 :                 ret = ml_model_load(test, opt, &t->model[i], i);
     310                 :          0 :                 if (ret != 0)
     311                 :          0 :                         goto error;
     312                 :            : 
     313                 :          0 :                 ret = ml_model_start(test, opt, &t->model[i], i);
     314                 :          0 :                 if (ret != 0)
     315                 :          0 :                         goto error;
     316                 :            :         }
     317                 :            : 
     318                 :            :         /* stop + unload */
     319                 :          0 :         for (i = 0; i < opt->nb_filelist; i++) {
     320                 :          0 :                 ret = ml_model_stop(test, opt, &t->model[i], i);
     321                 :          0 :                 if (ret != 0)
     322                 :          0 :                         goto error;
     323                 :            : 
     324                 :          0 :                 ret = ml_model_unload(test, opt, &t->model[i], i);
     325                 :          0 :                 if (ret != 0)
     326                 :          0 :                         goto error;
     327                 :            :         }
     328                 :            : 
     329                 :            :         return 0;
     330                 :            : 
     331                 :          0 : error:
     332                 :          0 :         for (i = 0; i < opt->nb_filelist; i++)
     333                 :          0 :                 ml_model_stop(test, opt, &t->model[i], i);
     334                 :            : 
     335                 :          0 :         for (i = 0; i < opt->nb_filelist; i++)
     336                 :          0 :                 ml_model_unload(test, opt, &t->model[i], i);
     337                 :            : 
     338                 :            :         return ret;
     339                 :            : }
     340                 :            : 
     341                 :            : static int
     342                 :          0 : test_model_ops_driver(struct ml_test *test, struct ml_options *opt)
     343                 :            : {
     344                 :            :         struct test_model_ops *t;
     345                 :            :         int ret = 0;
     346                 :            : 
     347                 :            :         t = ml_test_priv(test);
     348                 :            : 
     349                 :            :         /* device setup */
     350                 :          0 :         ret = test_model_ops_mldev_setup(test, opt);
     351                 :          0 :         if (ret != 0)
     352                 :            :                 return ret;
     353                 :            : 
     354                 :            :         printf("\n");
     355                 :            : 
     356                 :            :         /* sub-test A */
     357                 :          0 :         ret = test_model_ops_subtest_a(test, opt);
     358                 :          0 :         if (ret != 0) {
     359                 :            :                 printf("Model Ops Sub-test A: " CLRED "%s" CLNRM "\n", "Failed");
     360                 :          0 :                 goto error;
     361                 :            :         } else {
     362                 :            :                 printf("Model Ops Sub-test A: " CLYEL "%s" CLNRM "\n", "Passed");
     363                 :            :         }
     364                 :            : 
     365                 :            :         /* sub-test B */
     366                 :          0 :         ret = test_model_ops_subtest_b(test, opt);
     367                 :          0 :         if (ret != 0) {
     368                 :            :                 printf("Model Ops Sub-test B: " CLRED "%s" CLNRM "\n", "Failed");
     369                 :          0 :                 goto error;
     370                 :            :         } else {
     371                 :            :                 printf("Model Ops Sub-test B: " CLYEL "%s" CLNRM "\n", "Passed");
     372                 :            :         }
     373                 :            : 
     374                 :            :         /* sub-test C */
     375                 :          0 :         ret = test_model_ops_subtest_c(test, opt);
     376                 :          0 :         if (ret != 0) {
     377                 :            :                 printf("Model Ops Sub-test C: " CLRED "%s" CLNRM "\n", "Failed");
     378                 :          0 :                 goto error;
     379                 :            :         } else {
     380                 :            :                 printf("Model Ops Sub-test C: " CLYEL "%s" CLNRM "\n", "Passed");
     381                 :            :         }
     382                 :            : 
     383                 :            :         /* sub-test D */
     384                 :          0 :         ret = test_model_ops_subtest_d(test, opt);
     385                 :          0 :         if (ret != 0) {
     386                 :            :                 printf("Model Ops Sub-test D: " CLRED "%s" CLNRM "\n", "Failed");
     387                 :          0 :                 goto error;
     388                 :            :         } else {
     389                 :            :                 printf("Model Ops Sub-test D: " CLYEL "%s" CLNRM "\n", "Passed");
     390                 :            :         }
     391                 :            : 
     392                 :            :         printf("\n");
     393                 :            : 
     394                 :          0 :         ml_stats_get(test, opt, RTE_ML_DEV_XSTATS_DEVICE, -1);
     395                 :            : 
     396                 :            :         /* device destroy */
     397                 :          0 :         ret = test_model_ops_mldev_destroy(test, opt);
     398                 :          0 :         if (ret != 0)
     399                 :            :                 return ret;
     400                 :            : 
     401                 :          0 :         t->cmn.result = ML_TEST_SUCCESS;
     402                 :            : 
     403                 :          0 :         return 0;
     404                 :            : 
     405                 :          0 : error:
     406                 :          0 :         test_model_ops_mldev_destroy(test, opt);
     407                 :            : 
     408                 :          0 :         t->cmn.result = ML_TEST_FAILED;
     409                 :            : 
     410                 :          0 :         return ret;
     411                 :            : }
     412                 :            : 
     413                 :            : static int
     414                 :          0 : test_model_ops_result(struct ml_test *test, struct ml_options *opt)
     415                 :            : {
     416                 :            :         struct test_model_ops *t;
     417                 :            : 
     418                 :            :         RTE_SET_USED(opt);
     419                 :            : 
     420                 :            :         t = ml_test_priv(test);
     421                 :            : 
     422                 :          0 :         return t->cmn.result;
     423                 :            : }
     424                 :            : 
     425                 :            : static const struct ml_test_ops model_ops = {
     426                 :            :         .cap_check = test_model_ops_cap_check,
     427                 :            :         .opt_check = test_model_ops_opt_check,
     428                 :            :         .opt_dump = test_model_ops_opt_dump,
     429                 :            :         .test_setup = test_model_ops_setup,
     430                 :            :         .test_destroy = test_model_ops_destroy,
     431                 :            :         .test_driver = test_model_ops_driver,
     432                 :            :         .test_result = test_model_ops_result,
     433                 :            : };
     434                 :            : 
     435                 :          0 : ML_TEST_REGISTER(model_ops);

Generated by: LCOV version 1.14