Files
concrete/compilers/concrete-compiler/compiler/tests/tests_tools/assert.h
Alexandre Péré e8ef48ffd8 feat(compiler): introduce concrete-protocol
This commit:
 + Adds support for a protocol which enables inter-op between concrete,
   tfhe-rs and potentially other contributors to the fhe ecosystem.
 + Gets rid of hand-made serialization in the compiler, and
   client/server libs.
 + Refactors client/server libs to allow more pre/post processing of
   circuit inputs/outputs.

The protocol is supported by a definition in the shape of a capnp file,
which defines different types of objects among which:
 + ProgramInfo object, which is a precise description of a set of fhe
   circuit coming from the same compilation (understand function type
   information), and the associated key set.
 + *Key objects, which represent secret/public keys used to
   encrypt/execute fhe circuits.
 + Value object, which represent values that can be transferred between
   client and server to support calls to fhe circuits.

The hand-rolled serialization that was previously used is completely
dropped in favor of capnp in the whole codebase.

The client/server libs, are refactored to introduce a modular design for
pre-post processing. Reading the ProgramInfo file associated with a
compilation, the client and server libs assemble a pipeline of
transformers (functions) for pre and post processing of values coming in
and out of a circuit. This design properly decouples various aspects of
the processing, and allows these capabilities to be safely extended.

In practice this commit includes the following:
 + Defines the specification in a concreteprotocol package
 + Integrate the compilation of this package as a compiler dependency
   via cmake
 + Modify the compiler to use the Encodings objects defined in the
   protocol
 + Modify the compiler to emit ProgramInfo files as compilation
   artifact, and gets rid of the bloated ClientParameters.
 + Introduces a new Common library containing the functionalities shared
   between the compiler and the client/server libs.
 + Introduces a functional pre-post processing pipeline to this common
   library
 + Modify the client/server libs to support loading ProgramInfo objects,
   and calling circuits using Value messages.
 + Drops support of JIT.
 + Drops support of C-api.
 + Drops support of Rust bindings.

Co-authored-by: Nikita Frolov <nf@mkmks.org>
2023-11-09 17:09:04 +01:00

150 lines
6.9 KiB
C++

#ifndef UINT_TESTS_COMMON_ASSERT_H
#define UINT_TESTS_COMMON_ASSERT_H
#include "llvm/ADT/StringExtras.h"
#include <concretelang/Runtime/DFRuntime.hpp>
#include <gtest/gtest.h>
#define ASSERT_LLVM_ERROR(err) \
{ \
llvm::Error e = err; \
if (e) { \
handleAllErrors(std::move(e), [](const llvm::ErrorInfoBase &ei) { \
ASSERT_TRUE(false) << ei.message(); \
}); \
} \
}
#define DISCARD_LLVM_ERROR(err) \
{ \
llvm::Error e = std::move(err); \
if (e) { \
handleAllErrors(std::move(e), [](const llvm::ErrorInfoBase &ei) { \
ASSERT_TRUE(true); \
}); \
} \
}
// Checks that the value `val` is not in an error state. Returns
// `true` if the test passes, otherwise `false`.
template <typename T>
static bool assert_expected_success(llvm::Expected<T> &val) {
if (!((bool)val)) {
return false;
}
return true;
}
// Checks that the value `val` is not in an error state. Returns
// `true` if the test passes, otherwise `false`.
template <typename T>
static bool assert_expected_success(llvm::Expected<T> &&val) {
return assert_expected_success(val);
}
// Checks that the value `val` is not in an error state. Returns
// `true` if the test passes, otherwise `false`.
template <typename T>
static bool assert_expected_failure(llvm::Expected<T> &&val) {
if (!((bool)val)) {
if (!mlir::concretelang::dfr::_dfr_is_root_node()) {
llvm::toString(val.takeError());
return true;
}
// We need to consume the error, so let's do it here
llvm::errs() << "assert_expected_failure: "
<< llvm::toString(val.takeError()) << "\n";
return true;
}
return false;
}
// Checks that the value `val` of type `llvm::Expected<T>` is not in
// an error state.
#define ASSERT_EXPECTED_SUCCESS(val) \
do { \
if (!assert_expected_success(val)) { \
GTEST_FATAL_FAILURE_("Expected<T> in error state") \
<< llvm::toString(val.takeError()); \
} \
} while (0)
// Checks that the value `val` of type `llvm::Expected<T>` is in
// an error state.
#define ASSERT_EXPECTED_FAILURE(val) \
do { \
if (!assert_expected_failure(val)) \
GTEST_FATAL_FAILURE_("Expected<T> not in error state"); \
} while (0)
// Checks that the value `val` is not in an error state and is equal
// to the value given in `exp`. Returns `true` if the test passes,
// otherwise `false`.
template <typename T, typename V>
static bool assert_expected_value(llvm::Expected<T> &val, const V &exp) {
if (!assert_expected_success(val))
return false;
if (!(val.get() == static_cast<T>(exp))) {
llvm::errs() << "Expected value " << exp << ", but got " << val.get()
<< "\n";
return false;
}
return true;
}
// Checks that the value `val` is not in an error state and is equal
// to the value given in `exp`. Returns `true` if the test passes,
// otherwise `false`.
template <typename T, typename V>
static bool assert_expected_value(llvm::Expected<T> &&val, const V &exp) {
return assert_expected_value(val, exp);
}
// Checks that the value `val` of type `llvm::Expected<T>` is not in
// an error state and is equal to the value of type `T` given in
// `exp`.
#define ASSERT_EXPECTED_VALUE(val, exp) \
do { \
if (!assert_expected_value(val, exp)) { \
GTEST_FATAL_FAILURE_("Expected<T> with wrong value") \
<< llvm::toString(val.takeError()); \
} \
} while (0)
#define ASSERT_EQ_OUTCOME(val, exp) \
if (!val.has_value()) { \
std::string msg = "ERROR: <" + val.error().mesg + "> \n"; \
GTEST_FATAL_FAILURE_(msg.c_str()); \
}; \
ASSERT_EQ(val.value(), exp);
#define ASSERT_ASSIGN_OUTCOME_VALUE(ident, val) \
auto ident__ = val; \
if (!ident__.has_value()) { \
std::string msg = "Outcome failure " + ident__.error().mesg; \
GTEST_FATAL_FAILURE_(msg.c_str()); \
} \
auto ident = std::move(ident__.value());
#define ASSERT_OUTCOME_HAS_VALUE(val) \
{ \
auto tmp = val; \
if (!tmp.has_value()) { \
std::string msg = "Outcome failure " + tmp.error().mesg; \
GTEST_FATAL_FAILURE_(msg.c_str()); \
} \
}
#define ASSERT_OUTCOME_HAS_FAILURE(val) \
{ \
auto tmp = val; \
if (tmp.has_value()) { \
GTEST_FATAL_FAILURE_("Outcome value when failure expected"); \
} \
}
#endif