From e409d3d745f627f8ce4539498c45e3631124310b Mon Sep 17 00:00:00 2001 From: sdong Date: Mon, 8 Jun 2015 11:43:55 -0700 Subject: [PATCH] Make "make all" work for CYGWIN Summary: Some test and benchmark codes don't build for CYGWIN. Fix it. Test Plan: Build "make all" with TARGET_OS=Cygwin on cygwin and make sure it passes. Reviewers: rven, yhchiang, anthony, igor, kradhakrishnan Reviewed By: igor, kradhakrishnan Subscribers: leveldb, dhruba Differential Revision: https://reviews.facebook.net/D39711 --- db/column_family_test.cc | 2 +- db/compact_files_test.cc | 6 +++--- db/compaction_job_stats_test.cc | 2 +- db/comparator_db_test.cc | 5 +++++ db/db_bench.cc | 6 +++++- db/db_test.cc | 2 +- db/memtable_list_test.cc | 11 ++++++----- utilities/backupable/backupable_db_test.cc | 13 +++++++------ utilities/ttl/ttl_test.cc | 8 +++++++- .../write_batch_with_index_test.cc | 9 +++++---- 10 files changed, 41 insertions(+), 23 deletions(-) diff --git a/db/column_family_test.cc b/db/column_family_test.cc index c03e0d137..484a4c66a 100644 --- a/db/column_family_test.cc +++ b/db/column_family_test.cc @@ -121,7 +121,7 @@ class ColumnFamilyTest : public testing::Test { #ifndef CYGWIN return std::stoi(value); #else - return std::strtol(value.c_str(), 0); + return std::strtol(value.c_str(), 0 /* off */, 10 /* base */); #endif } diff --git a/db/compact_files_test.cc b/db/compact_files_test.cc index 3208b264b..b63e7f678 100644 --- a/db/compact_files_test.cc +++ b/db/compact_files_test.cc @@ -9,6 +9,7 @@ #include "rocksdb/db.h" #include "rocksdb/env.h" +#include "util/string_util.h" #include "util/testharness.h" namespace rocksdb { @@ -76,9 +77,8 @@ TEST_F(CompactFilesTest, ObsoleteFiles) { // create couple files for (int i = 1000; i < 2000; ++i) { - db->Put(WriteOptions(), - std::to_string(i), - std::string(kWriteBufferSize / 10, 'a' + (i % 26))); + db->Put(WriteOptions(), ToString(i), + std::string(kWriteBufferSize / 10, 'a' + (i % 26))); } auto l0_files = collector->GetFlushedFiles(); diff --git a/db/compaction_job_stats_test.cc b/db/compaction_job_stats_test.cc index ff76d5040..e481b4810 100644 --- a/db/compaction_job_stats_test.cc +++ b/db/compaction_job_stats_test.cc @@ -573,7 +573,7 @@ TEST_F(CompactionJobStatsTest, CompactionJobStatsTest) { snprintf(buf, kBufSize, "%d", ++num_L0_files); ASSERT_EQ(std::string(buf), FilesPerLevel(1)); } - ASSERT_EQ(std::to_string(num_L0_files), FilesPerLevel(1)); + ASSERT_EQ(ToString(num_L0_files), FilesPerLevel(1)); // 2nd Phase: perform L0 -> L1 compaction. int L0_compaction_count = 6; diff --git a/db/comparator_db_test.cc b/db/comparator_db_test.cc index 6013f75dc..c9f88d61e 100644 --- a/db/comparator_db_test.cc +++ b/db/comparator_db_test.cc @@ -177,8 +177,13 @@ class DoubleComparator : public Comparator { virtual const char* Name() const override { return "DoubleComparator"; } virtual int Compare(const Slice& a, const Slice& b) const override { +#ifndef CYGWIN double da = std::stod(a.ToString()); double db = std::stod(b.ToString()); +#else + double da = std::strtod(a.ToString().c_str(), 0 /* endptr */); + double db = std::strtod(a.ToString().c_str(), 0 /* endptr */); +#endif if (da == db) { return a.compare(b); } else if (da > db) { diff --git a/db/db_bench.cc b/db/db_bench.cc index b5fa4e277..d9ee310ce 100644 --- a/db/db_bench.cc +++ b/db/db_bench.cc @@ -3665,7 +3665,11 @@ int main(int argc, char** argv) { FLAGS_max_bytes_for_level_multiplier_additional, ','); for (unsigned int j= 0; j < fanout.size(); j++) { FLAGS_max_bytes_for_level_multiplier_additional_v.push_back( - std::stoi(fanout[j])); +#ifndef CYGWIN + std::stoi(fanout[j])); +#else + stoi(fanout[j])); +#endif } FLAGS_compression_type_e = diff --git a/db/db_test.cc b/db/db_test.cc index 3465e51d7..db6cc4cc7 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -13282,7 +13282,7 @@ TEST_F(DBTest, LargeBatchWithColumnFamilies) { pass); for (;;) { std::string data(3000, j++ % 127 + 20); - data += std::to_string(j); + data += ToString(j); batch.Put(handles_[0], Slice(data), Slice(data)); if (batch.GetDataSize() > write_size) { break; diff --git a/db/memtable_list_test.cc b/db/memtable_list_test.cc index 7b27c31fa..598c6b805 100644 --- a/db/memtable_list_test.cc +++ b/db/memtable_list_test.cc @@ -13,6 +13,7 @@ #include "db/writebuffer.h" #include "rocksdb/db.h" #include "rocksdb/status.h" +#include "util/string_util.h" #include "util/testharness.h" namespace rocksdb { @@ -415,11 +416,11 @@ TEST_F(MemTableListTest, FlushPendingTest) { std::string value; MergeContext merge_context; - mem->Add(++seq, kTypeValue, "key1", std::to_string(i)); - mem->Add(++seq, kTypeValue, "keyN" + std::to_string(i), "valueN"); - mem->Add(++seq, kTypeValue, "keyX" + std::to_string(i), "value"); - mem->Add(++seq, kTypeValue, "keyM" + std::to_string(i), "valueM"); - mem->Add(++seq, kTypeDeletion, "keyX" + std::to_string(i), ""); + mem->Add(++seq, kTypeValue, "key1", ToString(i)); + mem->Add(++seq, kTypeValue, "keyN" + ToString(i), "valueN"); + mem->Add(++seq, kTypeValue, "keyX" + ToString(i), "value"); + mem->Add(++seq, kTypeValue, "keyM" + ToString(i), "valueM"); + mem->Add(++seq, kTypeDeletion, "keyX" + ToString(i), ""); tables.push_back(mem); } diff --git a/utilities/backupable/backupable_db_test.cc b/utilities/backupable/backupable_db_test.cc index 1476d9df3..9c24140fb 100644 --- a/utilities/backupable/backupable_db_test.cc +++ b/utilities/backupable/backupable_db_test.cc @@ -18,6 +18,7 @@ #include "util/testharness.h" #include "util/random.h" #include "util/mutexlock.h" +#include "util/string_util.h" #include "util/testutil.h" #include "util/auto_roll_logger.h" @@ -323,8 +324,8 @@ class FileManager : public EnvWrapper { static size_t FillDB(DB* db, int from, int to) { size_t bytes_written = 0; for (int i = from; i < to; ++i) { - std::string key = "testkey" + std::to_string(i); - std::string value = "testvalue" + std::to_string(i); + std::string key = "testkey" + ToString(i); + std::string value = "testvalue" + ToString(i); bytes_written += key.size() + value.size(); EXPECT_OK(db->Put(WriteOptions(), Slice(key), Slice(value))); @@ -334,17 +335,17 @@ static size_t FillDB(DB* db, int from, int to) { static void AssertExists(DB* db, int from, int to) { for (int i = from; i < to; ++i) { - std::string key = "testkey" + std::to_string(i); + std::string key = "testkey" + ToString(i); std::string value; Status s = db->Get(ReadOptions(), Slice(key), &value); - ASSERT_EQ(value, "testvalue" + std::to_string(i)); + ASSERT_EQ(value, "testvalue" + ToString(i)); } } static void AssertEmpty(DB* db, int from, int to) { for (int i = from; i < to; ++i) { - std::string key = "testkey" + std::to_string(i); - std::string value = "testvalue" + std::to_string(i); + std::string key = "testkey" + ToString(i); + std::string value = "testvalue" + ToString(i); Status s = db->Get(ReadOptions(), Slice(key), &value); ASSERT_TRUE(s.IsNotFound()); diff --git a/utilities/ttl/ttl_test.cc b/utilities/ttl/ttl_test.cc index c970047bc..35ca34a05 100644 --- a/utilities/ttl/ttl_test.cc +++ b/utilities/ttl/ttl_test.cc @@ -305,7 +305,13 @@ class TtlTest : public testing::Test { size_t pos = key_string.find_first_of(search_str); int num_key_end; if (pos != std::string::npos) { - num_key_end = stoi(key_string.substr(pos, key.size() - pos)); + auto key_substr = key_string.substr(pos, key.size() - pos); +#ifndef CYGWIN + num_key_end = std::stoi(key_substr); +#else + num_key_end = std::strtol(key_substr.c_str(), 0, 10); +#endif + } else { return false; // Keep keys not matching the format "key" } diff --git a/utilities/write_batch_with_index/write_batch_with_index_test.cc b/utilities/write_batch_with_index/write_batch_with_index_test.cc index eda5382f3..d324eba85 100644 --- a/utilities/write_batch_with_index/write_batch_with_index_test.cc +++ b/utilities/write_batch_with_index/write_batch_with_index_test.cc @@ -12,6 +12,7 @@ #include #include "db/column_family.h" #include "rocksdb/utilities/write_batch_with_index.h" +#include "util/string_util.h" #include "util/testharness.h" #include "utilities/merge_operators.h" #include "utilities/merge_operators/string_append/stringappend.h" @@ -981,11 +982,11 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchMerge) { std::string expected = "X"; for (int i = 0; i < 5; i++) { - batch.Merge("x", std::to_string(i)); - expected = expected + "," + std::to_string(i); + batch.Merge("x", ToString(i)); + expected = expected + "," + ToString(i); if (i % 2 == 0) { - batch.Put("y", std::to_string(i / 2)); + batch.Put("y", ToString(i / 2)); } batch.Merge("z", "z"); @@ -996,7 +997,7 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchMerge) { s = batch.GetFromBatch(column_family, options, "y", &value); ASSERT_OK(s); - ASSERT_EQ(std::to_string(i / 2), value); + ASSERT_EQ(ToString(i / 2), value); s = batch.GetFromBatch(column_family, options, "z", &value); ASSERT_TRUE(s.IsMergeInProgress());