diff --git a/dftest.c b/dftest.c index 6c29148324..5844ee6762 100644 --- a/dftest.c +++ b/dftest.c @@ -39,6 +39,7 @@ #include "ui/cmdarg_err.h" #include "ui/failure_message.h" #include "ui/version_info.h" +#include "ui/exit_codes.h" static int opt_verbose = 0; #define DFTEST_LOG_NONE 0 @@ -280,13 +281,13 @@ main(int argc, char **argv) case 1000: if (strlen(ws_optarg) > 1 || !g_ascii_isdigit(*ws_optarg)) { printf("Error: \"%s\" is not a valid number 0-9\n", ws_optarg); - print_usage(EXIT_FAILURE); + print_usage(INVALID_OPTION); } errno = 0; opt_optimize = strtol(ws_optarg, NULL, 10); if (errno) { printf("Error: %s\n", g_strerror(errno)); - print_usage(EXIT_FAILURE); + print_usage(INVALID_OPTION); } break; case 2000: @@ -398,7 +399,7 @@ main(int argc, char **argv) /* Expand macros. */ expanded_text = expand_filter(text, timer); if (expanded_text == NULL) { - exit_status = 2; + exit_status = INVALID_FILTER; goto out; } @@ -407,7 +408,7 @@ main(int argc, char **argv) /* Compile it */ if (!compile_filter(expanded_text, &df, timer)) { - exit_status = 2; + exit_status = INVALID_FILTER; goto out; } @@ -418,7 +419,7 @@ main(int argc, char **argv) if (df == NULL) { printf("Filter is empty.\n"); - exit_status = 1; + exit_status = INVALID_FILTER; goto out; } diff --git a/test/subprocesstest.py b/test/subprocesstest.py index 02422a6cba..78db95aed0 100644 --- a/test/subprocesstest.py +++ b/test/subprocesstest.py @@ -118,8 +118,18 @@ class SubprocessTestCase(unittest.TestCase): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.exit_ok = 0 + + # See ui/exit_codes.h self.exit_command_line = 1 - self.exit_error = 2 + self.exit_invalid_interface = 2 + self.exit_invalid_file_error = 3 + self.exit_invalid_filter_error = 4 + self.exit_invalid_capability = 5 + self.exit_iface_no_link_types = 6 + self.exit_iface_has_no_timestamp_types = 7 + self.exit_init_failed = 8 + self.exit_open_error = 9 + self.exit_code = None self.log_fname = None self.log_fd = None diff --git a/test/suite_clopts.py b/test/suite_clopts.py index b0a17b1f49..553c1dad47 100644 --- a/test/suite_clopts.py +++ b/test/suite_clopts.py @@ -39,7 +39,7 @@ class case_dumpcap_options(subprocesstest.SubprocessTestCase): # XXX Should we generate individual test functions instead of looping? def test_dumpcap_interface_chars(self, cmd_dumpcap, base_env): '''Valid dumpcap parameters requiring capture permissions''' - valid_returns = [self.exit_ok, self.exit_error] + valid_returns = [self.exit_ok, self.exit_invalid_interface] for char_arg in 'DL': process = self.runProcess((cmd_dumpcap, '-' + char_arg), env=base_env) self.assertIn(process.returncode, valid_returns) @@ -83,7 +83,7 @@ class case_basic_clopts(subprocesstest.SubprocessTestCase): def test_nonexistent_file(self, cmd_tshark, capture_file): # $TSHARK - r ThisFileDontExist.pcap > ./testout.txt 2 > &1 self.assertRun((cmd_tshark, '-r', capture_file('__ceci_nest_pas_une.pcap')), - expected_return=self.exit_error) + expected_return=self.exit_invalid_file_error) @fixtures.mark_usefixtures('test_env') @@ -105,7 +105,7 @@ class case_tshark_options(subprocesstest.SubprocessTestCase): def test_tshark_interface_chars(self, cmd_tshark, cmd_dumpcap): '''Valid tshark parameters requiring capture permissions''' # These options require dumpcap - valid_returns = [self.exit_ok, self.exit_error] + valid_returns = [self.exit_ok, self.exit_invalid_capability] for char_arg in 'DL': process = self.runProcess((cmd_tshark, '-' + char_arg)) self.assertIn(process.returncode, valid_returns) diff --git a/test/suite_dfilter/dfiltertest.py b/test/suite_dfilter/dfiltertest.py index ca2f9860be..9a0accc41f 100644 --- a/test/suite_dfilter/dfiltertest.py +++ b/test/suite_dfilter/dfiltertest.py @@ -75,7 +75,7 @@ def checkDFilterFail(cmd_dftest, base_env): outs, errs = proc.communicate() assert error_message in errs, \ 'Unexpected dftest stderr:\n%s\nstdout:\n%s' % (errs, outs) - assert proc.returncode == 2, \ + assert proc.returncode == 4, \ 'Unexpected dftest exit code: %d. stdout:\n%s\n' % \ (proc.returncode, outs) return checkDFilterFail_real diff --git a/ui/exit_codes.h b/ui/exit_codes.h index 67ea73f4b6..f306e2d5c3 100644 --- a/ui/exit_codes.h +++ b/ui/exit_codes.h @@ -15,12 +15,12 @@ /* Exit codes */ #define INVALID_OPTION 1 #define INVALID_INTERFACE 2 -#define INVALID_FILE 2 -#define INVALID_FILTER 2 -#define INVALID_CAPABILITY 2 -#define IFACE_HAS_NO_LINK_TYPES 2 -#define IFACE_HAS_NO_TIMESTAMP_TYPES 2 -#define INIT_FAILED 2 -#define OPEN_ERROR 2 +#define INVALID_FILE 3 +#define INVALID_FILTER 4 +#define INVALID_CAPABILITY 5 +#define IFACE_HAS_NO_LINK_TYPES 6 +#define IFACE_HAS_NO_TIMESTAMP_TYPES 7 +#define INIT_FAILED 8 +#define OPEN_ERROR 9 #endif /* __EXIT_CODES_H__ */