LCOV - code coverage report
Current view: top level - app/test - test_alarm.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 1 13 7.7 %
Date: 2024-01-22 15:55:54 Functions: 1 3 33.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 8 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2010-2014 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <stdio.h>
       6                 :            : #include <stdint.h>
       7                 :            : 
       8                 :            : #include <rte_common.h>
       9                 :            : #include <rte_alarm.h>
      10                 :            : 
      11                 :            : #include "test.h"
      12                 :            : 
      13                 :            : #ifndef RTE_EXEC_ENV_WINDOWS
      14                 :            : static volatile int flag;
      15                 :            : 
      16                 :            : static void
      17                 :          0 : test_alarm_callback(void *cb_arg)
      18                 :            : {
      19                 :          0 :         flag = 1;
      20                 :            :         printf("Callback setting flag - OK. [cb_arg = %p]\n", cb_arg);
      21                 :          0 : }
      22                 :            : #endif
      23                 :            : 
      24                 :            : static int
      25                 :          0 : test_alarm(void)
      26                 :            : {
      27                 :            : #ifdef RTE_EXEC_ENV_FREEBSD
      28                 :            :         printf("The alarm API is not supported on FreeBSD\n");
      29                 :            :         return 0;
      30                 :            : #endif
      31                 :            : 
      32                 :            : #ifndef RTE_EXEC_ENV_WINDOWS
      33                 :            :         /* check if it will fail to set alarm with wrong us value */
      34                 :            :         printf("check if it will fail to set alarm with wrong ms values\n");
      35         [ #  # ]:          0 :         if (rte_eal_alarm_set(0, test_alarm_callback,
      36                 :            :                                                 NULL) >= 0) {
      37                 :            :                 printf("should not be successful with 0 us value\n");
      38                 :          0 :                 return -1;
      39                 :            :         }
      40         [ #  # ]:          0 :         if (rte_eal_alarm_set(UINT64_MAX - 1, test_alarm_callback,
      41                 :            :                                                 NULL) >= 0) {
      42                 :            :                 printf("should not be successful with (UINT64_MAX-1) us value\n");
      43                 :          0 :                 return -1;
      44                 :            :         }
      45                 :            : #endif
      46                 :            : 
      47                 :            :         /* check if it will fail to set alarm with null callback parameter */
      48                 :            :         printf("check if it will fail to set alarm with null callback parameter\n");
      49         [ #  # ]:          0 :         if (rte_eal_alarm_set(10 /* ms */, NULL, NULL) >= 0) {
      50                 :            :                 printf("should not be successful to set alarm with null callback parameter\n");
      51                 :          0 :                 return -1;
      52                 :            :         }
      53                 :            : 
      54                 :            :         /* check if it will fail to remove alarm with null callback parameter */
      55                 :            :         printf("check if it will fail to remove alarm with null callback parameter\n");
      56         [ #  # ]:          0 :         if (rte_eal_alarm_cancel(NULL, NULL) == 0) {
      57                 :            :                 printf("should not be successful to remove alarm with null callback parameter");
      58                 :          0 :                 return -1;
      59                 :            :         }
      60                 :            : 
      61                 :            :         return 0;
      62                 :            : }
      63                 :            : 
      64                 :        235 : REGISTER_TEST_COMMAND(alarm_autotest, test_alarm);

Generated by: LCOV version 1.14