Merge pull request #22397 from keithc-ca/ddrext · eclipse-openj9/openj9@bea4009

@@ -64,10 +64,10 @@ protected String exec(String ddrExtCmd, String[] arg) {

6464

if (SetupConfig.getDDRContxt() != null) {

6565

// this means we are running from ddr plugin

6666

DDROutputStream mps = SetupConfig.getPrintStream();

67-

log.debug("Execute command: !" + ddrExtCmd + argStr);

6867

if (ddrExtCmd.startsWith("!") == false) {

6968

ddrExtCmd = "!" + ddrExtCmd;

7069

}

70+

log.debug("Execute command: " + ddrExtCmd + argStr);

7171

currentCommand = "'" + ddrExtCmd + argStr + "'";

7272

SetupConfig.getDDRContxt().execute(ddrExtCmd, arg,

7373

SetupConfig.getPrintStream());

@@ -89,10 +89,10 @@ protected String exec(String ddrExtCmd, String[] arg) {

8989

}

9090

if (app != null) {

9191

DDROutputStream mps = SetupConfig.getPrintStream();

92-

log.debug("Execute command: !" + ddrExtCmd + argStr);

9392

if (ddrExtCmd.startsWith("!") == false) {

9493

ddrExtCmd = "!" + ddrExtCmd;

9594

}

95+

log.debug("Execute command: " + ddrExtCmd + argStr);

9696

currentCommand = "'" + ddrExtCmd + argStr + "'";

9797

app.execute(ddrExtCmd, arg);

9898

output = mps.getOutBuffer().toString();

@@ -225,20 +225,20 @@ protected boolean validate(String output, String successKeys,

225225

}

226226

}

227227228-

/* Performing exhaustive validation using all available structures (subcommands) in the output */

228+

/* Performing exhaustive validation using all available structures (subcommands) in the output. */

229229

if (goNextStep) {

230-

int firstIndex = output.indexOf("!");

230+

int firstIndex = output.indexOf('!');

231231

String parentCmd = currentCommand;

232232

boolean allNextCmdAlreadyCovered = true;

233233

if (firstIndex != -1) { // if this output contains any !subcommand

234234

ArrayList<String> structuresToRun = new ArrayList<>();

235-

output = output.substring(output.indexOf("!") + 1); // chop off

235+

output = output.substring(firstIndex + 1); // chop off

236236

Scanner scanner = new Scanner(output).useDelimiter("!");

237237

String structToRun = null;

238238

String structAddress = null;

239239

while (scanner.hasNext()) {

240240

String nextToken = scanner.next();

241-

String tokens[] = nextToken.split(" ");

241+

String[] tokens = nextToken.split(" ");

242242

if (tokens.length > 1) {

243243

structToRun = tokens[0].trim();

244244

if (coveredStructures.contains(structToRun) == false) {

@@ -260,7 +260,7 @@ protected boolean validate(String output, String successKeys,

260260

+ parentCmd);

261261

for (int i = 0; i < structuresToRun.size(); i++) {

262262

currentCommand = structuresToRun.get(i);

263-

log.info("Runing structure test with : !"

263+

log.info("Running structure test with : !"

264264

+ currentCommand);

265265

String[] tokens = currentCommand.trim().split(" ");

266266

String cmd = tokens[0];

@@ -274,9 +274,10 @@ protected boolean validate(String output, String successKeys,

274274

continue;

275275

}

276276277-

if (nxtOutput.contains("{")

278-

&& nxtOutput.contains("}")

279-

&& nxtOutput.indexOf("{") < nxtOutput.indexOf("}")) {

277+

int opener = nxtOutput.indexOf('{');

278+

int closer = nxtOutput.indexOf('}');

279+280+

if ((0 <= opener) && (opener < closer)) {

280281

String structPropertyPattern = ".*=.* 0x.*|<FAULT>";

281282

Pattern pattern = Pattern.compile(structPropertyPattern);

282283

Matcher matcher = pattern.matcher(nxtOutput);

@@ -291,7 +292,7 @@ && runCommonFailureTestForSubCmd(nxtOutput)) {

291292

} else {

292293

log.info("Can not validate: " + currentCommand

293294

+ " output is not a structure");

294-

log.debug(nxtOutput);

295+

log.error(nxtOutput);

295296

}

296297

}

297298

currentCommand = parentCmd;

@@ -309,26 +310,32 @@ && runCommonFailureTestForSubCmd(nxtOutput)) {

309310

* @return

310311

*/

311312

private static String cleanse(String address) {

312-

if (address.contains(Constants.NL)) {

313-

address = address.substring(0, address.indexOf(Constants.NL));

314-

}

315-316-

/* We make sure we are in fact dealing with a hex value string */

313+

/* Make sure we are in fact dealing with a hex value string. */

317314

if (address.startsWith("0x") == false) {

318315

return null;

319316

}

320317321-

if (address.contains(",")) {

322-

address = address.split(",")[0];

318+

int index;

319+320+

index = address.indexOf(Constants.NL);

321+

if (index >= 0) {

322+

address = address.substring(0, index);

323+

}

324+325+

index = address.indexOf(',');

326+

if (index >= 0) {

327+

address = address.substring(0, index);

323328

}

324329325-

if (address.contains("\t")) {

326-

address = address.split("\t")[0];

330+

index = address.indexOf('\t');

331+

if (index >= 0) {

332+

address = address.substring(0, index);

327333

}

328334329-

if (address.endsWith(")") || address.endsWith(">")) {

335+

if (address.endsWith(")") || address.endsWith(">") || address.endsWith(":")) {

330336

address = address.substring(0, address.length() - 1);

331337

}

338+332339

return address;

333340

}

334341