Commit 0bdbabee authored by Mateusz Rychlicki's avatar Mateusz Rychlicki
Browse files

INIT

parent 866176f5
# Extension-less executables #
##############################
*
!*.*
!*/
!Makefile
# Some specific folders #
#########################
**/build/
**/cmake-build-debug/
**/tmp/
# For safety #
###################
env.sh
# Compiled source #
###################
*.bdd
*.o
*.log
*.eps
*.fig
*~
.*
*.jpg
*.mexmaci64
# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
cmake_minimum_required(VERSION 3.3) # CMake version check
project(FairSyn VERSION 1.0)
set(CMAKE_CXX_STANDARD 11) # Enable c++11 standard
set(CMAKE_CXX_FLAGS "-O0 -Wall -Wextra -std=c++11 -Wfatal-errors -g -ldl --coverage -pthread") #-lgcov?
set(CMAKE_VERBOSE_MAKEFILE ON) # show everything
message("CMAKELIST: Root")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
set(FAIRSYN_ROOT ${PROJECT_SOURCE_DIR})
message("FAIRSYN_ROOT:" + ${FAIRSYN_ROOT})
set(ENV_VARIABLES env.sh)
set(CUDD_PATH "/home/mrychlicki/Desktop/cudd")
set(MASCOT_ROOT "/home/mrychlicki/Desktop/mascot-sds")
set(CUDD_LIBRARY_PATH "/home/mrychlicki/libraries/lib")
set(LD_LIBRARY_PATH "/home/mrychlicki/libraries/lib")
set(GOOGLE_TEST_PATH "/home/mrychlicki/Desktop/googletest")
set(SYLVAN_PATH "/home/mrychlicki/libraries")
set(CMAKE_BINARY_DIR ${FAIRSYN_ROOT}/build)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
include_directories(${FAIRSYN_ROOT}/ubdd)
include_directories(
${SYLVAN_PATH}/lib
${SYLVAN_PATH}/include)
include_directories(
${CUDD_PATH}
${CUDD_PATH}/include
${CUDD_PATH}/cudd
${CUDD_PATH}/lib
${CUDD_PATH}/util
${CUDD_PATH}/dddmph)
include_directories(${CUDD_LIBRARY_PATH})
#include_directories(
# ${HOAF_LIB_PATH}/
# ${HOAF_LIB_PATH}/cpphoafparser
# ${HOAF_LIB_PATH}/cpphoafparser/consumer
# ${HOAF_LIB_PATH}/cpphoafparser/parser
# ${HOAF_LIB_PATH}/cpphoafparser/util
# ${HOAF_LIB_PATH}/cpphoafparser/ast)
add_subdirectory(${FAIRSYN_ROOT}/ubdd)
add_subdirectory(${FAIRSYN_ROOT}/tests)
message("CMAKELIST: Tests")
include(GoogleTest) # For Terminal
find_package(GTest REQUIRED) # For Clion
add_executable(FairSynTests
ubdd/UBDDTests.h
ubdd/UBDDMintermIteratorTests.h
ubdd/CuddUBDDTests.cpp
ubdd/CuddUBDDMintermIteratorTests.cpp
ubdd/SylvanUBDDMintermIteratorTests.cpp
ubdd/SylvanUBDDTests.cpp
tests.cpp)
gtest_add_tests(TARGET FairSynTests)
set_target_properties(FairSynTests PROPERTIES LINKER_LANGUAGE CXX)
add_library(cudd STATIC IMPORTED)
set_property(TARGET cudd PROPERTY IMPORTED_LOCATION ${CUDD_LIBRARY_PATH}/libcudd.a)
target_link_libraries(FairSynTests cudd)
add_library(sylvan STATIC IMPORTED)
set_property(TARGET sylvan PROPERTY IMPORTED_LOCATION ${LD_LIBRARY_PATH}/libSylvan.a)
target_link_libraries(FairSynTests sylvan)
target_link_libraries(FairSynTests GTest::GTest GTest::Main)
#
# compiler
#
CC = g++
#CC = clang++
CXX_FLAGS = -Wall -Wextra -std=c++11 -O3 -DNDEBUG
TARGET = test
all: $(TARGET)
%.o:%.cc
$(CC) -c $(CXX_FLAGS) $(CUDD_INCa) $(CUDD_INCb) $< -o $@
$(TARGET): $(TARGET).o
$(CC) $(CXX_FLAGS) -o $(TARGET) $(TARGET).o $(CUDD_LIB_PATH) $(CUDD_LIBS)
clean:
rm -f ./$(TARGET) ./$(TARGET).o
/* a dummy test program to test the cudd installation */
#include "cuddObj.hh"
#include "dddmp.h"
#include <iostream>
int main() {
Cudd mgr(0, 0);
BDD x = mgr.bddVar();
}
//
// Created by mrychlicki on 7/27/21.
//
#include "gtest/gtest.h"
int main(int argc, char *argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
\ No newline at end of file
//
// Created by mrychlicki on 7/26/21.
//
#include "CuddUBDD.hh"
#include "UBDDMintermIteratorTests.h"
#include <gtest/gtest.h>
struct CuddUBDDMintermIteratorTests : UBDDMintermIteratorTests<CuddUBDD> {
};
TEST_F(CuddUBDDMintermIteratorTests, done) { check_done(); }
TEST_F(CuddUBDDMintermIteratorTests, numberOfMinterms) { check_numberOfMinterms(); }
TEST_F(CuddUBDDMintermIteratorTests, currentMinterm) { check_currentMinterm(); }
//
// Created by mrychlicki on 7/26/21.
//
#include "BaseUBDD.hh"
#include "CuddUBDD.hh"
#include "UBDDTests.h"
#include <gtest/gtest.h>
struct CuddUBDDTest : public UBDDTest<CuddUBDD> {
CuddUBDD *cudd_base;
CuddUBDDTest() {
cudd_base = new CuddUBDD();
}
};
TEST_F(CuddUBDDTest, CuddUBDD_operators) { check_operators(cudd_base); }
TEST_F(CuddUBDDTest, CuddUBDD_var) { check_var(cudd_base); }
TEST_F(CuddUBDDTest, CuddUBDD_nodeIndex) { check_nodeIndex(cudd_base); }
TEST_F(CuddUBDDTest, CuddUBDD_nodeSize) { check_nodeSize(cudd_base); }
TEST_F(CuddUBDDTest, CuddUBDD_cubes) { check_cubes(cudd_base); }
TEST_F(CuddUBDDTest, CuddUBDD_permute) { check_permute(cudd_base); }
TEST_F(CuddUBDDTest, CuddUBDD_countMinterm) { check_countMinterm(cudd_base); }
TEST_F(CuddUBDDTest, CuddUBDD_save_load) { check_save_load(cudd_base); }
\ No newline at end of file
//
// Created by mrychlicki on 8/12/21.
//
#ifndef MASCOTSDS_SYLVANTESTHELPER_H
#define MASCOTSDS_SYLVANTESTHELPER_H
#include "SylvanUBDD.hh"
struct SylvanTestHelper {
SylvanTestHelper() {
init_sylvan();
}
~SylvanTestHelper() {
stop_sylvan();
}
void init_sylvan() {
/* initiate the lace work-stealing framework and the sylvan parallel bdd library */
int dqsize = 100000;
lace_start(2, dqsize);
// use at most 1 GB, nodes:cache ratio 2:1, initial size 1/32 of maximum
sylvan::sylvan_set_limits(1 * 1024 * 1024 * 1024, 1, 5);
sylvan::sylvan_init_package();
sylvan::sylvan_init_mtbdd();
}
void stop_sylvan() {
sylvan::sylvan_stats_report(stdout);
sylvan::sylvan_quit();
lace_stop();
SylvanUBDD::nodes_map = std::map<size_t, SylvanUBDD *>();
SylvanUBDD::size_ = 0;
}
};
#endif//MASCOTSDS_SYLVANTESTHELPER_H
//
// Created by mrychlicki on 7/26/21.
//
#include "SylvanTestHelper.h"
//#include "SylvanUBDD.hh"
#include "UBDDMintermIteratorTests.h"
struct SylvanUBDDMintermIteratorTests : UBDDMintermIteratorTests<SylvanUBDD>, SylvanTestHelper {
};
TEST_F(SylvanUBDDMintermIteratorTests, done) { check_done(); }
TEST_F(SylvanUBDDMintermIteratorTests, numberOfMinterms) { check_numberOfMinterms(); }
TEST_F(SylvanUBDDMintermIteratorTests, currentMinterm) { check_currentMinterm(); }
//
// Created by mrychlicki on 7/26/21.
//
#include "BaseUBDD.hh"
#include "SylvanTestHelper.h"
#include "UBDDTests.h"
#include <gtest/gtest.h>
struct SylvanUBDDTest : public UBDDTest<SylvanUBDD>, SylvanTestHelper {
SylvanUBDD *sylvan_base;
SylvanUBDDTest() {
sylvan_base = new SylvanUBDD();
}
};
TEST_F(SylvanUBDDTest, operators) { check_operators(sylvan_base); }
TEST_F(SylvanUBDDTest, var) { check_var(sylvan_base); }
TEST_F(SylvanUBDDTest, nodeIndex) { check_nodeIndex(sylvan_base); }
TEST_F(SylvanUBDDTest, nodeSize) { check_nodeSize(sylvan_base); }
TEST_F(SylvanUBDDTest, cubes) { check_cubes(sylvan_base); }
TEST_F(SylvanUBDDTest, permute) { check_permute(sylvan_base); }
TEST_F(SylvanUBDDTest, countMinterm) { check_countMinterm(sylvan_base); }
TEST_F(SylvanUBDDTest, save_load) { check_save_load(sylvan_base); }
\ No newline at end of file
//
// Created by mrychlicki on 7/26/21.
//
#include "BaseUBDD.hh"
#include "UBDDMintermIterator.hh"
#include <algorithm>
#include <gtest/gtest.h>
#include <vector>
template <class UBDD>
struct UBDDMintermIteratorTests : testing::Test {
UBDD base;
void check_done() {
simple_test_done(base.var(0), {0}, 1);
simple_test_done(!base.var(0), {0}, 1);
simple_test_done(base.var(0) | base.var(1), {0, 1}, 3);
simple_test_done(base.var(0) | (!base.var(0)), {0}, 2);
simple_test_done(base.var(0) & (!base.var(0)), {0}, 0);
simple_test_done(base.var(42), {42}, 1);
simple_test_done(!base.var(42), {42}, 1);
simple_test_done(base.var(42) | base.var(2137), {42, 2137}, 3);
simple_test_done(base.var(42) | (!base.var(42)), {42}, 2);
simple_test_done(base.var(42) & (!base.var(42)), {42}, 0);
UBDD random = (base.var(42) ^ (!base.var(2137))) | base.var(69);
simple_test_done(random, {69, 42, 2137}, 6);
simple_test_done(!random, {69, 42, 2137}, 2);
}
void check_numberOfMinterms() {
simple_test_numberOfMinterms(base.var(0), {0}, 1);
simple_test_numberOfMinterms(!base.var(0), {0}, 1);
simple_test_numberOfMinterms(base.var(0) | base.var(1), {0, 1}, 3);
simple_test_numberOfMinterms(base.var(0) | (!base.var(0)), {0}, 2);
simple_test_numberOfMinterms(base.var(0) & (!base.var(0)), {0}, 0);
simple_test_numberOfMinterms(base.var(42), {42}, 1);
simple_test_numberOfMinterms(!base.var(42), {42}, 1);
simple_test_numberOfMinterms(base.var(42) | base.var(2137), {42, 2137}, 3);
simple_test_numberOfMinterms(base.var(42) | (!base.var(42)), {42}, 2);
simple_test_numberOfMinterms(base.var(42) & (!base.var(42)), {42}, 0);
UBDD random = (base.var(42) ^ (!base.var(2137))) | base.var(69);
simple_test_numberOfMinterms(random, {69, 42, 2137}, 6);
simple_test_done(!random, {69, 42, 2137}, 2);
UBDD large_ubdd = base.var(0);
std::vector<size_t> ivars_large(100);
for (int i = 0; i < 100; i++) {
large_ubdd |= base.var(20 * i);
ivars_large[i] = 20 * i;
}
EXPECT_ANY_THROW(large_ubdd.generateMintermIterator(ivars_large));
}
void check_currentMinterm() {
simple_test_currentMinterm(base.var(0), {0}, {{1}});
simple_test_currentMinterm(!base.var(0), {0}, {{0}});
simple_test_currentMinterm(base.var(0) | base.var(1), {0, 1}, {
{1, 1},
{0, 1},
{1, 0},
});
simple_test_currentMinterm(base.var(0) | (!base.var(0)), {0}, {{1}, {0}});
simple_test_currentMinterm(base.var(0) & (!base.var(0)), {0}, {});
simple_test_currentMinterm(base.var(42), {42}, {{1}});
simple_test_currentMinterm(!base.var(42), {42}, {{0}});
simple_test_currentMinterm(base.var(42) | base.var(2137), {42, 2137}, {
{1, 1},
{0, 1},
{1, 0},
});
simple_test_currentMinterm(base.var(42) | (!base.var(42)), {42}, {{1}, {0}});
simple_test_currentMinterm(base.var(42) & (!base.var(42)), {42}, {});
UBDD random = (base.var(42) ^ (!base.var(2137))) | base.var(69);
simple_test_currentMinterm(random, {69, 42, 2137}, {
{1, 1, 1},
{1, 1, 0},
{1, 0, 1},
{1, 0, 0},
{0, 1, 1},
{0, 0, 0},
});
simple_test_currentMinterm(!random, {69, 42, 2137}, {
{0, 1, 0},
{0, 0, 1},
});
}
private:
void simple_test_done(UBDD cube, std::vector<size_t> ivars, size_t prediction) {
UBDDMintermIterator *it = cube.generateMintermIterator(ivars);
for (size_t i = 0; i < prediction; i++) {
EXPECT_FALSE(it->done());
it->operator++();
}
EXPECT_TRUE(it->done());
}
void simple_test_numberOfMinterms(UBDD cube, std::vector<size_t> ivars, double prediction) {
UBDDMintermIterator *it = cube.generateMintermIterator(ivars);
EXPECT_FLOAT_EQ(it->numberOfMinterms(), prediction);
}
void simple_test_currentMinterm(UBDD cube, std::vector<size_t> ivars, std::set<std::vector<size_t>> prediction) {
UBDDMintermIterator *it = cube.generateMintermIterator(ivars);
std::set<std::vector<size_t>> s;
std::vector<size_t> minterm;
for (size_t i = 0; i < prediction.size(); i++) {
EXPECT_FALSE(it->done());
minterm = it->shortMinterm();
auto pointer = prediction.find(minterm);
EXPECT_FALSE(pointer == prediction.end());
EXPECT_TRUE(s.find(minterm) == s.end());
s.insert(minterm);
it->operator++();
}
EXPECT_TRUE(it->done());
}
};
</
//
// Created by mrychlicki on 7/26/21.
//
#include "BaseUBDD.hh"
#include <gtest/gtest.h>
template <class UBDD>
struct UBDDTest : testing::Test {
void check_operators(UBDD *A) {
EXPECT_TRUE(A->one() == A->one());
EXPECT_TRUE(A->zero() == A->zero());
EXPECT_FALSE(A->one() == A->zero());
check_booleans(A->zero(), A->zero());
check_booleans(A->zero(), A->one());
check_booleans(A->one(), A->zero());
check_booleans(A->one(), A->one());
}
void check_booleans(UBDD first, UBDD second) {
EXPECT_EQ(~first, !first);
EXPECT_EQ(first, !(!first));
EXPECT_EQ(first, !(!first));
EXPECT_TRUE((first == first));
EXPECT_TRUE(not(first == !first));
EXPECT_TRUE(not(first != first));
EXPECT_TRUE((first != !first));
EXPECT_EQ(first & second, first * second);
EXPECT_EQ(first | second, first + second);
EXPECT_EQ(first ^ second, (first & (!second)) | ((!first) & second));
EXPECT_EQ(first - second, first & (!second));
EXPECT_EQ(first.one(), first | (!first));
EXPECT_EQ(!(first | second), (!first) & (!second));
UBDD value_1 = first;
UBDD value_2;
value_2 = first;
EXPECT_EQ(value_1, value_2);
auto third = first;
third &= second;
EXPECT_EQ(first & second, third);
third = first;
third *= second;
EXPECT_EQ(first * second, third);
third = first;
third |= second;
EXPECT_EQ(first | second, third);
third = first;
third += second;
EXPECT_EQ(first + second, third);
third = first;
third ^= second;
EXPECT_EQ(first ^ second, third);
third = first;
third -= second;
EXPECT_EQ(first - second, third);
EXPECT_EQ(first < second, not(first >= second));
EXPECT_EQ(first > second, not(first <= second));
EXPECT_EQ(first == second, not(first != second));
EXPECT_EQ(first <= second, first < second || first == second);
EXPECT_EQ(first >= second, first > second || first == second);
EXPECT_EQ(first == second, first <= second && first >= second);
EXPECT_EQ(first != second, first < second || first > second);
}
void check_var(UBDD *A) {
auto var_0 = A->var();
auto var_1 = A->var();
auto ivar_0 = A->var(0);
auto ivar_1 = A->var(1);
auto ivar_41 = A->var(41);
auto var_42 = A->var();
auto ivar_42 = A->var(42);
EXPECT_EQ(var_0, ivar_0);
EXPECT_EQ(var_1, ivar_1);
EXPECT_EQ(var_42, ivar_42);
EXPECT_NE(var_0, var_1);
EXPECT_NE(var_0, var_42);
EXPECT_NE(var_1, var_42);
EXPECT_NE(var_42, ivar_41);
}
void check_nodeIndex(UBDD *A) {
auto var_0 = A->var();
auto var_1 = A->var();
auto ivar_41 = A->var(41);
auto var_42 = A->var();
auto ivar_1 = A->var(1);
EXPECT_EQ(var_0.nodeIndex(), 0);
EXPECT_EQ(var_1.nodeIndex(), 1);
EXPECT_EQ(ivar_41.nodeIndex(), 41);
EXPECT_EQ(var_42.nodeIndex(), 42);
EXPECT_EQ(ivar_1.nodeIndex(), 1);
}
void check_nodeSize(UBDD *A) {
size_t index = 0;
EXPECT_EQ(A->nodeSize(), index++);
auto a_0 = A->var();
EXPECT_EQ(A->nodeSize(), index++);
auto var = A->var();
EXPECT_EQ(var.nodeSize(), index);
EXPECT_EQ(A->nodeSize(), index++);
var.var();
EXPECT_EQ(var.nodeSize(), index);
EXPECT_EQ(A->nodeSize(), index++);
auto a_420 = A->var(420);
EXPECT_EQ(A->nodeSize(), 421);
EXPECT_EQ(var.nodeSize(), 421);
auto a_2137 = var.var(2137);
EXPECT_EQ(A->nodeSize(), 2138);
EXPECT_EQ(var.nodeSize(), 2138);
}
void check_cubes(UBDD *A) {
std::vector<UBDD> variables;
variables.push_back(A->var());
variables.push_back(A->var());
variables.push_back(A->var());
variables.push_back(A->var());
std::vector<uint8_t> values_char = {1, 1, 1, 1};
std::vector<int> values_int = {1, 1, 1, 1};
EXPECT_EQ(A->cube(variables, values_char), A->cube(variables, values_int));
EXPECT_EQ(A->cube(variables), A->cube(variables, values_int));
EXPECT_EQ(A->cube(variables), A->cube(variables, values_char));
values_char = {1, 0, 0, 1};
values_int = {1, 1, 1, 1};
EXPECT_TRUE(A->cube(variables, values_char) != A->cube(variables, values_int));
EXPECT_TRUE(A->cube(variables) == A->cube(variables, values_int));
EXPECT_TRUE(A->cube(variables) != A->cube(variables, values_char));
values_char = {1, 0, 0, 1};
values_int = {1, 0, 0, 1};
EXPECT_TRUE(A->cube(variables, values_char) == A->cube(variables, values_int));
EXPECT_TRUE(A->cube(variables) != A->cube(variables, values_int));
EXPECT_TRUE(A->cube(variables) != A->cube(variables, values_char));
}
void check_permute(UBDD *A) {
std::vector<UBDD> variables;
variables.push_back(A->var());
variables.push_back(A->var());
variables.push_back(A->var());
variables.push_back(A->var());
variables.push_back(A->var());
auto cube = A->cube(variables, std::vector<int>({0, 1, 0, 0, 0}));
EXPECT_EQ(cube, cube.permute({0, 1, 2, 3, 4}, {0, 1, 2, 3, 4}));
EXPECT_EQ(cube, cube.permute({0, 1, 2, 3, 4}, {0, 1, 2, 4, 3}));
EXPECT_EQ(cube, cube.permute({0, 1, 2, 3, 4}, {0, 1, 3, 2, 4}));
EXPECT_NE(cube, cube.permute({0, 1, 2, 3, 4}, {0, 4, 2, 3, 1}));
EXPECT_EQ(cube, cube.permute({3, 4}, {4, 3}));
EXPECT_NE(cube, cube.permute({1, 4}, {4, 1}));
EXPECT_EQ(cube, cube.permute({1, 2}, {2, 1}).permute({1, 2}, {2, 1}));
EXPECT_NE(cube, cube.permute({1, 2, 3}, {2, 3, 1}));
EXPECT_NE(cube, cube.permute({1, 2, 3}, {2, 3, 1}).permute({1, 2, 3}, {2, 3, 1}));
EXPECT_EQ(cube, cube.permute({1, 2, 3}, {2, 3, 1}).permute({1, 2, 3}, {2, 3, 1}).permute({1, 2, 3}, {2, 3, 1}));
}
void check_countMinterm(UBDD *A) {
std::vector<UBDD> variables;
UBDD a, b, c, tautology;
a = A->var();
EXPECT_FLOAT_EQ(a.countMinterm(0), 0.5);
EXPECT_FLOAT_EQ(a.countMinterm(1), 1);
EXPECT_FLOAT_EQ(a.countMinterm(2), 2);
EXPECT_FLOAT_EQ(a.countMinterm(3), 4);
variables = {A->var(0), A->var(0)};