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