From: Loic Dachary Date: Tue, 7 Oct 2014 12:06:38 +0000 (+0200) Subject: common: ceph_ioprio_string_to_class always returns -EINVAL X-Git-Tag: v0.87~32^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=7c4e278a1e12f8ecf4aca2858336fe367569340c;p=ceph.git common: ceph_ioprio_string_to_class always returns -EINVAL The l string is always empty because std::transform needs a pre-allocated string. Replace with the in-place version. Add unit tests. http://tracker.ceph.com/issues/9677 Fixes: #9677 Signed-off-by: Loic Dachary (cherry picked from commit 3535b7aba3df8b54fa5117b8a9c2f52b8f0f118b) --- diff --git a/src/common/io_priority.cc b/src/common/io_priority.cc index b9eeae88f65f8..be4dc2a20366b 100644 --- a/src/common/io_priority.cc +++ b/src/common/io_priority.cc @@ -41,8 +41,8 @@ int ceph_ioprio_set(int whence, int who, int ioprio) int ceph_ioprio_string_to_class(const std::string& s) { - std::string l; - std::transform(s.begin(), s.end(), l.begin(), ::tolower); + std::string l = s; + std::transform(l.begin(), l.end(), l.begin(), ::tolower); if (l == "idle") return IOPRIO_CLASS_IDLE; diff --git a/src/test/Makefile.am b/src/test/Makefile.am index d33a4ea241af7..2c9b848856367 100644 --- a/src/test/Makefile.am +++ b/src/test/Makefile.am @@ -372,6 +372,9 @@ unittest_pglog_SOURCES = test/osd/TestPGLog.cc unittest_pglog_CXXFLAGS = $(UNITTEST_CXXFLAGS) unittest_pglog_LDADD = $(LIBOSD) $(UNITTEST_LDADD) $(CEPH_GLOBAL) check_PROGRAMS += unittest_pglog +if LINUX +unittest_pglog_LDADD += -ldl +endif # LINUX unittest_ecbackend_SOURCES = test/osd/TestECBackend.cc unittest_ecbackend_CXXFLAGS = $(UNITTEST_CXXFLAGS) @@ -388,9 +391,10 @@ unittest_lru_CXXFLAGS = $(UNITTEST_CXXFLAGS) unittest_lru_LDADD = $(UNITTEST_LDADD) $(CEPH_GLOBAL) check_PROGRAMS += unittest_lru -if LINUX -unittest_pglog_LDADD += -ldl -endif # LINUX +unittest_io_priority_SOURCES = test/common/test_io_priority.cc +unittest_io_priority_CXXFLAGS = $(UNITTEST_CXXFLAGS) +unittest_io_priority_LDADD = $(UNITTEST_LDADD) $(CEPH_GLOBAL) +check_PROGRAMS += unittest_io_priority unittest_gather_SOURCES = test/gather.cc unittest_gather_LDADD = $(UNITTEST_LDADD) $(CEPH_GLOBAL) diff --git a/src/test/common/test_io_priority.cc b/src/test/common/test_io_priority.cc new file mode 100644 index 0000000000000..b2d4e2601164a --- /dev/null +++ b/src/test/common/test_io_priority.cc @@ -0,0 +1,51 @@ +// -*- 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) 2014 Red Hat + * + * Author: Loic Dachary + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + */ + +#include +#include + +#include "common/io_priority.h" + +TEST(io_priority, ceph_ioprio_string_to_class) { + ASSERT_EQ(IOPRIO_CLASS_IDLE, ceph_ioprio_string_to_class("idle")); + ASSERT_EQ(IOPRIO_CLASS_IDLE, ceph_ioprio_string_to_class("IDLE")); + + ASSERT_EQ(IOPRIO_CLASS_BE, ceph_ioprio_string_to_class("be")); + ASSERT_EQ(IOPRIO_CLASS_BE, ceph_ioprio_string_to_class("BE")); + ASSERT_EQ(IOPRIO_CLASS_BE, ceph_ioprio_string_to_class("besteffort")); + ASSERT_EQ(IOPRIO_CLASS_BE, ceph_ioprio_string_to_class("BESTEFFORT")); + ASSERT_EQ(IOPRIO_CLASS_BE, ceph_ioprio_string_to_class("best effort")); + ASSERT_EQ(IOPRIO_CLASS_BE, ceph_ioprio_string_to_class("BEST EFFORT")); + + ASSERT_EQ(IOPRIO_CLASS_RT, ceph_ioprio_string_to_class("rt")); + ASSERT_EQ(IOPRIO_CLASS_RT, ceph_ioprio_string_to_class("RT")); + ASSERT_EQ(IOPRIO_CLASS_RT, ceph_ioprio_string_to_class("realtime")); + ASSERT_EQ(IOPRIO_CLASS_RT, ceph_ioprio_string_to_class("REALTIME")); + ASSERT_EQ(IOPRIO_CLASS_RT, ceph_ioprio_string_to_class("real time")); + ASSERT_EQ(IOPRIO_CLASS_RT, ceph_ioprio_string_to_class("REAL TIME")); + + ASSERT_EQ(-EINVAL, ceph_ioprio_string_to_class("invalid")); +} + +/* + * Local Variables: + * compile-command: "cd ../.. ; + * make -j4 unittest_io_priority && + * libtool --mode=execute valgrind --tool=memcheck --leak-check=full \ + * ./unittest_io_priority + * " + * End: + */