[V2,11/19] selftests/resctrl: Abort running tests if not root user
diff mbox series

Message ID e8bed1e4ec3b294926670190beb863b1caa3fceb.1589835155.git.sai.praneeth.prakhya@intel.com
State New
Headers show
Series
  • Miscellaneous fixes for resctrl selftests
Related show

Commit Message

Prakhya, Sai Praneeth May 18, 2020, 10:08 p.m. UTC
Running resctrl selftest requires the test to write to resctrl file system
and only root user has permission to do so. Hence, abort the test suite if
the user is not running the test with root user privileges.

Fixes: ecdbb911f22d ("selftests/resctrl: Add MBM test")
Signed-off-by: Sai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
---
 tools/testing/selftests/resctrl/resctrl_tests.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c
index cab69ed8c67d..f005ba2b41ec 100644
--- a/tools/testing/selftests/resctrl/resctrl_tests.c
+++ b/tools/testing/selftests/resctrl/resctrl_tests.c
@@ -125,8 +125,10 @@  int main(int argc, char **argv)
 	 * 1. We write to resctrl FS
 	 * 2. We execute perf commands
 	 */
-	if (geteuid() != 0)
-		printf("# WARNING: not running as root, tests may fail.\n");
+	if (geteuid() != 0) {
+		printf("Bail out! not running as root, abort testing\n");
+		return -1;
+	}
 
 	/* Detect AMD vendor */
 	detect_amd();