Commit 037e0068 authored by Ian Craggs's avatar Ian Craggs

Add test reporting for all tests

parent 342e70ff
...@@ -161,7 +161,7 @@ ...@@ -161,7 +161,7 @@
<target name="test" > <target name="test" >
<foreach target="runAtest" param="aTest" list="test1,test4"/> <foreach target="runAtest" param="aTest" list="test1,test4"/>
<foreach target="runSSLtest" param="aTest" list="test3"/> <foreach target="runSSLtest" param="aTest" list="test3,test5"/>
</target> </target>
<target name="runAtest"> <target name="runAtest">
......
...@@ -456,21 +456,21 @@ int SSLSocket_setSocketForSSL(networkHandles* net, MQTTClient_SSLOptions* opts) ...@@ -456,21 +456,21 @@ int SSLSocket_setSocketForSSL(networkHandles* net, MQTTClient_SSLOptions* opts)
if (net->ctx != NULL || (rc = SSLSocket_createContext(net, opts)) == 1) if (net->ctx != NULL || (rc = SSLSocket_createContext(net, opts)) == 1)
{ {
int i; int i;
SSL_CTX_set_info_callback(net->ctx, SSL_CTX_info_callback); SSL_CTX_set_info_callback(net->ctx, SSL_CTX_info_callback);
if (opts->enableServerCertAuth) if (opts->enableServerCertAuth)
SSL_CTX_set_verify(net->ctx, SSL_VERIFY_PEER, NULL); SSL_CTX_set_verify(net->ctx, SSL_VERIFY_PEER, NULL);
net->ssl = SSL_new(net->ctx); net->ssl = SSL_new(net->ctx);
/* Log all ciphers available to the SSL sessions (loaded in ctx) */ /* Log all ciphers available to the SSL sessions (loaded in ctx) */
for (i = 0; ;i++) for (i = 0; ;i++)
{ {
const char* cipher = SSL_get_cipher_list(net->ssl, i); const char* cipher = SSL_get_cipher_list(net->ssl, i);
if (cipher == NULL) break; if (cipher == NULL)
Log(TRACE_MIN, 1, "SSL cipher available: %d:%s", i, cipher); break;
} Log(TRACE_MIN, 1, "SSL cipher available: %d:%s", i, cipher);
}
if ((rc = SSL_set_fd(net->ssl, net->socket)) != 1) if ((rc = SSL_set_fd(net->ssl, net->socket)) != 1)
SSLSocket_error("SSL_set_fd", net->ssl, net->socket, rc); SSLSocket_error("SSL_set_fd", net->ssl, net->socket, rc);
} }
...@@ -486,11 +486,11 @@ int SSLSocket_connect(SSL* ssl, int sock) ...@@ -486,11 +486,11 @@ int SSLSocket_connect(SSL* ssl, int sock)
FUNC_ENTRY; FUNC_ENTRY;
rc = SSL_connect(ssl); rc = SSL_connect(ssl);
if (rc != 1) if (rc != 1)
{ {
int error; int error;
error = SSLSocket_error("SSL_connect", ssl, sock, rc); error = SSLSocket_error("SSL_connect", ssl, sock, rc);
if (error == SSL_FATAL) if (error == SSL_FATAL)
rc = error; rc = error;
} }
......
...@@ -217,6 +217,21 @@ START_TIME_TYPE global_start_time; ...@@ -217,6 +217,21 @@ START_TIME_TYPE global_start_time;
char output[3000]; char output[3000];
char* cur_output = output; char* cur_output = output;
void write_test_result()
{
long 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");
}
void myassert(char* filename, int lineno, char* description, int value, char* format, ...) void myassert(char* filename, int lineno, char* description, int value, char* format, ...)
{ {
++tests; ++tests;
...@@ -377,14 +392,7 @@ int test1(struct Options options) ...@@ -377,14 +392,7 @@ int test1(struct Options options)
exit: 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);
write_test_result();
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;
} }
...@@ -540,14 +548,7 @@ int test2(struct Options options) ...@@ -540,14 +548,7 @@ int test2(struct Options options)
exit: exit:
MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.", MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", testname, tests, failures); (failures == 0) ? "passed" : "failed", testname, tests, failures);
write_test_result();
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;
} }
...@@ -627,14 +628,7 @@ int test3(struct Options options) ...@@ -627,14 +628,7 @@ int test3(struct Options options)
/* TODO - unused - remove ? exit: */ /* TODO - unused - remove ? exit: */
MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.", MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", testname, tests, failures); (failures == 0) ? "passed" : "failed", testname, tests, failures);
write_test_result();
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;
} }
...@@ -875,14 +869,7 @@ int test5(struct Options options) ...@@ -875,14 +869,7 @@ int test5(struct Options options)
exit: exit:
MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.", MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", testname, tests, failures); (failures == 0) ? "passed" : "failed", testname, tests, failures);
write_test_result();
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;
} }
...@@ -1113,14 +1100,7 @@ int test6(struct Options options) ...@@ -1113,14 +1100,7 @@ int test6(struct Options options)
exit: exit:
MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.\n", MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.\n",
(failures == 0) ? "passed" : "failed", testname, tests, failures); (failures == 0) ? "passed" : "failed", testname, tests, failures);
write_test_result();
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;
} }
...@@ -1129,10 +1109,12 @@ int main(int argc, char** argv) ...@@ -1129,10 +1109,12 @@ int main(int argc, char** argv)
int rc = 0; int rc = 0;
int (*tests[])() = {NULL, test1, test2, test3, test4, test5, test6}; int (*tests[])() = {NULL, test1, test2, test3, test4, test5, test6};
xml = fopen("TEST-test1.xml", "w"); xml = fopen("TEST-test1.xml", "w");
fprintf(xml, "<testsuite name=\"test1\" tests=\"%d\">\n", ARRAY_SIZE(tests) - 1); fprintf(xml, "<testsuite name=\"test1\" tests=\"%d\">\n", ARRAY_SIZE(tests) - 1);
setenv("MQTT_C_CLIENT_TRACE", "ON", 1);
setenv("MQTT_C_CLIENT_TRACE_LEVEL", "ERROR", 1);
getopts(argc, argv); getopts(argc, argv);
if (options.test_no == 0) if (options.test_no == 0)
......
...@@ -352,12 +352,12 @@ FILE* xml; ...@@ -352,12 +352,12 @@ FILE* xml;
START_TIME_TYPE global_start_time; START_TIME_TYPE global_start_time;
char output[3000]; char output[3000];
char* cur_output = output; char* cur_output = output;
long duration;
void write_test_result() void write_test_result()
{ {
duration = elapsed(global_start_time); long duration = elapsed(global_start_time);
fprintf(xml, " time=\"%d.%.3d\" >\n", duration / 1000, duration % 1000); fprintf(xml, " time=\"%d.%.3d\" >\n", duration / 1000, duration % 1000);
if (cur_output != output) if (cur_output != output)
{ {
......
...@@ -191,15 +191,9 @@ long elapsed(START_TIME_TYPE start_time) ...@@ -191,15 +191,9 @@ long elapsed(START_TIME_TYPE start_time)
} }
#endif #endif
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)
#define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e) #define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e)
int tests = 0; int tests = 0;
int failures = 0; int failures = 0;
FILE* xml; FILE* xml;
...@@ -207,6 +201,19 @@ START_TIME_TYPE global_start_time; ...@@ -207,6 +201,19 @@ START_TIME_TYPE global_start_time;
char output[3000]; char output[3000];
char* cur_output = output; char* cur_output = output;
void write_test_result()
{
long 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");
}
void myassert(char* filename, int lineno, char* description, int value, char* format, ...) void myassert(char* filename, int lineno, char* description, int value, char* format, ...)
{ {
++tests; ++tests;
...@@ -388,15 +395,7 @@ int test1(struct Options options) ...@@ -388,15 +395,7 @@ int test1(struct Options options)
exit: 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);
write_test_result();
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;
} }
...@@ -491,14 +490,7 @@ exit: ...@@ -491,14 +490,7 @@ 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);
duration = elapsed(global_start_time); write_test_result();
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;
} }
...@@ -710,14 +702,7 @@ int test3(struct Options options) ...@@ -710,14 +702,7 @@ 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);
duration = elapsed(global_start_time); write_test_result();
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;
} }
...@@ -901,14 +886,7 @@ int test4(struct Options options) ...@@ -901,14 +886,7 @@ 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);
duration = elapsed(global_start_time); write_test_result();
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;
} }
...@@ -993,14 +971,7 @@ int test5(struct Options options) ...@@ -993,14 +971,7 @@ 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);
duration = elapsed(global_start_time); write_test_result();
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;
} }
...@@ -1088,14 +1059,7 @@ int test6(struct Options options) ...@@ -1088,14 +1059,7 @@ 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);
duration = elapsed(global_start_time); write_test_result();
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;
} }
......
...@@ -233,7 +233,6 @@ long elapsed(START_TIME_TYPE start_time) ...@@ -233,7 +233,6 @@ long elapsed(START_TIME_TYPE start_time)
return (res.tv_sec) * 1000 + (res.tv_usec) / 1000; return (res.tv_sec) * 1000 + (res.tv_usec) / 1000;
} }
#endif #endif
START_TIME_TYPE global_start_time;
#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)
#define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e) #define assert1(a, b, c, d, e) myassert(__FILE__, __LINE__, a, b, c, d, e)
...@@ -242,6 +241,24 @@ START_TIME_TYPE global_start_time; ...@@ -242,6 +241,24 @@ 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 write_test_result()
{
long 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");
}
void myassert(char* filename, int lineno, char* description, int value, void myassert(char* filename, int lineno, char* description, int value,
char* format, ...) char* format, ...)
...@@ -576,6 +593,8 @@ int test1(struct Options options) ...@@ -576,6 +593,8 @@ int test1(struct Options options)
test1Finished = 0; test1Finished = 0;
failures = 0; failures = 0;
MyLog(LOGA_INFO, "Starting SSL test 1 - connection to nonSSL MQTT server"); MyLog(LOGA_INFO, "Starting SSL test 1 - connection to nonSSL MQTT server");
fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
global_start_time = start_clock();
snprintf(url, 100, "ssl://%s:1883", options.connection); snprintf(url, 100, "ssl://%s:1883", options.connection);
rc = MQTTAsync_create(&c, url, "test1", MQTTCLIENT_PERSISTENCE_DEFAULT, rc = MQTTAsync_create(&c, url, "test1", MQTTCLIENT_PERSISTENCE_DEFAULT,
...@@ -625,7 +644,7 @@ int test1(struct Options options) ...@@ -625,7 +644,7 @@ int test1(struct Options options)
exit: MQTTAsync_destroy(&c); exit: MQTTAsync_destroy(&c);
MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.", MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", testname, tests, failures); (failures == 0) ? "passed" : "failed", testname, tests, failures);
write_test_result();
return failures; return failures;
} }
...@@ -669,8 +688,10 @@ int test2a(struct Options options) ...@@ -669,8 +688,10 @@ int test2a(struct Options options)
int i; int i;
failures = 0; failures = 0;
MyLog(LOGA_INFO, "Starting test 2a - Mutual SSL authentication"); MyLog(LOGA_INFO, "Starting test 2a - Mutual SSL authentication");
fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
global_start_time = start_clock();
snprintf(url, 100, "ssl://%s:8883", options.connection); snprintf(url, 100, "ssl://%s:8883", options.connection);
MQTTAsync_create(&c, url, "test2a", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); MQTTAsync_create(&c, url, "test2a", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc); assert("good rc from create", rc == MQTTASYNC_SUCCESS, "rc was %d\n", rc);
...@@ -741,7 +762,7 @@ int test2a(struct Options options) ...@@ -741,7 +762,7 @@ int test2a(struct Options options)
exit: MQTTAsync_destroy(&c); exit: MQTTAsync_destroy(&c);
MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.", MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", testname, tests, failures); (failures == 0) ? "passed" : "failed", testname, tests, failures);
write_test_result();
return failures; return failures;
} }
...@@ -786,6 +807,8 @@ int test2b(struct Options options) ...@@ -786,6 +807,8 @@ int test2b(struct Options options)
MyLog( MyLog(
LOGA_INFO, LOGA_INFO,
"Starting test 2b - connection to SSL MQTT server with clientauth=req but server does not have client cert"); "Starting test 2b - connection to SSL MQTT server with clientauth=req but server does not have client cert");
fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
global_start_time = start_clock();
snprintf(url, 100, "ssl://%s:8884", options.connection); snprintf(url, 100, "ssl://%s:8884", options.connection);
rc = MQTTAsync_create(&c, url, "test2b", MQTTCLIENT_PERSISTENCE_DEFAULT, rc = MQTTAsync_create(&c, url, "test2b", MQTTCLIENT_PERSISTENCE_DEFAULT,
...@@ -837,7 +860,7 @@ int test2b(struct Options options) ...@@ -837,7 +860,7 @@ int test2b(struct Options options)
exit: MQTTAsync_destroy(&c); exit: MQTTAsync_destroy(&c);
MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.", MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", testname, tests, failures); (failures == 0) ? "passed" : "failed", testname, tests, failures);
write_test_result();
return failures; return failures;
} }
...@@ -882,6 +905,8 @@ int test2c(struct Options options) ...@@ -882,6 +905,8 @@ int test2c(struct Options options)
MyLog( MyLog(
LOGA_INFO, LOGA_INFO,
"Starting test 2c - connection to SSL MQTT server, server auth enabled but unknown cert"); "Starting test 2c - connection to SSL MQTT server, server auth enabled but unknown cert");
fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
global_start_time = start_clock();
snprintf(url, 100, "ssl://%s:8883", options.connection); snprintf(url, 100, "ssl://%s:8883", options.connection);
rc = MQTTAsync_create(&c, url, "test2c", MQTTCLIENT_PERSISTENCE_DEFAULT, rc = MQTTAsync_create(&c, url, "test2c", MQTTCLIENT_PERSISTENCE_DEFAULT,
...@@ -935,7 +960,7 @@ int test2c(struct Options options) ...@@ -935,7 +960,7 @@ int test2c(struct Options options)
exit: MQTTAsync_destroy(&c); exit: MQTTAsync_destroy(&c);
MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.", MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", testname, tests, failures); (failures == 0) ? "passed" : "failed", testname, tests, failures);
write_test_result();
return failures; return failures;
} }
...@@ -972,6 +997,9 @@ int test3a(struct Options options) ...@@ -972,6 +997,9 @@ int test3a(struct Options options)
failures = 0; failures = 0;
MyLog(LOGA_INFO, "Starting test 3a - Server authentication"); MyLog(LOGA_INFO, "Starting test 3a - Server authentication");
fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
global_start_time = start_clock();
snprintf(url, 100, "ssl://%s:8885", options.connection); snprintf(url, 100, "ssl://%s:8885", options.connection);
MQTTAsync_create(&c, url, "test3a", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); MQTTAsync_create(&c, url, "test3a", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
...@@ -1058,7 +1086,7 @@ int test3a(struct Options options) ...@@ -1058,7 +1086,7 @@ int test3a(struct Options options)
exit: MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.", (failures exit: MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.", (failures
== 0) ? "passed" : "failed", testname, tests, failures); == 0) ? "passed" : "failed", testname, tests, failures);
write_test_result();
return failures; return failures;
} }
...@@ -1103,6 +1131,8 @@ int test3b(struct Options options) ...@@ -1103,6 +1131,8 @@ int test3b(struct Options options)
MyLog( MyLog(
LOGA_INFO, LOGA_INFO,
"Starting test 3b - connection to SSL MQTT server with clientauth=opt but client does not have server cert"); "Starting test 3b - connection to SSL MQTT server with clientauth=opt but client does not have server cert");
fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
global_start_time = start_clock();
snprintf(url, 100, "ssl://%s:8885", options.connection); snprintf(url, 100, "ssl://%s:8885", options.connection);
rc = MQTTAsync_create(&c, url, "test3b", MQTTCLIENT_PERSISTENCE_DEFAULT, rc = MQTTAsync_create(&c, url, "test3b", MQTTCLIENT_PERSISTENCE_DEFAULT,
...@@ -1149,7 +1179,7 @@ int test3b(struct Options options) ...@@ -1149,7 +1179,7 @@ int test3b(struct Options options)
exit: MQTTAsync_destroy(&c); exit: MQTTAsync_destroy(&c);
MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.", MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", testname, tests, failures); (failures == 0) ? "passed" : "failed", testname, tests, failures);
write_test_result();
return failures; return failures;
} }
...@@ -1193,6 +1223,9 @@ int test4(struct Options options) ...@@ -1193,6 +1223,9 @@ int test4(struct Options options)
failures = 0; failures = 0;
MyLog(LOGA_INFO, "Starting test 4 - accept invalid server certificates"); MyLog(LOGA_INFO, "Starting test 4 - accept invalid server certificates");
fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
global_start_time = start_clock();
snprintf(url, 100, "ssl://%s:8885", options.connection); snprintf(url, 100, "ssl://%s:8885", options.connection);
MQTTAsync_create(&c, url, "test4", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); MQTTAsync_create(&c, url, "test4", MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);
...@@ -1277,7 +1310,7 @@ int test4(struct Options options) ...@@ -1277,7 +1310,7 @@ int test4(struct Options options)
exit: MQTTAsync_destroy(&c); exit: MQTTAsync_destroy(&c);
MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.", MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", testname, tests, failures); (failures == 0) ? "passed" : "failed", testname, tests, failures);
write_test_result();
return failures; return failures;
} }
...@@ -1321,6 +1354,9 @@ int test5a(struct Options options) ...@@ -1321,6 +1354,9 @@ int test5a(struct Options options)
MyLog(LOGA_INFO, MyLog(LOGA_INFO,
"Starting SSL test 5a - Anonymous ciphers - server authentication disabled"); "Starting SSL test 5a - Anonymous ciphers - server authentication disabled");
fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
global_start_time = start_clock();
snprintf(url, 100, "ssl://%s:8886", options.connection); snprintf(url, 100, "ssl://%s:8886", options.connection);
rc = MQTTAsync_create(&c, url, "test5a", MQTTCLIENT_PERSISTENCE_DEFAULT, rc = MQTTAsync_create(&c, url, "test5a", MQTTCLIENT_PERSISTENCE_DEFAULT,
NULL); NULL);
...@@ -1409,7 +1445,7 @@ int test5a(struct Options options) ...@@ -1409,7 +1445,7 @@ int test5a(struct Options options)
exit: MQTTAsync_destroy(&c); exit: MQTTAsync_destroy(&c);
MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.", MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", testname, tests, failures); (failures == 0) ? "passed" : "failed", testname, tests, failures);
write_test_result();
return failures; return failures;
} }
...@@ -1453,6 +1489,9 @@ int test5b(struct Options options) ...@@ -1453,6 +1489,9 @@ int test5b(struct Options options)
MyLog(LOGA_INFO, MyLog(LOGA_INFO,
"Starting SSL test 5b - Anonymous ciphers - server authentication enabled"); "Starting SSL test 5b - Anonymous ciphers - server authentication enabled");
fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
global_start_time = start_clock();
snprintf(url, 100, "ssl://%s:8886", options.connection); snprintf(url, 100, "ssl://%s:8886", options.connection);
rc = MQTTAsync_create(&c, url, "test5b", MQTTCLIENT_PERSISTENCE_DEFAULT, rc = MQTTAsync_create(&c, url, "test5b", MQTTCLIENT_PERSISTENCE_DEFAULT,
NULL); NULL);
...@@ -1541,7 +1580,7 @@ int test5b(struct Options options) ...@@ -1541,7 +1580,7 @@ int test5b(struct Options options)
exit: MQTTAsync_destroy(&c); exit: MQTTAsync_destroy(&c);
MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.", MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", testname, tests, failures); (failures == 0) ? "passed" : "failed", testname, tests, failures);
write_test_result();
return failures; return failures;
} }
...@@ -1585,6 +1624,8 @@ int test5c(struct Options options) ...@@ -1585,6 +1624,8 @@ int test5c(struct Options options)
failures = 0; failures = 0;
MyLog(LOGA_INFO, MyLog(LOGA_INFO,
"Starting SSL test 5c - Anonymous ciphers - client not using anonymous cipher"); "Starting SSL test 5c - Anonymous ciphers - client not using anonymous cipher");
fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
global_start_time = start_clock();
snprintf(url, 100, "ssl://%s:8886", options.connection); snprintf(url, 100, "ssl://%s:8886", options.connection);
rc = MQTTAsync_create(&c, url, "test5c", MQTTCLIENT_PERSISTENCE_DEFAULT, rc = MQTTAsync_create(&c, url, "test5c", MQTTCLIENT_PERSISTENCE_DEFAULT,
...@@ -1628,10 +1669,11 @@ int test5c(struct Options options) ...@@ -1628,10 +1669,11 @@ int test5c(struct Options options)
usleep(10000L); usleep(10000L);
#endif #endif
exit: MQTTAsync_destroy(&c); exit:
MQTTAsync_destroy(&c);
MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.", MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", testname, tests, failures); (failures == 0) ? "passed" : "failed", testname, tests, failures);
write_test_result();
return failures; return failures;
} }
...@@ -1672,6 +1714,9 @@ int test6(struct Options options) ...@@ -1672,6 +1714,9 @@ int test6(struct Options options)
int test6finished = 0; int test6finished = 0;
MyLog(LOGA_INFO, "Starting test 6 - multiple connections"); MyLog(LOGA_INFO, "Starting test 6 - multiple connections");
fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
global_start_time = start_clock();
snprintf(url, 100, "ssl://%s:8883", options.connection); snprintf(url, 100, "ssl://%s:8883", options.connection);
for (i = 0; i < num_clients; ++i) for (i = 0; i < num_clients; ++i)
...@@ -1750,7 +1795,7 @@ int test6(struct Options options) ...@@ -1750,7 +1795,7 @@ int test6(struct Options options)
exit: MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.", exit: MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", testname, tests, failures); (failures == 0) ? "passed" : "failed", testname, tests, failures);
write_test_result();
return failures; return failures;
} }
...@@ -1904,6 +1949,8 @@ int test7(struct Options options) ...@@ -1904,6 +1949,8 @@ int test7(struct Options options)
test_finished = failures = 0; test_finished = failures = 0;
snprintf(url, 100, "ssl://%s:8883", options.connection); snprintf(url, 100, "ssl://%s:8883", options.connection);
MyLog(LOGA_INFO, "Starting test 7 - big messages"); MyLog(LOGA_INFO, "Starting test 7 - big messages");
fprintf(xml, "<testcase classname=\"test5\" name=\"%s\"", testname);
global_start_time = start_clock();
rc = MQTTAsync_create(&c, url, "async_test_7", MQTTCLIENT_PERSISTENCE_NONE, rc = MQTTAsync_create(&c, url, "async_test_7", MQTTCLIENT_PERSISTENCE_NONE,
NULL); NULL);
...@@ -1967,7 +2014,7 @@ int test7(struct Options options) ...@@ -1967,7 +2014,7 @@ int test7(struct Options options)
exit: MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.", exit: MyLog(LOGA_INFO, "%s: test %s. %d tests run, %d failures.",
(failures == 0) ? "passed" : "failed", testname, tests, failures); (failures == 0) ? "passed" : "failed", testname, tests, failures);
write_test_result();
return failures; return failures;
} }
...@@ -1984,26 +2031,28 @@ int main(int argc, char** argv) ...@@ -1984,26 +2031,28 @@ int main(int argc, char** argv)
int (*tests[])() = int (*tests[])() =
{ NULL, test1, test2a, test2b, test2c, test3a, test3b, test4, test5a, { NULL, test1, test2a, test2b, test2c, test3a, test3b, test4, test5a,
test5b, test5c, test6, test7 }; test5b, test5c, test6, test7 };
//char** versionInfo = MQTTAsync_getVersionInfo();
/*for (i = 0; versionInfo[i] != NULL; i++) xml = fopen("TEST-test5.xml", "w");
{ fprintf(xml, "<testsuite name=\"test5\" tests=\"%d\">\n", ARRAY_SIZE(tests) - 1);
printf("%s\n", versionInfo[i]);
}*/
//client_mutex = CreateMutex(NULL, 0, NULL); MQTTAsync_setTraceCallback(handleTrace);
//MQTTAsync_setTraceLevel(MQTTASYNC_TRACE_PROTOCOL);
//MQTTAsync_setTraceCallback(handleTrace);
getopts(argc, argv); getopts(argc, argv);
if (options.test_no == 0) if (options.test_no == 0)
{ /* run all the tests */ { /* run all the tests */
for (options.test_no = 1; options.test_no < ARRAY_SIZE(tests); ++options.test_no) for (options.test_no = 1; options.test_no < ARRAY_SIZE(tests); ++options.test_no)
{
failures = 0;
MQTTAsync_setTraceLevel(MQTTASYNC_TRACE_ERROR);
rc += tests[options.test_no](options); /* return number of failures. 0 = test succeeded */ rc += tests[options.test_no](options); /* return number of failures. 0 = test succeeded */
}
} }
else else
{
MQTTAsync_setTraceLevel(MQTTASYNC_TRACE_ERROR);
rc = tests[options.test_no](options); /* run just the selected test */ rc = tests[options.test_no](options); /* run just the selected test */
}
MyLog(LOGA_INFO, "Total tests run: %d", *numtests); MyLog(LOGA_INFO, "Total tests run: %d", *numtests);
if (rc == 0) if (rc == 0)
...@@ -2011,6 +2060,9 @@ int main(int argc, char** argv) ...@@ -2011,6 +2060,9 @@ int main(int argc, char** argv)
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