From aa21e04752d7b57bea7f50813607f237148f522b Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Fri, 22 Jan 2016 13:11:00 +0100 Subject: [PATCH] change argument testing method (100% coverage) --- examples/simdag/dax/dax_test.c | 28 +++++++------------ examples/simdag/properties/sd_prop.c | 19 ++++--------- examples/simdag/properties/test_prop.tesh | 2 +- examples/simdag/scheduling/minmin_test.c | 34 +++++++++-------------- examples/simdag/sd_comm_throttling.c | 7 ++--- examples/simdag/sd_test.c | 7 ++--- examples/simdag/sd_test2.c | 9 +++--- examples/simdag/sd_typed_tasks_test.c | 7 ++--- examples/simdag/simdag_trace.c | 7 ++--- 9 files changed, 42 insertions(+), 78 deletions(-) diff --git a/examples/simdag/dax/dax_test.c b/examples/simdag/dax/dax_test.c index 92b035d1e6..934d812824 100644 --- a/examples/simdag/dax/dax_test.c +++ b/examples/simdag/dax/dax_test.c @@ -35,25 +35,17 @@ int main(int argc, char **argv) SD_init(&argc, argv); /* Check our arguments */ - if (argc < 3) { - XBT_INFO("Usage: %s platform_file dax_file [trace_file]", argv[0]); - XBT_INFO - ("example: %s ../sd_platform.xml Montage_50.xml Montage_50.mytrace", - argv[0]); - exit(1); - } - char *tracefilename; - if (argc == 3) { - char *last = strrchr(argv[2], '.'); - - tracefilename = - bprintf("%.*s.trace", - (int) (last == NULL ? strlen(argv[2]) : last - argv[2]), - argv[2]); - } else { + xbt_assert(argc > 2, "Usage: %s platform_file dax_file [jedule_file]\n" + "\tExample: %s simulacrum_7_hosts.xml Montage_25.xml Montage_25.jed", + argv[0], argv[0]); + + char *last = strrchr(argv[2], '.'); + char * tracefilename = bprintf("%.*s.trace",(int) (last == NULL ? + strlen(argv[2]) : + last - argv[2]), argv[2]); + if (argc == 4) tracefilename = xbt_strdup(argv[3]); - } - + /* creation of the environment */ SD_create_environment(argv[1]); diff --git a/examples/simdag/properties/sd_prop.c b/examples/simdag/properties/sd_prop.c index f11a8378f9..a015ef9ab3 100644 --- a/examples/simdag/properties/sd_prop.c +++ b/examples/simdag/properties/sd_prop.c @@ -29,11 +29,10 @@ int main(int argc, char **argv) /* SD initialization */ SD_init(&argc, argv); - if (argc < 2) { - XBT_INFO("Usage: %s platform_file", argv[0]); - XBT_INFO("example: %s sd_platform.xml", argv[0]); - exit(1); - } + xbt_assert(argc > 1, + "Usage: %s platform_file\n\tExample: %s ../two_hosts.xml", + argv[0], argv[0]); + SD_create_environment(argv[1]); /* init of platform elements */ @@ -61,10 +60,7 @@ int main(int argc, char **argv) /* Try to get a property that does not exist */ value = SD_workstation_get_property_value(w1, noexist); - if (value == NULL) - XBT_INFO("\tProperty: %s is undefined", noexist); - else - XBT_INFO("\tProperty: %s has value: %s", noexist, value); + XBT_INFO("\tProperty: %s has value: %s", noexist, value?value:"Undefined (NULL)"); XBT_INFO("Property list for workstation %s", name2); @@ -90,10 +86,7 @@ int main(int argc, char **argv) /* Test if we have changed the value */ value = SD_workstation_get_property_value(w2, exist); - if (value == NULL) - XBT_INFO("\tProperty: %s is undefined", exist); - else - XBT_INFO("\tProperty: %s new value: %s", exist, value); + XBT_INFO("\tProperty: %s new value: %s", exist, value?value:"Undefined (NULL)"); /* Test if properties are displayed by SD_workstation_dump */ SD_workstation_dump(w2); diff --git a/examples/simdag/properties/test_prop.tesh b/examples/simdag/properties/test_prop.tesh index 5e3323e8df..0748d8d6dc 100755 --- a/examples/simdag/properties/test_prop.tesh +++ b/examples/simdag/properties/test_prop.tesh @@ -8,7 +8,7 @@ $ $SG_TEST_EXENV properties/sd_prop ${srcdir:=.}/../platforms/prop.xml > [0.000000] [test/INFO] Property: mem has value: 4 > [0.000000] [test/INFO] Property: NewProp has value: newValue > [0.000000] [test/INFO] Property: Hdd has value: 180 -> [0.000000] [test/INFO] Property: NoProp is undefined +> [0.000000] [test/INFO] Property: NoProp has value: Undefined (NULL) > [0.000000] [test/INFO] Property list for workstation host2 > [0.000000] [test/INFO] Property: Hdd on host: 120 > [0.000000] [test/INFO] Modify an existing property diff --git a/examples/simdag/scheduling/minmin_test.c b/examples/simdag/scheduling/minmin_test.c index 2d60522fe1..130baf2df2 100644 --- a/examples/simdag/scheduling/minmin_test.c +++ b/examples/simdag/scheduling/minmin_test.c @@ -107,10 +107,10 @@ static double finish_on_at(SD_task_t task, SD_workstation_t workstation) if (SD_task_get_kind(parent) == SD_TASK_COMM_E2E) { grand_parents = SD_task_get_parents(parent); - if (xbt_dynar_length(grand_parents) > 1) { - XBT_ERROR("Warning: transfer %s has 2 parents", - SD_task_get_name(parent)); - } + xbt_assert(xbt_dynar_length(grand_parents) <2, + "Error: transfer %s has 2 parents", + SD_task_get_name(parent)); + xbt_dynar_get_cpy(grand_parents, 0, &grand_parent); grand_parent_workstation_list = @@ -261,24 +261,16 @@ int main(int argc, char **argv) SD_init(&argc, argv); /* Check our arguments */ - if (argc < 3) { - XBT_INFO("Usage: %s platform_file dax_file [jedule_file]", argv[0]); - XBT_INFO - ("example: %s simulacrum_7_hosts.xml Montage_25.xml Montage_25.jed", - argv[0]); - exit(1); - } - char *tracefilename; - if (argc == 3) { - char *last = strrchr(argv[2], '.'); - - tracefilename = bprintf("%.*s.jed", - (int) (last == - NULL ? strlen(argv[2]) : last - - argv[2]), argv[2]); - } else { + xbt_assert(argc > 2, "Usage: %s platform_file dax_file [jedule_file]\n" + "\tExample: %s simulacrum_7_hosts.xml Montage_25.xml Montage_25.jed", + argv[0], argv[0]); + + char *last = strrchr(argv[2], '.'); + char * tracefilename = bprintf("%.*s.jed",(int) (last == NULL ? + strlen(argv[2]) : + last - argv[2]), argv[2]); + if (argc == 4) tracefilename = xbt_strdup(argv[3]); - } /* creation of the environment */ SD_create_environment(argv[1]); diff --git a/examples/simdag/sd_comm_throttling.c b/examples/simdag/sd_comm_throttling.c index 2b630631b9..260ef34874 100644 --- a/examples/simdag/sd_comm_throttling.c +++ b/examples/simdag/sd_comm_throttling.c @@ -26,11 +26,8 @@ int main(int argc, char **argv) /* xbt_log_control_set("sd.thres=debug"); */ - if (argc < 2) { - XBT_INFO("Usage: %s platform_file", argv[0]); - XBT_INFO("example: %s sd_platform.xml", argv[0]); - exit(1); - } + xbt_assert(argc > 1, "Usage: %s platform_file\n" + "\nExample: %s two_clusters.xml", argv[0], argv[0]); /* creation of the environment */ platform_file = argv[1]; diff --git a/examples/simdag/sd_test.c b/examples/simdag/sd_test.c index b56fe8bc42..291ae49950 100644 --- a/examples/simdag/sd_test.c +++ b/examples/simdag/sd_test.c @@ -42,11 +42,8 @@ int main(int argc, char **argv) /* xbt_log_control_set("sd.thres=debug"); */ - if (argc < 2) { - XBT_INFO("Usage: %s platform_file", argv[0]); - XBT_INFO("example: %s sd_platform.xml", argv[0]); - exit(1); - } + xbt_assert(argc > 1, "Usage: %s platform_file\n" + "\nExample: %s two_clusters.xml", argv[0], argv[0]); /* creation of the environment */ platform_file = argv[1]; diff --git a/examples/simdag/sd_test2.c b/examples/simdag/sd_test2.c index 0a9bf565c1..fa3e41338b 100644 --- a/examples/simdag/sd_test2.c +++ b/examples/simdag/sd_test2.c @@ -60,11 +60,10 @@ int main(int argc, char **argv) SD_init(&argc, argv); /* creation of the environment */ - if (strstr(argv[1],".xml")) - SD_create_environment(argv[1]); - else - xbt_die("Unsupported platform description style (not XML): %s", - argv[1]); + xbt_assert(strstr(argv[1],".xml"), + "Unsupported platform description style (not XML): %s", + argv[1]); + SD_create_environment(argv[1]); /* getting platform infos */ n_hosts = SD_workstation_get_count(); diff --git a/examples/simdag/sd_typed_tasks_test.c b/examples/simdag/sd_typed_tasks_test.c index 32f3e592ae..e8fe7b4a2f 100644 --- a/examples/simdag/sd_typed_tasks_test.c +++ b/examples/simdag/sd_typed_tasks_test.c @@ -32,11 +32,8 @@ int main(int argc, char **argv) /* xbt_log_control_set("sd.thres=debug"); */ - if (argc < 2) { - XBT_INFO("Usage: %s platform_file", argv[0]); - XBT_INFO("example: %s sd_platform.xml", argv[0]); - exit(1); - } + xbt_assert(argc > 1, "Usage: %s platform_file\n" + "\nExample: %s two_clusters.xml", argv[0], argv[0]); /* creation of the environment */ platform_file = argv[1]; diff --git a/examples/simdag/simdag_trace.c b/examples/simdag/simdag_trace.c index 9786b1f8b0..59953f5983 100644 --- a/examples/simdag/simdag_trace.c +++ b/examples/simdag/simdag_trace.c @@ -29,11 +29,8 @@ int main(int argc, char **argv) /* xbt_log_control_set("sd.thres=debug"); */ - if (argc < 2) { - XBT_INFO("Usage: %s platform_file", argv[0]); - XBT_INFO("example: %s sd_platform.xml", argv[0]); - exit(1); - } + xbt_assert(argc > 1, "Usage: %s platform_file\n" + "\nExample: %s two_clusters.xml", argv[0], argv[0]); /* creation of the environment */ platform_file = argv[1]; -- 2.20.1