From 887bad918787eeb38f0c2f465bae83ebaf2a0168 Mon Sep 17 00:00:00 2001 From: adrianlizarraga Date: Thu, 23 Jan 2025 23:24:43 -0800 Subject: [PATCH] Update unit test to check that JSON file was generated --- .../test/providers/qnn/qnn_basic_test.cc | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/onnxruntime/test/providers/qnn/qnn_basic_test.cc b/onnxruntime/test/providers/qnn/qnn_basic_test.cc index ad7ef09c58..bbc308c4b0 100644 --- a/onnxruntime/test/providers/qnn/qnn_basic_test.cc +++ b/onnxruntime/test/providers/qnn/qnn_basic_test.cc @@ -1027,6 +1027,7 @@ TEST_F(QnnHTPBackendTests, EPRejectsDynamicShapesF32) { } TEST_F(QnnHTPBackendTests, DumpJsonQNNGraph) { + const ORTCHAR_T* ort_model_path = ORT_MODEL_FOLDER "nhwc_resize_sizes_opset18.quant.onnx"; Ort::SessionOptions so; onnxruntime::ProviderOptions options; #if defined(_WIN32) @@ -1035,16 +1036,29 @@ TEST_F(QnnHTPBackendTests, DumpJsonQNNGraph) { options["backend_path"] = "libQnnHtp.so"; #endif + const std::filesystem::path dump_dir = "test_qnn_graphs_"; + options["json_qnn_graph_dir"] = dump_dir.string(); options["dump_json_qnn_graph"] = "1"; + // Remove pre-existing json files. Note that fs::remove_all() can handle non-existing paths. + std::filesystem::remove_all(dump_dir); + ASSERT_TRUE(std::filesystem::create_directory(dump_dir)); + so.AppendExecutionProvider("QNN", options); - Ort::Status status(OrtSessionOptionsAppendExecutionProvider_CPU(so, 1)); - - const ORTCHAR_T* ort_model_path = ORT_MODEL_FOLDER "nhwc_resize_sizes_opset18.quant.onnx"; - Ort::Session session(*ort_env, ort_model_path, so); - // TODO(adrianlizarraga): Check that output json files were generated. + + // Check that QNN JSON file(s) exist. + bool has_a_json_file = false; + for (auto const& dir_entry : std::filesystem::directory_iterator{dump_dir}) { + EXPECT_TRUE(dir_entry.is_regular_file()); + EXPECT_EQ(dir_entry.path().extension().string(), ".json"); + has_a_json_file = true; + } + EXPECT_TRUE(has_a_json_file); + + // Cleaup generated files. Comment the following line to inspect generated JOSN files. + std::filesystem::remove_all(dump_dir); } // Test option for offloading quantization of graph inputs and dequantization of graph outputs to the CPU EP.