1 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
2 // Copyright (c) Lawrence Livermore National Security, LLC and other Ascent
3 // Project developers. See top-level LICENSE AND COPYRIGHT files for dates and
4 // other details. No copyright assignment is required to contribute to Ascent.
5 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
6 
7 //-----------------------------------------------------------------------------
8 ///
9 /// file: t_ascent_web.cpp
10 ///
11 //-----------------------------------------------------------------------------
12 
13 
14 #include "gtest/gtest.h"
15 
16 #include <ascent.hpp>
17 
18 #include <iostream>
19 #include <math.h>
20 
21 #include <conduit_blueprint.hpp>
22 
23 #include "t_config.hpp"
24 #include "t_utils.hpp"
25 
26 using namespace std;
27 using namespace conduit;
28 using namespace ascent;
29 
30 
31 const float64 PI_VALUE = 3.14159265359;
32 
33 bool launch_server = false;
34 bool use_doc_root  = false;
35 std::string doc_root = "";
36 
37 #include <flow.hpp>
38 
39 //-----------------------------------------------------------------------------
TEST(ascent_web,test_ascent_main_web_launch)40 TEST(ascent_web, test_ascent_main_web_launch)
41 {
42     // this test launches a web server and infinitely streams images from
43     // ascent we  only run it if we passed proper command line arg
44     if(!launch_server)
45     {
46         return;
47     }
48 
49 
50     //
51     // Create example mesh.
52     //
53     Node data, verify_info;
54     conduit::blueprint::mesh::examples::braid("hexs",100,100,100,data);
55 
56     EXPECT_TRUE(conduit::blueprint::mesh::verify(data,verify_info));
57 
58     string output_path = prepare_output_dir();
59     string output_file = conduit::utils::join_file_path(output_path,"tout_render_3d_web_main_runtime");
60 
61     // remove old images before rendering
62     remove_test_image(output_file);
63 
64 
65     //
66     // Create the actions.
67     //
68 
69     conduit::Node scenes;
70     scenes["s1/plots/p1/type"]  = "pseudocolor";
71     scenes["s1/plots/p1/field"] = "braid";
72     scenes["s1/image_prefix"] = output_file;
73 
74 
75     conduit::Node actions;
76     conduit::Node &add_plots = actions.append();
77     add_plots["action"] = "add_scenes";
78     add_plots["scenes"] = scenes;
79     actions.print();
80 
81     // we want the "flow" runtime
82     Node open_opts;
83     open_opts["runtime/type"] = "ascent";
84     open_opts["web/stream"] = "true";
85     if(use_doc_root)
86     {
87         open_opts["web/document_root"] = doc_root;
88     }
89     open_opts["ascent_info"] = "verbose";
90 
91     Ascent ascent;
92     ascent.open(open_opts);
93 
94     uint64  *cycle_ptr = data["state/cycle"].value();
95     float64 *time_ptr  = data["state/time"].value();
96 
97     ascent.publish(data);
98     ascent.execute(actions);
99 
100     while(true)
101     {
102         cycle_ptr[0]+=1;
103         time_ptr[0] = PI_VALUE * cycle_ptr[0];
104         ASCENT_INFO(data["state"].to_json());
105         // publish the same mesh data, but update the state info
106         actions.reset();
107         ascent.publish(data);
108         ascent.execute(actions);
109         conduit::utils::sleep(1000);
110     }
111 
112     ascent.close();
113 }
114 
115 
116 //-----------------------------------------------------------------------------
main(int argc,char * argv[])117 int main(int argc, char* argv[])
118 {
119     int result = 0;
120 
121     ::testing::InitGoogleTest(&argc, argv);
122 
123     for(int i=0; i < argc ; i++)
124     {
125         std::string arg_str(argv[i]);
126         if(arg_str == "launch")
127         {
128             launch_server = true;;
129         }
130         else if(arg_str == "doc_root" && (i+1 < argc) )
131         {
132             use_doc_root = true;
133             doc_root = std::string(argv[i+1]);
134             i++;
135         }
136     }
137 
138     result = RUN_ALL_TESTS();
139     return result;
140 }
141 
142 
143