Skip to content

Commit

Permalink
kunit: hide unexported try-catch interface in try-catch-impl.h
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
alan-maguire authored and shuahkh committed Jan 9, 2020
1 parent 109fb06 commit 9bbb11c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
10 changes: 0 additions & 10 deletions include/kunit/try-catch.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ struct kunit_try_catch {
void *context;
};

void kunit_try_catch_init(struct kunit_try_catch *try_catch,
struct kunit *test,
kunit_try_catch_func_t try,
kunit_try_catch_func_t catch);

void kunit_try_catch_run(struct kunit_try_catch *try_catch, void *context);

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

/*
* Exposed for testing only.
*/
void kunit_generic_try_catch_init(struct kunit_try_catch *try_catch);

#endif /* _KUNIT_TRY_CATCH_H */
2 changes: 2 additions & 0 deletions lib/kunit/test-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
#include <kunit/test.h>

#include "try-catch-impl.h"

struct kunit_try_catch_test_context {
struct kunit_try_catch *try_catch;
bool function_called;
Expand Down
2 changes: 1 addition & 1 deletion lib/kunit/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
*/

#include <kunit/test.h>
#include <kunit/try-catch.h>
#include <linux/kernel.h>
#include <linux/sched/debug.h>

#include "string-stream.h"
#include "try-catch-impl.h"

static void kunit_set_failure(struct kunit *test)
{
Expand Down
27 changes: 27 additions & 0 deletions lib/kunit/try-catch-impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Internal kunit try catch implementation to be shared with tests.
*
* Copyright (C) 2019, Google LLC.
* Author: Brendan Higgins <[email protected]>
*/

#ifndef _KUNIT_TRY_CATCH_IMPL_H
#define _KUNIT_TRY_CATCH_IMPL_H

#include <kunit/try-catch.h>
#include <linux/types.h>

struct kunit;

static inline void kunit_try_catch_init(struct kunit_try_catch *try_catch,
struct kunit *test,
kunit_try_catch_func_t try,
kunit_try_catch_func_t catch)
{
try_catch->test = test;
try_catch->try = try;
try_catch->catch = catch;
}

#endif /* _KUNIT_TRY_CATCH_IMPL_H */
13 changes: 2 additions & 11 deletions lib/kunit/try-catch.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
*/

#include <kunit/test.h>
#include <kunit/try-catch.h>
#include <linux/completion.h>
#include <linux/kernel.h>
#include <linux/kthread.h>
#include <linux/sched/sysctl.h>

#include "try-catch-impl.h"

void __noreturn kunit_try_catch_throw(struct kunit_try_catch *try_catch)
{
try_catch->try_result = -EFAULT;
Expand Down Expand Up @@ -106,13 +107,3 @@ void kunit_try_catch_run(struct kunit_try_catch *try_catch, void *context)

try_catch->catch(try_catch->context);
}

void kunit_try_catch_init(struct kunit_try_catch *try_catch,
struct kunit *test,
kunit_try_catch_func_t try,
kunit_try_catch_func_t catch)
{
try_catch->test = test;
try_catch->try = try;
try_catch->catch = catch;
}

0 comments on commit 9bbb11c

Please sign in to comment.