00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <time.h>
00027 #include <stdio.h>
00028 #include <errno.h>
00029 #include <string.h>
00030 #include <libxml/xmlwriter.h>
00031 #include "testresultlogger.h"
00032 #include "log.h"
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 LOCAL xmlTextWriterPtr writer;
00061 LOCAL FILE *ofile;
00062
00063
00064
00065
00066
00067
00068 struct
00069 {
00070 int (*write_td_start) (td_td *);
00071 int (*write_td_end) (td_td *);
00072 int (*write_pre_suite) (td_suite *);
00073 int (*write_post_suite) (td_suite *);
00074 int (*write_pre_set) (td_set *);
00075 int (*write_post_set) (td_set *);
00076 } out_cbs;
00077
00078
00079
00080 LOCAL int xml_write_td_start (td_td *);
00081
00082 LOCAL int xml_write_td_end (td_td *);
00083
00084 LOCAL int xml_write_pre_suite (td_suite *);
00085
00086 LOCAL int xml_write_post_suite (td_suite *);
00087
00088 LOCAL int xml_write_pre_set (td_set *);
00089
00090 LOCAL int xml_write_general_attributes (td_gen_attribs *);
00091
00092 LOCAL int xml_write_step (const void *, const void *);
00093
00094 LOCAL int xml_write_pre_post_step (const void *, const void *);
00095
00096 LOCAL int xml_write_case (const void *, const void *);
00097
00098 LOCAL int xml_write_file_data (const void *, const void *);
00099
00100 LOCAL int xml_write_post_set (td_set *);
00101
00102 LOCAL int txt_write_td_start (td_td *);
00103
00104 LOCAL int txt_write_td_end (td_td *);
00105
00106 LOCAL int txt_write_pre_suite (td_suite *);
00107
00108 LOCAL int txt_write_post_suite (td_suite *);
00109
00110 LOCAL int txt_write_pre_set (td_set *);
00111
00112 LOCAL int txt_write_post_set (td_set *);
00113
00114 LOCAL int txt_write_case (const void *, const void *);
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00129 LOCAL int xml_write_td_start (td_td *td)
00130 {
00131
00132 if (!td->version || xmlTextWriterWriteAttribute (writer,
00133 BAD_CAST "version",
00134 td->version) < 0)
00135 goto err_out;
00136
00137 return 0;
00138 err_out:
00139 return 1;
00140 }
00141
00146 LOCAL int xml_write_td_end (td_td *td)
00147 {
00148 if (td->hw_detector)
00149 if (xmlTextWriterWriteElement (writer,
00150 BAD_CAST "hwiddetect",
00151 td->hw_detector) < 0)
00152 goto err_out;
00153
00154 if (td->description)
00155 if (xmlTextWriterWriteElement (writer,
00156 BAD_CAST "description",
00157 td->description) < 0)
00158 goto err_out;
00159
00160 xmlTextWriterFlush (writer);
00161
00162 while (!xml_end_element());
00163 return 0;
00164 err_out:
00165 return 1;
00166 }
00167
00172 LOCAL int xml_write_pre_suite (td_suite *suite)
00173 {
00174
00175 if (xmlTextWriterStartElement (writer, BAD_CAST "suite") < 0)
00176 goto err_out;
00177
00178 if (xml_write_general_attributes (&suite->gen))
00179 goto err_out;
00180
00181
00182 return 0;
00183 err_out:
00184 return 1;
00185 }
00186
00191 LOCAL int xml_write_post_suite (td_suite *suite)
00192 {
00193 if (suite->description)
00194 if (xmlTextWriterWriteElement (writer,
00195 BAD_CAST "description",
00196 suite->description) < 0)
00197 goto err_out;
00198
00199 return xml_end_element();
00200 err_out:
00201 return 1;
00202 }
00203
00208 LOCAL int xml_write_pre_set (td_set *set)
00209 {
00210 if (xmlTextWriterStartElement (writer, BAD_CAST "set") < 0)
00211 goto err_out;
00212
00213 if (xml_write_general_attributes (&set->gen))
00214 goto err_out;
00215
00216
00217 if (set->environment)
00218 if (xmlTextWriterWriteAttribute (writer,
00219 BAD_CAST "environment",
00220 set->environment) < 0)
00221 goto err_out;
00222 return 0;
00223 err_out:
00224 return 1;
00225 }
00226
00231 LOCAL int xml_write_general_attributes (td_gen_attribs *gen)
00232 {
00233 if (gen->name)
00234 if (xmlTextWriterWriteAttribute (writer,
00235 BAD_CAST "name",
00236 gen->name) < 0)
00237 goto err_out;
00238
00239 if (gen->description)
00240 if (xmlTextWriterWriteAttribute (writer,
00241 BAD_CAST "description",
00242 gen->description) < 0)
00243 goto err_out;
00244
00245 if (gen->requirement)
00246 if (xmlTextWriterWriteAttribute (writer,
00247 BAD_CAST "requirement",
00248 gen->requirement) < 0)
00249 goto err_out;
00250
00251 if (xmlTextWriterWriteFormatAttribute (writer,
00252 BAD_CAST "timeout",
00253 "%lu",
00254 gen->timeout) < 0)
00255 goto err_out;
00256
00257 if (gen->type)
00258 if (xmlTextWriterWriteAttribute (writer,
00259 BAD_CAST "type",
00260 gen->type) < 0)
00261 goto err_out;
00262
00263
00264 if (gen->level)
00265 if (xmlTextWriterWriteAttribute (writer,
00266 BAD_CAST "level",
00267 gen->level) < 0)
00268 goto err_out;
00269
00270 if (xmlTextWriterWriteAttribute (writer,
00271 BAD_CAST "manual",
00272 BAD_CAST (gen->manual ? "true" :
00273 "false")) < 0)
00274 goto err_out;
00275
00276 if (xmlTextWriterWriteAttribute (writer,
00277 BAD_CAST "insignificant",
00278 BAD_CAST (gen->insignificant ?
00279 "true" :
00280 "false")) < 0)
00281 goto err_out;
00282
00283
00284 if (gen->domain)
00285 if (xmlTextWriterWriteAttribute (writer,
00286 BAD_CAST
00287 "domain",
00288 gen->domain) < 0)
00289 goto err_out;
00290
00291 if (gen->feature)
00292 if (xmlTextWriterWriteAttribute (writer,
00293 BAD_CAST "feature",
00294 gen->feature) < 0)
00295 goto err_out;
00296
00297 if (gen->component)
00298 if (xmlTextWriterWriteAttribute (writer,
00299 BAD_CAST "component",
00300 gen->component) < 0)
00301 goto err_out;
00302
00303 if (gen->hwid)
00304 if (xmlTextWriterWriteAttribute (writer,
00305 BAD_CAST "hwid",
00306 gen->hwid) < 0)
00307 goto err_out;
00308
00309 return 0;
00310 err_out:
00311 return 1;
00312 }
00313
00314
00320 LOCAL int xml_write_step (const void *data, const void *user)
00321 {
00322 td_step *step = (td_step *)data;
00323 struct tm *tm;
00324
00325 if (xmlTextWriterStartElement (writer, BAD_CAST "step") < 0)
00326 goto err_out;
00327
00328 if (xmlTextWriterWriteAttribute (writer,
00329 BAD_CAST "manual",
00330 BAD_CAST (step->manual ? "true" :
00331 "false")) < 0)
00332 goto err_out;
00333
00334 if (xmlTextWriterWriteAttribute (writer,
00335 BAD_CAST "command",
00336 step->step) < 0)
00337 goto err_out;
00338
00339 if (step->has_result == 0) {
00340 if (xmlTextWriterWriteAttribute (writer,
00341 BAD_CAST "result",
00342 BAD_CAST "N/A") < 0)
00343 goto err_out;
00344
00345
00346 } else if (xmlTextWriterWriteAttribute (writer,
00347 BAD_CAST "result",
00348 step->expected_result ==
00349 step->return_code ?
00350 BAD_CAST "PASS" :
00351 BAD_CAST "FAIL") < 0)
00352 goto err_out;
00353
00354 if (step->failure_info) {
00355 if (strlen ((char *)step->failure_info) >= FAILURE_INFO_MAX)
00356 step->failure_info[FAILURE_INFO_MAX - 1] = '\0';
00357 if (xmlTextWriterWriteAttribute (writer,
00358 BAD_CAST "failure_info",
00359 step->failure_info) < 0)
00360 goto err_out;
00361 }
00362
00363 if (xmlTextWriterWriteFormatElement (writer,
00364 BAD_CAST "expected_result",
00365 "%d", step->expected_result) < 0)
00366 goto err_out;
00367
00368 if (xmlTextWriterWriteFormatElement (writer,
00369 BAD_CAST "return_code",
00370 "%d", step->return_code) < 0)
00371 goto err_out;
00372
00373 tm = localtime (&step->start);
00374 if (xmlTextWriterWriteFormatElement (writer,
00375 BAD_CAST "start",
00376 "%02d-%02d-%02d %02d:%02d:%02d",
00377 tm->tm_year+1900,
00378 tm->tm_mon+1,
00379 tm->tm_mday,
00380 tm->tm_hour,
00381 tm->tm_min,
00382 tm->tm_sec) < 0)
00383 goto err_out;
00384
00385 tm = localtime (&step->end);
00386 if (xmlTextWriterWriteFormatElement (writer,
00387 BAD_CAST "end",
00388 "%02d-%02d-%02d %02d:%02d:%02d",
00389 tm->tm_year+1900,
00390 tm->tm_mon+1,
00391 tm->tm_mday,
00392 tm->tm_hour,
00393 tm->tm_min,
00394 tm->tm_sec) < 0)
00395 goto err_out;
00396
00397 if (xmlTextWriterWriteFormatElement (writer,
00398 BAD_CAST "stdout",
00399 "%s",
00400 step->stdout_ ? step->stdout_ :
00401 BAD_CAST "") < 0)
00402 goto err_out;
00403
00404 if (xmlTextWriterWriteFormatElement (writer,
00405 BAD_CAST "stderr",
00406 "%s",
00407 step->stderr_ ? step->stderr_ :
00408 BAD_CAST "") < 0)
00409 goto err_out;
00410
00411
00412 return !xml_end_element();
00413
00414 err_out:
00415 return 0;
00416 }
00417
00423 LOCAL int xml_write_pre_post_step (const void *data, const void *user)
00424 {
00425 td_step *step = (td_step *)data;
00426 struct tm *tm;
00427
00428 if (xmlTextWriterStartElement (writer, BAD_CAST "step") < 0)
00429 goto err_out;
00430
00431 if (xmlTextWriterWriteAttribute (writer,
00432 BAD_CAST "command",
00433 step->step) < 0)
00434 goto err_out;
00435
00436 if (step->has_result == 0) {
00437 if (xmlTextWriterWriteAttribute (writer,
00438 BAD_CAST "result",
00439 BAD_CAST "N/A") < 0)
00440 goto err_out;
00441
00442
00443 } else if (xmlTextWriterWriteAttribute (writer,
00444 BAD_CAST "result",
00445 step->expected_result ==
00446 step->return_code ?
00447 BAD_CAST "PASS" :
00448 BAD_CAST "FAIL") < 0)
00449 goto err_out;
00450
00451 if (step->failure_info) {
00452 if (strlen ((char *)step->failure_info) >= FAILURE_INFO_MAX)
00453 step->failure_info[FAILURE_INFO_MAX - 1] = '\0';
00454 if (xmlTextWriterWriteAttribute (writer,
00455 BAD_CAST "failure_info",
00456 step->failure_info) < 0)
00457 goto err_out;
00458 }
00459
00460 if (xmlTextWriterWriteFormatElement (writer,
00461 BAD_CAST "expected_result",
00462 "%d", step->expected_result) < 0)
00463 goto err_out;
00464
00465 if (xmlTextWriterWriteFormatElement (writer,
00466 BAD_CAST "return_code",
00467 "%d", step->return_code) < 0)
00468 goto err_out;
00469
00470 tm = localtime (&step->start);
00471 if (xmlTextWriterWriteFormatElement (writer,
00472 BAD_CAST "start",
00473 "%02d-%02d-%02d %02d:%02d:%02d",
00474 tm->tm_year+1900,
00475 tm->tm_mon+1,
00476 tm->tm_mday,
00477 tm->tm_hour,
00478 tm->tm_min,
00479 tm->tm_sec) < 0)
00480 goto err_out;
00481
00482 tm = localtime (&step->end);
00483 if (xmlTextWriterWriteFormatElement (writer,
00484 BAD_CAST "end",
00485 "%02d-%02d-%02d %02d:%02d:%02d",
00486 tm->tm_year+1900,
00487 tm->tm_mon+1,
00488 tm->tm_mday,
00489 tm->tm_hour,
00490 tm->tm_min,
00491 tm->tm_sec) < 0)
00492 goto err_out;
00493
00494 if (xmlTextWriterWriteFormatElement (writer,
00495 BAD_CAST "stdout",
00496 "%s",
00497 step->stdout_ ?
00498 step->stdout_ : BAD_CAST "") < 0)
00499 goto err_out;
00500
00501 if (xmlTextWriterWriteFormatElement (writer,
00502 BAD_CAST "stderr",
00503 "%s",
00504 step->stderr_ ?
00505 step->stderr_ : BAD_CAST "") < 0)
00506 goto err_out;
00507
00508
00509
00510 return !xml_end_element();
00511 err_out:
00512 return 0;
00513 }
00514
00520 LOCAL int xml_write_case (const void *data, const void *user)
00521 {
00522 td_case *c = (td_case *)data;
00523
00524 if (c->filtered)
00525 return 1;
00526
00527 if (xmlTextWriterStartElement (writer, BAD_CAST "case") < 0)
00528 goto err_out;
00529
00530 if (xml_write_general_attributes (&c->gen))
00531 goto err_out;
00532
00533 if (xmlTextWriterWriteAttribute (writer,
00534 BAD_CAST "result",
00535 BAD_CAST (case_result_str
00536 (c->case_res))) < 0)
00537
00538 goto err_out;
00539
00540 if (c->failure_info) {
00541 if (strlen ((char *)c->failure_info) >= FAILURE_INFO_MAX)
00542 c->failure_info[FAILURE_INFO_MAX - 1] = '\0';
00543 if (xmlTextWriterWriteAttribute (writer,
00544 BAD_CAST "failure_info",
00545 c->failure_info) < 0)
00546 goto err_out;
00547 }
00548
00549 if (c->subfeature)
00550 if (xmlTextWriterWriteAttribute (writer,
00551 BAD_CAST "subfeature",
00552 c->subfeature) < 0)
00553 goto err_out;
00554 if (c->bugzilla_id)
00555 if (xmlTextWriterWriteAttribute (writer,
00556 BAD_CAST "bugzilla_id",
00557 c->bugzilla_id) < 0)
00558 goto err_out;
00559 if (c->state)
00560 if (xmlTextWriterWriteAttribute (writer,
00561 BAD_CAST "state",
00562 c->state) < 0)
00563 goto err_out;
00564
00565
00566 if (c->gen.manual && c->comment)
00567 if (xmlTextWriterWriteAttribute (writer,
00568 BAD_CAST "comment",
00569 c->comment) < 0)
00570 goto err_out;
00571
00572
00573 xmlListWalk (c->steps, xml_write_step, NULL);
00574
00575 return !xml_end_element ();
00576
00577 err_out:
00578 LOG_MSG (LOG_ERR, "%s:%s: error\n", PROGNAME, __FUNCTION__);
00579
00580 return 0;
00581 }
00582
00588 LOCAL int xml_write_file_data (const void *data, const void *user)
00589 {
00590 td_file *f = (td_file *)data;
00591
00592 if (xmlTextWriterStartElement (writer, BAD_CAST "file") < 0)
00593 goto err_out;
00594 if (xmlTextWriterWriteAttribute (writer,
00595 BAD_CAST "delete_after",
00596 f->delete_after ? BAD_CAST "true"
00597 : BAD_CAST "false") < 0)
00598 goto err_out;
00599 if (xmlTextWriterWriteString (writer, f->filename) < 0)
00600 goto err_out;
00601 return !xml_end_element();
00602 err_out:
00603 return 0;
00604 }
00605
00610 LOCAL int xml_write_post_set (td_set *set)
00611 {
00612 td_steps *steps;
00613
00614 if (set->description)
00615 if (xmlTextWriterWriteElement (writer,
00616 BAD_CAST "description",
00617 set->description) < 0)
00618 goto err_out;
00619
00620 if (xmlListSize (set->pre_steps) > 0) {
00621 steps = xmlLinkGetData (xmlListFront (set->pre_steps));
00622
00623 if (xmlTextWriterStartElement (writer,
00624 BAD_CAST "pre_steps") < 0)
00625 goto err_out;
00626
00627 if (xmlTextWriterWriteFormatAttribute (writer,
00628 BAD_CAST "timeout",
00629 "%lu",
00630 steps->timeout) < 0)
00631 goto err_out;
00632
00633 xmlListWalk (steps->steps, xml_write_pre_post_step,
00634 NULL);
00635 xml_end_element ();
00636 }
00637
00638 xmlListWalk (set->cases, xml_write_case, NULL);
00639
00640 if (xmlListSize (set->post_steps) > 0) {
00641 steps = xmlLinkGetData (xmlListFront (set->post_steps));
00642
00643 if (xmlTextWriterStartElement (writer,
00644 BAD_CAST "post_steps") < 0)
00645 goto err_out;
00646 if (xmlTextWriterWriteFormatAttribute (writer,
00647 BAD_CAST "timeout",
00648 "%lu",
00649 steps->timeout) < 0)
00650 goto err_out;
00651
00652 xmlListWalk (steps->steps, xml_write_pre_post_step, NULL);
00653 xml_end_element ();
00654 }
00655
00656 if (xmlListSize (set->gets) > 0) {
00657 if (xmlTextWriterStartElement (writer,
00658 BAD_CAST "get") < 0)
00659 goto err_out;
00660
00661 xmlListWalk (set->gets, xml_write_file_data, NULL);
00662 xml_end_element();
00663 }
00664
00665 return 0;
00666
00667 err_out:
00668 return 1;
00669 }
00670
00671
00672
00678 LOCAL int txt_write_step (const void *data, const void *user)
00679 {
00680 td_step *step = (td_step *)data;
00681 struct tm *tm;
00682 fprintf (ofile, "----------------------------------"
00683 "----------------------------------\n");
00684 fprintf (ofile, " Test step : %s\n", step->step);
00685 tm = localtime (&step->start);
00686
00687 fprintf (ofile, " start : %02d-%02d-%02d"
00688 " %02d:%02d:%02d\n",
00689 tm->tm_year+1900,
00690 tm->tm_mon+1,
00691 tm->tm_mday,
00692 tm->tm_hour,
00693 tm->tm_min,
00694 tm->tm_sec);
00695 tm = localtime (&step->end);
00696 fprintf (ofile, " end : %02d-%02d-%02d"
00697 " %02d:%02d:%02d\n",
00698 tm->tm_year+1900,
00699 tm->tm_mon+1,
00700 tm->tm_mday,
00701 tm->tm_hour,
00702 tm->tm_min,
00703 tm->tm_sec);
00704 fprintf (ofile, " expected code : %d\n", step->expected_result);
00705 fprintf (ofile, " return code : %d\n", step->return_code);
00706 fprintf (ofile, " result : %s %s\n",
00707 (step->return_code == step->expected_result ? "PASS" : "FAIL"),
00708 (step->failure_info ? (char *)step->failure_info : " "));
00709 fprintf (ofile, " stdout : %s\n",
00710 step->stdout_ ? (char *)step->stdout_ : " ");
00711 fprintf (ofile, " stderr : %s\n",
00712 step->stderr_ ? (char *)step->stderr_ : " ");
00713 fflush (ofile);
00714
00715 return 1;
00716 }
00717
00723 LOCAL int txt_write_case (const void *data, const void *user)
00724 {
00725 td_case *c = (td_case *)data;
00726
00727 if (c->filtered)
00728 return 1;
00729
00730 fprintf (ofile, "----------------------------------"
00731 "----------------------------------\n");
00732 fprintf (ofile, " Test case name : %s\n", c->gen.name);
00733 fprintf (ofile, " description : %s\n", c->gen.description ?
00734 (char *)c->gen.description : "");
00735 fprintf (ofile, " manual : %s\n", c->gen.manual ?
00736 "true" : "false");
00737 fprintf (ofile, " result : %s",
00738 case_result_str(c->case_res));
00739 if (c->failure_info) {
00740 fprintf (ofile, " (%s)", c->failure_info);
00741 }
00742 fprintf (ofile, "\n");
00743
00744 if (c->gen.requirement)
00745 fprintf (ofile, " requirement : %s\n", c->gen.requirement);
00746 if (c->subfeature)
00747 fprintf (ofile, " subfeature : %s\n", c->subfeature);
00748 if (c->bugzilla_id)
00749 fprintf (ofile, " bugzilla_id : %s\n", c->bugzilla_id);
00750 if (c->gen.type)
00751 fprintf (ofile, " type : %s\n", c->gen.type);
00752 if (c->gen.level)
00753 fprintf (ofile, " level : %s\n", c->gen.level);
00754
00755 fprintf (ofile, " insignificant : %s\n", c->gen.insignificant ?
00756 "true" : "false");
00757
00758 if (c->gen.manual && c->comment)
00759 fprintf (ofile, " comment : %s\n", c->comment);
00760
00761 fflush (ofile);
00762
00763 xmlListWalk (c->steps, txt_write_step, NULL);
00764
00765
00766 return 1;
00767 }
00768
00773 LOCAL int txt_write_td_start (td_td *td)
00774 {
00775
00776 return 0;
00777 }
00778
00783 LOCAL int txt_write_td_end (td_td *td)
00784 {
00785 fprintf (ofile, "----------------------------------"
00786 "----------------------------------\n");
00787 fprintf (ofile, "End of test results.\n");
00788
00789 return 0;
00790 }
00791
00796 LOCAL int txt_write_pre_suite (td_suite *suite)
00797 {
00798 fprintf (ofile, "----------------------------------"
00799 "----------------------------------\n");
00800
00801 fprintf (ofile, "Test suite name : %s\n", suite->gen.name);
00802 fprintf (ofile, " description : %s\n", suite->gen.description ?
00803 (char *)suite->gen.description : " ");
00804 if (suite->gen.domain)
00805 fprintf (ofile, " domain : %s\n", suite->gen.domain);
00806
00807 fflush (ofile);
00808
00809 return 0;
00810 }
00811
00815 LOCAL int txt_write_post_suite (td_suite *suite)
00816 {
00817 return 0;
00818
00819 }
00820
00825 LOCAL int txt_write_pre_set (td_set *set)
00826 {
00827 fprintf (ofile, "----------------------------------"
00828 "----------------------------------\n");
00829
00830 fprintf (ofile, " Test set name : %s\n", set->gen.name);
00831 fprintf (ofile, " description : %s\n", set->gen.description ?
00832 (char *)set->gen.description : "");
00833 if (set->gen.feature)
00834 fprintf (ofile, " feature : %s\n", set->gen.feature);
00835
00836 fprintf (ofile, " environment : %s\n", set->environment ?
00837 (char *)set->environment : "");
00838
00839 fflush (ofile);
00840 return 0;
00841
00842 }
00843
00848 LOCAL int txt_write_post_set (td_set *set)
00849 {
00850
00851 xmlListWalk (set->cases, txt_write_case, NULL);
00852 fflush (ofile);
00853
00854 return 0;
00855 }
00856
00857
00858
00864 int init_result_logger (testrunner_lite_options *opts, hw_info *hwinfo)
00865 {
00866
00867 switch (opts->output_type) {
00868 case OUTPUT_TYPE_XML:
00869
00870
00871
00872 writer = xmlNewTextWriterFilename(opts->output_filename, 0);
00873 if (!writer) {
00874 LOG_MSG (LOG_ERR, "%s:%s:failed to create writer for %s\n",
00875 PROGNAME, __FUNCTION__, opts->output_filename);
00876 return 1;
00877 }
00878 xmlTextWriterSetIndent (writer, 1);
00879 if (xmlTextWriterStartDocument(writer,
00880 "1.0",
00881 "UTF-8",
00882 NULL) < 0) {
00883 LOG_MSG (LOG_ERR, "%s:%s:failed to write document start\n",
00884 PROGNAME, __FUNCTION__);
00885 return 1;
00886 }
00887
00888 if (xmlTextWriterStartElement (writer, BAD_CAST "testresults")
00889 < 0) {
00890 LOG_MSG (LOG_ERR, "%s:%s:failed to write "
00891 "testsresults tag\n",
00892 PROGNAME, __FUNCTION__);
00893 return 1;
00894 }
00895
00896 if (xmlTextWriterWriteAttribute (writer,
00897 BAD_CAST "environment",
00898 BAD_CAST (opts->environment ?
00899 opts->environment :
00900 "unknown")) < 0)
00901 return 1;
00902
00903
00904 if (xmlTextWriterWriteAttribute (writer,
00905 BAD_CAST "hwproduct",
00906 (hwinfo->product ?
00907 hwinfo->product :
00908 BAD_CAST "unknown")) < 0)
00909 return 1;
00910
00911
00912
00913 if (xmlTextWriterWriteAttribute (writer,
00914 BAD_CAST "hwbuild",
00915 (hwinfo->hw_build ?
00916 hwinfo->hw_build :
00917 BAD_CAST "unknown")) < 0)
00918 return 1;
00919
00920
00921
00922
00923
00924 out_cbs.write_td_start = xml_write_td_start;
00925 out_cbs.write_td_end = xml_write_td_end;
00926 out_cbs.write_pre_suite = xml_write_pre_suite;
00927 out_cbs.write_post_suite = xml_write_post_suite;
00928 out_cbs.write_pre_set = xml_write_pre_set;
00929 out_cbs.write_post_set = xml_write_post_set;
00930
00931
00932 break;
00933
00934 case OUTPUT_TYPE_TXT:
00935
00936
00937
00938 ofile = fopen (opts->output_filename, "w+");
00939 if (!ofile) {
00940 LOG_MSG (LOG_ERR, "%s:%s:failed to open file %s %s\n",
00941 PROGNAME, __FUNCTION__, opts->output_filename,
00942 strerror(errno));
00943 return 1;
00944 }
00945 fprintf (ofile,"Test results:\n");
00946 fprintf (ofile, " environment : %s\n", opts->environment);
00947
00948 fprintf (ofile, " hwproduct : %s\n",
00949 (char *)(hwinfo->product ? hwinfo->product :
00950 (unsigned char *)"unknown"));
00951
00952 fprintf (ofile, " hwbuild : %s\n",
00953 (char *)(hwinfo->hw_build ? hwinfo->hw_build :
00954 (unsigned char *)"unknown"));
00955
00956
00957
00958
00959
00960 out_cbs.write_td_start = txt_write_td_start;
00961 out_cbs.write_td_end = txt_write_td_end;
00962 out_cbs.write_pre_suite = txt_write_pre_suite;
00963 out_cbs.write_post_suite = txt_write_post_suite;
00964 out_cbs.write_pre_set = txt_write_pre_set;
00965 out_cbs.write_post_set = txt_write_post_set;
00966
00967 break;
00968
00969 default:
00970 LOG_MSG (LOG_ERR, "%s:%s:invalid output type %d\n",
00971 PROGNAME, __FUNCTION__, opts->output_type);
00972 return 1;
00973 }
00974
00975 return 0;
00976 }
00977
00982 int write_td_start (td_td *td)
00983 {
00984 return out_cbs.write_td_start (td);
00985 }
00986
00991 int write_td_end (td_td *td)
00992 {
00993 return out_cbs.write_td_end (td);
00994 }
00995
01000 int write_pre_suite (td_suite *suite)
01001 {
01002 return out_cbs.write_pre_suite (suite);
01003 }
01004
01009 int write_post_suite (td_suite *suite)
01010 {
01011
01012 return out_cbs.write_post_suite (suite);
01013 }
01014
01019 int write_pre_set (td_set *set)
01020 {
01021 return out_cbs.write_pre_set (set);
01022 }
01023
01028 int write_post_set (td_set *set)
01029 {
01030
01031 return out_cbs.write_post_set (set);
01032 }
01033
01037 int xml_end_element ()
01038 {
01039
01040 if (xmlTextWriterFullEndElement (writer) < 0)
01041 goto err_out;
01042 return 0;
01043 err_out:
01044 return 1;
01045 }
01046
01049 void close_result_logger (void)
01050 {
01051 if (writer) {
01052 xmlTextWriterFlush (writer);
01053 xmlFreeTextWriter (writer);
01054 writer = NULL;
01055 } else if (ofile) {
01056 fflush (ofile);
01057 fclose (ofile);
01058 ofile = NULL;
01059 } else {
01060 LOG_MSG (LOG_ERR, "%s:%s: Result logger not open?\n",
01061 PROGNAME, __FUNCTION__);
01062 }
01063
01064 return;
01065 }
01066
01067
01068
01069
01070