3 /* Copyright (c) 2007. SimGrid Team. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */
9 #include "xbt/sysdep.h" /* calloc, printf */
11 /* Create a log channel to have nice outputs. */
13 #include "xbt/asserts.h"
18 XBT_LOG_NEW_DEFAULT_CATEGORY(test,"Property test");
20 int master(int argc, char *argv[]);
21 int slave(int argc, char *argv[]);
22 int forwarder(int argc, char *argv[]);
23 MSG_error_t test_all(const char *platform_file, const char *application_file);
25 /** Emitter function */
26 int master(int argc, char *argv[])
29 m_host_t *slaves = NULL;
31 xbt_dict_cursor_t cursor=NULL;
34 const char *noexist="Unknown";
38 { /* Process organisation */
39 slaves_count = argc - 4;
40 slaves = xbt_new(m_host_t, sizeof(m_host_t) * slaves_count);
42 for (i = 4; i < argc; i++) {
43 slaves[i-4] = MSG_get_host_by_name(argv[i]);
44 xbt_assert1(slaves[i-4]!=NULL, "Unknown host %s. Stopping Now! ", argv[i]);
46 /* Get the property list of the host */
47 props = MSG_host_get_properties(slaves[i-4]);
51 /* Print the properties of the host */
52 xbt_dict_foreach(props,cursor,key,data) {
53 INFO3("Property: %s for host: %s has value: %s",key,argv[i],data);
56 /* Try to get a property that does not exist */
58 value = MSG_host_get_property_value(slaves[i-4], noexist);
60 INFO2("Property: %s for host %s is undefined", noexist, argv[i]);
62 INFO3("Property: %s for host %s has value: %s",(char*) noexist, argv[i], value);
64 /* Modify an existing property test. First check it exists */\
65 INFO0("Trying to modify a host property");
67 value = MSG_host_get_property_value(slaves[i-4],exist);
68 xbt_assert1(value,"\tProperty %s is undefined", exist);
69 INFO2("\tProperty: %s old value: %s", exist, value);
70 xbt_dict_set(props, exist, xbt_strdup("250"), free);
72 /* Test if we have changed the value */
73 value = MSG_host_get_property_value(slaves[i-4],exist);
74 xbt_assert1(value,"\tProperty %s is undefined", exist);
75 INFO2("\tProperty: %s new value: %s", exist, value);
83 /** Receiver function */
84 int slave(int argc, char *argv[])
86 /* Get the property list of current slave process */
87 xbt_dict_t props = MSG_process_get_properties(MSG_process_self());
88 xbt_dict_cursor_t cursor=NULL;
90 const char *noexist="UnknownProcessProp";
93 /* Print the properties of the process */
94 xbt_dict_foreach(props,cursor,key,data) {
95 INFO3("Property: %s for process %s has value: %s",key,MSG_process_get_name(MSG_process_self()),data);
98 /* Try to get a property that does not exist */
100 value = MSG_process_get_property_value(MSG_process_self(),noexist);
102 INFO2("Property: %s for process %s is undefined", noexist, MSG_process_get_name(MSG_process_self()));
104 INFO3("Property: %s for process %s has value: %s", noexist, MSG_process_get_name(MSG_process_self()), value);
110 MSG_error_t test_all(const char *platform_file,
111 const char *application_file)
113 MSG_error_t res = MSG_OK;
115 /* MSG_config("surf_workstation_model","KCCFLN05"); */
116 { /* Simulation setting */
117 // MSG_set_channel_number(MAX_CHANNEL);
118 MSG_paje_output("msg_test.trace");
119 MSG_create_environment(platform_file);
121 { /* Application deployment */
122 MSG_function_register("master", master);
123 MSG_function_register("slave", slave);
124 MSG_launch_application(application_file);
128 INFO1("Simulation time %g",MSG_get_clock());
130 } /* end_of_test_all */
134 int main(int argc, char *argv[])
136 MSG_error_t res = MSG_OK;
138 MSG_global_init(&argc,argv);
140 printf ("Usage: %s platform_file deployment_file\n",argv[0]);
141 printf ("example: %s msg_platform.xml msg_deployment.xml\n",argv[0]);
144 res = test_all(argv[1],argv[2]);