tests: ctrl: Test received ERROR messages are handled correctly

Change-Id: I3c8e95aaa1ca222d4cd1395e548f8461bf9d4cd6
This commit is contained in:
Pau Espin 2018-07-12 19:29:23 +02:00 committed by Harald Welte
parent 59e6059447
commit b885ef88c1
2 changed files with 55 additions and 2 deletions

View File

@ -70,18 +70,23 @@ void assert_same_str(const char *label, const char *expect, const char *got)
static void assert_test(struct ctrl_handle *ctrl, struct ctrl_connection *ccon, const struct one_test *t) static void assert_test(struct ctrl_handle *ctrl, struct ctrl_connection *ccon, const struct one_test *t)
{ {
struct ctrl_cmd *cmd; struct ctrl_cmd *cmd;
bool parse_failed;
struct msgb *msg = msgb_from_string(t->cmd_str); struct msgb *msg = msgb_from_string(t->cmd_str);
int ctx_size_was; int ctx_size_was;
printf("test: '%s'\n", osmo_escape_str(t->cmd_str, -1)); printf("test: '%s'\n", osmo_escape_str(t->cmd_str, -1));
printf("parsing:\n"); printf("parsing:\n");
cmd = ctrl_cmd_parse2(ctx, msg); cmd = ctrl_cmd_parse3(ctx, msg, &parse_failed);
OSMO_ASSERT(cmd); OSMO_ASSERT(cmd);
if (t->expect_parsed.type != cmd->type) { if (t->expect_parsed.type != cmd->type) {
printf("type mismatch: got %s\n", get_value_string(ctrl_type_vals, cmd->type)); printf("type mismatch: got %s\n", get_value_string(ctrl_type_vals, cmd->type));
OSMO_ASSERT(t->expect_parsed.type == cmd->type); OSMO_ASSERT(t->expect_parsed.type == cmd->type);
} else {
printf("type = '%s'%s\n", get_value_string(ctrl_type_vals, cmd->type),
cmd->type != CTRL_TYPE_ERROR ? "" :
(parse_failed ? " (parse failure)" : " (error received)"));
} }
#define ASSERT_SAME_STR(field) \ #define ASSERT_SAME_STR(field) \
@ -310,7 +315,20 @@ static const struct one_test test_messages_list[] = {
.reply = "OK", .reply = "OK",
}, },
}, },
{ "ERROR 1 some error message",
{
.type = CTRL_TYPE_ERROR,
.id = "1",
.reply = "some error message",
},
},
{ "ERROR err some error message",
{
.type = CTRL_TYPE_ERROR,
.id = "err",
.reply = "some error message",
},
},
}; };
static void test_messages() static void test_messages()

View File

@ -9,6 +9,7 @@ ctrl type 6 is ERROR -> 6 OK
ctrl type 64 is unknown 0x40 [PARSE FAILED] ctrl type 64 is unknown 0x40 [PARSE FAILED]
test: 'GET 1 variable' test: 'GET 1 variable'
parsing: parsing:
type = 'GET'
id = '1' id = '1'
variable = 'variable' variable = 'variable'
value = '(null)' value = '(null)'
@ -18,6 +19,7 @@ replied: 'ERROR 1 Command not found'
ok ok
test: 'GET 1 variable\n' test: 'GET 1 variable\n'
parsing: parsing:
type = 'GET'
id = '1' id = '1'
variable = 'variable' variable = 'variable'
value = '(null)' value = '(null)'
@ -27,6 +29,7 @@ replied: 'ERROR 1 Command not found'
ok ok
test: 'GET 1 var\ni\nable' test: 'GET 1 var\ni\nable'
parsing: parsing:
type = 'ERROR' (parse failure)
id = '1' id = '1'
reply = 'GET with trailing characters' reply = 'GET with trailing characters'
handling: handling:
@ -34,6 +37,7 @@ replied: 'ERROR 1 GET with trailing characters'
ok ok
test: 'GET 1 var\ti\table' test: 'GET 1 var\ti\table'
parsing: parsing:
type = 'ERROR' (parse failure)
id = '1' id = '1'
reply = 'GET variable contains invalid characters' reply = 'GET variable contains invalid characters'
handling: handling:
@ -41,6 +45,7 @@ replied: 'ERROR 1 GET variable contains invalid characters'
ok ok
test: 'GET 1 var\ri\rable' test: 'GET 1 var\ri\rable'
parsing: parsing:
type = 'ERROR' (parse failure)
id = '1' id = '1'
reply = 'GET variable contains invalid characters' reply = 'GET variable contains invalid characters'
handling: handling:
@ -48,6 +53,7 @@ replied: 'ERROR 1 GET variable contains invalid characters'
ok ok
test: 'GET 1 variable value' test: 'GET 1 variable value'
parsing: parsing:
type = 'ERROR' (parse failure)
id = '1' id = '1'
reply = 'GET with trailing characters' reply = 'GET with trailing characters'
handling: handling:
@ -55,6 +61,7 @@ replied: 'ERROR 1 GET with trailing characters'
ok ok
test: 'GET 1 variable value\n' test: 'GET 1 variable value\n'
parsing: parsing:
type = 'ERROR' (parse failure)
id = '1' id = '1'
reply = 'GET with trailing characters' reply = 'GET with trailing characters'
handling: handling:
@ -62,6 +69,7 @@ replied: 'ERROR 1 GET with trailing characters'
ok ok
test: 'GET 1 variable multiple value tokens' test: 'GET 1 variable multiple value tokens'
parsing: parsing:
type = 'ERROR' (parse failure)
id = '1' id = '1'
reply = 'GET with trailing characters' reply = 'GET with trailing characters'
handling: handling:
@ -69,6 +77,7 @@ replied: 'ERROR 1 GET with trailing characters'
ok ok
test: 'GET 1 variable multiple value tokens\n' test: 'GET 1 variable multiple value tokens\n'
parsing: parsing:
type = 'ERROR' (parse failure)
id = '1' id = '1'
reply = 'GET with trailing characters' reply = 'GET with trailing characters'
handling: handling:
@ -76,6 +85,7 @@ replied: 'ERROR 1 GET with trailing characters'
ok ok
test: 'SET 1 variable value' test: 'SET 1 variable value'
parsing: parsing:
type = 'SET'
id = '1' id = '1'
variable = 'variable' variable = 'variable'
value = 'value' value = 'value'
@ -85,6 +95,7 @@ replied: 'ERROR 1 Command not found'
ok ok
test: 'SET 1 variable value\n' test: 'SET 1 variable value\n'
parsing: parsing:
type = 'SET'
id = '1' id = '1'
variable = 'variable' variable = 'variable'
value = 'value' value = 'value'
@ -94,6 +105,7 @@ replied: 'ERROR 1 Command not found'
ok ok
test: 'SET weird_id variable value' test: 'SET weird_id variable value'
parsing: parsing:
type = 'ERROR' (parse failure)
id = 'err' id = 'err'
reply = 'Invalid message ID number' reply = 'Invalid message ID number'
handling: handling:
@ -101,6 +113,7 @@ replied: 'ERROR err Invalid message ID number'
ok ok
test: 'SET weird_id variable value\n' test: 'SET weird_id variable value\n'
parsing: parsing:
type = 'ERROR' (parse failure)
id = 'err' id = 'err'
reply = 'Invalid message ID number' reply = 'Invalid message ID number'
handling: handling:
@ -108,6 +121,7 @@ replied: 'ERROR err Invalid message ID number'
ok ok
test: 'SET 1 variable multiple value tokens' test: 'SET 1 variable multiple value tokens'
parsing: parsing:
type = 'SET'
id = '1' id = '1'
variable = 'variable' variable = 'variable'
value = 'multiple value tokens' value = 'multiple value tokens'
@ -117,6 +131,7 @@ replied: 'ERROR 1 Command not found'
ok ok
test: 'SET 1 variable multiple value tokens\n' test: 'SET 1 variable multiple value tokens\n'
parsing: parsing:
type = 'SET'
id = '1' id = '1'
variable = 'variable' variable = 'variable'
value = 'multiple value tokens' value = 'multiple value tokens'
@ -126,6 +141,7 @@ replied: 'ERROR 1 Command not found'
ok ok
test: 'SET 1 variable value_with_trailing_spaces ' test: 'SET 1 variable value_with_trailing_spaces '
parsing: parsing:
type = 'SET'
id = '1' id = '1'
variable = 'variable' variable = 'variable'
value = 'value_with_trailing_spaces ' value = 'value_with_trailing_spaces '
@ -135,6 +151,7 @@ replied: 'ERROR 1 Command not found'
ok ok
test: 'SET 1 variable value_with_trailing_spaces \n' test: 'SET 1 variable value_with_trailing_spaces \n'
parsing: parsing:
type = 'SET'
id = '1' id = '1'
variable = 'variable' variable = 'variable'
value = 'value_with_trailing_spaces ' value = 'value_with_trailing_spaces '
@ -144,6 +161,7 @@ replied: 'ERROR 1 Command not found'
ok ok
test: 'SET \n special_char_id value' test: 'SET \n special_char_id value'
parsing: parsing:
type = 'ERROR' (parse failure)
id = 'err' id = 'err'
reply = 'Invalid message ID number' reply = 'Invalid message ID number'
handling: handling:
@ -151,6 +169,7 @@ replied: 'ERROR err Invalid message ID number'
ok ok
test: 'SET \t special_char_id value' test: 'SET \t special_char_id value'
parsing: parsing:
type = 'ERROR' (parse failure)
id = 'err' id = 'err'
reply = 'Invalid message ID number' reply = 'Invalid message ID number'
handling: handling:
@ -158,6 +177,7 @@ replied: 'ERROR err Invalid message ID number'
ok ok
test: 'GET_REPLY 1 variable OK' test: 'GET_REPLY 1 variable OK'
parsing: parsing:
type = 'GET_REPLY'
id = '1' id = '1'
variable = 'variable' variable = 'variable'
value = '(null)' value = '(null)'
@ -166,12 +186,27 @@ handling:
ok ok
test: 'SET_REPLY 1 variable OK' test: 'SET_REPLY 1 variable OK'
parsing: parsing:
type = 'SET_REPLY'
id = '1' id = '1'
variable = 'variable' variable = 'variable'
value = '(null)' value = '(null)'
reply = 'OK' reply = 'OK'
handling: handling:
ok ok
test: 'ERROR 1 some error message'
parsing:
type = 'ERROR' (error received)
id = '1'
reply = 'some error message'
handling:
ok
test: 'ERROR err some error message'
parsing:
type = 'ERROR' (error received)
id = 'err'
reply = 'some error message'
handling:
ok
test_deferred_cmd test_deferred_cmd
get_test_defer called get_test_defer called