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/include/tst_safe_stdio.h b/include/tst_safe_stdio.h
new file mode 100644
index 0000000..9162a6d
--- /dev/null
+++ b/include/tst_safe_stdio.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2013-2016 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * 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 2 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/>.
+ */
+
+#ifndef TST_SAFE_STDIO_H__
+#define TST_SAFE_STDIO_H__
+
+#include <stdio.h>
+
+#include "safe_stdio_fn.h"
+
+#define SAFE_FOPEN(path, mode) \
+ safe_fopen(__FILE__, __LINE__, NULL, path, mode)
+
+#define SAFE_FCLOSE(f) \
+ safe_fclose(__FILE__, __LINE__, NULL, f)
+
+#define SAFE_ASPRINTF(strp, fmt, ...) \
+ safe_asprintf(__FILE__, __LINE__, NULL, strp, fmt, __VA_ARGS__)
+
+#define SAFE_POPEN(command, type) \
+ safe_popen(__FILE__, __LINE__, NULL, command, type)
+
+#endif /* TST_SAFE_STDIO_H__ */