]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/libcephfs/multiclient.cc
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / test / libcephfs / multiclient.cc
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 #include "gtest/gtest.h"
16 #include "include/cephfs/libcephfs.h"
17 #include <errno.h>
18 #include <fcntl.h>
19 #include <unistd.h>
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <dirent.h>
23 #include <sys/xattr.h>
24
25 TEST(LibCephFS, MulticlientSimple) {
26 struct ceph_mount_info *ca, *cb;
27 ASSERT_EQ(ceph_create(&ca, NULL), 0);
28 ASSERT_EQ(ceph_conf_read_file(ca, NULL), 0);
29 ASSERT_EQ(0, ceph_conf_parse_env(ca, NULL));
30 ASSERT_EQ(ceph_mount(ca, NULL), 0);
31
32 ASSERT_EQ(ceph_create(&cb, NULL), 0);
33 ASSERT_EQ(ceph_conf_read_file(cb, NULL), 0);
34 ASSERT_EQ(0, ceph_conf_parse_env(cb, NULL));
35 ASSERT_EQ(ceph_mount(cb, NULL), 0);
36
37 char name[20];
38 snprintf(name, sizeof(name), "foo.%d", getpid());
39 int fda = ceph_open(ca, name, O_CREAT|O_RDWR, 0644);
40 ASSERT_LE(0, fda);
41 int fdb = ceph_open(cb, name, O_CREAT|O_RDWR, 0644);
42 ASSERT_LE(0, fdb);
43
44 char bufa[4] = "foo";
45 char bufb[4];
46
47 for (int i=0; i<10; i++) {
48 strcpy(bufa, "foo");
49 ASSERT_EQ((int)sizeof(bufa), ceph_write(ca, fda, bufa, sizeof(bufa), i*6));
50 ASSERT_EQ((int)sizeof(bufa), ceph_read(cb, fdb, bufb, sizeof(bufa), i*6));
51 ASSERT_EQ(0, memcmp(bufa, bufb, sizeof(bufa)));
52 strcpy(bufb, "bar");
53 ASSERT_EQ((int)sizeof(bufb), ceph_write(cb, fdb, bufb, sizeof(bufb), i*6+3));
54 ASSERT_EQ((int)sizeof(bufb), ceph_read(ca, fda, bufa, sizeof(bufb), i*6+3));
55 ASSERT_EQ(0, memcmp(bufa, bufb, sizeof(bufa)));
56 }
57
58 ceph_close(ca, fda);
59 ceph_close(cb, fdb);
60
61 ceph_shutdown(ca);
62 ceph_shutdown(cb);
63 }
64
65 TEST(LibCephFS, MulticlientHoleEOF) {
66 struct ceph_mount_info *ca, *cb;
67 ASSERT_EQ(ceph_create(&ca, NULL), 0);
68 ASSERT_EQ(ceph_conf_read_file(ca, NULL), 0);
69 ASSERT_EQ(0, ceph_conf_parse_env(ca, NULL));
70 ASSERT_EQ(ceph_mount(ca, NULL), 0);
71
72 ASSERT_EQ(ceph_create(&cb, NULL), 0);
73 ASSERT_EQ(ceph_conf_read_file(cb, NULL), 0);
74 ASSERT_EQ(0, ceph_conf_parse_env(cb, NULL));
75 ASSERT_EQ(ceph_mount(cb, NULL), 0);
76
77 char name[20];
78 snprintf(name, sizeof(name), "foo.%d", getpid());
79 int fda = ceph_open(ca, name, O_CREAT|O_RDWR, 0644);
80 ASSERT_LE(0, fda);
81 int fdb = ceph_open(cb, name, O_CREAT|O_RDWR, 0644);
82 ASSERT_LE(0, fdb);
83
84 ASSERT_EQ(3, ceph_write(ca, fda, "foo", 3, 0));
85 ASSERT_EQ(0, ceph_ftruncate(ca, fda, 1000000));
86
87 char buf[4];
88 ASSERT_EQ(2, ceph_read(cb, fdb, buf, sizeof(buf), 1000000-2));
89 ASSERT_EQ(0, buf[0]);
90 ASSERT_EQ(0, buf[1]);
91
92 ceph_close(ca, fda);
93 ceph_close(cb, fdb);
94
95 ceph_shutdown(ca);
96 ceph_shutdown(cb);
97 }