diff --git a/tests/cpp/CMakeLists.txt b/tests/cpp/CMakeLists.txt index 59eda908..b29a9bd8 100644 --- a/tests/cpp/CMakeLists.txt +++ b/tests/cpp/CMakeLists.txt @@ -215,5 +215,16 @@ add_zkllvm_unit_test("algebra/de_composition/decomposition/lsb") #multi provers tests add_zkllvm_unit_test("multi_provers/shift_add") +#customer's tests +add_zkllvm_unit_test("custom_cases/getelementptr_as_constant/getelementptr_as_constant") + +#libc functions +add_zkllvm_unit_test("libc/memset/memset") +add_zkllvm_unit_test("libc/strlen/strlen") +add_zkllvm_unit_test("libc/strcmp/strcmp") +add_zkllvm_unit_test("libc/strncmp/strncmp") +add_zkllvm_unit_test("libc/strcpy/strcpy") +add_zkllvm_unit_test("libc/strncpy/strncpy") + add_dependencies(all_for_test_run all_circuit_tests) add_dependencies(all_for_test_run all_expected_res_tests) diff --git a/tests/cpp/custom_cases/getelementptr_as_constant/getelementptr_as_constant.cpp b/tests/cpp/custom_cases/getelementptr_as_constant/getelementptr_as_constant.cpp new file mode 100644 index 00000000..0d29c0b9 --- /dev/null +++ b/tests/cpp/custom_cases/getelementptr_as_constant/getelementptr_as_constant.cpp @@ -0,0 +1,44 @@ +#ifndef __ZKLLVM__ +#include "../../read_boost_json.hpp" +#include +#include +#endif + +#include + +struct lumpinfo_s +{ + lumpinfo_s * next; + lumpinfo_s * prev; + int data1; +}; + +lumpinfo_s first; + +[[circuit]] int list_demo(int unused) { + + first.next = first.prev = &first; + +#ifndef __ZKLLVM__ + std::cout << 0 <(input_json, 0); + + list_demo(a); + return 0; +} +#endif diff --git a/tests/cpp/libc/memset/memset.cpp b/tests/cpp/libc/memset/memset.cpp new file mode 100644 index 00000000..13a17a25 --- /dev/null +++ b/tests/cpp/libc/memset/memset.cpp @@ -0,0 +1,41 @@ +#ifndef __ZKLLVM__ +#include "../../read_boost_json.hpp" +#include +#include +#endif + +#include + +[[circuit]] uint32_t test_func(char *buf) { + uint32_t out = 0; + memset((void*)buf, 5, 2); + out = buf[0] + buf[1]; + +#ifndef __ZKLLVM__ + std::cout << out < +#include +#endif + +#include + +[[circuit]] int test_func(const char *s1, const char *s2) { + int out = strcmp(s1, s2); + +#ifndef __ZKLLVM__ + std::cout << out < +#include +#endif + +#include + +[[circuit]] uint32_t test_func(char *dst, const char *src) { + uint32_t out = 0; + char* ch = strcpy(dst, src); + out = ch[0] + ch[1]; + +#ifndef __ZKLLVM__ + std::cout << out < +#include +#endif + +#include + +[[circuit]] uint32_t test_func(const char *buf) { + uint32_t out = 0; + out = strlen(buf); + +#ifndef __ZKLLVM__ + std::cout << out < +#include +#endif + +#include + +[[circuit]] int test_func(const char *s1, const char *s2, uint32_t n) { + int out = strncmp(s1, s2, n); + +#ifndef __ZKLLVM__ + std::cout << out <(input_json, 2); + + + test_func(s1.c_str(), s2.c_str(), n); + + return 0; +} +#endif diff --git a/tests/cpp/libc/strncpy/strncpy.cpp b/tests/cpp/libc/strncpy/strncpy.cpp new file mode 100644 index 00000000..af857bd3 --- /dev/null +++ b/tests/cpp/libc/strncpy/strncpy.cpp @@ -0,0 +1,42 @@ +#ifndef __ZKLLVM__ +#include "../../read_boost_json.hpp" +#include +#include +#endif + +#include + +[[circuit]] uint32_t test_func(char *dst, const char *src, uint32_t n) { + uint32_t out = 0; + char* ch = strncpy(dst, src, n); + out = ch[0] + ch[1]; + +#ifndef __ZKLLVM__ + std::cout << out <(input_json, 2); + + char* buf = new char[s.size()]; + memset((void*)buf, 0, s.size()); + + test_func(buf, s.c_str(), n); + + delete[] buf; + return 0; +} +#endif \ No newline at end of file diff --git a/tests/cpp/read_boost_json.hpp b/tests/cpp/read_boost_json.hpp index bcfdbdd1..f8218e4d 100644 --- a/tests/cpp/read_boost_json.hpp +++ b/tests/cpp/read_boost_json.hpp @@ -168,4 +168,16 @@ PointType read_curve(boost::json::value& input_json_value, std::size_t position) } } return res; +} + +std::string read_string(boost::json::value& input_json_value, std::size_t position) { + + const boost::json::object ¤t_value = input_json_value.as_array()[position].as_object(); + if(!current_value.contains("string")) + assert(false && "json value must contain \"string\""); + if (current_value.at("string").is_string()) { + assert(false && "value is not string."); + } + + return current_value.at("string").as_string().c_str(); } \ No newline at end of file diff --git a/tests/disabled_inputs/libc/strcmp/0_1.inp b/tests/disabled_inputs/libc/strcmp/0_1.inp new file mode 100644 index 00000000..db520815 --- /dev/null +++ b/tests/disabled_inputs/libc/strcmp/0_1.inp @@ -0,0 +1 @@ +[ {"string": "abc"}, {"string": "abx"}] diff --git a/tests/disabled_inputs/libc/strncmp/0_1.inp b/tests/disabled_inputs/libc/strncmp/0_1.inp new file mode 100644 index 00000000..6f24fbf1 --- /dev/null +++ b/tests/disabled_inputs/libc/strncmp/0_1.inp @@ -0,0 +1 @@ +[ {"string": "abc"}, {"string": "abx"}, {"int": 3}] diff --git a/tests/inputs/custom_cases/getelementptr_as_constant/0_0.inp b/tests/inputs/custom_cases/getelementptr_as_constant/0_0.inp new file mode 100644 index 00000000..44d0c735 --- /dev/null +++ b/tests/inputs/custom_cases/getelementptr_as_constant/0_0.inp @@ -0,0 +1 @@ +[ {"int": 10}] diff --git a/tests/inputs/libc/memset/0_0.inp b/tests/inputs/libc/memset/0_0.inp new file mode 100644 index 00000000..c5a9f68a --- /dev/null +++ b/tests/inputs/libc/memset/0_0.inp @@ -0,0 +1 @@ +[ {"string": "ab"}] diff --git a/tests/inputs/libc/strcmp/0_0.inp b/tests/inputs/libc/strcmp/0_0.inp new file mode 100644 index 00000000..f1a6ffc3 --- /dev/null +++ b/tests/inputs/libc/strcmp/0_0.inp @@ -0,0 +1 @@ +[ {"string": "abc"}, {"string": "abc"}] diff --git a/tests/inputs/libc/strcmp/0_2.inp b/tests/inputs/libc/strcmp/0_2.inp new file mode 100644 index 00000000..cd69c7ab --- /dev/null +++ b/tests/inputs/libc/strcmp/0_2.inp @@ -0,0 +1 @@ +[ {"string": "abx"}, {"string": "abc"}] diff --git a/tests/inputs/libc/strcmp/0_3.inp b/tests/inputs/libc/strcmp/0_3.inp new file mode 100644 index 00000000..68c02a45 --- /dev/null +++ b/tests/inputs/libc/strcmp/0_3.inp @@ -0,0 +1 @@ +[ {"string": "abc"}, {"string": "ab"}] diff --git a/tests/inputs/libc/strcpy/0_0.inp b/tests/inputs/libc/strcpy/0_0.inp new file mode 100644 index 00000000..f1a6ffc3 --- /dev/null +++ b/tests/inputs/libc/strcpy/0_0.inp @@ -0,0 +1 @@ +[ {"string": "abc"}, {"string": "abc"}] diff --git a/tests/inputs/libc/strlen/0_0.inp b/tests/inputs/libc/strlen/0_0.inp new file mode 100644 index 00000000..56c46eb4 --- /dev/null +++ b/tests/inputs/libc/strlen/0_0.inp @@ -0,0 +1 @@ +[ {"string": "abc"}] diff --git a/tests/inputs/libc/strncmp/0_0.inp b/tests/inputs/libc/strncmp/0_0.inp new file mode 100644 index 00000000..187c41af --- /dev/null +++ b/tests/inputs/libc/strncmp/0_0.inp @@ -0,0 +1 @@ +[ {"string": "abc"}, {"string": "abc"}, {"int": 3}] diff --git a/tests/inputs/libc/strncmp/0_2.inp b/tests/inputs/libc/strncmp/0_2.inp new file mode 100644 index 00000000..fac3f9a8 --- /dev/null +++ b/tests/inputs/libc/strncmp/0_2.inp @@ -0,0 +1 @@ +[ {"string": "abx"}, {"string": "abc"}, {"int": 3}] diff --git a/tests/inputs/libc/strncmp/0_3.inp b/tests/inputs/libc/strncmp/0_3.inp new file mode 100644 index 00000000..6316bfaf --- /dev/null +++ b/tests/inputs/libc/strncmp/0_3.inp @@ -0,0 +1 @@ +[ {"string": "abc"}, {"string": "abx"}, {"int": 2}] diff --git a/tests/inputs/libc/strncpy/0_0.inp b/tests/inputs/libc/strncpy/0_0.inp new file mode 100644 index 00000000..f561b649 --- /dev/null +++ b/tests/inputs/libc/strncpy/0_0.inp @@ -0,0 +1 @@ +[ {"string": "ab"}, {"string": "ab"}, {"int": 3}] diff --git a/tests/inputs/libc/strncpy/0_1.inp b/tests/inputs/libc/strncpy/0_1.inp new file mode 100644 index 00000000..a50c80d4 --- /dev/null +++ b/tests/inputs/libc/strncpy/0_1.inp @@ -0,0 +1 @@ +[ {"string": "abc"}, {"string": "abc"}, {"int": 2}]