diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5c7159b12410400d70310dfc1781e55f218946e5..5f91f8b8aaeb915c3f667007e7ce47ab382b1af9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,9 +3,9 @@ repos: sha: v1.0.1 hooks: - id: remove-crlf - files: (src).*\.(md|py|mm|swift|java|c|cc|cxx|cpp|cu|h|hpp|hxx)$ + files: (src/).*\.(md|py|mm|swift|java|c|cc|cxx|cpp|cu|h|hpp|hxx)$ - id: remove-tabs - files: (src).*\.(md|py|mm|swift|java|c|cc|cxx|cpp|cu|h|hpp|hxx)$ + files: (test/|src/).*\.(md|py|mm|swift|java|c|cc|cxx|cpp|cu|h|hpp|hxx)$ - repo: https://github.com/pre-commit/pre-commit-hooks sha: 5bf6c09bfa1297d3692cadd621ef95f1284e33c0 @@ -16,9 +16,9 @@ repos: - id: detect-private-key files: (?!.*tar.gz)^.*$ - id: end-of-file-fixer - files: (src).*\.(md|py|mm|swift|java|c|cc|cxx|cpp|h|hpp|hxx)$ + files: (test/|src/).*\.(md|py|mm|swift|java|c|cc|cxx|cpp|h|hpp|hxx)$ - id: trailing-whitespace - files: (src).*\.(md|py|mm|swift|java|c|cc|cxx|cpp|h|hpp|hxx)$ + files: (test/|src/).*\.(md|py|mm|swift|java|c|cc|cxx|cpp|h|hpp|hxx)$ - repo: local hooks: @@ -26,7 +26,7 @@ repos: name: copyright entry: python ./tools/pre-commit.hooks/copyright.hook language: system - files: (src).*\.(c|cc|cxx|cpp|h|hpp|hxx|py)$ + files: (test/|src/).*\.(c|cc|cxx|cpp|h|hpp|hxx|py)$ exclude: (?!.*third_party)^.*$ | (?!.*book)^.*$ - repo: local @@ -36,17 +36,7 @@ repos: description: Format files with ClangFormat. entry: bash ./tools/pre-commit.hooks/clang-format.hook -i language: system - files: (src).*\.(c|cc|cxx|cpp|h|hpp|hxx)$ - -# -#- repo: local -# hooks: -# - id: clang-tidy -# name: clang-tidy -# description: Check C++ code style using clang-tidy. -# entry: bash ./tools/pre-commit.hooks/.clang-tidy.hook -i -# language: system -# files: (src).*\.(c|cc|cxx|cpp|h|hpp|hxx)$ + files: (test/|src/).*\.(c|cc|cxx|cpp|h|hpp|hxx)$ - repo: local hooks: @@ -55,6 +45,16 @@ repos: description: Check C++ code style using cpplint. entry: bash ./tools/pre-commit.hooks/cpplint.hook language: system - files: (test|src).*\.(c|cc|cxx|cpp|h|hpp|hxx)$ + files: (test/|src/).*\.(c|cc|cxx|cpp|h|hpp|hxx)$ exclude: (?!.*third_party)^.*$ | (?!.*book)^.*$i | *\.pb\.cpp + +# +#- repo: local +# hooks: +# - id: clang-tidy +# name: clang-tidy +# description: Check C++ code style using clang-tidy. +# entry: bash ./tools/pre-commit.hooks/.clang-tidy.hook -i +# language: system +# files: (src).*\.(c|cc|cxx|cpp|h|hpp|hxx)$ diff --git a/test/common/test_log.cpp b/test/common/test_log.cpp index 6707d9ccd9e0a1b10ad6a4a61fac02363bc18b6d..9efcf007d01b39d60be42736ec52ec382a5cd775 100644 --- a/test/common/test_log.cpp +++ b/test/common/test_log.cpp @@ -15,7 +15,6 @@ limitations under the License. */ #include "common/log.h" int main() { - DLOGF("DASJFDAFJ%d -- %f", 12345, 344.234); LOGF(paddle_mobile::kLOG_DEBUG, "DASJFDAFJ%d -- %f", 12345, 344.234); diff --git a/test/framework/executor_for_test.cpp b/test/framework/executor_for_test.cpp index 39039e80235fdb425eb249271c353502d5cffb5b..36af9899573b4e2c8f6eaaaa1c85136c87573e6f 100644 --- a/test/framework/executor_for_test.cpp +++ b/test/framework/executor_for_test.cpp @@ -12,13 +12,12 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#include "executor_for_test.h" +#include "framework/executor_for_test.h" template Executor4Test::Executor4Test(const Program p, std::string op_type) : Executor(p) { - if (this->program_.originProgram == nullptr) { LOG(paddle_mobile::LogLevel::kLOG_ERROR) << "to_predict_program_ == nullptr"; @@ -27,7 +26,7 @@ Executor4Test::Executor4Test(const Program p, const std::vector> blocks = this->to_predict_program_->Blocks(); - for (std::shared_ptr block_desc: blocks) { + for (std::shared_ptr block_desc : blocks) { std::vector> ops = block_desc->Ops(); for (std::shared_ptr op : ops) { if (op->Type() == op_type) { @@ -43,9 +42,8 @@ Executor4Test::Executor4Test(const Program p, } template -std::shared_ptr -Executor4Test::predict(const Tensor &t, std::string input, - std::string output, DDim &dDim) { +std::shared_ptr Executor4Test::predict( + const Tensor &t, std::string input, std::string output, const DDim &dDim) { auto scope = this->program_.scope; Variable *g_feed_value = scope->Var(input); auto tensor = g_feed_value->GetMutable(); @@ -68,5 +66,5 @@ template class Executor4Test< paddle_mobile::CPU, paddle_mobile::operators::PoolOp>; template class Executor4Test< - paddle_mobile::CPU, - paddle_mobile::operators::SoftmaxOp>; + paddle_mobile::CPU, + paddle_mobile::operators::SoftmaxOp>; diff --git a/test/framework/executor_for_test.h b/test/framework/executor_for_test.h index 306b09df87496359ff4419bfa45046f47005e956..392b433c7775fd1d547049ff57ba10f4dfa66ed1 100644 --- a/test/framework/executor_for_test.h +++ b/test/framework/executor_for_test.h @@ -21,20 +21,20 @@ limitations under the License. */ #include "operators/pool_op.h" #include "operators/softmax_op.h" -using paddle_mobile::framework::Tensor; -using paddle_mobile::framework::LoDTensor; -using std::string; +using paddle_mobile::framework::BlockDesc; using paddle_mobile::framework::DDim; using paddle_mobile::framework::Executor; -using paddle_mobile::framework::Program; -using paddle_mobile::framework::BlockDesc; +using paddle_mobile::framework::LoDTensor; using paddle_mobile::framework::OpDesc; +using paddle_mobile::framework::Program; +using paddle_mobile::framework::Tensor; using paddle_mobile::framework::Variable; +using std::string; template class Executor4Test : public Executor { public: Executor4Test(Program p, string op_type); std::shared_ptr predict(const Tensor &t, string input, string output, - DDim &dDim); + const DDim &dDim); }; diff --git a/test/framework/test_load.cpp b/test/framework/test_load.cpp index d805070675e978ed2e413aacd3e23b8eb363ae32..5cc6b372a0fc41514d7f8f5bc370fa791c76acdc 100644 --- a/test/framework/test_load.cpp +++ b/test/framework/test_load.cpp @@ -12,13 +12,13 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#include "io.h" +#include "/io.h" int main() { paddle_mobile::Loader loader; - //../../../test/models/googlenet - //../../../test/models/mobilenet + // ../../../test/models/googlenet + // ../../../test/models/mobilenet auto program = loader.Load(std::string("../models/googlenet")); return 0; -} \ No newline at end of file +} diff --git a/test/framework/test_optimize.cpp b/test/framework/test_optimize.cpp index 5a85c4edaf367fcdc741578b20adf3c0f02ca46d..6cfc1afdc9193b94bacdd2c0842373ea61e30bf3 100644 --- a/test/framework/test_optimize.cpp +++ b/test/framework/test_optimize.cpp @@ -12,23 +12,19 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ +#include "/io.h" #include "framework/program/program-optimize/node.h" #include "framework/program/program-optimize/program_optimize.h" -#include "io.h" - -using namespace paddle_mobile; -using namespace paddle_mobile::framework; int main() { - Loader loader; // "../../../test/models/googlenet" auto program = loader.Load("../models/googlenet"); ProgramOptimize optimize; -// program.originProgram->Description("origin"); + // program.originProgram->Description("origin"); auto optimize_program = optimize.FushionOptimize(program.originProgram); if (optimize_program != nullptr) { -// optimize_program->Description("optimize"); + // optimize_program->Description("optimize"); } else { LOG(kLOG_ERROR) << "optimize_program is null"; } diff --git a/test/operators/test_batchnorm_op.cpp b/test/operators/test_batchnorm_op.cpp index 7f475f0f5a7d8f961aaa8aaf9f9baaa7f7c9e73d..271a42c0c3be4b24e5be59ea0cb4915e980b07d0 100644 --- a/test/operators/test_batchnorm_op.cpp +++ b/test/operators/test_batchnorm_op.cpp @@ -19,8 +19,9 @@ limitations under the License. */ namespace paddle_mobile { namespace framework { -template class TestBatchNormOp { -public: +template +class TestBatchNormOp { + public: explicit TestBatchNormOp(const Program p) : program_(p) { if (use_optimize_) { to_predict_program_ = program_.optimizeProgram; @@ -59,8 +60,9 @@ public: } } - std::shared_ptr predict_bn(Tensor &t1, Tensor &t2, Tensor &t3, - Tensor &t4, Tensor &t5) { + std::shared_ptr predict_bn(const Tensor &t1, const Tensor &t2, + const Tensor &t3, const Tensor &t4, + const Tensor &t5) { // feed auto scope = program_.scope; Variable *x1_feed_value = scope->Var("conv2d_0.tmp_0"); @@ -96,7 +98,7 @@ public: return out_tensor; } -private: + private: const framework::Program program_; std::shared_ptr to_predict_program_; std::map; -} // namespace framework -} // namespace paddle_mobile +} // namespace framework +} // namespace paddle_mobile int main() { DLOG << "----------**********----------"; diff --git a/test/operators/test_concat_op.cpp b/test/operators/test_concat_op.cpp index d3c78280cbd6a9acd58ac41be4554cca58cc31f8..205274ea7ab240f2a9917960029b3efd40ee9205 100644 --- a/test/operators/test_concat_op.cpp +++ b/test/operators/test_concat_op.cpp @@ -19,8 +19,9 @@ limitations under the License. */ namespace paddle_mobile { namespace framework { -template class TestConcatOp { -public: +template +class TestConcatOp { + public: explicit TestConcatOp(const Program p) : program_(p) { if (use_optimize_) { to_predict_program_ = program_.optimizeProgram; @@ -55,8 +56,8 @@ public: } } - std::shared_ptr predict_concat(Tensor &t1, Tensor &t2, Tensor &t3, - Tensor &t4) { + std::shared_ptr predict_concat(const Tensor &t1, const Tensor &t2, + const Tensor &t3, const Tensor &t4) { // feed auto scope = program_.scope; Variable *x1_feed_value = scope->Var("conv2d_3.tmp_1"); @@ -88,7 +89,7 @@ public: return out_tensor; } -private: + private: const framework::Program program_; std::shared_ptr to_predict_program_; std::map; -} // namespace framework -} // namespace paddle_mobile +} // namespace framework +} // namespace paddle_mobile int main() { DLOG << "----------**********----------"; diff --git a/test/operators/test_cov_op.cpp b/test/operators/test_cov_op.cpp index 4e88b86ba542c2efe995d90d32c566f323c6793e..f44bb31bafd666d9d7428e5cb5ce2909676c0036 100644 --- a/test/operators/test_cov_op.cpp +++ b/test/operators/test_cov_op.cpp @@ -12,13 +12,13 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#include "../framework/executor_for_test.h" -#include "../test_helper.h" -#include "./io.h" +#include +#include "framework/executor_for_test.h" +#include "framework/test_helper.h" int main() { paddle_mobile::Loader loader; - //../models/image_classification_resnet.inference.model + // ../models/image_classification_resnet.inference.model auto program = loader.Load(std::string("../models/googlenet")); if (program.originProgram == nullptr) { DLOG << "program file read fail"; @@ -32,8 +32,7 @@ int main() { SetupTensor(&input, {1, 3, 32, 32}, static_cast(0), static_cast(1)); auto out_ddim = paddle_mobile::framework::make_ddim({1, 64, 56, 56}); - auto output = - executor.predict(input, "data", "conv2d_0.tmp_0", out_ddim); + auto output = executor.predict(input, "data", "conv2d_0.tmp_0", out_ddim); auto output_ptr = output->data(); for (int j = 0; j < output->numel(); ++j) { diff --git a/test/operators/test_elementwise_add_op.cpp b/test/operators/test_elementwise_add_op.cpp index 8d0bfbe4179c5adee659966e1e7b52d92a1b2c24..309f86b22d46306158d67260305cbf8c87a2668a 100644 --- a/test/operators/test_elementwise_add_op.cpp +++ b/test/operators/test_elementwise_add_op.cpp @@ -19,8 +19,9 @@ limitations under the License. */ namespace paddle_mobile { namespace framework { -template class TestElementwiseAddOp { -public: +template +class TestElementwiseAddOp { + public: explicit TestElementwiseAddOp(const Program p) : program_(p) { if (use_optimize_) { to_predict_program_ = program_.optimizeProgram; @@ -59,7 +60,7 @@ public: } } - std::shared_ptr predict_add(Tensor &t1, Tensor &t2) { + std::shared_ptr predict_add(const Tensor &t1, const Tensor &t2) { // feed auto scope = program_.scope; Variable *x_feed_value = scope->Var("batch_norm_2.tmp_2"); @@ -83,7 +84,7 @@ public: return out_tensor; } -private: + private: const framework::Program program_; std::shared_ptr to_predict_program_; std::map; -} // namespace framework -} // namespace paddle_mobile +} // namespace framework +} // namespace paddle_mobile int main() { DLOG << "----------**********----------"; DLOG << "begin to run ElementAddOp Test"; diff --git a/test/operators/test_lrn_op.cpp b/test/operators/test_lrn_op.cpp index 94dad826ee328817f91fcf064c9948840fd4f3bb..2284b38abc378d38e8441d2d7462cc345678fef4 100644 --- a/test/operators/test_lrn_op.cpp +++ b/test/operators/test_lrn_op.cpp @@ -19,8 +19,9 @@ limitations under the License. */ namespace paddle_mobile { namespace framework { -template class TestLrnOp { -public: +template +class TestLrnOp { + public: explicit TestLrnOp(const Program p) : program_(p) { if (use_optimize_) { to_predict_program_ = program_.optimizeProgram; @@ -57,7 +58,7 @@ public: } } - std::shared_ptr predict_lrn(Tensor &t1) { + std::shared_ptr predict_lrn(const Tensor &t1) { // feed auto scope = program_.scope; Variable *x1_feed_value = scope->Var("pool2d_0.tmp_0"); @@ -77,7 +78,7 @@ public: return out_tensor; } -private: + private: const framework::Program program_; std::shared_ptr to_predict_program_; std::map; -} // namespace framework -} // namespace paddle_mobile +} // namespace framework +} // namespace paddle_mobile int main() { DLOG << "----------**********----------"; diff --git a/test/operators/test_mul_op.cpp b/test/operators/test_mul_op.cpp index 59991c3363c7c4b76a43e4798334ba6c1eccc291..061a942ed85737b41fbf0d5658134757ffbea68a 100644 --- a/test/operators/test_mul_op.cpp +++ b/test/operators/test_mul_op.cpp @@ -19,8 +19,9 @@ limitations under the License. */ namespace paddle_mobile { namespace framework { -template class TestMulOp { -public: +template +class TestMulOp { + public: explicit TestMulOp(const Program p) : program_(p) { if (use_optimize_) { to_predict_program_ = program_.optimizeProgram; @@ -59,7 +60,7 @@ public: } } - std::shared_ptr predict_mul(Tensor &t1, Tensor &t2) { + std::shared_ptr predict_mul(const Tensor &t1, const Tensor &t2) { // feed auto scope = program_.scope; Variable *x_feed_value = scope->Var("pool2d_0.tmp_0"); @@ -83,7 +84,7 @@ public: return out_tensor; } -private: + private: const framework::Program program_; std::shared_ptr to_predict_program_; std::map; -} // namespace framework -} // namespace paddle_mobile +} // namespace framework +} // namespace paddle_mobile int main() { DLOG << "----------**********----------"; diff --git a/test/test_helper.h b/test/test_helper.h index 9c3bbb29c75c618c838001cae3eabd70da3d8dea..43db08a623639938477bd98fc39c6f50e30d7508 100644 --- a/test/test_helper.h +++ b/test/test_helper.h @@ -12,11 +12,14 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ +#ifndef TEST_TEST_INCLUDE_H_ +#define TEST_TEST_INCLUDE_H_ + #pragma once +#include #include "common/log.h" #include "framework/ddim.h" #include "framework/tensor.h" -#include template void SetupTensor(paddle_mobile::framework::Tensor *input, @@ -30,3 +33,5 @@ void SetupTensor(paddle_mobile::framework::Tensor *input, input_ptr[i] = static_cast(uniform_dist(rng) * (upper - lower) + lower); } } + +#endif diff --git a/test/test_include.h b/test/test_include.h index 092ebe7c3dc1003cc6f8a67f13a5d4ea775cde7a..e1d9592d6151c1b1eee7b034db6424b4e9272d47 100644 --- a/test/test_include.h +++ b/test/test_include.h @@ -12,18 +12,23 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ +#ifndef TEST_TEST_INCLUDE_H_ +#define TEST_TEST_INCLUDE_H_ + #include #include #include -#include "framework/program/block_desc.h" +#include "./test_helper.h" +#include "/io.h" #include "framework/framework.pb.h" #include "framework/lod_tensor.h" #include "framework/operator.h" +#include "framework/program/block_desc.h" #include "framework/program/program.h" #include "framework/program/program_desc.h" #include "framework/scope.h" #include "framework/tensor.h" #include "framework/variable.h" -#include "io.h" -#include "test_helper.h" + +#endif // TEST_TEST_INCLUDE_H_