qcacld-3.0: Use vtable for unit test ioctl

Convert the current hard-coded list of unit-test callbacks in
hdd_we_unit_test() to a vtable. This streamlines future additions.

Change-Id: I216bbb6699ae50eaa96ac559999cb42ba080867c
CRs-Fixed: 2358606
This commit is contained in:
Dustin Brown
2018-11-29 14:28:13 -08:00
committed by nshrivas
parent 9f383bfc0b
commit 7d038e52b4
2 changed files with 61 additions and 29 deletions

View File

@@ -552,21 +552,12 @@ uint32_t dsc_unit_test(void)
{
uint32_t errors = 0;
dsc_debug("Starting dsc component tests");
errors += dsc_test_create_destroy();
errors += dsc_test_driver_trans_blocks();
errors += dsc_test_psoc_trans_blocks();
errors += dsc_test_vdev_trans_blocks();
errors += dsc_test_trans_wait();
if (errors) {
dsc_err("FAIL: %u dsc component tests failed!", errors);
return errors;
}
dsc_info("PASS: dsc component tests passed successfully");
return 0;
return errors;
}

View File

@@ -5388,32 +5388,73 @@ static int iw_setnone_get_threeint(struct net_device *dev,
}
#ifdef WLAN_UNIT_TEST
static int hdd_we_unit_test(struct hdd_context *hdd_ctx, const char *component)
typedef uint32_t (*hdd_ut_callback)(void);
struct hdd_ut_entry {
const hdd_ut_callback callback;
const char *name;
};
struct hdd_ut_entry hdd_ut_entries[] = {
{ .name = "dsc", .callback = dsc_unit_test },
};
#define hdd_for_each_ut_entry(cursor) \
for (cursor = hdd_ut_entries; \
cursor < hdd_ut_entries + ARRAY_SIZE(hdd_ut_entries); \
cursor++)
static struct hdd_ut_entry *hdd_ut_lookup(const char *name)
{
uint32_t errors = 0;
bool all = !component || !component[0];
struct hdd_ut_entry *entry;
if (all)
hdd_info("Starting unit tests for all components");
else
hdd_info("Starting unit tests for component '%s'", component);
if (all || qdf_str_eq(component, "dsc"))
errors += dsc_unit_test();
/* add future tests here */
if (errors) {
hdd_err("Unit tests failed with %u errors", errors);
return -EPERM;
hdd_for_each_ut_entry(entry) {
if (qdf_str_eq(entry->name, name))
return entry;
}
hdd_info("Unit tests passed successfully");
return NULL;
}
return 0;
static uint32_t hdd_ut_single(const struct hdd_ut_entry *entry)
{
uint32_t errors;
hdd_nofl_info("START: '%s'", entry->name);
errors = entry->callback();
if (errors)
hdd_nofl_err("FAIL: '%s' with %u errors", entry->name, errors);
else
hdd_nofl_info("PASS: '%s'", entry->name);
return errors;
}
static int hdd_we_unit_test(struct hdd_context *hdd_ctx, const char *name)
{
struct hdd_ut_entry *entry;
uint32_t errors = 0;
hdd_nofl_info("Unit tests begin");
if (!name || !name[0] || qdf_str_eq(name, "all")) {
hdd_for_each_ut_entry(entry)
errors += hdd_ut_single(entry);
} else {
entry = hdd_ut_lookup(name);
if (entry)
errors += hdd_ut_single(entry);
else
hdd_nofl_err("Unit test '%s' not found", name);
}
hdd_nofl_info("Unit tests complete");
return errors ? -EPERM : 0;
}
#else
static int hdd_we_unit_test(struct hdd_context *hdd_ctx, const char *component)
static int hdd_we_unit_test(struct hdd_context *hdd_ctx, const char *name)
{
return -EOPNOTSUPP;
}