pytorch/test/cpp/jit/test_inliner.cpp
Michael Suo 22401b850b port all JIT tests to gtest (#45264)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/45264

Context for why we are porting to gtest in: https://github.com/pytorch/pytorch/pull/45018.

This PR completes the process of porting and removes unused files/macros.

Test Plan: Imported from OSS

Reviewed By: ZolotukhinM

Differential Revision: D23901392

Pulled By: suo

fbshipit-source-id: 89526890e1a49462f3f77718f4ee273c5bc578ba
2020-09-25 11:37:43 -07:00

52 lines
1.0 KiB
C++

#include <gtest/gtest.h>
#include <torch/csrc/jit/api/compilation_unit.h>
#include <torch/csrc/jit/api/module.h>
#include <torch/csrc/jit/passes/inliner.h>
#include <torch/csrc/jit/testing/file_check.h>
const auto testSource = R"JIT(
def foo1(x):
print("one")
return x
def foo2(x):
print("two")
return foo1(x)
def foo3(x):
print("three")
return foo2(x)
)JIT";
namespace torch {
namespace jit {
using namespace testing;
struct InlinerGuard {
explicit InlinerGuard(bool shouldInline)
: oldState_(getInlineEverythingMode()) {
getInlineEverythingMode() = shouldInline;
}
~InlinerGuard() {
getInlineEverythingMode() = oldState_;
}
bool oldState_;
};
TEST(InlinerTest, Basic) {
// disable automatic inlining so we can test it manually
InlinerGuard guard(/*shouldInline=*/false);
CompilationUnit cu(testSource);
auto& fn = cu.get_function("foo3");
auto g = fn.graph();
Inline(*g);
FileCheck().check_count("prim::Print", 3)->run(*g);
}
} // namespace jit
} // namespace torch