public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: Bernd Schmidt <bschmidt@redhat.com>, Jeff Law <law@redhat.com>,
	       David Malcolm <dmalcolm@redhat.com>
Subject: [PATCH 08/15] Add selftests to gimple.c
Date: Thu, 19 Nov 2015 16:46:00 -0000	[thread overview]
Message-ID: <1447952699-40820-9-git-send-email-dmalcolm@redhat.com> (raw)
In-Reply-To: <1447952699-40820-1-git-send-email-dmalcolm@redhat.com>

Jeff approved an earlier version of this (as
unittests/test-gimple.c):
 https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03304.html

> Comment indicates addition. But code actually generates a
> MULT_EXPR. Please fix.
Fixed

> OK if/when prereqs are approved. Minor twiddling if we end
> up moving it elsewhere or standardizing/reducing header files
> is pre-approved.

This version moves the tests into gimple.c.

gcc/ChangeLog:
	* gimple.c: Include "selftest.h".
	Include "gimple-pretty-print.h".
	(class gimple_test): New subclass.
	(gimple_test, assign_single): New selftest.
	(gimple_test, assign_binop): New selftest.
	(gimple_test, nop_stmt): New selftest.
	(gimple_test, return_stmt): New selftest.
	(gimple_test, return_without_value): New selftest.
---
 gcc/gimple.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)

diff --git a/gcc/gimple.c b/gcc/gimple.c
index 2764df8..17d3896 100644
--- a/gcc/gimple.c
+++ b/gcc/gimple.c
@@ -38,6 +38,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-walk.h"
 #include "gimplify.h"
 #include "target.h"
+#include "selftest.h"
+#include "gimple-pretty-print.h"
 
 
 /* All the tuples have their operand vector (if present) at the very bottom
@@ -2990,3 +2992,104 @@ maybe_remove_unused_call_args (struct function *fn, gimple *stmt)
       update_stmt_fn (fn, stmt);
     }
 }
+
+#if CHECKING_P
+
+namespace {
+
+class gimple_test : public ::selftest::test
+{
+ protected:
+  void
+  verify_gimple_pp (const char *expected, gimple *stmt)
+  {
+    pretty_printer pp;
+    pp_gimple_stmt_1 (&pp, stmt, 0 /* spc */, 0 /* flags */);
+    EXPECT_STREQ (expected, pp_formatted_text (&pp));
+  }
+};
+
+TEST_F (gimple_test, assign_single)
+{
+  /* Build "tmp = 5;"  */
+  tree type = integer_type_node;
+  tree lhs = build_decl (UNKNOWN_LOCATION, VAR_DECL,
+			 get_identifier ("tmp"),
+			 type);
+  tree rhs = build_int_cst (type, 5);
+  gassign *stmt = gimple_build_assign (lhs, rhs);
+  verify_gimple_pp ("tmp = 5;", stmt);
+
+  EXPECT_TRUE (is_gimple_assign (stmt));
+  EXPECT_EQ (lhs, gimple_assign_lhs (stmt));
+  EXPECT_EQ (lhs, gimple_get_lhs (stmt));
+  EXPECT_EQ (rhs, gimple_assign_rhs1 (stmt));
+  EXPECT_EQ (NULL, gimple_assign_rhs2 (stmt));
+  EXPECT_EQ (NULL, gimple_assign_rhs3 (stmt));
+  EXPECT_TRUE (gimple_assign_single_p (stmt));
+  EXPECT_EQ (INTEGER_CST, gimple_assign_rhs_code (stmt));
+}
+
+TEST_F (gimple_test, assign_binop)
+{
+  /* Build "tmp = a * b;"  */
+  tree type = integer_type_node;
+  tree lhs = build_decl (UNKNOWN_LOCATION, VAR_DECL,
+			 get_identifier ("tmp"),
+			 type);
+  tree a = build_decl (UNKNOWN_LOCATION, VAR_DECL,
+		       get_identifier ("a"),
+		       type);
+  tree b = build_decl (UNKNOWN_LOCATION, VAR_DECL,
+		       get_identifier ("b"),
+		       type);
+  gassign *stmt = gimple_build_assign (lhs, MULT_EXPR, a, b);
+  verify_gimple_pp ("tmp = a * b;", stmt);
+
+  EXPECT_TRUE (is_gimple_assign (stmt));
+  EXPECT_EQ (lhs, gimple_assign_lhs (stmt));
+  EXPECT_EQ (lhs, gimple_get_lhs (stmt));
+  EXPECT_EQ (a, gimple_assign_rhs1 (stmt));
+  EXPECT_EQ (b, gimple_assign_rhs2 (stmt));
+  EXPECT_EQ (NULL, gimple_assign_rhs3 (stmt));
+  EXPECT_FALSE (gimple_assign_single_p (stmt));
+  EXPECT_EQ (MULT_EXPR, gimple_assign_rhs_code (stmt));
+}
+
+TEST_F (gimple_test, nop_stmt)
+{
+  gimple *stmt = gimple_build_nop ();
+  verify_gimple_pp ("GIMPLE_NOP", stmt);
+  EXPECT_EQ (GIMPLE_NOP, gimple_code (stmt));
+  EXPECT_EQ (NULL, gimple_get_lhs (stmt));
+  EXPECT_FALSE (gimple_assign_single_p (stmt));
+}
+
+TEST_F (gimple_test, return_stmt)
+{
+  /* Build "return 7;"  */
+  tree type = integer_type_node;
+  tree val = build_int_cst (type, 7);
+  greturn *stmt = gimple_build_return (val);
+  verify_gimple_pp ("return 7;", stmt);
+
+  EXPECT_EQ (GIMPLE_RETURN, gimple_code (stmt));
+  EXPECT_EQ (NULL, gimple_get_lhs (stmt));
+  EXPECT_EQ (val, gimple_return_retval (stmt));
+  EXPECT_FALSE (gimple_assign_single_p (stmt));
+}
+
+TEST_F (gimple_test, return_without_value)
+{
+  greturn *stmt = gimple_build_return (NULL);
+  verify_gimple_pp ("return;", stmt);
+
+  EXPECT_EQ (GIMPLE_RETURN, gimple_code (stmt));
+  EXPECT_EQ (NULL, gimple_get_lhs (stmt));
+  EXPECT_EQ (NULL, gimple_return_retval (stmt));
+  EXPECT_FALSE (gimple_assign_single_p (stmt));
+}
+
+}  /* anon namespace.  */
+
+#endif /* CHECKING_P */
-- 
1.8.5.3

  parent reply	other threads:[~2015-11-19 16:46 UTC|newest]

Thread overview: 176+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-10 15:10 [PATCH 00/17] RFC: Addding a unit testing framework to gcc David Malcolm
2015-06-10 15:10 ` [PATCH 02/17] Add test-bitmap.c to gcc/unittests David Malcolm
2015-06-23 19:17   ` Jeff Law
2015-06-10 15:10 ` [PATCH 01/17] Add Make-lang.in and config-lang.in " David Malcolm
2015-06-10 15:10 ` [PATCH 09/17] Add test-hash-set.c " David Malcolm
2015-06-10 15:10 ` [PATCH 04/17] Add test-folding.c " David Malcolm
2015-06-10 15:10 ` [PATCH 11/17] Add test-rtl.c " David Malcolm
2015-06-10 15:10 ` [PATCH 08/17] Add test-hash-map.c " David Malcolm
2015-06-10 15:10 ` [PATCH 05/17] Add test-functions.c " David Malcolm
2015-06-10 15:10 ` [PATCH 10/17] Add test-locations.c " David Malcolm
2015-06-10 15:10 ` [PATCH 07/17] Add test-gimple.c " David Malcolm
2015-06-10 15:10 ` [PATCH 12/17] Add test-tree.c " David Malcolm
2015-06-10 15:17 ` [PATCH 03/17] Add test-cfg.c " David Malcolm
2015-06-23 19:26   ` Jeff Law
2015-06-25 18:13     ` David Malcolm
2015-06-10 15:25 ` [PATCH 17/17] toplev.c: move location_adhoc_data_fini call David Malcolm
2015-06-10 15:26 ` [PATCH 13/17] Add test-vec.c to gcc/unittests David Malcolm
2015-06-10 15:26 ` [PATCH 16/17] Add unittests-main.c " David Malcolm
2015-06-10 15:28 ` [PATCH 15/17] Add unittests-frontend.c " David Malcolm
2015-06-10 15:28 ` [PATCH 06/17] Add test-ggc.c " David Malcolm
2015-06-10 15:34 ` [PATCH 14/17] Add test-wide-int.c " David Malcolm
2015-06-10 16:19 ` [PATCH 00/17] RFC: Addding a unit testing framework to gcc Jakub Jelinek
2015-06-10 16:25   ` Richard Biener
2015-06-10 17:56   ` David Malcolm
2015-06-10 23:42     ` Jakub Jelinek
2015-06-17 20:36       ` [PATCH/RFC]: unittesting v2: as a plugin (was Re: [PATCH 00/17] RFC: Addding a unit testing framework to gcc) David Malcolm
2015-06-23 19:29         ` Jeff Law
2015-10-27 19:31           ` [PATCH 00/16] Unit tests framework (v3) David Malcolm
2015-10-27 19:31             ` [PATCH 03/16] Add test-bitmap.c to unittests David Malcolm
2015-10-29 21:36               ` Jeff Law
2015-10-27 19:31             ` [PATCH 01/16] Add unittest infrastructure David Malcolm
2015-10-30  5:20               ` Jeff Law
2015-10-27 19:31             ` [PATCH 15/16] Add test-vec.c to unittests David Malcolm
2015-10-30  5:10               ` Jeff Law
2015-10-27 19:31             ` [PATCH 05/16] Add test-et-forest.c " David Malcolm
2015-10-30  4:11               ` Jeff Law
2015-10-27 19:31             ` [PATCH 11/16] Add test-hash-set.c " David Malcolm
2015-10-30  4:54               ` Jeff Law
2015-10-27 19:32             ` [PATCH 07/16] Add test-functions.c " David Malcolm
2015-10-30  5:19               ` Jeff Law
2015-10-27 19:32             ` [PATCH 10/16] Add test-hash-map.c " David Malcolm
2015-10-30  4:57               ` Jeff Law
2015-10-27 19:32             ` [PATCH 04/16] Add test-cfg.c " David Malcolm
2015-10-29 22:23               ` Jeff Law
2015-10-27 19:35             ` [PATCH 06/16] Add test-folding.c " David Malcolm
2015-10-30  5:06               ` Jeff Law
2015-10-27 19:48             ` [PATCH 14/16] Add test-tree.c " David Malcolm
2015-10-30  5:00               ` Jeff Law
2015-10-27 19:49             ` [PATCH 12/16] Add test-locations.c " David Malcolm
2015-10-30  5:09               ` Jeff Law
2015-10-27 19:49             ` [PATCH 08/16] Add test-ggc.c " David Malcolm
2015-10-30  5:08               ` Jeff Law
2015-10-27 19:50             ` [PATCH 13/16] Add test-rtl.c " David Malcolm
2015-10-30  4:58               ` Jeff Law
2015-10-31 20:36                 ` Segher Boessenkool
2015-10-27 19:51             ` [PATCH 16/16] Add test-wide-int.c " David Malcolm
2015-10-30  5:15               ` Jeff Law
2015-10-27 19:58             ` [PATCH 09/16] Add test-gimple.c " David Malcolm
2015-10-28 12:39               ` Richard Biener
2015-10-28 12:44                 ` Richard Biener
2015-10-28 16:22                   ` Jeff Law
2015-10-30  5:02               ` Jeff Law
2015-10-27 20:16             ` [PATCH 00/16] Unit tests framework (v3) David Malcolm
2015-10-30  5:28               ` Jeff Law
2015-10-28 11:53             ` Bernd Schmidt
2015-10-28 13:02               ` Bernd Schmidt
2015-10-29 16:20               ` David Malcolm
2015-10-29 19:38                 ` Jeff Law
2015-10-29 22:32                   ` Mike Stump
2015-10-30  3:59                     ` Jeff Law
2015-10-29 19:21               ` Jeff Law
2015-10-30 10:54                 ` Bernd Schmidt
2015-10-30 16:08                   ` Jeff Law
2015-11-16 18:17                     ` Bernd Schmidt
2015-11-16 18:48                       ` David Malcolm
2015-11-16 21:22                         ` Bernd Schmidt
2015-11-16 23:12                         ` Jeff Law
2015-11-17  1:54                           ` Mike Stump
2015-11-17 12:51                             ` Bernd Schmidt
2015-11-17 18:06                               ` Jeff Law
2015-11-19 16:46                       ` [PATCH 00/15] Unittests framework v4: -fself-test David Malcolm
2015-11-19 16:46                         ` [PATCH 07/15] Fix warning in function-tests.c David Malcolm
2015-11-19 16:46                         ` [PATCH 03/15] Add selftests to tree-cfg.c David Malcolm
2015-11-19 16:46                         ` David Malcolm [this message]
2015-11-19 16:46                         ` [PATCH 05/15] Add selftests to fold-const.c David Malcolm
2015-11-19 16:46                         ` [PATCH 02/15] Add selftests to bitmap.c David Malcolm
2015-11-20 10:41                           ` Richard Biener
2015-11-24 21:13                           ` Jeff Law
2015-11-19 16:46                         ` [PATCH 09/15] Add hash-map-tests.c David Malcolm
2015-11-19 16:46                         ` [PATCH 10/15] Add hash-set-tests.c David Malcolm
2015-11-19 16:46                         ` [PATCH 06/15] Add function-tests.c David Malcolm
2015-11-19 16:46                         ` [PATCH 13/15] Add selftests to tree.c David Malcolm
2015-11-19 16:46                         ` [PATCH 14/15] Add selftests to vec.c David Malcolm
2015-11-19 16:46                         ` [PATCH 01/15] Selftest framework (unittests v4) David Malcolm
2015-11-19 17:35                           ` Bernd Schmidt
2015-11-19 18:08                             ` David Malcolm
2015-11-19 18:15                               ` Mike Stump
2015-11-19 18:44                               ` Bernd Schmidt
2015-11-19 20:04                                 ` Mikhail Maltsev
2015-11-24 20:45                                 ` Jeff Law
2015-11-25  2:43                                   ` David Malcolm
2015-11-25 10:56                                     ` Bernd Schmidt
2015-11-25 16:57                                       ` Mike Stump
2015-11-29 18:10                                         ` Jeff Law
2015-11-25 22:58                                       ` David Malcolm
2015-11-25  7:43                                   ` Trevor Saunders
2015-11-25 22:53                                 ` David Malcolm
2015-11-26 13:00                                   ` Bernd Schmidt
2015-11-30 23:05                                     ` Jeff Law
2015-11-24 20:29                             ` Jeff Law
2015-11-24 22:43                           ` Jeff Law
2015-11-19 16:46                         ` [PATCH 15/15] RFC: Add ggc-tests.c David Malcolm
2015-11-19 16:46                         ` [PATCH 04/15] Add selftests to et-forest.c David Malcolm
2015-11-19 17:03                         ` [PATCH 12/15] Add rtl-tests.c David Malcolm
2015-11-19 17:03                         ` [PATCH 11/15] Add selftests to input.c David Malcolm
2016-06-01 20:54                         ` [PATCH 00/21] Add -fself-test framework for fast, early unit-testing (unittests v5) David Malcolm
2016-06-01 20:54                           ` [PATCH 20/21] Add selftests to tree.c David Malcolm
2016-06-01 20:54                           ` [PATCH 18/21] Add selftests to input.c David Malcolm
2016-06-01 20:54                           ` [PATCH 01/21] Selftest framework (unittests v5) David Malcolm
2016-06-01 20:54                           ` [PATCH 10/21] Add selftests to fold-const.c David Malcolm
2016-06-01 20:54                           ` [PATCH 07/21] Add selftests to bitmap.c David Malcolm
2016-06-01 20:54                           ` [PATCH 04/21] Add -fself-test-regex= David Malcolm
2016-06-01 20:54                           ` [PATCH 02/21] Makefile.in integration David Malcolm
2016-06-01 20:54                           ` [PATCH 09/21] Add selftests to et-forest.c David Malcolm
2016-06-01 20:54                           ` [PATCH 03/21] Various selftest::runner tweaks David Malcolm
2016-06-01 20:54                           ` [PATCH 17/21] Add hash-set-tests.c David Malcolm
2016-06-01 21:09                           ` [PATCH 12/21] Fix warning in function-tests.c David Malcolm
2016-06-01 21:10                           ` [PATCH 06/21] Convert Levenshtein test from a plugin to a selftest David Malcolm
2016-06-01 21:10                           ` [PATCH 08/21] Add selftests to tree-cfg.c David Malcolm
2016-06-01 21:10                           ` [PATCH 11/21] Add function-tests.c David Malcolm
2016-06-01 21:10                           ` [PATCH 21/21] Add selftests to vec.c David Malcolm
2016-06-01 21:11                           ` [PATCH 16/21] Add hash-map-tests.c David Malcolm
2016-06-01 21:20                           ` [PATCH 00/21] Add -fself-test framework for fast, early unit-testing (unittests v5) Sandra Loosemore
2016-06-02 13:08                             ` David Malcolm
2016-06-01 21:21                           ` [PATCH 05/21] Add selftests for diagnostic-show-locus.c David Malcolm
2016-06-01 21:22                           ` [PATCH 19/21] Add rtl-tests.c David Malcolm
2016-06-01 21:23                           ` [PATCH 15/21] Add selftests to gimple.c David Malcolm
2016-06-01 21:26                           ` [PATCH 14/21] Remove x86_64-isms in function-tests.c David Malcolm
2016-06-01 21:29                           ` [PATCH 13/21] Fixup to function-tests.c David Malcolm
2016-06-02 10:30                           ` [PATCH 00/21] Add -fself-test framework for fast, early unit-testing (unittests v5) Bernd Schmidt
2016-06-02 13:41                             ` David Malcolm
2016-06-02 20:41                               ` [PATCH 00/16] v6 of -fself-test/unit-testing patch David Malcolm
2016-06-02 20:41                                 ` [PATCH 01/16] Core of selftest framework (v6) David Malcolm
2016-06-02 23:21                                   ` Bernd Schmidt
2016-06-03 18:47                                     ` [PATCH] Selftest framework (v7) David Malcolm
2016-06-05 11:38                                       ` Bernd Schmidt
2016-06-06 14:17                                         ` David Malcolm
2016-06-06 14:41                                           ` Bernd Schmidt
2016-06-06 17:18                                             ` [Committed] Selftest framework (v8) David Malcolm
2016-06-06 21:47                                           ` [PATCH] Selftest framework (v7) Trevor Saunders
2016-06-06 21:57                                             ` Jakub Jelinek
2016-06-07  2:07                                               ` Trevor Saunders
2016-06-07 14:18                                                 ` David Malcolm
2016-06-08  0:23                                                   ` Trevor Saunders
2016-06-02 20:41                                 ` [PATCH 10/16] Add hash-map-tests.c David Malcolm
2016-06-02 20:41                                 ` [PATCH 02/16] diagnostic-show-locus.c: add selftests David Malcolm
2016-06-02 20:41                                 ` [PATCH 03/16] spellcheck.c: convert Levenshtein test from a plugin to a selftest David Malcolm
2016-06-02 20:41                                 ` [PATCH 04/16] bitmap.c: add selftests David Malcolm
2016-06-02 20:41                                 ` [PATCH 05/16] tree-cfg.c: " David Malcolm
2016-06-02 20:41                                 ` [PATCH 09/16] gimple.c: " David Malcolm
2016-06-02 20:57                                 ` [PATCH 08/16] Add function-tests.c David Malcolm
2016-06-02 20:58                                 ` [PATCH 14/16] tree.c: add selftests David Malcolm
2016-06-02 21:03                                 ` [PATCH 12/16] input.c: " David Malcolm
2016-06-02 21:03                                 ` [PATCH 13/16] Add rtl-tests.c David Malcolm
2016-06-02 21:03                                 ` [PATCH 16/16] wide-int.cc: add selftests David Malcolm
2016-06-02 21:06                                 ` [PATCH 15/16] vec.c: " David Malcolm
2016-06-02 21:09                                 ` [PATCH 07/16] fold-const.c: " David Malcolm
2016-06-02 21:09                                 ` [PATCH 11/16] Add hash-set-tests.c David Malcolm
2016-06-02 21:09                                 ` [PATCH 06/16] et-forest.c: add selftests David Malcolm
2015-10-28 16:05             ` [PATCH 00/16] Unit tests framework (v3) Jeff Law
2015-10-28 20:26             ` Mike Stump
2015-06-23 19:06     ` [PATCH 00/17] RFC: Addding a unit testing framework to gcc Jeff Law
2015-06-23 20:04     ` Mike Stump
2015-06-10 18:21   ` David Malcolm
2015-06-10 22:15     ` Jakub Jelinek
2015-06-11 14:49 ` Martin Liška

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1447952699-40820-9-git-send-email-dmalcolm@redhat.com \
    --to=dmalcolm@redhat.com \
    --cc=bschmidt@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).