aboutsummaryrefslogtreecommitdiffstats
path: root/test.h
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2018-12-15 14:56:23 +0100
committerMattias Andrée <maandree@kth.se>2018-12-15 14:56:23 +0100
commitd1122de6bb461e0448897869b4406300c12f259f (patch)
tree031bf1bdb887be786e5bb370c83eb52eef649ddc /test.h
parentA bunch of stuff (diff)
downloadlibsimple-d1122de6bb461e0448897869b4406300c12f259f.tar.gz
libsimple-d1122de6bb461e0448897869b4406300c12f259f.tar.bz2
libsimple-d1122de6bb461e0448897869b4406300c12f259f.tar.xz
More tests and fix attributes on wcsndup
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'test.h')
-rw-r--r--test.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/test.h b/test.h
index fe229ef..d8ac2d4 100644
--- a/test.h
+++ b/test.h
@@ -95,3 +95,42 @@ test_fprintf(FILE *restrict stream, const char *restrict format, ...)
return test_vfprintf(stream, format, ap);
va_end(ap);
}
+
+
+
+static size_t
+gcd(size_t u, size_t v)
+{
+ size_t t;
+ int shift = 0;
+ /* Not needed because u>0, v>0: if (!(u | v)) return u + v; */
+ while (!((u | v) & 1)) u >>= 1, v >>= 1, shift++;
+ while (!(u & 1)) u >>= 1;
+ do {
+ while (!(v & 1)) v >>= 1;
+ if (u > v) t = u, u = v, v = t;
+ } while (v -= u);
+ return u << shift;
+}
+
+static inline size_t
+lcm(size_t u, size_t v)
+{
+ return u / gcd(u, v) * v;
+}
+
+#define ASSERT_ALIGNMENT(INFO, ALIGN)\
+ do {\
+ assert((INFO)->alignment <= lcm(cacheline, ALIGN));\
+ assert(!((INFO)->alignment % (ALIGN)));\
+ if ((cacheline - (ALIGN) % cacheline) % cacheline + (INFO)->size % (ALIGN) > cacheline)\
+ assert(!((INFO)->alignment % cacheline));\
+ } while (0)
+
+#define DEFINE_PAGESIZE size_t pagesize = (size_t)sysconf(_SC_PAGESIZE)
+
+#ifdef _SC_LEVEL1_DCACHE_LINESIZ
+#define DEFINE_CACHELINE size_t cacheline = (size_t)sysconf(_SC_LEVEL1_DCACHE_LINESIZE)
+#else
+#define DEFINE_CACHELINE size_t cacheline = 64
+#endif