Skip to content

Commit 9bbb11c

Browse files
alan-maguireshuahkh
authored andcommitted
kunit: hide unexported try-catch interface in try-catch-impl.h
Define function as static inline in try-catch-impl.h to allow it to be used in kunit itself and tests. Also remove unused kunit_generic_try_catch Co-developed-by: Knut Omang <[email protected]> Signed-off-by: Knut Omang <[email protected]> Signed-off-by: Alan Maguire <[email protected]> Reviewed-by: Brendan Higgins <[email protected]> Tested-by: Brendan Higgins <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 109fb06 commit 9bbb11c

File tree

5 files changed

+32
-22
lines changed

5 files changed

+32
-22
lines changed

include/kunit/try-catch.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ struct kunit_try_catch {
5353
void *context;
5454
};
5555

56-
void kunit_try_catch_init(struct kunit_try_catch *try_catch,
57-
struct kunit *test,
58-
kunit_try_catch_func_t try,
59-
kunit_try_catch_func_t catch);
60-
6156
void kunit_try_catch_run(struct kunit_try_catch *try_catch, void *context);
6257

6358
void __noreturn kunit_try_catch_throw(struct kunit_try_catch *try_catch);
@@ -67,9 +62,4 @@ static inline int kunit_try_catch_get_result(struct kunit_try_catch *try_catch)
6762
return try_catch->try_result;
6863
}
6964

70-
/*
71-
* Exposed for testing only.
72-
*/
73-
void kunit_generic_try_catch_init(struct kunit_try_catch *try_catch);
74-
7565
#endif /* _KUNIT_TRY_CATCH_H */

lib/kunit/test-test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*/
88
#include <kunit/test.h>
99

10+
#include "try-catch-impl.h"
11+
1012
struct kunit_try_catch_test_context {
1113
struct kunit_try_catch *try_catch;
1214
bool function_called;

lib/kunit/test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
*/
88

99
#include <kunit/test.h>
10-
#include <kunit/try-catch.h>
1110
#include <linux/kernel.h>
1211
#include <linux/sched/debug.h>
1312

1413
#include "string-stream.h"
14+
#include "try-catch-impl.h"
1515

1616
static void kunit_set_failure(struct kunit *test)
1717
{

lib/kunit/try-catch-impl.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Internal kunit try catch implementation to be shared with tests.
4+
*
5+
* Copyright (C) 2019, Google LLC.
6+
* Author: Brendan Higgins <[email protected]>
7+
*/
8+
9+
#ifndef _KUNIT_TRY_CATCH_IMPL_H
10+
#define _KUNIT_TRY_CATCH_IMPL_H
11+
12+
#include <kunit/try-catch.h>
13+
#include <linux/types.h>
14+
15+
struct kunit;
16+
17+
static inline void kunit_try_catch_init(struct kunit_try_catch *try_catch,
18+
struct kunit *test,
19+
kunit_try_catch_func_t try,
20+
kunit_try_catch_func_t catch)
21+
{
22+
try_catch->test = test;
23+
try_catch->try = try;
24+
try_catch->catch = catch;
25+
}
26+
27+
#endif /* _KUNIT_TRY_CATCH_IMPL_H */

lib/kunit/try-catch.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
*/
99

1010
#include <kunit/test.h>
11-
#include <kunit/try-catch.h>
1211
#include <linux/completion.h>
1312
#include <linux/kernel.h>
1413
#include <linux/kthread.h>
1514
#include <linux/sched/sysctl.h>
1615

16+
#include "try-catch-impl.h"
17+
1718
void __noreturn kunit_try_catch_throw(struct kunit_try_catch *try_catch)
1819
{
1920
try_catch->try_result = -EFAULT;
@@ -106,13 +107,3 @@ void kunit_try_catch_run(struct kunit_try_catch *try_catch, void *context)
106107

107108
try_catch->catch(try_catch->context);
108109
}
109-
110-
void kunit_try_catch_init(struct kunit_try_catch *try_catch,
111-
struct kunit *test,
112-
kunit_try_catch_func_t try,
113-
kunit_try_catch_func_t catch)
114-
{
115-
try_catch->test = test;
116-
try_catch->try = try;
117-
try_catch->catch = catch;
118-
}

0 commit comments

Comments
 (0)