The catalog java code also implements a equivalent method for processing the debug actions in the Java code. See DebugUtils.java for more details. Any changes to the implementation logic here like adding a new type of action, should make changes in the DebugUtils.java too.
| 418 | /// implementation logic here like adding a new type of action, should make changes in |
| 419 | /// the DebugUtils.java too. |
| 420 | Status DebugActionImpl(const string& debug_action, const char* label, |
| 421 | const std::vector<string>& args, bool verify_only) { |
| 422 | const DebugActionTokens& action_list = TokenizeDebugActions(debug_action); |
| 423 | static const char ERROR_MSG[] = "Invalid debug_action $0:$1 ($2)"; |
| 424 | for (const vector<string>& components : action_list) { |
| 425 | string action_str; |
| 426 | if (!verify_only) { |
| 427 | // 'components' should be of the form {label, arg_0, ..., arg_n, action} |
| 428 | if (components.size() != 2 + args.size() || !iequals(components[0], label)) { |
| 429 | continue; |
| 430 | } |
| 431 | // Check if the arguments match. |
| 432 | bool matches = true; |
| 433 | for (int i = 0; i < args.size(); ++i) { |
| 434 | if (!iequals(components[i + 1], args[i])) { |
| 435 | matches = false; |
| 436 | break; |
| 437 | } |
| 438 | } |
| 439 | if (!matches) continue; |
| 440 | action_str = components[args.size() + 1]; |
| 441 | } |
| 442 | else { |
| 443 | if (components.size() < 2) { |
| 444 | continue; |
| 445 | } |
| 446 | action_str = components.back(); |
| 447 | } |
| 448 | |
| 449 | // 'tokens' becomes {command, param0, param1, ... } |
| 450 | vector<string> tokens = TokenizeDebugActionParams(action_str); |
| 451 | DCHECK_GE(tokens.size(), 1); |
| 452 | const string& cmd = tokens[0]; |
| 453 | int sleep_millis = 0; |
| 454 | if (iequals(cmd, "SLEEP")) { |
| 455 | // SLEEP@<millis> |
| 456 | if (tokens.size() != 2) { |
| 457 | return Status( |
| 458 | Substitute(ERROR_MSG, components[0], action_str, "expected SLEEP@<ms>")); |
| 459 | } |
| 460 | sleep_millis = atoi(tokens[1].c_str()); |
| 461 | } else if (iequals(cmd, "JITTER")) { |
| 462 | // JITTER@<millis>[@<probability>} |
| 463 | if (tokens.size() < 2 || tokens.size() > 3) { |
| 464 | return Status(Substitute(ERROR_MSG, components[0], action_str, |
| 465 | "expected JITTER@<ms>[@<probability>]")); |
| 466 | } |
| 467 | int max_millis = atoi(tokens[1].c_str()); |
| 468 | if (tokens.size() == 3) { |
| 469 | bool should_execute = true; |
| 470 | if (!ParseProbability(tokens[2], &should_execute)) { |
| 471 | return Status( |
| 472 | Substitute(ERROR_MSG, components[0], action_str, "invalid probability")); |
| 473 | } |
| 474 | if (!should_execute) continue; |
| 475 | } |
| 476 | sleep_millis = rand() % (max_millis + 1); |
| 477 | } else if (iequals(cmd, "FAIL")) { |
no test coverage detected