From 7c97f783935ec122fbf0d7d070c00804738abd6a Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 11 Sep 2017 01:27:46 +0300 Subject: klee: Start preparing for klee tests First stage: something compiling without klee, but with a buch of dirty hacks - done. Second stage: something running under klee, able to emit useful results, but still using dirty hacks - done. Third stage: make CMake care about clang argumnets - not done, may be omitted if proves to be too hard. Not that klee can be run on CI in any case. --- test/symbolic/klee/viml_expressions_parser.c | 102 +++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 test/symbolic/klee/viml_expressions_parser.c (limited to 'test/symbolic/klee/viml_expressions_parser.c') diff --git a/test/symbolic/klee/viml_expressions_parser.c b/test/symbolic/klee/viml_expressions_parser.c new file mode 100644 index 0000000000..2bad1adc53 --- /dev/null +++ b/test/symbolic/klee/viml_expressions_parser.c @@ -0,0 +1,102 @@ +#ifdef USE_KLEE +# error UNFINISHED +# include +#else +# include +#endif +#include +#include +#include + +#include "nvim/viml/parser/expressions.h" +#include "nvim/viml/parser/parser.h" +#include "nvim/mbyte.h" + +#include "nvim/memory.c" +#include "nvim/mbyte.c" +#include "nvim/charset.c" +#include "nvim/garray.c" +#include "nvim/gettext.c" +#include "nvim/viml/parser/expressions.c" + +#define INPUT_SIZE 50 + +uint8_t avoid_optimizing_out; + +void simple_get_line(void *cookie, ParserLine *ret_pline) +{ + ParserLine **plines_p = (ParserLine **)cookie; + *ret_pline = **plines_p; + (*plines_p)++; +} + +int main(const int argc, const char *const *const argv, + const char *const *const environ) +{ + char input[INPUT_SIZE]; + uint8_t shift; + int flags; + const bool peek = false; + avoid_optimizing_out = argc; + +#ifndef USE_KLEE + sscanf(argv[2], "%d", &flags); +#endif + +#ifdef USE_KLEE + klee_make_symbolic(input, sizeof(input), "input"); + klee_make_symbolic(&shift, sizeof(shift), "shift"); + klee_make_symbolic(&flags, sizeof{flags}, "flags"); + klee_assume(shift < INPUT_SIZE); + klee_assume( + flags <= kExprFlagsMulti|kExprFlagsDisallowEOC|kExprFlagsPrintError); +#endif + + ParserLine plines[] = { + { +#ifdef USE_KLEE + .data = &input[shift], + .size = sizeof(input) - shift, +#else + .data = argv[1], + .size = strlen(argv[1]), +#endif + .allocated = false, + }, + { + .data = NULL, + .size = 0, + .allocated = false, + }, + }; +#ifdef USE_KLEE + assert(plines[0].size <= INPUT_SIZE); + assert((plines[0].data[0] != 5) | (plines[0].data[0] != argc)); +#endif + ParserLine *cur_pline = &plines[0]; + + ParserState pstate = { + .reader = { + .get_line = simple_get_line, + .cookie = &cur_pline, + .lines = KV_INITIAL_VALUE, + .conv.vc_type = CONV_NONE, + }, + .pos = { 0, 0 }, + .colors = NULL, + .can_continuate = false, + }; + kvi_init(pstate.reader.lines); + + const ExprAST ast = viml_pexpr_parse(&pstate, flags); + assert(ast.root != NULL + || plines[0].size == 0); + assert(ast.root != NULL || !ast.correct); + assert(ast.correct + || (ast.err.msg != NULL + && ast.err.arg != NULL + && ast.err.arg >= plines[0].data + && ((size_t)(ast.err.arg - plines[0].data) + ast.err.arg_len + <= plines[0].size))); + // FIXME: free memory and assert no memory leaks +} -- cgit From 6168e1127c1c80a3810854649b0776146545043b Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 2 Oct 2017 02:41:55 +0300 Subject: viml/parser/expressions: Add support for comparison operators --- test/symbolic/klee/viml_expressions_parser.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'test/symbolic/klee/viml_expressions_parser.c') diff --git a/test/symbolic/klee/viml_expressions_parser.c b/test/symbolic/klee/viml_expressions_parser.c index 2bad1adc53..5ad592b99f 100644 --- a/test/symbolic/klee/viml_expressions_parser.c +++ b/test/symbolic/klee/viml_expressions_parser.c @@ -91,12 +91,6 @@ int main(const int argc, const char *const *const argv, const ExprAST ast = viml_pexpr_parse(&pstate, flags); assert(ast.root != NULL || plines[0].size == 0); - assert(ast.root != NULL || !ast.correct); - assert(ast.correct - || (ast.err.msg != NULL - && ast.err.arg != NULL - && ast.err.arg >= plines[0].data - && ((size_t)(ast.err.arg - plines[0].data) + ast.err.arg_len - <= plines[0].size))); + assert(ast.root != NULL || ast.err.msg); // FIXME: free memory and assert no memory leaks } -- cgit From af38cea133f5ebb67208cedd289e408cd1dad15a Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 8 Oct 2017 21:52:38 +0300 Subject: viml/parser/expressions: Add support for string parsing --- test/symbolic/klee/viml_expressions_parser.c | 1 + 1 file changed, 1 insertion(+) (limited to 'test/symbolic/klee/viml_expressions_parser.c') diff --git a/test/symbolic/klee/viml_expressions_parser.c b/test/symbolic/klee/viml_expressions_parser.c index 5ad592b99f..e1cea2d990 100644 --- a/test/symbolic/klee/viml_expressions_parser.c +++ b/test/symbolic/klee/viml_expressions_parser.c @@ -18,6 +18,7 @@ #include "nvim/garray.c" #include "nvim/gettext.c" #include "nvim/viml/parser/expressions.c" +#include "nvim/keymap.c" #define INPUT_SIZE 50 -- cgit From 8178ba2871bb427e03419a2f68c0fb119e44e717 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 14 Oct 2017 00:26:52 +0300 Subject: klee: Fix some errors made in …parser.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/symbolic/klee/viml_expressions_parser.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/symbolic/klee/viml_expressions_parser.c') diff --git a/test/symbolic/klee/viml_expressions_parser.c b/test/symbolic/klee/viml_expressions_parser.c index e1cea2d990..a4fbdb6bf4 100644 --- a/test/symbolic/klee/viml_expressions_parser.c +++ b/test/symbolic/klee/viml_expressions_parser.c @@ -1,5 +1,4 @@ #ifdef USE_KLEE -# error UNFINISHED # include #else # include @@ -47,10 +46,10 @@ int main(const int argc, const char *const *const argv, #ifdef USE_KLEE klee_make_symbolic(input, sizeof(input), "input"); klee_make_symbolic(&shift, sizeof(shift), "shift"); - klee_make_symbolic(&flags, sizeof{flags}, "flags"); + klee_make_symbolic(&flags, sizeof(flags), "flags"); klee_assume(shift < INPUT_SIZE); klee_assume( - flags <= kExprFlagsMulti|kExprFlagsDisallowEOC|kExprFlagsPrintError); + flags <= (kExprFlagsMulti|kExprFlagsDisallowEOC|kExprFlagsPrintError)); #endif ParserLine plines[] = { @@ -93,5 +92,6 @@ int main(const int argc, const char *const *const argv, assert(ast.root != NULL || plines[0].size == 0); assert(ast.root != NULL || ast.err.msg); + // FIXME: check for AST recursiveness // FIXME: free memory and assert no memory leaks } -- cgit From 6c19cbef2611c389da6f3e06d8c8eb635d065774 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 15 Oct 2017 20:05:35 +0300 Subject: viml/parser/expressions,tests: Add AST freeing, with sanity checks --- test/symbolic/klee/viml_expressions_parser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/symbolic/klee/viml_expressions_parser.c') diff --git a/test/symbolic/klee/viml_expressions_parser.c b/test/symbolic/klee/viml_expressions_parser.c index a4fbdb6bf4..c0cedceb21 100644 --- a/test/symbolic/klee/viml_expressions_parser.c +++ b/test/symbolic/klee/viml_expressions_parser.c @@ -92,6 +92,6 @@ int main(const int argc, const char *const *const argv, assert(ast.root != NULL || plines[0].size == 0); assert(ast.root != NULL || ast.err.msg); - // FIXME: check for AST recursiveness - // FIXME: free memory and assert no memory leaks + viml_pexpr_free_ast(ast); + assert(allocated_memory == 0); } -- cgit From 3aa2c0d63ae488e302a89fdcdd650404cb2670fd Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 15 Oct 2017 21:11:00 +0300 Subject: viml/parser/expressions,klee: Fix some problems found by KLEE run --- test/symbolic/klee/viml_expressions_parser.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'test/symbolic/klee/viml_expressions_parser.c') diff --git a/test/symbolic/klee/viml_expressions_parser.c b/test/symbolic/klee/viml_expressions_parser.c index c0cedceb21..ed280adb22 100644 --- a/test/symbolic/klee/viml_expressions_parser.c +++ b/test/symbolic/klee/viml_expressions_parser.c @@ -89,8 +89,6 @@ int main(const int argc, const char *const *const argv, kvi_init(pstate.reader.lines); const ExprAST ast = viml_pexpr_parse(&pstate, flags); - assert(ast.root != NULL - || plines[0].size == 0); assert(ast.root != NULL || ast.err.msg); viml_pexpr_free_ast(ast); assert(allocated_memory == 0); -- cgit From ed253b5fe6515840fe6dd9df83855a0316de8bad Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 16 Oct 2017 00:39:48 +0300 Subject: klee: Include colors in test --- test/symbolic/klee/viml_expressions_parser.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'test/symbolic/klee/viml_expressions_parser.c') diff --git a/test/symbolic/klee/viml_expressions_parser.c b/test/symbolic/klee/viml_expressions_parser.c index ed280adb22..8f015ae9a7 100644 --- a/test/symbolic/klee/viml_expressions_parser.c +++ b/test/symbolic/klee/viml_expressions_parser.c @@ -75,6 +75,9 @@ int main(const int argc, const char *const *const argv, #endif ParserLine *cur_pline = &plines[0]; + ParserHighlight colors; + kvi_init(colors); + ParserState pstate = { .reader = { .get_line = simple_get_line, @@ -83,13 +86,18 @@ int main(const int argc, const char *const *const argv, .conv.vc_type = CONV_NONE, }, .pos = { 0, 0 }, - .colors = NULL, + .colors = &colors, .can_continuate = false, }; kvi_init(pstate.reader.lines); const ExprAST ast = viml_pexpr_parse(&pstate, flags); assert(ast.root != NULL || ast.err.msg); + // Can’t possibly have more highlight tokens then there are bytes in string. + assert(kv_size(colors) <= INPUT_SIZE - shift); + kvi_destroy(colors); + // Not destroying pstate.reader.lines because there is no way it could exceed + // its limits in the current circumstances. viml_pexpr_free_ast(ast); assert(allocated_memory == 0); } -- cgit From c9f511d24a64da135bef4b9874c7bec04d9330e4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 16 Oct 2017 09:06:05 +0300 Subject: viml/parser/expressions: Remove unused flag --- test/symbolic/klee/viml_expressions_parser.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'test/symbolic/klee/viml_expressions_parser.c') diff --git a/test/symbolic/klee/viml_expressions_parser.c b/test/symbolic/klee/viml_expressions_parser.c index 8f015ae9a7..9448937430 100644 --- a/test/symbolic/klee/viml_expressions_parser.c +++ b/test/symbolic/klee/viml_expressions_parser.c @@ -35,7 +35,7 @@ int main(const int argc, const char *const *const argv, { char input[INPUT_SIZE]; uint8_t shift; - int flags; + unsigned flags; const bool peek = false; avoid_optimizing_out = argc; @@ -48,8 +48,7 @@ int main(const int argc, const char *const *const argv, klee_make_symbolic(&shift, sizeof(shift), "shift"); klee_make_symbolic(&flags, sizeof(flags), "flags"); klee_assume(shift < INPUT_SIZE); - klee_assume( - flags <= (kExprFlagsMulti|kExprFlagsDisallowEOC|kExprFlagsPrintError)); + klee_assume(flags <= (kExprFlagsMulti|kExprFlagsDisallowEOC)); #endif ParserLine plines[] = { @@ -91,7 +90,7 @@ int main(const int argc, const char *const *const argv, }; kvi_init(pstate.reader.lines); - const ExprAST ast = viml_pexpr_parse(&pstate, flags); + const ExprAST ast = viml_pexpr_parse(&pstate, (int)flags); assert(ast.root != NULL || ast.err.msg); // Can’t possibly have more highlight tokens then there are bytes in string. assert(kv_size(colors) <= INPUT_SIZE - shift); -- cgit From c7495ebcc0918ffd682083408895451318e41d1f Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 12 Nov 2017 02:18:43 +0300 Subject: viml/parser/expressions: Add support for parsing assignments --- test/symbolic/klee/viml_expressions_parser.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/symbolic/klee/viml_expressions_parser.c') diff --git a/test/symbolic/klee/viml_expressions_parser.c b/test/symbolic/klee/viml_expressions_parser.c index 9448937430..fd75e8d355 100644 --- a/test/symbolic/klee/viml_expressions_parser.c +++ b/test/symbolic/klee/viml_expressions_parser.c @@ -48,7 +48,8 @@ int main(const int argc, const char *const *const argv, klee_make_symbolic(&shift, sizeof(shift), "shift"); klee_make_symbolic(&flags, sizeof(flags), "flags"); klee_assume(shift < INPUT_SIZE); - klee_assume(flags <= (kExprFlagsMulti|kExprFlagsDisallowEOC)); + klee_assume( + flags <= (kExprFlagsMulti|kExprFlagsDisallowEOC|kExprFlagsParseLet)); #endif ParserLine plines[] = { -- cgit From 342239a9c53cf4857d18c0583d4cab1fdca534fa Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 13 Nov 2017 01:10:39 +0300 Subject: unittests,viml/parser/expressions: Start adding asgn parsing tests --- test/symbolic/klee/viml_expressions_parser.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/symbolic/klee/viml_expressions_parser.c') diff --git a/test/symbolic/klee/viml_expressions_parser.c b/test/symbolic/klee/viml_expressions_parser.c index fd75e8d355..9a876ed3fa 100644 --- a/test/symbolic/klee/viml_expressions_parser.c +++ b/test/symbolic/klee/viml_expressions_parser.c @@ -93,6 +93,20 @@ int main(const int argc, const char *const *const argv, const ExprAST ast = viml_pexpr_parse(&pstate, (int)flags); assert(ast.root != NULL || ast.err.msg); + if (flags & kExprFlagsParseLet) { + assert(ast.err.msg != NULL + || ast.root->type == kExprNodeAssignment + || (ast.root->type == kExprNodeListLiteral + && ast.root->children != NULL) + || ast.root->type == kExprNodeComplexIdentifier + || ast.root->type == kExprNodeCurlyBracesIdentifier + || ast.root->type == kExprNodePlainIdentifier + || ast.root->type == kExprNodeRegister + || ast.root->type == kExprNodeEnvironment + || ast.root->type == kExprNodeOption + || ast.root->type == kExprNodeSubscript + || ast.root->type == kExprNodeConcatOrSubscript); + } // Can’t possibly have more highlight tokens then there are bytes in string. assert(kv_size(colors) <= INPUT_SIZE - shift); kvi_destroy(colors); -- cgit