Subversion Repositories tpanel

Rev

Rev 328 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 328 Rev 330
Line 43... Line 43...
43
using namespace dir;
43
using namespace dir;
44
 
44
 
45
atomic<bool> __success{false};
45
atomic<bool> __success{false};
46
atomic<bool> __done{false};
46
atomic<bool> __done{false};
47
bool _testmode{false};
47
bool _testmode{false};
-
 
48
bool _run_test_ready{false};
48
string gLastCommand;
49
string gLastCommand;
49
_TestMode *_gTestMode{nullptr};
50
_TestMode *_gTestMode{nullptr};
50
 
51
 
51
extern amx::TAmxNet *gAmxNet;
52
extern amx::TAmxNet *gAmxNet;
52
 
53
 
Line 112... Line 113...
112
void _TestMode::start()
113
void _TestMode::start()
113
{
114
{
114
    isRunning = true;
115
    isRunning = true;
115
    DECL_TRACER("_TestMode::start()");
116
    DECL_TRACER("_TestMode::start()");
116
 
117
 
-
 
118
    while (!_run_test_ready)
-
 
119
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
-
 
120
 
117
    vector<string>::iterator iter;
121
    vector<string>::iterator iter;
118
 
122
 
119
    for (iter = mCmdFiles.begin(); iter != mCmdFiles.end(); ++iter)
123
    for (iter = mCmdFiles.begin(); iter != mCmdFiles.end(); ++iter)
120
    {
124
    {
121
        _TESTCMD tcmd;
125
        _TESTCMD tcmd;
Line 123... Line 127...
123
        try
127
        try
124
        {
128
        {
125
            ifstream is(*iter);
129
            ifstream is(*iter);
126
            char buffer[4096];
130
            char buffer[4096];
127
            int line = 1;
131
            int line = 1;
-
 
132
            int port = 1;
-
 
133
            string command, content;
128
            tcmd.command.clear();
134
            tcmd.command.clear();
129
            tcmd.result.clear();
135
            tcmd.result.clear();
130
            tcmd.compare = false;
136
            tcmd.compare = false;
131
 
137
 
132
            while (is.getline(buffer, sizeof(buffer)))
138
            while (is.getline(buffer, sizeof(buffer)))
133
            {
139
            {
134
                if (buffer[0] == '#')
140
                if (buffer[0] == '#')
135
                    continue;
141
                    continue;
136
 
142
 
-
 
143
                string scmd(buffer);
-
 
144
                command.clear();
-
 
145
                content.clear();
137
                if (startsWith(buffer, "command="))
146
                size_t pos = scmd.find("=");
-
 
147
 
-
 
148
                // Parse the command line and extract the command and the content
-
 
149
                if (scmd == "exec")
-
 
150
                    command = scmd;
-
 
151
                else if (pos == string::npos)
-
 
152
                {
-
 
153
                    MSG_WARNING("Line " << line << ": Invalid or malformed command!");
-
 
154
                    continue;
-
 
155
                }
-
 
156
                else
138
                {
157
                {
139
                    string scmd(buffer);
158
                    command = scmd.substr(0, pos);
-
 
159
                    content = scmd.substr(pos + 1);
-
 
160
                }
140
 
161
 
-
 
162
                // Test for the command and take the desired action.
141
                    size_t pos = scmd.find("=");
163
                if (command == "command")
-
 
164
                {
142
                    tcmd.command = scmd.substr(pos + 1);
165
                    tcmd.command = content;
143
                }
166
                }
144
                else if (startsWith(buffer, "result="))
167
                else if (command == "port")
145
                {
168
                {
146
                    string scmd(buffer);
169
                    int p = atoi(content.c_str());
147
 
170
 
148
                    size_t pos = scmd.find("=");
171
                    if (p > 0)
149
                    tcmd.result = scmd.substr(pos + 1);
172
                        port = p;
150
                }
173
                }
151
                else if (startsWith(buffer, "compare="))
174
                else if (command == "result")
152
                {
175
                {
153
                    string scmd(buffer);
176
                    tcmd.result = content;
-
 
177
                }
-
 
178
                else if (command == "compare")
-
 
179
                {
-
 
180
                    tcmd.compare = isTrue(content);
-
 
181
                }
-
 
182
                else if (command == "wait")
-
 
183
                {
-
 
184
                    unsigned long ms = atol(content.c_str());
154
 
185
 
155
                    size_t pos = scmd.find("=");
186
                    if (ms != 0)
156
                    string res = scmd.substr(pos + 1);
187
                        std::this_thread::sleep_for(std::chrono::milliseconds(ms));
157
                    tcmd.compare = isTrue(res);
-
 
158
                }
188
                }
159
                else if (startsWith(buffer, "exec"))
189
                else if (command == "exec")
160
                {
190
                {
161
                    if (tcmd.command.empty())
191
                    if (tcmd.command.empty())
162
                    {
192
                    {
163
                       MSG_WARNING("Nothing to execute on line " << line << "!");
193
                       MSG_WARNING("Nothing to execute on line " << line << "!");
164
                       line++;
194
                       line++;
165
                       continue;
195
                       continue;
166
                    }
196
                    }
167
 
197
 
168
                    inform("Testing command: " + tcmd.command);
198
                    inform("Testing command: " + tcmd.command);
169
                    inject(1, tcmd.command);
199
                    inject(port, tcmd.command);
170
                    testSuccess(tcmd);
200
                    testSuccess(tcmd);
171
 
201
 
172
                    tcmd.command.clear();
202
                    tcmd.command.clear();
173
                    tcmd.result.clear();
203
                    tcmd.result.clear();
174
                    tcmd.compare = false;
204
                    tcmd.compare = false;
-
 
205
                    port = 1;
175
                }
206
                }
176
 
207
 
177
                line++;
208
                line++;
178
            }
209
            }
179
 
210
 
Line 183... Line 214...
183
        {
214
        {
184
            MSG_ERROR("Error on file " << *iter << ": " << e.what());
215
            MSG_ERROR("Error on file " << *iter << ": " << e.what());
185
            continue;
216
            continue;
186
        }
217
        }
187
    }
218
    }
188
/*
-
 
189
    inform("Testing command: ^MUT-1");
-
 
190
    inject(1, "^MUT-1");
-
 
191
    testSuccess();
-
 
192
 
219
 
193
    inform("Testing command: ^MUT-0");
-
 
194
    inject(1, "^MUT-0");
-
 
195
    testSuccess();
-
 
196
*/
-
 
197
    isRunning = false;
220
    isRunning = false;
198
    delete this;
221
    delete this;
199
}
222
}
200
 
223
 
201
void _TestMode::inject(int port, const string& c)
224
void _TestMode::inject(int port, const string& c)