Skip to content

Commit

Permalink
dft: migrate unit testing to gtest
Browse files Browse the repository at this point in the history
Signed-off-by: Felipe Garay <fgaray@google.com>
  • Loading branch information
fgaray committed Aug 3, 2023
1 parent 72f6333 commit e44c568
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 84 deletions.
9 changes: 2 additions & 7 deletions src/dft/src/architect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,15 @@ add_library(dft_architect_lib

target_link_libraries(dft_architect_lib
PRIVATE
utl_lib
dft_utils_lib
dft_cells_lib
dft_base_scan_cell_lib
dft_clock_domain_lib
dft_config_lib
dft_utils_lib
dft_utils_scan_pin_lib
)

target_link_libraries(dft_architect_lib
PRIVATE
odb
dbSta
OpenSTA
utl
)

target_include_directories(dft_architect_lib
Expand Down
18 changes: 17 additions & 1 deletion src/dft/src/cells/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
add_library(dft_cells_lib
# Keep sorted
OneBitScanCell.cpp
ScanCell.cpp
ScanCellFactory.cpp
)

Expand All @@ -20,3 +19,20 @@ target_include_directories(dft_cells_lib
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)

add_library(dft_base_scan_cell_lib
ScanCell.cpp
)

target_link_libraries(dft_base_scan_cell_lib
PRIVATE
odb
dft_clock_domain_lib
dft_config_lib
dft_utils_scan_pin_lib
)

target_include_directories(dft_base_scan_cell_lib
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)
4 changes: 1 addition & 3 deletions src/dft/src/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ target_include_directories(dft_config_lib
target_link_libraries(dft_config_lib
PRIVATE
odb
dbSta
OpenSTA
utl_lib
dft_utils_lib
dft_utils_formatting_lib
)
2 changes: 1 addition & 1 deletion src/dft/src/config/ScanArchitectConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#include "ScanArchitectConfig.hh"

#include "Utils.hh"
#include "Formatting.hh"

namespace dft {

Expand Down
24 changes: 23 additions & 1 deletion src/dft/src/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
add_library(dft_utils_lib
# Keep sorted
Utils.cpp
ScanPin.cpp
)

target_link_libraries(dft_utils_lib
Expand All @@ -16,3 +15,26 @@ target_include_directories(dft_utils_lib
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)


add_library(dft_utils_scan_pin_lib
ScanPin.cpp
)

target_link_libraries(dft_utils_scan_pin_lib
PRIVATE
odb
)

target_include_directories(dft_utils_scan_pin_lib
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)


add_library(dft_utils_formatting_lib INTERFACE)

target_include_directories(dft_utils_formatting_lib
INTERFACE
${CMAKE_CURRENT_LIST_DIR}
)
18 changes: 18 additions & 0 deletions src/dft/src/utils/Formatting.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <spdlog/fmt/fmt.h>

#include <optional>
#include <string>

namespace dft::utils {

// Helper to format optional values for the config reports
template <typename T>
std::string FormatForReport(const std::optional<T>& opt)
{
if (opt.has_value()) {
return fmt::format("{}", opt.value());
}
return "Undefined";
}

} // namespace dft::utils
10 changes: 0 additions & 10 deletions src/dft/src/utils/Utils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,4 @@ std::vector<odb::dbITerm*> GetClockPin(odb::dbInst* inst);
// Returns a sta::Clock of the given iterm
std::optional<sta::Clock*> GetClock(sta::dbSta* sta, odb::dbITerm* iterm);

// Helper to format optional values for the config reports
template <typename T>
std::string FormatForReport(const std::optional<T>& opt)
{
if (opt.has_value()) {
return fmt::format("{}", opt.value());
}
return "Undefined";
}

} // namespace dft::utils
30 changes: 13 additions & 17 deletions src/dft/test/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
find_package(Boost)
include("openroad")


set(DFT_HOME ${PROJECT_SOURCE_DIR})

set(TEST_LIBS
utl_lib
dbSta_lib
gtest
gmock
gtest_main
odb
dft_cells_lib
dft_base_scan_cell_lib
dft_config_lib
dft_architect_lib
dft_clock_domain_lib
dft_utils_lib
dft_utils_scan_pin_lib
)

add_executable(TestScanArchitect TestScanArchitect.cpp)
target_link_libraries(TestScanArchitect ${TEST_LIBS})
gtest_discover_tests(TestScanArchitect WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

add_executable(TestScanArchitectHeuristic TestScanArchitectHeuristic.cpp ScanCellMock.cpp)
target_link_libraries(TestScanArchitectHeuristic ${TEST_LIBS})
target_include_directories(TestScanArchitectHeuristic
PRIVATE
${DFT_HOME}/src
)
gtest_discover_tests(TestScanArchitectHeuristic WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})


add_executable(TestScanArchitect TestScanArchitect.cpp)
target_link_libraries(TestScanArchitect ${TEST_LIBS})
target_include_directories(TestScanArchitect
PRIVATE
${DFT_HOME}/src
add_dependencies(build_and_test
TestScanArchitect
TestScanArchitectHeuristic
)
25 changes: 10 additions & 15 deletions src/dft/test/cpp/TestScanArchitect.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
#define BOOST_TEST_MODULE TestScanArchitect
#include <boost/test/included/unit_test.hpp>
#include <limits>
#include <random>
#include <sstream>

#include "ScanArchitect.hh"
#include "ScanArchitectConfig.hh"
#include "gtest/gtest.h"

namespace dft {
namespace {

BOOST_AUTO_TEST_SUITE(test_suite)

using namespace dft;

bool operator!=(const ScanArchitect::HashDomainLimits& lhs,
const ScanArchitect::HashDomainLimits& rhs)
{
Expand Down Expand Up @@ -44,41 +40,40 @@ ScanArchitect::HashDomainLimits CreateTestHashDomainLimits(uint64_t chain_count,
}

// Check if we are correctly calculating the limits of the hash domains
BOOST_AUTO_TEST_CASE(test_calculate_chain_count_and_max_length)
TEST(TestScanArchitect, CalculatesChainCountAndMaxLength)
{
// For 1 hash domain (1) with 10 bits and a max length of 5, we need to have a
// chain count of 2 in that hash domain (1)
BOOST_TEST(CompareUnordered(
EXPECT_TRUE(CompareUnordered(
ScanArchitect::inferChainCountFromMaxLength({{1, 10}}, 5),
{{1, CreateTestHashDomainLimits(2, 5)}}));
// Unbalance cases
// We create 2 chains with max_length of 4
BOOST_TEST(
EXPECT_TRUE(
CompareUnordered(ScanArchitect::inferChainCountFromMaxLength({{1, 9}}, 5),
{{1, CreateTestHashDomainLimits(2, 5)}}));
// We create 2 chains with max_length of 3
BOOST_TEST(
EXPECT_TRUE(
CompareUnordered(ScanArchitect::inferChainCountFromMaxLength({{1, 6}}, 5),
{{1, CreateTestHashDomainLimits(2, 3)}}));

// Two hash domains, balance case
BOOST_TEST(CompareUnordered(
EXPECT_TRUE(CompareUnordered(
ScanArchitect::inferChainCountFromMaxLength({{1, 10}, {2, 10}}, 5),
{{1, CreateTestHashDomainLimits(2, 5)},
{2, CreateTestHashDomainLimits(2, 5)}}));
// Unbalance
BOOST_TEST(CompareUnordered(
EXPECT_TRUE(CompareUnordered(
ScanArchitect::inferChainCountFromMaxLength({{1, 10}, {2, 9}}, 5),
{{1, CreateTestHashDomainLimits(2, 5)},
{2, CreateTestHashDomainLimits(2, 5)}}));

//// Two hash domains with different number of cells
BOOST_TEST(CompareUnordered(
EXPECT_TRUE(CompareUnordered(
ScanArchitect::inferChainCountFromMaxLength({{1, 10}, {2, 15}}, 5),
{{1, CreateTestHashDomainLimits(2, 5)},
{2, CreateTestHashDomainLimits(3, 5)}}));
}

BOOST_AUTO_TEST_SUITE_END()

} // namespace
} // namespace dft
38 changes: 14 additions & 24 deletions src/dft/test/cpp/TestScanArchitectHeuristic.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
#define BOOST_TEST_MODULE TestScanReplace
#include <boost/test/included/unit_test.hpp>
#include <sstream>
#include <unordered_set>

#include "ClockDomain.hh"
#include "ScanArchitect.hh"
#include "ScanArchitectConfig.hh"
#include "ScanCellMock.hh"
#include "gtest/gtest.h"

namespace dft::test {
namespace {

using namespace dft;
using namespace dft::test;
BOOST_AUTO_TEST_SUITE(test_suite)

// Check if we can architect a simple two chain design with clock no mix
BOOST_AUTO_TEST_CASE(test_one_clock_domain_no_mix)
TEST(TestScanArchitectHeuristic, ArchitectWithOneClockDomainNoMix)
{
utl::Logger* logger = new utl::Logger();

Expand Down Expand Up @@ -48,12 +43,12 @@ BOOST_AUTO_TEST_CASE(test_one_clock_domain_no_mix)
= scan_architect->getScanChains();

// There should be 2 chains
BOOST_TEST(scan_chains.size() == 2);
EXPECT_EQ(scan_chains.size(), 2);

// All the scan cells should be in the chains
std::unordered_set<std::string_view> scan_cells_in_chains_names;
for (const std::unique_ptr<ScanChain>& scan_chain : scan_chains) {
BOOST_TEST(!scan_chain->empty()); // All the chains should have cells
EXPECT_FALSE(scan_chain->empty()); // All the chains should have cells
for (const auto& scan_cell : scan_chain->getScanCells()) {
scan_cells_in_chains_names.insert(scan_cell->getName());
}
Expand All @@ -62,13 +57,11 @@ BOOST_AUTO_TEST_CASE(test_one_clock_domain_no_mix)
for (const std::string& name : scan_cell_names) {
const bool test = scan_cells_in_chains_names.find(name)
!= scan_cells_in_chains_names.end();
BOOST_TEST(test); // Was the cell included?
EXPECT_TRUE(test); // Was the cell included?
}
}

// Check if we can architect a simple four chain design, with two clocks and no
// clock mixing
BOOST_AUTO_TEST_CASE(test_two_clock_domain_no_mix)
TEST(TestScanArchitectHeuristic, ArchitectWithTwoClockDomainNoMix)
{
utl::Logger* logger = new utl::Logger();

Expand Down Expand Up @@ -114,20 +107,18 @@ BOOST_AUTO_TEST_CASE(test_two_clock_domain_no_mix)
= scan_architect->getScanChains();

// There should be 4 chains
BOOST_TEST(scan_chains.size() == 4);
EXPECT_EQ(scan_chains.size(), 4);

uint64_t total_bits = 0;
for (const auto& scan_chain : scan_chains) {
for (const auto& scan_cell : scan_chain->getScanCells()) {
total_bits += scan_cell->getBits();
}
}
BOOST_TEST(total_bits == 20 + 15);
EXPECT_EQ(total_bits, 20 + 15);
}

// Check if we can architect a simple four chain design, with two clocks and no
// clock mixing
BOOST_AUTO_TEST_CASE(test_two_edges_no_mix)
TEST(TestScanArchitectHeuristic, ArchitectWithTwoEdgesNoMix)
{
utl::Logger* logger = new utl::Logger();

Expand Down Expand Up @@ -173,7 +164,7 @@ BOOST_AUTO_TEST_CASE(test_two_edges_no_mix)
= scan_architect->getScanChains();

// There should be 4 chains
BOOST_TEST(scan_chains.size() == 4);
EXPECT_EQ(scan_chains.size(), 4);

uint64_t total_bits_rising = 0;
uint64_t total_bits_falling = 0;
Expand All @@ -189,10 +180,9 @@ BOOST_AUTO_TEST_CASE(test_two_edges_no_mix)
}
}
}
BOOST_TEST(total_bits_rising == 20);
BOOST_TEST(total_bits_falling == 15);
EXPECT_EQ(total_bits_rising, 20);
EXPECT_EQ(total_bits_falling, 15);
}

BOOST_AUTO_TEST_SUITE_END()

} // namespace
} // namespace dft::test
5 changes: 0 additions & 5 deletions src/dft/test/regression_tests.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,3 @@ record_tests {
scan_architect_no_mix_sky130
scan_architect_clock_mix_sky130
}


record_pass_fail_tests {
cpp_tests
}

0 comments on commit e44c568

Please sign in to comment.