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;
33 { /* Process organisation */
34 slaves_count = argc - 4;
35 slaves = xbt_new(m_host_t, sizeof(m_host_t) * slaves_count);
37 for (i = 4; i < argc; i++) {
38 slaves[i-4] = MSG_get_host_by_name(argv[i]);
39 xbt_assert1(slaves[i-4]!=NULL, "Unknown host %s. Stopping Now! ", argv[i]);
41 /* Get the property list of the host */
42 props = MSG_host_get_properties(slaves[i-4]);
43 xbt_dict_cursor_t cursor=NULL;
46 /* Print the properties of the host */
47 xbt_dict_foreach(props,cursor,key,data) {
48 INFO3("Property: %s for host: %s has value: %s",key,argv[i],data);
51 /* Try to get a property that does not exist */
52 const char *noexist="Unknown";
53 const char*value = MSG_host_get_property_value(slaves[i-4], noexist);
55 INFO2("Property: %s for host %s is undefined", noexist, argv[i]);
57 INFO3("Property: %s for host %s has value: %s",(char*) noexist, argv[i], value);
59 /* Modify an existing property test. First check it exists */\
60 INFO0("Trying to modify a host property");
62 value = MSG_host_get_property_value(slaves[i-4],exist);
63 xbt_assert1(value,"\tProperty %s is undefined", exist);
64 INFO2("\tProperty: %s old value: %s", exist, value);
65 xbt_dict_set(props, exist, xbt_strdup("250"), free);
67 /* Test if we have changed the value */
68 value = MSG_host_get_property_value(slaves[i-4],exist);
69 xbt_assert1(value,"\tProperty %s is undefined", exist);
70 INFO2("\tProperty: %s new value: %s", exist, value);
78 /** Receiver function */
79 int slave(int argc, char *argv[])
81 /* Get the property list of current slave process */
82 xbt_dict_t props = MSG_process_get_properties(MSG_process_self());
83 xbt_dict_cursor_t cursor=NULL;
86 /* Print the properties of the process */
87 xbt_dict_foreach(props,cursor,key,data) {
88 INFO3("Property: %s for process %s has value: %s",key,MSG_process_get_name(MSG_process_self()),data);
91 /* Try to get a property that does not exist */
92 const char *noexist="UnknownProcessProp";
93 const char *value = MSG_process_get_property_value(MSG_process_self(),noexist);
95 INFO2("Property: %s for process %s is undefined", noexist, MSG_process_get_name(MSG_process_self()));
97 INFO3("Property: %s for process %s has value: %s", noexist, MSG_process_get_name(MSG_process_self()), value);
103 MSG_error_t test_all(const char *platform_file,
104 const char *application_file)
106 MSG_error_t res = MSG_OK;
108 /* MSG_config("surf_workstation_model","KCCFLN05"); */
109 { /* Simulation setting */
110 // MSG_set_channel_number(MAX_CHANNEL);
111 MSG_paje_output("msg_test.trace");
112 MSG_create_environment(platform_file);
114 { /* Application deployment */
115 MSG_function_register("master", master);
116 MSG_function_register("slave", slave);
117 MSG_launch_application(application_file);
121 INFO1("Simulation time %g",MSG_get_clock());
123 } /* end_of_test_all */
127 int main(int argc, char *argv[])
129 MSG_error_t res = MSG_OK;
131 MSG_global_init(&argc,argv);
133 printf ("Usage: %s platform_file deployment_file\n",argv[0]);
134 printf ("example: %s msg_platform.xml msg_deployment.xml\n",argv[0]);
137 res = test_all(argv[1],argv[2]);