/
SimulationDumpJSONTest.cpp
1296 lines (1141 loc) · 42.9 KB
/
SimulationDumpJSONTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright (c) 2017. The WRENCH Team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
#include <gtest/gtest.h>
#include <wrench-dev.h>
#include <nlohmann/json.hpp>
#include "../../include/TestWithFork.h"
#include "../../include/UniqueTmpPathPrefix.h"
#include <fstream>
#include <algorithm>
/**********************************************************************/
/** SimulationDumpJSONTest **/
/**********************************************************************/
class SimulationDumpJSONTest : public ::testing::Test {
public:
wrench::WorkflowTask *t1 = nullptr;
wrench::WorkflowTask *t2 = nullptr;
wrench::WorkflowTask *t3 = nullptr;
wrench::WorkflowTask *t4 = nullptr;
void do_SimulationDumpWorkflowExecutionJSON_test();
void do_SimulationDumpWorkflowGraphJSON_test();
void do_SimulationSearchForHostUtilizationGraphLayout_test();
void do_SimulationDumpHostEnergyConsumptionJSON_test();
protected:
SimulationDumpJSONTest() {
// platform without energy consumption information
std::string xml = "<?xml version='1.0'?>"
"<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\">"
"<platform version=\"4.1\"> "
" <zone id=\"AS0\" routing=\"Full\"> "
" <host id=\"host1\" speed=\"1f\" core=\"10\"> "
" <prop id=\"ram\" value=\"10\"/>"
" </host>"
" <host id=\"host2\" speed=\"1f\" core=\"20\"> "
" <prop id=\"ram\" value=\"20\"/> "
" </host> "
" <link id=\"1\" bandwidth=\"1Gbps\" latency=\"1us\"/>"
" <route src=\"host1\" dst=\"host2\"> <link_ctn id=\"1\"/> </route>"
" </zone> "
"</platform>";
FILE *platform_file = fopen(platform_file_path.c_str(), "w");
fprintf(platform_file, "%s", xml.c_str());
fclose(platform_file);
// platform with energy consumption information
std::string xml2 = "<?xml version='1.0'?>"
"<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\">"
"<platform version=\"4.1\">"
"<zone id=\"AS0\" routing=\"Full\">"
"<host id=\"host1\" speed=\"100.0Mf,50.0Mf,20.0Mf\" pstate=\"1\" core=\"1\" >"
"<prop id=\"watt_per_state\" value=\"100.0:200.0, 93.0:170.0, 90.0:150.0\" />"
"<prop id=\"watt_off\" value=\"10\" />"
"</host>"
"<host id=\"host2\" speed=\"100.0Mf,50.0Mf,20.0Mf\" pstate=\"0\" core=\"1\" >"
"<prop id=\"watt_per_state\" value=\"100.0:200.0, 93.0:170.0, 90.0:150.0\" />"
"<prop id=\"watt_off\" value=\"10\" />"
"</host>"
"</zone>"
"</platform>";
FILE *platform_file2 = fopen(platform_file_path2.c_str(), "w");
fprintf(platform_file2, "%s", xml2.c_str());
fclose(platform_file2);
workflow = std::unique_ptr<wrench::Workflow>(new wrench::Workflow());
}
std::string platform_file_path = UNIQUE_TMP_PATH_PREFIX + "platform.xml";
std::string platform_file_path2 = UNIQUE_TMP_PATH_PREFIX + "platform2.xml";
std::string execution_data_json_file_path = UNIQUE_TMP_PATH_PREFIX + "workflow_data.json";
std::string workflow_graph_json_file_path = UNIQUE_TMP_PATH_PREFIX + "workflow_graph_data.json";
std::string energy_consumption_data_file_path = UNIQUE_TMP_PATH_PREFIX + "energy_consumption.json";
std::unique_ptr<wrench::Workflow> workflow;
};
// some comparison functions to be used when sorting lists of JSON objects so that the tests are deterministic
bool compareStartTimes(const nlohmann::json &lhs, const nlohmann::json &rhs) {
return lhs["whole_task"]["start"] < rhs["whole_task"]["start"];
}
bool compareTaskIDs(const nlohmann::json &lhs, const nlohmann::json &rhs) {
return lhs["task_id"] < rhs["task_id"];
}
bool compareNodes(const nlohmann::json &lhs, const nlohmann::json &rhs) {
return lhs["id"] < rhs["id"];
}
bool compareLinks(const nlohmann::json &lhs, const nlohmann::json &rhs) {
if (lhs["source"] < rhs["source"]) {
return true;
}
if (lhs["source"] > rhs["source"]) {
return false;
}
if (lhs["target"] < rhs["target"]) {
return true;
}
if (lhs["target"] > rhs["target"]) {
return false;
}
return false;
}
/**********************************************************************/
/** SimulationDumpWorkflowExecutionJSONTest **/
/**********************************************************************/
void SimulationDumpJSONTest::do_SimulationDumpWorkflowExecutionJSON_test() {
int argc = 1;
auto argv = (char **) calloc(1, sizeof(char *));
argv[0] = strdup("simulation_dump_workflow_execution_test");
std::unique_ptr<wrench::Simulation> simulation = std::unique_ptr<wrench::Simulation>(new wrench::Simulation());
simulation->init(&argc, argv);
simulation->instantiatePlatform(platform_file_path);
workflow = std::unique_ptr<wrench::Workflow>(new wrench::Workflow());
t1 = workflow->addTask("task1", 1, 1, 1, 1.0, 0);
t2 = workflow->addTask("task2", 1, 1, 1, 1.0, 0);
t1->setStartDate(1.0);
t1->setEndDate(2.0);
t1->setExecutionHost("host1");
t1->setNumCoresAllocated(8);
t1->setStartDate(2.0);
t1->setEndDate(3.0);
t1->setExecutionHost("host2");
t1->setNumCoresAllocated(10);
t2->setStartDate(3.0);
t2->setEndDate(4.0);
t2->setExecutionHost("host2");
t2->setNumCoresAllocated(20);
nlohmann::json expected_json = R"(
[
{
"compute": {
"end": -1.0,
"start": -1.0
},
"execution_host": {
"cores": 20,
"flop_rate": 1.0,
"hostname": "host2",
"memory": 20.0
},
"failed": -1.0,
"num_cores_allocated": 10,
"read": {
"end": -1.0,
"start": -1.0
},
"task_id": "task1",
"terminated": -1.0,
"vertical_position": 0,
"whole_task": {
"end": 3.0,
"start": 2.0
},
"write": {
"end": -1.0,
"start": -1.0
}
},
{
"compute": {
"end": -1.0,
"start": -1.0
},
"execution_host": {
"cores": 10,
"flop_rate": 1.0,
"hostname": "host1",
"memory": 10.0
},
"failed": -1.0,
"num_cores_allocated": 8,
"read": {
"end": -1.0,
"start": -1.0
},
"task_id": "task1",
"terminated": -1.0,
"vertical_position": 0,
"whole_task": {
"end": 2.0,
"start": 1.0
},
"write": {
"end": -1.0,
"start": -1.0
}
},
{
"compute": {
"end": -1.0,
"start": -1.0
},
"execution_host": {
"cores": 20,
"flop_rate": 1.0,
"hostname": "host2",
"memory": 20.0
},
"failed": -1.0,
"num_cores_allocated": 20,
"read": {
"end": -1.0,
"start": -1.0
},
"task_id": "task2",
"terminated": -1.0,
"vertical_position": 0,
"whole_task": {
"end": 4.0,
"start": 3.0
},
"write": {
"end": -1.0,
"start": -1.0
}
}
]
)"_json;
EXPECT_THROW(simulation->getOutput().dumpWorkflowExecutionJSON(nullptr, execution_data_json_file_path), std::invalid_argument);
EXPECT_THROW(simulation->getOutput().dumpWorkflowExecutionJSON(workflow.get(), ""), std::invalid_argument);
EXPECT_NO_THROW(simulation->getOutput().dumpWorkflowExecutionJSON(workflow.get(), execution_data_json_file_path, true));
std::ifstream json_file(execution_data_json_file_path);
nlohmann::json result_json;
json_file >> result_json;
/*
* nlohmann::json doesn't maintain order when you push_back json objects into a vector so, before
* comparing results with expected values, we sort the json lists so the test is deterministic.
*/
std::sort(result_json.begin(), result_json.end(), compareStartTimes);
std::sort(expected_json.begin(), expected_json.end(), compareStartTimes);
EXPECT_TRUE(result_json == expected_json);
free(argv[0]);
free(argv);
}
TEST_F(SimulationDumpJSONTest, SimulationDumpWorkflowExecutionJSONTest) {
DO_TEST_WITH_FORK(do_SimulationDumpWorkflowExecutionJSON_test);
}
/**********************************************************************/
/** SimulationSearchForHostUtilizationGraphLayout **/
/**********************************************************************/
void SimulationDumpJSONTest::do_SimulationSearchForHostUtilizationGraphLayout_test() {
int argc = 1;
auto argv = (char **) calloc(1, sizeof(char *));
argv[0] = strdup("simulation_search_for_host_utilization_graph_layout_test");
std::unique_ptr<wrench::Simulation> simulation = std::unique_ptr<wrench::Simulation>(new wrench::Simulation());
simulation->init(&argc, argv);
simulation->instantiatePlatform(platform_file_path);
std::ifstream json_file;
workflow = std::unique_ptr<wrench::Workflow>(new wrench::Workflow());
t1 = workflow->addTask("task1", 1, 1, 1, 1.0, 0);
t2 = workflow->addTask("task2", 1, 1, 1, 1.0, 0);
/*
* Two tasks run in parallel on a single host. Both use 5 out of the 10 cores.
* We expect the following vertical positions to be set:
* - task1: 0 (uses cores 0-4)
* - task2: 5 (uses cores 5-9)
*/
t1->setStartDate(1.0);
t1->setEndDate(2.0);
t1->setExecutionHost("host1");
t1->setNumCoresAllocated(5);
t2->setStartDate(1.0);
t2->setEndDate(2.0);
t2->setExecutionHost("host1");
t2->setNumCoresAllocated(5);
nlohmann::json expected_json1 = R"(
[
{
"compute": {
"end": -1.0,
"start": -1.0
},
"execution_host": {
"cores": 10,
"flop_rate": 1.0,
"hostname": "host1",
"memory": 10.0
},
"failed": -1.0,
"num_cores_allocated": 5,
"read": {
"end": -1.0,
"start": -1.0
},
"task_id": "task1",
"terminated": -1.0,
"vertical_position": 0,
"whole_task": {
"end": 2.0,
"start": 1.0
},
"write": {
"end": -1.0,
"start": -1.0
}
},
{
"compute": {
"end": -1.0,
"start": -1.0
},
"execution_host": {
"cores": 10,
"flop_rate": 1.0,
"hostname": "host1",
"memory": 10.0
},
"failed": -1.0,
"num_cores_allocated": 5,
"read": {
"end": -1.0,
"start": -1.0
},
"task_id": "task2",
"terminated": -1.0,
"vertical_position": 5,
"whole_task": {
"end": 2.0,
"start": 1.0
},
"write": {
"end": -1.0,
"start": -1.0
}
}
]
)"_json;
EXPECT_NO_THROW(simulation->getOutput().dumpWorkflowExecutionJSON(workflow.get(), execution_data_json_file_path, true));
json_file = std::ifstream(execution_data_json_file_path);
nlohmann::json result_json1;
json_file >> result_json1;
/*
* nlohmann::json doesn't maintain order when you push_back json objects into a vector so, before
* comparing results with expected values, we sort the json lists so the test is deterministic.
*/
std::sort(result_json1.begin(), result_json1.end(), compareTaskIDs);
std::sort(expected_json1.begin(), expected_json1.end(), compareTaskIDs);
EXPECT_TRUE(result_json1 == expected_json1);
workflow = std::unique_ptr<wrench::Workflow>(new wrench::Workflow);
t1 = workflow->addTask("task1", 1, 1, 1, 1.0, 0);
t2 = workflow->addTask("task2", 1, 1, 1, 1.0, 0);
/*
* Two tasks run, one after the other on host1. task2 starts at the same time that task1 ends.
* Both tasks should have a vertical position of 0.
*/
t1->setStartDate(1.0);
t1->setEndDate(2.0);
t1->setExecutionHost("host1");
t1->setNumCoresAllocated(5);
t2->setStartDate(2.0);
t2->setEndDate(3.0);
t2->setExecutionHost("host1");
t2->setNumCoresAllocated(5);
nlohmann::json expected_json2 = R"(
[
{
"compute": {
"end": -1.0,
"start": -1.0
},
"execution_host": {
"cores": 10,
"flop_rate": 1.0,
"hostname": "host1",
"memory": 10.0
},
"failed": -1.0,
"num_cores_allocated": 5,
"read": {
"end": -1.0,
"start": -1.0
},
"task_id": "task1",
"terminated": -1.0,
"vertical_position": 0,
"whole_task": {
"end": 2.0,
"start": 1.0
},
"write": {
"end": -1.0,
"start": -1.0
}
},
{
"compute": {
"end": -1.0,
"start": -1.0
},
"execution_host": {
"cores": 10,
"flop_rate": 1.0,
"hostname": "host1",
"memory": 10.0
},
"failed": -1.0,
"num_cores_allocated": 5,
"read": {
"end": -1.0,
"start": -1.0
},
"task_id": "task2",
"terminated": -1.0,
"vertical_position": 0,
"whole_task": {
"end": 3.0,
"start": 2.0
},
"write": {
"end": -1.0,
"start": -1.0
}
}
]
)"_json;
EXPECT_NO_THROW(simulation->getOutput().dumpWorkflowExecutionJSON(workflow.get(), execution_data_json_file_path, true));
json_file = std::ifstream(execution_data_json_file_path);
nlohmann::json result_json2;
json_file >> result_json2;
/*
* nlohmann::json doesn't maintain order when you push_back json objects into a vector so, before
* comparing results with expected values, we sort the json lists so the test is deterministic.
*/
std::sort(result_json2.begin(), result_json2.end(), compareTaskIDs);
std::sort(expected_json2.begin(), expected_json2.end(), compareTaskIDs);
EXPECT_TRUE(result_json2 == expected_json2);
workflow = std::unique_ptr<wrench::Workflow>(new wrench::Workflow);
t1 = workflow->addTask("task1", 1, 1, 1, 1.0, 0);
t2 = workflow->addTask("task2", 1, 1, 1, 1.0, 0);
t3 = workflow->addTask("task3", 1, 1, 1, 1.0, 0);
t4 = workflow->addTask("task4", 1, 1, 1, 1.0, 0);
/*
* Two hosts run two tasks each. We expect the following vertical positions to be set:
* - task1: 0
* - task2: 5
* - task3: 0
* - task4: 1
*/
t1->setStartDate(1.0);
t1->setEndDate(2.0);
t1->setExecutionHost("host1");
t1->setNumCoresAllocated(5);
t2->setStartDate(1.0);
t2->setEndDate(2.0);
t2->setExecutionHost("host1");
t2->setNumCoresAllocated(5);
t3->setStartDate(1.0);
t3->setEndDate(2.0);
t3->setExecutionHost("host2");
t3->setNumCoresAllocated(1);
t4->setStartDate(1.0);
t4->setEndDate(2.0);
t4->setExecutionHost("host2");
t4->setNumCoresAllocated(1);
nlohmann::json expected_json3 = R"(
[
{
"compute": {
"end": -1.0,
"start": -1.0
},
"execution_host": {
"cores": 10,
"flop_rate": 1.0,
"hostname": "host1",
"memory": 10.0
},
"failed": -1.0,
"num_cores_allocated": 5,
"read": {
"end": -1.0,
"start": -1.0
},
"task_id": "task1",
"terminated": -1.0,
"vertical_position": 0,
"whole_task": {
"end": 2.0,
"start": 1.0
},
"write": {
"end": -1.0,
"start": -1.0
}
},
{
"compute": {
"end": -1.0,
"start": -1.0
},
"execution_host": {
"cores": 10,
"flop_rate": 1.0,
"hostname": "host1",
"memory": 10.0
},
"failed": -1.0,
"num_cores_allocated": 5,
"read": {
"end": -1.0,
"start": -1.0
},
"task_id": "task2",
"terminated": -1.0,
"vertical_position": 5,
"whole_task": {
"end": 2.0,
"start": 1.0
},
"write": {
"end": -1.0,
"start": -1.0
}
},
{
"compute": {
"end": -1.0,
"start": -1.0
},
"execution_host": {
"cores": 20,
"flop_rate": 1.0,
"hostname": "host2",
"memory": 20.0
},
"failed": -1.0,
"num_cores_allocated": 1,
"read": {
"end": -1.0,
"start": -1.0
},
"task_id": "task3",
"terminated": -1.0,
"vertical_position": 0,
"whole_task": {
"end": 2.0,
"start": 1.0
},
"write": {
"end": -1.0,
"start": -1.0
}
},
{
"compute": {
"end": -1.0,
"start": -1.0
},
"execution_host": {
"cores": 20,
"flop_rate": 1.0,
"hostname": "host2",
"memory": 20.0
},
"failed": -1.0,
"num_cores_allocated": 1,
"read": {
"end": -1.0,
"start": -1.0
},
"task_id": "task4",
"terminated": -1.0,
"vertical_position": 1,
"whole_task": {
"end": 2.0,
"start": 1.0
},
"write": {
"end": -1.0,
"start": -1.0
}
}
]
)"_json;
EXPECT_NO_THROW(simulation->getOutput().dumpWorkflowExecutionJSON(workflow.get(), execution_data_json_file_path, true));
json_file = std::ifstream(execution_data_json_file_path);
nlohmann::json result_json3;
json_file >> result_json3;
/*
* nlohmann::json doesn't maintain order when you push_back json objects into a vector so, before
* comparing results with expected values, we sort the json lists so the test is deterministic.
*/
std::sort(result_json3.begin(), result_json3.end(), compareTaskIDs);
std::sort(expected_json3.begin(), expected_json3.end(), compareTaskIDs);
EXPECT_TRUE(result_json3 == expected_json3);
workflow = std::unique_ptr<wrench::Workflow>(new wrench::Workflow);
t1 = workflow->addTask("task1", 1, 1, 1, 1.0, 0);
t2 = workflow->addTask("task2", 1, 1, 1, 1.0, 0);
/*
* An execution that has no layout because we were possibly oversubscribed. std::runtime_error should be thrown.
*/
t1->setStartDate(1.0);
t1->setEndDate(2.0);
t1->setExecutionHost("host1");
t1->setNumCoresAllocated(10);
t2->setStartDate(1.0);
t2->setEndDate(2.0);
t2->setExecutionHost("host1");
t2->setNumCoresAllocated(10);
EXPECT_THROW(simulation->getOutput().dumpWorkflowExecutionJSON(workflow.get(), execution_data_json_file_path, true), std::runtime_error);
free(argv[0]);
free(argv);
}
TEST_F(SimulationDumpJSONTest, SimulationSearchForHostUtilizationGraphLayoutTest) {
DO_TEST_WITH_FORK(do_SimulationSearchForHostUtilizationGraphLayout_test);
}
/**********************************************************************/
/** SimulationDumpWorkflowGraphJSONTest **/
/**********************************************************************/
void SimulationDumpJSONTest::do_SimulationDumpWorkflowGraphJSON_test() {
int argc = 1;
auto argv = (char **) calloc(1, sizeof(char *));
argv[0] = strdup("simulation_dump_workflow_execution_test");
std::unique_ptr<wrench::Simulation> simulation = std::unique_ptr<wrench::Simulation>(new wrench::Simulation());
simulation->init(&argc, argv);
EXPECT_THROW(simulation->getOutput().dumpWorkflowGraphJSON(nullptr, UNIQUE_TMP_PATH_PREFIX + "file.json"), std::invalid_argument);
EXPECT_THROW(simulation->getOutput().dumpWorkflowGraphJSON((wrench::Workflow *)&argc, ""), std::invalid_argument);
std::ifstream graph_json_file;
// Generate a workflow with two independent tasks. Both tasks each have one input file and one output file.
std::unique_ptr<wrench::Workflow> independent_tasks_workflow = std::unique_ptr<wrench::Workflow>(new wrench::Workflow());
t1 = independent_tasks_workflow->addTask("task1", 1.0, 1, 1, 1.0, 0);
t1->addInputFile(independent_tasks_workflow->addFile("task1_input", 1.0));
t1->addOutputFile(independent_tasks_workflow->addFile("task1_output", 1.0));
t2 = independent_tasks_workflow->addTask("task2", 1.0, 1, 1, 1.0, 0);
t2->addInputFile(independent_tasks_workflow->addFile("task2_input", 1.0));
t2->addOutputFile(independent_tasks_workflow->addFile("task2_output", 1.0));
EXPECT_NO_THROW(simulation->getOutput().dumpWorkflowGraphJSON(independent_tasks_workflow.get(), workflow_graph_json_file_path));
nlohmann::json result_json1;
graph_json_file = std::ifstream(workflow_graph_json_file_path);
graph_json_file >> result_json1;
auto expected_json1 = R"(
{
"links": [
{
"source": "task1_input",
"target": "task1"
},
{
"source": "task1",
"target": "task1_output"
},
{
"source": "task2_input",
"target": "task2"
},
{
"source": "task2",
"target": "task2_output"
}
],
"nodes": [
{
"flops": 1.0,
"id": "task1",
"max_cores": 1,
"memory": 0.0,
"min_cores": 1,
"parallel_efficiency": 1.0,
"type": "task"
},
{
"flops": 1.0,
"id": "task2",
"max_cores": 1,
"memory": 0.0,
"min_cores": 1,
"parallel_efficiency": 1.0,
"type": "task"
},
{
"id": "task1_input",
"size": 1.0,
"type": "file"
},
{
"id": "task1_output",
"size": 1.0,
"type": "file"
},
{
"id": "task2_input",
"size": 1.0,
"type": "file"
},
{
"id": "task2_output",
"size": 1.0,
"type": "file"
}
]
})"_json;
/*
* nlohmann::json doesn't maintain order when you push_back json objects into a vector so, before
* comparing results with expected values, we sort the json lists so the test is deterministic.
*/
std::sort(result_json1["links"].begin(), result_json1["links"].end(), compareLinks);
std::sort(result_json1["nodes"].begin(), result_json1["nodes"].end(), compareNodes);
std::sort(expected_json1["links"].begin(), expected_json1["links"].end(), compareLinks);
std::sort(expected_json1["nodes"].begin(), expected_json1["nodes"].end(), compareNodes);
EXPECT_TRUE(result_json1 == expected_json1);
// Generate a workflow with two tasks, two input files, and four output files. Both tasks use both input files and produce two output files each.
std::unique_ptr<wrench::Workflow> two_tasks_use_all_files_workflow = std::unique_ptr<wrench::Workflow>(new wrench::Workflow());
t1 = two_tasks_use_all_files_workflow->addTask("task1", 1.0, 1, 1, 1.0, 0);
t1->addInputFile(two_tasks_use_all_files_workflow->addFile("input_file1", 1));
t1->addInputFile(two_tasks_use_all_files_workflow->addFile("input_file2", 2));
t1->addOutputFile(two_tasks_use_all_files_workflow->addFile("output_file1", 1));
t1->addOutputFile(two_tasks_use_all_files_workflow->addFile("output_file2", 2));
t2 = two_tasks_use_all_files_workflow->addTask("task2", 1.0, 1, 1, 1.0, 0);
for (auto &file : t1->getInputFiles()) {
t2->addInputFile(file);
}
t2->addOutputFile(two_tasks_use_all_files_workflow->addFile("output_file3", 1));
t2->addOutputFile(two_tasks_use_all_files_workflow->addFile("output_file4", 1));
EXPECT_NO_THROW(simulation->getOutput().dumpWorkflowGraphJSON(two_tasks_use_all_files_workflow.get(), workflow_graph_json_file_path));
nlohmann::json result_json2;
graph_json_file = std::ifstream(workflow_graph_json_file_path);
graph_json_file >> result_json2;
auto expected_json2 = R"(
{
"links": [
{
"source": "input_file1",
"target": "task1"
},
{
"source": "input_file2",
"target": "task1"
},
{
"source": "task1",
"target": "output_file1"
},
{
"source": "task1",
"target": "output_file2"
},
{
"source": "input_file1",
"target": "task2"
},
{
"source": "input_file2",
"target": "task2"
},
{
"source": "task2",
"target": "output_file3"
},
{
"source": "task2",
"target": "output_file4"
}
],
"nodes": [
{
"flops": 1.0,
"id": "task1",
"max_cores": 1,
"memory": 0.0,
"min_cores": 1,
"parallel_efficiency": 1.0,
"type": "task"
},
{
"flops": 1.0,
"id": "task2",
"max_cores": 1,
"memory": 0.0,
"min_cores": 1,
"parallel_efficiency": 1.0,
"type": "task"
},
{
"id": "input_file1",
"size": 1.0,
"type": "file"
},
{
"id": "input_file2",
"size": 2.0,
"type": "file"
},
{
"id": "output_file1",
"size": 1.0,
"type": "file"
},
{
"id": "output_file2",
"size": 2.0,
"type": "file"
},
{
"id": "output_file3",
"size": 1.0,
"type": "file"
},
{
"id": "output_file4",
"size": 1.0,
"type": "file"
}
]
})"_json;
/*
* nlohmann::json doesn't maintain order when you push_back json objects into a vector so, before
* comparing results with expected values, we sort the json lists so the test is deterministic.
*/
std::sort(result_json2["links"].begin(), result_json2["links"].end(), compareLinks);
std::sort(result_json2["nodes"].begin(), result_json2["nodes"].end(), compareNodes);
std::sort(expected_json2["links"].begin(), expected_json2["links"].end(), compareLinks);
std::sort(expected_json2["nodes"].begin(), expected_json2["nodes"].end(), compareNodes);
EXPECT_TRUE(result_json2 == expected_json2);
// Generate a workflow where one task forks into two tasks, then those two tasks join into one.
std::unique_ptr<wrench::Workflow> fork_join_workflow = std::unique_ptr<wrench::Workflow>(new wrench::Workflow());
t1 = fork_join_workflow->addTask("task1", 1.0, 1, 1, 1.0, 0);
t1->addInputFile(fork_join_workflow->addFile("task1_input", 1.0));
t1->addOutputFile(fork_join_workflow->addFile("task1_output1", 1.0));
t1->addOutputFile(fork_join_workflow->addFile("task1_output2", 1.0));
t2 = fork_join_workflow->addTask("task2", 1.0, 1, 1, 1.0, 0);
t2->addInputFile(fork_join_workflow->getFileByID("task1_output1"));
t2->addOutputFile(fork_join_workflow->addFile("task2_output1", 1.0));
fork_join_workflow->addControlDependency(t1, t2);
t3 = fork_join_workflow->addTask("task3", 1.0, 1, 1, 1.0, 0);
t3->addInputFile(fork_join_workflow->getFileByID("task1_output2"));
t3->addOutputFile(fork_join_workflow->addFile("task3_output1", 1.0));
fork_join_workflow->addControlDependency(t1, t3);
t4 = fork_join_workflow->addTask("task4", 1.0, 1, 1, 1.0, 0);
t4->addInputFile(fork_join_workflow->getFileByID("task2_output1"));
t4->addInputFile(fork_join_workflow->getFileByID("task3_output1"));
t4->addOutputFile(fork_join_workflow->addFile("task4_output1", 1.0));
fork_join_workflow->addControlDependency(t2, t4);
fork_join_workflow->addControlDependency(t3, t4);
EXPECT_NO_THROW(simulation->getOutput().dumpWorkflowGraphJSON(fork_join_workflow.get(), workflow_graph_json_file_path));
nlohmann::json result_json3;
graph_json_file = std::ifstream(workflow_graph_json_file_path);
graph_json_file >> result_json3;
auto expected_json3 = R"(
{
"links": [
{
"source": "task1_input",
"target": "task1"
},
{
"source": "task1",
"target": "task1_output1"
},
{
"source": "task1",
"target": "task1_output2"
},
{
"source": "task1_output1",
"target": "task2"
},
{
"source": "task2",
"target": "task2_output1"
},
{
"source": "task1_output2",
"target": "task3"
},
{
"source": "task3",
"target": "task3_output1"
},
{
"source": "task2_output1",
"target": "task4"
},
{
"source": "task3_output1",
"target": "task4"
},
{
"source": "task4",
"target": "task4_output1"
}