]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: ceph_ioprio_string_to_class always returns -EINVAL 2661/head
authorLoic Dachary <loic-201408@dachary.org>
Tue, 7 Oct 2014 12:06:38 +0000 (14:06 +0200)
committerLoic Dachary <loic-201408@dachary.org>
Tue, 7 Oct 2014 18:30:26 +0000 (20:30 +0200)
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 <loic-201408@dachary.org>
(cherry picked from commit 3535b7aba3df8b54fa5117b8a9c2f52b8f0f118b)

src/common/io_priority.cc
src/test/Makefile.am
src/test/common/test_io_priority.cc [new file with mode: 0644]

index b9eeae88f65f8336cea1f83103f204357abf753c..be4dc2a20366b1b55cf8a255213c723d85979eeb 100644 (file)
@@ -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;
index d33a4ea241af761781154783b2e656b57c5a1319..2c9b8488563676399f982792ac81b0030581d436 100644 (file)
@@ -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 (file)
index 0000000..b2d4e26
--- /dev/null
@@ -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 <contact@redhat.com>
+ *
+ * Author: Loic Dachary <loic@dachary.org>
+ *
+ *  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 <errno.h>
+#include <gtest/gtest.h>
+
+#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:
+ */