LCOV - code coverage report
Current view: top level - app/test - test_interrupts.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 141 199 70.9 %
Date: 2026-11-01 19:11:22 Functions: 10 11 90.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 75 150 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2010-2014 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #define ALLOW_INTERNAL_API
       6                 :            : 
       7                 :            : #include <stdio.h>
       8                 :            : #include <stdint.h>
       9                 :            : #include <unistd.h>
      10                 :            : 
      11                 :            : #include <rte_common.h>
      12                 :            : #include <rte_cycles.h>
      13                 :            : #include <rte_interrupts.h>
      14                 :            : 
      15                 :            : #include "test.h"
      16                 :            : 
      17                 :            : #define TEST_INTERRUPT_CHECK_INTERVAL 100 /* ms */
      18                 :            : 
      19                 :            : /* predefined interrupt handle types */
      20                 :            : enum test_interrupt_handle_type {
      21                 :            :         TEST_INTERRUPT_HANDLE_INVALID = 0,
      22                 :            :         TEST_INTERRUPT_HANDLE_VALID,
      23                 :            :         TEST_INTERRUPT_HANDLE_VALID_UIO,
      24                 :            :         TEST_INTERRUPT_HANDLE_VALID_ALARM,
      25                 :            :         TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT,
      26                 :            :         TEST_INTERRUPT_HANDLE_CASE1,
      27                 :            :         TEST_INTERRUPT_HANDLE_MAX
      28                 :            : };
      29                 :            : 
      30                 :            : /* flag of if callback is called */
      31                 :            : static volatile int flag;
      32                 :            : static struct rte_intr_handle *intr_handles[TEST_INTERRUPT_HANDLE_MAX];
      33                 :            : static enum test_interrupt_handle_type test_intr_type =
      34                 :            :                                 TEST_INTERRUPT_HANDLE_MAX;
      35                 :            : 
      36                 :            : #ifdef RTE_EXEC_ENV_LINUX
      37                 :            : union intr_pipefds{
      38                 :            :         struct {
      39                 :            :                 int pipefd[2];
      40                 :            :         };
      41                 :            :         struct {
      42                 :            :                 int readfd;
      43                 :            :                 int writefd;
      44                 :            :         };
      45                 :            : };
      46                 :            : 
      47                 :            : static union intr_pipefds pfds;
      48                 :            : 
      49                 :            : /**
      50                 :            :  * Check if the interrupt handle is valid.
      51                 :            :  */
      52                 :            : static inline int
      53                 :            : test_interrupt_handle_sanity_check(struct rte_intr_handle *intr_handle)
      54                 :            : {
      55   [ -  -  +  -  :     260029 :         if (!intr_handle || rte_intr_fd_get(intr_handle) < 0)
                   +  - ]
      56                 :            :                 return -1;
      57                 :            : 
      58                 :            :         return 0;
      59                 :            : }
      60                 :            : 
      61                 :            : /**
      62                 :            :  * Initialization for interrupt test.
      63                 :            :  */
      64                 :            : static int
      65                 :          1 : test_interrupt_init(void)
      66                 :            : {
      67                 :            :         struct rte_intr_handle *test_intr_handle;
      68                 :            :         int i;
      69                 :            : 
      70         [ +  - ]:          1 :         if (pipe(pfds.pipefd) < 0)
      71                 :            :                 return -1;
      72                 :            : 
      73         [ +  + ]:          7 :         for (i = 0; i < TEST_INTERRUPT_HANDLE_MAX; i++) {
      74                 :          6 :                 intr_handles[i] =
      75                 :          6 :                         rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE);
      76         [ +  - ]:          6 :                 if (!intr_handles[i])
      77                 :            :                         return -1;
      78         [ +  - ]:          6 :                 if (rte_intr_fd_get(intr_handles[i]) != -1)
      79                 :            :                         return -1;
      80         [ +  - ]:          6 :                 if (rte_intr_dev_fd_get(intr_handles[i]) != -1)
      81                 :            :                         return -1;
      82                 :            :         }
      83                 :            : 
      84                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_INVALID];
      85         [ +  - ]:          1 :         if (rte_intr_type_set(test_intr_handle, RTE_INTR_HANDLE_UNKNOWN))
      86                 :            :                 return -1;
      87                 :            : 
      88                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID];
      89         [ +  - ]:          1 :         if (rte_intr_fd_set(test_intr_handle, pfds.readfd))
      90                 :            :                 return -1;
      91         [ +  - ]:          1 :         if (rte_intr_type_set(test_intr_handle, RTE_INTR_HANDLE_UNKNOWN))
      92                 :            :                 return -1;
      93                 :            : 
      94                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_UIO];
      95         [ +  - ]:          1 :         if (rte_intr_fd_set(test_intr_handle, pfds.readfd))
      96                 :            :                 return -1;
      97                 :            :         /* HACK: UIO type does not require a device FD, but a valid handle should contain one */
      98         [ +  - ]:          1 :         if (rte_intr_dev_fd_set(test_intr_handle, INT_MAX))
      99                 :            :                 return -1;
     100         [ +  - ]:          1 :         if (rte_intr_type_set(test_intr_handle, RTE_INTR_HANDLE_UIO))
     101                 :            :                 return -1;
     102                 :            : 
     103                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_ALARM];
     104         [ +  - ]:          1 :         if (rte_intr_fd_set(test_intr_handle, pfds.readfd))
     105                 :            :                 return -1;
     106         [ +  - ]:          1 :         if (rte_intr_type_set(test_intr_handle, RTE_INTR_HANDLE_ALARM))
     107                 :            :                 return -1;
     108                 :            : 
     109                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT];
     110         [ +  - ]:          1 :         if (rte_intr_fd_set(test_intr_handle, pfds.readfd))
     111                 :            :                 return -1;
     112         [ +  - ]:          1 :         if (rte_intr_type_set(test_intr_handle, RTE_INTR_HANDLE_DEV_EVENT))
     113                 :            :                 return -1;
     114                 :            : 
     115                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_CASE1];
     116         [ +  - ]:          1 :         if (rte_intr_fd_set(test_intr_handle, pfds.writefd))
     117                 :            :                 return -1;
     118                 :            :         /* HACK: UIO type does not require a device FD, but a valid handle should contain one */
     119         [ +  - ]:          1 :         if (rte_intr_dev_fd_set(test_intr_handle, INT_MAX))
     120                 :            :                 return -1;
     121         [ -  + ]:          1 :         if (rte_intr_type_set(test_intr_handle, RTE_INTR_HANDLE_UIO))
     122                 :          0 :                 return -1;
     123                 :            : 
     124                 :            :         return 0;
     125                 :            : }
     126                 :            : 
     127                 :            : /**
     128                 :            :  * Deinitialization for interrupt test.
     129                 :            :  */
     130                 :            : static int
     131                 :          1 : test_interrupt_deinit(void)
     132                 :            : {
     133                 :            :         int i;
     134                 :            : 
     135         [ +  + ]:          7 :         for (i = 0; i < TEST_INTERRUPT_HANDLE_MAX; i++) {
     136                 :          6 :                 rte_intr_fd_set(intr_handles[i], -1);
     137                 :          6 :                 rte_intr_dev_fd_set(intr_handles[i], -1);
     138                 :          6 :                 rte_intr_instance_free(intr_handles[i]);
     139                 :            :         }
     140                 :          1 :         close(pfds.pipefd[0]);
     141                 :          1 :         close(pfds.pipefd[1]);
     142                 :            : 
     143                 :          1 :         return 0;
     144                 :            : }
     145                 :            : 
     146                 :            : /**
     147                 :            :  * Write the pipe to simulate an interrupt.
     148                 :            :  */
     149                 :            : static int
     150                 :            : test_interrupt_trigger_interrupt(void)
     151                 :            : {
     152         [ +  - ]:          4 :         if (write(pfds.writefd, "1", 1) < 0)
     153                 :            :                 return -1;
     154                 :            : 
     155                 :            :         return 0;
     156                 :            : }
     157                 :            : 
     158                 :            : /**
     159                 :            :  * Check if two interrupt handles are the same.
     160                 :            :  */
     161                 :            : static int
     162                 :     260029 : test_interrupt_handle_compare(struct rte_intr_handle *intr_handle_l,
     163                 :            :                                 struct rte_intr_handle *intr_handle_r)
     164                 :            : {
     165         [ +  - ]:     260029 :         if (!intr_handle_l || !intr_handle_r)
     166                 :            :                 return -1;
     167                 :            : 
     168         [ +  - ]:     520058 :         if (rte_intr_fd_get(intr_handle_l) !=
     169         [ -  + ]:     520058 :             rte_intr_fd_get(intr_handle_r) ||
     170                 :     260029 :                 rte_intr_type_get(intr_handle_l) !=
     171                 :     260029 :                 rte_intr_type_get(intr_handle_r))
     172                 :          0 :                 return -1;
     173                 :            : 
     174                 :            :         return 0;
     175                 :            : }
     176                 :            : 
     177                 :            : /**
     178                 :            :  * Tests for rte_intr_fd_close() and rte_intr_dev_fd_close().
     179                 :            :  */
     180                 :            : static int
     181                 :          1 : test_interrupt_close(void)
     182                 :            : {
     183                 :            :         struct rte_intr_handle *intr_handle;
     184                 :            :         int pipefd[2];
     185                 :            : 
     186                 :            :         /* check with null intr_handle */
     187                 :          1 :         rte_intr_fd_close(NULL);
     188                 :          1 :         rte_intr_dev_fd_close(NULL);
     189                 :            : 
     190                 :          1 :         intr_handle = rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_PRIVATE);
     191         [ +  - ]:          1 :         if (!intr_handle)
     192                 :            :                 return -1;
     193                 :            : 
     194         [ -  + ]:          1 :         if (pipe(pipefd) < 0) {
     195                 :          0 :                 rte_intr_instance_free(intr_handle);
     196                 :          0 :                 return -1;
     197                 :            :         }
     198                 :            : 
     199   [ +  -  -  + ]:          2 :         if (rte_intr_fd_set(intr_handle, pipefd[0]) < 0 ||
     200                 :          1 :                         rte_intr_dev_fd_set(intr_handle, pipefd[1]) < 0) {
     201                 :          0 :                 close(pipefd[0]);
     202                 :          0 :                 close(pipefd[1]);
     203                 :          0 :                 rte_intr_instance_free(intr_handle);
     204                 :          0 :                 return -1;
     205                 :            :         }
     206                 :            : 
     207                 :            :         /* check rte_intr_fd_close */
     208                 :          1 :         rte_intr_fd_close(intr_handle);
     209                 :            : 
     210         [ -  + ]:          1 :         if (rte_intr_fd_get(intr_handle) != -1) {
     211                 :            :                 printf("fd not set to -1 after close\n");
     212                 :          0 :                 close(pipefd[1]);
     213                 :          0 :                 rte_intr_instance_free(intr_handle);
     214                 :          0 :                 return -1;
     215                 :            :         }
     216                 :            : 
     217                 :            :         /* calling again should be a noop */
     218                 :          1 :         rte_intr_fd_close(intr_handle);
     219                 :            : 
     220                 :            :         /* check rte_intr_dev_fd_close */
     221                 :          1 :         rte_intr_dev_fd_close(intr_handle);
     222                 :            : 
     223         [ -  + ]:          1 :         if (rte_intr_dev_fd_get(intr_handle) != -1) {
     224                 :            :                 printf("dev_fd not set to -1 after close\n");
     225                 :          0 :                 rte_intr_instance_free(intr_handle);
     226                 :          0 :                 return -1;
     227                 :            :         }
     228                 :            : 
     229                 :            :         /* calling again should be a noop */
     230                 :          1 :         rte_intr_dev_fd_close(intr_handle);
     231                 :            : 
     232                 :          1 :         rte_intr_instance_free(intr_handle);
     233                 :          1 :         return 0;
     234                 :            : }
     235                 :            : 
     236                 :            : #else
     237                 :            : /* to be implemented for bsd later */
     238                 :            : static inline int
     239                 :            : test_interrupt_handle_sanity_check(struct rte_intr_handle *intr_handle)
     240                 :            : {
     241                 :            :         RTE_SET_USED(intr_handle);
     242                 :            : 
     243                 :            :         return 0;
     244                 :            : }
     245                 :            : 
     246                 :            : static int
     247                 :            : test_interrupt_init(void)
     248                 :            : {
     249                 :            :         return 0;
     250                 :            : }
     251                 :            : 
     252                 :            : static int
     253                 :            : test_interrupt_deinit(void)
     254                 :            : {
     255                 :            :         return 0;
     256                 :            : }
     257                 :            : 
     258                 :            : static int
     259                 :            : test_interrupt_trigger_interrupt(void)
     260                 :            : {
     261                 :            :         return 0;
     262                 :            : }
     263                 :            : 
     264                 :            : static int
     265                 :            : test_interrupt_handle_compare(struct rte_intr_handle *intr_handle_l,
     266                 :            :                                 struct rte_intr_handle *intr_handle_r)
     267                 :            : {
     268                 :            :         (void)intr_handle_l;
     269                 :            :         (void)intr_handle_r;
     270                 :            : 
     271                 :            :         return 0;
     272                 :            : }
     273                 :            : 
     274                 :            : static int
     275                 :            : test_interrupt_close(void)
     276                 :            : {
     277                 :            :         return 0;
     278                 :            : }
     279                 :            : #endif /* RTE_EXEC_ENV_LINUX */
     280                 :            : 
     281                 :            : /**
     282                 :            :  * Callback for the test interrupt.
     283                 :            :  */
     284                 :            : static void
     285                 :     260029 : test_interrupt_callback(void *arg)
     286                 :            : {
     287                 :            :         struct rte_intr_handle *intr_handle = arg;
     288                 :            :         struct rte_intr_handle *test_intr_handle;
     289                 :            : 
     290         [ -  + ]:     260029 :         if (test_intr_type >= TEST_INTERRUPT_HANDLE_MAX) {
     291                 :            :                 printf("invalid interrupt type\n");
     292                 :          0 :                 flag = -1;
     293                 :          0 :                 return;
     294                 :            :         }
     295                 :            : 
     296                 :            :         if (test_interrupt_handle_sanity_check(intr_handle) < 0) {
     297                 :            :                 printf("null or invalid intr_handle for %s\n", __func__);
     298                 :          0 :                 flag = -1;
     299                 :          0 :                 return;
     300                 :            :         }
     301                 :            : 
     302         [ -  + ]:     260029 :         if (rte_intr_callback_unregister(intr_handle,
     303                 :            :                         test_interrupt_callback, arg) >= 0) {
     304                 :            :                 printf("%s: unexpectedly able to unregister itself\n",
     305                 :            :                         __func__);
     306                 :          0 :                 flag = -1;
     307                 :          0 :                 return;
     308                 :            :         }
     309                 :            : 
     310                 :     260029 :         test_intr_handle = intr_handles[test_intr_type];
     311         [ +  - ]:     260029 :         if (test_interrupt_handle_compare(intr_handle, test_intr_handle) == 0)
     312                 :     260029 :                 flag = 1;
     313                 :            : }
     314                 :            : 
     315                 :            : /**
     316                 :            :  * Callback for the test interrupt.
     317                 :            :  */
     318                 :            : static void
     319         [ #  # ]:          0 : test_interrupt_callback_1(void *arg)
     320                 :            : {
     321                 :            :         struct rte_intr_handle *intr_handle = arg;
     322                 :            :         if (test_interrupt_handle_sanity_check(intr_handle) < 0) {
     323                 :            :                 printf("null or invalid intr_handle for %s\n", __func__);
     324                 :          0 :                 flag = -1;
     325                 :          0 :                 return;
     326                 :            :         }
     327                 :            : }
     328                 :            : 
     329                 :            : /**
     330                 :            :  * Tests for rte_intr_enable().
     331                 :            :  */
     332                 :            : static int
     333                 :          1 : test_interrupt_enable(void)
     334                 :            : {
     335                 :            :         struct rte_intr_handle *test_intr_handle;
     336                 :            : 
     337                 :            :         /* check with null intr_handle */
     338         [ -  + ]:          1 :         if (rte_intr_enable(NULL) == 0) {
     339                 :            :                 printf("unexpectedly enable null intr_handle successfully\n");
     340                 :          0 :                 return -1;
     341                 :            :         }
     342                 :            : 
     343                 :            :         /* check with invalid intr_handle */
     344                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_INVALID];
     345         [ -  + ]:          1 :         if (rte_intr_enable(test_intr_handle) == 0) {
     346                 :            :                 printf("unexpectedly enable invalid intr_handle "
     347                 :            :                         "successfully\n");
     348                 :          0 :                 return -1;
     349                 :            :         }
     350                 :            : 
     351                 :            :         /* check with valid intr_handle */
     352                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID];
     353         [ -  + ]:          1 :         if (rte_intr_enable(test_intr_handle) == 0) {
     354                 :            :                 printf("unexpectedly enable a specific intr_handle "
     355                 :            :                         "successfully\n");
     356                 :          0 :                 return -1;
     357                 :            :         }
     358                 :            : 
     359                 :            :         /* check with specific valid intr_handle */
     360                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_ALARM];
     361         [ -  + ]:          1 :         if (rte_intr_enable(test_intr_handle) == 0) {
     362                 :            :                 printf("unexpectedly enable a specific intr_handle "
     363                 :            :                         "successfully\n");
     364                 :          0 :                 return -1;
     365                 :            :         }
     366                 :            : 
     367                 :            :         /* check with specific valid intr_handle */
     368                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT];
     369         [ -  + ]:          1 :         if (rte_intr_enable(test_intr_handle) == 0) {
     370                 :            :                 printf("unexpectedly enable a specific intr_handle "
     371                 :            :                         "successfully\n");
     372                 :          0 :                 return -1;
     373                 :            :         }
     374                 :            : 
     375                 :            :         /* check with valid handler and its type */
     376                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_CASE1];
     377         [ -  + ]:          1 :         if (rte_intr_enable(test_intr_handle) < 0) {
     378                 :            :                 printf("fail to enable interrupt on a simulated handler\n");
     379                 :          0 :                 return -1;
     380                 :            :         }
     381                 :            : 
     382                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_UIO];
     383         [ -  + ]:          1 :         if (rte_intr_enable(test_intr_handle) == 0) {
     384                 :            :                 printf("unexpectedly enable a specific intr_handle "
     385                 :            :                         "successfully\n");
     386                 :          0 :                 return -1;
     387                 :            :         }
     388                 :            : 
     389                 :            :         return 0;
     390                 :            : }
     391                 :            : 
     392                 :            : /**
     393                 :            :  * Tests for rte_intr_disable().
     394                 :            :  */
     395                 :            : static int
     396                 :          1 : test_interrupt_disable(void)
     397                 :            : {
     398                 :            :         struct rte_intr_handle *test_intr_handle;
     399                 :            : 
     400                 :            :         /* check with null intr_handle */
     401         [ -  + ]:          1 :         if (rte_intr_disable(NULL) == 0) {
     402                 :            :                 printf("unexpectedly disable null intr_handle "
     403                 :            :                         "successfully\n");
     404                 :          0 :                 return -1;
     405                 :            :         }
     406                 :            : 
     407                 :            :         /* check with invalid intr_handle */
     408                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_INVALID];
     409         [ -  + ]:          1 :         if (rte_intr_disable(test_intr_handle) == 0) {
     410                 :            :                 printf("unexpectedly disable invalid intr_handle "
     411                 :            :                         "successfully\n");
     412                 :          0 :                 return -1;
     413                 :            :         }
     414                 :            : 
     415                 :            :         /* check with valid intr_handle */
     416                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID];
     417         [ -  + ]:          1 :         if (rte_intr_disable(test_intr_handle) == 0) {
     418                 :            :                 printf("unexpectedly disable a specific intr_handle "
     419                 :            :                         "successfully\n");
     420                 :          0 :                 return -1;
     421                 :            :         }
     422                 :            : 
     423                 :            :         /* check with specific valid intr_handle */
     424                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_ALARM];
     425         [ -  + ]:          1 :         if (rte_intr_disable(test_intr_handle) == 0) {
     426                 :            :                 printf("unexpectedly disable a specific intr_handle "
     427                 :            :                         "successfully\n");
     428                 :          0 :                 return -1;
     429                 :            :         }
     430                 :            : 
     431                 :            :         /* check with specific valid intr_handle */
     432                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT];
     433         [ -  + ]:          1 :         if (rte_intr_disable(test_intr_handle) == 0) {
     434                 :            :                 printf("unexpectedly disable a specific intr_handle "
     435                 :            :                         "successfully\n");
     436                 :          0 :                 return -1;
     437                 :            :         }
     438                 :            : 
     439                 :            :         /* check with valid handler and its type */
     440                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_CASE1];
     441         [ -  + ]:          1 :         if (rte_intr_disable(test_intr_handle) < 0) {
     442                 :            :                 printf("fail to disable interrupt on a simulated handler\n");
     443                 :          0 :                 return -1;
     444                 :            :         }
     445                 :            : 
     446                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_UIO];
     447         [ -  + ]:          1 :         if (rte_intr_disable(test_intr_handle) == 0) {
     448                 :            :                 printf("unexpectedly disable a specific intr_handle "
     449                 :            :                         "successfully\n");
     450                 :          0 :                 return -1;
     451                 :            :         }
     452                 :            : 
     453                 :            :         return 0;
     454                 :            : }
     455                 :            : 
     456                 :            : /**
     457                 :            :  * Check the full path of a specified type of interrupt simulated.
     458                 :            :  */
     459                 :            : static int
     460                 :          4 : test_interrupt_full_path_check(enum test_interrupt_handle_type intr_type)
     461                 :            : {
     462                 :            :         int count;
     463                 :            :         struct rte_intr_handle *test_intr_handle;
     464                 :            : 
     465                 :          4 :         flag = 0;
     466                 :          4 :         test_intr_handle = intr_handles[intr_type];
     467                 :          4 :         test_intr_type = intr_type;
     468         [ -  + ]:          4 :         if (rte_intr_callback_register(test_intr_handle,
     469                 :            :                         test_interrupt_callback, test_intr_handle) < 0) {
     470                 :            :                 printf("fail to register callback\n");
     471                 :          0 :                 return -1;
     472                 :            :         }
     473                 :            : 
     474                 :            :         if (test_interrupt_trigger_interrupt() < 0)
     475                 :            :                 return -1;
     476                 :            : 
     477                 :            :         /* check flag */
     478   [ +  +  +  - ]:          7 :         for (count = 0; flag == 0 && count < 3; count++)
     479                 :            :                 rte_delay_ms(TEST_INTERRUPT_CHECK_INTERVAL);
     480                 :            : 
     481                 :            :         rte_delay_ms(TEST_INTERRUPT_CHECK_INTERVAL);
     482                 :            :         while ((count =
     483                 :          4 :                 rte_intr_callback_unregister(test_intr_handle,
     484                 :            :                                              test_interrupt_callback,
     485         [ -  + ]:          4 :                                              test_intr_handle)) < 0) {
     486         [ #  # ]:          0 :                 if (count != -EAGAIN)
     487                 :            :                         return -1;
     488                 :            :         }
     489                 :            : 
     490         [ -  + ]:          4 :         if (flag == 0) {
     491                 :            :                 printf("callback has not been called\n");
     492                 :          0 :                 return -1;
     493         [ -  + ]:          4 :         } else if (flag < 0) {
     494                 :            :                 printf("it has internal error in callback\n");
     495                 :          0 :                 return -1;
     496                 :            :         }
     497                 :            : 
     498                 :            :         return 0;
     499                 :            : }
     500                 :            : 
     501                 :            : /**
     502                 :            :  * Main function of testing interrupt.
     503                 :            :  */
     504                 :            : static int
     505                 :          1 : test_interrupt(void)
     506                 :            : {
     507                 :            :         int ret = -1;
     508                 :            :         struct rte_intr_handle *test_intr_handle;
     509                 :            : 
     510                 :            :         if (RTE_EXEC_ENV_IS_WINDOWS || RTE_EXEC_ENV_IS_FREEBSD)
     511                 :            :                 return TEST_SKIPPED;
     512                 :            : 
     513         [ -  + ]:          1 :         if (test_interrupt_init() < 0) {
     514                 :            :                 printf("fail to initialize for testing interrupt\n");
     515                 :          0 :                 goto out;
     516                 :            :         }
     517                 :            : 
     518                 :            :         printf("Check unknown valid interrupt full path\n");
     519         [ -  + ]:          1 :         if (test_interrupt_full_path_check(TEST_INTERRUPT_HANDLE_VALID) < 0) {
     520                 :            :                 printf("failure occurred during checking unknown valid "
     521                 :            :                                                 "interrupt full path\n");
     522                 :          0 :                 goto out;
     523                 :            :         }
     524                 :            : 
     525                 :            :         printf("Check valid UIO interrupt full path\n");
     526         [ -  + ]:          1 :         if (test_interrupt_full_path_check(TEST_INTERRUPT_HANDLE_VALID_UIO)
     527                 :            :                                                                         < 0) {
     528                 :            :                 printf("failure occurred during checking valid UIO interrupt "
     529                 :            :                                                                 "full path\n");
     530                 :          0 :                 goto out;
     531                 :            :         }
     532                 :            : 
     533                 :            :         printf("Check valid device event interrupt full path\n");
     534         [ -  + ]:          1 :         if (test_interrupt_full_path_check(
     535                 :            :                 TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT) < 0) {
     536                 :            :                 printf("failure occurred during checking valid device event "
     537                 :            :                                                 "interrupt full path\n");
     538                 :          0 :                 goto out;
     539                 :            :         }
     540                 :            : 
     541                 :            :         printf("Check valid alarm interrupt full path\n");
     542         [ -  + ]:          1 :         if (test_interrupt_full_path_check(
     543                 :            :                 TEST_INTERRUPT_HANDLE_VALID_ALARM) < 0) {
     544                 :            :                 printf("failure occurred during checking valid alarm "
     545                 :            :                                                 "interrupt full path\n");
     546                 :          0 :                 goto out;
     547                 :            :         }
     548                 :            : 
     549                 :            :         printf("start register/unregister test\n");
     550                 :            :         /* check if it will fail to register cb with intr_handle = NULL */
     551         [ -  + ]:          1 :         if (rte_intr_callback_register(NULL, test_interrupt_callback,
     552                 :            :                                                         NULL) == 0) {
     553                 :            :                 printf("unexpectedly register successfully with null "
     554                 :            :                         "intr_handle\n");
     555                 :          0 :                 goto out;
     556                 :            :         }
     557                 :            : 
     558                 :            :         /* check if it will fail to register cb with invalid intr_handle */
     559                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_INVALID];
     560         [ -  + ]:          1 :         if (rte_intr_callback_register(test_intr_handle,
     561                 :            :                         test_interrupt_callback, test_intr_handle) == 0) {
     562                 :            :                 printf("unexpectedly register successfully with invalid "
     563                 :            :                         "intr_handle\n");
     564                 :          0 :                 goto out;
     565                 :            :         }
     566                 :            : 
     567                 :            :         /* check if it will fail to register without callback */
     568                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID];
     569         [ -  + ]:          1 :         if (rte_intr_callback_register(test_intr_handle, NULL,
     570                 :            :                                        test_intr_handle) == 0) {
     571                 :            :                 printf("unexpectedly register successfully with "
     572                 :            :                         "null callback\n");
     573                 :          0 :                 goto out;
     574                 :            :         }
     575                 :            : 
     576                 :            :         /* check if it will fail to unregister cb with intr_handle = NULL */
     577         [ -  + ]:          1 :         if (rte_intr_callback_unregister(NULL,
     578                 :            :                         test_interrupt_callback, NULL) > 0) {
     579                 :            :                 printf("unexpectedly unregister successfully with "
     580                 :            :                         "null intr_handle\n");
     581                 :          0 :                 goto out;
     582                 :            :         }
     583                 :            : 
     584                 :            :         /* check if it will fail to unregister cb with invalid intr_handle */
     585                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_INVALID];
     586         [ -  + ]:          1 :         if (rte_intr_callback_unregister(test_intr_handle,
     587                 :            :                         test_interrupt_callback, test_intr_handle) > 0) {
     588                 :            :                 printf("unexpectedly unregister successfully with "
     589                 :            :                         "invalid intr_handle\n");
     590                 :          0 :                 goto out;
     591                 :            :         }
     592                 :            : 
     593                 :            :         /* check if it is ok to register the same intr_handle twice */
     594                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID];
     595         [ -  + ]:          1 :         if (rte_intr_callback_register(test_intr_handle,
     596                 :            :                         test_interrupt_callback, test_intr_handle) < 0) {
     597                 :            :                 printf("it fails to register test_interrupt_callback\n");
     598                 :          0 :                 goto out;
     599                 :            :         }
     600         [ -  + ]:          1 :         if (rte_intr_callback_register(test_intr_handle,
     601                 :            :                         test_interrupt_callback_1, test_intr_handle) < 0) {
     602                 :            :                 printf("it fails to register test_interrupt_callback_1\n");
     603                 :          0 :                 goto out;
     604                 :            :         }
     605                 :            :         /* check if it will fail to unregister with invalid parameter */
     606         [ -  + ]:          1 :         if (rte_intr_callback_unregister(test_intr_handle,
     607                 :            :                         test_interrupt_callback, (void *)0xff) != 0) {
     608                 :            :                 printf("unexpectedly unregisters successfully with "
     609                 :            :                                                         "invalid arg\n");
     610                 :          0 :                 goto out;
     611                 :            :         }
     612         [ -  + ]:          1 :         if (rte_intr_callback_unregister(test_intr_handle,
     613                 :            :                         test_interrupt_callback, test_intr_handle) <= 0) {
     614                 :            :                 printf("it fails to unregister test_interrupt_callback\n");
     615                 :          0 :                 goto out;
     616                 :            :         }
     617         [ -  + ]:          1 :         if (rte_intr_callback_unregister(test_intr_handle,
     618                 :            :                         test_interrupt_callback_1, (void *)-1) <= 0) {
     619                 :            :                 printf("it fails to unregister test_interrupt_callback_1 "
     620                 :            :                         "for all\n");
     621                 :          0 :                 goto out;
     622                 :            :         }
     623                 :            :         rte_delay_ms(TEST_INTERRUPT_CHECK_INTERVAL);
     624                 :            : 
     625                 :            :         printf("start interrupt enable/disable test\n");
     626                 :            :         /* check interrupt enable/disable functions */
     627         [ -  + ]:          1 :         if (test_interrupt_enable() < 0) {
     628                 :            :                 printf("fail to check interrupt enabling\n");
     629                 :          0 :                 goto out;
     630                 :            :         }
     631                 :            :         rte_delay_ms(TEST_INTERRUPT_CHECK_INTERVAL);
     632                 :            : 
     633         [ -  + ]:          1 :         if (test_interrupt_disable() < 0) {
     634                 :            :                 printf("fail to check interrupt disabling\n");
     635                 :          0 :                 goto out;
     636                 :            :         }
     637                 :            :         rte_delay_ms(TEST_INTERRUPT_CHECK_INTERVAL);
     638                 :            : 
     639                 :            :         printf("start interrupt close test\n");
     640         [ -  + ]:          1 :         if (test_interrupt_close() < 0) {
     641                 :            :                 printf("fail to check interrupt close\n");
     642                 :          0 :                 goto out;
     643                 :            :         }
     644                 :            :         rte_delay_ms(TEST_INTERRUPT_CHECK_INTERVAL);
     645                 :            : 
     646                 :            :         ret = 0;
     647                 :            : 
     648                 :          1 : out:
     649                 :            :         printf("Clearing for interrupt tests\n");
     650                 :            :         /* clear registered callbacks */
     651                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID];
     652                 :          1 :         rte_intr_callback_unregister(test_intr_handle,
     653                 :            :                         test_interrupt_callback, (void *)-1);
     654                 :          1 :         rte_intr_callback_unregister(test_intr_handle,
     655                 :            :                         test_interrupt_callback_1, (void *)-1);
     656                 :            : 
     657                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_UIO];
     658                 :          1 :         rte_intr_callback_unregister(test_intr_handle,
     659                 :            :                         test_interrupt_callback, (void *)-1);
     660                 :          1 :         rte_intr_callback_unregister(test_intr_handle,
     661                 :            :                         test_interrupt_callback_1, (void *)-1);
     662                 :            : 
     663                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_ALARM];
     664                 :          1 :         rte_intr_callback_unregister(test_intr_handle,
     665                 :            :                         test_interrupt_callback, (void *)-1);
     666                 :          1 :         rte_intr_callback_unregister(test_intr_handle,
     667                 :            :                         test_interrupt_callback_1, (void *)-1);
     668                 :            : 
     669                 :          1 :         test_intr_handle = intr_handles[TEST_INTERRUPT_HANDLE_VALID_DEV_EVENT];
     670                 :          1 :         rte_intr_callback_unregister(test_intr_handle,
     671                 :            :                         test_interrupt_callback, (void *)-1);
     672                 :          1 :         rte_intr_callback_unregister(test_intr_handle,
     673                 :            :                         test_interrupt_callback_1, (void *)-1);
     674                 :            : 
     675                 :            :         rte_delay_ms(2 * TEST_INTERRUPT_CHECK_INTERVAL);
     676                 :            :         /* deinit */
     677                 :          1 :         test_interrupt_deinit();
     678                 :            : 
     679                 :            :         return ret;
     680                 :            : }
     681                 :            : 
     682                 :        305 : REGISTER_FAST_TEST(interrupt_autotest, NOHUGE_OK, ASAN_OK, test_interrupt);

Generated by: LCOV version 1.14