]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/system/systest_runnable.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / test / system / systest_runnable.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2011 New Dream Network
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15 #ifndef CEPH_SYSTEM_TEST_H
16 #define CEPH_SYSTEM_TEST_H
17
18 #include <pthread.h>
19 #include <stdio.h>
20 #include <string>
21 #include <vector>
22
23 #include "common/Preforker.h"
24
25 #define RETURN1_IF_NOT_VAL(expected, expr) \
26 do {\
27 int _rinv_ret = expr;\
28 if (_rinv_ret != expected) {\
29 printf("%s: file %s, line %d: expected %d, got %d\n",\
30 get_id_str(), __FILE__, __LINE__, expected, _rinv_ret);\
31 return 1; \
32 }\
33 } while(0);
34
35 #define RETURN1_IF_NONZERO(expr) \
36 RETURN1_IF_NOT_VAL(0, expr)
37
38 extern void* systest_runnable_pthread_helper(void *arg);
39 std::string get_temp_pool_name(const char* prefix);
40 /* Represents a single test thread / process.
41 *
42 * Inherit from this class and implement the test body in run().
43 */
44 class SysTestRunnable
45 {
46 public:
47 static const int ID_STR_SZ = 128;
48
49 SysTestRunnable(int argc, const char **argv);
50 virtual ~SysTestRunnable();
51
52 /* Returns 0 on success; error code otherwise. */
53 virtual int run() = 0;
54
55 /* Return a string identifying the runnable. */
56 const char* get_id_str(void) const;
57
58 /* Start the Runnable */
59 int start();
60
61 /* Wait until the Runnable is finished. Returns an error string on failure. */
62 std::string join();
63
64 /* Starts a bunch of SystemTestRunnables and waits until they're done.
65 *
66 * Returns an error string on failure. */
67 static std::string run_until_finished(std::vector < SysTestRunnable * >&
68 runnables);
69
70 protected:
71 int m_argc;
72 const char **m_argv;
73
74 private:
75 explicit SysTestRunnable(const SysTestRunnable &rhs);
76 SysTestRunnable& operator=(const SysTestRunnable &rhs);
77 void update_id_str(bool started);
78 void set_argv(int argc, const char **argv);
79
80 friend void* systest_runnable_pthread_helper(void *arg);
81
82 Preforker preforker;
83 const char **m_argv_orig;
84 bool m_started;
85 int m_id;
86 pthread_t m_pthread;
87 char m_id_str[ID_STR_SZ];
88 };
89
90 #endif