lib: Add new test library API

The main features are:

o The cleanup callback is not passed directly to various library functions but
  is set once globally in the structure that describes a test

   - this makes the test API easier to use

   - also fixes a few common mistakes such as passing cleanup callback
     to functions executed from a cleanup

o Most of the boilerplate code is moved to library

  - no more copying standard looping code around :)

o Various resources are initialized and freed automatically when requested

  - this means much less race conditions and ordering problems in cleanups

o The result reporting functions now use shared memory to propagate
  test results from child processes

  - writing tests in child processes is now easier than ever

+ The test-writing-guidelines.txt were updated

Many thanks to Jan who reviewed numerous respins of this patches and
provided valuable suggestions and also to Alexey who pointed out some
stupid mistakes of mine.

Reviewed-by: Jan Stancek <jstancek@redhat.com>
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
diff --git a/lib/ltp_priv.h b/lib/ltp_priv.h
index 813df2a..de45e4a 100644
--- a/lib/ltp_priv.h
+++ b/lib/ltp_priv.h
@@ -22,6 +22,8 @@
 #ifndef __LTP_PRIV_H__
 #define __LTP_PRIV_H__
 
+#include <stdarg.h>
+
 /* declared in tst_tmpdir.c */
 const char *tst_get_startwd(void);
 
@@ -50,4 +52,26 @@
 const char *parse_opts(int ac, char **av, const option_t *user_optarr, void
                        (*uhf)(void));
 
+/* Interface for rerouting to new lib calls from tst_res.c */
+extern void *tst_test;
+
+void tst_vbrk_(const char *file, const int lineno, int ttype,
+               const char *fmt, va_list va) __attribute__((noreturn));
+
+void tst_brk_(const char *file, const int lineno, int ttype,
+              const char *msg, ...) __attribute__((noreturn));
+
+void tst_vres_(const char *file, const int lineno, int ttype,
+               const char *fmt, va_list va);
+
+void tst_res_(const char *file, const int lineno, int ttype,
+              const char *msg, ...);
+
+
+#define NO_NEWLIB_ASSERT(file, lineno)                                \
+	if (tst_test) {                                               \
+		tst_brk_(file, lineno, TBROK,                         \
+			 "%s() executed from newlib!", __FUNCTION__); \
+	}
+
 #endif /* __LTP_PRIV_H__ */