Skip to content

Commit eebce96

Browse files
committed
goto-instrument/argc-argv2: add test case for new --add-cmd-line-arg
option
1 parent 045e625 commit eebce96

File tree

7 files changed

+59
-26
lines changed

7 files changed

+59
-26
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <assert.h>
2+
3+
int main(int argc, char *argv[])
4+
{
5+
if(argc >= 2)
6+
{
7+
assert(argv[0][0] == 'A');
8+
assert(argv[1][0] == 'B');
9+
}
10+
11+
return 0;
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--add-cmd-line-arg A --add-cmd-line-arg B
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--model-argc-argv 2
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
^warning: ignoring

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,32 +1060,32 @@ void goto_instrument_parse_optionst::instrument_goto_program()
10601060
log.status() << "Adding up to " << max_argc << " command line arguments"
10611061
<< messaget::eom;
10621062

1063-
if(model_argc_argv(goto_model, argv, true /*model_argv*/,
1064-
ui_message_handler))
1063+
if(model_argc_argv(
1064+
goto_model, argv, true /*model_argv*/, ui_message_handler))
10651065
throw 0;
10661066
}
10671067

10681068
if(cmdline.isset("add-cmd-line-arg"))
10691069
{
1070-
10711070
const std::list<std::string> &argv = cmdline.get_values("add-cmd-line-arg");
10721071
unsigned argc = 0;
10731072

10741073
std::stringstream ss;
10751074
ss << "[";
10761075
std::string sep = "";
1077-
for (auto const& arg : argv) {
1078-
ss << sep << "\"" << arg << "\"";
1079-
argc++;
1080-
sep = ", ";
1076+
for(auto const &arg : argv)
1077+
{
1078+
ss << sep << "\"" << arg << "\"";
1079+
argc++;
1080+
sep = ", ";
10811081
}
10821082
ss << "]";
10831083

10841084
log.status() << "Adding " << argc << " arguments: " << ss.str()
1085-
<< messaget::eom;
1085+
<< messaget::eom;
10861086

1087-
if(model_argc_argv(goto_model, argv, false /*model_argv*/,
1088-
ui_message_handler))
1087+
if(model_argc_argv(
1088+
goto_model, argv, false /*model_argv*/, ui_message_handler))
10891089
throw 0;
10901090
}
10911091

src/goto-instrument/goto_instrument_parse_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ Author: Daniel Kroening, [email protected]
3232
#include "contracts/contracts.h"
3333
#include "generate_function_bodies.h"
3434
#include "insert_final_assert_false.h"
35-
#include "nondet_volatile.h"
3635
#include "model_argc_argv.h"
36+
#include "nondet_volatile.h"
3737
#include "replace_calls.h"
3838

3939
#include "count_eloc.h"

src/goto-instrument/model_argc_argv.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ bool model_argc_argv(
9494
unsigned max_argc = argv_args.size();
9595
unsigned argc = argv_args.size();
9696

97-
if ( model_argv ) {
97+
if(model_argv)
98+
{
9899
oss << "int ARGC;\n"
99100
<< "char *ARGV[1];\n"
100101
<< "void " << goto_model.goto_functions.entry_point() << "()\n"
@@ -114,18 +115,21 @@ bool model_argc_argv(
114115
<< " next+=len+1;\n"
115116
<< " }\n"
116117
<< "}";
117-
} else { // model_argv = false, set each argv[i] explicitly
118-
oss << "int ARGC = " << argc << ";\n"
119-
<< "char *ARGV[" << argc << "];\n"
120-
<< "void " << goto_model.goto_functions.entry_point() << "()\n"
121-
<< "{\n";
122-
int i = 0;
123-
for (auto const& arg : argv_args) {
124-
oss << "ARGV[" << i << "]=\"" << arg << "\";\n";
125-
i++;
126-
}
127-
oss << "}";
118+
}
119+
else
120+
{ // model_argv = false, set each argv[i] explicitly
121+
oss << "int ARGC = " << argc << ";\n"
122+
<< "char *ARGV[" << argc << "];\n"
123+
<< "void " << goto_model.goto_functions.entry_point() << "()\n"
124+
<< "{\n";
125+
int i = 0;
126+
for(auto const &arg : argv_args)
127+
{
128+
oss << "ARGV[" << i << "]=\"" << arg << "\";\n";
129+
i++;
128130
}
131+
oss << "}";
132+
}
129133

130134
std::istringstream iss(oss.str());
131135

src/goto-instrument/model_argc_argv.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ bool model_argc_argv(
2828

2929
#define OPT_ARGC_ARGV "(model-argc-argv):(add-cmd-line-arg):"
3030

31-
#define HELP_ARGC_ARGV \
32-
" --model-argc-argv <n> model up to <n> command line arguments\n" \
33-
" --add-cmd-line-arg <arg> add command line argument (may be repeated)\n"
31+
#define HELP_ARGC_ARGV \
32+
" --model-argc-argv <n> model up to <n> command line arguments\n" \
33+
" --add-cmd-line-arg <arg> add command line argument (may be " \
34+
"repeated)\n"
3435

3536
#endif // CPROVER_GOTO_INSTRUMENT_MODEL_ARGC_ARGV_H

0 commit comments

Comments
 (0)