Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/cxx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (c) ONNX Project Contributors
#
# SPDX-License-Identifier: Apache-2.0

name: Build and Test

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
build_and_test:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- run: cmake -GNinja -DONNX_BUILD_TESTS=ON -B build -S .
- run: cmake --build build
- run: cmake --build build -t test
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,10 @@ install(TARGETS
onnx_optimizer onnx_optimizer_c_api
EXPORT ONNXOptimizerTargets DESTINATION ${CMAKE_INSTALL_LIBDIR})

if(ONNX_BUILD_TESTS)
enable_testing()
include(third_party/onnx/cmake/external/googletest.cmake)
add_executable(test_simple tests/test_simple.cc)
target_link_libraries(test_simple onnx_optimizer gtest gtest_main)
add_test(NAME test_simple COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_simple)
endif()
25 changes: 25 additions & 0 deletions tests/test_simple.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <gtest/gtest.h>
#include <onnxoptimizer/optimize.h>
#include <onnx/defs/parser.h>

TEST(OptimizerTest, NopReshape) {
const char* graph_str = R"(
<
ir_version: 7,
opset_import: [ "": 10]
>
agraph (float[5, 7] X) => (float[5, 7] Z)
{
Shape = Constant<value=int64[2]{5, -1}> ()
Y = Reshape (X, Shape)
Z = Identity(Y)
}
)";
onnx::ModelProto model;
const onnx::Status status = onnx::OnnxParser::Parse(model, graph_str);
EXPECT_TRUE(status.IsOK());
auto optimized_model = onnx::optimization::Optimize(model, {"eliminate_nop_reshape", "eliminate_deadend"});

ASSERT_EQ(optimized_model.graph().node().size(), 1);
ASSERT_EQ(optimized_model.graph().node()[0].op_type(), "Identity");
}