Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 45aa1a1

Browse files
committed
Update jit RunBenchmarks test to no longer use XPath
Rewrite to use linq-to-xml instead. Verified at least that this can still parse the adjoining xml file. Also now able to crossgen this test case. Closes #11082.
1 parent ec9976a commit 45aa1a1

File tree

2 files changed

+57
-131
lines changed

2 files changed

+57
-131
lines changed

tests/src/JIT/Performance/RunBenchmarks/RunBenchmarks.cs

Lines changed: 57 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@
7070
//
7171

7272
using System;
73-
using System.Collections;
7473
using System.Collections.Generic;
7574
using System.Diagnostics;
75+
using System.Linq;
7676
using System.Xml;
77-
using System.Xml.XPath;
77+
using System.Xml.Linq;
7878
using System.IO;
7979

8080
namespace BenchmarkConsoleApplication
@@ -497,115 +497,6 @@ int expectedResults
497497
}
498498
}
499499

500-
// XML processing, select a single node given root node and xpath field name.
501-
502-
public XmlNode SelectSingleNode
503-
(
504-
XmlNode node,
505-
string xpath
506-
)
507-
{
508-
#if DESKTOP
509-
return node.SelectSingleNode(xpath);
510-
#else
511-
return XmlDocumentXPathExtensions.SelectSingleNode(node, xpath);
512-
#endif
513-
}
514-
515-
// XML processing, get a string field value given a node and xpath field name.
516-
// Can be optional field.
517-
518-
public string GetField
519-
(
520-
XmlNode node,
521-
string xpath,
522-
bool optional = false
523-
)
524-
{
525-
XmlNode fieldNode = SelectSingleNode(node, xpath);
526-
if (fieldNode == null)
527-
{
528-
if (optional)
529-
{
530-
return "";
531-
}
532-
throw new Exception("missing field: " + xpath);
533-
}
534-
535-
return fieldNode.InnerText;
536-
}
537-
538-
// XML processing, get a boolean field value given a node and xpath field name.
539-
// Can be optional field.
540-
541-
public bool GetBooleanField
542-
(
543-
XmlNode node,
544-
string xpath,
545-
bool optional = false
546-
)
547-
{
548-
string value = GetField(node, xpath, optional);
549-
550-
if (value == "true")
551-
return true;
552-
if (value == "false")
553-
return false;
554-
if (optional)
555-
return false;
556-
557-
throw new Exception("bad boolean value: " + value);
558-
}
559-
560-
// XML processing, get an integer field value given a node and xpath field name.
561-
// Can be optional field.
562-
563-
public int GetIntegerField
564-
(
565-
XmlNode node,
566-
string xpath,
567-
bool optional = false
568-
)
569-
{
570-
string value = GetField(node, xpath, optional);
571-
572-
if (value != "")
573-
{
574-
int number = Int32.Parse(value);
575-
return number;
576-
}
577-
if (optional)
578-
return 0;
579-
580-
throw new Exception("bad integer value: " + value);
581-
}
582-
583-
// XML processing, select a list of nodes given root node and xpath field name.
584-
585-
public XmlNodeList SelectNodes
586-
(
587-
XmlNode node,
588-
string xpath
589-
)
590-
{
591-
#if DESKTOP
592-
return node.SelectNodes(xpath);
593-
#else
594-
return XmlDocumentXPathExtensions.SelectNodes(node, xpath);
595-
#endif
596-
}
597-
598-
// XML processing, get a list of nodes given root node and xpath field name.
599-
600-
public XmlNodeList GetList
601-
(
602-
XmlNode node,
603-
string xpath
604-
)
605-
{
606-
return SelectNodes(node, xpath);
607-
}
608-
609500
// Exit benchmark system with specified exit code.
610501

611502
public int Exit(int exitCode)
@@ -657,6 +548,45 @@ string directoryName
657548
return platformSpecificDirectoryName;
658549
}
659550

551+
public static bool GetBool
552+
(
553+
XElement node,
554+
string name,
555+
bool optional = true
556+
)
557+
{
558+
string value = node.Element(name)?.Value;
559+
560+
if (value == "true")
561+
return true;
562+
if (value == "false")
563+
return false;
564+
if (optional)
565+
return false;
566+
567+
throw new Exception("bad boolean value: " + value);
568+
}
569+
570+
public static int GetInteger
571+
(
572+
XElement node,
573+
string name,
574+
bool optional = true
575+
)
576+
{
577+
string value = node.Element(name)?.Value;
578+
579+
if (value != "")
580+
{
581+
int number = Int32.Parse(value);
582+
return number;
583+
}
584+
if (optional)
585+
return 0;
586+
587+
throw new Exception("bad integer value: " + value);
588+
}
589+
660590
// Build list of benchmarks by reading in and processing .XML file.
661591

662592
public void BuildBenchmarksList()
@@ -691,44 +621,42 @@ public void BuildBenchmarksList()
691621

692622
// Load XML description of benchmarks.
693623

694-
XmlDocument benchmarkXml = new XmlDocument();
695-
var xmlFile = new FileStream(benchmarkXmlFullFileName, FileMode.Open, FileAccess.Read);
696-
benchmarkXml.Load(xmlFile);
624+
XElement benchmarkXml = XElement.Load(benchmarkXmlFullFileName);
697625

698626
// Get root directory for benchmark system. Command line argument overrides
699627
// specification in benchmark control file.
700628

701629
benchmarkRootDirectoryName = Controls.BenchmarksRootDirectory;
702630
if (benchmarkRootDirectoryName == "")
703631
{
704-
benchmarkRootDirectoryName = GetField(benchmarkXml.DocumentElement, "benchmark-root-directory");
632+
benchmarkRootDirectoryName =
705633
Controls.BenchmarksRootDirectory = benchmarkRootDirectoryName;
706634
}
707635
benchmarkRootDirectoryName = PlatformSpecificDirectoryName(benchmarkRootDirectoryName);
708636
Controls.BenchmarksRootDirectory = benchmarkRootDirectoryName;
709637

710638
// Process each benchmark suite in the list of benchmark suites.
711639

712-
XmlNodeList benchmarkSuiteList = GetList(benchmarkXml.DocumentElement, "benchmark-suite");
713-
foreach (XmlNode benchmarkSuite in benchmarkSuiteList)
640+
var benchmarkSuiteList = from e in benchmarkXml.Descendants("benchmark-suite") select e;
641+
foreach (XElement benchmarkSuite in benchmarkSuiteList)
714642
{
715-
benchmarkSuiteName = GetField(benchmarkSuite, "name");
643+
benchmarkSuiteName = benchmarkSuite.Element("name").Value;
716644

717645
//Process each benchmark in benchmark suite.
718646

719-
XmlNodeList benchmarkList = GetList(benchmarkSuite, "benchmark");
720-
foreach (XmlNode benchmark in benchmarkList)
647+
var benchmarkList = from e in benchmarkSuite.Descendants("benchmark") select e;
648+
foreach (XElement benchmark in benchmarkList)
721649
{
722-
benchmarkName = GetField(benchmark, "name");
723-
benchmarkDirectoryName = GetField(benchmark, "directory", OptionalField);
650+
benchmarkName = benchmark.Element("name").Value;
651+
benchmarkDirectoryName = benchmark.Element("directory")?.Value ?? "";
724652
benchmarkDirectoryName = PlatformSpecificDirectoryName(benchmarkDirectoryName);
725-
benchmarkExecutableName = GetField(benchmark, "executable");
726-
benchmarkArgs = GetField(benchmark, "args", OptionalField);
727-
useSSE = GetBooleanField(benchmark, "useSSE", OptionalField);
728-
useAVX = GetBooleanField(benchmark, "useAVX", OptionalField);
729-
expectedResults = GetIntegerField(benchmark, "expected-results", OptionalField);
730-
doRunInShell = GetBooleanField(benchmark, "run-in-shell", OptionalField);
731-
tags = GetField(benchmark, "tags", OptionalField);
653+
benchmarkExecutableName = benchmark.Element("executable").Value;
654+
benchmarkArgs = benchmark.Element("args")?.Value ?? "";
655+
useSSE = GetBool(benchmark, "useSSE");
656+
useAVX = GetBool(benchmark, "useAVX");
657+
doRunInShell = GetBool(benchmark, "run-in-shell");
658+
expectedResults = GetInteger(benchmark, "expected-results");
659+
tags = benchmark.Element("tags")?.Value ?? "";
732660
AddBenchmark(benchmarkName, benchmarkSuiteName, tags, benchmarkDirectoryName,
733661
benchmarkExecutableName, benchmarkArgs, doRunInShell, useSSE, useAVX, expectedResults);
734662
}

tests/src/JIT/config/benchmark/project.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
"System.Threading.ThreadPool": "4.4.0-beta-24913-02",
2929
"System.Diagnostics.Process": "4.4.0-beta-24913-02",
3030
"System.Xml.XmlDocument": "4.4.0-beta-24913-02",
31-
"System.Xml.XPath": "4.4.0-beta-24913-02",
32-
"System.Xml.XPath.XmlDocument": "4.4.0-beta-24913-02",
3331
"xunit": "2.2.0-beta2-build3300",
3432
"xunit.console.netcore": "1.0.2-prerelease-00177",
3533
"xunit.runner.utility": "2.2.0-beta2-build3300"

0 commit comments

Comments
 (0)