- Timestamp:
- 02/13/07 09:22:14 (17 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/streaming-rework/tests/test-timestampedbuffer.cpp
r392 r393 73 73 uint64_t total_cycles; 74 74 uint64_t buffersize; 75 uint64_t start_at_cycle; 75 76 }; 76 77 … … 84 85 {"cycles", 'c', "n", 0, "Total cycles to run (2000)" }, 85 86 {"buffersize", 'b', "n", 0, "Buffer size (in frames) (1024)" }, 87 {"startcycle", 's', "n", 0, "Start at cycle (0)" }, 86 88 { 0 } 87 89 }; … … 101 103 case 'v': 102 104 if (arg) { 103 arguments->verbose = strtol ( arg, &tail, 0 );105 arguments->verbose = strtoll( arg, &tail, 0 ); 104 106 if ( errno ) { 105 107 fprintf( stderr, "Could not parse 'verbose' argument\n" ); … … 115 117 case 'w': 116 118 if (arg) { 117 arguments->wrap_at = strtol ( arg, &tail, 0 );119 arguments->wrap_at = strtoll( arg, &tail, 0 ); 118 120 if ( errno ) { 119 121 fprintf( stderr, "Could not parse 'wrap' argument\n" ); … … 129 131 case 'f': 130 132 if (arg) { 131 arguments->frames_per_packet = strtol ( arg, &tail, 0 );133 arguments->frames_per_packet = strtoll( arg, &tail, 0 ); 132 134 if ( errno ) { 133 135 fprintf( stderr, "Could not parse 'fpp' argument\n" ); … … 143 145 case 'e': 144 146 if (arg) { 145 arguments->events_per_frame = strtol ( arg, &tail, 0 );147 arguments->events_per_frame = strtoll( arg, &tail, 0 ); 146 148 if ( errno ) { 147 149 fprintf( stderr, "Could not parse 'epf' argument\n" ); … … 157 159 case 'c': 158 160 if (arg) { 159 arguments->total_cycles = strtol ( arg, &tail, 0 );161 arguments->total_cycles = strtoll( arg, &tail, 0 ); 160 162 if ( errno ) { 161 163 fprintf( stderr, "Could not parse 'cycles' argument\n" ); … … 169 171 } 170 172 break; 173 case 's': 174 if (arg) { 175 arguments->start_at_cycle = strtoll( arg, &tail, 0 ); 176 if ( errno ) { 177 fprintf( stderr, "Could not parse 'startcycle' argument\n" ); 178 return ARGP_ERR_UNKNOWN; 179 } 180 } else { 181 if ( errno ) { 182 fprintf( stderr, "Could not parse 'startcycle' argument\n" ); 183 return ARGP_ERR_UNKNOWN; 184 } 185 } 186 break; 171 187 case 'b': 172 188 if (arg) { 173 arguments->buffersize = strtol ( arg, &tail, 0 );189 arguments->buffersize = strtoll( arg, &tail, 0 ); 174 190 if ( errno ) { 175 191 fprintf( stderr, "Could not parse 'buffersize' argument\n" ); … … 228 244 arguments.total_cycles = 2000; 229 245 arguments.buffersize = 1024; 246 arguments.start_at_cycle = 0; 230 247 231 248 // Parse our arguments; every option seen by `parse_opt' will … … 275 292 276 293 usleep(1000); 294 295 debugOutput(DEBUG_LEVEL_NORMAL, "Start test 1...\n"); 277 296 278 297 int dummyframe_in[arguments.events_per_frame*arguments.frames_per_packet]; … … 283 302 } 284 303 285 uint64_t timestamp=0; 304 uint64_t time=arguments.start_at_cycle*3072; 305 306 // initialize the timestamp 307 uint64_t timestamp=time; 308 if (timestamp >= arguments.wrap_at) { 309 // here we need a modulo because start_at_cycle can be large 310 timestamp %= arguments.wrap_at; 311 } 286 312 t->setBufferTailTimestamp(timestamp); 313 287 314 timestamp += (uint64_t)(arguments.rate * arguments.frames_per_packet); 288 289 uint64_t time=0; 315 if (timestamp >= arguments.wrap_at) { 316 timestamp -= arguments.wrap_at; 317 } 290 318 291 for(unsigned int cycle=0;cycle < arguments.total_cycles; cycle++) { 319 for(unsigned int cycle=arguments.start_at_cycle; 320 cycle < arguments.start_at_cycle+arguments.total_cycles; 321 cycle++) { 322 292 323 // simulate the rate adaptation 293 int64_t diff= time-timestamp;324 int64_t diff=(time%arguments.wrap_at)-timestamp; 294 325 295 326 if (diff>(int64_t)arguments.wrap_at/2) { … … 302 333 303 334 if(diff>0) { 335 uint64_t ts_head, fc_head; 336 uint64_t ts_tail, fc_tail; 337 304 338 // write one packet 305 339 t->writeFrames(arguments.frames_per_packet, (char *)&dummyframe_in, timestamp); 306 340 341 // read the buffer head timestamp 342 t->getBufferHeadTimestamp(&ts_head, &fc_head); 343 t->getBufferTailTimestamp(&ts_tail, &fc_tail); 344 debugOutput(DEBUG_LEVEL_NORMAL, 345 " TS after write: HEAD: %011llu, FC=%04u\n", 346 ts_head,fc_head); 347 debugOutput(DEBUG_LEVEL_NORMAL, 348 " TAIL: %011llu, FC=%04u\n", 349 ts_tail,fc_tail); 350 307 351 // read one packet 308 352 t->readFrames(arguments.frames_per_packet, (char *)&dummyframe_out); 309 353 354 // read the buffer head timestamp 355 t->getBufferHeadTimestamp(&ts_head, &fc_head); 356 t->getBufferTailTimestamp(&ts_tail, &fc_tail); 357 debugOutput(DEBUG_LEVEL_NORMAL, 358 " TS after write: HEAD: %011llu, FC=%04u\n", 359 ts_head,fc_head); 360 debugOutput(DEBUG_LEVEL_NORMAL, 361 " TAIL: %011llu, FC=%04u\n", 362 ts_tail,fc_tail); 363 310 364 // check 311 365 bool pass=true; … … 315 369 if (!pass) { 316 370 debugOutput(DEBUG_LEVEL_NORMAL, "write/read check for cycle %d failed\n",cycle); 371 } 372 373 // update the timestamp 374 timestamp += (uint64_t)(arguments.rate * arguments.frames_per_packet); 375 if (timestamp >= arguments.wrap_at) { 376 timestamp -= arguments.wrap_at; 377 } 378 } 379 380 // simulate the cycle timer clock in ticks 381 time += 3072; 382 if (time >= arguments.wrap_at) { 383 time -= arguments.wrap_at; 384 } 385 386 // allow for the messagebuffer thread to catch up 387 usleep(200); 388 389 if(!run) break; 390 } 391 392 // second run, now do block processing 393 debugOutput(DEBUG_LEVEL_NORMAL, "Start test 2...\n"); 394 unsigned int blocksize=32; 395 int dummyframe_out_block[arguments.events_per_frame*arguments.frames_per_packet*blocksize]; 396 397 time=arguments.start_at_cycle*3072; 398 399 // initialize the timestamp 400 timestamp=time; 401 if (timestamp >= arguments.wrap_at) { 402 // here we need a modulo because start_at_cycle can be large 403 timestamp %= arguments.wrap_at; 404 } 405 t->setBufferTailTimestamp(timestamp); 406 407 timestamp += (uint64_t)(arguments.rate * arguments.frames_per_packet); 408 if (timestamp >= arguments.wrap_at) { 409 timestamp -= arguments.wrap_at; 410 } 411 412 for(unsigned int cycle=arguments.start_at_cycle; 413 cycle < arguments.start_at_cycle+arguments.total_cycles; 414 cycle++) { 415 416 // simulate the rate adaptation 417 int64_t diff=(time%arguments.wrap_at)-timestamp; 418 419 if (diff>(int64_t)arguments.wrap_at/2) { 420 diff -= arguments.wrap_at; 421 } else if (diff<(-(int64_t)arguments.wrap_at)/2){ 422 diff += arguments.wrap_at; 423 } 424 425 debugOutput(DEBUG_LEVEL_NORMAL, "Simulating cycle %d @ time=%011llu, diff=%lld\n",cycle,time,diff); 426 427 if(diff>0) { 428 uint64_t ts_head, fc_head; 429 uint64_t ts_tail, fc_tail; 430 431 // write one packet 432 t->writeFrames(arguments.frames_per_packet, (char *)&dummyframe_in, timestamp); 433 434 // read the buffer head timestamp 435 t->getBufferHeadTimestamp(&ts_head, &fc_head); 436 t->getBufferTailTimestamp(&ts_tail, &fc_tail); 437 debugOutput(DEBUG_LEVEL_NORMAL, 438 " TS after write: HEAD: %011llu, FC=%04u\n", 439 ts_head,fc_head); 440 debugOutput(DEBUG_LEVEL_NORMAL, 441 " TAIL: %011llu, FC=%04u\n", 442 ts_tail,fc_tail); 443 444 if (fc_head > blocksize) { 445 debugOutput(DEBUG_LEVEL_NORMAL,"Reading one block (%u frames)\n",blocksize); 446 447 // read one block 448 t->readFrames(blocksize, (char *)&dummyframe_out_block); 449 450 // read the buffer head timestamp 451 t->getBufferHeadTimestamp(&ts_head, &fc_head); 452 t->getBufferTailTimestamp(&ts_tail, &fc_tail); 453 debugOutput(DEBUG_LEVEL_NORMAL, 454 " TS after read: HEAD: %011llu, FC=%04u\n", 455 ts_head,fc_head); 456 debugOutput(DEBUG_LEVEL_NORMAL, 457 " TAIL: %011llu, FC=%04u\n", 458 ts_tail,fc_tail); 317 459 } 318 460 … … 323 465 } 324 466 } 325 467 326 468 // simulate the cycle timer clock in ticks 327 469 time += 3072; … … 332 474 // allow for the messagebuffer thread to catch up 333 475 usleep(200); 334 335 } 476 477 if(!run) break; 478 } 479 336 480 337 481 delete t;