Skip to content

Commit b76c46b

Browse files
committed
Add C++ test
Signed-off-by: take-cheeze <[email protected]>
1 parent 5094dcf commit b76c46b

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

.github/workflows/cxx.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) ONNX Project Contributors
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
name: Build and Test
6+
7+
on:
8+
push:
9+
branches:
10+
- main
11+
pull_request:
12+
workflow_dispatch:
13+
14+
jobs:
15+
build_and_test:
16+
runs-on: ubuntu-24.04
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
submodules: recursive
21+
- run: cmake -GNinja -DONNX_BUILD_TESTS=ON -B build -S .
22+
- run: cmake --build build
23+
- run: cmake --build build -t test

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,10 @@ install(TARGETS
9898
onnx_optimizer onnx_optimizer_c_api
9999
EXPORT ONNXOptimizerTargets DESTINATION ${CMAKE_INSTALL_LIBDIR})
100100

101+
if(ONNX_BUILD_TESTS)
102+
enable_testing()
103+
include(third_party/onnx/cmake/external/googletest.cmake)
104+
add_executable(test_simple tests/test_simple.cc)
105+
target_link_libraries(test_simple onnx_optimizer gtest gtest_main)
106+
add_test(NAME test_simple COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_simple)
107+
endif()

tests/test_simple.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <gtest/gtest.h>
2+
#include <onnxoptimizer/optimize.h>
3+
#include <onnx/defs/parser.h>
4+
5+
TEST(OptimizerTest, NopReshape) {
6+
const char* graph_str = R"(
7+
<
8+
ir_version: 7,
9+
opset_import: [ "": 10]
10+
>
11+
agraph (float[5, 7] X) => (float[5, 7] Z)
12+
{
13+
Shape = Constant<value=int64[2]{5, -1}> ()
14+
Y = Reshape (X, Shape)
15+
Z = Identity(Y)
16+
}
17+
)";
18+
onnx::ModelProto model;
19+
const onnx::Status status = onnx::OnnxParser::Parse(model, graph_str);
20+
EXPECT_TRUE(status.IsOK());
21+
auto optimized_model = onnx::optimization::Optimize(model, {"eliminate_nop_reshape", "eliminate_deadend"});
22+
23+
ASSERT_EQ(optimized_model.graph().node().size(), 1);
24+
ASSERT_EQ(optimized_model.graph().node()[0].op_type(), "Identity");
25+
}

0 commit comments

Comments
 (0)