aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern Brandenburg <bbb@mpi-sws.org>2016-07-25 12:50:59 -0400
committerBjoern Brandenburg <bbb@mpi-sws.org>2017-03-10 10:36:43 -0500
commit7e2cfc39e4014d0465d52dfb7eaf0c2b20aba13b (patch)
tree4addd1feaad13013ff6386a9d322afaa040f092b
parent9a3de35bbd507cd58e9116a9f8e214a0ed5fce36 (diff)
rtspin: improve argument handling
-rw-r--r--bin/rtspin.c43
1 files changed, 17 insertions, 26 deletions
diff --git a/bin/rtspin.c b/bin/rtspin.c
index 924a2c9..f647ff9 100644
--- a/bin/rtspin.c
+++ b/bin/rtspin.c
@@ -339,18 +339,18 @@ int main(int argc, char** argv)
339 wait = 1; 339 wait = 1;
340 break; 340 break;
341 case 'p': 341 case 'p':
342 cluster = atoi(optarg); 342 cluster = want_non_negative_int(optarg, "-p");
343 migrate = 1; 343 migrate = 1;
344 break; 344 break;
345 case 'r': 345 case 'r':
346 reservation = atoi(optarg); 346 reservation = want_non_negative_int(optarg, "-r");
347 break; 347 break;
348 case 'R': 348 case 'R':
349 create_reservation = 1; 349 create_reservation = 1;
350 reservation = getpid(); 350 reservation = getpid();
351 break; 351 break;
352 case 'q': 352 case 'q':
353 priority = atoi(optarg); 353 priority = want_non_negative_int(optarg, "-q");
354 if (!litmus_is_valid_fixed_prio(priority)) 354 if (!litmus_is_valid_fixed_prio(priority))
355 usage("Invalid priority."); 355 usage("Invalid priority.");
356 break; 356 break;
@@ -369,7 +369,7 @@ int main(int argc, char** argv)
369 background_loop = 1; 369 background_loop = 1;
370 break; 370 break;
371 case 'C': 371 case 'C':
372 column = atoi(optarg); 372 column = want_non_negative_int(optarg, "-C");
373 break; 373 break;
374 case 'F': 374 case 'F':
375 file = optarg; 375 file = optarg;
@@ -391,29 +391,23 @@ int main(int argc, char** argv)
391 linux_sleep = 1; 391 linux_sleep = 1;
392 break; 392 break;
393 case 'm': 393 case 'm':
394 nr_of_pages = atoi(optarg); 394 nr_of_pages = want_non_negative_int(optarg, "-m");
395 break; 395 break;
396 case 's': 396 case 's':
397 scale = atof(optarg); 397 scale = want_non_negative_double(optarg, "-s");
398 break; 398 break;
399 case 'o': 399 case 'o':
400 offset_ms = atof(optarg); 400 offset_ms = want_non_negative_double(optarg, "-o");
401 break; 401 break;
402 case 'd': 402 case 'd':
403 deadline_ms = atof(optarg); 403 deadline_ms = want_non_negative_double(optarg, "-d");
404 if (!deadline_ms || deadline_ms < 0) {
405 usage("The relative deadline must be a positive"
406 " number.");
407 }
408 break; 404 break;
409 case 'u': 405 case 'u':
410 underrun_ms = atof(optarg); 406 underrun_ms = want_positive_double(optarg, "-u");
411 if (underrun_ms <= 0)
412 usage("-u: positive argument needed.");
413 break; 407 break;
414 case 'U': 408 case 'U':
415 underrun_frac = atof(optarg); 409 underrun_frac = want_positive_double(optarg, "-U");
416 if (underrun_frac <= 0 || underrun_frac > 1) 410 if (underrun_frac > 1)
417 usage("-U: argument must be in the range (0, 1]"); 411 usage("-U: argument must be in the range (0, 1]");
418 break; 412 break;
419 case 'X': 413 case 'X':
@@ -422,14 +416,11 @@ int main(int argc, char** argv)
422 usage("Unknown locking protocol specified."); 416 usage("Unknown locking protocol specified.");
423 break; 417 break;
424 case 'L': 418 case 'L':
425 cs_length = atof(optarg); 419 cs_length = want_positive_double(optarg, "-L");
426 if (cs_length <= 0)
427 usage("Invalid critical section length.");
428 break; 420 break;
429 case 'Q': 421 case 'Q':
430 resource_id = atoi(optarg); 422 resource_id = want_non_negative_int(optarg, "-Q");
431 if (resource_id <= 0 && strcmp(optarg, "0")) 423
432 usage("Invalid resource ID.");
433 break; 424 break;
434 case 'v': 425 case 'v':
435 verbose = 1; 426 verbose = 1;
@@ -491,8 +482,8 @@ int main(int argc, char** argv)
491 if (argc - optind < 3 || (argc - optind < 2 && !file)) 482 if (argc - optind < 3 || (argc - optind < 2 && !file))
492 usage("Arguments missing."); 483 usage("Arguments missing.");
493 484
494 wcet_ms = atof(argv[optind + 0]); 485 wcet_ms = want_positive_double(argv[optind + 0], "WCET");
495 period_ms = atof(argv[optind + 1]); 486 period_ms = want_positive_double(argv[optind + 1], "PERIOD");
496 487
497 wcet = ms2ns(wcet_ms); 488 wcet = ms2ns(wcet_ms);
498 period = ms2ns(period_ms); 489 period = ms2ns(period_ms);
@@ -520,7 +511,7 @@ int main(int argc, char** argv)
520 * take duration from file. */ 511 * take duration from file. */
521 duration = num_jobs * period_ms * 0.001; 512 duration = num_jobs * period_ms * 0.001;
522 else 513 else
523 duration = atof(argv[optind + 2]); 514 duration = want_positive_double(argv[optind + 2], "DURATION");
524 515
525 if (underrun_frac) { 516 if (underrun_frac) {
526 underrun_ms = underrun_frac * wcet_ms; 517 underrun_ms = underrun_frac * wcet_ms;