LCOV - code coverage report
Current view: top level - ccan/list/test - run-CCAN_LIST_DEBUG.c (source / functions) Hit Total Coverage
Test: skiboot.info Lines: 16 17 94.1 %
Date: 2024-01-02 21:04:04 Functions: 2 2 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* Check that CCAN_LIST_DEBUG works */
       2                 :            : #include <setjmp.h>
       3                 :            : #include <stdlib.h>
       4                 :            : #include <stdio.h>
       5                 :            : #include <stdarg.h>
       6                 :            : #include <string.h>
       7                 :            : #include <err.h>
       8                 :            : 
       9                 :            : /* We don't actually want it to exit... */
      10                 :            : static jmp_buf aborted;
      11                 :            : #define abort() longjmp(aborted, 1)
      12                 :            : 
      13                 :            : #define fprintf my_fprintf
      14                 :            : static char printf_buffer[1000];
      15                 :            : 
      16                 :         10 : static int my_fprintf(FILE *stream, const char *format, ...)
      17                 :            : {
      18                 :            :         va_list ap;
      19                 :            :         int ret;
      20                 :            :         (void)stream;
      21                 :         10 :         va_start(ap, format);
      22                 :         10 :         ret = vsprintf(printf_buffer, format, ap);
      23                 :         10 :         va_end(ap);
      24                 :         10 :         return ret;
      25                 :            : }
      26                 :            : 
      27                 :            : #define CCAN_LIST_DEBUG 1
      28                 :            : #include <ccan/list/list.h>
      29                 :            : #include <ccan/tap/tap.h>
      30                 :            : #include <ccan/list/list.c>
      31                 :            : 
      32                 :         10 : int main(void)
      33                 :            : {
      34                 :            :         struct list_head list;
      35                 :            :         struct list_node n1;
      36                 :            :         char expect[100];
      37                 :            : 
      38                 :            :         plan_tests(2);
      39                 :            :         /* Empty list. */
      40                 :         10 :         list.n.next = &list.n;
      41                 :         10 :         list.n.prev = &list.n;
      42                 :         10 :         ok1(list_check(&list, NULL) == &list);
      43                 :            : 
      44                 :            :         /* Bad back ptr */
      45                 :         10 :         list.n.prev = &n1;
      46                 :            : 
      47                 :            :         /* Aborting version. */
      48                 :         10 :         sprintf(expect, "run-CCAN_LIST_DEBUG.c:51: prev corrupt in node %p (0) of %p\n",
      49                 :            :                 &list, &list);
      50                 :         10 :         if (setjmp(aborted) == 0) {
      51                 :         10 :                 assert(list_empty(&list));
      52                 :          0 :                 fail("list_empty on empty with bad back ptr didn't fail!");
      53                 :            :         } else {
      54                 :            :                 /* __FILE__ might give full path. */
      55                 :         10 :                 int prep = strlen(printf_buffer) - strlen(expect);
      56                 :         10 :                 ok1(prep >= 0 && strcmp(printf_buffer + prep, expect) == 0);
      57                 :            :         }
      58                 :            : 
      59                 :         10 :         return exit_status();
      60                 :            : }

Generated by: LCOV version 1.14