Re: [PATCH v10 2/2] Add gcov MC/DC tests for GDC

2024-02-23 Thread Iain Buclaw
Excerpts from Jørgen Kvalsvik's message of Februar 23, 2024 12:18 pm:
> This is a mostly straight port from the gcov-19.c tests from the C test
> suite. The only notable differences from C to D are that D flips the
> true/false outcomes for loop headers, and the D front end ties loop and
> ternary conditions to slightly different locus.
> 
> The test for >64 conditions warning is disabled as it either needs
> support from the testing framework or a something similar to #pragma GCC
> diagnostic push to not cause a test failure from detecting a warning.
> 
> gcc/testsuite/ChangeLog:
> 
>   * gdc.dg/gcov.exp: New test.
>   * gdc.dg/gcov1.d: New test.
> ---
>  gcc/testsuite/gdc.dg/gcov.exp |   44 +
>  gcc/testsuite/gdc.dg/gcov1.d  | 1712 +
>  2 files changed, 1756 insertions(+)
>  create mode 100644 gcc/testsuite/gdc.dg/gcov.exp
>  create mode 100644 gcc/testsuite/gdc.dg/gcov1.d
> 

I think I said this before in the previous series, no objections to
adding more tests to the gdc testsuite.

OK.

Thanks,
Iain.


[PATCH v10 2/2] Add gcov MC/DC tests for GDC

2024-02-23 Thread Jørgen Kvalsvik
This is a mostly straight port from the gcov-19.c tests from the C test
suite. The only notable differences from C to D are that D flips the
true/false outcomes for loop headers, and the D front end ties loop and
ternary conditions to slightly different locus.

The test for >64 conditions warning is disabled as it either needs
support from the testing framework or a something similar to #pragma GCC
diagnostic push to not cause a test failure from detecting a warning.

gcc/testsuite/ChangeLog:

* gdc.dg/gcov.exp: New test.
* gdc.dg/gcov1.d: New test.
---
 gcc/testsuite/gdc.dg/gcov.exp |   44 +
 gcc/testsuite/gdc.dg/gcov1.d  | 1712 +
 2 files changed, 1756 insertions(+)
 create mode 100644 gcc/testsuite/gdc.dg/gcov.exp
 create mode 100644 gcc/testsuite/gdc.dg/gcov1.d

diff --git a/gcc/testsuite/gdc.dg/gcov.exp b/gcc/testsuite/gdc.dg/gcov.exp
new file mode 100644
index 000..4218771b208
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/gcov.exp
@@ -0,0 +1,44 @@
+#   Copyright (C) 1997-2023 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# .
+
+# Gcov test driver.
+
+# Load support procs.
+load_lib gdc-dg.exp
+load_lib gcov.exp
+
+global GDC_UNDER_TEST
+
+# For now find gcov in the same directory as $GDC_UNDER_TEST.
+if { ![is_remote host] && [string match "*/*" [lindex $GDC_UNDER_TEST 0]] } {
+set GCOV [file dirname [lindex $GDC_UNDER_TEST 
0]]/[gcc-transform-out-of-tree gcov]
+} else {
+set GCOV [gcc-transform-out-of-tree gcov]
+}
+
+# Initialize harness.
+dg-init
+
+# Delete old .gcda files.
+set files [glob -nocomplain gcov*.gcda]
+if { $files != "" } {
+eval "remote_file build delete $files"
+}
+
+# Main loop.
+gdc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/gcov*.d]] "" ""
+
+dg-finish
diff --git a/gcc/testsuite/gdc.dg/gcov1.d b/gcc/testsuite/gdc.dg/gcov1.d
new file mode 100644
index 000..10ffa4a0e30
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/gcov1.d
@@ -0,0 +1,1712 @@
+/* { dg-options "-fcondition-coverage -ftest-coverage" } */
+/* { dg-do run { target native } } */
+
+/* Some side effect to stop branches from being pruned.  */
+int x = 0;
+
+int id  (int x) { return  x; }
+int inv (int x) { return !x; }
+
+/* || works.  */
+void
+mcdc001a (int a, int b)
+{
+if (a || b) /* conditions(1/4) true(0) false(0 1) */
+   /* conditions(end) */
+   x = 1;
+else
+   x = 2;
+}
+
+void
+mcdc001b (int a, int b)
+{
+if (a || b) /* conditions(3/4) true(0) */
+   /* conditions(end) */
+   x = 1;
+else
+   x = 2;
+}
+
+void
+mcdc001c (int a, int b)
+{
+if (a || b) /* conditions(4/4) */
+   x = 1;
+else
+   x = 2;
+}
+
+void
+mcdc001d (int a, int b, int c)
+{
+if (a || b || c) /* conditions(2/6) false(0 1 2) true(2) */
+/* conditions(end) */
+   x = 1;
+}
+
+/* && works */
+void
+mcdc002a (int a, int b)
+{
+if (a && b) /* conditions(1/4) true(0 1) false(0) */
+   /* conditions(end) */
+   x = 1;
+else
+   x = 2;
+}
+
+void
+mcdc002b (int a, int b)
+{
+if (a && b) /* conditions(3/4) false(0) */
+   /* conditions(end) */
+   x = 1;
+else
+   x = 2;
+}
+
+void
+mcdc002c (int a, int b)
+{
+if (a && b) /* conditions(4/4) */
+   x = 1;
+else
+   x = 2;
+}
+
+void
+mcdc002d (int a, int b, int c)
+{
+if (a && b && c) /* conditions(4/6) false(0 2) */
+/* conditions(end) */
+   x = 1;
+}
+
+/* Negation works.  */
+void
+mcdc003a (int a, int b)
+{
+if (!a || !b) /* conditions(2/4) false(0 1) */
+ /* conditions(end) */
+   x = 1;
+else
+   x = 2;
+}
+
+/* Single conditionals with and without else.  */
+void
+mcdc004a (int a)
+{
+if (a) /* conditions(1/2) true(0) */
+  /* conditions(end) */
+   x = 1;
+else
+   x = 2;
+}
+
+void
+mcdc004b (int a)
+{
+if (a) /* conditions(2/2) */
+   x = 1;
+else
+   x = 2;
+}
+
+void
+mcdc004c (int a)
+{
+if (a) /* conditions(1/2) false(0) */
+  /* conditions(end) */
+   x = 1;
+}
+
+void
+mcdc004d (int a, int b, int c)
+{
+if (a)  /* conditions(2/2) */
+{
+   if (b || c) /* conditions(1/4) true(1) false(0 1) */
+   x = a + b + c;
+}
+}
+
+void
+mcdc004e (int a, int b, int c)
+{
+if (a)