|
70 | 70 | //
|
71 | 71 |
|
72 | 72 | using System;
|
73 |
| -using System.Collections; |
74 | 73 | using System.Collections.Generic;
|
75 | 74 | using System.Diagnostics;
|
| 75 | +using System.Linq; |
76 | 76 | using System.Xml;
|
77 |
| -using System.Xml.XPath; |
| 77 | +using System.Xml.Linq; |
78 | 78 | using System.IO;
|
79 | 79 |
|
80 | 80 | namespace BenchmarkConsoleApplication
|
@@ -497,115 +497,6 @@ int expectedResults
|
497 | 497 | }
|
498 | 498 | }
|
499 | 499 |
|
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 |
| - |
609 | 500 | // Exit benchmark system with specified exit code.
|
610 | 501 |
|
611 | 502 | public int Exit(int exitCode)
|
@@ -657,6 +548,45 @@ string directoryName
|
657 | 548 | return platformSpecificDirectoryName;
|
658 | 549 | }
|
659 | 550 |
|
| 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 | + |
660 | 590 | // Build list of benchmarks by reading in and processing .XML file.
|
661 | 591 |
|
662 | 592 | public void BuildBenchmarksList()
|
@@ -691,44 +621,42 @@ public void BuildBenchmarksList()
|
691 | 621 |
|
692 | 622 | // Load XML description of benchmarks.
|
693 | 623 |
|
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); |
697 | 625 |
|
698 | 626 | // Get root directory for benchmark system. Command line argument overrides
|
699 | 627 | // specification in benchmark control file.
|
700 | 628 |
|
701 | 629 | benchmarkRootDirectoryName = Controls.BenchmarksRootDirectory;
|
702 | 630 | if (benchmarkRootDirectoryName == "")
|
703 | 631 | {
|
704 |
| - benchmarkRootDirectoryName = GetField(benchmarkXml.DocumentElement, "benchmark-root-directory"); |
| 632 | + benchmarkRootDirectoryName = |
705 | 633 | Controls.BenchmarksRootDirectory = benchmarkRootDirectoryName;
|
706 | 634 | }
|
707 | 635 | benchmarkRootDirectoryName = PlatformSpecificDirectoryName(benchmarkRootDirectoryName);
|
708 | 636 | Controls.BenchmarksRootDirectory = benchmarkRootDirectoryName;
|
709 | 637 |
|
710 | 638 | // Process each benchmark suite in the list of benchmark suites.
|
711 | 639 |
|
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) |
714 | 642 | {
|
715 |
| - benchmarkSuiteName = GetField(benchmarkSuite, "name"); |
| 643 | + benchmarkSuiteName = benchmarkSuite.Element("name").Value; |
716 | 644 |
|
717 | 645 | //Process each benchmark in benchmark suite.
|
718 | 646 |
|
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) |
721 | 649 | {
|
722 |
| - benchmarkName = GetField(benchmark, "name"); |
723 |
| - benchmarkDirectoryName = GetField(benchmark, "directory", OptionalField); |
| 650 | + benchmarkName = benchmark.Element("name").Value; |
| 651 | + benchmarkDirectoryName = benchmark.Element("directory")?.Value ?? ""; |
724 | 652 | 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 ?? ""; |
732 | 660 | AddBenchmark(benchmarkName, benchmarkSuiteName, tags, benchmarkDirectoryName,
|
733 | 661 | benchmarkExecutableName, benchmarkArgs, doRunInShell, useSSE, useAVX, expectedResults);
|
734 | 662 | }
|
|
0 commit comments