Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Implement functions SD_task_dependency_add and SD_task_dependency_remove.
[simgrid.git] / testsuite / simdag / sd_test.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "simdag/simdag.h"
4 #include "xbt/ex.h"
5
6 int main(int argc, char **argv) {
7   
8   /* No deployment file
9   if (argc < 3) {
10      printf ("Usage: %s platform_file deployment_file\n", argv[0]);
11      printf ("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
12      exit(1);
13   }
14   */
15
16   if (argc < 2) {
17      printf ("Usage: %s platform_file\n", argv[0]);
18      printf ("example: %s msg_platform.xml\n", argv[0]);
19      exit(1);
20   }
21
22   /* initialisation of SD */
23   SD_init(&argc, argv);
24
25   /* creation of the environment */
26   char * platform_file = argv[1];
27   SD_create_environment(platform_file);
28
29   /* creation of the tasks and their dependencies */
30   SD_task_t volatile taskA = SD_task_create("Task A", NULL, 10.0);
31   SD_task_t volatile taskB = SD_task_create("Task B", NULL, 40.0);
32   SD_task_t volatile taskC = SD_task_create("Task C", NULL, 30.0);
33
34   SD_task_dependency_add(NULL, NULL, taskA, taskB);
35   SD_task_dependency_add(NULL, NULL, taskA, taskC);
36
37   xbt_ex_t ex;
38
39   TRY {
40     SD_task_dependency_add(NULL, NULL, taskA, taskA); /* shouldn't work and must raise an exception */
41     xbt_assert0(0, "Hey, I can add a dependency between Task A and Task A!");
42   }
43   CATCH (ex) {
44   }
45   
46   TRY {
47     SD_task_dependency_add(NULL, NULL, taskA, taskB); /* shouldn't work and must raise an exception */
48     xbt_assert0(0, "Oh oh, I can add an already existing dependency!");
49   }
50   CATCH (ex) {
51   }
52
53   SD_task_dependency_remove(taskA, taskB);
54
55   TRY {
56     SD_task_dependency_remove(taskC, taskA); /* shouldn't work and must raise an exception */
57     xbt_assert0(0, "Dude, I can remove an unknown dependency!");
58   }
59   CATCH (ex) {
60   }
61
62   TRY {
63     SD_task_dependency_remove(taskC, taskC); /* shouldn't work and must raise an exception */
64     xbt_assert0(0, "Wow, I can remove a dependency between Task C and itself!");
65   }
66   CATCH (ex) {
67   }
68   /* if everything is ok, no exception is forwarded or rethrown by main() */
69
70   /* watch points */
71   SD_task_watch(taskA, SD_SCHEDULED);
72   SD_task_watch(taskA, SD_DONE);
73   SD_task_unwatch(taskA, SD_SCHEDULED);
74   SD_task_watch(taskA, SD_DONE);
75   SD_task_watch(taskA, SD_SCHEDULED);
76   
77   /* let's launch the simulation! */
78   SD_simulate(100);
79
80   SD_task_destroy(taskA);
81   SD_task_destroy(taskB);
82   SD_task_destroy(taskC);
83   SD_exit();
84   return 0;
85 }