TaskStats: remove unused attribute "Time"
[xcsoar.git] / test / src / test_debug.cpp
blob2c9c1ff08c5622ee8d203a8dd447a42f45713b86
1 /* Copyright_License {
3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "test_debug.hpp"
24 #include "harness_wind.hpp"
25 #include "harness_task.hpp"
26 #include "harness_flight.hpp"
27 #include "Contest/Solvers/ContestDijkstra.hpp"
28 #include <stdlib.h>
29 #include <stdio.h>
31 int n_samples = 0;
32 int interactive = 0;
33 int output_skip = 5;
35 AutopilotParameters autopilot_parms;
37 int terrain_height = 1;
38 std::string replay_file = "test/data/0asljd01.igc";
39 std::string task_file = "";
41 #ifdef INSTRUMENT_TASK
42 extern long count_mc;
43 long count_intersections;
44 extern unsigned n_queries;
45 extern unsigned count_distbearing;
46 #endif
48 #ifdef INSTRUMENT_ZERO
49 extern unsigned long zero_skipped;
50 extern unsigned long zero_total;
51 #endif
53 void PrintDistanceCounts() {
54 if (n_samples) {
55 printf("# Instrumentation\n");
56 #ifdef INSTRUMENT_TASK
57 printf("# dist+bearing calcs/c %d\n",count_distbearing/n_samples);
58 printf("# mc calcs/c %d\n",(int)(count_mc/n_samples));
59 if (n_queries>0) {
60 printf("# intersection tests/q %d\n",(unsigned)(count_intersections/n_queries));
61 printf("# (total queries %d)\n\n",n_queries);
63 #endif
64 printf("# (total cycles %d)\n#\n",n_samples);
65 #ifdef INSTRUMENT_ZERO
66 if (zero_total) {
67 printf("# ZeroFinder total %ld\n",zero_total);
68 printf("# ZeroFinder %%skipped %d\n",(int)(100*zero_skipped/zero_total));
70 #endif
72 n_samples = 0;
73 #ifdef INSTRUMENT_TASK
74 count_intersections = 0;
75 n_queries = 0;
76 count_distbearing = 0;
77 count_mc = 0;
78 #endif
79 #ifdef INSTRUMENT_ZERO
80 zero_skipped = 0;
81 zero_total = 0;
82 #endif
85 void PrintQueries(unsigned n, std::ostream &fout) {
86 #ifdef INSTRUMENT_TASK
87 if (n_queries>0) {
88 fout << n << " " << count_intersections/n_queries << "\n";
90 count_intersections = 0;
91 n_queries = 0;
92 #endif
95 /**
96 * Wait-for-key prompt
98 * @param time time of simulation
100 * @return character received by keyboard
102 char
103 WaitPrompt() {
104 if (interactive) {
105 puts("# [enter to continue]");
106 return getchar();
108 return 0;
111 bool
112 ParseArgs(int argc, char** argv)
114 // initialise random number generator once per test program
115 srand(0);
117 while (1) {
118 static struct option long_options[] =
120 /* These options set a flag. */
121 {"verbose", optional_argument, 0, 'v'},
122 {"interactive", optional_argument, 0, 'i'},
123 {"startalt", required_argument, 0, 'a'},
124 {"bearingnoise", required_argument, 0, 'n'},
125 {"outputskip", required_argument, 0, 's'},
126 {"targetnoise", required_argument, 0, 't'},
127 {"turnspeed", required_argument, 0, 'r'},
128 {"igc", required_argument, 0, 'f'},
129 {"task", required_argument, 0, 'x'},
130 {0, 0, 0, 0}
132 /* getopt_long stores the option index here. */
133 int option_index = 0;
135 int c = getopt_long (argc, argv, "s:v:i:n:t:r:a:f:x:",
136 long_options, &option_index);
137 /* Detect the end of the options. */
138 if (c == -1)
139 break;
141 switch (c) {
142 case 0:
143 /* If this option set a flag, do nothing else now. */
144 if (long_options[option_index].flag != 0)
145 break;
146 printf ("option %s", long_options[option_index].name);
147 if (optarg)
148 printf (" with arg %s", optarg);
149 printf ("\n");
150 break;
151 case 'f':
152 replay_file = optarg;
153 break;
154 case 'x':
155 task_file = optarg;
156 break;
157 case 'a':
158 autopilot_parms.start_alt = (fixed)atof(optarg);
159 break;
160 case 's':
161 output_skip = atoi(optarg);
162 break;
163 case 'v':
164 if (optarg) {
165 verbose = atoi(optarg);
166 } else {
167 verbose = 1;
169 break;
170 case 'n':
171 autopilot_parms.bearing_noise = (fixed)atof(optarg);
172 break;
173 case 't':
174 autopilot_parms.target_noise = (fixed)atof(optarg);
175 break;
176 case 'r':
177 autopilot_parms.turn_speed = (fixed)atof(optarg);
178 break;
179 case 'i':
180 if (optarg) {
181 interactive = atoi(optarg);
182 } else {
183 interactive = 1;
185 break;
186 case '?':
187 /* getopt_long already printed an error message. */
189 for (unsigned i=0; i+1< sizeof(long_options)/sizeof(option); i++) {
190 switch (long_options[i].has_arg) {
191 case 0:
192 printf(" --%s %c\n", long_options[i].name,
193 long_options[i].val);
194 break;
195 case 1:
196 printf(" --%s -%c value\n", long_options[i].name,
197 long_options[i].val);
198 break;
199 case 2:
200 printf(" --%s -%c [value]\n", long_options[i].name,
201 long_options[i].val);
204 abort();
205 return false;
206 break;
207 default:
208 return false;
212 if (interactive && !verbose) {
213 verbose=1;
216 return true;
219 const char* GetTestName(const char* in, int task_num, int wind_num)
221 static char buffer[80];
222 sprintf(buffer,"%s (task %s, wind %s)", in, task_name(task_num), wind_name(wind_num));
223 return buffer;