aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/lib.h
diff options
context:
space:
mode:
authorklaar36 <klas.arvidsson@liu.se>2015-03-20 17:30:24 +0100
committerklaar36 <klas.arvidsson@liu.se>2015-03-20 17:30:24 +0100
commite7bc50ca8ffcaa6ed68ebd2315f78b0f5a7d10ad (patch)
tree4de97af7207676b69cb6a9aba8cb443cc134855d /src/tests/lib.h
parentb0418a24e709f0632d2ede5b0f327c422931939b (diff)
downloadpintos-rs-e7bc50ca8ffcaa6ed68ebd2315f78b0f5a7d10ad.tar.gz
Initial Pintos
Diffstat (limited to 'src/tests/lib.h')
-rw-r--r--src/tests/lib.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/tests/lib.h b/src/tests/lib.h
new file mode 100644
index 0000000..648327b
--- /dev/null
+++ b/src/tests/lib.h
@@ -0,0 +1,50 @@
+#ifndef TESTS_LIB_H
+#define TESTS_LIB_H
+
+#include <debug.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <syscall.h>
+
+extern const char *test_name;
+extern bool quiet;
+
+void msg (const char *, ...) PRINTF_FORMAT (1, 2);
+void fail (const char *, ...) PRINTF_FORMAT (1, 2) NO_RETURN;
+
+/* Takes an expression to test for SUCCESS and a message, which
+ may include printf-style arguments. Logs the message, then
+ tests the expression. If it is zero, indicating failure,
+ emits the message as a failure.
+
+ Somewhat tricky to use:
+
+ - SUCCESS must not have side effects that affect the
+ message, because that will cause the original message and
+ the failure message to differ.
+
+ - The message must not have side effects of its own, because
+ it will be printed twice on failure, or zero times on
+ success if quiet is set. */
+#define CHECK(SUCCESS, ...) \
+ do \
+ { \
+ msg (__VA_ARGS__); \
+ if (!(SUCCESS)) \
+ fail (__VA_ARGS__); \
+ } \
+ while (0)
+
+void shuffle (void *, size_t cnt, size_t size);
+
+void exec_children (const char *child_name, pid_t pids[], size_t child_cnt);
+void wait_children (pid_t pids[], size_t child_cnt);
+
+void check_file_handle (int fd, const char *file_name,
+ const void *buf_, size_t filesize);
+void check_file (const char *file_name, const void *buf, size_t filesize);
+
+void compare_bytes (const void *read_data, const void *expected_data,
+ size_t size, size_t ofs, const char *file_name);
+
+#endif /* test/lib.h */