1 /** @file 2 3 A brief file description 4 5 @section license License 6 7 Licensed to the Apache Software Foundation (ASF) under one 8 or more contributor license agreements. See the NOTICE file 9 distributed with this work for additional information 10 regarding copyright ownership. The ASF licenses this file 11 to you under the Apache License, Version 2.0 (the 12 "License"); you may not use this file except in compliance 13 with the License. You may obtain a copy of the License at 14 15 http://www.apache.org/licenses/LICENSE-2.0 16 17 Unless required by applicable law or agreed to in writing, software 18 distributed under the License is distributed on an "AS IS" BASIS, 19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 See the License for the specific language governing permissions and 21 limitations under the License. 22 */ 23 24 #pragma once 25 26 #include "tscore/ink_platform.h" 27 #include "tscore/Regex.h" 28 #include "tscore/Diags.h" 29 30 // Each module should provide one or more regression tests 31 // 32 // An example: 33 // 34 // REGRESSION_TEST(Addition)(RegressionTest *t, int atype, int *pstatus) { 35 // if (atype < REGRESSION_TEST_NIGHTLY) { // to expensive to do more than nightly 36 // *pstatus = REGRESSION_TEST_NOT_RUN; 37 // return; 38 // } 39 // if (1 + 1 != 2) { 40 // rprintf(t, "drat, 1+1 isn't 2??"); 41 // *pstatus = REGRESSION_TEST_FAILED; 42 // } else 43 // *pstatus = REGRESSION_TEST_PASSED; 44 // } 45 46 // status values 47 #define REGRESSION_TEST_PASSED 1 48 #define REGRESSION_TEST_INPROGRESS 0 // initial value 49 #define REGRESSION_TEST_FAILED -1 50 #define REGRESSION_TEST_NOT_RUN -2 51 52 // regression types 53 #define REGRESSION_TEST_NONE 0 54 #define REGRESSION_TEST_QUICK 1 55 #define REGRESSION_TEST_NIGHTLY 2 56 #define REGRESSION_TEST_EXTENDED 3 57 58 // regression options 59 #define REGRESSION_OPT_EXCLUSIVE (1 << 0) 60 61 #define RegressionMakeLocation(f) SourceLocation(__FILE__, f, __LINE__) 62 63 struct RegressionTest; 64 65 typedef void TestFunction(RegressionTest *t, int type, int *status); 66 67 struct RegressionTest { 68 const char *name; 69 const SourceLocation location; 70 TestFunction *function; 71 RegressionTest *next; 72 int status; 73 bool printed; 74 int opt; 75 76 RegressionTest(const char *name_arg, const SourceLocation &loc, TestFunction *function_arg, int aopt); 77 78 static int final_status; 79 static int ran_tests; 80 static DFA dfa; 81 static RegressionTest *current; 82 static int run(const char *name, int regression_level); 83 static void list(); 84 static int run_some(int regression_level); 85 static int check_status(int regression_level); 86 87 static int main(int argc, const char **argv, int level); 88 }; 89 90 #define REGRESSION_TEST(_f) \ 91 void RegressionTest_##_f(RegressionTest *t, int atype, int *pstatus); \ 92 RegressionTest regressionTest_##_f(#_f, RegressionMakeLocation("RegressionTest_" #_f), &RegressionTest_##_f, 0); \ 93 void RegressionTest_##_f 94 95 #define EXCLUSIVE_REGRESSION_TEST(_f) \ 96 void RegressionTest_##_f(RegressionTest *t, int atype, int *pstatus); \ 97 RegressionTest regressionTest_##_f(#_f, RegressionMakeLocation("RegressionTest_" #_f), &RegressionTest_##_f, \ 98 REGRESSION_OPT_EXCLUSIVE); \ 99 void RegressionTest_##_f 100 101 int rprintf(RegressionTest *t, const char *format, ...); 102 int rperf(RegressionTest *t, const char *tag, double val); 103 char *regression_status_string(int status); 104