mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Summary: As GoogleTest `TEST` macro is non-compliant with it as well as `DEFINE_DISPATCH` All changes but the ones to `.clang-tidy` are generated using following script: ``` for i in `find . -type f -iname "*.c*" -or -iname "*.h"|xargs grep cppcoreguidelines-avoid-non-const-global-variables|cut -f1 -d:|sort|uniq`; do sed -i "/\/\/ NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)/d" $i; done ``` Pull Request resolved: https://github.com/pytorch/pytorch/pull/62008 Reviewed By: driazati, r-barnes Differential Revision: D29838584 Pulled By: malfet fbshipit-source-id: 1b2f8602c945bd4ce50a9bfdd204755556e31d13
52 lines
1.0 KiB
C++
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
|