mirror of git://git.sysmocom.de/ofono
stktest: Further flesh out test framework
This commit is contained in:
parent
1a3047ac84
commit
aaf7ae0fd6
|
@ -96,8 +96,42 @@ static GAtServer *emulator;
|
||||||
/* Emulated modem state variables */
|
/* Emulated modem state variables */
|
||||||
static int modem_mode = 0;
|
static int modem_mode = 0;
|
||||||
|
|
||||||
|
void __stktest_test_next();
|
||||||
|
void __stktest_test_finish(gboolean successful);
|
||||||
static gboolean create_tcp(void);
|
static gboolean create_tcp(void);
|
||||||
|
|
||||||
|
#define STKTEST_AGENT_ASSERT(expr) \
|
||||||
|
do { \
|
||||||
|
if (!(expr)) { \
|
||||||
|
g_printerr("Assertion Failed %s:%d %s\n", \
|
||||||
|
__FILE__, __LINE__, #expr); \
|
||||||
|
__stktest_test_finish(FALSE); \
|
||||||
|
return stktest_error_failed(msg); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define STKTEST_RESPONSE_ASSERT(expect_pdu, expect_pdu_len, \
|
||||||
|
got_pdu, got_pdu_len) \
|
||||||
|
do { \
|
||||||
|
if ((expect_pdu_len) != (got_pdu_len)) { \
|
||||||
|
g_printerr("Assertion Failed %s:%d" \
|
||||||
|
" Wrong response len" \
|
||||||
|
" want: %d, got: %d\n", \
|
||||||
|
__FILE__, __LINE__, \
|
||||||
|
expect_pdu_len, got_pdu_len); \
|
||||||
|
__stktest_test_finish(FALSE); \
|
||||||
|
return; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
if (memcmp(expect_pdu, got_pdu, expect_pdu_len) != 0) { \
|
||||||
|
g_printerr("Assertion Failed %s:%d" \
|
||||||
|
"Wrong response\n", \
|
||||||
|
__FILE__, __LINE__); \
|
||||||
|
__stktest_test_finish(FALSE); \
|
||||||
|
return; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
static const char *to_hex(const unsigned char *data, unsigned int len)
|
static const char *to_hex(const unsigned char *data, unsigned int len)
|
||||||
{
|
{
|
||||||
static char buf[512+1];
|
static char buf[512+1];
|
||||||
|
@ -163,6 +197,8 @@ static DBusMessage *agent_display_text(DBusConnection *conn, DBusMessage *msg,
|
||||||
const char *text;
|
const char *text;
|
||||||
unsigned char icon_id;
|
unsigned char icon_id;
|
||||||
dbus_bool_t urgent;
|
dbus_bool_t urgent;
|
||||||
|
struct test *test;
|
||||||
|
display_text_cb_t func;
|
||||||
|
|
||||||
if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &text,
|
if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &text,
|
||||||
DBUS_TYPE_BYTE, &icon_id,
|
DBUS_TYPE_BYTE, &icon_id,
|
||||||
|
@ -170,9 +206,13 @@ static DBusMessage *agent_display_text(DBusConnection *conn, DBusMessage *msg,
|
||||||
DBUS_TYPE_INVALID) == FALSE)
|
DBUS_TYPE_INVALID) == FALSE)
|
||||||
return stktest_error_invalid_args(msg);
|
return stktest_error_invalid_args(msg);
|
||||||
|
|
||||||
g_print("Got DisplayText with: %s, %u, %d\n", text, icon_id, urgent);
|
if (cur_test == NULL)
|
||||||
|
return stktest_error_failed(msg);
|
||||||
|
|
||||||
return dbus_message_new_method_return(msg);
|
test = cur_test->data;
|
||||||
|
func = test->agent_func;
|
||||||
|
|
||||||
|
return func(msg, text, icon_id, urgent);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void server_debug(const char *str, void *data)
|
static void server_debug(const char *str, void *data)
|
||||||
|
@ -319,6 +359,8 @@ static void cusatt_cb(GAtServer *server, GAtServerRequestType type,
|
||||||
GAtResultIter iter;
|
GAtResultIter iter;
|
||||||
const unsigned char *pdu;
|
const unsigned char *pdu;
|
||||||
int len;
|
int len;
|
||||||
|
struct test *test;
|
||||||
|
terminal_response_func func;
|
||||||
|
|
||||||
g_at_result_iter_init(&iter, cmd);
|
g_at_result_iter_init(&iter, cmd);
|
||||||
g_at_result_iter_next(&iter, "");
|
g_at_result_iter_next(&iter, "");
|
||||||
|
@ -326,7 +368,14 @@ static void cusatt_cb(GAtServer *server, GAtServerRequestType type,
|
||||||
if (g_at_result_iter_next_hexstring(&iter, &pdu, &len) == FALSE)
|
if (g_at_result_iter_next_hexstring(&iter, &pdu, &len) == FALSE)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
if (cur_test == NULL)
|
||||||
|
goto error;
|
||||||
|
|
||||||
g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
|
g_at_server_send_final(server, G_AT_SERVER_RESULT_OK);
|
||||||
|
|
||||||
|
test = cur_test->data;
|
||||||
|
func = test->tr_func;
|
||||||
|
func(pdu, len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -341,6 +390,9 @@ error:
|
||||||
|
|
||||||
static void listen_again(gpointer user_data)
|
static void listen_again(gpointer user_data)
|
||||||
{
|
{
|
||||||
|
g_at_server_unref(emulator);
|
||||||
|
emulator = NULL;
|
||||||
|
|
||||||
if (create_tcp() == TRUE)
|
if (create_tcp() == TRUE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -592,6 +644,7 @@ static void register_agent_reply(DBusPendingCall *call, void *user_data)
|
||||||
{
|
{
|
||||||
DBusMessage *reply = dbus_pending_call_steal_reply(call);
|
DBusMessage *reply = dbus_pending_call_steal_reply(call);
|
||||||
DBusError err;
|
DBusError err;
|
||||||
|
struct test *test;
|
||||||
|
|
||||||
dbus_error_init(&err);
|
dbus_error_init(&err);
|
||||||
|
|
||||||
|
@ -603,6 +656,8 @@ static void register_agent_reply(DBusPendingCall *call, void *user_data)
|
||||||
dbus_message_unref(reply);
|
dbus_message_unref(reply);
|
||||||
|
|
||||||
state = TEST_STATE_RUNNING;
|
state = TEST_STATE_RUNNING;
|
||||||
|
test = cur_test->data;
|
||||||
|
send_proactive_command(test->req_pdu, test->req_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void register_agent()
|
static void register_agent()
|
||||||
|
@ -738,7 +793,7 @@ done:
|
||||||
g_main_loop_quit(main_loop);
|
g_main_loop_quit(main_loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
powerup();
|
__stktest_test_next();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_modems(DBusConnection *conn)
|
static int get_modems(DBusConnection *conn)
|
||||||
|
@ -836,6 +891,37 @@ static void disconnect_callback(DBusConnection *conn, void *user_data)
|
||||||
g_main_loop_quit(main_loop);
|
g_main_loop_quit(main_loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void power_down_reply(DBusPendingCall *call, void *user_data)
|
||||||
|
{
|
||||||
|
__stktest_test_next();
|
||||||
|
}
|
||||||
|
|
||||||
|
void __stktest_test_finish(gboolean successful)
|
||||||
|
{
|
||||||
|
struct test *test = cur_test->data;
|
||||||
|
dbus_bool_t powered = FALSE;
|
||||||
|
|
||||||
|
test->result = successful ? TEST_RESULT_PASSED : TEST_RESULT_FAILED;
|
||||||
|
|
||||||
|
state = TEST_STATE_POWERING_DOWN;
|
||||||
|
set_property(STKTEST_PATH, OFONO_MODEM_INTERFACE, "Powered",
|
||||||
|
DBUS_TYPE_BOOLEAN, &powered,
|
||||||
|
power_down_reply, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void __stktest_test_next()
|
||||||
|
{
|
||||||
|
if (cur_test == NULL)
|
||||||
|
cur_test = tests;
|
||||||
|
else
|
||||||
|
cur_test = cur_test->next;
|
||||||
|
|
||||||
|
if (cur_test == NULL)
|
||||||
|
g_main_loop_quit(main_loop);
|
||||||
|
|
||||||
|
powerup();
|
||||||
|
}
|
||||||
|
|
||||||
static void stktest_add_test(const char *name, const char *method,
|
static void stktest_add_test(const char *name, const char *method,
|
||||||
const unsigned char *req, unsigned int req_len,
|
const unsigned char *req, unsigned int req_len,
|
||||||
const unsigned char *rsp, unsigned int rsp_len,
|
const unsigned char *rsp, unsigned int rsp_len,
|
||||||
|
|
Loading…
Reference in New Issue