Ver Fonte

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
Dustin Brown há 6 anos atrás
pai
commit
7d038e52b4
2 ficheiros alterados com 57 adições e 25 exclusões
  1. 1 10
      components/dsc/test/wlan_dsc_test.c
  2. 56 15
      core/hdd/src/wlan_hdd_wext.c

+ 1 - 10
components/dsc/test/wlan_dsc_test.c

@@ -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;
 }
 

+ 56 - 15
core/hdd/src/wlan_hdd_wext.c

@@ -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;
+
+	hdd_for_each_ut_entry(entry) {
+		if (qdf_str_eq(entry->name, name))
+			return entry;
+	}
+
+	return NULL;
+}
 
-	if (all)
-		hdd_info("Starting unit tests for all components");
+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_info("Starting unit tests for component '%s'", component);
+		hdd_nofl_info("PASS: '%s'", entry->name);
 
-	if (all || qdf_str_eq(component, "dsc"))
-		errors += dsc_unit_test();
+	return errors;
+}
 
-	/* add future tests here */
+static int hdd_we_unit_test(struct hdd_context *hdd_ctx, const char *name)
+{
+	struct hdd_ut_entry *entry;
+	uint32_t errors = 0;
 
-	if (errors) {
-		hdd_err("Unit tests failed with %u errors", errors);
-		return -EPERM;
+	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_info("Unit tests passed successfully");
+	hdd_nofl_info("Unit tests complete");
 
-	return 0;
+	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;
 }