Skip to content

Commit

Permalink
Merge pull request #322 from rocallahan/unit-tests
Browse files Browse the repository at this point in the history
Adds unit testing framework to ABC
  • Loading branch information
alanminko authored Aug 24, 2024
2 parents af77b80 + 49a4895 commit 034492b
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build-posix-cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ jobs:
run: |
cmake --build build
- name: Run Unit Tests
run: |
ctest --output-on-failure
- name: Test Executable
run: |
./build/abc -c "r i10.aig; b; ps; b; rw -l; rw -lz; b; rw -lz; b; ps; cec"
Expand Down
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,17 @@ add_library(libabc-pic EXCLUDE_FROM_ALL ${ABC_SRC})
abc_properties(libabc-pic PUBLIC)
set_property(TARGET libabc-pic PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET libabc-pic PROPERTY OUTPUT_NAME abc-pic)

if(NOT DEFINED ABC_SKIP_TESTS)
enable_testing()
include(FetchContent)
FetchContent_Declare(
googletest
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
# Specify the commit you depend on and update it regularly.
URL "https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip"
)
FetchContent_MakeAvailable(googletest)
include(GoogleTest)
add_subdirectory(test)
endif()
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(gia)
11 changes: 11 additions & 0 deletions test/gia/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_executable(gia_test gia_test.cc)

target_link_libraries(gia_test
gtest
gtest_main
libabc
)

gtest_discover_tests(gia_test
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
54 changes: 54 additions & 0 deletions test/gia/gia_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "gtest/gtest.h"

#include "aig/gia/gia.h"

ABC_NAMESPACE_IMPL_START

TEST(GiaTest, CanAllocateGiaManager) {
Gia_Man_t* aig_manager = Gia_ManStart(100);

EXPECT_TRUE(aig_manager != nullptr);
Gia_ManStop(aig_manager);
}

TEST(GiaTest, CanAddACi) {
Gia_Man_t* aig_manager = Gia_ManStart(100);
Gia_ManAppendCi(aig_manager);

EXPECT_EQ(Gia_ManCiNum(aig_manager), 1);
Gia_ManStop(aig_manager);
}

TEST(GiaTest, CanAddACo) {
Gia_Man_t* aig_manager = Gia_ManStart(100);
int input1 = Gia_ManAppendCi(aig_manager);
Gia_ManAppendCo(aig_manager, input1);

EXPECT_EQ(Gia_ManCiNum(aig_manager), 1);
EXPECT_EQ(Gia_ManCoNum(aig_manager), 1);
Gia_ManStop(aig_manager);
}

TEST(GiaTest, CanAddAnAndGate) {
Gia_Man_t* aig_manager = Gia_ManStart(100);

int input1 = Gia_ManAppendCi(aig_manager);
int input2 = Gia_ManAppendCi(aig_manager);

int and_output = Gia_ManAppendAnd(aig_manager, input1, input2);
Gia_ManAppendCo(aig_manager, and_output);

Vec_Wrd_t* stimulus = Vec_WrdAlloc(2);
Vec_WrdPush(stimulus, /*A*/1);
Vec_WrdPush(stimulus, /*B*/1);
Vec_Wrd_t* output = Gia_ManSimPatSimOut(aig_manager, stimulus, /*fouts*/1);

EXPECT_EQ(Gia_ManCiNum(aig_manager), 2);
EXPECT_EQ(Gia_ManCoNum(aig_manager), 1);
// A = 1, B = 1 -> A & B == 1
EXPECT_EQ(Vec_WrdGetEntry(output, 0), 1);
Vec_WrdFree(output);
Gia_ManStop(aig_manager);
}

ABC_NAMESPACE_IMPL_END

0 comments on commit 034492b

Please sign in to comment.