On Mon, Mar 30, 2020 at 8:57 PM Patricia Alfonso trishalfonso@google.com wrote:
On Thu, Mar 26, 2020 at 4:15 PM Patricia Alfonso trishalfonso@google.com wrote:
kasan-dev@googlegroups.com wrote: > > Transfer all previous tests for KASAN to KUnit so they can be run > more easily. Using kunit_tool, developers can run these tests with their > other KUnit tests and see "pass" or "fail" with the appropriate KASAN > report instead of needing to parse each KASAN report to test KASAN > functionalities. All KASAN reports are still printed to dmesg. > > Stack tests do not work in UML so those tests are protected inside an > "#if IS_ENABLED(CONFIG_KASAN_STACK)" so this only runs if stack > instrumentation is enabled. > > copy_user_test cannot be run in KUnit so there is a separate test file > for those tests, which can be run as before as a module.
Hi Patricia,
FWIW I've got some conflicts applying this patch on latest linux-next next-20200324. There are some changes to the tests in mm tree I think.
Which tree will this go through? I would be nice to resolve these conflicts somehow, but I am not sure how. Maybe the kasan tests changes are merged upstream next windows, and then rebase this?
Also, how can I apply this for testing? I assume this is based on some kunit branch? which one?
Hmm... okay, that sounds like a problem. I will have to look into the conflicts. I'm not sure which tree this will go through upstream; I expect someone will tell me which is best when the time comes. This is based on the kunit branch in the kunit documentation here: https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/lo...
I've checked out:
commit 0476e69f39377192d638c459d11400c6e9a6ffb0 (HEAD, kselftest/kunit) Date: Mon Mar 23 12:04:59 2020 -0700
But the build still fails for me:
mm/kasan/report.c: In function ‘kasan_update_kunit_status’: mm/kasan/report.c:466:6: error: implicit declaration of function ‘kunit_find_named_resource’ [-Werror=implicit-function-declar] 466 | if (kunit_find_named_resource(cur_test, "kasan_data")) { | ^~~~~~~~~~~~~~~~~~~~~~~~~ mm/kasan/report.c:467:12: warning: assignment to ‘struct kunit_resource *’ from ‘int’ makes pointer from integer without a cas] 467 | resource = kunit_find_named_resource(cur_test, "kasan_data"); | ^ mm/kasan/report.c:468:24: error: ‘struct kunit_resource’ has no member named ‘data’ 468 | kasan_data = resource->data; | ^~
What am I doing wrong?
This patchset relies on another RFC patchset from Alan: https://lore.kernel.org/linux-kselftest/1583251361-12748-1-git-send-email-al...
I thought I linked it in the commit message but it may only be in the commit message for part 2/3. It should work with Alan's patchset, but let me know if you have any trouble.
Please push your state of code to some git repository, so that I can pull it. Github or gerrit or whatever.
Here's a Gerrit link: https://kunit-review.googlesource.com/c/linux/+/3513
This worked well for me! Thanks!
The first thing I hit is that my default config has panic_on_warn=1 set, which has the same effect as the "multi shot" setting. I think we need to save/restore panic_on_warn the same way we do for multi shot (+rename kasan_multi_shot_init/exit to something more generic).
After removing panic_on_warn=1 I was able to run the tests successfully on x86_64.
And after injecting some simple bugs, I got expected test failures:
[ 3.191793] # kasan_memchr: EXPECTATION FAILED at lib/test_kasan.c:509 [ 3.191793] Expected kasan_data->report_expected == kasan_data->report_found, but [ 3.191793] kasan_data->report_expected == 1 [ 3.191793] kasan_data->report_found == 0 [ 3.191852] not ok 30 - kasan_memchr [ 3.195588] # kasan_memcmp: EXPECTATION FAILED at lib/test_kasan.c:523 [ 3.195588] Expected kasan_data->report_expected == kasan_data->report_found, but [ 3.195588] kasan_data->report_expected == 1 [ 3.195588] kasan_data->report_found == 0 [ 3.195659] not ok 31 - kasan_memcmp
All of these should be static:
struct kunit_resource resource; struct kunit_kasan_expectation fail_data; bool multishot; int kasan_multi_shot_init(struct kunit *test) void kasan_multi_shot_exit(struct kunit *test)
With the comments in the previous emails, this looks good to me.