Skip to content

Commit a173604

Browse files
committed
Fix issues in tests because of hard-coded z3 path.
1 parent 8b4b3bb commit a173604

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/util/piped_process.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ piped_processt::piped_processt(const std::string &command)
1818
// This should use the new error state from PR #6131 once that is done
1919
INVARIANT(false, "New SMT2 backend WIP: Windows piped_process constructor.");
2020
#else
21+
2122
if (pipe(pipe_input) == -1) {
2223
throw std::runtime_error("Input pipe creation failed");
2324
}
2425

2526
if (pipe(pipe_output) == -1) {
2627
throw std::runtime_error("Output pipe creation failed");
2728
}
29+
2830
// Default state
2931
process_state = process_statet::NOT_CREATED;
3032

@@ -74,19 +76,23 @@ bool piped_processt::send(const std::string &message)
7476
// This should use the new error state from PR #6131 once that is done
7577
INVARIANT(false, "New SMT2 backend WIP: Windows piped_processt::send.");
7678
#else
79+
7780
if(process_state != process_statet::CREATED)
7881
{
7982
return false;
8083
}
84+
8185
// send message to solver process
8286
int send_status = fputs(message.c_str(), command_stream);
8387
fflush(command_stream);
88+
8489
if(send_status == EOF)
8590
{
8691
// Some kind of error occured, maybe we should update the
8792
// solver status here?
8893
return false;
8994
}
95+
9096
return true;
9197
#endif
9298
}
@@ -97,11 +103,14 @@ std::string piped_processt::receive()
97103
// This should use the new error state from PR #6131 once that is done
98104
INVARIANT(false, "New SMT2 backend WIP: Windows piped_processt::receive.");
99105
#else
106+
100107
if(process_state != process_statet::CREATED)
101108
return NULL;
109+
102110
std::string response = std::string("");
103111
int nbytes;
104112
char buff[BUFSIZE];
113+
105114
while (true)
106115
{
107116
nbytes = read(pipe_output[0], buff, BUFSIZE);
@@ -121,6 +130,7 @@ std::string piped_processt::receive()
121130
response.append(buff, nbytes);
122131
}
123132
}
133+
124134
UNREACHABLE;
125135
#endif
126136
}
@@ -131,6 +141,7 @@ char ** piped_processt::split_command_args(const std::string &command)
131141
char ** res = NULL;
132142
int n_spaces = 0;
133143
char *p = strtok(strdup(command.c_str()), " ");
144+
134145
while(p)
135146
{
136147
res = (char **)realloc(res, sizeof (char*) * ++n_spaces);
@@ -139,16 +150,8 @@ char ** piped_processt::split_command_args(const std::string &command)
139150
res[n_spaces-1] = p;
140151
p = strtok (NULL, " ");
141152
}
153+
142154
res = (char **)realloc (res, sizeof (char*) * (n_spaces+1));
143155
res[n_spaces] = 0;
144156
return res;
145157
}
146-
147-
// Below is simple testing code to see that things (mostly) work.
148-
// int main(int argc, char *argv[])
149-
// {
150-
// piped_processt subp = piped_processt("/usr/local/bin/z3 --help");
151-
// std::string data = subp.receive();
152-
// std::cout << data << std::endl;
153-
// return 0;
154-
// }

unit/util/piped_process.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
TEST_CASE("We create a pipe and we can read from it", "[core][util][piped_process]")
1313
{
14-
std::string to_be_echoed = "The Jaberwocky";
14+
std::string to_be_echoed = "The Jabberwocky";
15+
// Need to give up to avoid shell built-in invocation
1516
std::string binary = "/bin/echo";
1617
std::string command = binary + " " + to_be_echoed;
1718
piped_processt process = piped_processt(command);
@@ -29,7 +30,7 @@ TEST_CASE("We create a pipe and we can read from it", "[core][util][piped_proces
2930

3031
TEST_CASE("We create a pipe, send and receive from it", "[core][util][piped_process]")
3132
{
32-
std::string binary = "/usr/local/bin/z3 -in";
33+
std::string binary = "z3 -in";
3334
std::string statement = "(echo \"hi\")";
3435
std::string termination_statement = "(exit)";
3536
piped_processt process = piped_processt(binary);
@@ -55,7 +56,7 @@ TEST_CASE("We create a pipe, send and receive from it", "[core][util][piped_proc
5556

5657
TEST_CASE("We create a pipe, interact", "[core][util][piped_process]")
5758
{
58-
std::string binary = "/usr/local/bin/z3 -in";
59+
std::string binary = "z3 -in";
5960
std::string statement = "(echo \"hi\")";
6061
std::string termination_statement = "(exit)";
6162
piped_processt process = piped_processt(binary);

0 commit comments

Comments
 (0)