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