kunit: transition: add macro for defining struct kunit_resource/test_resource
Change-Id: I00532f95a806e029c6ac5410f6e3cac3e2506c18
diff --git a/include/test/test-names.h b/include/test/test-names.h
index 6a138d3..821ed6e 100644
--- a/include/test/test-names.h
+++ b/include/test/test-names.h
@@ -3,9 +3,11 @@
#ifdef CONFIG_KUNIT_USE_UPSTREAM_NAMES
#define KUNIT_T kunit
+#define KUNIT_RESOURCE_T kunit_resource
#else
#define KUNIT_T test
+#define KUNIT_RESOURCE_T test_resource
#endif
diff --git a/include/test/test.h b/include/test/test.h
index f0811e2..2011a62 100644
--- a/include/test/test.h
+++ b/include/test/test.h
@@ -17,7 +17,7 @@
#include <test/try-catch.h>
/**
- * struct test_resource - represents a *test managed resource*
+ * struct KUNIT_RESOURCE_T - represents a *test managed resource*
* @allocation: for the user to store arbitrary data.
* @free: a user supplied function to free the resource. Populated by
* test_alloc_resource().
@@ -34,7 +34,7 @@
* gfp_t gfp;
* };
*
- * static int test_kmalloc_init(struct test_resource *res, void *context)
+ * static int test_kmalloc_init(struct KUNIT_RESOURCE_T *res, void *context)
* {
* struct test_kmalloc_params *params = context;
* res->allocation = kmalloc(params->size, params->gfp);
@@ -45,7 +45,7 @@
* return 0;
* }
*
- * static void test_kmalloc_free(struct test_resource *res)
+ * static void test_kmalloc_free(struct KUNIT_RESOURCE_T *res)
* {
* kfree(res->allocation);
* }
@@ -53,7 +53,7 @@
* void *test_kmalloc(struct KUNIT_T *test, size_t size, gfp_t gfp)
* {
* struct test_kmalloc_params params;
- * struct test_resource *res;
+ * struct KUNIT_RESOURCE_T *res;
*
* params.size = size;
* params.gfp = gfp;
@@ -68,9 +68,9 @@
* return NULL;
* }
*/
-struct test_resource {
+struct KUNIT_RESOURCE_T {
void *allocation;
- void (*free)(struct test_resource *res);
+ void (*free)(struct KUNIT_RESOURCE_T *res);
/* private: internal use only. */
struct list_head node;
};
@@ -250,16 +250,16 @@
* @context: for the user to pass in arbitrary data.
*
* Allocates a *test managed resource*, a resource which will automatically be
- * cleaned up at the end of a test case. See &struct test_resource for an
+ * cleaned up at the end of a test case. See &struct KUNIT_RESOURCE_T for an
* example.
*/
-struct test_resource *test_alloc_resource(struct KUNIT_T *test,
- int (*init)(struct test_resource *,
+struct KUNIT_RESOURCE_T *test_alloc_resource(struct KUNIT_T *test,
+ int (*init)(struct KUNIT_RESOURCE_T *,
void *),
- void (*free)(struct test_resource *),
+ void (*free)(struct KUNIT_RESOURCE_T *),
void *context);
-void test_free_resource(struct KUNIT_T *test, struct test_resource *res);
+void test_free_resource(struct KUNIT_T *test, struct KUNIT_RESOURCE_T *res);
/**
* test_kmalloc() - Just like kmalloc() except the allocation is *test managed*.
@@ -269,7 +269,7 @@
*
* Just like `kmalloc(...)`, except the allocation is managed by the test case
* and is automatically cleaned up after the test case concludes. See &struct
- * test_resource for more information.
+ * KUNIT_RESOURCE_T for more information.
*/
void *test_kmalloc(struct KUNIT_T *test, size_t size, gfp_t gfp);
diff --git a/test/test-stream.c b/test/test-stream.c
index 7861bd3..12ecef2 100644
--- a/test/test-stream.c
+++ b/test/test-stream.c
@@ -81,7 +81,7 @@
this->clear(this);
}
-static int test_stream_init(struct test_resource *res, void *context)
+static int test_stream_init(struct KUNIT_RESOURCE_T *res, void *context)
{
struct test_stream *stream;
struct KUNIT_T *test = context;
@@ -105,7 +105,7 @@
return 0;
}
-static void test_stream_free(struct test_resource *res)
+static void test_stream_free(struct KUNIT_RESOURCE_T *res)
{
struct test_stream *stream = res->allocation;
@@ -121,7 +121,7 @@
struct test_stream *test_new_stream(struct KUNIT_T *test)
{
- struct test_resource *res;
+ struct KUNIT_RESOURCE_T *res;
res = test_alloc_resource(test,
test_stream_init,
diff --git a/test/test-test.c b/test/test-test.c
index 6e82e36..2c9d72d 100644
--- a/test/test-test.c
+++ b/test/test-test.c
@@ -7,7 +7,7 @@
*/
#include <test/test.h>
-typedef void (*test_resource_free_t)(struct test_resource *);
+typedef void (*test_resource_free_t)(struct KUNIT_RESOURCE_T *);
/*
* Context for testing test managed resources
@@ -18,7 +18,7 @@
bool is_resource_initialized;
};
-static int fake_resource_init(struct test_resource *res, void *context)
+static int fake_resource_init(struct KUNIT_RESOURCE_T *res, void *context)
{
struct test_test_context *ctx = context;
@@ -27,7 +27,7 @@
return 0;
}
-static void fake_resource_free(struct test_resource *res)
+static void fake_resource_free(struct KUNIT_RESOURCE_T *res)
{
bool *is_resource_initialized = res->allocation;
@@ -46,7 +46,7 @@
static void test_test_alloc_resource(struct KUNIT_T *test)
{
struct test_test_context *ctx = test->priv;
- struct test_resource *res;
+ struct KUNIT_RESOURCE_T *res;
res = test_alloc_resource(&ctx->test,
fake_resource_init,
@@ -64,7 +64,7 @@
static void test_test_free_resource(struct KUNIT_T *test)
{
struct test_test_context *ctx = test->priv;
- struct test_resource *res = test_alloc_resource(&ctx->test,
+ struct KUNIT_RESOURCE_T *res = test_alloc_resource(&ctx->test,
fake_resource_init,
fake_resource_free,
ctx);
@@ -80,7 +80,7 @@
int i;
const int num_res = 5;
struct test_test_context *ctx = test->priv;
- struct test_resource *resources[num_res];
+ struct KUNIT_RESOURCE_T *resources[num_res];
for (i = 0; i < num_res; i++) {
resources[i] = test_alloc_resource(&ctx->test,
diff --git a/test/test.c b/test/test.c
index 3077822..d9bbbae 100644
--- a/test/test.c
+++ b/test/test.c
@@ -330,13 +330,13 @@
return 0;
}
-struct test_resource *test_alloc_resource(struct KUNIT_T *test,
- int (*init)(struct test_resource *,
+struct KUNIT_RESOURCE_T *test_alloc_resource(struct KUNIT_T *test,
+ int (*init)(struct KUNIT_RESOURCE_T *,
void *),
- void (*free)(struct test_resource *),
+ void (*free)(struct KUNIT_RESOURCE_T *),
void *context)
{
- struct test_resource *res;
+ struct KUNIT_RESOURCE_T *res;
int ret;
res = kzalloc(sizeof(*res), GFP_KERNEL);
@@ -353,7 +353,7 @@
return res;
}
-void test_free_resource(struct KUNIT_T *test, struct test_resource *res)
+void test_free_resource(struct KUNIT_T *test, struct KUNIT_RESOURCE_T *res)
{
res->free(res);
list_del(&res->node);
@@ -365,7 +365,7 @@
gfp_t gfp;
};
-static int test_kmalloc_init(struct test_resource *res, void *context)
+static int test_kmalloc_init(struct KUNIT_RESOURCE_T *res, void *context)
{
struct test_kmalloc_params *params = context;
@@ -376,7 +376,7 @@
return 0;
}
-static void test_kmalloc_free(struct test_resource *res)
+static void test_kmalloc_free(struct KUNIT_RESOURCE_T *res)
{
kfree(res->allocation);
}
@@ -384,7 +384,7 @@
void *test_kmalloc(struct KUNIT_T *test, size_t size, gfp_t gfp)
{
struct test_kmalloc_params params;
- struct test_resource *res;
+ struct KUNIT_RESOURCE_T *res;
params.size = size;
params.gfp = gfp;
@@ -402,7 +402,7 @@
void test_cleanup(struct KUNIT_T *test)
{
- struct test_resource *resource, *resource_safe;
+ struct KUNIT_RESOURCE_T *resource, *resource_safe;
list_for_each_entry_safe(resource,
resource_safe,