Reads golden ApiDef files and returns a map from file name to ApiDef file contents.
| 47 | // Reads golden ApiDef files and returns a map from file name to ApiDef file |
| 48 | // contents. |
| 49 | void GetGoldenApiDefs(Env* env, const string& api_files_dir, |
| 50 | std::unordered_map<string, ApiDef>* name_to_api_def) { |
| 51 | std::vector<string> matching_paths; |
| 52 | TF_CHECK_OK(env->GetMatchingPaths( |
| 53 | io::JoinPath(api_files_dir, kApiDefFilePattern), &matching_paths)); |
| 54 | |
| 55 | for (auto& file_path : matching_paths) { |
| 56 | string file_contents; |
| 57 | TF_CHECK_OK(ReadFileToString(env, file_path, &file_contents)); |
| 58 | file_contents = PBTxtFromMultiline(file_contents); |
| 59 | |
| 60 | ApiDefs api_defs; |
| 61 | QCHECK(tensorflow::protobuf::TextFormat::ParseFromString(file_contents, |
| 62 | &api_defs)) |
| 63 | << "Failed to load " << file_path; |
| 64 | CHECK_EQ(api_defs.op_size(), 1); |
| 65 | (*name_to_api_def)[api_defs.op(0).graph_op_name()] = api_defs.op(0); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | void TestAllApiDefsHaveCorrespondingOp( |
| 70 | const OpList& ops, const std::unordered_map<string, ApiDef>& api_defs_map) { |
no test coverage detected