Commit 1bfa3943 authored by Ian Craggs's avatar Ian Craggs

Add test4

parent 865591a9
...@@ -145,7 +145,7 @@ ...@@ -145,7 +145,7 @@
</target> </target>
<target name="test" > <target name="test" >
<foreach target="runAtest" param="aTest" list="test1"/> <foreach target="runAtest" param="aTest" list="test4"/>
</target> </target>
<target name="runAtest"> <target name="runAtest">
......
...@@ -60,10 +60,10 @@ struct Options ...@@ -60,10 +60,10 @@ struct Options
int size; /**< size of big message */ int size; /**< size of big message */
} options = } options =
{ {
"tcp://m2m.eclipse.org:1883", "m2m.eclipse.org:1883",
0, 0,
-1, -1,
5000000, 10000,
}; };
void getopts(int argc, char** argv) void getopts(int argc, char** argv)
...@@ -193,6 +193,7 @@ long elapsed(START_TIME_TYPE start_time) ...@@ -193,6 +193,7 @@ long elapsed(START_TIME_TYPE start_time)
START_TIME_TYPE global_start_time; START_TIME_TYPE global_start_time;
long duration;
#define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d) #define assert(a, b, c, d) myassert(__FILE__, __LINE__, a, b, c, d)
...@@ -201,7 +202,10 @@ START_TIME_TYPE global_start_time; ...@@ -201,7 +202,10 @@ START_TIME_TYPE global_start_time;
int tests = 0; int tests = 0;
int failures = 0; int failures = 0;
FILE* xml;
START_TIME_TYPE global_start_time;
char output[3000];
char* cur_output = output;
void myassert(char* filename, int lineno, char* description, int value, char* format, ...) void myassert(char* filename, int lineno, char* description, int value, char* format, ...)
{ {
...@@ -216,6 +220,9 @@ void myassert(char* filename, int lineno, char* description, int value, char* fo ...@@ -216,6 +220,9 @@ void myassert(char* filename, int lineno, char* description, int value, char* fo
va_start(args, format); va_start(args, format);
vprintf(format, args); vprintf(format, args);
va_end(args); va_end(args);
cur_output += sprintf(cur_output, "<failure type=\"%s\">file %s, line %d </failure>\n",
description, filename, lineno);
} }
else else
MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description); MyLog(LOGA_DEBUG, "Assertion succeeded, file %s, line %d, description: %s", filename, lineno, description);
...@@ -331,8 +338,9 @@ int test1(struct Options options) ...@@ -331,8 +338,9 @@ int test1(struct Options options)
int rc = 0; int rc = 0;
char* test_topic = "C client test1"; char* test_topic = "C client test1";
failures = 0;
MyLog(LOGA_INFO, "Starting test 1 - asynchronous connect"); MyLog(LOGA_INFO, "Starting test 1 - asynchronous connect");
fprintf(xml, "<testcase classname=\"test1\" name=\"asynchronous connect\"");
global_start_time = start_clock();
rc = MQTTAsync_create(&c, options.connection, "async_test", rc = MQTTAsync_create(&c, options.connection, "async_test",
MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
...@@ -381,6 +389,14 @@ exit: ...@@ -381,6 +389,14 @@ exit:
MyLog(LOGA_INFO, "TEST1: test %s. %d tests run, %d failures.", MyLog(LOGA_INFO, "TEST1: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", tests, failures); (failures == 0) ? "passed" : "failed", tests, failures);
duration = elapsed(global_start_time);
fprintf(xml, " time=\"%d.%.3d\" >\n", duration / 1000, duration % 1000);
if (cur_output != output)
{
fprintf(xml, output);
cur_output = output;
}
fprintf(xml, "</testcase>\n");
return failures; return failures;
} }
...@@ -422,6 +438,8 @@ int test2(struct Options options) ...@@ -422,6 +438,8 @@ int test2(struct Options options)
test_finished = 0; test_finished = 0;
MyLog(LOGA_INFO, "Starting test 2 - connect timeout"); MyLog(LOGA_INFO, "Starting test 2 - connect timeout");
fprintf(xml, "<testcase classname=\"test1\" name=\"connect timeout\"");
global_start_time = start_clock();
rc = MQTTAsync_create(&c, "tcp://9.20.96.160:66", "connect timeout", rc = MQTTAsync_create(&c, "tcp://9.20.96.160:66", "connect timeout",
MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
...@@ -474,6 +492,13 @@ exit: ...@@ -474,6 +492,13 @@ exit:
MyLog(LOGA_INFO, "TEST2: test %s. %d tests run, %d failures.", MyLog(LOGA_INFO, "TEST2: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", tests, failures); (failures == 0) ? "passed" : "failed", tests, failures);
fprintf(xml, " time=\"%d\" >\n", elapsed(global_start_time) / 1000);
if (cur_output != output)
{
fprintf(xml, output);
cur_output = output;
}
fprintf(xml, "</testcase>\n");
return failures; return failures;
} }
...@@ -631,6 +656,8 @@ int test3(struct Options options) ...@@ -631,6 +656,8 @@ int test3(struct Options options)
test_finished = 0; test_finished = 0;
MyLog(LOGA_INFO, "Starting test 3 - multiple connections"); MyLog(LOGA_INFO, "Starting test 3 - multiple connections");
fprintf(xml, "<testcase classname=\"test1\" name=\"asynchronous connect\"");
global_start_time = start_clock();
for (i = 0; i < num_clients; ++i) for (i = 0; i < num_clients; ++i)
{ {
...@@ -683,7 +710,13 @@ int test3(struct Options options) ...@@ -683,7 +710,13 @@ int test3(struct Options options)
exit: exit:
MyLog(LOGA_INFO, "TEST3: test %s. %d tests run, %d failures.", MyLog(LOGA_INFO, "TEST3: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", tests, failures); (failures == 0) ? "passed" : "failed", tests, failures);
fprintf(xml, " time=\"%d\" >\n", elapsed(global_start_time) / 1000);
if (cur_output != output)
{
fprintf(xml, output);
cur_output = output;
}
fprintf(xml, "</testcase>\n");
return failures; return failures;
} }
...@@ -818,6 +851,8 @@ int test4(struct Options options) ...@@ -818,6 +851,8 @@ int test4(struct Options options)
test_finished = failures = 0; test_finished = failures = 0;
MyLog(LOGA_INFO, "Starting test 4 - big messages"); MyLog(LOGA_INFO, "Starting test 4 - big messages");
fprintf(xml, "<testcase classname=\"test1\" name=\"big messages\"");
global_start_time = start_clock();
rc = MQTTAsync_create(&c, options.connection, "async_test_4", rc = MQTTAsync_create(&c, options.connection, "async_test_4",
MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
...@@ -865,7 +900,13 @@ int test4(struct Options options) ...@@ -865,7 +900,13 @@ int test4(struct Options options)
exit: exit:
MyLog(LOGA_INFO, "TEST4: test %s. %d tests run, %d failures.", MyLog(LOGA_INFO, "TEST4: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", tests, failures); (failures == 0) ? "passed" : "failed", tests, failures);
fprintf(xml, " time=\"%d\" >\n", elapsed(global_start_time) / 1000);
if (cur_output != output)
{
fprintf(xml, output);
cur_output = output;
}
fprintf(xml, "</testcase>\n");
return failures; return failures;
} }
...@@ -912,6 +953,8 @@ int test5(struct Options options) ...@@ -912,6 +953,8 @@ int test5(struct Options options)
test_finished = failures = 0; test_finished = failures = 0;
MyLog(LOGA_INFO, "Starting test 5 - connack return codes"); MyLog(LOGA_INFO, "Starting test 5 - connack return codes");
fprintf(xml, "<testcase classname=\"test1\" name=\"connack return codes\"");
global_start_time = start_clock();
rc = MQTTAsync_create(&c, options.connection, "a clientid that is too long to be accepted", rc = MQTTAsync_create(&c, options.connection, "a clientid that is too long to be accepted",
MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
...@@ -948,7 +991,13 @@ int test5(struct Options options) ...@@ -948,7 +991,13 @@ int test5(struct Options options)
exit: exit:
MyLog(LOGA_INFO, "TEST5: test %s. %d tests run, %d failures.", MyLog(LOGA_INFO, "TEST5: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", tests, failures); (failures == 0) ? "passed" : "failed", tests, failures);
fprintf(xml, " time=\"%d\" >\n", elapsed(global_start_time) / 1000);
if (cur_output != output)
{
fprintf(xml, output);
cur_output = output;
}
fprintf(xml, "</testcase>\n");
return failures; return failures;
} }
...@@ -996,6 +1045,8 @@ int test6(struct Options options) ...@@ -996,6 +1045,8 @@ int test6(struct Options options)
test_finished = failures = 0; test_finished = failures = 0;
MyLog(LOGA_INFO, "Starting test 7 - HA connections"); MyLog(LOGA_INFO, "Starting test 7 - HA connections");
fprintf(xml, "<testcase classname=\"test1\" name=\"HA connections\"");
global_start_time = start_clock();
rc = MQTTAsync_create(&c, options.connection, "a clientid that is too long to be accepted", rc = MQTTAsync_create(&c, options.connection, "a clientid that is too long to be accepted",
MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
...@@ -1034,7 +1085,13 @@ int test6(struct Options options) ...@@ -1034,7 +1085,13 @@ int test6(struct Options options)
exit: exit:
MyLog(LOGA_INFO, "TEST6: test %s. %d tests run, %d failures.", MyLog(LOGA_INFO, "TEST6: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", tests, failures); (failures == 0) ? "passed" : "failed", tests, failures);
fprintf(xml, " time=\"%d\" >\n", elapsed(global_start_time) / 1000);
if (cur_output != output)
{
fprintf(xml, output);
cur_output = output;
}
fprintf(xml, "</testcase>\n");
return failures; return failures;
} }
...@@ -1054,6 +1111,9 @@ int main(int argc, char** argv) ...@@ -1054,6 +1111,9 @@ int main(int argc, char** argv)
int (*tests[])() = {NULL, test1, test2, test3, test4, test5, test6}; /* indexed starting from 1 */ int (*tests[])() = {NULL, test1, test2, test3, test4, test5, test6}; /* indexed starting from 1 */
MQTTAsync_nameValue* info; MQTTAsync_nameValue* info;
xml = fopen("TEST-test4.xml", "w");
fprintf(xml, "<testsuite name=\"test4\" tests=\"%d\">\n", ARRAY_SIZE(tests) - 1);
getopts(argc, argv); getopts(argc, argv);
MQTTAsync_setTraceCallback(trace_callback); MQTTAsync_setTraceCallback(trace_callback);
...@@ -1080,10 +1140,13 @@ int main(int argc, char** argv) ...@@ -1080,10 +1140,13 @@ int main(int argc, char** argv)
rc = tests[options.test_no](options); /* run just the selected test */ rc = tests[options.test_no](options); /* run just the selected test */
} }
if (failures == 0) if (rc == 0)
MyLog(LOGA_INFO, "verdict pass"); MyLog(LOGA_INFO, "verdict pass");
else else
MyLog(LOGA_INFO, "verdict fail"); MyLog(LOGA_INFO, "verdict fail");
fprintf(xml, "</testsuite>\n");
fclose(xml);
return rc; return rc;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment