]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/common/test_util.cc
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / test / common / test_util.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 General Public
10 * License version 2, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15 #include "common/ceph_context.h"
16 #include "include/util.h"
17 #include "gtest/gtest.h"
18
19 #include <sstream>
20
21 TEST(util, unit_to_bytesize)
22 {
23 ASSERT_EQ(1234ll, unit_to_bytesize("1234", &cerr));
24 ASSERT_EQ(1024ll, unit_to_bytesize("1K", &cerr));
25 ASSERT_EQ(1024ll, unit_to_bytesize("1k", &cerr));
26 ASSERT_EQ(1048576ll, unit_to_bytesize("1M", &cerr));
27 ASSERT_EQ(1073741824ll, unit_to_bytesize("1G", &cerr));
28 ASSERT_EQ(1099511627776ll, unit_to_bytesize("1T", &cerr));
29 ASSERT_EQ(1125899906842624ll, unit_to_bytesize("1P", &cerr));
30 ASSERT_EQ(1152921504606846976ll, unit_to_bytesize("1E", &cerr));
31
32 ASSERT_EQ(65536ll, unit_to_bytesize(" 64K", &cerr));
33 }
34
35 #if defined(__linux__)
36 TEST(util, collect_sys_info)
37 {
38 map<string, string> sys_info;
39
40 CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_CLIENT))->get();
41 collect_sys_info(&sys_info, cct);
42
43 ASSERT_TRUE(sys_info.find("distro") != sys_info.end());
44 ASSERT_TRUE(sys_info.find("distro_version") != sys_info.end());
45 ASSERT_TRUE(sys_info.find("distro_description") != sys_info.end());
46
47 cct->put();
48 }
49 #endif