command_options_unittest.cc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <cstddef>
  15. #include <stdint.h>
  16. #include <string>
  17. #include <gtest/gtest.h>
  18. #include "../command_options.h"
  19. #include "exceptions/exceptions.h"
  20. using namespace std;
  21. using namespace isc;
  22. using namespace isc::perfdhcp;
  23. /// \brief Test Fixture Class
  24. ///
  25. /// This test fixture class is used to perform
  26. /// unit tests on perfdhcp CommandOptions class.
  27. class CommandOptionsTest : public virtual ::testing::Test
  28. {
  29. public:
  30. /// \brief Default Constructor
  31. CommandOptionsTest() { }
  32. protected:
  33. /// \brief Parse command line and cleanup
  34. ///
  35. /// The method tokenizes command line to array of C-strings,
  36. /// parses arguments using CommandOptions class to set
  37. /// its data members and de-allocates array of C-strings.
  38. ///
  39. /// \param cmdline Command line to parse
  40. /// \throws std::bad allocation if tokenization failed
  41. void process(const std::string& cmdline) {
  42. CommandOptions& opt = CommandOptions::instance();
  43. int argc = 0;
  44. char** argv = tokenizeString(cmdline, &argc);
  45. opt.reset();
  46. opt.parse(argc, argv);
  47. for(int i = 0; i < argc; ++i) {
  48. free(argv[i]);
  49. argv[i] = NULL;
  50. }
  51. free(argv);
  52. }
  53. /// \brief Check default initialized values
  54. ///
  55. /// Check if initialized values are correct
  56. void checkDefaults() {
  57. CommandOptions& opt = CommandOptions::instance();
  58. process("perfdhcp");
  59. EXPECT_EQ(4, opt.getIpVersion());
  60. EXPECT_EQ(CommandOptions::DORA_SARR, opt.getExchangeMode());
  61. EXPECT_EQ(0, opt.getRate());
  62. EXPECT_EQ(0, opt.getReportDelay());
  63. EXPECT_EQ(0, opt.getClientsNum());
  64. // default mac
  65. uint8_t mac[6] = { 0x00, 0x0C, 0x01, 0x02, 0x03, 0x04 };
  66. std::vector<uint8_t> v1 = opt.getMacPrefix();
  67. ASSERT_EQ(6, v1.size());
  68. EXPECT_TRUE(std::equal(v1.begin(), v1.end(), mac));
  69. EXPECT_EQ(0, opt.getBase().size());
  70. EXPECT_EQ(0, opt.getNumRequests().size());
  71. EXPECT_EQ(0, opt.getPeriod());
  72. for (int i = 0; i < opt.getDropTime().size(); ++i) {
  73. EXPECT_DOUBLE_EQ(1, opt.getDropTime()[i]);
  74. }
  75. ASSERT_EQ(opt.getMaxDrop().size(), opt.getMaxDropPercentage().size());
  76. for (int i = 0; i < opt.getMaxDrop().size(); ++i) {
  77. EXPECT_EQ(0, opt.getMaxDrop()[i]);
  78. EXPECT_EQ(0, opt.getMaxDropPercentage()[i]);
  79. }
  80. EXPECT_EQ("", opt.getLocalName());
  81. EXPECT_FALSE(opt.isInterface());
  82. EXPECT_EQ(0, opt.getPreload());
  83. EXPECT_EQ(1, opt.getAggressivity());
  84. EXPECT_EQ(0, opt.getLocalPort());
  85. EXPECT_FALSE(opt.isSeeded());
  86. EXPECT_EQ(0, opt.getSeed());
  87. EXPECT_FALSE(opt.isBroadcast());
  88. EXPECT_FALSE(opt.isRapidCommit());
  89. EXPECT_FALSE(opt.isUseFirst());
  90. EXPECT_EQ(0, opt.getTemplateFiles().size());
  91. EXPECT_EQ(0, opt.getTransactionIdOffset().size());
  92. EXPECT_EQ(0, opt.getRandomOffset().size());
  93. EXPECT_GT(0, opt.getElapsedTimeOffset());
  94. EXPECT_GT(0, opt.getServerIdOffset());
  95. EXPECT_GT(0, opt.getRequestedIpOffset());
  96. EXPECT_EQ("", opt.getDiags());
  97. EXPECT_EQ("", opt.getWrapped());
  98. EXPECT_EQ("", opt.getServerName());
  99. }
  100. /// \brief Split string to array of C-strings
  101. ///
  102. /// \param s String to split (tokenize)
  103. /// \param num Number of tokens returned
  104. /// \return array of C-strings (tokens)
  105. char** tokenizeString(const std::string& text_to_split, int* num) const {
  106. char** results = NULL;
  107. // Tokenization with std streams
  108. std::stringstream text_stream(text_to_split);
  109. // Iterators to be used for tokenization
  110. std::istream_iterator<std::string> text_iterator(text_stream);
  111. std::istream_iterator<std::string> text_end;
  112. // Tokenize string (space is a separator) using begin and end iteratos
  113. std::vector<std::string> tokens(text_iterator, text_end);
  114. if (tokens.size() > 0) {
  115. // Allocate array of C-strings where we will store tokens
  116. results = static_cast<char**>(malloc(tokens.size() * sizeof(char*)));
  117. if (results == NULL) {
  118. throw std::bad_alloc();
  119. }
  120. // Store tokens in C-strings array
  121. for (int i = 0; i < tokens.size(); ++i) {
  122. char* cs = static_cast<char*>(malloc(tokens[i].length() + 1));
  123. strcpy(cs, tokens[i].c_str());
  124. results[i] = cs;
  125. }
  126. // Return number of tokens to calling function
  127. if (num != NULL) {
  128. *num = tokens.size();
  129. }
  130. }
  131. return results;
  132. }
  133. };
  134. TEST_F(CommandOptionsTest, Defaults) {
  135. process("perfdhcp");
  136. checkDefaults();
  137. }
  138. TEST_F(CommandOptionsTest, UseFirst) {
  139. CommandOptions& opt = CommandOptions::instance();
  140. process("perfdhcp -1 -B -l ethx");
  141. EXPECT_TRUE(opt.isUseFirst());
  142. }
  143. TEST_F(CommandOptionsTest, IpVersion) {
  144. CommandOptions& opt = CommandOptions::instance();
  145. process("perfdhcp -6 -l ethx -c -i");
  146. EXPECT_EQ(6, opt.getIpVersion());
  147. EXPECT_EQ("ethx", opt.getLocalName());
  148. EXPECT_TRUE(opt.isRapidCommit());
  149. EXPECT_FALSE(opt.isBroadcast());
  150. process("perfdhcp -4 -B -l ethx");
  151. EXPECT_EQ(4, opt.getIpVersion());
  152. EXPECT_TRUE(opt.isBroadcast());
  153. EXPECT_FALSE(opt.isRapidCommit());
  154. // Negative test cases
  155. // -4 and -6 must not coexist
  156. EXPECT_THROW(process("perfdhcp -4 -6 -l ethx"), isc::InvalidParameter);
  157. // -6 and -B must not coexist
  158. EXPECT_THROW(process("perfdhcp -6 -B -l ethx"), isc::InvalidParameter);
  159. // -c and -4 (default) must not coexist
  160. EXPECT_THROW(process("perfdhcp -c -l ethx"), isc::InvalidParameter);
  161. }
  162. TEST_F(CommandOptionsTest, Rate) {
  163. CommandOptions& opt = CommandOptions::instance();
  164. process("perfdhcp -4 -r 10 -l ethx");
  165. EXPECT_EQ(10, opt.getRate());
  166. // Negative test cases
  167. // Rate must not be 0
  168. EXPECT_THROW(process("perfdhcp -4 -r 0 -l ethx"), isc::InvalidParameter);
  169. // -r must be specified to use -n, -p and -D
  170. EXPECT_THROW(process("perfdhcp -6 -t 5 -l ethx"), isc::InvalidParameter);
  171. EXPECT_THROW(process("perfdhcp -4 -n 150 -l ethx"), isc::InvalidParameter);
  172. EXPECT_THROW(process("perfdhcp -6 -p 120 -l ethx"), isc::InvalidParameter);
  173. EXPECT_THROW(process("perfdhcp -4 -D 1400 -l ethx"), isc::InvalidParameter);
  174. }
  175. TEST_F(CommandOptionsTest, ReportDelay) {
  176. CommandOptions& opt = CommandOptions::instance();
  177. process("perfdhcp -r 100 -t 17 -l ethx");
  178. EXPECT_EQ(17, opt.getReportDelay());
  179. // Negative test cases
  180. // -t must be positive integer
  181. EXPECT_THROW(process("perfdhcp -r 10 -t -8 -l ethx"), isc::InvalidParameter);
  182. EXPECT_THROW(process("perfdhcp -r 10 -t 0 -l ethx"), isc::InvalidParameter);
  183. EXPECT_THROW(process("perfdhcp -r 10 -t s -l ethx"), isc::InvalidParameter);
  184. }
  185. TEST_F(CommandOptionsTest, ClientsNum) {
  186. CommandOptions& opt = CommandOptions::instance();
  187. process("perfdhcp -R 200 -l ethx");
  188. EXPECT_EQ(200, opt.getClientsNum());
  189. process("perfdhcp -R 0 -l ethx");
  190. EXPECT_EQ(0, opt.getClientsNum());
  191. // Negative test cases
  192. // Number of clients must be non-negative integer
  193. EXPECT_THROW(process("perfdhcp -R -5 -l ethx"), isc::InvalidParameter);
  194. EXPECT_THROW(process("perfdhcp -R gs -l ethx"), isc::InvalidParameter);
  195. }
  196. TEST_F(CommandOptionsTest, Base) {
  197. CommandOptions& opt = CommandOptions::instance();
  198. process("perfdhcp -6 -b MAC=10::20::30::40::50::60 -l ethx -b duiD=1AB7F5670901FF");
  199. uint8_t mac[6] = {0x10, 0x20, 0x30, 0x40, 0x50, 0x60 };
  200. uint8_t duid[7] = { 0x1A, 0xB7, 0xF5, 0x67, 0x09, 0x01, 0xFF };
  201. // Test Mac
  202. std::vector<uint8_t> v1 = opt.getMacPrefix();
  203. ASSERT_EQ(6, v1.size());
  204. EXPECT_TRUE(std::equal(v1.begin(), v1.end(), mac));
  205. // "3x" is invalid value in MAC address
  206. EXPECT_THROW(process("perfdhcp -b mac=10::2::3x::4::5::6 -l ethx"), isc::InvalidParameter);
  207. // Test DUID
  208. std::vector<uint8_t> v2 = opt.getDuidPrefix();
  209. ASSERT_EQ(sizeof(duid) / sizeof(uint8_t), v2.size());
  210. EXPECT_TRUE(std::equal(v2.begin(), v2.end(), duid));
  211. // "t" is invalid digit in DUID
  212. EXPECT_THROW(process("perfdhcp -6 -l ethx -b duiD=1AB7Ft670901FF"), isc::InvalidParameter);
  213. // Some more negative test cases
  214. // Base is not specified
  215. EXPECT_THROW(process("perfdhcp -b -l ethx"), isc::InvalidParameter);
  216. // Typo: should be mac= instead of mc=
  217. EXPECT_THROW(process("perfdhcp -l ethx -b mc=00:01:02:03::04:05"), isc::InvalidParameter);
  218. }
  219. TEST_F(CommandOptionsTest, DropTime) {
  220. CommandOptions& opt = CommandOptions::instance();
  221. process("perfdhcp -l ethx -d 12");
  222. ASSERT_EQ(2, opt.getDropTime().size());
  223. EXPECT_DOUBLE_EQ(12, opt.getDropTime()[0]);
  224. EXPECT_DOUBLE_EQ(1, opt.getDropTime()[1]);
  225. process("perfdhcp -l ethx -d 2 -d 4.7");
  226. ASSERT_EQ(2, opt.getDropTime().size());
  227. EXPECT_DOUBLE_EQ(2, opt.getDropTime()[0]);
  228. EXPECT_DOUBLE_EQ(4.7, opt.getDropTime()[1]);
  229. // Negative test cases
  230. // Drop time must not be negative
  231. EXPECT_THROW(process("perfdhcp -l ethx -d -2 -d 4.7"), isc::InvalidParameter);
  232. EXPECT_THROW(process("perfdhcp -l ethx -d -9.1 -d 0"), isc::InvalidParameter);
  233. }
  234. TEST_F(CommandOptionsTest, TimeOffset) {
  235. CommandOptions& opt = CommandOptions::instance();
  236. process("perfdhcp -l ethx -T file1.x -T file2.x -E 4");
  237. EXPECT_EQ(4, opt.getElapsedTimeOffset());
  238. // Negative test cases
  239. // Argument -E must be used with -T
  240. EXPECT_THROW(process("perfdhcp -l ethx -E 3 -i"), isc::InvalidParameter);
  241. // Value in -E not specified
  242. EXPECT_THROW(process("perfdhcp -l ethx -T file.x -E -i"), isc::InvalidParameter);
  243. // Value for -E must not be negative
  244. EXPECT_THROW(process("perfdhcp -l ethx -E -3 -T file.x"), isc::InvalidParameter);
  245. }
  246. TEST_F(CommandOptionsTest, ExchangeMode) {
  247. CommandOptions& opt = CommandOptions::instance();
  248. process("perfdhcp -l ethx -i");
  249. EXPECT_EQ(CommandOptions::DO_SA, opt.getExchangeMode());
  250. // Negative test cases
  251. // No template file specified
  252. EXPECT_THROW(process("perfdhcp -i -l ethx -X 3"), isc::InvalidParameter);
  253. // Offsets can't be used in simple exchanges (-i)
  254. EXPECT_THROW(process("perfdhcp -i -l ethx -O 2 -T file.x"), isc::InvalidParameter);
  255. EXPECT_THROW(process("perfdhcp -i -l ethx -E 3 -T file.x"), isc::InvalidParameter);
  256. EXPECT_THROW(process("perfdhcp -i -l ethx -S 1 -T file.x"), isc::InvalidParameter);
  257. EXPECT_THROW(process("perfdhcp -i -l ethx -I 2 -T file.x"), isc::InvalidParameter);
  258. }
  259. TEST_F(CommandOptionsTest, Offsets) {
  260. CommandOptions& opt = CommandOptions::instance();
  261. process("perfdhcp -E5 -4 -I 2 -S3 -O 30 -X7 -l ethx -X3 -T file1.x -T file2.x");
  262. EXPECT_EQ(2, opt.getRequestedIpOffset());
  263. EXPECT_EQ(5, opt.getElapsedTimeOffset());
  264. EXPECT_EQ(3, opt.getServerIdOffset());
  265. ASSERT_EQ(2, opt.getRandomOffset().size());
  266. EXPECT_EQ(30, opt.getRandomOffset()[0]);
  267. EXPECT_EQ(30, opt.getRandomOffset()[1]);
  268. ASSERT_EQ(2, opt.getTransactionIdOffset().size());
  269. EXPECT_EQ(7, opt.getTransactionIdOffset()[0]);
  270. EXPECT_EQ(3, opt.getTransactionIdOffset()[1]);
  271. // Negative test cases
  272. // IP offset/IA_NA offset must be positive
  273. EXPECT_THROW(process("perfdhcp -6 -I 0 -l ethx"), isc::InvalidParameter);
  274. EXPECT_THROW(process("perfdhcp -6 -I -4 -l ethx"), isc::InvalidParameter);
  275. // TODO - other negative cases
  276. }
  277. TEST_F(CommandOptionsTest, LocalPort) {
  278. CommandOptions& opt = CommandOptions::instance();
  279. process("perfdhcp -l ethx -L 2000");
  280. EXPECT_EQ(2000, opt.getLocalPort());
  281. // Negative test cases
  282. // Local port must be between 0..65535
  283. EXPECT_THROW(process("perfdhcp -l ethx -L -2"), isc::InvalidParameter);
  284. EXPECT_THROW(process("perfdhcp -l ethx -L"), isc::InvalidParameter);
  285. EXPECT_THROW(process("perfdhcp -l ethx -L 65540"), isc::InvalidParameter);
  286. }
  287. TEST_F(CommandOptionsTest, Preload) {
  288. CommandOptions& opt = CommandOptions::instance();
  289. process("perfdhcp -1 -P 3 -l ethx");
  290. EXPECT_EQ(3, opt.getPreload());
  291. // Negative test cases
  292. // Number of preload packages must not be negative integer
  293. EXPECT_THROW(process("perfdhcp -P -1 -l ethx"), isc::InvalidParameter);
  294. EXPECT_THROW(process("perfdhcp -P -3 -l ethx"), isc::InvalidParameter);
  295. }
  296. TEST_F(CommandOptionsTest, Seed) {
  297. CommandOptions& opt = CommandOptions::instance();
  298. process("perfdhcp -6 -P 2 -s 23 -l ethx");
  299. EXPECT_EQ(23, opt.getSeed());
  300. EXPECT_TRUE(opt.isSeeded());
  301. process("perfdhcp -6 -P 2 -s 0 -l ethx");
  302. EXPECT_EQ(0, opt.getSeed());
  303. EXPECT_FALSE(opt.isSeeded());
  304. // Negtaive test cases
  305. // Seed must be non-negative integer
  306. EXPECT_THROW(process("perfdhcp -6 -P 2 -s -5 -l ethx"), isc::InvalidParameter);
  307. EXPECT_THROW(process("perfdhcp -6 -P 2 -s -l ethx"), isc::InvalidParameter);
  308. }
  309. TEST_F(CommandOptionsTest, TemplateFiles) {
  310. CommandOptions& opt = CommandOptions::instance();
  311. process("perfdhcp -T file1.x -l ethx");
  312. ASSERT_EQ(1, opt.getTemplateFiles().size());
  313. EXPECT_EQ("file1.x", opt.getTemplateFiles()[0]);
  314. process("perfdhcp -T file1.x -s 12 -w start -T file2.x -4 -l ethx");
  315. ASSERT_EQ(2, opt.getTemplateFiles().size());
  316. EXPECT_EQ("file1.x", opt.getTemplateFiles()[0]);
  317. EXPECT_EQ("file2.x", opt.getTemplateFiles()[1]);
  318. // Negative test cases
  319. // No template file specified
  320. EXPECT_THROW(process("perfdhcp -s 12 -l ethx -T"), isc::InvalidParameter);
  321. // Too many template files specified
  322. EXPECT_THROW(process("perfdhcp -s 12 -l ethx -T file.x -T file.x -T file.x"), isc::InvalidParameter);
  323. }
  324. TEST_F(CommandOptionsTest, Wrapped) {
  325. CommandOptions& opt = CommandOptions::instance();
  326. process("perfdhcp -B -w start -i -l ethx");
  327. EXPECT_EQ("start", opt.getWrapped());
  328. // Negative test cases
  329. // Missing command after -w, expected start/stop
  330. EXPECT_THROW(process("perfdhcp -B -i -l ethx -w"), isc::InvalidParameter);
  331. }
  332. TEST_F(CommandOptionsTest, Diagnostics) {
  333. CommandOptions& opt = CommandOptions::instance();
  334. process("perfdhcp -l ethx -i -x asTe");
  335. EXPECT_EQ("asTe", opt.getDiags());
  336. // Negative test cases
  337. // No diagnostics string specified
  338. EXPECT_THROW(process("perfdhcp -l ethx -i -x"), isc::InvalidParameter);
  339. }
  340. TEST_F(CommandOptionsTest, Aggressivity) {
  341. CommandOptions& opt = CommandOptions::instance();
  342. process("perfdhcp -a 10 -l 192.168.0.1");
  343. EXPECT_EQ(10, opt.getAggressivity());
  344. // Negative test cases
  345. // Aggressivity must be non negative integer
  346. EXPECT_THROW(process("perfdhcp -l ethx -a 0"), isc::InvalidParameter);
  347. EXPECT_THROW(process("perfdhcp -l ethx -a"), isc::InvalidParameter);
  348. EXPECT_THROW(process("perfdhcp -a -2 -l ethx -a 3"), isc::InvalidParameter);
  349. }
  350. TEST_F(CommandOptionsTest, MaxDrop) {
  351. CommandOptions& opt = CommandOptions::instance();
  352. process("perfdhcp -D 25 -l ethx -r 10");
  353. EXPECT_EQ(25, opt.getMaxDrop()[0]);
  354. process("perfdhcp -D 25 -l ethx -D 15 -r 10");
  355. EXPECT_EQ(25, opt.getMaxDrop()[0]);
  356. EXPECT_EQ(15, opt.getMaxDrop()[1]);
  357. process("perfdhcp -D 15% -l ethx -r 10");
  358. EXPECT_EQ(15, opt.getMaxDropPercentage()[0]);
  359. process("perfdhcp -D 15% -D25% -l ethx -r 10");
  360. EXPECT_EQ(15, opt.getMaxDropPercentage()[0]);
  361. EXPECT_EQ(25, opt.getMaxDropPercentage()[1]);
  362. process("perfdhcp -D 1% -D 99% -l ethx -r 10");
  363. EXPECT_EQ(1, opt.getMaxDropPercentage()[0]);
  364. EXPECT_EQ(99, opt.getMaxDropPercentage()[1]);
  365. // Negative test cases
  366. // Too many -D<value> options
  367. EXPECT_THROW(process("perfdhcp -D 0% -D 1 -l ethx -r20 -D 3"), isc::InvalidParameter);
  368. // Too many -D<value%> options
  369. EXPECT_THROW(process("perfdhcp -D 99% -D 13% -l ethx -r20 -D 10%"), isc::InvalidParameter);
  370. // Percentage is out of bounds
  371. EXPECT_THROW(process("perfdhcp -D101% -D 13% -l ethx -r20"), isc::InvalidParameter);
  372. EXPECT_THROW(process("perfdhcp -D0% -D 13% -l ethx -r20"), isc::InvalidParameter);
  373. }
  374. TEST_F(CommandOptionsTest, NumRequest) {
  375. CommandOptions& opt = CommandOptions::instance();
  376. process("perfdhcp -n 1000 -r 10 -l ethx");
  377. EXPECT_EQ(1000, opt.getNumRequests()[0]);
  378. process("perfdhcp -n 5 -r 10 -n 500 -l ethx");
  379. EXPECT_EQ(5, opt.getNumRequests()[0]);
  380. EXPECT_EQ(500, opt.getNumRequests()[1]);
  381. // Negative test cases
  382. // Too many -n<value> parameters, expected maximum 2
  383. EXPECT_THROW(process("perfdhcp -n 1 -n 2 -l ethx -n3 -r 20"), isc::InvalidParameter);
  384. // Num request must be positive integer
  385. EXPECT_THROW(process("perfdhcp -n 1 -n -22 -l ethx -r 10"), isc::InvalidParameter);
  386. EXPECT_THROW(process("perfdhcp -n 0 -l ethx -r 10"), isc::InvalidParameter);
  387. }
  388. TEST_F(CommandOptionsTest, Period) {
  389. CommandOptions& opt = CommandOptions::instance();
  390. process("perfdhcp -p 120 -l ethx -r 100");
  391. EXPECT_EQ(120, opt.getPeriod());
  392. // Negative test cases
  393. // Test period must be positive integer
  394. EXPECT_THROW(process("perfdhcp -p 0 -l ethx -r 50"), isc::InvalidParameter);
  395. EXPECT_THROW(process("perfdhcp -p -3 -l ethx -r 50"), isc::InvalidParameter);
  396. }