LCOV - code coverage report
Current view: top level - lib/torture - subunit.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 62 77 80.5 %
Date: 2024-04-21 15:09:00 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       38638 : static void subunit_send_event(char const * const event,
      24             :                 char const * const name,
      25             :                 char const * const details)
      26             : {
      27       38638 :         if (NULL == details) {
      28       32887 :                 printf("%s: %s\n", event, name);
      29             :         } else {
      30        5751 :                 printf("%s: %s [\n", event, name);
      31        5751 :                 printf("%s", details);
      32        5751 :                 if (details[strlen(details) - 1] != '\n')
      33        4621 :                         puts("");
      34        5751 :                 puts("]");
      35             :         }
      36       38638 :         fflush(stdout);
      37       38638 : }
      38             : 
      39        5587 : static void torture_subunit_suite_start(struct torture_context *ctx,
      40             :                                 struct torture_suite *suite)
      41             : {
      42        5587 : }
      43             : 
      44       40920 : static void torture_subunit_report_time(struct torture_context *tctx)
      45             : {
      46        3011 :         struct timespec tp;
      47        3011 :         struct tm *tmp;
      48        3011 :         char timestr[200];
      49       40920 :         if (clock_gettime(CLOCK_REALTIME, &tp) != 0) {
      50           0 :                 perror("clock_gettime");
      51           0 :                 return;
      52             :         }
      53             : 
      54       40920 :         tmp = gmtime(&tp.tv_sec);
      55       40920 :         if (!tmp) {
      56           0 :                 perror("gmtime");
      57           0 :                 return;
      58             :         }
      59             : 
      60       40920 :         if (strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", tmp) <= 0) {
      61           0 :                 perror("strftime");
      62           0 :                 return;
      63             :         }
      64             : 
      65       40920 :         printf("time: %s.%06ld\n", timestr, tp.tv_nsec / 1000);
      66             : }
      67             : 
      68       19319 : static void torture_subunit_test_start(struct torture_context *context, 
      69             :                                struct torture_tcase *tcase,
      70             :                                struct torture_test *test)
      71             : {
      72       19319 :         char *fullname = torture_subunit_test_name(context, context->active_tcase, context->active_test);
      73       19319 :         subunit_send_event("test", fullname, NULL);
      74       19319 :         torture_subunit_report_time(context);
      75       19319 :         talloc_free(fullname);
      76       19319 : }
      77             : 
      78       19319 : static void torture_subunit_test_result(struct torture_context *context, 
      79             :                                 enum torture_result res, const char *reason)
      80             : {
      81       19319 :         char *fullname = torture_subunit_test_name(context, context->active_tcase, context->active_test);
      82       19319 :         const char *result_str = "unknown";
      83       19319 :         torture_subunit_report_time(context);
      84       19319 :         switch (res) {
      85       13568 :         case TORTURE_OK:
      86       13568 :                 result_str = "success";
      87       13568 :                 break;
      88        1815 :         case TORTURE_FAIL:
      89        1815 :                 result_str = "failure";
      90        1815 :                 break;
      91           0 :         case TORTURE_ERROR:
      92           0 :                 result_str = "error";
      93           0 :                 break;
      94        3936 :         case TORTURE_SKIP:
      95        3936 :                 result_str = "skip";
      96        3936 :                 break;
      97             :         }
      98       19319 :         subunit_send_event(result_str, fullname, reason);
      99       19319 :         talloc_free(fullname);
     100       19319 : }
     101             : 
     102      192128 : static void torture_subunit_comment(struct torture_context *test,
     103             :                             const char *comment)
     104             : {
     105      192128 :         fprintf(stderr, "%s", comment);
     106      192128 : }
     107             : 
     108        8931 : static void torture_subunit_warning(struct torture_context *test,
     109             :                             const char *comment)
     110             : {
     111        8931 :         fprintf(stderr, "WARNING!: %s\n", comment);
     112        8931 : }
     113             : 
     114       14017 : static void torture_subunit_progress(struct torture_context *tctx, int offset, enum torture_progress_whence whence)
     115             : {
     116       14017 :         switch (whence) {
     117        5421 :         case TORTURE_PROGRESS_SET:
     118        5587 :                 printf("progress: %d\n", offset);
     119        5421 :                 break;
     120           0 :         case TORTURE_PROGRESS_CUR:
     121           0 :                 printf("progress: %+-d\n", offset);
     122           0 :                 break;
     123        4129 :         case TORTURE_PROGRESS_POP:
     124        4215 :                 printf("progress: pop\n");
     125        4129 :                 break;
     126        4129 :         case TORTURE_PROGRESS_PUSH:
     127        4215 :                 printf("progress: push\n");
     128        4129 :                 break;
     129           0 :         default:
     130           0 :                 fprintf(stderr, "Invalid call to progress()\n");
     131           0 :                 break;
     132             :         }
     133       14017 : }
     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.14