[Asterisk-code-review] test.c: Fix counting of tests and add 2 new tests (asterisk[master])
Friendly Automation
asteriskteam at digium.com
Mon Apr 10 10:48:48 CDT 2023
Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/20042 )
Change subject: test.c: Fix counting of tests and add 2 new tests
......................................................................
test.c: Fix counting of tests and add 2 new tests
The unit test XML output was counting all registered tests as "run"
even when only a subset were actually requested to be run and
the "failures" attribute was missing.
* The "tests" attribute of the "testsuite" element in the
output XML now reflects only the tests actually requested
to be executed instead of all the tests registered.
* The "failures" attribute was added to the "testsuite"
element.
Also added 2 new unit tests that just pass and fail to be
used for CI testing.
Change-Id: Ia137814b5aeb0e1a44c75034bd3615c26021da69
---
A doc/CHANGES-staging/test.txt
M main/test.c
M tests/test_pbx.c
3 files changed, 79 insertions(+), 3 deletions(-)
Approvals:
Sean Bright: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
diff --git a/doc/CHANGES-staging/test.txt b/doc/CHANGES-staging/test.txt
new file mode 100644
index 0000000..05a2694
--- /dev/null
+++ b/doc/CHANGES-staging/test.txt
@@ -0,0 +1,11 @@
+Subject: test.c
+
+The "tests" attribute of the "testsuite" element in the
+output XML now reflects only the tests actually requested
+to be executed instead of all the tests registered.
+
+The "failures" attribute was added to the "testsuite"
+element.
+
+Also added two new unit tests that just pass and fail
+to be used for testing CI itself.
diff --git a/main/test.c b/main/test.c
index 9eefbd0..7ec505b 100644
--- a/main/test.c
+++ b/main/test.c
@@ -715,8 +715,8 @@
/* update total counts as well during this iteration
* even if the current test did not execute this time */
last_results.total_time += test->time;
- last_results.total_tests++;
if (test->state != AST_TEST_NOT_RUN) {
+ last_results.total_tests++;
if (test->state == AST_TEST_PASS) {
last_results.total_passed++;
} else {
@@ -793,10 +793,10 @@
*/
fprintf(f_xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
fprintf(f_xml, "<testsuites>\n");
- fprintf(f_xml, "\t<testsuite errors=\"0\" time=\"%u.%u\" tests=\"%u\" "
+ fprintf(f_xml, "\t<testsuite errors=\"0\" time=\"%u.%u\" tests=\"%u\" failures=\"%u\" "
"name=\"AsteriskUnitTests\">\n",
last_results.total_time / 1000, last_results.total_time % 1000,
- last_results.total_tests);
+ last_results.total_tests, last_results.total_failed);
fprintf(f_xml, "\t\t<properties>\n");
fprintf(f_xml, "\t\t\t<property name=\"version\" value=\"%s\"/>\n", ast_get_version());
fprintf(f_xml, "\t\t</properties>\n");
diff --git a/tests/test_pbx.c b/tests/test_pbx.c
index d4858e4..3986d7d 100644
--- a/tests/test_pbx.c
+++ b/tests/test_pbx.c
@@ -383,8 +383,48 @@
return AST_TEST_PASS;
}
+AST_TEST_DEFINE(just_fail)
+{
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "JUST_FAIL";
+ info->category = "/TEST_PASS_FAIL/";
+ info->summary = "Just fails";
+ info->description = "Just fails. "
+ "This test is mainly used for testing CI and tool failure scenarios.";
+ info->explicit_only = 1;
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+ ast_test_status_update(test, "This test just forces a fail\n");
+
+ return AST_TEST_FAIL;
+}
+
+AST_TEST_DEFINE(just_pass)
+{
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "JUST_PASS";
+ info->category = "/TEST_PASS_FAIL/";
+ info->summary = "Just passes";
+ info->description = "Just passes. "
+ "This test is mainly used for testing CI and tool failure scenarios.";
+ info->explicit_only = 1;
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+ ast_test_status_update(test, "This test just forces a pass\n");
+
+ return AST_TEST_PASS;
+}
+
static int unload_module(void)
{
+ AST_TEST_UNREGISTER(just_pass);
+ AST_TEST_UNREGISTER(just_fail);
AST_TEST_UNREGISTER(call_backtrace);
AST_TEST_UNREGISTER(call_assert);
AST_TEST_UNREGISTER(segv);
@@ -398,6 +438,8 @@
AST_TEST_REGISTER(segv);
AST_TEST_REGISTER(call_assert);
AST_TEST_REGISTER(call_backtrace);
+ AST_TEST_REGISTER(just_fail);
+ AST_TEST_REGISTER(just_pass);
return AST_MODULE_LOAD_SUCCESS;
}
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/20042
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Ia137814b5aeb0e1a44c75034bd3615c26021da69
Gerrit-Change-Number: 20042
Gerrit-PatchSet: 2
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: N A <asterisk at phreaknet.org>
Gerrit-Reviewer: Sean Bright <sean at seanbright.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20230410/8d71abb5/attachment.html>
More information about the asterisk-code-review
mailing list