Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Adding option templates to wdt. Right now, there is only flash and disk. Depending on the option type, flags are initialized to different values. Value of a specific option can be changed using flags. For disk, only number of threads is changed and block mode is disabled. Reviewed By: @ldemailly, @nikunjy Differential Revision: D2363348
- Loading branch information
Showing
8 changed files
with
256 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
#include "WdtFlags.h" | ||
#include "WdtOptions.h" | ||
#include <glog/logging.h> | ||
#include <gtest/gtest.h> | ||
|
||
/* | ||
* Tests in this file can not be run in the same process. That is because we | ||
* rely on is_default property of gflags to determine whether a flag has been | ||
* specified by the user. And if a flag is ever changed, is_default becomes | ||
* false and can never be reset to true. So, after running one test, other | ||
* tests would fail. To run tests in this file, use wdt/wdt_option_type_test.sh. | ||
* That script runs each test in separate process and also tests for both long | ||
* and short flags. | ||
*/ | ||
|
||
namespace facebook { | ||
namespace wdt { | ||
|
||
const std::string NUM_PORTS_FLAG = | ||
WdtFlags::getFlagNameFromOptionName("num_ports"); | ||
const std::string BLOCK_SIZE_FLAG = | ||
WdtFlags::getFlagNameFromOptionName("block_size_mbytes"); | ||
const std::string OPTION_TYPE_FLAG = | ||
WdtFlags::getFlagNameFromOptionName("option_type"); | ||
|
||
void overrideTest1(const std::string &optionType) { | ||
const auto &options = WdtOptions::get(); | ||
google::SetCommandLineOption(OPTION_TYPE_FLAG.c_str(), optionType.c_str()); | ||
google::SetCommandLineOption(NUM_PORTS_FLAG.c_str(), "4"); | ||
google::SetCommandLineOption(BLOCK_SIZE_FLAG.c_str(), "8"); | ||
WdtFlags::initializeFromFlags(); | ||
EXPECT_EQ(4, options.num_ports); | ||
EXPECT_EQ(8, options.block_size_mbytes); | ||
} | ||
|
||
void overrideTest2(const std::string &optionType) { | ||
const auto &options = WdtOptions::get(); | ||
google::SetCommandLineOption(OPTION_TYPE_FLAG.c_str(), optionType.c_str()); | ||
google::SetCommandLineOption(NUM_PORTS_FLAG.c_str(), "8"); | ||
google::SetCommandLineOption(BLOCK_SIZE_FLAG.c_str(), "16"); | ||
WdtFlags::initializeFromFlags(); | ||
EXPECT_EQ(8, options.num_ports); | ||
EXPECT_EQ(16, options.block_size_mbytes); | ||
} | ||
|
||
TEST(OptionType, FlashOptionTypeTest1) { | ||
const auto &options = WdtOptions::get(); | ||
google::SetCommandLineOption(OPTION_TYPE_FLAG.c_str(), "flash"); | ||
WdtFlags::initializeFromFlags(); | ||
EXPECT_EQ(8, options.num_ports); | ||
EXPECT_EQ(16, options.block_size_mbytes); | ||
} | ||
|
||
TEST(OptionType, FlashOptionTypeTest2) { | ||
overrideTest1("flash"); | ||
} | ||
|
||
TEST(OptionType, FlashOptionTypeTest3) { | ||
overrideTest2("flash"); | ||
} | ||
|
||
TEST(OptionType, DiskOptionTypeTest1) { | ||
const auto &options = WdtOptions::get(); | ||
google::SetCommandLineOption(OPTION_TYPE_FLAG.c_str(), "disk"); | ||
WdtFlags::initializeFromFlags(); | ||
EXPECT_EQ(1, options.num_ports); | ||
EXPECT_EQ(-1, options.block_size_mbytes); | ||
} | ||
|
||
TEST(OptionType, DiskOptionTypeTest2) { | ||
overrideTest1("disk"); | ||
} | ||
|
||
TEST(OptionType, DiskOptionTypeTest3) { | ||
overrideTest2("disk"); | ||
} | ||
} | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
FLAGS_logtostderr = true; | ||
testing::InitGoogleTest(&argc, argv); | ||
google::ParseCommandLineFlags(&argc, &argv, true); | ||
google::InitGoogleLogging(argv[0]); | ||
int ret = RUN_ALL_TESTS(); | ||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#! /bin/sh | ||
|
||
# Tests for option types can not be run in the same process because gflags | ||
# can not be reset to default condition. This script runs all the tests one by | ||
# one in separate processes | ||
|
||
binaries=(_bin/wdt/option_type_test_long_flags \ | ||
_bin/wdt/short_flags/option_type_test_short_flags) | ||
|
||
for binary in "${binaries[@]}" | ||
do | ||
for test_name in $($binary --gtest_list_tests | \ | ||
tail -n +2 | sed 's/^ *//g') | ||
do | ||
echo "$binary --gtest_filter=*.$test_name" | ||
$binary --gtest_filter="*.$test_name" | ||
LAST_STATUS=$? | ||
if [ $LAST_STATUS -ne 0 ] ; then | ||
exit $LAST_STATUS | ||
fi | ||
done | ||
done | ||
exit 0 |
8cc5254
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixes #49