Jlm
Loading...
Searching...
No Matches
JlmOptCommandTests.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 Nico Reißmann <nico.reissmann@gmail.com>
3 * See COPYING for terms of redistribution.
4 */
5
6#include <gtest/gtest.h>
7
11#include <jlm/util/strfmt.hpp>
12
13#include <fstream>
14
15TEST(JlmOptCommandTests, TestStatistics)
16{
17 using namespace jlm::llvm;
18 using namespace jlm::tooling;
19 using namespace jlm::util;
20
21 // Arrange
22 FilePath expectedStatisticsDir("/tmp/myStatisticsDir/");
23
24 jlm::util::StatisticsCollectorSettings statisticsCollectorSettings(
26 expectedStatisticsDir,
27 "inputFile");
28
29 JlmOptCommandLineOptions commandLineOptions(
30 jlm::util::FilePath("inputFile.ll"),
31 JlmOptCommandLineOptions::InputFormat::Llvm,
32 jlm::util::FilePath("outputFile.ll"),
33 JlmOptCommandLineOptions::OutputFormat::Llvm,
34 statisticsCollectorSettings,
36 { JlmOptCommandLineOptions::OptimizationId::DeadNodeElimination,
37 JlmOptCommandLineOptions::OptimizationId::LoopUnrolling },
38 false);
39
40 JlmOptCommand command("jlm-opt", commandLineOptions);
41
42 // Act
43 auto receivedCommandLine = command.ToString();
44
45 // Assert
46 std::string expectedCommandLine = jlm::util::strfmt(
47 "jlm-opt ",
48 "--input-format=llvm ",
49 "--output-format=llvm ",
50 "--DeadNodeElimination --LoopUnrolling ",
51 "-s " + expectedStatisticsDir.to_str() + " ",
52 "--print-andersen-analysis ",
53 "-o outputFile.ll ",
54 "inputFile.ll");
55
56 EXPECT_EQ(receivedCommandLine, expectedCommandLine);
57}
58
59TEST(JlmOptCommandTests, OptimizationIdToOptimizationTranslation)
60{
61 using namespace jlm::llvm;
62 using namespace jlm::tooling;
63 using namespace jlm::util;
64
65 // Arrange
66 std::vector<JlmOptCommandLineOptions::OptimizationId> optimizationIds;
67 for (size_t n =
68 static_cast<std::size_t>(JlmOptCommandLineOptions::OptimizationId::FirstEnumValue) + 1;
69 n != static_cast<std::size_t>(JlmOptCommandLineOptions::OptimizationId::LastEnumValue);
70 n++)
71 {
72 auto optimizationId = static_cast<JlmOptCommandLineOptions::OptimizationId>(n);
73 optimizationIds.emplace_back(optimizationId);
74 }
75
77 FilePath(""),
78 JlmOptCommandLineOptions::InputFormat::Llvm,
79 FilePath(""),
80 JlmOptCommandLineOptions::OutputFormat::Llvm,
83 optimizationIds,
84 false);
85
86 // Act & Assert
87 // terminates on unhandled optimization id
88 JlmOptCommand command("jlm-opt", options);
89}
90
91TEST(JlmOptCommandTests, PrintRvsdgTreeToFile)
92{
93 using namespace jlm;
94
95 // Arrange
96 util::FilePath outputFile("/tmp/RvsdgTree");
97
98 jlm::llvm::LlvmRvsdgModule rvsdgModule(jlm::util::FilePath(""), "", "");
100
101 // Act
102 tooling::JlmOptCommand::PrintRvsdgModule(
103 rvsdgModule,
104 outputFile,
105 tooling::JlmOptCommandLineOptions::OutputFormat::Tree,
107
108 // Assert
109 std::stringstream buffer;
110 std::ifstream istream(outputFile.to_str());
111 buffer << istream.rdbuf();
112
113 EXPECT_EQ(buffer.str(), "RootRegion\n");
114}
static jlm::util::StatisticsCollector statisticsCollector
TEST(JlmOptCommandTests, TestStatistics)
const std::string & to_str() const noexcept
Definition file.hpp:275
Global memory state passed between functions.
static std::string strfmt(Args... args)
Definition strfmt.hpp:35