summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Opasiak <k.opasiak@samsung.com>2015-12-21 23:43:57 +0100
committerKrzysztof Opasiak <k.opasiak@samsung.com>2015-12-23 00:49:03 +0100
commitec6400e101ebc5a7273d9929edad59d3cb9dcb3e (patch)
treeca28a5e8cb8caff2716d3c40e9566167dfbd3605
parent54eff8a3449fb6c5df6b580aa2f68557d3181f42 (diff)
downloadlibusbg-ec6400e101ebc5a7273d9929edad59d3cb9dcb3e.tar.gz
libusbg-ec6400e101ebc5a7273d9929edad59d3cb9dcb3e.tar.bz2
libusbg-ec6400e101ebc5a7273d9929edad59d3cb9dcb3e.zip
libusbgx: tests: Port all tests to new API
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
-rw-r--r--tests/test.c52
-rw-r--r--tests/usbg-test.c101
-rw-r--r--tests/usbg-test.h15
3 files changed, 99 insertions, 69 deletions
diff --git a/tests/test.c b/tests/test.c
index bd17af9..3a5ea7d 100644
--- a/tests/test.c
+++ b/tests/test.c
@@ -196,30 +196,33 @@ static struct test_gadget long_udc_gadgets[] = {
struct test_function_attrs_data {
struct test_state *state;
- usbg_function_attrs *attrs;
+ void *attrs;
};
struct test_data {
struct test_state *state;
struct usbg_state *usbg_state;
};
-#define FUNC_ATTRS(t, label, a...) { \
- .header = { \
- .attrs_type = t \
- }, \
- .attrs = { \
- .label = { a } \
- }, \
-}
+static int simple_serial_attrs = 42;
+
+static struct usbg_f_net_attrs simple_net_attrs = {
+ .dev_addr = {}, .host_addr = {}, .ifname = "if", .qmult = 1,
+};
+
+static char *simple_phonet_attrs = "if";
+
+static char *simple_ffs_attrs = "0";
+
+static int writable_serial_attrs = 0;
+
+static struct usbg_f_net_attrs writable_net_attrs = {
+ .dev_addr = {}, .host_addr = {}, .ifname = "", .qmult = 1,
+};
+
+static char *writable_phonet_attrs = "";
+
+static char *writable_ffs_attrs = "";
-static usbg_function_attrs simple_serial_attrs = FUNC_ATTRS(USBG_F_ATTRS_SERIAL, serial, 42);
-static usbg_function_attrs simple_net_attrs = FUNC_ATTRS(USBG_F_ATTRS_NET, net, {}, {}, "if", 1);
-static usbg_function_attrs simple_phonet_attrs = FUNC_ATTRS(USBG_F_ATTRS_PHONET, phonet, "if");
-static usbg_function_attrs writable_serial_attrs = FUNC_ATTRS(USBG_F_ATTRS_SERIAL, serial, 0);
-static usbg_function_attrs writable_net_attrs = FUNC_ATTRS(USBG_F_ATTRS_NET, net, {}, {}, "", 42);
-static usbg_function_attrs writable_phonet_attrs = FUNC_ATTRS(USBG_F_ATTRS_PHONET, phonet, "");
-static usbg_function_attrs simple_ffs_attrs = FUNC_ATTRS(USBG_F_ATTRS_FFS, ffs, "0");
-static usbg_function_attrs writable_ffs_attrs = FUNC_ATTRS(USBG_F_ATTRS_FFS, ffs, "");
struct test_gadget_strs_data {
struct test_state *state;
@@ -438,7 +441,7 @@ static int setup_random_len_gadget_strs_data(void **state)
return 0;
}
-static void *setup_f_attrs(int f_type, usbg_function_attrs *attrs)
+static void *setup_f_attrs(int f_type, void *attrs)
{
struct test_function_attrs_data *data;
struct test_function *func;
@@ -1767,7 +1770,14 @@ static void test_get_function_attrs(void **state)
usbg_state *s;
usbg_function *f;
usbg_gadget *g;
- usbg_function_attrs actual;
+ union {
+ struct usbg_f_net_attrs net;
+ char *ffs_dev_name;
+ struct usbg_f_ms_attrs ms;
+ struct usbg_f_midi_attrs midi;
+ int serial_port_num;
+ char *phonet_ifname;
+ } actual;
int ret;
data = (struct test_function_attrs_data *)(*state);
@@ -1786,9 +1796,9 @@ static void test_get_function_attrs(void **state)
ret = usbg_get_function_attrs(f, &actual);
assert_int_equal(ret, 0);
- assert_function_attrs_equal(&actual, data->attrs, data->attrs->header.attrs_type);
+ assert_function_attrs_equal(&actual, data->attrs, f->type);
- usbg_cleanup_function_attrs(&actual);
+ usbg_cleanup_function_attrs(f, &actual);
}
/**
diff --git a/tests/usbg-test.c b/tests/usbg-test.c
index 972492e..1b88f05 100644
--- a/tests/usbg-test.c
+++ b/tests/usbg-test.c
@@ -1009,18 +1009,18 @@ void pull_create_config(struct test_config *tc)
#define ETHER_ADDR_STR_LEN 19
static void push_serial_attrs(struct test_function *func,
- usbg_f_serial_attrs *attrs)
+ int *port_num)
{
char *path;
char *content;
safe_asprintf(&path, "%s/%s/port_num", func->path, func->name);
- safe_asprintf(&content, "%d\n", attrs->port_num);
+ safe_asprintf(&content, "%d\n", *port_num);
PUSH_FILE(path, content);
}
static void push_net_attrs(struct test_function *func,
- usbg_f_net_attrs *attrs)
+ struct usbg_f_net_attrs *attrs)
{
char *path;
char *content;
@@ -1051,41 +1051,43 @@ static void push_net_attrs(struct test_function *func,
}
static void push_phonet_attrs(struct test_function *func,
- usbg_f_phonet_attrs *attrs)
+ char **ifname)
{
char *path;
char *content;
safe_asprintf(&path, "%s/%s/ifname", func->path, func->name);
- safe_asprintf(&content, "%s\n", attrs->ifname);
+ safe_asprintf(&content, "%s\n", *ifname);
PUSH_FILE(path, content);
}
-void push_function_attrs(struct test_function *func, usbg_function_attrs *function_attrs)
+void push_function_attrs(struct test_function *func, void *function_attrs)
{
- int attrs_type;
- usbg_f_attrs *attrs = &function_attrs->attrs;
-
- attrs_type = usbg_lookup_function_attrs_type(func->type);
-
- switch (attrs_type) {
- case USBG_F_ATTRS_SERIAL:
- push_serial_attrs(func, &attrs->serial);
+ switch (func->type) {
+ case F_ACM:
+ case F_OBEX:
+ case F_SERIAL:
+ push_serial_attrs(func, function_attrs);
break;
- case USBG_F_ATTRS_NET:
- push_net_attrs(func, &attrs->net);
+ case F_ECM:
+ case F_SUBSET:
+ case F_NCM:
+ case F_EEM:
+ case F_RNDIS:
+ push_net_attrs(func, function_attrs);
break;
- case USBG_F_ATTRS_PHONET:
- push_phonet_attrs(func, &attrs->phonet);
+ case F_PHONET:
+ push_phonet_attrs(func, function_attrs);
break;
- case USBG_F_ATTRS_FFS:
+ case F_FFS:
// ffs does not exist in filesystem
default:
break;
}
}
-static void pull_function_net_attrs(struct test_function *func, usbg_f_net_attrs *attrs)
+static void pull_function_net_attrs(struct test_function *func,
+ struct usbg_f_net_attrs *attrs)
{
char *path;
char *content;
@@ -1109,11 +1111,19 @@ static void pull_function_net_attrs(struct test_function *func, usbg_f_net_attrs
EXPECT_WRITE(path, content);
}
-void pull_function_attrs(struct test_function *func, usbg_function_attrs *attrs)
+void pull_function_attrs(struct test_function *func, void *attrs)
{
- /* only net attributes are writtable */
- if (attrs->header.attrs_type == USBG_F_ATTRS_NET)
- pull_function_net_attrs(func, &attrs->attrs.net);
+ switch (func->type) {
+ case F_ECM:
+ case F_SUBSET:
+ case F_NCM:
+ case F_EEM:
+ case F_RNDIS:
+ pull_function_net_attrs(func, attrs);
+ break;
+ default:
+ break;
+ }
}
void pull_create_function(struct test_function *tf)
@@ -1262,10 +1272,9 @@ void assert_gadget_strs_equal(usbg_gadget_strs *actual, usbg_gadget_strs *expect
assert_string_equal(get_gadget_str(actual, i), get_gadget_str(expected, i));
}
-void assert_f_serial_attrs_equal(usbg_f_serial_attrs *actual,
- usbg_f_serial_attrs *expected)
+void assert_f_serial_attrs_equal(int *actual, int *expected)
{
- assert_int_equal(actual->port_num, expected->port_num);
+ assert_int_equal(*actual, *expected);
}
static void assert_ether_addrs_equal(const struct ether_addr *ea1,
@@ -1275,7 +1284,8 @@ static void assert_ether_addrs_equal(const struct ether_addr *ea1,
ETHER_ADDR_LEN);
}
-void assert_f_net_attrs_equal(usbg_f_net_attrs *actual, usbg_f_net_attrs *expected)
+void assert_f_net_attrs_equal(struct usbg_f_net_attrs *actual,
+ struct usbg_f_net_attrs *expected)
{
assert_ether_addrs_equal(&actual->dev_addr, &expected->dev_addr);
assert_ether_addrs_equal(&actual->host_addr, &expected->host_addr);
@@ -1283,32 +1293,37 @@ void assert_f_net_attrs_equal(usbg_f_net_attrs *actual, usbg_f_net_attrs *expect
assert_int_equal(actual->qmult, expected->qmult);
}
-void assert_f_phonet_attrs_equal(usbg_f_phonet_attrs *actual,
- usbg_f_phonet_attrs *expected)
+void assert_f_phonet_attrs_equal(char **actual, char **expected)
{
- assert_string_equal(actual->ifname, expected->ifname);
+ assert_string_equal(*actual, *expected);
}
-void assert_f_ffs_attrs_equal(usbg_f_ffs_attrs *actual, usbg_f_ffs_attrs *expected)
+void assert_f_ffs_attrs_equal(char **actual, char **expected)
{
- assert_string_equal(actual->dev_name, expected->dev_name);
+ assert_string_equal(*actual, *expected);
}
-void assert_function_attrs_equal(usbg_function_attrs *actual,
- usbg_function_attrs *expected, usbg_f_attrs_type type)
+void assert_function_attrs_equal(void *actual, void *expected,
+ usbg_function_type type)
{
switch (type) {
- case USBG_F_ATTRS_SERIAL:
- assert_f_serial_attrs_equal(&actual->attrs.serial, &expected->attrs.serial);
+ case F_ACM:
+ case F_OBEX:
+ case F_SERIAL:
+ assert_f_serial_attrs_equal(actual, expected);
break;
- case USBG_F_ATTRS_NET:
- assert_f_net_attrs_equal(&actual->attrs.net, &expected->attrs.net);
+ case F_ECM:
+ case F_SUBSET:
+ case F_NCM:
+ case F_EEM:
+ case F_RNDIS:
+ assert_f_net_attrs_equal(actual, expected);
break;
- case USBG_F_ATTRS_PHONET:
- assert_f_phonet_attrs_equal(&actual->attrs.phonet, &expected->attrs.phonet);
+ case F_PHONET:
+ assert_f_phonet_attrs_equal(actual, expected);
break;
- case USBG_F_ATTRS_FFS:
- assert_f_ffs_attrs_equal(&actual->attrs.ffs, &expected->attrs.ffs);
+ case F_FFS:
+ assert_f_ffs_attrs_equal(actual, expected);
break;
default:
fail();
diff --git a/tests/usbg-test.h b/tests/usbg-test.h
index 127b90e..f7890ab 100644
--- a/tests/usbg-test.h
+++ b/tests/usbg-test.h
@@ -2,6 +2,12 @@
#define USBG_TEST_H
#include <usbg/usbg.h>
+#include <usbg/function/ms.h>
+#include <usbg/function/net.h>
+#include <usbg/function/ffs.h>
+#include <usbg/function/phonet.h>
+#include <usbg/function/midi.h>
+
#include <sys/queue.h>
#include "usbg/usbg_internal.h"
@@ -18,7 +24,7 @@ struct test_function
char *path;
char *name;
- usbg_function_attrs *attrs;
+ void *attrs;
int writable;
};
@@ -231,7 +237,7 @@ void pull_gadget_attrs(struct test_gadget *gadget, usbg_gadget_attrs *attrs);
* @warning Calling usbg_get_function_attrs function whithout this
* preparation and with wrapped i/o may fail.
*/
-void push_function_attrs(struct test_function *func, usbg_function_attrs *attrs);
+void push_function_attrs(struct test_function *func, void *attrs);
/**
* @brief Prepare fake filesystem to set given function attributes
@@ -240,7 +246,7 @@ void push_function_attrs(struct test_function *func, usbg_function_attrs *attrs)
* @warning Calling usbg_set_function_attrs function whithout this
* preparation and with wrapped i/o may fail.
*/
-void pull_function_attrs(struct test_function *func, usbg_function_attrs *attrs);
+void pull_function_attrs(struct test_function *func, void *attrs);
/**
* @brief Get gadget string
@@ -446,8 +452,7 @@ void assert_gadget_attrs_equal(usbg_gadget_attrs *actual,
* @param[in] expected Pointer to expected attributes obejct
* @param[in] type Type of function, which attributes are checked
*/
-void assert_function_attrs_equal(usbg_function_attrs *actual,
- usbg_function_attrs *expected, usbg_f_attrs_type type);
+void assert_function_attrs_equal(void *actual, void *expected, usbg_function_type type);
/**
* @brief Assert that given gadget strings are equal