comparison test/callback_suite/main.c @ 487:d8f0e6cecdab

- simplified test/callback_suite
author Tassilo Philipp
date Fri, 18 Mar 2022 09:47:18 +0100
parents 7608e34098b0
children 45ac093ca822
comparison
equal deleted inserted replaced
486:d160046da104 487:d8f0e6cecdab
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 23
24 */ 24 */
25 25
26 #include <assert.h> 26 #include <stdio.h>
27 #include <stdlib.h> 27 #include <stdlib.h>
28 #include "_auto_config.h"
29 #include "env.h" 28 #include "env.h"
30 #include "../common/platformInit.h" 29 #include "../common/platformInit.h"
31 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */ 30 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */
32 31
33 32
34 void PrintUsage(const char* appName) 33 static void PrintUsage(const char* appName)
35 { 34 {
36 printf("usage:\n\ 35 printf("usage:\n\
37 %s [ -v ] [ from [to] ]\n\ 36 %s [ -v ] [ from [to] ]\n\
38 where\n\ 37 where\n\
39 from, to: test range\n\ 38 from, to: test range\n\
43 \n\ 42 \n\
44 ", appName); 43 ", appName);
45 } 44 }
46 45
47 46
48
49 const char* appname = "unknown";
50
51 /* test one case, returns error code */ 47 /* test one case, returns error code */
52 int DoTest(int id); 48 int DoTest(int id);
53 49
54 /* capture total results for failure (0) and success (1) */
55 int totalErrorCodes[2] = { 0, 0 };
56
57 void TestRange(int from, int to)
58 {
59 int i;
60 for(i = from ; i <= to ; ++i )
61 {
62 int status = DoTest(i);
63 totalErrorCodes[status]++;
64 }
65 }
66
67 void InitEnv(); 50 void InitEnv();
68 51
69 void ExitWithUsage()
70 {
71 PrintUsage(appname);
72 exit(0);
73 }
74 52
75 #define Error(X, Y) fprintf(stderr, X, Y); ExitWithUsage() 53 #define Error(X, Y, N) { fprintf(stderr, X, Y); PrintUsage(N); exit(1); }
76 54
77 int main(int argc, char* argv[] ) 55 int main(int argc, char* argv[])
78 { 56 {
79 int from = 1; 57 int from = 1;
80 int to = CONFIG_NSIGS; 58 int to = CONFIG_NSIGS;
81 int ncases; 59 int ncases;
82 60
83 int i; 61 int i;
84 int pos; 62 int pos;
85 int number;
86 int totalResult; 63 int totalResult;
64
65 /* capture total results for failure (0) and success (1) */
66 int totalErrorCodes[2] = { 0, 0 };
87 67
88 dcTest_initPlatform(); 68 dcTest_initPlatform();
89 69
90 InitEnv(); 70 InitEnv();
91 appname = argv[0];
92 71
93 pos = 0; 72 pos = 0;
94 for(i = 1 ; i < argc ; ++i ) { 73 for(i = 1 ; i < argc ; ++i)
74 {
75 int number;
95 76
96 if ( argv[i][0] == '-' ) { 77 if(argv[i][0] == '-')
78 {
97 switch(argv[i][1]) { 79 switch(argv[i][1]) {
98 case 'v': OptionVerbose = 1; continue; 80 case 'v':
99 case 'h': PrintUsage(appname); return 0; 81 OptionVerbose = 1;
100 default: Error("invalid option: %s", argv[i]); 82 continue;
83 case 'h':
84 case '?':
85 PrintUsage(argv[0]);
86 return 0;
87 default: Error("invalid option: %s\n\n", argv[i], argv[0]);
101 } 88 }
102 } 89 }
103 90
104 number = atoi(argv[i]); 91 number = atoi(argv[i]);
105 switch(pos) { 92 switch(pos++) {
106 case 0: to = from = number; ++pos; break; 93 case 0: to = from = number; break;
107 case 1: to = number; break; 94 case 1: to = number; break;
108 default: Error("too many arguments%s", ""); 95 default: Error("too many arguments (%d given, 2 allowed)\n\n", pos, argv[0]);
109 } 96 }
110 } 97 }
111 98
112 assert(from > 0); 99 if(from <= 0 || to > CONFIG_NSIGS || from > to)
113 assert(to <= CONFIG_NSIGS); 100 Error("invalid arguments (provided from or to not in order or outside of range [1,%d])\n\n", CONFIG_NSIGS, argv[0]);
114 assert(from <= to);
115 101
116 ncases = (to - from) + 1; 102 ncases = (to - from) + 1;
117 103
118 printf("case\tsignat.\tresult\n"); 104 printf("case\tsignat.\tresult\n");
119 TestRange(from, to); 105
106 for(i = from ; i <= to ; ++i )
107 ++totalErrorCodes[!!DoTest(i)];
108
120 totalResult = (totalErrorCodes[1] == ncases); 109 totalResult = (totalErrorCodes[1] == ncases);
121 printf("result: callback_suite: %d\n", totalResult); 110 printf("result: callback_suite: %d\n", totalResult);
122 111
123 dcTest_deInitPlatform(); 112 dcTest_deInitPlatform();
124 113