-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuzz_lexer_main.cpp
64 lines (50 loc) · 1.35 KB
/
fuzz_lexer_main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "test_utils.h"
#include "lexer.h"
#include <iostream>
#include <signal.h>
void disable_sigint()
{
sigset_t base_mask;
sigemptyset (&base_mask);
sigaddset (&base_mask, SIGINT);
sigprocmask (SIG_SETMASK, &base_mask, NULL);
}
bool is_sigint_pending()
{
sigset_t waiting_mask;
sigpending(&waiting_mask);
return sigismember(&waiting_mask, SIGINT);
}
int main()
{
disable_sigint();
std::random_device rnd_device;
std::mt19937 mersenne_engine(rnd_device());
std::uniform_int_distribution<size_t> dist(1, 20);
auto gen = std::bind(dist, mersenne_engine);
size_t i = 0;
for (;;)
{
if ((i % (16 * 1024)) == 0)
{
if (is_sigint_pending())
break;
std::cout << '.' << std::flush;
}
size_t size = gen();
std::vector<char> input = random_vector(size, mersenne_engine);
/*write_string_screened(std::cout, std::string(input.begin(), input.end()));
std::cout << std::endl;*/
input.push_back(guard_value);
lexer lex(input.data(), input.data() + input.size() - 1);
token tok = lex.fetch(true);
for (;;)
{
if (tok.tok_type == token_type::eof)
break;
tok = lex.fetch(false);
}
++i;
}
std::cout << "run " << i << " times\n";
}