### Install libfqfft library Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/libfqfft/README.md Install the libfqfft library. Headers are installed to /install/path/include if -DCMAKE_INSTALL_PREFIX is specified; otherwise, they go to the default location. ```bash make install ``` -------------------------------- ### Install benchmark library globally Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/benchmark/README.md Command to install the built library system-wide. Remember to link against pthread when building your own benchmarks. ```bash sudo make install ``` -------------------------------- ### Compile and install libff Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/libff/README.md Compile and install the library from the build directory. ```bash make make install ``` -------------------------------- ### Install git and cmake on Ubuntu/Debian Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/benchmark/README.md Commands to install git and cmake, prerequisites for building the benchmark library. ```bash sudo apt-get install git sudo apt-get install cmake ``` -------------------------------- ### Setup Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/ate-pairing/java/java.md Load the native library and initialize the BN254 system before using any other classes. ```APIDOC ## Setup ### Description Load the native library and initialize the BN254 system before using any other classes. ### Usage ```java System.loadLibrary("bn254_if_wrap"); BN254.SystemInit(); ``` ``` -------------------------------- ### compare.py example output Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/benchmark/docs/tools.md Example output from running compare.py with two benchmark binaries and filters. The Time and CPU columns in the comparison table are calculated as (new - old) / |old|. ```text $ ./compare.py benchmarksfiltered ./a.out BM_memcpy ./a.out BM_copy RUNNING: ./a.out --benchmark_filter=BM_memcpy --benchmark_out=/tmp/tmp_FvbYg Run on (8 X 4000 MHz CPU s) 2017-11-07 21:38:27 ------------------------------------------------------ Benchmark Time CPU Iterations ------------------------------------------------------ BM_memcpy/8 37 ns 37 ns 18953482 204.118MB/s BM_memcpy/64 74 ns 74 ns 9206578 828.245MB/s BM_memcpy/512 91 ns 91 ns 8086195 5.25476GB/s BM_memcpy/1024 120 ns 120 ns 5804513 7.95662GB/s BM_memcpy/8192 664 ns 664 ns 1028363 11.4948GB/s RUNNING: ./a.out --benchmark_filter=BM_copy --benchmark_out=/tmp/tmpDfL5iE Run on (8 X 4000 MHz CPU s) 2017-11-07 21:38:32 ---------------------------------------------------- Benchmark Time CPU Iterations ---------------------------------------------------- BM_copy/8 230 ns 230 ns 2985909 33.1161MB/s BM_copy/64 1654 ns 1653 ns 419408 36.9137MB/s BM_copy/512 13122 ns 13120 ns 53403 37.2156MB/s BM_copy/1024 26679 ns 26666 ns 26575 36.6218MB/s BM_copy/8192 215068 ns 215053 ns 3221 36.3283MB/s Comparing BM_memcpy (from ./a.out) to BM_copy (from ./a.out) Benchmark Time CPU Time Old Time New CPU Old CPU New -------------------------------------------------------------------------------------------------------------------- [BM_memcpy vs. BM_copy]/8 +5.1649 +5.1637 37 230 37 230 [BM_memcpy vs. BM_copy]/64 +21.4352 +21.4374 74 1654 74 1653 [BM_memcpy vs. BM_copy]/512 +143.6022 +143.5865 91 13122 91 13120 [BM_memcpy vs. BM_copy]/1024 +221.5903 +221.4790 120 26679 120 26666 [BM_memcpy vs. BM_copy]/8192 +322.9059 +323.0096 664 215068 664 215053 ``` -------------------------------- ### Setup: load library and initialize system Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/ate-pairing/java/java.md Call these functions first to load the native library and initialize the BN254 system. ```java > System.loadLibrary("bn254_if_wrap"); > BN254.SystemInit(); ``` -------------------------------- ### Run Docker container for Ligero proofs Source: https://github.com/hicolasnuber/pqkryvos/blob/main/ARTIFACT-APPENDIX.md Starts the pq-kryvos-container with a volume mount to the directory containing the circuit files. ```bash $ docker run --rm -it -v PATH/:/app/precompiled_circuits pq-kryvos-container ``` -------------------------------- ### Install dependencies on Ubuntu 14.04 LTS Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/libfqfft/README.md Install the required dependencies on Ubuntu 14.04 LTS. This command installs build tools, Git, Boost, CMake, GMP, OpenSSL, libprocps, pkg-config, and gnuplot. ```bash sudo apt-get install build-essential git libboost-all-dev cmake libgmp3-dev libssl-dev libprocps3-dev pkg-config gnuplot-x11 ``` -------------------------------- ### Start the profiler Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/libfqfft/README.md Runs the profiler from the project root directory. ```bash ./profiling_menu ``` -------------------------------- ### Basic Google Mock test example with MockTurtle and Painter Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/docs/ForDummies.md This example demonstrates the typical workflow: importing Google Mock names, creating a mock object, setting expectations with EXPECT_CALL, exercising code, and automatic verification. It also shows the required initialization in main. ```cpp #include "path/to/mock-turtle.h" #include "gmock/gmock.h" #include "gtest/gtest.h" using ::testing::AtLeast; // #1 TEST(PainterTest, CanDrawSomething) { MockTurtle turtle; // #2 EXPECT_CALL(turtle, PenDown()) // #3 .Times(AtLeast(1)); Painter painter(&turtle); // #4 EXPECT_TRUE(painter.DrawCircle(0, 0, 10)); } // #5 int main(int argc, char** argv) { // The following line must be executed to initialize Google Mock // (and Google Test) before running the tests. ::testing::InitGoogleMock(&argc, argv); return RUN_ALL_TESTS(); } ``` -------------------------------- ### Example output of compare.py comparing two benchmarks Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/benchmark/docs/tools.md Example output from running compare.py with two benchmark executables. It shows the benchmark runs and the comparison table with relative differences in Time and CPU columns. ```text $ ./compare.py benchmarks ./a.out ./a.out RUNNING: ./a.out --benchmark_out=/tmp/tmprBT5nW Run on (8 X 4000 MHz CPU s) 2017-11-07 21:16:44 ------------------------------------------------------ Benchmark Time CPU Iterations ------------------------------------------------------ BM_memcpy/8 36 ns 36 ns 19101577 211.669MB/s BM_memcpy/64 76 ns 76 ns 9412571 800.199MB/s BM_memcpy/512 84 ns 84 ns 8249070 5.64771GB/s BM_memcpy/1024 116 ns 116 ns 6181763 8.19505GB/s BM_memcpy/8192 643 ns 643 ns 1062855 11.8636GB/s BM_copy/8 222 ns 222 ns 3137987 34.3772MB/s BM_copy/64 1608 ns 1608 ns 432758 37.9501MB/s BM_copy/512 12589 ns 12589 ns 54806 38.7867MB/s BM_copy/1024 25169 ns 25169 ns 27713 38.8003MB/s BM_copy/8192 201165 ns 201112 ns 3486 38.8466MB/s RUNNING: ./a.out --benchmark_out=/tmp/tmpt1wwG_ Run on (8 X 4000 MHz CPU s) 2017-11-07 21:16:53 ------------------------------------------------------ Benchmark Time CPU Iterations ------------------------------------------------------ BM_memcpy/8 36 ns 36 ns 19397903 211.255MB/s BM_memcpy/64 73 ns 73 ns 9691174 839.635MB/s BM_memcpy/512 85 ns 85 ns 8312329 5.60101GB/s BM_memcpy/1024 118 ns 118 ns 6438774 8.11608GB/s BM_memcpy/8192 656 ns 656 ns 1068644 11.6277GB/s BM_copy/8 223 ns 223 ns 3146977 34.2338MB/s BM_copy/64 1611 ns 1611 ns 435340 37.8751MB/s BM_copy/512 12622 ns 12622 ns 54818 38.6844MB/s BM_copy/1024 25257 ns 25257 ns 27779 38.6927MB/s BM_copy/8192 205013 ns 205010 ns 3479 38.108MB/s Comparing ./a.out to ./a.out Benchmark Time CPU Time Old Time New CPU Old CPU New ------------------------------------------------------------------------------------------------------ BM_memcpy/8 +0.0020 +0.0020 36 36 36 36 BM_memcpy/64 -0.0468 -0.0470 76 73 76 73 BM_memcpy/512 +0.0081 +0.0083 84 85 84 85 BM_memcpy/1024 +0.0098 +0.0097 116 118 116 118 BM_memcpy/8192 +0.0200 +0.0203 643 656 643 656 BM_copy/8 +0.0046 +0.0042 222 223 222 223 BM_copy/64 +0.0020 +0.0020 1608 1611 1608 1611 BM_copy/512 +0.0027 +0.0026 12589 12622 12589 12622 BM_copy/1024 +0.0035 +0.0028 25169 25257 25169 25239 BM_copy/8192 +0.0191 +0.0194 201165 205013 201112 205010 ``` -------------------------------- ### Per-test-case set-up and tear-down example Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googletest/docs/AdvancedGuide.md Example of sharing resources between tests in the same test case. Define static member variables for shared resources, and static SetUpTestCase/TearDownTestCase methods to set up and tear down those resources. Google Test calls SetUpTestCase before the first test and TearDownTestCase after the last test. Tests must not depend on order and must restore shared resource state if modified. ```cpp class FooTest : public ::testing::Test { protected: // Per-test-case set-up. // Called before the first test in this test case. // Can be omitted if not needed. static void SetUpTestCase() { shared_resource_ = new ...; } // Per-test-case tear-down. // Called after the last test in this test case. // Can be omitted if not needed. static void TearDownTestCase() { delete shared_resource_; shared_resource_ = NULL; } // You can define per-test set-up and tear-down logic as usual. virtual void SetUp() { ... } virtual void TearDown() { ... } // Some expensive resource shared by all tests. static T* shared_resource_; }; T* FooTest::shared_resource_ = NULL; TEST_F(FooTest, Test1) { ... you can refer to shared_resource here ... } TEST_F(FooTest, Test2) { ... you can refer to shared_resource here ... } ``` -------------------------------- ### JSON format example output Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/benchmark/README.md Example JSON output with two top-level attributes: context (run information) and benchmarks (list of benchmark runs). ```json { "context": { "date": "2015/03/17-18:40:25", "num_cpus": 40, "mhz_per_cpu": 2801, "cpu_scaling_enabled": false, "build_type": "debug" }, "benchmarks": [ { "name": "BM_SetInsert/1024/1", "iterations": 94877, "real_time": 29275, "cpu_time": 29836, "bytes_per_second": 134066, "items_per_second": 33516 }, { "name": "BM_SetInsert/1024/8", "iterations": 21609, "real_time": 32317, "cpu_time": 32429, "bytes_per_second": 986770, "items_per_second": 246693 }, { "name": "BM_SetInsert/1024/10", "iterations": 21393, "real_time": 32724, "cpu_time": 33355, "bytes_per_second": 1199226, "items_per_second": 299807 } ] } ``` -------------------------------- ### Multithreaded benchmark with setup and teardown Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/benchmark/README.md Shows a multithreaded benchmark that uses thread_index to wrap global setup and teardown, ensuring they run only once. The benchmark is registered with Threads(2). ```c++ static void BM_MultiThreaded(benchmark::State& state) { if (state.thread_index == 0) { // Setup code here. } for (auto _ : state) { // Run the test as normal. } if (state.thread_index == 0) { // Teardown code here. } } BENCHMARK(BM_MultiThreaded)->Threads(2); ``` -------------------------------- ### Install dependencies on Ubuntu 14.04 LTS Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/libff/README.md Install required packages for building libff on Ubuntu 14.04 LTS using apt-get. ```bash sudo apt-get install build-essential git libboost-all-dev cmake libgmp3-dev libssl-dev libprocps3-dev pkg-config ``` -------------------------------- ### C++ usage example with mpz_class Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/ate-pairing/readme.md Example usage of the library: initialize parameters, create points, perform scalar multiplication with mpz_class (requires MIE_ATE_USE_GMP), and compute the optimal ate pairing. See sample2() in sample.cpp for more details. ```cpp using namespace bn; Param::init(); const Ec2 g2(...); const Ec1 g1(...); mpz_class a("123456789"); mpz_class b("98765432"); Ec1 g1a = g1 * a; Ec2 g2b = g2 * b; Fp12 e; opt_atePairing(e, g2b, g1a); ``` -------------------------------- ### Example: ACTION_P(Add, n) returns arg0 + n Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/docs/DesignDoc.md Defines an action 'Add' that takes a parameter 'n' and returns the sum of the first argument (arg0) and n. The example shows how to use it in a WillOnce call: WillOnce(Add(5)). ```cpp ACTION_P(Add, n) { return arg0 + n; } ``` ```cpp // Returns argument #0 + 5. ... WillOnce(Add(5)); ``` -------------------------------- ### Define Environment class with SetUp and TearDown Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googletest/docs/AdvancedGuide.md Subclass ::testing::Environment to define a test environment. Override SetUp() and TearDown() to set up and tear down the environment. The destructor is virtual. ```cpp class Environment { public: virtual ~Environment() {} // Override this to define how to set up the environment. virtual void SetUp() {} // Override this to define how to tear down the environment. virtual void TearDown() {} }; ``` -------------------------------- ### Run the pq-kryvos container Source: https://github.com/hicolasnuber/pqkryvos/blob/main/ARTIFACT-APPENDIX.md Starts the Docker container for the artifact. Run from the project's root directory. ```bash $ docker run --rm -it pq-kryvos-container ``` -------------------------------- ### Run container with precompiled circuits Source: https://github.com/hicolasnuber/pqkryvos/blob/main/README.md Runs the container with the precompiled circuits directory mounted. This is the recommended starting point. ```bash docker run --rm -it -v ./precompiled_circuits/:/app/precompiled_circuits pq-kryvos-container ``` -------------------------------- ### Using the wildcard matcher _ Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/docs/CookBook.md Shows the frequently used matcher _ which matches anything. The example expects DoThat with any first argument and a non-NULL second argument. ```cpp using ::testing::_; using ::testing::NotNull; ... EXPECT_CALL(foo, DoThat(_, NotNull())); ``` -------------------------------- ### Create and register fixture-based benchmarks Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/benchmark/README.md Demonstrates how to define a fixture class and use BENCHMARK_F, BENCHMARK_DEFINE_F, and BENCHMARK_REGISTER_F macros. The example shows that BarTest is not registered until BENCHMARK_REGISTER_F is called with Threads(2). ```c++ class MyFixture : public benchmark::Fixture {}; BENCHMARK_F(MyFixture, FooTest)(benchmark::State& st) { for (auto _ : st) { ... } } BENCHMARK_DEFINE_F(MyFixture, BarTest)(benchmark::State& st) { for (auto _ : st) { ... } } /* BarTest is NOT registered */ BENCHMARK_REGISTER_F(MyFixture, BarTest)->Threads(2); /* BarTest is now registered */ ``` -------------------------------- ### Install Google Mock Doctor alias Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/docs/FrequentlyAskedQuestions.md Run this command to set up an alias for the Google Mock Doctor tool, which scans gcc error messages and provides diagnoses. Replace '' with the actual path to your Google Mock installation. ```bash alias gmd='/scripts/gmock_doctor.py' ``` -------------------------------- ### Create templated fixture benchmarks Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/benchmark/README.md Shows how to define a templated fixture and use BENCHMARK_TEMPLATE_F and BENCHMARK_TEMPLATE_DEFINE_F macros. The example registers a DoubleTest with Threads(2) after defining it. ```c++ template class MyFixture : public benchmark::Fixture {}; BENCHMARK_TEMPLATE_F(MyFixture, IntTest, int)(benchmark::State& st) { for (auto _ : st) { ... } } BENCHMARK_TEMPLATE_DEFINE_F(MyFixture, DoubleTest, double)(benchmark::State& st) { for (auto _ : st) { ... } } BENCHMARK_REGISTER_F(MyFixture, DoubleTest)->Threads(2); ``` -------------------------------- ### Using user-allocated memory for JIT code Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/xbyak/readme.md Shows how to create JIT code on pre-allocated memory. It includes getting an aligned address, protecting the memory for execution, and constructing the code generator on that memory. ```cpp class Sample : public Xbyak::CodeGenerator { public: Sample(void *userPtr, size_t size) : Xbyak::CodeGenerator(size, userPtr) { ... } }; const size_t codeSize = 1024; uint8 buf[codeSize + 16]; // get 16-byte aligned address uint8 *p = Xbyak::CodeArray::getAlignedAddress(buf); // append executable attribute to the memory Xbyak::CodeArray::protect(p, codeSize, true); // construct your jit code on the memory Sample s(p, codeSize); ``` -------------------------------- ### View svn:externals property example Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googletest/docs/XcodeGuide.md Shows the output of 'svn propget svn:externals trunk' for a project, which checks out Google Test into the 'trunk/externals/src/googletest/' directory. ```bash [Computer:svn] user$ svn propget svn:externals trunk externals/src/googletest http://googletest.googlecode.com/svn/trunk ``` -------------------------------- ### MinimalistPrinter event listener example Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googletest/docs/AdvancedGuide.md Subclass testing::EmptyTestEventListener and override the virtual methods to handle test events. The example prints test start, test part result (failure or success), and test end messages. Use this as a template for custom event listeners. ```cpp class MinimalistPrinter : public ::testing::EmptyTestEventListener { // Called before a test starts. virtual void OnTestStart(const ::testing::TestInfo& test_info) { printf("*** Test %s.%s starting.\n", test_info.test_case_name(), test_info.name()); } // Called after a failed assertion or a SUCCEED() invocation. virtual void OnTestPartResult( const ::testing::TestPartResult& test_part_result) { printf("%s in %s:%d\n%s\n", test_part_result.failed() ? "*** Failure" : "Success", test_part_result.file_name(), test_part_result.line_number(), test_part_result.summary()); } // Called after a test ends. virtual void OnTestEnd(const ::testing::TestInfo& test_info) { printf("*** Test %s.%s ending.\n", test_info.test_case_name(), test_info.name()); } }; ``` -------------------------------- ### Mock function signature for ACTION example Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/docs/DesignDoc.md Shows the signature of a mock function used to illustrate the predefined symbols in an ACTION body. ```cpp int DoSomething(bool flag, int* ptr); ``` -------------------------------- ### Predicate Assertion Example with MutuallyPrime Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googletest/docs/AdvancedGuide.md Provides a boolean function and variables used with EXPECT_PRED2. The function MutuallyPrime returns true if m and n have no common divisors except 1. The example shows the setup for the assertion EXPECT_PRED2(MutuallyPrime, a, b) which succeeds, and EXPECT_PRED2(MutuallyPrime, b, c) which fails. ```cpp // Returns true iff m and n have no common divisors except 1. bool MutuallyPrime(int m, int n) { ... } const int a = 3; const int b = 4; const int c = 10; ``` -------------------------------- ### Run Sage script to generate curve parameters Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/libff/libff/algebra/curves/mnt/README.md Execute the SageMath script 'mnt.sage' to generate the MNT4/6 curve parameters. Requires SageMath to be installed. ```bash sage mnt.sage ``` -------------------------------- ### Manual adaptor to match mock signature Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/docs/CookBook.md Defines a manual adaptor MyIsVisibleInQuadrant1 with the same signature as Foo() that calls the custom action with the right arguments. This is the 'after' example that compiles and works, but is awkward compared to WithArgs. ```cpp using ::testing::_; using ::testing::Invoke; bool MyIsVisibleInQuadrant1(bool visible, const string& name, int x, int y, const map, double>& weight, double min_weight, double max_wight) { return IsVisibleInQuadrant1(visible, x, y); } ... EXPECT_CALL(mock, Foo(_, _, _, _, _, _, _)) .WillOnce(Invoke(MyIsVisibleInQuadrant1)); // Now it works. ``` -------------------------------- ### Attempting to Return Live Values with ByRef (Fails) Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/docs/CookBook.md This example shows an attempt to return a live value using ByRef(x) with Return. It fails because Return converts the value to the actual return type at action creation time, not execution time. The test expects 42 but gets 0. ```cpp using testing::ByRef; using testing::Return; class MockFoo : public Foo { public: MOCK_METHOD0(GetValue, int()); }; ... int x = 0; MockFoo foo; EXPECT_CALL(foo, GetValue()) .WillRepeatedly(Return(ByRef(x))); x = 42; EXPECT_EQ(42, foo.GetValue()); ``` ```cpp Value of: foo.GetValue() Actual: 0 Expected: 42 ``` -------------------------------- ### Field() and Property() usage examples in a table Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/docs/CookBook.md These expressions show how to use Field() and Property() with specific matchers. Field(&Foo::number, Ge(3)) matches x where x.number >= 3, and Property(&Foo::name, StartsWith("John ")) matches x where x.name() starts with "John ". ```cpp Field(&Foo::number, Ge(3)) ``` ```cpp Property(&Foo::name, StartsWith("John ")) ``` -------------------------------- ### Set default actions with ON_CALL and argument matchers Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/docs/CookBook.md Use ON_CALL to set default return values for a mock method based on argument matchers. The last matching ON_CALL takes precedence, allowing common behavior to be set in the constructor or fixture setup and specialized later. The example shows Sign returning -1, 0, or 1 depending on the argument. ```cpp using ::testing::_; using ::testing::AnyNumber; using ::testing::Gt; using ::testing::Return; ... ON_CALL(foo, Sign(_)) .WillByDefault(Return(-1)); ON_CALL(foo, Sign(0)) .WillByDefault(Return(0)); ON_CALL(foo, Sign(Gt(0))) .WillByDefault(Return(1)); EXPECT_CALL(foo, Sign(_)) .Times(AnyNumber()); foo.Sign(5); // This should return 1. foo.Sign(-9); // This should return -1. foo.Sign(0); // This should return 0. ``` -------------------------------- ### Compile tutorials with make tutorials Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/libfqfft/README.md Compiles the tutorial executables into the build/tutorials folder and runs them. ```bash make tutorials ``` -------------------------------- ### CMake: Use pkg-config to find gtest_main Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googletest/docs/Pkgconfig.md CMakeLists.txt example that uses pkg_search_module to find gtest_main and links it to a test executable. Recommended to use target_compile_options with _CFLAGS and _LDFLAGS instead of _INCLUDE_DIRS and _LIBRARIES. ```cmake cmake_minimum_required(VERSION 3.0) cmake_policy(SET CMP0048 NEW) project(my_gtest_pkgconfig VERSION 0.0.1 LANGUAGES CXX) find_package(PkgConfig) pkg_search_module(GTEST REQUIRED gtest_main) add_executable(testapp samples/sample3_unittest.cc) target_link_libraries(testapp ${GTEST_LDFLAGS}) target_compile_options(testapp PUBLIC ${GTEST_CFLAGS}) include(CTest) add_test(first_and_only_test testapp) ``` -------------------------------- ### SCOPED_TRACE example output Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googletest/docs/AdvancedGuide.md Example failure messages that include trace information from the SCOPED_TRACE example. Shows the trace point line and message. ```text path/to/foo_test.cc:11: Failure Value of: Bar(n) Expected: 1 Actual: 2 Trace: path/to/foo_test.cc:17: A path/to/foo_test.cc:12: Failure Value of: Bar(n + 1) Expected: 2 Actual: 3 ``` -------------------------------- ### Clone and build google/benchmark Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/benchmark/README.md Commands to clone the repository, create a build directory, configure with CMake, and build. ```bash git clone https://github.com/google/benchmark.git cd benchmark mkdir build cd build cmake .. -DCMAKE_BUILD_TYPE=RELEASE make ``` -------------------------------- ### Build and run sample1_unittest with make Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googletest/README.md Commands to build Google Test and run a sample test using the provided Makefile. If errors occur, tweak make/Makefile. ```bash cd ${GTEST_DIR}/make make ./sample1_unittest ``` -------------------------------- ### Instantiating an action template Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/docs/CookBook.md Shows how to create an instance of an action template with template arguments and value arguments. ```cpp ActionName(v1, ..., v_n) ``` -------------------------------- ### CSV format example output Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/benchmark/README.md Example CSV output. The context is output on stderr and the CSV itself on stdout. ```text name,iterations,real_time,cpu_time,bytes_per_second,items_per_second,label "BM_SetInsert/1024/1",65465,17890.7,8407.45,475768,118942, "BM_SetInsert/1024/8",116606,18810.1,9766.64,3.27646e+06,819115, "BM_SetInsert/1024/10",106365,17238.4,8421.53,4.74973e+06,1.18743e+06, ``` -------------------------------- ### Make: Build and run sample test Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/README.md Commands to build Google Mock using the provided Makefile and run the sample test. If errors occur, tweak make/Makefile. ```shell cd ${GMOCK_DIR}/make make ./gmock_test ``` -------------------------------- ### XML output for RecordProperty example Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googletest/docs/AdvancedGuide.md Example XML output produced by the test that calls RecordProperty. The recorded properties appear as attributes on the testcase element. ```xml ... ... ``` -------------------------------- ### MATCHER example: IsPositive Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/docs/DesignDoc.md Example matcher definition using MATCHER that returns true if the argument is greater than 0. Can be used as IsPositive() to match values greater than 0. ```cpp MATCHER(IsPositive) { return arg > 0; } ``` -------------------------------- ### Manual build: Compile and link test Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/README.md Compile a test source file with Google Mock includes and link with libgmock.a. ```shell g++ -isystem ${GTEST_DIR}/include -isystem ${GMOCK_DIR}/include \ -pthread path/to/your_test.cc libgmock.a -o your_test ``` -------------------------------- ### Create build directory and run cmake Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/libff/README.md Create the build directory and generate the Makefile using cmake. ```bash mkdir build && cd build cmake .. ``` -------------------------------- ### Windows: Clone dependencies and build with Visual Studio Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/ate-pairing/readme.md Commands to clone the required repositories (xbyak, ate-pairing, cybozulib-ext) and then open ate/ate.sln to compile test_bn in Release mode. The produced binary is ate/x64/Release/test_bn.exe. ```shell > git clone git://github.com/herumi/xbyak.git > git clone git://github.com/herumi/ate-pairing.git > git clone git://github.com/herumi/cybozulib-ext.git ; compiled binary of mpir ``` -------------------------------- ### Console format example output Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/benchmark/README.md Example tabular output from the console format, which is human-readable and outputs context to stderr and tabular data to stdout. By default, it generates color output. ```text Benchmark Time(ns) CPU(ns) Iterations ---------------------------------------------------------------------- BM_SetInsert/1024/1 28928 29349 23853 133.097kB/s 33.2742k items/s BM_SetInsert/1024/8 32065 32913 21375 949.487kB/s 237.372k items/s BM_SetInsert/1024/10 33157 33648 21431 1.13369MB/s 290.225k items/s ``` -------------------------------- ### DAG diagram for partial order example Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/docs/CookBook.md ASCII diagram showing the DAG specified by the Sequence example: A must occur before B and C, and C before D, with no restriction on B relative to C or D. ```text +---> B | A ---| | +---> C ---> D ``` -------------------------------- ### Manual build: Compile Google Mock library Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/README.md Compile gtest-all.cc and gmock-all.cc with system include paths and create libgmock.a. Requires -pthread because Google Test and Google Mock use threads. ```shell g++ -isystem ${GTEST_DIR}/include -I${GTEST_DIR} \ -isystem ${GMOCK_DIR}/include -I${GMOCK_DIR} \ -pthread -c ${GTEST_DIR}/src/gtest-all.cc g++ -isystem ${GTEST_DIR}/include -I${GTEST_DIR} \ -isystem ${GMOCK_DIR}/include -I${GMOCK_DIR} \ -pthread -c ${GMOCK_DIR}/src/gmock-all.cc ar -rv libgmock.a gtest-all.o gmock-all.o ``` -------------------------------- ### Example: ACTION_P2(ReturnDistanceTo, x, y) computes distance Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/docs/DesignDoc.md Defines a two-parameter action that computes the Euclidean distance between the point (arg0, arg1) and (x, y). The example shows usage with WillOnce(ReturnDistanceTo(5.0, 26.5)). ```cpp ACTION_P2(ReturnDistanceTo, x, y) { double dx = arg0 - x; double dy = arg1 - y; return sqrt(dx*dx + dy*dy); } ``` ```cpp ... WillOnce(ReturnDistanceTo(5.0, 26.5)); ``` -------------------------------- ### Cygwin: Build and run test/bn.exe Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/ate-pairing/readme.md Commands to set the PATH for mingw64, build with make, and run test/bn.exe. The executable uses mulx if possible; run with '-mulx 0' to disable it. ```shell PATH=/usr/x86_64-w64-mingw32/sys-root/mingw/bin/:$PATH make -j test/bn.exe ``` -------------------------------- ### Autotools: Prepare build system Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/README.md Run autoreconf to configure the Autotools build system for Google Mock on Unix. ```shell cd googlemock autoreconf -fvi ``` -------------------------------- ### Factorial Test Case Example Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googletest/docs/Primer.md Example test case for the Factorial function, showing two tests in the same test case 'FactorialTest'. Tests are grouped by test case, and the first argument to TEST() should be the same for logically-related tests. ```cpp // Tests factorial of 0. TEST(FactorialTest, HandlesZeroInput) { EXPECT_EQ(1, Factorial(0)); } // Tests factorial of positive numbers. TEST(FactorialTest, HandlesPositiveInput) { EXPECT_EQ(1, Factorial(1)); EXPECT_EQ(2, Factorial(2)); EXPECT_EQ(6, Factorial(3)); EXPECT_EQ(40320, Factorial(8)); } ``` -------------------------------- ### Example JSON report generated by gUnit Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googletest/docs/AdvancedGuide.md An example JSON report that could be generated from the preceding C++ test program. It shows the structure with testsuites, test cases, and failure messages. Note that the exact format is subject to change. ```json { "tests": 3, "failures": 1, "errors": 0, "time": "0.035s", "timestamp": "2011-10-31T18:52:42Z" "name": "AllTests", "testsuites": [ { "name": "MathTest", "tests": 2, "failures": 1, "errors": 0, "time": "0.015s", "testsuite": [ { "name": "Addition", "status": "RUN", "time": "0.007s", "classname": "", "failures": [ { "message": "Value of: add(1, 1)\x0A Actual: 3\x0AExpected: 2", "type": "" }, { "message": "Value of: add(1, -1)\x0A Actual: 1\x0AExpected: 0", "type": "" } ] }, { "name": "Subtraction", "status": "RUN", "time": "0.005s", "classname": "" } ] } { "name": "LogicTest", "tests": 1, "failures": 0, "errors": 0, "time": "0.005s", "testsuite": [ { "name": "NonContradiction", "status": "RUN", "time": "0.005s", "classname": "" } ] } ] } ``` -------------------------------- ### Build and execute tests Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/libff/README.md Run the test suite for the library. ```bash make check ``` -------------------------------- ### Configure Google Mock with Autotools Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/CONTRIBUTING.md Run this command from the build output directory to configure Google Mock. Use --help for more options. ```bash ${GMOCK_DIR}/configure # try --help for more info ``` -------------------------------- ### Custom EvenNumberCardinality example Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/docs/CookBook.md A complete example of a custom cardinality that is satisfied when the call count is even. It implements CardinalityInterface, provides a factory function EvenNumber(), and shows usage in EXPECT_CALL with Times(). The IsSaturatedByCallCount always returns false, meaning it never saturates. ```cpp using ::testing::Cardinality; using ::testing::CardinalityInterface; using ::testing::MakeCardinality; class EvenNumberCardinality : public CardinalityInterface { public: virtual bool IsSatisfiedByCallCount(int call_count) const { return (call_count % 2) == 0; } virtual bool IsSaturatedByCallCount(int call_count) const { return false; } virtual void DescribeTo(::std::ostream* os) const { *os << "called even number of times"; } }; Cardinality EvenNumber() { return MakeCardinality(new EvenNumberCardinality); } ... ``` ```cpp EXPECT_CALL(foo, Bar(3)) .Times(EvenNumber()); ``` -------------------------------- ### Running benchmarks with --benchmark_filter Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/benchmark/README.md Shows how to use the --benchmark_filter= option to run only benchmarks matching the specified regex. The example command runs benchmarks matching 'BM_memcpy/32' and displays the resulting output. ```bash $ ./run_benchmarks.x --benchmark_filter=BM_memcpy/32 Run on (1 X 2300 MHz CPU ) 2016-06-25 19:34:24 Benchmark Time CPU Iterations ---------------------------------------------------- BM_memcpy/32 11 ns 11 ns 79545455 BM_memcpy/32k 2181 ns 2185 ns 324074 BM_memcpy/32 12 ns 12 ns 54687500 BM_memcpy/32k 1834 ns 1837 ns 357143 ``` -------------------------------- ### Example XML report generated by Google Test Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googletest/docs/AdvancedGuide.md An example XML report generated by Google Test for the test program above. It shows the structure with testsuites, testsuite, testcase, and failure elements, including attributes like tests, failures, errors, time, and name. ```xml ``` -------------------------------- ### EXPECT_CALL example with turtle mock Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/docs/ForDummies.md An example of using EXPECT_CALL to set expectations on a turtle mock object's GetX method. It specifies that the method will be called five times, returning 100 the first time, 150 the second time, and 200 subsequently. ```cpp using ::testing::Return; ... EXPECT_CALL(turtle, GetX()) .Times(5) .WillOnce(Return(100)) .WillOnce(Return(150)) .WillRepeatedly(Return(200)); ``` -------------------------------- ### Build commands for Windows (make_wrap.bat) Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/ate-pairing/java/java.md Commands to build the Java wrapper on Windows. Requires setting SWIG and JAVA_DIR in the batch files. Produces bin/bn254_if_wrap.dll. ```batch > cd java > make_wrap.bat ``` -------------------------------- ### Invoke compare_bench.py with benchmark files Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/benchmark/docs/tools.md Shows the command-line syntax for compare_bench.py. The tool accepts either benchmark executables or JSON output files, automatically detecting the type. Options are passed to the benchmark invocation. ```bash $ compare_bench.py [benchmark options]... ``` -------------------------------- ### Ambiguous overload example Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/docs/CookBook.md Illustrates the ambiguity that arises when overloading on template parameters is allowed. ```cpp OverloadedAction(x); ``` -------------------------------- ### Failure messages for IsDivisibleBy7 Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/docs/CookBook.md Example output when the assertions fail, showing auto-generated descriptions. ```text Value of: some_expression Expected: is divisible by 7 Actual: 27 ... Value of: some_other_expression Expected: not (is divisible by 7) Actual: 21 ``` -------------------------------- ### Class with FRIEND_TEST in namespace Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googletest/docs/AdvancedGuide.md Example of a class defined in a namespace with friend test declarations. ```cpp namespace my_namespace { class Foo { friend class FooTest; FRIEND_TEST(FooTest, Bar); FRIEND_TEST(FooTest, Baz); ... definition of the class Foo ... }; } // namespace my_namespace ``` -------------------------------- ### Example: Using DuplicateArg in EXPECT_CALL Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/docs/CookBook.md Demonstrates using the DuplicateArg action template in a mock expectation. ```cpp using ::testing::_; ... int n; EXPECT_CALL(mock, Foo(_, _)) .WillOnce(DuplicateArg<1, unsigned char>(&n)); ``` -------------------------------- ### Build and configure Google Benchmark with CMake Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/benchmark/README.md Commands to clone the benchmark repository, add GTest as a subdirectory, configure with CMake, and build using make. Requires GTest as a dependency, which can be provided by cloning into benchmark/googletest, using -DBENCHMARK_DOWNLOAD_DEPENDENCIES=ON, or via find_package(GTest REQUIRED). ```bash $ git clone https://github.com/google/benchmark.git # Benchmark requires GTest as a dependency. Add the source tree as a subdirectory. $ git clone https://github.com/google/googletest.git benchmark/googletest $ mkdir build && cd build $ cmake -G [options] ../benchmark # Assuming a makefile generator was used $ make ``` -------------------------------- ### Improved failure message with result_listener Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/docs/CookBook.md Example output showing the additional information provided by result_listener. ```text Value of: some_expression Expected: is divisible by 7 Actual: 27 (the remainder is 6) ``` -------------------------------- ### Meson: Use dependency('gtest_main') Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googletest/docs/Pkgconfig.md Meson build file that declares a dependency on gtest_main and builds a test executable. Uses the native pkgconfig support. ```meson project('my_gtest_pkgconfig', 'cpp', version : '0.0.1') gtest_dep = dependency('gtest_main') testapp = executable( 'testapp', files(['samples/sample3_unittest.cc']), dependencies : gtest_dep, install : false) test('first_and_only_test', testapp) ``` -------------------------------- ### Factorial Function Declaration Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googletest/docs/Primer.md Declaration of a simple integer function used as an example for writing tests. ```cpp int Factorial(int n); // Returns the factorial of n ``` -------------------------------- ### Failure message example for EXPECT_THAT Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/docs/CookBook.md Shows the informative failure message generated when an EXPECT_THAT assertion fails. ```text Value of: Foo() Actual: "Hi, world!" Expected: starts with "Hello" ``` -------------------------------- ### Using Sticky Expectations to Allow Any Number of Calls Source: https://github.com/hicolasnuber/pqkryvos/blob/main/libiop/depends/gtest/googlemock/docs/ForDummies.md This example shows how to set up expectations that allow any number of calls to GoTo(_, _) while requiring exactly two calls to GoTo(0, 0). Because expectations are sticky, the second expectation remains active after its upper bound is reached, causing an error if a third matching call occurs. ```cpp using ::testing::_; ... EXPECT_CALL(turtle, GoTo(_, _)) // #1 .Times(AnyNumber()); EXPECT_CALL(turtle, GoTo(0, 0)) // #2 .Times(2); ``` -------------------------------- ### Build Docker image with amd64 emulation Source: https://github.com/hicolasnuber/pqkryvos/blob/main/ARTIFACT-APPENDIX.md Alternative command to build the Docker image using amd64 emulation, recommended for non-amd64 architectures such as Apple Silicon. ```bash $ docker build --platform linux/amd64 -t pq-kryvos-container . ```