Message ID | 20240229155235.263157-1-laura.nao@collabora.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-87031-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp508027dyb; Thu, 29 Feb 2024 08:14:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXNtInbrANR2Cys0mMwXkAvG6SWTOztwwYqDOEmUqkEgfi8zgRCrRyp0PiiuYFoUd1bH8JanhzB19W7ws2EgPgQx0HEwg== X-Google-Smtp-Source: AGHT+IFdL60QuygkRh0fnKIMHFmSnZQnRiP7gITzL/albAxFWO6ovY7AwM88RVedg44ptukm5XUV X-Received: by 2002:a05:6402:4494:b0:565:7bca:eebf with SMTP id er20-20020a056402449400b005657bcaeebfmr2088507edb.14.1709223246332; Thu, 29 Feb 2024 08:14:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709223246; cv=pass; d=google.com; s=arc-20160816; b=IdmITbChpOMRL3Hvtz59p653RyPm69pTGrWRxXONt6D5qEhrEXBep66yPG7zwDGv/V yXpj7VhPCN5cPhWNXy94rt8ubOQHiZbWPHoYAHK2LM93sFrAnX/dvGbHyeho9UwXwTNN qjJD4L/WOKAU3OH74DvXaFqbV40J3NP35KLvEWYQ0cqPDB9JwYRzQF5niLTR6gN/sIVr IEK6URs3kcCMw7C+E2QA1wiCI5E3FH/rdVwSgwHBnGxbxlPteWAdALWecqXjivVXCdk6 /ZjK7BIXuWDXpukqofSDnBwAKeo5YFKg6wnpO+wWhQ3JChFqOM60f3wx2MNsc5ujPRpv VSfA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=WZvXtf6+zDK7RczDDEJ38DF7ggMlSb2PCQ2Ylaa1XHQ=; fh=Y/k4m5MZG4Pz6YQSPmO4dQ7bKvZyloaqyMGoXKaIXbw=; b=eEYq7osTl+oRJxgmutim/w9NvCfpITK4Md6fkZN/IJJ5yhGIkexCeWYKITi6XchMBn KFVC3ZXi/KY/OF6Nw571VI6k0BJfM8CK6w5ZpQtnNU9DQmqYYmSbP8Ya8teXy6R0YPVI YFPwGPfzkBCzRgBwsRYknlTzOGcrb9ZVKmFKS4pSODuF5JCw9w2Kk8OWYZu9sbEouaFY IMdicZKXAQE7J0o1n/jedvvxANpkGr2/41Xcdf0SuNFlvkHofcA1rA/+UvJLnSYv5B8k 2ZsKCP6u6293O/1WuRzBoDRZpngjKv+pTsT2spT5/zcJeZiM86v/qy5MvKMfXxEneDph YRjQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="C/CQefgI"; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-87031-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87031-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id n18-20020a509352000000b00564432aa4f9si656600eda.411.2024.02.29.08.14.06 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:14:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87031-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="C/CQefgI"; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-87031-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87031-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id EBE951F21696 for <ouuuleilei@gmail.com>; Thu, 29 Feb 2024 16:14:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D88EA1586D2; Thu, 29 Feb 2024 15:53:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="C/CQefgI" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1E4D155A35; Thu, 29 Feb 2024 15:53:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709222015; cv=none; b=uN9kvY3uFutmkUTSSdMrhsFEh2xeIJPBgsQrjB5jdDJ6m2zMjoJBcoRcr2cEXeWHrJGnOEpwptIXuitKF7F/o3Cmeh5Z9epT2kdJkNsEtuTvrzHBB/SKzkd7cDS1N0/OBIiLz05Q3oLfOQQcqB9xsOfy8RmD80OcuyzfPYrT7aY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709222015; c=relaxed/simple; bh=eH26C+V3gmZDbyoRlGOTopoefFB8XzOGpUJcXpz1tHI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=L6dr+duPePUumXOAkoY4OFLGytsbXkeLjDBT+DIUQTR9wi+8/9jj0O7v8MRNoo1yhILQ8TwpUbPhKdhe30Dh+xQ/FkDxrGLVEnygdSL+pY+8j6GunQMNixf/tVjebXKEHg+tBXfY1tzkRypxcJDE+mWDpryCSLv29g/QpBIaQds= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=C/CQefgI; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1709222011; bh=eH26C+V3gmZDbyoRlGOTopoefFB8XzOGpUJcXpz1tHI=; h=From:To:Cc:Subject:Date:From; b=C/CQefgI3sOJj7jZTQlDP9R9Zlhn0+WOhFtJex+7xwdoprt+MjgC/v28XSGbBrrIs dbObe7Xp6y/0Lo/0mAukWJoPwEA0EmXqihZj3Ptsz9e5AuAaGGHNApxKqWHT4KzYX/ T805pO7GpJeCkMpPv9HhFSrHD/IyTPitYTiwMsJxv1x+E1jHcCkva1hBxKNwCTUqQh DvqhFfaa4XJTEYiI+OEi481B4ScKPQ7XtKxXOycz4opVF5LaLGwSz5/mInIAbBHtx1 FZm07Bosc0FNKHL6RrSV/P5038XD+Yb0oeU9sBAGmWBRkkYVF0ysuB93sqqZjexHAK p1KRKEwIJmTCw== Received: from localhost.localdomain (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: laura.nao) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 0375537810EF; Thu, 29 Feb 2024 15:53:29 +0000 (UTC) From: Laura Nao <laura.nao@collabora.com> To: ojeda@kernel.org, alex.gaynor@gmail.com, wedsonaf@gmail.com, shuah@kernel.org Cc: usama.anjum@collabora.com, a.hindborg@samsung.com, aliceryhl@google.com, benno.lossin@proton.me, bjorn3_gh@protonmail.com, boqun.feng@gmail.com, gary@garyguo.net, kernel@collabora.com, laura.nao@collabora.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, rust-for-linux@vger.kernel.org, kernel@valentinobst.de, sergio.collado@gmail.com Subject: [PATCH v5] kselftest: Add basic test for probing the rust sample modules Date: Thu, 29 Feb 2024 16:52:35 +0100 Message-Id: <20240229155235.263157-1-laura.nao@collabora.com> X-Mailer: git-send-email 2.30.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792250474316103756 X-GMAIL-MSGID: 1792250474316103756 |
Series |
[v5] kselftest: Add basic test for probing the rust sample modules
|
|
Commit Message
Laura Nao
Feb. 29, 2024, 3:52 p.m. UTC
Add new basic kselftest that checks if the available rust sample modules can be added and removed correctly. Signed-off-by: Laura Nao <laura.nao@collabora.com> Reviewed-by: Sergio Gonzalez Collado <sergio.collado@gmail.com> Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com> --- Depends on: - https://lore.kernel.org/all/20240102141528.169947-1-laura.nao@collabora.com/T/#u - https://lore.kernel.org/all/20240131-ktap-sh-helpers-extend-v1-0-98ffb468712c@collabora.com/ Changes in v5: - Skip the test gracefully when ktap helpers file is missing - Skip the test when the sample modules are missing Changes in v4: - Added config file Changes in v3: - Removed useless KSFT_PASS, KSFT_FAIL, KSFT_SKIP constants - Used ktap_finished to print the results summary and handle the return code Changes in v2: - Added missing SPDX line - Edited test_probe_samples.sh script to use the common KTAP helpers file --- MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + tools/testing/selftests/rust/Makefile | 4 ++ tools/testing/selftests/rust/config | 5 +++ .../selftests/rust/test_probe_samples.sh | 41 +++++++++++++++++++ 5 files changed, 52 insertions(+) create mode 100644 tools/testing/selftests/rust/Makefile create mode 100644 tools/testing/selftests/rust/config create mode 100755 tools/testing/selftests/rust/test_probe_samples.sh
Comments
On Thu, Feb 29, 2024 at 4:53 PM Laura Nao <laura.nao@collabora.com> wrote: > > Add new basic kselftest that checks if the available rust sample modules > can be added and removed correctly. > > Signed-off-by: Laura Nao <laura.nao@collabora.com> > Reviewed-by: Sergio Gonzalez Collado <sergio.collado@gmail.com> > Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com> Thanks for this Laura! Replying here to what you wrote in v4: > At first, I hadn't planned for the kselftest to skip entirely if only > one of the two sample modules was missing. However, considering that > this kselftest is designed to test all available sample modules, and > given that both are enabled with the provided configuration file, I > believe it's more logical to verify the presence of both modules before > running the test. If either of them is missing, then we exit the test > with a skip code. This also covers the case where rust is not available. I guess it depends on what is the expected behavior in kselftests in general and whether the user is expected to have merged the provided `config` or not. Also, what about modules being built-in / `--first-run` in `modprobe`? `modprobe` by default may return successfully even if no module was loaded (or even present, if it was builtin). In that case, is a kselftest script supposed to succeed, skip or fail? I would say at the least it should be "skip" (like it is done in the case where the module is not found), and I wouldn't mind "fail" either (i.e. running `modprobe` with `--first-run`). In addition, what about module removal failures? Are they ignored on purpose, e.g. because the kernel might not be configured with module unloading? If it is possible to check whether `MODULE_UNLOAD` is supported in the current config, it would be nice to check the removal also worked. And if it is not supported, skipping the removal entirely. Finally, what about the case where `RUST` isn't enabled? I think Shuah mentioned it in a previous version. > +KTAP_HELPERS="${DIR}/../kselftest/ktap_helpers.sh" > +if [ -e "$KTAP_HELPERS" ]; then > + source "$KTAP_HELPERS" > +else > + echo "$KTAP_HELPERS file not found [SKIP]" > + exit 4 > +fi I am not sure I understand this. In which situation could this happen? The helpers should always be there, no? I tested this with `make -C...../selftests install TARGETS=rust INSTALL_PATH=...` and it seems to work in that case too. To be clear, I agree with Shuah that we should test that everything is working as expected. In fact, I would prefer to run with `-e` or, much better, use something else than bash :) But if something should never happen, should it be a skip? Shouldn't we just fail because the test infrastructure is somehow missing? Orthogonally, if we want the test, shouldn't this just test the `source` command directly rather than a proxy (file existing)? Thanks! Cheers, Miguel
Hi Miguel, On 2/29/24 17:44, Miguel Ojeda wrote: > On Thu, Feb 29, 2024 at 4:53 PM Laura Nao <laura.nao@collabora.com> wrote: >> >> Add new basic kselftest that checks if the available rust sample modules >> can be added and removed correctly. >> >> Signed-off-by: Laura Nao <laura.nao@collabora.com> >> Reviewed-by: Sergio Gonzalez Collado <sergio.collado@gmail.com> >> Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com> > > Thanks for this Laura! > > Replying here to what you wrote in v4: > >> At first, I hadn't planned for the kselftest to skip entirely if only >> one of the two sample modules was missing. However, considering that >> this kselftest is designed to test all available sample modules, and >> given that both are enabled with the provided configuration file, I >> believe it's more logical to verify the presence of both modules before >> running the test. If either of them is missing, then we exit the test >> with a skip code. This also covers the case where rust is not available. > > I guess it depends on what is the expected behavior in kselftests in > general and whether the user is expected to have merged the provided > `config` or not. > It's my understanding (and please correct if I'm wrong) that when a kselftest is shipped with a config file, that config file should be treated as a requirement for the test and the user is expected to use it (running make kselftest-merge). I agree the script shouldn't blow up if the user doesn't though, so it still makes sense to gracefully skip the test when the requirements are not met. > Also, what about modules being built-in / `--first-run` in `modprobe`? > `modprobe` by default may return successfully even if no module was > loaded (or even present, if it was builtin). In that case, is a > kselftest script supposed to succeed, skip or fail? I would say at the > least it should be "skip" (like it is done in the case where the > module is not found), and I wouldn't mind "fail" either (i.e. running > `modprobe` with `--first-run`). > This makes me realize that I should probably put these in the config too: CONFIG_MODULES=y CONFIG_MODULE_UNLOAD=y Adding --first-time (you meant --first-time, right?) definitely makes sense, thanks for the pointer. I think having the modules being built-in should be treated as a skip, same as when they are not there at all. So something like this: for sample in "${rust_sample_modules[@]}"; do - if ! /sbin/modprobe -n -q "$sample"; then + if ! /sbin/modprobe -n -q --first-time "$sample"; then ktap_skip_all "module $sample is not found in /lib/modules/$(uname -r)" exit "$KSFT_SKIP" fi will cover both cases. > In addition, what about module removal failures? Are they ignored on > purpose, e.g. because the kernel might not be configured with module > unloading? If it is possible to check whether `MODULE_UNLOAD` is > supported in the current config, it would be nice to check the removal > also worked. And if it is not supported, skipping the removal entirely. > I think it's safe to assume no other module will depend on the sample rust modules, so is there any other reason unloading the modules might fail apart from MODULE_UNLOAD not being enabled? If not, then I think we should just check if the removal worked and continue/skip the test accordingly. I can't just simply skip all tests like this though: for sample in "${rust_sample_modules[@]}"; do if /sbin/modprobe -q "$sample"; then - /sbin/modprobe -q -r "$sample" + if ! /sbin/modprobe -q -r "$sample"; then + ktap_skip_all "Failed to unload module $sample, please enable CONFIG_MODULE_UNLOAD" + exit "$KSFT_SKIP" + fi ktap_test_pass "$sample" else ktap_test_fail "$sample" as the test plan has already been printed by then. I'll need to rework the script a bit to skip the test upon errors on module removal. > Finally, what about the case where `RUST` isn't enabled? I think Shuah > mentioned it in a previous version. > When rust is not enabled, no sample module is enabled either so the test would still catch this in the first `if ! /sbin/modprobe -n -q --first-time "$sample"` block and exit with the skip code. If we need more granularity on the feedback provided to the user (i.e. indication on what particular options are missing), then I guess we could check the current kernel config (/proc/config.gz) and skip the entire test if any required config is missing. However, this adds an extra dependency on CONFIG_IKCONFIG=y and CONFIG_IKCONFIG_PROC=y. Any advice on the best approach here? >> +KTAP_HELPERS="${DIR}/../kselftest/ktap_helpers.sh" >> +if [ -e "$KTAP_HELPERS" ]; then >> + source "$KTAP_HELPERS" >> +else >> + echo "$KTAP_HELPERS file not found [SKIP]" >> + exit 4 >> +fi > > I am not sure I understand this. In which situation could this happen? > The helpers should always be there, no? I tested this with `make > -C...../selftests install TARGETS=rust INSTALL_PATH=...` and it seems > to work in that case too. > > To be clear, I agree with Shuah that we should test that everything is > working as expected. In fact, I would prefer to run with `-e` or, much > better, use something else than bash :) But if something should never > happen, should it be a skip? Shouldn't we just fail because the test > infrastructure is somehow missing? > Kselftest exit codes are predefined (https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/kselftest.h?h=v6.8-rc6#n74), so if we use `set -e` and source a missing file we end up returning "1" as if the test was run and failed. With this check we're sure to return a value that makes sense in the event the helpers file ever gets moved. > Orthogonally, if we want the test, shouldn't this just test the > `source` command directly rather than a proxy (file existing)? > Sure, checking the return value for source also makes sense. Thanks! Best, Laura
On Fri, Mar 1, 2024 at 4:22 PM Laura Nao <laura.nao@collabora.com> wrote: > > Adding --first-time (you meant --first-time, right?) definitely makes > sense, thanks for the pointer. I think having the modules being built-in > should be treated as a skip, same as when they are not there at all. Yeah, I meant `--first-time`, sorry. I didn't see other tests using it, so I am not sure if there is a reason not to do that (ditto for adding `MODULES` etc. to `config` and whether we should fail/skip in certain cases) -- I guess Shuah will let us know. > So something like this: > > for sample in "${rust_sample_modules[@]}"; do > - if ! /sbin/modprobe -n -q "$sample"; then > + if ! /sbin/modprobe -n -q --first-time "$sample"; then > ktap_skip_all "module $sample is not found in /lib/modules/$(uname -r)" > exit "$KSFT_SKIP" > fi > > will cover both cases. What about the other calls to `modprobe`? > I think it's safe to assume no other module will depend on the sample > rust modules, so is there any other reason unloading the modules > might fail apart from MODULE_UNLOAD not being enabled? If not, then I I was thinking more in general terms: that we would like to catch if unloading does not work as expected. Especially since these "simple samples" are, in part, testing that the basic infrastructure for Rust modules works. So I would say it is important to check whether module unloading failed. For instance, if something is very broken, a Rust module could in principle fail unloading even if `MODULE_UNLOAD=y` and even if C modules unload without issue. > I can't just simply skip all tests like this though: > > for sample in "${rust_sample_modules[@]}"; do > if /sbin/modprobe -q "$sample"; then > - /sbin/modprobe -q -r "$sample" > + if ! /sbin/modprobe -q -r "$sample"; then > + ktap_skip_all "Failed to unload module $sample, please enable CONFIG_MODULE_UNLOAD" > + exit "$KSFT_SKIP" > + fi > ktap_test_pass "$sample" > else > ktap_test_fail "$sample" > > as the test plan has already been printed by then. > I'll need to rework the script a bit to skip the test upon errors on > module removal. Perhaps Shuah prefers to merge this before and then improve it instead -- I don't know. I didn't mean to trigger a rework :) Especially since it is unclear what is the "pattern" to follow here -- perhaps this is another case of a wider cleanup for more tests, like the ktap helpers I suggested (thanks for implementing those by the way!). > If we need more granularity on the feedback provided to the user (i.e. > indication on what particular options are missing), then I guess we > could check the current kernel config (/proc/config.gz) and skip the > entire test if any required config is missing. However, this adds an > extra dependency on CONFIG_IKCONFIG=y and CONFIG_IKCONFIG_PROC=y. > > Any advice on the best approach here? I guess this also depends on what tests are supposed to do etc., so let's see what Shuah says. > Kselftest exit codes are predefined > (https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/kselftest.h?h=v6.8-rc6#n74), > so if we use `set -e` and source a missing file we end up returning "1" > as if the test was run and failed. With this check we're sure to return > a value that makes sense in the event the helpers file ever gets moved. Yeah, definitely. I was thinking here about just failing if something does not work as expected, i.e. speaking more generally (that is why I also mentioned even other languages). By "failing" here I didn't mean reporting the test as failing; I see it as something in the layer above. That is, if the helpers file is ever moved or is not installed for whatever reason, then it is the test infrastructure that failed. So I would have expected that "skip" is due to a reason related to the test itself rather than something unexpected related to the infrastructure, but I guess it may be part of the "skip" meaning in kselftests. So it depends on what is supposed to mean in kselftests, which I don't know. > Thanks! My pleasure! Cheers, Miguel
Perhaps we can also add a section about these tests to the new `Documentation/rust/testing.rst` [1]. We could mention that they exist, how to run them, and link to the kselftest documentation for further information. Not necessary to resend, perhaps we can do that in a separate patch when this patch and the one by Dirk are merged. - Best Valentin Cc: Dirk Behme <dirk.behme@de.bosch.com> Link: https://lore.kernel.org/r/20240130075117.4137360-1-dirk.behme@de.bosch.com [1]
On 03.03.2024 15:48, Valentin Obst wrote: > Perhaps we can also add a section about these tests to the new > `Documentation/rust/testing.rst` [1]. We could mention that they exist, > how to run them, and link to the kselftest documentation for further > information. > > Not necessary to resend, perhaps we can do that in a separate patch when > this patch and the one by Dirk are merged. Yes, that sounds good :) Laura: If you like to write some basic intro as proposed by Valentin please do it against https://github.com/Rust-for-Linux/linux/blob/rust-next/Documentation/rust/testing.rst in a separate patch. Best regards Dirk
diff --git a/MAINTAINERS b/MAINTAINERS index e1475ca38ff2..94e31dac6d2c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19231,6 +19231,7 @@ F: Documentation/rust/ F: rust/ F: samples/rust/ F: scripts/*rust* +F: tools/testing/selftests/rust/ K: \b(?i:rust)\b RXRPC SOCKETS (AF_RXRPC) diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index f7255969b695..e1504833654d 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -80,6 +80,7 @@ TARGETS += riscv TARGETS += rlimits TARGETS += rseq TARGETS += rtc +TARGETS += rust TARGETS += seccomp TARGETS += sgx TARGETS += sigaltstack diff --git a/tools/testing/selftests/rust/Makefile b/tools/testing/selftests/rust/Makefile new file mode 100644 index 000000000000..fce1584d3bc0 --- /dev/null +++ b/tools/testing/selftests/rust/Makefile @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 +TEST_PROGS += test_probe_samples.sh + +include ../lib.mk diff --git a/tools/testing/selftests/rust/config b/tools/testing/selftests/rust/config new file mode 100644 index 000000000000..b4002acd40bc --- /dev/null +++ b/tools/testing/selftests/rust/config @@ -0,0 +1,5 @@ +CONFIG_RUST=y +CONFIG_SAMPLES=y +CONFIG_SAMPLES_RUST=y +CONFIG_SAMPLE_RUST_MINIMAL=m +CONFIG_SAMPLE_RUST_PRINT=m \ No newline at end of file diff --git a/tools/testing/selftests/rust/test_probe_samples.sh b/tools/testing/selftests/rust/test_probe_samples.sh new file mode 100755 index 000000000000..ad0397e4986f --- /dev/null +++ b/tools/testing/selftests/rust/test_probe_samples.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2023 Collabora Ltd +# +# This script tests whether the rust sample modules can +# be added and removed correctly. +# +DIR="$(dirname "$(readlink -f "$0")")" + +KTAP_HELPERS="${DIR}/../kselftest/ktap_helpers.sh" +if [ -e "$KTAP_HELPERS" ]; then + source "$KTAP_HELPERS" +else + echo "$KTAP_HELPERS file not found [SKIP]" + exit 4 +fi + +rust_sample_modules=("rust_minimal" "rust_print") + +ktap_print_header + +for sample in "${rust_sample_modules[@]}"; do + if ! /sbin/modprobe -n -q "$sample"; then + ktap_skip_all "module $sample is not found in /lib/modules/$(uname -r)" + exit "$KSFT_SKIP" + fi +done + +ktap_set_plan "${#rust_sample_modules[@]}" + +for sample in "${rust_sample_modules[@]}"; do + if /sbin/modprobe -q "$sample"; then + /sbin/modprobe -q -r "$sample" + ktap_test_pass "$sample" + else + ktap_test_fail "$sample" + fi +done + +ktap_finished