LCOV - code coverage report
Current view: top level - lib/torture - subunit.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 59 74 79.7 %
Date: 2021-09-23 10:06:22 Functions: 8 8 100.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             :    Samba utility functions
       4             :    Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
       5             :    
       6             :    This program is free software; you can redistribute it and/or modify
       7             :    it under the terms of the GNU General Public License as published by
       8             :    the Free Software Foundation; either version 3 of the License, or
       9             :    (at your option) any later version.
      10             :    
      11             :    This program is distributed in the hope that it will be useful,
      12             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :    GNU General Public License for more details.
      15             :    
      16             :    You should have received a copy of the GNU General Public License
      17             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             : */
      19             : 
      20             : #include "includes.h"
      21             : #include "lib/torture/torture.h"
      22             : 
      23       37962 : static void subunit_send_event(char const * const event,
      24             :                 char const * const name,
      25             :                 char const * const details)
      26             : {
      27       37962 :         if (NULL == details) {
      28       30243 :                 printf("%s: %s\n", event, name);
      29             :         } else {
      30        5214 :                 printf("%s: %s [\n", event, name);
      31        5214 :                 printf("%s", details);
      32        5214 :                 if (details[strlen(details) - 1] != '\n')
      33        4124 :                         puts("");
      34        5214 :                 puts("]");
      35             :         }
      36       37962 :         fflush(stdout);
      37       37962 : }
      38             : 
      39        5581 : static void torture_subunit_suite_start(struct torture_context *ctx,
      40             :                                 struct torture_suite *suite)
      41             : {
      42        5581 : }
      43             : 
      44       40245 : static void torture_subunit_report_time(struct torture_context *tctx)
      45             : {
      46             :         struct timespec tp;
      47             :         struct tm *tmp;
      48             :         char timestr[200];
      49       40245 :         if (clock_gettime(CLOCK_REALTIME, &tp) != 0) {
      50           0 :                 perror("clock_gettime");
      51           0 :                 return;
      52             :         }
      53             : 
      54       40245 :         tmp = gmtime(&tp.tv_sec);
      55       40245 :         if (!tmp) {
      56           0 :                 perror("gmtime");
      57           0 :                 return;
      58             :         }
      59             : 
      60       40245 :         if (strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", tmp) <= 0) {
      61           0 :                 perror("strftime");
      62           0 :                 return;
      63             :         }
      64             : 
      65       42932 :         printf("time: %s.%06ld\n", timestr, tp.tv_nsec / 1000);
      66             : }
      67             : 
      68       18981 : static void torture_subunit_test_start(struct torture_context *context, 
      69             :                                struct torture_tcase *tcase,
      70             :                                struct torture_test *test)
      71             : {
      72       18981 :         char *fullname = torture_subunit_test_name(context, context->active_tcase, context->active_test);
      73       18981 :         subunit_send_event("test", fullname, NULL);
      74       18981 :         torture_subunit_report_time(context);
      75       18981 :         talloc_free(fullname);
      76       18981 : }
      77             : 
      78       18981 : static void torture_subunit_test_result(struct torture_context *context, 
      79             :                                 enum torture_result res, const char *reason)
      80             : {
      81       18981 :         char *fullname = torture_subunit_test_name(context, context->active_tcase, context->active_test);
      82       18981 :         const char *result_str = "unknown";
      83       18981 :         torture_subunit_report_time(context);
      84       18981 :         switch (res) {
      85       13767 :         case TORTURE_OK:
      86       13767 :                 result_str = "success";
      87       13767 :                 break;
      88        1822 :         case TORTURE_FAIL:
      89        1822 :                 result_str = "failure";
      90        1822 :                 break;
      91           0 :         case TORTURE_ERROR:
      92           0 :                 result_str = "error";
      93           0 :                 break;
      94        3392 :         case TORTURE_SKIP:
      95        3392 :                 result_str = "skip";
      96        3392 :                 break;
      97             :         }
      98       18981 :         subunit_send_event(result_str, fullname, reason);
      99       18981 :         talloc_free(fullname);
     100       18981 : }
     101             : 
     102      232198 : static void torture_subunit_comment(struct torture_context *test,
     103             :                             const char *comment)
     104             : {
     105      236974 :         fprintf(stderr, "%s", comment);
     106      232198 : }
     107             : 
     108        9029 : static void torture_subunit_warning(struct torture_context *test,
     109             :                             const char *comment)
     110             : {
     111        9034 :         fprintf(stderr, "WARNING!: %s\n", comment);
     112        9029 : }
     113             : 
     114       13973 : static void torture_subunit_progress(struct torture_context *tctx, int offset, enum torture_progress_whence whence)
     115             : {
     116       13973 :         switch (whence) {
     117        5581 :         case TORTURE_PROGRESS_SET:
     118        5423 :                 printf("progress: %d\n", offset);
     119        5423 :                 break;
     120           0 :         case TORTURE_PROGRESS_CUR:
     121           0 :                 printf("progress: %+-d\n", offset);
     122           0 :                 break;
     123        4196 :         case TORTURE_PROGRESS_POP:
     124        4116 :                 printf("progress: pop\n");
     125        4116 :                 break;
     126        4196 :         case TORTURE_PROGRESS_PUSH:
     127        4116 :                 printf("progress: push\n");
     128        4116 :                 break;
     129           0 :         default:
     130           0 :                 fprintf(stderr, "Invalid call to progress()\n");
     131           0 :                 break;
     132             :         }
     133       13973 : }
     134             : 
     135             : const struct torture_ui_ops torture_subunit_ui_ops = {
     136             :         .comment = torture_subunit_comment,
     137             :         .warning = torture_subunit_warning,
     138             :         .test_start = torture_subunit_test_start,
     139             :         .test_result = torture_subunit_test_result,
     140             :         .suite_start = torture_subunit_suite_start,
     141             :         .progress = torture_subunit_progress,
     142             :         .report_time = torture_subunit_report_time,
     143             : };

Generated by: LCOV version 1.13