1 /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */
8 #include "xbt/sysdep.h" /* calloc, printf */
10 /* Create a log channel to have nice outputs. */
12 #include "xbt/asserts.h"
17 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Property test");
19 int alice(int argc, char *argv[]);
20 int bob(int argc, char *argv[]);
21 int carole(int argc, char *argv[]);
22 int forwarder(int argc, char *argv[]);
23 MSG_error_t test_all(const char *platform_file,
24 const char *application_file);
26 static void test_host(const char*hostname)
28 m_host_t thehost = MSG_get_host_by_name(hostname);
29 xbt_dict_t props = MSG_host_get_properties(thehost);
30 xbt_dict_cursor_t cursor = NULL;
32 const char *noexist = "Unknown";
34 char exist[] = "SG_TEST_Hdd";
36 XBT_INFO("== Print the properties of the host");
37 xbt_dict_foreach(props, cursor, key, data)
38 XBT_INFO(" Host property: '%s' -> '%s'", key, data);
40 XBT_INFO("== Try to get a host property that does not exist");
41 value = MSG_host_get_property_value(thehost, noexist);
42 xbt_assert(!value, "The key exists (it's not supposed to)");
44 XBT_INFO("== Try to get a host property that does exist");
45 value = MSG_host_get_property_value(thehost, exist);
46 xbt_assert(value, "\tProperty %s is undefined (where it should)",
48 xbt_assert(!strcmp(value, "180"),
49 "\tValue of property %s is defined to %s (where it should be 180)",
51 XBT_INFO(" Property: %s old value: %s", exist, value);
53 XBT_INFO("== Trying to modify a host property");
54 xbt_dict_set(props, exist, xbt_strdup("250"), NULL);
56 /* Test if we have changed the value */
57 value = MSG_host_get_property_value(thehost, exist);
58 xbt_assert(value, "Property %s is undefined (where it should)", exist);
59 xbt_assert(!strcmp(value, "250"),
60 "Value of property %s is defined to %s (where it should be 250)",
62 XBT_INFO(" Property: %s old value: %s", exist, value);
64 /* Restore the value for the next test */
65 xbt_dict_set(props, exist, xbt_strdup("180"), NULL);
68 int alice(int argc, char *argv[]) { /* Dump what we have on the current host */
72 int carole(int argc, char *argv[]) {/* Dump what we have on a remote host */
73 MSG_process_sleep(1); // Wait for alice to be done with its experiment
78 int bob(int argc, char *argv[])
80 /* Get the property list of current bob process */
81 xbt_dict_t props = MSG_process_get_properties(MSG_process_self());
82 xbt_dict_cursor_t cursor = NULL;
84 const char *noexist = "UnknownProcessProp";
85 _XBT_GNUC_UNUSED const char *value;
87 XBT_INFO("== Print the properties of the process");
88 xbt_dict_foreach(props, cursor, key, data)
89 XBT_INFO(" Process property: %s -> %s", key, data);
91 XBT_INFO("== Try to get a process property that does not exist");
93 value = MSG_process_get_property_value(MSG_process_self(), noexist);
94 xbt_assert(!value, "The property is defined (it shouldnt)");
100 MSG_error_t test_all(const char *platform_file,
101 const char *application_file)
103 MSG_function_register("alice", alice);
104 MSG_function_register("bob", bob);
105 MSG_function_register("carole", carole);
107 MSG_create_environment(platform_file);
108 MSG_launch_application(application_file);
111 } /* end_of_test_all */
115 int main(int argc, char *argv[])
117 MSG_error_t res = MSG_OK;
119 MSG_global_init(&argc, argv);
121 printf("Usage: %s platform_file deployment_file\n", argv[0]);
122 printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
125 res = test_all(argv[1], argv[2]);