lists.linaro.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
List overview
Download
Linux-kselftest-mirror
August 2020
----- 2024 -----
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
linux-kselftest-mirror@lists.linaro.org
88 participants
115 discussions
Start a n
N
ew thread
[PATCH 1/2] kunit: expect failures from dynamic analysis tools
by Uriel Guajardo
Adds support to KUnit for failure expectation for specific tools. Uses named KUnit resources to keep track of whether or not a failure expectation has been set by the user. - Adds a generic KUNIT_EXPECT_TOOL_FAIL macro that can expect failure from any supported tool that uses the same identifying name - Adds kunit_fail_from_tool which is used to flag failures for specific tools. Requires "kunit: suppport failure from dynamic analysis tools":
https://lore.kernel.org/linux-kselftest/20200813205722.1384108-1-urielguaja…
Signed-off-by: Uriel Guajardo <urielguajardo(a)google.com> --- include/kunit/test-bug.h | 53 ++++++++++++++++++++++++++++++++++++++++ include/kunit/test.h | 5 ++++ lib/kunit/test.c | 46 +++++++++++++++++++++++++++++----- 3 files changed, 98 insertions(+), 6 deletions(-) diff --git a/include/kunit/test-bug.h b/include/kunit/test-bug.h index 283c19ec328f..383198f70cb5 100644 --- a/include/kunit/test-bug.h +++ b/include/kunit/test-bug.h @@ -9,16 +9,69 @@ #ifndef _KUNIT_TEST_BUG_H #define _KUNIT_TEST_BUG_H +/** + * struct kunit_expectation - represents expectations in KUnit, specifically + * used to keep track of failure expectations from analysis tools + */ +struct kunit_expectation { + bool expected; + bool found; +}; + #if IS_ENABLED(CONFIG_KUNIT) extern void kunit_fail_current_test(void); +/** + * kunit_fail_from_tool() - Fails the currently running KUnit tests under the + * given tool name. + * + * Note: Uses a named KUnit resource to track state. Do not use the name + * KUNIT_TOOL_{tool} for KUnit resources outside of here. + */ +#define kunit_fail_from_tool(tool) \ + if (current->kunit_test) \ + kunit_tool_fail(current->kunit_test, #tool,\ + "KUNIT_TOOL_" #tool) + +/** + * kunit_tool_expectation() - Returns the kunit_expectation for the given + * tool. If it cannot find the expectation, it creates an expectation and + * returns it. + * + * Note: Uses a named KUnit resource to track state. Do not use the name + * KUNIT_TOOL_{tool} for KUnit resources outside of here. + */ +#define kunit_tool_expectation(test, tool) \ + kunit_find_expectation(test, "KUNIT_TOOL_" #tool) + + +/** + * KUNIT_EXPECT_TOOL_FAIL() - Fails the currently running KUnit test if the + * condition does not cause an error within the given tool. + * + * Note: 'tool' must be consistent with the name specified in + * kunit_fail_from_tool(). If the tool fails KUnit using another name, KUnit + * will treat it as a separate tool. + */ +#define KUNIT_EXPECT_TOOL_FAIL(test, condition, tool) do { \ + struct kunit_expectation *data = kunit_tool_expectation(test, tool);\ + data->expected = true; \ + data->found = false; \ + condition; \ + KUNIT_EXPECT_EQ(test, data->expected, data->found); \ + data->expected = false; \ + data->found = false; \ +} while (0) + #else static inline void kunit_fail_current_test(void) { } +#define kunit_fail_from_tool(tool) do { } while (0) + #endif #endif /* _KUNIT_TEST_BUG_H */ diff --git a/include/kunit/test.h b/include/kunit/test.h index 81bf43a1abda..3da8e17ee32b 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -511,6 +511,11 @@ static inline int kunit_destroy_named_resource(struct kunit *test, */ void kunit_remove_resource(struct kunit *test, struct kunit_resource *res); +void kunit_tool_fail(struct kunit *test, char *tool_name, char *resource_name); + +struct kunit_expectation *kunit_find_expectation(struct kunit *test, + char *resource_name); + /** * kunit_kmalloc() - Like kmalloc() except the allocation is *test managed*. * @test: The test context object. diff --git a/lib/kunit/test.c b/lib/kunit/test.c index d8189d827368..458d1ad2daf2 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -22,6 +22,45 @@ void kunit_fail_current_test(void) kunit_set_failure(current->kunit_test); } +static void kunit_data_free(struct kunit_resource *res) +{ + kfree(res->data); +} + +struct kunit_expectation *kunit_find_expectation(struct kunit *test, + char *resource_name) +{ + struct kunit_resource *resource; + struct kunit_expectation *expectation; + + struct kunit_resource *existing = kunit_find_named_resource( + test, resource_name); + if (!existing) { + expectation = kzalloc(sizeof(*expectation), GFP_KERNEL); + resource = kunit_alloc_and_get_resource(test, NULL, + kunit_data_free, GFP_KERNEL, + expectation); + resource->name = resource_name; + kunit_put_resource(resource); + return expectation; + } + kunit_put_resource(existing); + return existing->data; +} +EXPORT_SYMBOL_GPL(kunit_find_expectation); + +void kunit_tool_fail(struct kunit *test, char *tool_name, char *resource_name) +{ + struct kunit_expectation *data = kunit_find_expectation(test, + resource_name); + if (!data->expected) { + kunit_warn(test, "Dynamic analysis tool failure from %s", + tool_name); + return kunit_fail_current_test(); + } + data->found = true; +} + static void kunit_print_tap_version(void) { static bool kunit_has_printed_tap_version; @@ -538,11 +577,6 @@ static int kunit_kmalloc_init(struct kunit_resource *res, void *context) return 0; } -static void kunit_kmalloc_free(struct kunit_resource *res) -{ - kfree(res->data); -} - void *kunit_kmalloc(struct kunit *test, size_t size, gfp_t gfp) { struct kunit_kmalloc_params params = { @@ -552,7 +586,7 @@ void *kunit_kmalloc(struct kunit *test, size_t size, gfp_t gfp) return kunit_alloc_resource(test, kunit_kmalloc_init, - kunit_kmalloc_free, + kunit_data_free, gfp, ¶ms); } -- 2.28.0.297.g1956fa8f8d-goog
3 years, 8 months
1
1
0
0
[PATCH] kunit: Customize KUNIT_EXCEPT/KUNIT_ASSERT Expected messages
by Vitor Massaru Iha
In some cases, to maintain the consistency of the Expected messages with the original runtime test, it is necessary to customize the Expected messages on KUnit. As an example test_overflow conversion to KUnit (I added 1, p->s_of+1, just to fail the test). Using KUNIT_EXPECT_EQ: Expected _of == p->s_of+1, but _of == 0 p->s_of+1 == 1 not ok 1 - overflow_calculation_test ok 2 - overflow_shift_test Using KUNIT_EXPECT_EQ_CUSTOM_MSG: Expected 0 + 0 to not overflow (type u8) not ok 1 - overflow_calculation_test Which is more similar to the error message of the original test. Signed-off-by: Vitor Massaru Iha <vitor(a)massaru.org> --- include/kunit/assert.h | 8 ++- include/kunit/test.h | 151 +++++++++++++++++++++++++++++++++++++++-- lib/kunit/assert.c | 34 ++++++---- 3 files changed, 172 insertions(+), 21 deletions(-) diff --git a/include/kunit/assert.h b/include/kunit/assert.h index ad889b539ab3..b3c25b4420c8 100644 --- a/include/kunit/assert.h +++ b/include/kunit/assert.h @@ -204,6 +204,7 @@ struct kunit_binary_assert { long long left_value; const char *right_text; long long right_value; + bool custom_msg; }; void kunit_binary_assert_format(const struct kunit_assert *assert, @@ -219,6 +220,7 @@ void kunit_binary_assert_format(const struct kunit_assert *assert, * @left_val: The actual evaluated value of the expression in the left slot. * @right_str: A string representation of the expression in the right slot. * @right_val: The actual evaluated value of the expression in the right slot. + * @custom_msg_bool: Show a custom expect message instead the default message. * * Initializes a &struct kunit_binary_assert. Intended to be used in * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. @@ -229,7 +231,8 @@ void kunit_binary_assert_format(const struct kunit_assert *assert, left_str, \ left_val, \ right_str, \ - right_val) { \ + right_val, \ + custom_msg_bool) { \ .assert = KUNIT_INIT_ASSERT_STRUCT(test, \ type, \ kunit_binary_assert_format), \ @@ -237,7 +240,8 @@ void kunit_binary_assert_format(const struct kunit_assert *assert, .left_text = left_str, \ .left_value = left_val, \ .right_text = right_str, \ - .right_value = right_val \ + .right_value = right_val, \ + .custom_msg = custom_msg_bool, \ } /** diff --git a/include/kunit/test.h b/include/kunit/test.h index 59f3144f009a..ec821a57ec5b 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -699,6 +699,7 @@ void kunit_do_assertion(struct kunit *test, left, \ op, \ right, \ + custom_msg_bool, \ fmt, \ ...) \ do { \ @@ -715,7 +716,8 @@ do { \ #left, \ __left, \ #right, \ - __right), \ + __right, \ + custom_msg_bool), \ fmt, \ ##__VA_ARGS__); \ } while (0) @@ -726,6 +728,7 @@ do { \ assert_type, \ left, \ right, \ + custom_msg_bool, \ fmt, \ ...) \ KUNIT_BASE_BINARY_ASSERTION(test, \ @@ -733,6 +736,7 @@ do { \ ASSERT_CLASS_INIT, \ assert_type, \ left, ==, right, \ + custom_msg_bool, \ fmt, \ ##__VA_ARGS__) @@ -742,6 +746,7 @@ do { \ assert_type, \ left, \ right, \ + custom_msg_bool, \ fmt, \ ...) \ KUNIT_BASE_BINARY_ASSERTION(test, \ @@ -749,6 +754,7 @@ do { \ ASSERT_CLASS_INIT, \ assert_type, \ left, !=, right, \ + custom_msg_bool, \ fmt, \ ##__VA_ARGS__) @@ -765,6 +771,7 @@ do { \ ASSERT_CLASS_INIT, \ assert_type, \ left, <, right, \ + custom_msg_bool, \ fmt, \ ##__VA_ARGS__) @@ -774,6 +781,7 @@ do { \ assert_type, \ left, \ right, \ + custom_msg_bool, \ fmt, \ ...) \ KUNIT_BASE_BINARY_ASSERTION(test, \ @@ -781,6 +789,7 @@ do { \ ASSERT_CLASS_INIT, \ assert_type, \ left, <=, right, \ + custom_msg_bool, \ fmt, \ ##__VA_ARGS__) @@ -797,6 +806,7 @@ do { \ ASSERT_CLASS_INIT, \ assert_type, \ left, >, right, \ + custom_msg_bool, \ fmt, \ ##__VA_ARGS__) @@ -813,16 +823,23 @@ do { \ ASSERT_CLASS_INIT, \ assert_type, \ left, >=, right, \ + custom_msg_bool, \ fmt, \ ##__VA_ARGS__) -#define KUNIT_BINARY_EQ_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ +#define KUNIT_BINARY_EQ_MSG_ASSERTION(test, \ + assert_type, \ + left, right, \ + custom_msg_bool, \ + fmt, \ + ...) \ KUNIT_BASE_EQ_MSG_ASSERTION(test, \ kunit_binary_assert, \ KUNIT_INIT_BINARY_ASSERT_STRUCT, \ assert_type, \ left, \ right, \ + custom_msg_bool, \ fmt, \ ##__VA_ARGS__) @@ -831,6 +848,7 @@ do { \ assert_type, \ left, \ right, \ + false, \ NULL) #define KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \ @@ -862,6 +880,18 @@ do { \ assert_type, \ left, \ right, \ + false, \ + fmt, \ + ##__VA_ARGS__) + +#define KUNIT_BINARY_NE_CUSTOM_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ + KUNIT_BASE_NE_MSG_ASSERTION(test, \ + kunit_binary_assert, \ + KUNIT_INIT_BINARY_ASSERT_STRUCT, \ + assert_type, \ + left, \ + right, \ + true, \ fmt, \ ##__VA_ARGS__) @@ -870,6 +900,7 @@ do { \ assert_type, \ left, \ right, \ + false, \ NULL) #define KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \ @@ -904,11 +935,12 @@ do { \ fmt, \ ##__VA_ARGS__) -#define KUNIT_BINARY_LT_ASSERTION(test, assert_type, left, right) \ +#define KUNIT_BINARY_LT_ASSERTION(test, assert_type, left, right, custom_msg_bool)\ KUNIT_BINARY_LT_MSG_ASSERTION(test, \ assert_type, \ left, \ right, \ + custom_msg_bool, \ NULL) #define KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test, \ @@ -923,6 +955,7 @@ do { \ assert_type, \ left, \ right, \ + false, \ fmt, \ ##__VA_ARGS__) @@ -933,13 +966,20 @@ do { \ right, \ NULL) -#define KUNIT_BINARY_LE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ +#define KUNIT_BINARY_LE_MSG_ASSERTION(test, \ + assert_type, \ + left, \ + right, \ + custom_msg_bool, \ + fmt, \ + ...) \ KUNIT_BASE_LE_MSG_ASSERTION(test, \ kunit_binary_assert, \ KUNIT_INIT_BINARY_ASSERT_STRUCT, \ assert_type, \ left, \ right, \ + custom_msg_bool, \ fmt, \ ##__VA_ARGS__) @@ -948,6 +988,7 @@ do { \ assert_type, \ left, \ right, \ + false, \ NULL) #define KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test, \ @@ -972,13 +1013,20 @@ do { \ right, \ NULL) -#define KUNIT_BINARY_GT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ +#define KUNIT_BINARY_GT_MSG_ASSERTION(test, \ + assert_type, \ + left, \ + right, \ + custom_msg_bool, \ + fmt, \ + ...) \ KUNIT_BASE_GT_MSG_ASSERTION(test, \ kunit_binary_assert, \ KUNIT_INIT_BINARY_ASSERT_STRUCT, \ assert_type, \ left, \ right, \ + custom_msg_bool, \ fmt, \ ##__VA_ARGS__) @@ -1001,6 +1049,7 @@ do { \ assert_type, \ left, \ right, \ + custom_msg_bool, \ fmt, \ ##__VA_ARGS__) @@ -1011,7 +1060,13 @@ do { \ right, \ NULL) -#define KUNIT_BINARY_GE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ +#define KUNIT_BINARY_GE_MSG_ASSERTION(test, \ + assert_type, \ + left, \ + right, \ + custom_msg_bool, \ + fmt, \ + ...) \ KUNIT_BASE_GE_MSG_ASSERTION(test, \ kunit_binary_assert, \ KUNIT_INIT_BINARY_ASSERT_STRUCT, \ @@ -1026,12 +1081,14 @@ do { \ assert_type, \ left, \ right, \ + false, \ NULL) #define KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test, \ assert_type, \ left, \ right, \ + custom_msg_bool, \ fmt, \ ...) \ KUNIT_BASE_GE_MSG_ASSERTION(test, \ @@ -1040,6 +1097,7 @@ do { \ assert_type, \ left, \ right, \ + custom_msg_bool, \ fmt, \ ##__VA_ARGS__) @@ -1197,6 +1255,16 @@ do { \ KUNIT_EXPECTATION, \ left, \ right, \ + false, \ + fmt, \ + ##__VA_ARGS__) + +#define KUNIT_EXPECT_EQ_CUSTOM_MSG(test, left, right, fmt, ...) \ + KUNIT_BINARY_EQ_MSG_ASSERTION(test, \ + KUNIT_EXPECTATION, \ + left, \ + right, \ + true, \ fmt, \ ##__VA_ARGS__) @@ -1222,9 +1290,18 @@ do { \ KUNIT_EXPECTATION, \ left, \ right, \ + false, \ fmt, \ ##__VA_ARGS__) +#define KUNIT_EXPECT_PTR_EQ_CUSTOM_MSG(test, left, right, fmt, ...) \ + KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \ + KUNIT_EXPECTATION, \ + left, \ + right, \ + true, \ + fmt, \ + ##__VA_ARGS__) /** * KUNIT_EXPECT_NE() - An expectation that @left and @right are not equal. * @test: The test context object. @@ -1244,6 +1321,16 @@ do { \ KUNIT_EXPECTATION, \ left, \ right, \ + false, \ + fmt, \ + ##__VA_ARGS__) + +#define KUNIT_EXPECT_NE_CUSTOM_MSG(test, left, right, fmt, ...) \ + KUNIT_BINARY_NE_MSG_ASSERTION(test, \ + KUNIT_EXPECTATION, \ + left, \ + right, \ + true, \ fmt, \ ##__VA_ARGS__) @@ -1269,6 +1356,7 @@ do { \ KUNIT_EXPECTATION, \ left, \ right, \ + false, \ fmt, \ ##__VA_ARGS__) @@ -1313,6 +1401,16 @@ do { \ KUNIT_EXPECTATION, \ left, \ right, \ + false, \ + fmt, \ + ##__VA_ARGS__) + +#define KUNIT_EXPECT_LE_CUSTOM_MSG(test, left, right, fmt, ...) \ + KUNIT_BINARY_LE_MSG_ASSERTION(test, \ + KUNIT_EXPECTATION, \ + left, \ + right, \ + true, \ fmt, \ ##__VA_ARGS__) @@ -1467,6 +1565,8 @@ do { \ fmt, \ ##__VA_ARGS__) +//#define KUNIT_ASSERT_EQ_TYPE(test, ) + /** * KUNIT_ASSERT_EQ() - Sets an assertion that @left and @right are equal. * @test: The test context object. @@ -1485,6 +1585,16 @@ do { \ KUNIT_ASSERTION, \ left, \ right, \ + false, \ + fmt, \ + ##__VA_ARGS__) + +#define KUNIT_ASSERT_EQ_CUSTOM_MSG(test, left, right, fmt, ...) \ + KUNIT_BINARY_EQ_MSG_ASSERTION(test, \ + KUNIT_ASSERTION, \ + left, \ + right, \ + true, \ fmt, \ ##__VA_ARGS__) @@ -1506,9 +1616,18 @@ do { \ KUNIT_ASSERTION, \ left, \ right, \ + false, \ fmt, \ ##__VA_ARGS__) +#define KUNIT_ASSERT_PTR_EQ_CUSTOM_MSG(test, left, right, fmt, ...) \ + KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \ + KUNIT_ASSERTION, \ + left, \ + right, \ + true, \ + fmt, \ + ##__VA_ARGS__) /** * KUNIT_ASSERT_NE() - An assertion that @left and @right are not equal. * @test: The test context object. @@ -1527,6 +1646,7 @@ do { \ KUNIT_ASSERTION, \ left, \ right, \ + false, \ fmt, \ ##__VA_ARGS__) @@ -1549,6 +1669,7 @@ do { \ KUNIT_ASSERTION, \ left, \ right, \ + false, \ fmt, \ ##__VA_ARGS__) /** @@ -1594,6 +1715,15 @@ do { \ fmt, \ ##__VA_ARGS__) +#define KUNIT_ASSERT_LE_CUSTOM_MSG(test, left, right, fmt, ...) \ + KUNIT_BINARY_LE_MSG_ASSERTION(test, \ + KUNIT_ASSERTION, \ + left, \ + right, \ + true, \ + fmt, \ + ##__VA_ARGS__) + /** * KUNIT_ASSERT_GT() - An assertion that @left is greater than @right. * @test: The test context object. @@ -1638,6 +1768,15 @@ do { \ fmt, \ ##__VA_ARGS__) +#define KUNIT_ASSERT_GE_CUSTOM_MSG(test, left, right, fmt, ...) \ + KUNIT_BINARY_GE_MSG_ASSERTION(test, \ + KUNIT_ASSERTION, \ + left, \ + right, \ + true, \ + fmt, \ + ##__VA_ARGS__) + /** * KUNIT_ASSERT_STREQ() - An assertion that strings @left and @right are equal. * @test: The test context object. diff --git a/lib/kunit/assert.c b/lib/kunit/assert.c index 33acdaa28a7d..202f9fdeed0e 100644 --- a/lib/kunit/assert.c +++ b/lib/kunit/assert.c @@ -32,8 +32,14 @@ EXPORT_SYMBOL_GPL(kunit_base_assert_format); void kunit_assert_print_msg(const struct kunit_assert *assert, struct string_stream *stream) { - if (assert->message.fmt) - string_stream_add(stream, "\n%pV", &assert->message); + struct kunit_binary_assert *binary_assert = container_of( + assert, struct kunit_binary_assert, assert); + if (assert->message.fmt) { + if (binary_assert->custom_msg == false) + string_stream_add(stream, "\n" KUNIT_SUBSUBTEST_INDENT "%pV", &assert->message); + else + string_stream_add(stream, KUNIT_SUBTEST_INDENT "%pV", &assert->message); + } } EXPORT_SYMBOL_GPL(kunit_assert_print_msg); @@ -92,17 +98,19 @@ void kunit_binary_assert_format(const struct kunit_assert *assert, assert, struct kunit_binary_assert, assert); kunit_base_assert_format(assert, stream); - string_stream_add(stream, - KUNIT_SUBTEST_INDENT "Expected %s %s %s, but\n", - binary_assert->left_text, - binary_assert->operation, - binary_assert->right_text); - string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n", - binary_assert->left_text, - binary_assert->left_value); - string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld", - binary_assert->right_text, - binary_assert->right_value); + if (binary_assert->custom_msg == false) { + string_stream_add(stream, + KUNIT_SUBTEST_INDENT "Expected %s %s %s, but\n", + binary_assert->left_text, + binary_assert->operation, + binary_assert->right_text); + string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n", + binary_assert->left_text, + binary_assert->left_value); + string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld", + binary_assert->right_text, + binary_assert->right_value); + } kunit_assert_print_msg(assert, stream); } EXPORT_SYMBOL_GPL(kunit_binary_assert_format); base-commit: d43c7fb05765152d4d4a39a8ef957c4ea14d8847 -- 2.26.2
3 years, 8 months
2
2
0
0
[PATCH bpf-next 6/6] selftests: bpf: test sockmap update from BPF
by Lorenz Bauer
Add a test which copies a socket from a sockmap into another sockmap or sockhash. This excercises bpf_map_update_elem support from BPF context. Compare the socket cookies from source and destination to ensure that the copy succeeded. Signed-off-by: Lorenz Bauer <lmb(a)cloudflare.com> --- .../selftests/bpf/prog_tests/sockmap_basic.c | 76 +++++++++++++++++++ .../selftests/bpf/progs/test_sockmap_copy.c | 48 ++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/test_sockmap_copy.c diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c index 96e7b7f84c65..d30cabc00e9e 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c @@ -4,6 +4,7 @@ #include "test_progs.h" #include "test_skmsg_load_helpers.skel.h" +#include "test_sockmap_copy.skel.h" #define TCP_REPAIR 19 /* TCP sock is under repair right now */ @@ -101,6 +102,77 @@ static void test_skmsg_helpers(enum bpf_map_type map_type) test_skmsg_load_helpers__destroy(skel); } +static void test_sockmap_copy(enum bpf_map_type map_type) +{ + struct bpf_prog_test_run_attr attr; + struct test_sockmap_copy *skel; + __u64 src_cookie, dst_cookie; + int err, prog, s, src, dst; + const __u32 zero = 0; + char dummy[14] = {0}; + + s = connected_socket_v4(); + if (CHECK_FAIL(s == -1)) + return; + + skel = test_sockmap_copy__open_and_load(); + if (CHECK_FAIL(!skel)) { + close(s); + perror("test_sockmap_copy__open_and_load"); + return; + } + + prog = bpf_program__fd(skel->progs.copy_sock_map); + src = bpf_map__fd(skel->maps.src); + if (map_type == BPF_MAP_TYPE_SOCKMAP) + dst = bpf_map__fd(skel->maps.dst_sock_map); + else + dst = bpf_map__fd(skel->maps.dst_sock_hash); + + err = bpf_map_update_elem(src, &zero, &s, BPF_NOEXIST); + if (CHECK_FAIL(err)) { + perror("bpf_map_update"); + goto out; + } + + err = bpf_map_lookup_elem(src, &zero, &src_cookie); + if (CHECK_FAIL(err)) { + perror("bpf_map_lookup_elem(src)"); + goto out; + } + + attr = (struct bpf_prog_test_run_attr){ + .prog_fd = prog, + .repeat = 1, + .data_in = dummy, + .data_size_in = sizeof(dummy), + }; + + err = bpf_prog_test_run_xattr(&attr); + if (err) { + test__fail(); + perror("bpf_prog_test_run"); + goto out; + } else if (!attr.retval) { + PRINT_FAIL("bpf_prog_test_run: program returned %u\n", + attr.retval); + goto out; + } + + err = bpf_map_lookup_elem(dst, &zero, &dst_cookie); + if (CHECK_FAIL(err)) { + perror("bpf_map_lookup_elem(dst)"); + goto out; + } + + if (dst_cookie != src_cookie) + PRINT_FAIL("cookie %llu != %llu\n", dst_cookie, src_cookie); + +out: + close(s); + test_sockmap_copy__destroy(skel); +} + void test_sockmap_basic(void) { if (test__start_subtest("sockmap create_update_free")) @@ -111,4 +183,8 @@ void test_sockmap_basic(void) test_skmsg_helpers(BPF_MAP_TYPE_SOCKMAP); if (test__start_subtest("sockhash sk_msg load helpers")) test_skmsg_helpers(BPF_MAP_TYPE_SOCKHASH); + if (test__start_subtest("sockmap copy")) + test_sockmap_copy(BPF_MAP_TYPE_SOCKMAP); + if (test__start_subtest("sockhash copy")) + test_sockmap_copy(BPF_MAP_TYPE_SOCKHASH); } diff --git a/tools/testing/selftests/bpf/progs/test_sockmap_copy.c b/tools/testing/selftests/bpf/progs/test_sockmap_copy.c new file mode 100644 index 000000000000..9d0c9f28cab2 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/test_sockmap_copy.c @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2020 Cloudflare +#include "vmlinux.h" +#include <bpf/bpf_helpers.h> + +struct { + __uint(type, BPF_MAP_TYPE_SOCKMAP); + __uint(max_entries, 1); + __type(key, __u32); + __type(value, __u64); +} src SEC(".maps"); + +struct { + __uint(type, BPF_MAP_TYPE_SOCKMAP); + __uint(max_entries, 1); + __type(key, __u32); + __type(value, __u64); +} dst_sock_map SEC(".maps"); + +struct { + __uint(type, BPF_MAP_TYPE_SOCKHASH); + __uint(max_entries, 1); + __type(key, __u32); + __type(value, __u64); +} dst_sock_hash SEC(".maps"); + +SEC("classifier/copy_sock_map") +int copy_sock_map(void *ctx) +{ + struct bpf_sock *sk; + bool failed = false; + __u32 key = 0; + + sk = bpf_map_lookup_elem(&src, &key); + if (!sk) + return SK_DROP; + + if (bpf_map_update_elem(&dst_sock_map, &key, sk, 0)) + failed = true; + + if (bpf_map_update_elem(&dst_sock_hash, &key, sk, 0)) + failed = true; + + bpf_sk_release(sk); + return failed ? SK_DROP : SK_PASS; +} + +char _license[] SEC("license") = "GPL"; -- 2.25.1
3 years, 8 months
2
4
0
0
[PATCH bpf-next v2 6/6] selftests: bpf: test sockmap update from BPF
by Lorenz Bauer
Add a test which copies a socket from a sockmap into another sockmap or sockhash. This excercises bpf_map_update_elem support from BPF context. Compare the socket cookies from source and destination to ensure that the copy succeeded. Signed-off-by: Lorenz Bauer <lmb(a)cloudflare.com> --- .../selftests/bpf/prog_tests/sockmap_basic.c | 71 +++++++++++++++++++ .../selftests/bpf/progs/test_sockmap_copy.c | 48 +++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/test_sockmap_copy.c diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c index 96e7b7f84c65..cd05ff5e88e1 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c @@ -4,6 +4,7 @@ #include "test_progs.h" #include "test_skmsg_load_helpers.skel.h" +#include "test_sockmap_copy.skel.h" #define TCP_REPAIR 19 /* TCP sock is under repair right now */ @@ -101,6 +102,72 @@ static void test_skmsg_helpers(enum bpf_map_type map_type) test_skmsg_load_helpers__destroy(skel); } +static void test_sockmap_copy(enum bpf_map_type map_type) +{ + struct bpf_prog_test_run_attr tattr; + struct test_sockmap_copy *skel; + __u64 src_cookie, dst_cookie; + int err, prog, src, dst; + const __u32 zero = 0; + char dummy[14] = {0}; + __s64 sk; + + sk = connected_socket_v4(); + if (CHECK_FAIL(sk == -1)) + return; + + skel = test_sockmap_copy__open_and_load(); + if (CHECK_FAIL(!skel)) { + close(sk); + perror("test_sockmap_copy__open_and_load"); + return; + } + + prog = bpf_program__fd(skel->progs.copy_sock_map); + src = bpf_map__fd(skel->maps.src); + if (map_type == BPF_MAP_TYPE_SOCKMAP) + dst = bpf_map__fd(skel->maps.dst_sock_map); + else + dst = bpf_map__fd(skel->maps.dst_sock_hash); + + err = bpf_map_update_elem(src, &zero, &sk, BPF_NOEXIST); + if (CHECK_FAIL(err)) { + perror("bpf_map_update"); + goto out; + } + + err = bpf_map_lookup_elem(src, &zero, &src_cookie); + if (CHECK_FAIL(err)) { + perror("bpf_map_lookup_elem(src)"); + goto out; + } + + tattr = (struct bpf_prog_test_run_attr){ + .prog_fd = prog, + .repeat = 1, + .data_in = dummy, + .data_size_in = sizeof(dummy), + }; + + err = bpf_prog_test_run_xattr(&tattr); + if (CHECK_ATTR(err || !tattr.retval, "bpf_prog_test_run", + "errno=%u retval=%u\n", errno, tattr.retval)) + goto out; + + err = bpf_map_lookup_elem(dst, &zero, &dst_cookie); + if (CHECK_FAIL(err)) { + perror("bpf_map_lookup_elem(dst)"); + goto out; + } + + if (dst_cookie != src_cookie) + PRINT_FAIL("cookie %llu != %llu\n", dst_cookie, src_cookie); + +out: + close(sk); + test_sockmap_copy__destroy(skel); +} + void test_sockmap_basic(void) { if (test__start_subtest("sockmap create_update_free")) @@ -111,4 +178,8 @@ void test_sockmap_basic(void) test_skmsg_helpers(BPF_MAP_TYPE_SOCKMAP); if (test__start_subtest("sockhash sk_msg load helpers")) test_skmsg_helpers(BPF_MAP_TYPE_SOCKHASH); + if (test__start_subtest("sockmap copy")) + test_sockmap_copy(BPF_MAP_TYPE_SOCKMAP); + if (test__start_subtest("sockhash copy")) + test_sockmap_copy(BPF_MAP_TYPE_SOCKHASH); } diff --git a/tools/testing/selftests/bpf/progs/test_sockmap_copy.c b/tools/testing/selftests/bpf/progs/test_sockmap_copy.c new file mode 100644 index 000000000000..9d0c9f28cab2 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/test_sockmap_copy.c @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2020 Cloudflare +#include "vmlinux.h" +#include <bpf/bpf_helpers.h> + +struct { + __uint(type, BPF_MAP_TYPE_SOCKMAP); + __uint(max_entries, 1); + __type(key, __u32); + __type(value, __u64); +} src SEC(".maps"); + +struct { + __uint(type, BPF_MAP_TYPE_SOCKMAP); + __uint(max_entries, 1); + __type(key, __u32); + __type(value, __u64); +} dst_sock_map SEC(".maps"); + +struct { + __uint(type, BPF_MAP_TYPE_SOCKHASH); + __uint(max_entries, 1); + __type(key, __u32); + __type(value, __u64); +} dst_sock_hash SEC(".maps"); + +SEC("classifier/copy_sock_map") +int copy_sock_map(void *ctx) +{ + struct bpf_sock *sk; + bool failed = false; + __u32 key = 0; + + sk = bpf_map_lookup_elem(&src, &key); + if (!sk) + return SK_DROP; + + if (bpf_map_update_elem(&dst_sock_map, &key, sk, 0)) + failed = true; + + if (bpf_map_update_elem(&dst_sock_hash, &key, sk, 0)) + failed = true; + + bpf_sk_release(sk); + return failed ? SK_DROP : SK_PASS; +} + +char _license[] SEC("license") = "GPL"; -- 2.25.1
3 years, 8 months
1
0
0
0
Re: WARNING in __cfg80211_connect_result
by syzbot
syzbot has bisected this issue to: commit e7096c131e5161fa3b8e52a650d7719d2857adfd Author: Jason A. Donenfeld <Jason(a)zx2c4.com> Date: Sun Dec 8 23:27:34 2019 +0000 net: WireGuard secure network tunnel bisection log:
https://syzkaller.appspot.com/x/bisect.txt?x=175ad8b1900000
start commit: e3ec1e8c net: eliminate meaningless memcpy to data in pskb.. git tree: net-next final oops:
https://syzkaller.appspot.com/x/report.txt?x=14dad8b1900000
console output:
https://syzkaller.appspot.com/x/log.txt?x=10dad8b1900000
kernel config:
https://syzkaller.appspot.com/x/.config?x=3d400a47d1416652
dashboard link:
https://syzkaller.appspot.com/bug?extid=cc4c0f394e2611edba66
syz repro:
https://syzkaller.appspot.com/x/repro.syz?x=15d9de91900000
Reported-by: syzbot+cc4c0f394e2611edba66(a)syzkaller.appspotmail.com Fixes: e7096c131e51 ("net: WireGuard secure network tunnel") For information about bisection process see:
https://goo.gl/tpsmEJ#bisection
3 years, 8 months
4
3
0
0
[PATCH AUTOSEL 4.19 15/18] tools/testing/selftests/cgroup/cgroup_util.c: cg_read_strcmp: fix null pointer dereference
by Sasha Levin
From: Gaurav Singh <gaurav1086(a)gmail.com> [ Upstream commit d830020656c5b68ced962ed3cb51a90e0a89d4c4 ] Haven't reproduced this issue. This PR is does a minor code cleanup. Signed-off-by: Gaurav Singh <gaurav1086(a)gmail.com> Signed-off-by: Andrew Morton <akpm(a)linux-foundation.org> Reviewed-by: Andrew Morton <akpm(a)linux-foundation.org> Cc: Shuah Khan <shuah(a)kernel.org> Cc: Tejun Heo <tj(a)kernel.org> Cc: Michal Koutn <mkoutny(a)suse.com> Cc: Roman Gushchin <guro(a)fb.com> Cc: Christian Brauner <christian.brauner(a)ubuntu.com> Cc: Chris Down <chris(a)chrisdown.name> Link:
http://lkml.kernel.org/r/20200726013808.22242-1-gaurav1086@gmail.com
Signed-off-by: Linus Torvalds <torvalds(a)linux-foundation.org> Signed-off-by: Sasha Levin <sashal(a)kernel.org> --- tools/testing/selftests/cgroup/cgroup_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/cgroup/cgroup_util.c b/tools/testing/selftests/cgroup/cgroup_util.c index 075cb0c730149..90418d79ef676 100644 --- a/tools/testing/selftests/cgroup/cgroup_util.c +++ b/tools/testing/selftests/cgroup/cgroup_util.c @@ -95,7 +95,7 @@ int cg_read_strcmp(const char *cgroup, const char *control, /* Handle the case of comparing against empty string */ if (!expected) - size = 32; + return -1; else size = strlen(expected) + 1; -- 2.25.1
3 years, 8 months
1
0
0
0
[PATCH AUTOSEL 5.4 19/22] tools/testing/selftests/cgroup/cgroup_util.c: cg_read_strcmp: fix null pointer dereference
by Sasha Levin
From: Gaurav Singh <gaurav1086(a)gmail.com> [ Upstream commit d830020656c5b68ced962ed3cb51a90e0a89d4c4 ] Haven't reproduced this issue. This PR is does a minor code cleanup. Signed-off-by: Gaurav Singh <gaurav1086(a)gmail.com> Signed-off-by: Andrew Morton <akpm(a)linux-foundation.org> Reviewed-by: Andrew Morton <akpm(a)linux-foundation.org> Cc: Shuah Khan <shuah(a)kernel.org> Cc: Tejun Heo <tj(a)kernel.org> Cc: Michal Koutn <mkoutny(a)suse.com> Cc: Roman Gushchin <guro(a)fb.com> Cc: Christian Brauner <christian.brauner(a)ubuntu.com> Cc: Chris Down <chris(a)chrisdown.name> Link:
http://lkml.kernel.org/r/20200726013808.22242-1-gaurav1086@gmail.com
Signed-off-by: Linus Torvalds <torvalds(a)linux-foundation.org> Signed-off-by: Sasha Levin <sashal(a)kernel.org> --- tools/testing/selftests/cgroup/cgroup_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/cgroup/cgroup_util.c b/tools/testing/selftests/cgroup/cgroup_util.c index bdb69599c4bdc..5e939ff1e3f95 100644 --- a/tools/testing/selftests/cgroup/cgroup_util.c +++ b/tools/testing/selftests/cgroup/cgroup_util.c @@ -105,7 +105,7 @@ int cg_read_strcmp(const char *cgroup, const char *control, /* Handle the case of comparing against empty string */ if (!expected) - size = 32; + return -1; else size = strlen(expected) + 1; -- 2.25.1
3 years, 8 months
1
0
0
0
[PATCH AUTOSEL 5.7 21/24] tools/testing/selftests/cgroup/cgroup_util.c: cg_read_strcmp: fix null pointer dereference
by Sasha Levin
From: Gaurav Singh <gaurav1086(a)gmail.com> [ Upstream commit d830020656c5b68ced962ed3cb51a90e0a89d4c4 ] Haven't reproduced this issue. This PR is does a minor code cleanup. Signed-off-by: Gaurav Singh <gaurav1086(a)gmail.com> Signed-off-by: Andrew Morton <akpm(a)linux-foundation.org> Reviewed-by: Andrew Morton <akpm(a)linux-foundation.org> Cc: Shuah Khan <shuah(a)kernel.org> Cc: Tejun Heo <tj(a)kernel.org> Cc: Michal Koutn <mkoutny(a)suse.com> Cc: Roman Gushchin <guro(a)fb.com> Cc: Christian Brauner <christian.brauner(a)ubuntu.com> Cc: Chris Down <chris(a)chrisdown.name> Link:
http://lkml.kernel.org/r/20200726013808.22242-1-gaurav1086@gmail.com
Signed-off-by: Linus Torvalds <torvalds(a)linux-foundation.org> Signed-off-by: Sasha Levin <sashal(a)kernel.org> --- tools/testing/selftests/cgroup/cgroup_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/cgroup/cgroup_util.c b/tools/testing/selftests/cgroup/cgroup_util.c index 8a637ca7d73a4..05853b0b88318 100644 --- a/tools/testing/selftests/cgroup/cgroup_util.c +++ b/tools/testing/selftests/cgroup/cgroup_util.c @@ -106,7 +106,7 @@ int cg_read_strcmp(const char *cgroup, const char *control, /* Handle the case of comparing against empty string */ if (!expected) - size = 32; + return -1; else size = strlen(expected) + 1; -- 2.25.1
3 years, 8 months
1
0
0
0
[PATCH AUTOSEL 5.8 23/27] tools/testing/selftests/cgroup/cgroup_util.c: cg_read_strcmp: fix null pointer dereference
by Sasha Levin
From: Gaurav Singh <gaurav1086(a)gmail.com> [ Upstream commit d830020656c5b68ced962ed3cb51a90e0a89d4c4 ] Haven't reproduced this issue. This PR is does a minor code cleanup. Signed-off-by: Gaurav Singh <gaurav1086(a)gmail.com> Signed-off-by: Andrew Morton <akpm(a)linux-foundation.org> Reviewed-by: Andrew Morton <akpm(a)linux-foundation.org> Cc: Shuah Khan <shuah(a)kernel.org> Cc: Tejun Heo <tj(a)kernel.org> Cc: Michal Koutn <mkoutny(a)suse.com> Cc: Roman Gushchin <guro(a)fb.com> Cc: Christian Brauner <christian.brauner(a)ubuntu.com> Cc: Chris Down <chris(a)chrisdown.name> Link:
http://lkml.kernel.org/r/20200726013808.22242-1-gaurav1086@gmail.com
Signed-off-by: Linus Torvalds <torvalds(a)linux-foundation.org> Signed-off-by: Sasha Levin <sashal(a)kernel.org> --- tools/testing/selftests/cgroup/cgroup_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/cgroup/cgroup_util.c b/tools/testing/selftests/cgroup/cgroup_util.c index 8a637ca7d73a4..05853b0b88318 100644 --- a/tools/testing/selftests/cgroup/cgroup_util.c +++ b/tools/testing/selftests/cgroup/cgroup_util.c @@ -106,7 +106,7 @@ int cg_read_strcmp(const char *cgroup, const char *control, /* Handle the case of comparing against empty string */ if (!expected) - size = 32; + return -1; else size = strlen(expected) + 1; -- 2.25.1
3 years, 8 months
1
0
0
0
[PATCH] kunit: fix: kunit_binary_assert_format() only prints signed int
by Vitor Massaru Iha
Some tests, such as overflow_kunit(), uses unsigned int, But kunit_binary_assert_format() only prints signed int, this commit also deals with the unsigned int print. Signed-off-by: Vitor Massaru Iha <vitor(a)massaru.org> --- lib/kunit/assert.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/kunit/assert.c b/lib/kunit/assert.c index 202f9fdeed0e..3ae90c09986a 100644 --- a/lib/kunit/assert.c +++ b/lib/kunit/assert.c @@ -104,12 +104,23 @@ void kunit_binary_assert_format(const struct kunit_assert *assert, binary_assert->left_text, binary_assert->operation, binary_assert->right_text); - string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n", + + if (binary_assert->left_value - 1 < 0) { + string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld\n", + binary_assert->left_text, + binary_assert->left_value); + string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld", + binary_assert->right_text, + binary_assert->right_value); + } + else { + string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %llu\n", binary_assert->left_text, binary_assert->left_value); - string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %lld", + string_stream_add(stream, KUNIT_SUBSUBTEST_INDENT "%s == %llu", binary_assert->right_text, binary_assert->right_value); + } } kunit_assert_print_msg(assert, stream); } base-commit: d43c7fb05765152d4d4a39a8ef957c4ea14d8847 prerequisite-patch-id: bf4b0962b0b955e4e45f5d25fece889562118158 -- 2.26.2
3 years, 8 months
2
4
0
0
← Newer
1
...
4
5
6
7
8
9
10
11
12
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
Results per page:
10
25
50
100
200