tests: move fill_memory and fill_memory_ex into a separate file
authorEugene Syromyatnikov <evgsyr@gmail.com>
Sun, 2 Oct 2016 20:39:11 +0000 (23:39 +0300)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 26 Oct 2016 01:06:09 +0000 (01:06 +0000)
* tests/fill_memory.c: New file.
* tests/Makefile.am (libtests_a_SOURCES): Add it.
* tests/quotactl.h (fill_memory, fill_memory_ex): Move to fill_memory.c.
* tests/tests.h (fill_memory, fill_memory_ex): New prototypes.

tests/Makefile.am
tests/fill_memory.c [new file with mode: 0644]
tests/quotactl.h
tests/tests.h

index 0c249696eedde30d41164578789e7c8f905ec6eb..61381993da63371dec784678b6ebb9dd7454eeda 100644 (file)
@@ -43,6 +43,7 @@ AM_LDFLAGS = $(ARCH_MFLAGS)
 libtests_a_SOURCES = \
        errno2name.c \
        error_msg.c \
+       fill_memory.c \
        get_page_size.c \
        hexdump_strdup.c \
        hexquote_strndup.c \
diff --git a/tests/fill_memory.c b/tests/fill_memory.c
new file mode 100644 (file)
index 0000000..9a6e83c
--- /dev/null
@@ -0,0 +1,18 @@
+#include "tests.h"
+
+void
+fill_memory_ex(char *ptr, size_t size, unsigned char start,
+              unsigned char period)
+{
+       size_t i;
+
+       for (i = 0; i < size; i++) {
+               ptr[i] = start + i % period;
+       }
+}
+
+void
+fill_memory(char *ptr, size_t size)
+{
+       fill_memory_ex(ptr, size, 0x80, 0x80);
+}
index 240fdb29e26f67400f5046f791f17d199bbf54d3..b97153f11798ceae33d7cad706e3738612c70519 100644 (file)
@@ -91,23 +91,6 @@ enum check_quotactl_flags {
 };
 
 
-static inline void
-fill_memory_ex(char *ptr, size_t size, unsigned char start,
-              unsigned char period)
-{
-       size_t i;
-
-       for (i = 0; i < size; i++) {
-               ptr[i] = start + i % period;
-       }
-}
-
-static inline void
-fill_memory(char *ptr, size_t size)
-{
-       fill_memory_ex(ptr, size, 0x80, 0x80);
-}
-
 static inline void
 check_quota(uint32_t flags, int cmd, const char *cmd_str,
        const char *special, const char *special_str, ...)
index f3ddc85edbcd527c97764329e7d845fb28c4cf01..10bccdbcc87816fb9e2526a3f7b42b241735c50c 100644 (file)
@@ -67,6 +67,16 @@ void *tail_alloc(const size_t)
 void *tail_memdup(const void *, const size_t)
        ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((2));
 
+/*
+ * Fill memory (pointed by ptr, having size bytes) with different bytes (with
+ * values starting with start and resetting every period) in order to catch
+ * sign, byte order and/or alignment errors.
+ */
+void fill_memory_ex(char *ptr, size_t size, unsigned char start,
+                   unsigned char period);
+/* Shortcut for fill_memory_ex(ptr, size, 0x80, 0x80) */
+void fill_memory(char *ptr, size_t size);
+
 /* Close stdin, move stdout to a non-standard descriptor, and print. */
 void tprintf(const char *, ...)
        ATTRIBUTE_FORMAT((printf, 1, 2));