<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/20042">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span></span><br></pre><div style="white-space:pre-wrap">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

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">test.c: Fix counting of tests and add 2 new tests<br><br>The unit test XML output was counting all registered tests as "run"<br>even when only a subset were actually requested to be run and<br>the "failures" attribute was missing.<br><br>* The "tests" attribute of the "testsuite" element in the<br>  output XML now reflects only the tests actually requested<br>  to be executed instead of all the tests registered.<br><br>* The "failures" attribute was added to the "testsuite"<br>  element.<br><br>Also added 2 new unit tests that just pass and fail to be<br>used for CI testing.<br><br>Change-Id: Ia137814b5aeb0e1a44c75034bd3615c26021da69<br>---<br>A doc/CHANGES-staging/test.txt<br>M main/test.c<br>M tests/test_pbx.c<br>3 files changed, 79 insertions(+), 3 deletions(-)<br><br></pre>
<pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/doc/CHANGES-staging/test.txt b/doc/CHANGES-staging/test.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..05a2694</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/test.txt</span><br><span>@@ -0,0 +1,11 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: test.c</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+The "tests" attribute of the "testsuite" element in the</span><br><span style="color: hsl(120, 100%, 40%);">+output XML now reflects only the tests actually requested</span><br><span style="color: hsl(120, 100%, 40%);">+to be executed instead of all the tests registered.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+The "failures" attribute was added to the "testsuite"</span><br><span style="color: hsl(120, 100%, 40%);">+element.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Also added two new unit tests that just pass and fail</span><br><span style="color: hsl(120, 100%, 40%);">+to be used for testing CI itself.</span><br><span>diff --git a/main/test.c b/main/test.c</span><br><span>index 9eefbd0..7ec505b 100644</span><br><span>--- a/main/test.c</span><br><span>+++ b/main/test.c</span><br><span>@@ -715,8 +715,8 @@</span><br><span>                 /* update total counts as well during this iteration</span><br><span>                  * even if the current test did not execute this time */</span><br><span>             last_results.total_time += test->time;</span><br><span style="color: hsl(0, 100%, 40%);">-               last_results.total_tests++;</span><br><span>          if (test->state != AST_TEST_NOT_RUN) {</span><br><span style="color: hsl(120, 100%, 40%);">+                     last_results.total_tests++;</span><br><span>                  if (test->state == AST_TEST_PASS) {</span><br><span>                               last_results.total_passed++;</span><br><span>                         } else {</span><br><span>@@ -793,10 +793,10 @@</span><br><span>              */</span><br><span>          fprintf(f_xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");</span><br><span>          fprintf(f_xml, "<testsuites>\n");</span><br><span style="color: hsl(0, 100%, 40%);">-               fprintf(f_xml, "\t<testsuite errors=\"0\" time=\"%u.%u\" tests=\"%u\" "</span><br><span style="color: hsl(120, 100%, 40%);">+            fprintf(f_xml, "\t<testsuite errors=\"0\" time=\"%u.%u\" tests=\"%u\" failures=\"%u\" "</span><br><span>                                 "name=\"AsteriskUnitTests\">\n",</span><br><span>                              last_results.total_time / 1000, last_results.total_time % 1000,</span><br><span style="color: hsl(0, 100%, 40%);">-                         last_results.total_tests);</span><br><span style="color: hsl(120, 100%, 40%);">+                            last_results.total_tests, last_results.total_failed);</span><br><span>                fprintf(f_xml, "\t\t<properties>\n");</span><br><span>                fprintf(f_xml, "\t\t\t<property name=\"version\" value=\"%s\"/>\n", ast_get_version());</span><br><span>          fprintf(f_xml, "\t\t</properties>\n");</span><br><span>diff --git a/tests/test_pbx.c b/tests/test_pbx.c</span><br><span>index d4858e4..3986d7d 100644</span><br><span>--- a/tests/test_pbx.c</span><br><span>+++ b/tests/test_pbx.c</span><br><span>@@ -383,8 +383,48 @@</span><br><span>   return AST_TEST_PASS;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+AST_TEST_DEFINE(just_fail)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ switch (cmd) {</span><br><span style="color: hsl(120, 100%, 40%);">+        case TEST_INIT:</span><br><span style="color: hsl(120, 100%, 40%);">+               info->name = "JUST_FAIL";</span><br><span style="color: hsl(120, 100%, 40%);">+                info->category = "/TEST_PASS_FAIL/";</span><br><span style="color: hsl(120, 100%, 40%);">+             info->summary = "Just fails";</span><br><span style="color: hsl(120, 100%, 40%);">+            info->description = "Just fails. "</span><br><span style="color: hsl(120, 100%, 40%);">+                       "This test is mainly used for testing CI and tool failure scenarios.";</span><br><span style="color: hsl(120, 100%, 40%);">+              info->explicit_only = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+           return AST_TEST_NOT_RUN;</span><br><span style="color: hsl(120, 100%, 40%);">+      case TEST_EXECUTE:</span><br><span style="color: hsl(120, 100%, 40%);">+            break;</span><br><span style="color: hsl(120, 100%, 40%);">+        }</span><br><span style="color: hsl(120, 100%, 40%);">+     ast_test_status_update(test, "This test just forces a fail\n");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   return AST_TEST_FAIL;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+AST_TEST_DEFINE(just_pass)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     switch (cmd) {</span><br><span style="color: hsl(120, 100%, 40%);">+        case TEST_INIT:</span><br><span style="color: hsl(120, 100%, 40%);">+               info->name = "JUST_PASS";</span><br><span style="color: hsl(120, 100%, 40%);">+                info->category = "/TEST_PASS_FAIL/";</span><br><span style="color: hsl(120, 100%, 40%);">+             info->summary = "Just passes";</span><br><span style="color: hsl(120, 100%, 40%);">+           info->description = "Just passes. "</span><br><span style="color: hsl(120, 100%, 40%);">+                      "This test is mainly used for testing CI and tool failure scenarios.";</span><br><span style="color: hsl(120, 100%, 40%);">+              info->explicit_only = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+           return AST_TEST_NOT_RUN;</span><br><span style="color: hsl(120, 100%, 40%);">+      case TEST_EXECUTE:</span><br><span style="color: hsl(120, 100%, 40%);">+            break;</span><br><span style="color: hsl(120, 100%, 40%);">+        }</span><br><span style="color: hsl(120, 100%, 40%);">+     ast_test_status_update(test, "This test just forces a pass\n");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   return AST_TEST_PASS;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int unload_module(void)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+     AST_TEST_UNREGISTER(just_pass);</span><br><span style="color: hsl(120, 100%, 40%);">+       AST_TEST_UNREGISTER(just_fail);</span><br><span>      AST_TEST_UNREGISTER(call_backtrace);</span><br><span>         AST_TEST_UNREGISTER(call_assert);</span><br><span>    AST_TEST_UNREGISTER(segv);</span><br><span>@@ -398,6 +438,8 @@</span><br><span>     AST_TEST_REGISTER(segv);</span><br><span>     AST_TEST_REGISTER(call_assert);</span><br><span>      AST_TEST_REGISTER(call_backtrace);</span><br><span style="color: hsl(120, 100%, 40%);">+    AST_TEST_REGISTER(just_fail);</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_TEST_REGISTER(just_pass);</span><br><span>        return AST_MODULE_LOAD_SUCCESS;</span><br><span> }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/20042">change 20042</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/20042"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ia137814b5aeb0e1a44c75034bd3615c26021da69 </div>
<div style="display:none"> Gerrit-Change-Number: 20042 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: N A <asterisk@phreaknet.org> </div>
<div style="display:none"> Gerrit-Reviewer: Sean Bright <sean@seanbright.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>