• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Regression.cc

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 /****************************************************************************
00025 
00026   Regression.cc
00027 
00028 
00029  ****************************************************************************/
00030 
00031 #include "libts.h"
00032 #include "Regression.h"
00033 
00034 static RegressionTest *test = NULL;
00035 static RegressionTest *exclusive_test = NULL;
00036 
00037 RegressionTest *RegressionTest::current = 0;
00038 int RegressionTest::ran_tests = 0;
00039 DFA RegressionTest::dfa;
00040 int regression_level = 0;
00041 int RegressionTest::final_status = REGRESSION_TEST_PASSED;
00042 
00043 char *
00044 regression_status_string(int status)
00045 {
00046   return (char *) (status == REGRESSION_TEST_NOT_RUN ? "NOT_RUN" :
00047                    (status == REGRESSION_TEST_PASSED ? "PASSED" :
00048                     (status == REGRESSION_TEST_INPROGRESS ? "INPROGRESS" : "FAILED")));
00049 }
00050 
00051 RegressionTest::RegressionTest(const char *name_arg, TestFunction * function_arg, int aopt)
00052 {
00053   name = name_arg;
00054   function = function_arg;
00055   status = REGRESSION_TEST_NOT_RUN;
00056   printed = 0;
00057   opt = aopt;
00058 
00059   if (opt == REGRESSION_OPT_EXCLUSIVE) {
00060     if (exclusive_test)
00061       this->next = exclusive_test;
00062     exclusive_test = this;
00063   } else {
00064     if (test)
00065       this->next = test;
00066     test = this;
00067   }
00068 }
00069 
00070 static inline int
00071 start_test(RegressionTest * t)
00072 {
00073   ink_assert(t->status == REGRESSION_TEST_NOT_RUN);
00074   t->status = REGRESSION_TEST_INPROGRESS;
00075   fprintf(stderr, "REGRESSION TEST %s started\n", t->name);
00076   (*t->function) (t, regression_level, &t->status);
00077   int tresult = t->status;
00078   if (tresult != REGRESSION_TEST_INPROGRESS) {
00079     fprintf(stderr, "    REGRESSION_RESULT %s:%*s %s\n", t->name,
00080             40 - (int)strlen(t->name), " ", regression_status_string(tresult));
00081     t->printed = 1;
00082   }
00083   return tresult;
00084 }
00085 
00086 int
00087 RegressionTest::run(char *atest)
00088 {
00089   if (atest)
00090     dfa.compile(atest);
00091   else
00092     dfa.compile(".*");
00093   fprintf(stderr, "REGRESSION_TEST initialization begun\n");
00094   // start the non exclusive tests
00095   for (RegressionTest * t = test; t; t = t->next) {
00096     if ((dfa.match(t->name) >= 0)) {
00097       int res = start_test(t);
00098       if (res == REGRESSION_TEST_FAILED)
00099         final_status = REGRESSION_TEST_FAILED;
00100     }
00101   }
00102   current = exclusive_test;
00103   return run_some();
00104 }
00105 
00106 int
00107 RegressionTest::run_some()
00108 {
00109 
00110   if (current) {
00111     if (current->status == REGRESSION_TEST_INPROGRESS)
00112       return REGRESSION_TEST_INPROGRESS;
00113     else if (current->status != REGRESSION_TEST_NOT_RUN) {
00114       if (!current->printed) {
00115         current->printed = true;
00116         fprintf(stderr, "    REGRESSION_RESULT %s:%*s %s\n", current->name,
00117                 40 - (int)strlen(current->name), " ", regression_status_string(current->status));
00118       }
00119       current = current->next;
00120     }
00121   }
00122 
00123   for (; current; current = current->next) {
00124     if ((dfa.match(current->name) >= 0)) {
00125       int res = start_test(current);
00126       if (res == REGRESSION_TEST_INPROGRESS)
00127         return res;
00128       if (res == REGRESSION_TEST_FAILED)
00129         final_status = REGRESSION_TEST_FAILED;
00130     }
00131   }
00132   return REGRESSION_TEST_INPROGRESS;
00133 }
00134 
00135 int
00136 RegressionTest::check_status()
00137 {
00138   int status = REGRESSION_TEST_PASSED;
00139   if (current) {
00140     status = run_some();
00141     if (!current)
00142       return status;
00143   }
00144   RegressionTest *t = test;
00145   int exclusive = 0;
00146 
00147 check_test_list:
00148   while (t) {
00149     if ((t->status == REGRESSION_TEST_PASSED || t->status == REGRESSION_TEST_FAILED) && !t->printed) {
00150       t->printed = true;
00151       fprintf(stderr, "    REGRESSION_RESULT %s:%*s %s\n", t->name,
00152               40 - (int)strlen(t->name), " ", regression_status_string(t->status));
00153     }
00154 
00155     switch (t->status) {
00156     case REGRESSION_TEST_FAILED:
00157       final_status = REGRESSION_TEST_FAILED;
00158       break;
00159     case REGRESSION_TEST_INPROGRESS:
00160       printf("Regression test(%s) still in progress\n", t->name);
00161       status = REGRESSION_TEST_INPROGRESS;
00162       break;
00163     default:
00164       break;
00165     }
00166     t = t->next;
00167   }
00168   if (!exclusive) {
00169     exclusive = 1;
00170     t = exclusive_test;
00171     goto check_test_list;
00172   }
00173 
00174   return (status == REGRESSION_TEST_INPROGRESS) ? REGRESSION_TEST_INPROGRESS : final_status;
00175 }
00176 
00177 int
00178 rprintf(RegressionTest *t, const char *format, ...)
00179 {
00180   int l;
00181   char buffer[8192];
00182 
00183   snprintf(buffer, sizeof(buffer), "RPRINT %s: ", t->name);
00184   fputs(buffer, stderr);
00185 
00186   va_list ap;
00187   va_start(ap, format);
00188   l = vsnprintf(buffer, sizeof(buffer), format, ap);
00189   va_end(ap);
00190 
00191   fputs(buffer, stderr);
00192   return (l);
00193 }
00194 
00195 int
00196 rperf(RegressionTest *t, const char *tag, double val)
00197 {
00198   int l;
00199   char format2[8192];
00200   l = snprintf(format2, sizeof(format2), "RPERF %s.%s %f\n", t->name, tag, val);
00201   fputs(format2, stderr);
00202   return (l);
00203 }
00204 
00205 REGRESSION_TEST(Regression) (RegressionTest * t, int atype, int *status) {
00206   (void) t;
00207   (void) atype;
00208   rprintf(t, "regression test\n");
00209   rperf(t, "speed", 100.0);
00210   if (!test)
00211     *status = REGRESSION_TEST_FAILED;
00212   else
00213     *status = REGRESSION_TEST_PASSED;
00214 }

Generated by  doxygen 1.7.1