| 15 | public: |
| 16 | virtual ~CallBackTest() = default; |
| 17 | virtual bool run(int precision) { |
| 18 | // build net |
| 19 | std::unique_ptr<NetT> net(new NetT); |
| 20 | std::unique_ptr<OpT> input(new OpT); |
| 21 | input->type = OpType_Input; |
| 22 | auto param(new InputT); |
| 23 | param->dims.push_back(1); |
| 24 | param->dims.push_back(1); |
| 25 | param->dims.push_back(1); |
| 26 | param->dims.push_back(64); |
| 27 | input->main.type = OpParameter_Input; |
| 28 | input->main.value = param; |
| 29 | input->outputIndexes.push_back(0); |
| 30 | net->oplists.emplace_back(std::move(input)); |
| 31 | std::unique_ptr<OpT> op(new OpT); |
| 32 | op->type = OpType_TanH; |
| 33 | op->inputIndexes.push_back(0); |
| 34 | op->outputIndexes.push_back(1); |
| 35 | net->oplists.emplace_back(std::move(op)); |
| 36 | net->tensorName.push_back("tensor_0"); |
| 37 | net->tensorName.push_back("tensor_1"); |
| 38 | net->tensorNumber = 2; |
| 39 | net->usage = Usage_INFERENCE; |
| 40 | flatbuffers::FlatBufferBuilder builder(1024); |
| 41 | auto offset = MNN::Net::Pack(builder, net.get()); |
| 42 | builder.Finish(offset); |
| 43 | int size = builder.GetSize(); |
| 44 | auto buffer = builder.GetBufferPointer(); |
| 45 | std::shared_ptr<Interpreter> interpreter(Interpreter::createFromBuffer(buffer, size)); |
| 46 | ScheduleConfig config; |
| 47 | Session* session = interpreter->createSession(config); |
| 48 | // run callback |
| 49 | bool opType = false, opInput = false, opOutput = false; |
| 50 | TensorCallBackWithInfo before = [&](const std::vector<Tensor*>& nTensors, const OperatorInfo* info) { |
| 51 | opType = info->type() == "UnaryOp"; |
| 52 | opInput = nTensors.size() == 1 && nTensors[0]->shape()[3] == 64; |
| 53 | return false; |
| 54 | }; |
| 55 | TensorCallBackWithInfo after = [&](const std::vector<Tensor*>& nTensors, const OperatorInfo* info) { |
| 56 | opType &= info->type() == "UnaryOp"; |
| 57 | opOutput = nTensors.size() == 1 && nTensors[0]->shape()[3] == 64; |
| 58 | return true; |
| 59 | }; |
| 60 | interpreter->runSessionWithCallBackInfo(session, before, after); |
| 61 | return opType && opInput && opOutput; |
| 62 | } |
| 63 | }; |
| 64 | MNNTestSuiteRegister(CallBackTest, "core/callback"); |
nothing calls this directly
no test coverage detected