LCOV - code coverage report
Current view: top level - spdk/test/unit/lib/idxd/idxd.c - idxd_ut.c (source / functions) Hit Total Coverage
Test: Combined Lines: 0 222 0.0 %
Date: 2024-07-15 12:34:20 Functions: 0 10 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) 2023 Intel Corporation.
       3                 :            :  *   All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "spdk_internal/cunit.h"
       7                 :            : #include "spdk_internal/mock.h"
       8                 :            : #include "spdk_internal/idxd.h"
       9                 :            : #include "common/lib/test_env.c"
      10                 :            : 
      11                 :            : #include "idxd/idxd.c"
      12                 :            : 
      13                 :            : static void
      14                 :          0 : test_idxd_validate_dif_common_params(void)
      15                 :            : {
      16                 :          0 :         struct spdk_dif_ctx dif_ctx;
      17                 :          0 :         struct spdk_dif_ctx_init_ext_opts dif_opts;
      18                 :            :         int rc;
      19                 :            : 
      20                 :          0 :         dif_opts.size = SPDK_SIZEOF(&dif_opts, dif_pi_format);
      21                 :          0 :         dif_opts.dif_pi_format = SPDK_DIF_PI_FORMAT_16;
      22                 :            : 
      23                 :            :         /* Check all supported combinations of the data block size and metadata size */
      24                 :            :         /* ## supported: data-block-size = 512, metadata = 8 */
      25                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
      26                 :            :                                DATA_BLOCK_SIZE_512 + METADATA_SIZE_8,
      27                 :            :                                METADATA_SIZE_8,
      28                 :            :                                true,
      29                 :            :                                false,
      30                 :            :                                SPDK_DIF_TYPE1,
      31                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_APPTAG_CHECK |
      32                 :            :                                SPDK_DIF_FLAGS_REFTAG_CHECK,
      33                 :            :                                0, 0, 0, 0, 0, &dif_opts);
      34                 :          0 :         CU_ASSERT(rc == 0);
      35                 :          0 :         rc = idxd_validate_dif_common_params(&dif_ctx);
      36                 :          0 :         CU_ASSERT(rc == 0);
      37                 :            : 
      38                 :            :         /* ## supported: data-block-size = 512, metadata = 16 */
      39                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
      40                 :            :                                DATA_BLOCK_SIZE_512 + METADATA_SIZE_16,
      41                 :            :                                METADATA_SIZE_16,
      42                 :            :                                true,
      43                 :            :                                false,
      44                 :            :                                SPDK_DIF_TYPE1,
      45                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_APPTAG_CHECK |
      46                 :            :                                SPDK_DIF_FLAGS_REFTAG_CHECK,
      47                 :            :                                0, 0, 0, 0, 0, &dif_opts);
      48                 :          0 :         CU_ASSERT(rc == 0);
      49                 :          0 :         rc = idxd_validate_dif_common_params(&dif_ctx);
      50                 :          0 :         CU_ASSERT(rc == 0);
      51                 :            : 
      52                 :            :         /* ## supported: data-block-size = 4096, metadata = 8 */
      53                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
      54                 :            :                                DATA_BLOCK_SIZE_4096 + METADATA_SIZE_8,
      55                 :            :                                METADATA_SIZE_8,
      56                 :            :                                true,
      57                 :            :                                false,
      58                 :            :                                SPDK_DIF_TYPE1,
      59                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_APPTAG_CHECK |
      60                 :            :                                SPDK_DIF_FLAGS_REFTAG_CHECK,
      61                 :            :                                0, 0, 0, 0, 0, &dif_opts);
      62                 :          0 :         CU_ASSERT(rc == 0);
      63                 :          0 :         rc = idxd_validate_dif_common_params(&dif_ctx);
      64                 :          0 :         CU_ASSERT(rc == 0);
      65                 :            : 
      66                 :            :         /* ## supported: data-block-size = 4096, metadata = 16 */
      67                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
      68                 :            :                                DATA_BLOCK_SIZE_4096 + METADATA_SIZE_16,
      69                 :            :                                METADATA_SIZE_16,
      70                 :            :                                true,
      71                 :            :                                false,
      72                 :            :                                SPDK_DIF_TYPE1,
      73                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_APPTAG_CHECK |
      74                 :            :                                SPDK_DIF_FLAGS_REFTAG_CHECK,
      75                 :            :                                0, 0, 0, 0, 0, &dif_opts);
      76                 :          0 :         CU_ASSERT(rc == 0);
      77                 :          0 :         rc = idxd_validate_dif_common_params(&dif_ctx);
      78                 :          0 :         CU_ASSERT(rc == 0);
      79                 :            : 
      80                 :            :         /* Check byte offset from the start of the whole data buffer */
      81                 :            :         /* ## not-supported: data_offset != 0 */
      82                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
      83                 :            :                                DATA_BLOCK_SIZE_512 + METADATA_SIZE_8,
      84                 :            :                                METADATA_SIZE_8,
      85                 :            :                                true,
      86                 :            :                                false,
      87                 :            :                                SPDK_DIF_TYPE1,
      88                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_APPTAG_CHECK |
      89                 :            :                                SPDK_DIF_FLAGS_REFTAG_CHECK,
      90                 :            :                                0, 0, 0, 10, 0, &dif_opts);
      91                 :          0 :         CU_ASSERT(rc == 0);
      92                 :          0 :         rc = idxd_validate_dif_common_params(&dif_ctx);
      93                 :          0 :         CU_ASSERT(rc == -EINVAL);
      94                 :            : 
      95                 :            :         /* Check seed value for guard computation */
      96                 :            :         /* ## not-supported: guard_seed != 0 */
      97                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
      98                 :            :                                DATA_BLOCK_SIZE_512 + METADATA_SIZE_8,
      99                 :            :                                METADATA_SIZE_8,
     100                 :            :                                true,
     101                 :            :                                false,
     102                 :            :                                SPDK_DIF_TYPE1,
     103                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_APPTAG_CHECK |
     104                 :            :                                SPDK_DIF_FLAGS_REFTAG_CHECK,
     105                 :            :                                0, 0, 0, 0, 10, &dif_opts);
     106                 :          0 :         CU_ASSERT(rc == 0);
     107                 :          0 :         rc = idxd_validate_dif_common_params(&dif_ctx);
     108                 :          0 :         CU_ASSERT(rc == -EINVAL);
     109                 :            : 
     110                 :            :         /* Check for supported metadata sizes */
     111                 :            :         /* ## not-supported: md_size != 8 or md_size != 16 */
     112                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     113                 :            :                                DATA_BLOCK_SIZE_4096 + 32,
     114                 :            :                                32,
     115                 :            :                                true,
     116                 :            :                                false,
     117                 :            :                                SPDK_DIF_TYPE1,
     118                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_APPTAG_CHECK |
     119                 :            :                                SPDK_DIF_FLAGS_REFTAG_CHECK,
     120                 :            :                                0, 0, 0, 0, 0, &dif_opts);
     121                 :          0 :         CU_ASSERT(rc == 0);
     122                 :          0 :         rc = idxd_validate_dif_common_params(&dif_ctx);
     123                 :          0 :         CU_ASSERT(rc == -EINVAL);
     124                 :            : 
     125                 :            :         /* Check for supported metadata locations */
     126                 :            :         /* ## not-supported: md_interleave == false (separated metadata location) */
     127                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     128                 :            :                                DATA_BLOCK_SIZE_4096,
     129                 :            :                                METADATA_SIZE_16,
     130                 :            :                                false,
     131                 :            :                                false,
     132                 :            :                                SPDK_DIF_TYPE1,
     133                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_APPTAG_CHECK |
     134                 :            :                                SPDK_DIF_FLAGS_REFTAG_CHECK,
     135                 :            :                                0, 0, 0, 0, 0, &dif_opts);
     136                 :          0 :         CU_ASSERT(rc == 0);
     137                 :          0 :         rc = idxd_validate_dif_common_params(&dif_ctx);
     138                 :          0 :         CU_ASSERT(rc == -EINVAL);
     139                 :            : 
     140                 :            :         /* Check for supported DIF alignments */
     141                 :            :         /* ## not-supported: dif_loc == true (DIF left alignment) */
     142                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     143                 :            :                                DATA_BLOCK_SIZE_4096 + METADATA_SIZE_16,
     144                 :            :                                METADATA_SIZE_16,
     145                 :            :                                true,
     146                 :            :                                true,
     147                 :            :                                SPDK_DIF_TYPE1,
     148                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_APPTAG_CHECK |
     149                 :            :                                SPDK_DIF_FLAGS_REFTAG_CHECK,
     150                 :            :                                0, 0, 0, 0, 0, &dif_opts);
     151                 :          0 :         CU_ASSERT(rc == 0);
     152                 :          0 :         rc = idxd_validate_dif_common_params(&dif_ctx);
     153                 :          0 :         CU_ASSERT(rc == -EINVAL);
     154                 :            : 
     155                 :            :         /* Check for supported DIF block sizes */
     156                 :            :         /* ## not-supported: data block_size != 512,520,4096,4104 */
     157                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     158                 :            :                                DATA_BLOCK_SIZE_512 + 10,
     159                 :            :                                METADATA_SIZE_8,
     160                 :            :                                true,
     161                 :            :                                false,
     162                 :            :                                SPDK_DIF_TYPE1,
     163                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_APPTAG_CHECK |
     164                 :            :                                SPDK_DIF_FLAGS_REFTAG_CHECK,
     165                 :            :                                0, 0, 0, 0, 0, &dif_opts);
     166                 :          0 :         CU_ASSERT(rc == 0);
     167                 :          0 :         rc = idxd_validate_dif_common_params(&dif_ctx);
     168                 :          0 :         CU_ASSERT(rc == -EINVAL);
     169                 :            : 
     170                 :            :         /* Check for supported DIF PI formats */
     171                 :            :         /* ## not-supported: DIF PI format == 32 */
     172                 :          0 :         dif_opts.dif_pi_format = SPDK_DIF_PI_FORMAT_32;
     173                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     174                 :            :                                DATA_BLOCK_SIZE_4096 + METADATA_SIZE_16,
     175                 :            :                                METADATA_SIZE_16,
     176                 :            :                                true,
     177                 :            :                                false,
     178                 :            :                                SPDK_DIF_TYPE1,
     179                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_APPTAG_CHECK |
     180                 :            :                                SPDK_DIF_FLAGS_REFTAG_CHECK,
     181                 :            :                                0, 0, 0, 0, 0, &dif_opts);
     182                 :          0 :         CU_ASSERT(rc == 0);
     183                 :          0 :         rc = idxd_validate_dif_common_params(&dif_ctx);
     184                 :          0 :         CU_ASSERT(rc == -EINVAL);
     185                 :            : 
     186                 :            :         /* ## not-supported: DIF PI format == 64 */
     187                 :          0 :         dif_opts.dif_pi_format = SPDK_DIF_PI_FORMAT_64;
     188                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     189                 :            :                                DATA_BLOCK_SIZE_4096 + METADATA_SIZE_16,
     190                 :            :                                METADATA_SIZE_16,
     191                 :            :                                true,
     192                 :            :                                false,
     193                 :            :                                SPDK_DIF_TYPE1,
     194                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_APPTAG_CHECK |
     195                 :            :                                SPDK_DIF_FLAGS_REFTAG_CHECK,
     196                 :            :                                0, 0, 0, 0, 0, &dif_opts);
     197                 :          0 :         CU_ASSERT(rc == 0);
     198                 :          0 :         rc = idxd_validate_dif_common_params(&dif_ctx);
     199                 :          0 :         CU_ASSERT(rc == -EINVAL);
     200                 :          0 : }
     201                 :            : 
     202                 :            : static void
     203                 :          0 : test_idxd_validate_dif_check_params(void)
     204                 :            : {
     205                 :          0 :         struct spdk_dif_ctx dif_ctx;
     206                 :          0 :         struct spdk_dif_ctx_init_ext_opts dif_opts;
     207                 :            :         int rc;
     208                 :            : 
     209                 :          0 :         dif_opts.size = SPDK_SIZEOF(&dif_opts, dif_pi_format);
     210                 :          0 :         dif_opts.dif_pi_format = SPDK_DIF_PI_FORMAT_16;
     211                 :            : 
     212                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     213                 :            :                                DATA_BLOCK_SIZE_512 + METADATA_SIZE_8,
     214                 :            :                                METADATA_SIZE_8,
     215                 :            :                                true,
     216                 :            :                                false,
     217                 :            :                                SPDK_DIF_TYPE1,
     218                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_REFTAG_CHECK,
     219                 :            :                                0, 0, 0, 0, 0, &dif_opts);
     220                 :          0 :         CU_ASSERT(rc == 0);
     221                 :            : 
     222                 :          0 :         rc = idxd_validate_dif_check_params(&dif_ctx);
     223                 :          0 :         CU_ASSERT(rc == 0);
     224                 :          0 : }
     225                 :            : 
     226                 :            : static void
     227                 :          0 : test_idxd_validate_dif_insert_params(void)
     228                 :            : {
     229                 :          0 :         struct spdk_dif_ctx dif_ctx;
     230                 :          0 :         struct spdk_dif_ctx_init_ext_opts dif_opts;
     231                 :            :         int rc;
     232                 :            : 
     233                 :          0 :         dif_opts.size = SPDK_SIZEOF(&dif_opts, dif_pi_format);
     234                 :          0 :         dif_opts.dif_pi_format = SPDK_DIF_PI_FORMAT_16;
     235                 :            : 
     236                 :            :         /* Check for required DIF flags */
     237                 :            :         /* ## supported: Guard, ApplicationTag, ReferenceTag check flags set */
     238                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     239                 :            :                                512 + 8,
     240                 :            :                                8,
     241                 :            :                                true,
     242                 :            :                                false,
     243                 :            :                                SPDK_DIF_TYPE1,
     244                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_APPTAG_CHECK |
     245                 :            :                                SPDK_DIF_FLAGS_REFTAG_CHECK,
     246                 :            :                                0, 0, 0, 0, 0, &dif_opts);
     247                 :          0 :         CU_ASSERT(rc == 0);
     248                 :          0 :         rc = idxd_validate_dif_insert_params(&dif_ctx);
     249                 :          0 :         CU_ASSERT(rc == 0);
     250                 :            : 
     251                 :            :         /* ## not-supported: Guard check flag not set */
     252                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     253                 :            :                                512 + 8,
     254                 :            :                                8,
     255                 :            :                                true,
     256                 :            :                                false,
     257                 :            :                                SPDK_DIF_TYPE1,
     258                 :            :                                SPDK_DIF_FLAGS_APPTAG_CHECK | SPDK_DIF_FLAGS_REFTAG_CHECK,
     259                 :            :                                0, 0, 0, 0, 0, &dif_opts);
     260                 :          0 :         CU_ASSERT(rc == 0);
     261                 :          0 :         rc = idxd_validate_dif_insert_params(&dif_ctx);
     262                 :          0 :         CU_ASSERT(rc == -EINVAL);
     263                 :            : 
     264                 :            :         /* ## not-supported: Application Tag check flag not set */
     265                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     266                 :            :                                512 + 8,
     267                 :            :                                8,
     268                 :            :                                true,
     269                 :            :                                false,
     270                 :            :                                SPDK_DIF_TYPE1,
     271                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_REFTAG_CHECK,
     272                 :            :                                0, 0, 0, 0, 0, &dif_opts);
     273                 :          0 :         CU_ASSERT(rc == 0);
     274                 :          0 :         rc = idxd_validate_dif_insert_params(&dif_ctx);
     275                 :          0 :         CU_ASSERT(rc == -EINVAL);
     276                 :            : 
     277                 :            :         /* ## not-supported: Reference Tag check flag not set */
     278                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     279                 :            :                                512 + 8,
     280                 :            :                                8,
     281                 :            :                                true,
     282                 :            :                                false,
     283                 :            :                                SPDK_DIF_TYPE1,
     284                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_APPTAG_CHECK,
     285                 :            :                                0, 0, 0, 0, 0, &dif_opts);
     286                 :          0 :         CU_ASSERT(rc == 0);
     287                 :          0 :         rc = idxd_validate_dif_insert_params(&dif_ctx);
     288                 :          0 :         CU_ASSERT(rc == -EINVAL);
     289                 :          0 : }
     290                 :            : 
     291                 :            : static void
     292                 :          0 : test_idxd_validate_dif_check_buf_align(void)
     293                 :            : {
     294                 :          0 :         struct spdk_dif_ctx dif_ctx;
     295                 :          0 :         struct spdk_dif_ctx_init_ext_opts dif_opts;
     296                 :            :         int rc;
     297                 :            : 
     298                 :          0 :         dif_opts.size = SPDK_SIZEOF(&dif_opts, dif_pi_format);
     299                 :          0 :         dif_opts.dif_pi_format = SPDK_DIF_PI_FORMAT_16;
     300                 :            : 
     301                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     302                 :            :                                DATA_BLOCK_SIZE_512 + METADATA_SIZE_8,
     303                 :            :                                METADATA_SIZE_8,
     304                 :            :                                true,
     305                 :            :                                false,
     306                 :            :                                SPDK_DIF_TYPE1,
     307                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_APPTAG_CHECK |
     308                 :            :                                SPDK_DIF_FLAGS_REFTAG_CHECK,
     309                 :            :                                0, 0, 0, 0, 0, &dif_opts);
     310                 :          0 :         CU_ASSERT(rc == 0);
     311                 :            : 
     312                 :          0 :         rc = idxd_validate_dif_check_buf_align(&dif_ctx, 4 * (512 + 8));
     313                 :          0 :         CU_ASSERT(rc == 0);
     314                 :            : 
     315                 :            :         /* The memory buffer length is not a multiple of block size */
     316                 :          0 :         rc = idxd_validate_dif_check_buf_align(&dif_ctx, 4 * (512 + 8) + 10);
     317                 :          0 :         CU_ASSERT(rc == -EINVAL);
     318                 :          0 : }
     319                 :            : 
     320                 :            : static void
     321                 :          0 : test_idxd_validate_dif_insert_buf_align(void)
     322                 :            : {
     323                 :          0 :         struct spdk_dif_ctx dif_ctx;
     324                 :          0 :         struct spdk_dif_ctx_init_ext_opts dif_opts;
     325                 :            :         int rc;
     326                 :            : 
     327                 :          0 :         dif_opts.size = SPDK_SIZEOF(&dif_opts, dif_pi_format);
     328                 :          0 :         dif_opts.dif_pi_format = SPDK_DIF_PI_FORMAT_16;
     329                 :            : 
     330                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     331                 :            :                                512 + 8,
     332                 :            :                                8,
     333                 :            :                                true,
     334                 :            :                                false,
     335                 :            :                                SPDK_DIF_TYPE1,
     336                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_APPTAG_CHECK |
     337                 :            :                                SPDK_DIF_FLAGS_REFTAG_CHECK,
     338                 :            :                                0, 0, 0, 0, 0, &dif_opts);
     339                 :          0 :         CU_ASSERT(rc == 0);
     340                 :            : 
     341                 :            :         /* The memory source and destination buffer length set correctly */
     342                 :          0 :         rc = idxd_validate_dif_insert_buf_align(&dif_ctx, 4 * 512, 4 * 520);
     343                 :          0 :         CU_ASSERT(rc == 0);
     344                 :            : 
     345                 :            :         /* The memory source buffer length is not a multiple of data block size */
     346                 :          0 :         rc = idxd_validate_dif_insert_buf_align(&dif_ctx, 4 * 512 + 10, 4 * 520);
     347                 :          0 :         CU_ASSERT(rc == -EINVAL);
     348                 :            : 
     349                 :            :         /* The memory destination buffer length is not a multiple of block size */
     350                 :          0 :         rc = idxd_validate_dif_insert_buf_align(&dif_ctx, 4 * 512, 4 * 520 + 10);
     351                 :          0 :         CU_ASSERT(rc == -EINVAL);
     352                 :            : 
     353                 :            :         /* The memory source and destiantion must hold the same number of blocks */
     354                 :          0 :         rc = idxd_validate_dif_insert_buf_align(&dif_ctx, 4 * 512, 5 * 520);
     355                 :          0 :         CU_ASSERT(rc == -EINVAL);
     356                 :          0 : }
     357                 :            : 
     358                 :            : static void
     359                 :          0 : test_idxd_validate_dif_strip_buf_align(void)
     360                 :            : {
     361                 :          0 :         struct spdk_dif_ctx dif_ctx;
     362                 :          0 :         struct spdk_dif_ctx_init_ext_opts dif_opts;
     363                 :            :         int rc;
     364                 :            : 
     365                 :          0 :         dif_opts.size = SPDK_SIZEOF(&dif_opts, dif_pi_format);
     366                 :          0 :         dif_opts.dif_pi_format = SPDK_DIF_PI_FORMAT_16;
     367                 :            : 
     368                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     369                 :            :                                512 + 8,
     370                 :            :                                8,
     371                 :            :                                true,
     372                 :            :                                false,
     373                 :            :                                SPDK_DIF_TYPE1,
     374                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_APPTAG_CHECK |
     375                 :            :                                SPDK_DIF_FLAGS_REFTAG_CHECK,
     376                 :            :                                0, 0, 0, 0, 0, &dif_opts);
     377                 :          0 :         CU_ASSERT(rc == 0);
     378                 :            : 
     379                 :            :         /* The memory source and destination buffer length set correctly */
     380                 :          0 :         rc = idxd_validate_dif_strip_buf_align(&dif_ctx, 4 * 520, 4 * 512);
     381                 :          0 :         CU_ASSERT(rc == 0);
     382                 :            : 
     383                 :            :         /* The memory source buffer length is not a multiple of data block size */
     384                 :          0 :         rc = idxd_validate_dif_strip_buf_align(&dif_ctx, 4 * 520 + 10, 4 * 512);
     385                 :          0 :         CU_ASSERT(rc == -EINVAL);
     386                 :            : 
     387                 :            :         /* The memory destination buffer length is not a multiple of block size */
     388                 :          0 :         rc = idxd_validate_dif_strip_buf_align(&dif_ctx, 4 * 512, 4 * 520 + 10);
     389                 :          0 :         CU_ASSERT(rc == -EINVAL);
     390                 :            : 
     391                 :            :         /* The memory source and destiantion must hold the same number of blocks */
     392                 :          0 :         rc = idxd_validate_dif_strip_buf_align(&dif_ctx, 4 * 520, 5 * 512);
     393                 :          0 :         CU_ASSERT(rc == -EINVAL);
     394                 :          0 : }
     395                 :            : 
     396                 :            : static void
     397                 :          0 : test_idxd_get_dif_flags(void)
     398                 :            : {
     399                 :          0 :         struct spdk_dif_ctx dif_ctx;
     400                 :          0 :         struct spdk_dif_ctx_init_ext_opts dif_opts;
     401                 :          0 :         uint8_t flags;
     402                 :            :         int rc;
     403                 :            : 
     404                 :          0 :         dif_opts.size = SPDK_SIZEOF(&dif_opts, dif_pi_format);
     405                 :          0 :         dif_opts.dif_pi_format = SPDK_DIF_PI_FORMAT_16;
     406                 :            : 
     407                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     408                 :            :                                DATA_BLOCK_SIZE_512 + METADATA_SIZE_8,
     409                 :            :                                METADATA_SIZE_8,
     410                 :            :                                true,
     411                 :            :                                false,
     412                 :            :                                SPDK_DIF_TYPE1,
     413                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_APPTAG_CHECK |
     414                 :            :                                SPDK_DIF_FLAGS_REFTAG_CHECK,
     415                 :            :                                0, 0, 0, 0, 0, &dif_opts);
     416                 :          0 :         CU_ASSERT(rc == 0);
     417                 :            : 
     418                 :          0 :         rc = idxd_get_dif_flags(&dif_ctx, &flags);
     419                 :          0 :         CU_ASSERT(rc == 0);
     420                 :          0 :         CU_ASSERT(flags == IDXD_DIF_FLAG_DIF_BLOCK_SIZE_512);
     421                 :            : 
     422                 :          0 :         dif_ctx.guard_interval = 100;
     423                 :          0 :         rc = idxd_get_dif_flags(&dif_ctx, &flags);
     424                 :          0 :         CU_ASSERT(rc == -EINVAL);
     425                 :            : 
     426                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     427                 :            :                                DATA_BLOCK_SIZE_520 + METADATA_SIZE_8,
     428                 :            :                                METADATA_SIZE_8,
     429                 :            :                                true,
     430                 :            :                                false,
     431                 :            :                                SPDK_DIF_TYPE1,
     432                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_APPTAG_CHECK |
     433                 :            :                                SPDK_DIF_FLAGS_REFTAG_CHECK,
     434                 :            :                                0, 0, 0, 0, 0, &dif_opts);
     435                 :          0 :         CU_ASSERT(rc == 0);
     436                 :            : 
     437                 :          0 :         rc = idxd_get_dif_flags(&dif_ctx, &flags);
     438                 :          0 :         CU_ASSERT(rc == 0);
     439                 :          0 :         CU_ASSERT(flags == IDXD_DIF_FLAG_DIF_BLOCK_SIZE_520);
     440                 :            : 
     441                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     442                 :            :                                DATA_BLOCK_SIZE_4096 + METADATA_SIZE_8,
     443                 :            :                                METADATA_SIZE_8,
     444                 :            :                                true,
     445                 :            :                                false,
     446                 :            :                                SPDK_DIF_TYPE1,
     447                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_APPTAG_CHECK |
     448                 :            :                                SPDK_DIF_FLAGS_REFTAG_CHECK,
     449                 :            :                                0, 0, 0, 0, 0, &dif_opts);
     450                 :          0 :         CU_ASSERT(rc == 0);
     451                 :            : 
     452                 :          0 :         rc = idxd_get_dif_flags(&dif_ctx, &flags);
     453                 :          0 :         CU_ASSERT(rc == 0);
     454                 :          0 :         CU_ASSERT(flags == IDXD_DIF_FLAG_DIF_BLOCK_SIZE_4096);
     455                 :            : 
     456                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     457                 :            :                                DATA_BLOCK_SIZE_4104 + METADATA_SIZE_8,
     458                 :            :                                METADATA_SIZE_8,
     459                 :            :                                true,
     460                 :            :                                false,
     461                 :            :                                SPDK_DIF_TYPE1,
     462                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_APPTAG_CHECK |
     463                 :            :                                SPDK_DIF_FLAGS_REFTAG_CHECK,
     464                 :            :                                0, 0, 0, 0, 0, &dif_opts);
     465                 :          0 :         CU_ASSERT(rc == 0);
     466                 :            : 
     467                 :          0 :         rc = idxd_get_dif_flags(&dif_ctx, &flags);
     468                 :          0 :         CU_ASSERT(rc == 0);
     469                 :          0 :         CU_ASSERT(flags == IDXD_DIF_FLAG_DIF_BLOCK_SIZE_4104);
     470                 :          0 : }
     471                 :            : 
     472                 :            : static void
     473                 :          0 : test_idxd_get_source_dif_flags(void)
     474                 :            : {
     475                 :          0 :         struct spdk_dif_ctx dif_ctx;
     476                 :          0 :         struct spdk_dif_ctx_init_ext_opts dif_opts;
     477                 :          0 :         uint8_t flags;
     478                 :            :         int rc;
     479                 :            : 
     480                 :          0 :         dif_opts.size = SPDK_SIZEOF(&dif_opts, dif_pi_format);
     481                 :          0 :         dif_opts.dif_pi_format = SPDK_DIF_PI_FORMAT_16;
     482                 :            : 
     483                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     484                 :            :                                DATA_BLOCK_SIZE_512 + METADATA_SIZE_8,
     485                 :            :                                METADATA_SIZE_8,
     486                 :            :                                true,
     487                 :            :                                false,
     488                 :            :                                SPDK_DIF_TYPE1,
     489                 :            :                                0,
     490                 :            :                                0, 0, 0, 0, 0, &dif_opts);
     491                 :          0 :         CU_ASSERT(rc == 0);
     492                 :            : 
     493                 :          0 :         rc = idxd_get_source_dif_flags(&dif_ctx, &flags);
     494                 :          0 :         CU_ASSERT(rc == 0);
     495                 :          0 :         CU_ASSERT(flags == (IDXD_DIF_SOURCE_FLAG_GUARD_CHECK_DISABLE |
     496                 :            :                             IDXD_DIF_SOURCE_FLAG_REF_TAG_CHECK_DISABLE |
     497                 :            :                             IDXD_DIF_SOURCE_FLAG_APP_TAG_F_DETECT));
     498                 :            : 
     499                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     500                 :            :                                DATA_BLOCK_SIZE_512 + METADATA_SIZE_8,
     501                 :            :                                METADATA_SIZE_8,
     502                 :            :                                true,
     503                 :            :                                false,
     504                 :            :                                SPDK_DIF_TYPE1,
     505                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_REFTAG_CHECK,
     506                 :            :                                0, 0, 0, 0, 0, &dif_opts);
     507                 :          0 :         CU_ASSERT(rc == 0);
     508                 :            : 
     509                 :          0 :         rc = idxd_get_source_dif_flags(&dif_ctx, &flags);
     510                 :          0 :         CU_ASSERT(rc == 0);
     511                 :          0 :         CU_ASSERT(flags == (IDXD_DIF_SOURCE_FLAG_APP_TAG_F_DETECT));
     512                 :            : 
     513                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     514                 :            :                                DATA_BLOCK_SIZE_512 + METADATA_SIZE_8,
     515                 :            :                                METADATA_SIZE_8,
     516                 :            :                                true,
     517                 :            :                                false,
     518                 :            :                                SPDK_DIF_TYPE3,
     519                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_REFTAG_CHECK,
     520                 :            :                                0, 0, 0, 0, 0, &dif_opts);
     521                 :          0 :         CU_ASSERT(rc == 0);
     522                 :            : 
     523                 :          0 :         rc = idxd_get_source_dif_flags(&dif_ctx, &flags);
     524                 :          0 :         CU_ASSERT(rc == 0);
     525                 :          0 :         CU_ASSERT(flags == (IDXD_DIF_SOURCE_FLAG_APP_AND_REF_TAG_F_DETECT));
     526                 :            : 
     527                 :          0 :         dif_ctx.dif_type = 0xF;
     528                 :          0 :         rc = idxd_get_source_dif_flags(&dif_ctx, &flags);
     529                 :          0 :         CU_ASSERT(rc == -EINVAL);
     530                 :          0 : }
     531                 :            : 
     532                 :            : static void
     533                 :          0 : test_idxd_get_app_tag_mask(void)
     534                 :            : {
     535                 :          0 :         struct spdk_dif_ctx dif_ctx;
     536                 :          0 :         struct spdk_dif_ctx_init_ext_opts dif_opts;
     537                 :          0 :         uint16_t app_tag_mask, app_tag_mask_expected;
     538                 :            :         int rc;
     539                 :            : 
     540                 :          0 :         dif_opts.size = SPDK_SIZEOF(&dif_opts, dif_pi_format);
     541                 :          0 :         dif_opts.dif_pi_format = SPDK_DIF_PI_FORMAT_16;
     542                 :            : 
     543                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     544                 :            :                                DATA_BLOCK_SIZE_512 + METADATA_SIZE_8,
     545                 :            :                                METADATA_SIZE_8,
     546                 :            :                                true,
     547                 :            :                                false,
     548                 :            :                                SPDK_DIF_TYPE1,
     549                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK,
     550                 :            :                                0, 0, 0, 0, 0, &dif_opts);
     551                 :          0 :         CU_ASSERT(rc == 0);
     552                 :            : 
     553                 :          0 :         rc = idxd_get_app_tag_mask(&dif_ctx, &app_tag_mask);
     554                 :          0 :         CU_ASSERT(rc == 0);
     555                 :          0 :         app_tag_mask_expected = 0xFFFF;
     556                 :          0 :         CU_ASSERT(app_tag_mask == app_tag_mask_expected);
     557                 :            : 
     558                 :          0 :         rc = spdk_dif_ctx_init(&dif_ctx,
     559                 :            :                                DATA_BLOCK_SIZE_512 + METADATA_SIZE_8,
     560                 :            :                                METADATA_SIZE_8,
     561                 :            :                                true,
     562                 :            :                                false,
     563                 :            :                                SPDK_DIF_TYPE1,
     564                 :            :                                SPDK_DIF_FLAGS_GUARD_CHECK | SPDK_DIF_FLAGS_APPTAG_CHECK,
     565                 :            :                                0, 10, 0, 0, 0, &dif_opts);
     566                 :          0 :         CU_ASSERT(rc == 0);
     567                 :            : 
     568                 :          0 :         rc = idxd_get_app_tag_mask(&dif_ctx, &app_tag_mask);
     569                 :          0 :         CU_ASSERT(rc == 0);
     570                 :          0 :         app_tag_mask_expected = ~dif_ctx.apptag_mask;
     571                 :          0 :         CU_ASSERT(app_tag_mask == app_tag_mask_expected);
     572                 :          0 : }
     573                 :            : 
     574                 :            : int
     575                 :          0 : main(int argc, char **argv)
     576                 :            : {
     577                 :          0 :         CU_pSuite   suite = NULL;
     578                 :            :         unsigned int    num_failures;
     579                 :            : 
     580                 :          0 :         CU_initialize_registry();
     581                 :            : 
     582                 :          0 :         suite = CU_add_suite("idxd", NULL, NULL);
     583                 :            : 
     584                 :          0 :         CU_ADD_TEST(suite, test_idxd_validate_dif_common_params);
     585                 :          0 :         CU_ADD_TEST(suite, test_idxd_validate_dif_check_params);
     586                 :          0 :         CU_ADD_TEST(suite, test_idxd_validate_dif_check_buf_align);
     587                 :          0 :         CU_ADD_TEST(suite, test_idxd_validate_dif_insert_params);
     588                 :          0 :         CU_ADD_TEST(suite, test_idxd_validate_dif_insert_buf_align);
     589                 :          0 :         CU_ADD_TEST(suite, test_idxd_validate_dif_strip_buf_align);
     590                 :          0 :         CU_ADD_TEST(suite, test_idxd_get_dif_flags);
     591                 :          0 :         CU_ADD_TEST(suite, test_idxd_get_source_dif_flags);
     592                 :          0 :         CU_ADD_TEST(suite, test_idxd_get_app_tag_mask);
     593                 :            : 
     594                 :          0 :         num_failures = spdk_ut_run_tests(argc, argv, NULL);
     595                 :          0 :         CU_cleanup_registry();
     596                 :          0 :         return num_failures;
     597                 :            : }

Generated by: LCOV version 1.14