Skip to content

Commit 63d5736

Browse files
akokoshnakokoshn
authored andcommitted
Add tests
1 parent 23e3483 commit 63d5736

23 files changed

Lines changed: 314 additions & 0 deletions

File tree

tests/cpp/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,5 +215,16 @@ add_zkllvm_unit_test("algebra/de_composition/decomposition/lsb")
215215
#multi provers tests
216216
add_zkllvm_unit_test("multi_provers/shift_add")
217217

218+
#customer's tests
219+
add_zkllvm_unit_test("custom_cases/getelementptr_as_constant/getelementptr_as_constant")
220+
221+
#libc functions
222+
add_zkllvm_unit_test("libc/memset/memset")
223+
add_zkllvm_unit_test("libc/strlen/strlen")
224+
add_zkllvm_unit_test("libc/strcmp/strcmp")
225+
add_zkllvm_unit_test("libc/strncmp/strncmp")
226+
add_zkllvm_unit_test("libc/strcpy/strcpy")
227+
add_zkllvm_unit_test("libc/strncpy/strncpy")
228+
218229
add_dependencies(all_for_test_run all_circuit_tests)
219230
add_dependencies(all_for_test_run all_expected_res_tests)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#ifndef __ZKLLVM__
2+
#include "../../read_boost_json.hpp"
3+
#include <cstdint>
4+
#include <fstream>
5+
#endif
6+
7+
#include <nil/crypto3/algebra/curves/pallas.hpp>
8+
9+
struct lumpinfo_s
10+
{
11+
lumpinfo_s * next;
12+
lumpinfo_s * prev;
13+
int data1;
14+
};
15+
16+
lumpinfo_s first;
17+
18+
[[circuit]] int list_demo(int unused) {
19+
20+
first.next = first.prev = &first;
21+
22+
#ifndef __ZKLLVM__
23+
std::cout << 0 <<std::endl;
24+
#endif
25+
26+
return 0;
27+
}
28+
29+
#ifndef __ZKLLVM__
30+
31+
int main (int argc, char *argv[]){
32+
if (argc != 2) {
33+
std::cerr << "one command line argument must be provided\n";
34+
std::abort();
35+
}
36+
37+
boost::json::value input_json = read_boost_json(std::string(argv[1]));
38+
39+
int a = read_uint<int>(input_json, 0);
40+
41+
list_demo(a);
42+
return 0;
43+
}
44+
#endif

tests/cpp/libc/memset/memset.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#ifndef __ZKLLVM__
2+
#include "../../read_boost_json.hpp"
3+
#include <cstdint>
4+
#include <fstream>
5+
#endif
6+
7+
#include <nil/crypto3/algebra/curves/pallas.hpp>
8+
9+
[[circuit]] uint32_t test_func(char *buf) {
10+
uint32_t out = 0;
11+
memset((void*)buf, 5, 2);
12+
out = buf[0] + buf[1];
13+
14+
#ifndef __ZKLLVM__
15+
std::cout << out <<std::endl;
16+
#endif
17+
18+
return out;
19+
}
20+
21+
#ifndef __ZKLLVM__
22+
23+
int main (int argc, char *argv[]){
24+
if (argc != 2) {
25+
std::cerr << "one command line argument must be provided\n";
26+
std::abort();
27+
}
28+
29+
boost::json::value input_json = read_boost_json(std::string(argv[1]));
30+
31+
std::string s = read_string(input_json, 0);
32+
33+
char* buf = new char[s.size()];
34+
strcpy(buf, s.c_str());
35+
36+
test_func(buf);
37+
38+
delete[] buf;
39+
return 0;
40+
}
41+
#endif

tests/cpp/libc/strcmp/strcmp.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#ifndef __ZKLLVM__
2+
#include "../../read_boost_json.hpp"
3+
#include <cstdint>
4+
#include <fstream>
5+
#endif
6+
7+
#include <nil/crypto3/algebra/curves/pallas.hpp>
8+
9+
[[circuit]] int test_func(const char *s1, const char *s2) {
10+
int out = strcmp(s1, s2);
11+
12+
#ifndef __ZKLLVM__
13+
std::cout << out <<std::endl;
14+
#endif
15+
16+
return out;
17+
}
18+
19+
#ifndef __ZKLLVM__
20+
21+
int main (int argc, char *argv[]){
22+
if (argc != 2) {
23+
std::cerr << "one command line argument must be provided\n";
24+
std::abort();
25+
}
26+
27+
boost::json::value input_json = read_boost_json(std::string(argv[1]));
28+
29+
std::string s1 = read_string(input_json, 0);
30+
std::string s2 = read_string(input_json, 1);
31+
32+
test_func(s1.c_str(), s2.c_str());
33+
34+
return 0;
35+
}
36+
#endif

tests/cpp/libc/strcpy/strcpy.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef __ZKLLVM__
2+
#include "../../read_boost_json.hpp"
3+
#include <cstdint>
4+
#include <fstream>
5+
#endif
6+
7+
#include <nil/crypto3/algebra/curves/pallas.hpp>
8+
9+
[[circuit]] uint32_t test_func(char *dst, const char *src) {
10+
uint32_t out = 0;
11+
char* ch = strcpy(dst, src);
12+
out = ch[0] + ch[1];
13+
14+
#ifndef __ZKLLVM__
15+
std::cout << out <<std::endl;
16+
#endif
17+
18+
return out;
19+
}
20+
21+
#ifndef __ZKLLVM__
22+
23+
int main (int argc, char *argv[]){
24+
if (argc != 2) {
25+
std::cerr << "one command line argument must be provided\n";
26+
std::abort();
27+
}
28+
29+
boost::json::value input_json = read_boost_json(std::string(argv[1]));
30+
31+
std::string s = read_string(input_json, 0);
32+
33+
char* buf = new char[s.size()];
34+
35+
test_func(buf, s.c_str());
36+
37+
delete[] buf;
38+
return 0;
39+
}
40+
#endif

tests/cpp/libc/strlen/strlen.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#ifndef __ZKLLVM__
2+
#include "../../read_boost_json.hpp"
3+
#include <cstdint>
4+
#include <fstream>
5+
#endif
6+
7+
#include <nil/crypto3/algebra/curves/pallas.hpp>
8+
9+
[[circuit]] uint32_t test_func(const char *buf) {
10+
uint32_t out = 0;
11+
out = strlen(buf);
12+
13+
#ifndef __ZKLLVM__
14+
std::cout << out <<std::endl;
15+
#endif
16+
17+
return out;
18+
}
19+
20+
#ifndef __ZKLLVM__
21+
22+
int main (int argc, char *argv[]){
23+
if (argc != 2) {
24+
std::cerr << "one command line argument must be provided\n";
25+
std::abort();
26+
}
27+
28+
boost::json::value input_json = read_boost_json(std::string(argv[1]));
29+
30+
std::string s = read_string(input_json, 0);
31+
32+
test_func(s.c_str());
33+
34+
return 0;
35+
}
36+
#endif

tests/cpp/libc/strncmp/strncmp.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef __ZKLLVM__
2+
#include "../../read_boost_json.hpp"
3+
#include <cstdint>
4+
#include <fstream>
5+
#endif
6+
7+
#include <nil/crypto3/algebra/curves/pallas.hpp>
8+
9+
[[circuit]] int test_func(const char *s1, const char *s2, uint32_t n) {
10+
int out = strncmp(s1, s2, n);
11+
12+
#ifndef __ZKLLVM__
13+
std::cout << out <<std::endl;
14+
#endif
15+
16+
return out;
17+
}
18+
19+
#ifndef __ZKLLVM__
20+
21+
int main (int argc, char *argv[]){
22+
if (argc != 2) {
23+
std::cerr << "one command line argument must be provided\n";
24+
std::abort();
25+
}
26+
27+
boost::json::value input_json = read_boost_json(std::string(argv[1]));
28+
29+
std::string s1 = read_string(input_json, 0);
30+
std::string s2 = read_string(input_json, 1);
31+
uint32_t n = read_uint<uint32_t>(input_json, 2);
32+
33+
34+
test_func(s1.c_str(), s2.c_str(), n);
35+
36+
return 0;
37+
}
38+
#endif

tests/cpp/libc/strncpy/strncpy.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef __ZKLLVM__
2+
#include "../../read_boost_json.hpp"
3+
#include <cstdint>
4+
#include <fstream>
5+
#endif
6+
7+
#include <nil/crypto3/algebra/curves/pallas.hpp>
8+
9+
[[circuit]] uint32_t test_func(char *dst, const char *src, uint32_t n) {
10+
uint32_t out = 0;
11+
char* ch = strncpy(dst, src, n);
12+
out = ch[0] + ch[1];
13+
14+
#ifndef __ZKLLVM__
15+
std::cout << out <<std::endl;
16+
#endif
17+
18+
return out;
19+
}
20+
21+
#ifndef __ZKLLVM__
22+
23+
int main (int argc, char *argv[]){
24+
if (argc != 2) {
25+
std::cerr << "one command line argument must be provided\n";
26+
std::abort();
27+
}
28+
29+
boost::json::value input_json = read_boost_json(std::string(argv[1]));
30+
31+
std::string s = read_string(input_json, 0);
32+
uint32_t n = read_uint<uint32_t>(input_json, 2);
33+
34+
char* buf = new char[s.size()];
35+
memset((void*)buf, 0, s.size());
36+
37+
test_func(buf, s.c_str(), n);
38+
39+
delete[] buf;
40+
return 0;
41+
}
42+
#endif

tests/cpp/read_boost_json.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,16 @@ PointType read_curve(boost::json::value& input_json_value, std::size_t position)
168168
}
169169
}
170170
return res;
171+
}
172+
173+
std::string read_string(boost::json::value& input_json_value, std::size_t position) {
174+
175+
const boost::json::object &current_value = input_json_value.as_array()[position].as_object();
176+
if(!current_value.contains("string"))
177+
assert(false && "json value must contain \"string\"");
178+
if (current_value.at("string").is_string()) {
179+
assert(false && "value is not string.");
180+
}
181+
182+
return current_value.at("string").as_string().c_str();
171183
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[ {"string": "abc"}, {"string": "abx"}]

0 commit comments

Comments
 (0)