[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/5] stdalign-tests: new module
From: |
Paul Eggert |
Subject: |
[PATCH 2/5] stdalign-tests: new module |
Date: |
Sun, 16 Oct 2011 17:27:54 -0700 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.23) Gecko/20110922 Thunderbird/3.1.15 |
* modules/stdalign-tests, tests/test-stdalign.c: New files.
---
ChangeLog | 3 ++
modules/stdalign-tests | 12 +++++++
tests/test-stdalign.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 92 insertions(+), 0 deletions(-)
create mode 100644 modules/stdalign-tests
create mode 100644 tests/test-stdalign.c
diff --git a/ChangeLog b/ChangeLog
index b3b3034..99664de 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,9 @@
* MODULES.html.sh (c1x_core_properties): Add stdalign.
* doc/gnulib.texi (Header File Substitutes): Add stdalign.
+ stdalign-tests: new module
+ * modules/stdalign-tests, tests/test-stdalign.c: New files.
+
2011-10-15 Bruno Haible <address@hidden>
xstrtoll: Fix compilation failure.
diff --git a/modules/stdalign-tests b/modules/stdalign-tests
new file mode 100644
index 0000000..44382bf
--- /dev/null
+++ b/modules/stdalign-tests
@@ -0,0 +1,12 @@
+Files:
+tests/test-stdalign.c
+
+Depends-on:
+verify
+stdint
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-stdalign
+check_PROGRAMS += test-stdalign
diff --git a/tests/test-stdalign.c b/tests/test-stdalign.c
new file mode 100644
index 0000000..136661a
--- /dev/null
+++ b/tests/test-stdalign.c
@@ -0,0 +1,77 @@
+/* Test of <stdalign.h>.
+ Copyright 2009-2011 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 this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert, inspired by Bruno Haible's test-alignof.c. */
+
+#include <config.h>
+
+#include <stdalign.h>
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "verify.h"
+
+typedef long double longdouble;
+typedef struct { char a[1]; } struct1;
+typedef struct { char a[2]; } struct2;
+typedef struct { char a[3]; } struct3;
+typedef struct { char a[4]; } struct4;
+
+verify (__alignof_is_defined == 1);
+#ifndef alignof
+# error "alignof is not a macro"
+#endif
+
+#if __alignas_is_defined
+verify (__alignas_is_defined == 1);
+# ifndef alignas
+# error "alignas is not a macro"
+# endif
+# define CHECK_ALIGNAS(type) \
+ type alignas (1 << 3) type##_alignas; \
+ type _Alignas (1 << 3) type##_Alignas;
+#else
+# define CHECK_ALIGNAS(type)
+#endif
+
+#define CHECK(type) \
+ typedef struct { char slot1; type slot2; } type##_helper; \
+ verify (alignof (type) == offsetof (type##_helper, slot2)); \
+ verify (_Alignof (type) == alignof (type)); \
+ const int type##_alignment = alignof (type); \
+ CHECK_ALIGNAS(type)
+
+CHECK (char)
+CHECK (short)
+CHECK (int)
+CHECK (long)
+CHECK (float)
+CHECK (double)
+CHECK (longdouble)
+#ifdef INT64_MAX
+CHECK (int64_t)
+#endif
+CHECK (struct1)
+CHECK (struct2)
+CHECK (struct3)
+CHECK (struct4)
+
+int
+main ()
+{
+ return 0;
+}
--
1.7.4.4
- [PATCH 2/5] stdalign-tests: new module,
Paul Eggert <=