about summary refs log tree commit diff
path: root/gmon/tst-gmon.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2017-08-15 15:49:40 +0200
committerFlorian Weimer <fweimer@redhat.com>2017-08-15 15:49:45 +0200
commit6014c65de2ac75ac4ef147754d80c7992f07ece8 (patch)
treefb1c32b9acf4a86ce341a0ce8eb5923de389d30f /gmon/tst-gmon.c
parentee72219a497b6317c49dc0a9a02308fe408c8c5e (diff)
downloadglibc-6014c65de2ac75ac4ef147754d80c7992f07ece8.tar.gz
glibc-6014c65de2ac75ac4ef147754d80c7992f07ece8.tar.xz
glibc-6014c65de2ac75ac4ef147754d80c7992f07ece8.zip
gmon: Add test for basic mcount/gprof functionality
Diffstat (limited to 'gmon/tst-gmon.c')
-rw-r--r--gmon/tst-gmon.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/gmon/tst-gmon.c b/gmon/tst-gmon.c
new file mode 100644
index 0000000000..ce81aa41b8
--- /dev/null
+++ b/gmon/tst-gmon.c
@@ -0,0 +1,50 @@
+/* Test program for profiling information collection (_mcount/gprof).
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+/* This program does not use the test harness because we want tight
+   control over the call graph.  */
+
+__attribute__ ((noinline, noclone, weak)) void
+f1 (void)
+{
+}
+
+__attribute__ ((noinline, noclone, weak)) void
+f2 (void)
+{
+  f1 ();
+  /* Prevent tail call.  */
+  asm volatile ("");
+}
+
+__attribute__ ((noinline, noclone, weak)) void
+f3 (int count)
+{
+  for (int i = 0; i < count; ++i)
+    {
+      f1 ();
+      f2 ();
+    }
+}
+
+int
+main (void)
+{
+  f3 (1000);
+  return 0;
+}