2 #include "test/ots_mm_udp_interface.h"
4 int main(
int argc,
char* argv[])
10 "usage: ots_mm_udp_test <mm IP> <mm Port> <Front-end UID> <FEMacro "
11 "Name> <Macro Input args...> \n");
13 "\t If <Front-end UID> not specified, then the list of existing FE UIDs "
16 "\t If <FEMacro Name> not specified, then the list of existing FE Macro "
17 "Names will be output associated with the specified FE UID\n");
19 "\t Note: use quotes around command line arguments with spaces to "
20 "prevent them from being interpreted as multiple arguments.\n");
24 std::string target_mm_ip = argv[1];
25 int target_mm_port = atoi(argv[2]);
27 __COUTV__(target_mm_ip);
28 __COUTV__(target_mm_port);
30 __COUT__ <<
"instantiating..." << __E__;
33 std::string feStr = mm.getFrontendList();
35 std::vector<std::string> fes = getVectorFromString(feStr, {
';'});
43 std::string target_fe = argv[3];
44 for(fe = 0; fe < fes.size(); ++fe)
45 if(fes[fe] == target_fe)
49 __COUT_ERR__ <<
"Illegal front-end UID " << target_fe
50 <<
" not found in FE list: " << vectorToString(fes, {
';'}) <<
"."
58 <<
"No front-end UID specified, here is the list of existing Front-end UIDs:"
60 for(fe = 0; fe < fes.size(); ++fe)
61 __COUT_ERR__ <<
"\t\t" << fes[fe] << __E__;
68 __COUT_ERR__ <<
"Illegal front-end index " << fe <<
" vs " << fes.size()
69 <<
" count." << __E__;
74 std::string commandStr = mm.getCommandList(fes[fe]);
75 __COUTV__(commandStr);
77 std::vector<std::string> commands = getVectorFromString(commandStr, {
';'});
82 std::string target_command = argv[4];
83 for(cmd = 0; cmd < commands.size(); ++cmd)
84 if(commands[cmd] == target_command)
86 if(cmd >= commands.size())
88 __COUT_ERR__ <<
"Illegal Front-end Macro Command name '" << target_command
89 <<
"' not found in '" << fes[fe]
90 <<
"' Command list: " << vectorToString(commands, {
';'}) <<
"."
97 __COUT_ERR__ <<
"No FE Macro Name specified, here is the list of existing FE "
98 "Macro Names corresponding to the specified Front-end UID '"
99 << argv[3] <<
"':" << __E__;
100 for(cmd = 0; cmd < commands.size(); ++cmd)
101 __COUT_ERR__ <<
"\t\t" << commands[cmd] << __E__;
106 if(cmd >= commands.size())
108 __COUT_ERR__ <<
"Illegal command index " << cmd <<
" vs " << commands.size()
109 <<
" count." << __E__;
113 __COUTV__(commands[cmd]);
115 uint32_t numberOfInputs = mm.getCommandInputCount(fes[fe], commands[cmd]);
116 __COUTV__(numberOfInputs);
118 uint32_t numberOfOutputs = mm.getCommandOutputCount(fes[fe], commands[cmd]);
119 __COUTV__(numberOfOutputs);
121 std::vector<std::string> inputs;
122 if(argc !=
int(5 + numberOfInputs))
125 <<
"Incorrect number of inputs provided for Front-end Macro Command name '"
126 << commands[cmd] <<
"' on FE UID '" << fes[fe] <<
"': " << argc - 5 <<
" vs "
127 << numberOfInputs <<
" expected." << __E__;
128 __COUT_INFO__ <<
"Will not run command." << __E__;
130 for(uint32_t i = 0; i < numberOfInputs; ++i)
132 std::string inputName = mm.getCommandInputName(fes[fe], commands[cmd], i);
133 __COUT_INFO__ <<
"\tExpected input #" << i + 1 <<
": " << inputName << __E__;
138 __COUTV__(vectorToString(inputs, {
';'}));
139 for(uint32_t i = 0; i < numberOfInputs; ++i)
141 inputs.push_back(ots_mm_udp_interface::encodeURIComponent(argv[5 + i]));
142 std::string inputName = mm.getCommandInputName(fes[fe], commands[cmd], i);
143 __COUT_INFO__ <<
"\tInput #" << i <<
": " << inputName <<
" = " << inputs.back()
147 __COUT_INFO__ <<
"Running command with these expected outputs..." << __E__;
148 for(uint32_t i = 0; i < numberOfOutputs; ++i)
150 std::string outputName = mm.getCommandOutputName(fes[fe], commands[cmd], i);
151 __COUT_INFO__ <<
"\tOutput #" << i <<
": " << outputName << __E__;
154 std::string commandResult =
155 mm.runCommand(fes[fe], commands[cmd], vectorToString(inputs, {
';'}));
157 std::vector<std::string> outputs = getVectorFromString(commandResult, {
';'});
159 if(numberOfOutputs != outputs.size())
161 __COUTV__(commandResult);
162 __COUT_ERR__ <<
"Illegal response, mismatch in output arguments returned: "
163 << outputs.size() <<
" vs " << numberOfOutputs <<
" expected."
168 __COUTV__(vectorToString(outputs, {
';'}));
169 for(uint32_t i = 0; i < numberOfOutputs; ++i)
171 std::string outputName = mm.getCommandOutputName(fes[fe], commands[cmd], i);
172 __COUT__ <<
"\tOutput #" << i <<
": " << outputName <<
" = "
173 << mm.decodeURIComponent(outputs[i]) << __E__;
175 __COUT_INFO__ <<
"Done." << __E__;
178 catch(
const std::runtime_error& e)
180 __COUT_ERR__ <<
"Error caught during test execution: \n" << e.what() << __E__;