annotate test/callback_suite/main.c @ 495:45ac093ca822

- test/callback_suite: make it use shared random sig generator from call_suite and call_suite_aggrs
author Tassilo Philipp
date Mon, 21 Mar 2022 16:50:44 +0100
parents d8f0e6cecdab
children 049e04af13c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 /*
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 Package: dyncall
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 Library: test
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 File: test/callback_suite/main.c
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 Description:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 License:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8
410
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
9 Copyright (c) 2011-2021 Daniel Adler <dadler@uni-goettingen.de>,
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 Tassilo Philipp <tphilipp@potion-studios.com>
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 Permission to use, copy, modify, and distribute this software for any
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 purpose with or without fee is hereby granted, provided that the above
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 copyright notice and this permission notice appear in all copies.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
26 #include <stdio.h>
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27 #include <stdlib.h>
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28 #include "env.h"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29 #include "../common/platformInit.h"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
33 static void PrintUsage(const char* appName)
410
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
34 {
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
35 printf("usage:\n\
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
36 %s [ -v ] [ from [to] ]\n\
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
37 where\n\
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
38 from, to: test range\n\
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
39 options\n\
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
40 -v verbose reports\n\
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
41 -h help on usage\n\
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
42 \n\
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
43 ", appName);
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
44 }
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
45
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
46
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
47 /* test one case, returns error code */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
48 int DoTest(int id);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
49
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
50 void InitEnv();
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
51
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
52
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
53 #define Error(X, Y, N) { fprintf(stderr, X, Y); PrintUsage(N); exit(1); }
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
54
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
55 int main(int argc, char* argv[])
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
56 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
57 int from = 1;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
58 int to = CONFIG_NSIGS;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
59 int ncases;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
60
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
61 int i;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
62 int pos;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
63 int totalResult;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
64
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
65 /* capture total results for failure (0) and success (1) */
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
66 int totalErrorCodes[2] = { 0, 0 };
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
67
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
68 dcTest_initPlatform();
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
69
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
70 InitEnv();
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
71
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
72 pos = 0;
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
73 for(i = 1 ; i < argc ; ++i)
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
74 {
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
75 int number;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
76
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
77 if(argv[i][0] == '-')
495
45ac093ca822 - test/callback_suite: make it use shared random sig generator from call_suite and call_suite_aggrs
Tassilo Philipp
parents: 487
diff changeset
78 {
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
79 switch(argv[i][1]) {
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
80 case 'v':
495
45ac093ca822 - test/callback_suite: make it use shared random sig generator from call_suite and call_suite_aggrs
Tassilo Philipp
parents: 487
diff changeset
81 OptionVerbose = 1;
45ac093ca822 - test/callback_suite: make it use shared random sig generator from call_suite and call_suite_aggrs
Tassilo Philipp
parents: 487
diff changeset
82 continue;
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
83 case 'h':
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
84 case '?':
495
45ac093ca822 - test/callback_suite: make it use shared random sig generator from call_suite and call_suite_aggrs
Tassilo Philipp
parents: 487
diff changeset
85 PrintUsage(argv[0]);
45ac093ca822 - test/callback_suite: make it use shared random sig generator from call_suite and call_suite_aggrs
Tassilo Philipp
parents: 487
diff changeset
86 return 0;
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
87 default: Error("invalid option: %s\n\n", argv[i], argv[0]);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
88 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
89 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
90
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
91 number = atoi(argv[i]);
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
92 switch(pos++) {
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
93 case 0: to = from = number; break;
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
94 case 1: to = number; break;
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
95 default: Error("too many arguments (%d given, 2 allowed)\n\n", pos, argv[0]);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
96 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
97 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
98
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
99 if(from <= 0 || to > CONFIG_NSIGS || from > to)
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
100 Error("invalid arguments (provided from or to not in order or outside of range [1,%d])\n\n", CONFIG_NSIGS, argv[0]);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
101
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
102 ncases = (to - from) + 1;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
103
410
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
104 printf("case\tsignat.\tresult\n");
487
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
105
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
106 for(i = from ; i <= to ; ++i )
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
107 ++totalErrorCodes[!!DoTest(i)];
d8f0e6cecdab - simplified test/callback_suite
Tassilo Philipp
parents: 410
diff changeset
108
410
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
109 totalResult = (totalErrorCodes[1] == ncases);
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
110 printf("result: callback_suite: %d\n", totalResult);
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
111
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
112 dcTest_deInitPlatform();
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
113
410
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
114 return !totalResult;
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
115 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
116