summaryrefslogtreecommitdiffstats
path: root/src/test/system/systest_runnable.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
commite6918187568dbd01842d8d1d2c808ce16a894239 (patch)
tree64f88b554b444a49f656b6c656111a145cbbaa28 /src/test/system/systest_runnable.h
parentInitial commit. (diff)
downloadceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz
ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/system/systest_runnable.h')
-rw-r--r--src/test/system/systest_runnable.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/test/system/systest_runnable.h b/src/test/system/systest_runnable.h
new file mode 100644
index 000000000..bfa9130ed
--- /dev/null
+++ b/src/test/system/systest_runnable.h
@@ -0,0 +1,94 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2011 New Dream Network
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+
+#ifndef CEPH_SYSTEM_TEST_H
+#define CEPH_SYSTEM_TEST_H
+
+#include <pthread.h>
+#include <stdio.h>
+#include <string>
+#include <vector>
+
+#ifndef _WIN32
+#include "common/Preforker.h"
+#endif
+
+#define RETURN1_IF_NOT_VAL(expected, expr) \
+ do {\
+ int _rinv_ret = expr;\
+ if (_rinv_ret != expected) {\
+ printf("%s: file %s, line %d: expected %d, got %d\n",\
+ get_id_str(), __FILE__, __LINE__, expected, _rinv_ret);\
+ return 1; \
+ }\
+ } while(0);
+
+#define RETURN1_IF_NONZERO(expr) \
+ RETURN1_IF_NOT_VAL(0, expr)
+
+extern void* systest_runnable_pthread_helper(void *arg);
+std::string get_temp_pool_name(const char* prefix);
+/* Represents a single test thread / process.
+ *
+ * Inherit from this class and implement the test body in run().
+*/
+class SysTestRunnable
+{
+public:
+ static const int ID_STR_SZ = 196;
+
+ SysTestRunnable(int argc, const char **argv);
+ virtual ~SysTestRunnable();
+
+ /* Returns 0 on success; error code otherwise. */
+ virtual int run() = 0;
+
+ /* Return a string identifying the runnable. */
+ const char* get_id_str(void) const;
+
+ /* Start the Runnable */
+ int start();
+
+ /* Wait until the Runnable is finished. Returns an error string on failure. */
+ std::string join();
+
+ /* Starts a bunch of SystemTestRunnables and waits until they're done.
+ *
+ * Returns an error string on failure. */
+ static std::string run_until_finished(std::vector < SysTestRunnable * >&
+ runnables);
+
+protected:
+ int m_argc;
+ const char **m_argv;
+
+private:
+ explicit SysTestRunnable(const SysTestRunnable &rhs);
+ SysTestRunnable& operator=(const SysTestRunnable &rhs);
+ void update_id_str(bool started);
+ void set_argv(int argc, const char **argv);
+
+ friend void* systest_runnable_pthread_helper(void *arg);
+
+ #ifndef _WIN32
+ Preforker preforker;
+ #endif
+ const char **m_argv_orig;
+ bool m_started;
+ int m_id;
+ pthread_t m_pthread;
+ char m_id_str[ID_STR_SZ];
+};
+
+#endif