3 /* Copyright (c) 2002,2004,2004 Arnaud Legrand. 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. */
9 * \brief Test program for msg.
14 /** This flag enable the debugging messages from PRINT_DEBUG_MESSAGE() */
18 int unix_emitter(int argc, char *argv[]);
19 int unix_receiver(int argc, char *argv[]);
20 int unix_forwarder(int argc, char *argv[]);
21 void test_all(const char *platform_file, const char *application_file);
24 /** The names of the channels we will use in this simulation. There is
25 only one channel identified by the name PORT_22. */
31 void print_args(int argc, char** argv);
32 void print_args(int argc, char** argv)
38 fprintf(stderr,"%s ",argv[i]);
39 fprintf(stderr,">\n");
42 /** The number of task each slave will process */
44 int unix_emitter(int argc, char *argv[])
47 m_host_t *slaves = NULL;
49 m_task_t *todo = NULL;
53 print_args(argc,argv);
55 { /* Process organisation */
56 slaves_count = argc - 1;
57 slaves = calloc(slaves_count, sizeof(m_host_t));
59 for (i = 1; i < argc; i++) {
60 slaves[i-1] = MSG_get_host_by_name(argv[i]);
61 if(slaves[i-1]==NULL) {
62 PRINT_MESSAGE("Unknown host %s. Stopping Now! \n", argv[i]);
69 char sprintf_buffer[64];
70 int slave = slaves_count;
72 todo = calloc(NB_TASK * slave, sizeof(m_task_t));
73 todo_count = NB_TASK * slave;
75 for (i = 0; i < NB_TASK * slave; i++) {
76 sprintf(sprintf_buffer, "Task_%d", i);
77 todo[i] = MSG_task_create(sprintf_buffer, 5000, 10, NULL);
81 PRINT_MESSAGE("Got %d slave(s) :\n", slaves_count);
82 for (i = 0; i < slaves_count; i++)
83 PRINT_MESSAGE("\t %s\n", slaves[i]->name);
85 PRINT_MESSAGE("Got %d task to process :\n", todo_count);
87 for (i = 0; i < todo_count; i++)
88 PRINT_MESSAGE("\t\"%s\"\n", todo[i]->name);
90 for (i = 0; i < todo_count; i++) {
91 PRINT_MESSAGE("Sending \"%s\" to \"%s\"\n",
93 slaves[i % slaves_count]->name);
94 MSG_task_put(todo[i], slaves[i % slaves_count],
96 PRINT_MESSAGE("Send completed\n");
104 int unix_receiver(int argc, char *argv[])
107 m_task_t *todo = (m_task_t *) calloc(NB_TASK, sizeof(m_task_t));
110 print_args(argc,argv);
112 for (i = 0; i < NB_TASK;) {
114 PRINT_MESSAGE("Awaiting Task %d \n", i);
115 a = MSG_task_get(&(todo[i]), PORT_22);
118 PRINT_MESSAGE("Received \"%s\" \n", todo[i]->name);
119 PRINT_MESSAGE("Processing \"%s\" \n", todo[i]->name);
120 MSG_task_execute(todo[i]);
121 PRINT_MESSAGE("\"%s\" done \n", todo[i]->name);
122 MSG_task_destroy(todo[i]);
125 PRINT_MESSAGE("Hey ?! What's up ? \n");
126 DIE("Unexpected behaviour");
130 PRINT_MESSAGE("I'm done. See you!\n");
135 int unix_forwarder(int argc, char *argv[])
138 m_task_t *todo = (m_task_t *) calloc(NB_TASK, sizeof(m_task_t));
141 print_args(argc,argv);
143 for (i = 0; i < NB_TASK;) {
145 PRINT_MESSAGE("Awaiting Task %d \n", i);
146 a = MSG_task_get(&(todo[i]), PORT_22);
149 PRINT_MESSAGE("Received \"%s\" \n", todo[i]->name);
150 PRINT_MESSAGE("Processing \"%s\" \n", todo[i]->name);
151 MSG_task_execute(todo[i]);
152 PRINT_MESSAGE("\"%s\" done \n", todo[i]->name);
153 MSG_task_destroy(todo[i]);
156 PRINT_MESSAGE("Hey ?! What's up ? \n");
157 DIE("Unexpected behaviour");
161 PRINT_MESSAGE("I'm done. See you!\n");
166 void test_all(const char *platform_file,const char *application_file)
168 { /* Simulation setting */
169 MSG_set_channel_number(MAX_CHANNEL);
170 MSG_create_environment(platform_file);
172 { /* Application deployment */
173 MSG_function_register("master", unix_emitter);
174 MSG_function_register("slave", unix_receiver);
175 MSG_launch_application(application_file);
178 printf("Simulation time %Lg\n",MSG_getClock());
181 int main(int argc, char *argv[])
183 MSG_global_init_args(&argc,argv);
184 test_all("msg_platform.xml","msg_deployment.xml");