From patchwork Fri Jul 5 23:29:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= X-Patchwork-Id: 13725584 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 F17D51494CD; Fri, 5 Jul 2024 23:30:10 +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=1720222213; cv=none; b=VAmu1AOoCHxpMpD2vNWKtEkw4B5B3bZ9/oM3anCoSmSNaoeo//TX51YaCBY/1NTBBoIUUtHxVZfoTvKsg2ogjMQk7fBRvvBQDNu4XHyqMWoqeBJtkUTeq0L82xzYHHQQhs7Z4nrVkgrq99zIPuPmxjmrLMjrTO7uLynH9a0+Lrw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720222213; c=relaxed/simple; bh=+5Axi8pUbv9XBWCm5KmHeoSVyq6vEZaUSVZeT+DQHF4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iZO/UTFRvEasOD7wHDZ+Ovp32hSrvWlJQtoTMRyeOm+5YF1/RH1zB4HttNoEdJoDcqDR18pDRBU4CCf33yJL1UrSLf1hsI+21ImiBYtEn0yWqGmHiP5crTNfxADi2JJOpODUtkPpaGDK+po4Ksj/WUXTIISTCUIATDhiwE0aiB0= 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=DwDUZBuk; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="DwDUZBuk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1720222209; bh=+5Axi8pUbv9XBWCm5KmHeoSVyq6vEZaUSVZeT+DQHF4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=DwDUZBuk9A2BOBe7ytpzgBGEI20Teo6NW1BWxXTV+sdQoTMdPCGjpbOks/Gw7CIyq SCV0YMpVcrvFUSUHmPMnzKTQAd5yC9eb0WWNUI46zT40rPrt+Bsglbp54T63z7jpwN 8+hNlAj0NyNEvC3bXEl8NmImBoZA3r8bQUVtTPj8U9dJGckWFuGyCkNeSX8pzoabaO Wt4D2pFeXYPTuL1Cxw708waV2K2yPacL7Z6olq53UjjWXAZU3Uqdoaek5LQHfCVtiQ CTkTvmuVWmzmJ3/zsqzFxchnH8N14qHr2IdqmZz7qivvXsAKplhFVoKKlWFb20mSu+ M9vdGnbz4bfoA== Received: from [192.168.1.238] (tango.collaboradmins.com [167.235.144.72]) (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: nfraprado) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 23EAE378206B; Fri, 5 Jul 2024 23:30:08 +0000 (UTC) From: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= Date: Fri, 05 Jul 2024 19:29:54 -0400 Subject: [PATCH v2 1/3] kselftest: devices: Move discoverable devices test to subdirectory Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240705-dev-err-log-selftest-v2-1-163b9cd7b3c1@collabora.com> References: <20240705-dev-err-log-selftest-v2-0-163b9cd7b3c1@collabora.com> In-Reply-To: <20240705-dev-err-log-selftest-v2-0-163b9cd7b3c1@collabora.com> To: Shuah Khan , Greg Kroah-Hartman Cc: kernel@collabora.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kernelci@lists.linux.dev, =?utf-8?b?TsOtY29s?= =?utf-8?b?YXMgRi4gUi4gQS4gUHJhZG8=?= X-Mailer: b4 0.14.0 Move the discoverable devices test to a subdirectory to allow other related tests to be added to the devices directory. Signed-off-by: Nícolas F. R. A. Prado --- tools/testing/selftests/Makefile | 2 +- tools/testing/selftests/devices/{ => probe}/Makefile | 2 +- .../selftests/devices/{ => probe}/boards/Dell Inc.,XPS 13 9300.yaml | 0 tools/testing/selftests/devices/{ => probe}/boards/google,spherion.yaml | 0 tools/testing/selftests/devices/{ => probe}/ksft.py | 0 .../testing/selftests/devices/{ => probe}/test_discoverable_devices.py | 0 6 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 9039f3709aff..37214201d974 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -13,7 +13,7 @@ TARGETS += core TARGETS += cpufreq TARGETS += cpu-hotplug TARGETS += damon -TARGETS += devices +TARGETS += devices/probe TARGETS += dmabuf-heaps TARGETS += drivers/dma-buf TARGETS += drivers/s390x/uvdevice diff --git a/tools/testing/selftests/devices/Makefile b/tools/testing/selftests/devices/probe/Makefile similarity index 77% rename from tools/testing/selftests/devices/Makefile rename to tools/testing/selftests/devices/probe/Makefile index ca29249b30c3..7a6eaa031cfe 100644 --- a/tools/testing/selftests/devices/Makefile +++ b/tools/testing/selftests/devices/probe/Makefile @@ -1,4 +1,4 @@ TEST_PROGS := test_discoverable_devices.py TEST_FILES := boards ksft.py -include ../lib.mk +include ../../lib.mk diff --git a/tools/testing/selftests/devices/boards/Dell Inc.,XPS 13 9300.yaml b/tools/testing/selftests/devices/probe/boards/Dell Inc.,XPS 13 9300.yaml similarity index 100% rename from tools/testing/selftests/devices/boards/Dell Inc.,XPS 13 9300.yaml rename to tools/testing/selftests/devices/probe/boards/Dell Inc.,XPS 13 9300.yaml diff --git a/tools/testing/selftests/devices/boards/google,spherion.yaml b/tools/testing/selftests/devices/probe/boards/google,spherion.yaml similarity index 100% rename from tools/testing/selftests/devices/boards/google,spherion.yaml rename to tools/testing/selftests/devices/probe/boards/google,spherion.yaml diff --git a/tools/testing/selftests/devices/ksft.py b/tools/testing/selftests/devices/probe/ksft.py similarity index 100% rename from tools/testing/selftests/devices/ksft.py rename to tools/testing/selftests/devices/probe/ksft.py diff --git a/tools/testing/selftests/devices/test_discoverable_devices.py b/tools/testing/selftests/devices/probe/test_discoverable_devices.py similarity index 100% rename from tools/testing/selftests/devices/test_discoverable_devices.py rename to tools/testing/selftests/devices/probe/test_discoverable_devices.py From patchwork Fri Jul 5 23:29:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= X-Patchwork-Id: 13725585 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 94C391474AF; Fri, 5 Jul 2024 23:30:12 +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=1720222214; cv=none; b=t6JSjlJXBbbMZRtTUNboXtnuk5VGF+sF+TYMx4z1ZwcKKNKiA0zAAZuuurLWnas5hfLzZOS0BR3FwvhrMKeT08ls7UzthPLC50DlfNLE282eS/CuG/1wT38jBKE2BDescgIDJnHVMXO3/SFMAUqaT63vTWKPrJ7jkBH/lpX0OkI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720222214; c=relaxed/simple; bh=b7rCEd2uhHL8+s2zLp8duj9amCJ1UnPquiE+ouQCNGg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dxi0cGxyINGdlCYY/JpXZpQ7oK4tywg2OtUbYxUYChPvh4iv7rg8ce7XVHy9ueSs5If4ZUdYMy9cIgnafrj20C2aeilbCHTrfBRq47LC92jWjLcZy0UfC4cbV6hRDFw0PTa1NGCHumDnFh6VBqysSu5jN7zvU3nuUNU8MXuWtug= 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=jGjk7yPL; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="jGjk7yPL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1720222210; bh=b7rCEd2uhHL8+s2zLp8duj9amCJ1UnPquiE+ouQCNGg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=jGjk7yPLl8AoA2ENzIMf5xkOi4iMWjpKyE6WVCicokbMgQhcgaqj1RyJmpHmW4eAa r4agbZCCS8kCl0AW/ehCyaBHQRdw4UQsmNNTOD/NLxDa2BHbD4umpvc/ZM3+ddllhN fIw1SMjsQ1yf2unY6iro8++rWtAHl/cSK85HsAjxz74QNHowOffuviwuhr2wESPC3A M2cCJ2ZkNZjvhi+dmePLCAsWzQV9lRGcputZIQ3JQZPePJlDzooUzhVvzIW8up+Dyg PCy9wLcWgZOBd1dlKxLiNoaYJSB8P0kOCM6bSoliJ6DjkYzG/q8tlDBkK2kl9MO7+G KOekdlh8HkwMg== Received: from [192.168.1.238] (tango.collaboradmins.com [167.235.144.72]) (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: nfraprado) by madrid.collaboradmins.com (Postfix) with ESMTPSA id B437B3782200; Fri, 5 Jul 2024 23:30:09 +0000 (UTC) From: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= Date: Fri, 05 Jul 2024 19:29:55 -0400 Subject: [PATCH v2 2/3] kselftest: Move ksft helper module to common directory Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240705-dev-err-log-selftest-v2-2-163b9cd7b3c1@collabora.com> References: <20240705-dev-err-log-selftest-v2-0-163b9cd7b3c1@collabora.com> In-Reply-To: <20240705-dev-err-log-selftest-v2-0-163b9cd7b3c1@collabora.com> To: Shuah Khan , Greg Kroah-Hartman Cc: kernel@collabora.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kernelci@lists.linux.dev, =?utf-8?b?TsOtY29s?= =?utf-8?b?YXMgRi4gUi4gQS4gUHJhZG8=?= X-Mailer: b4 0.14.0 Move the ksft python module, which provides generic helpers for kselftests, to a common directory so it can be more easily shared between different tests. Signed-off-by: Nícolas F. R. A. Prado --- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/devices/probe/Makefile | 2 +- tools/testing/selftests/devices/probe/test_discoverable_devices.py | 7 ++++++- tools/testing/selftests/{devices/probe => kselftest}/ksft.py | 0 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 37214201d974..7bd78b9f5cdd 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -251,6 +251,7 @@ ifdef INSTALL_PATH install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/ install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/ install -m 744 kselftest/ktap_helpers.sh $(INSTALL_PATH)/kselftest/ + install -m 744 kselftest/ksft.py $(INSTALL_PATH)/kselftest/ install -m 744 run_kselftest.sh $(INSTALL_PATH)/ rm -f $(TEST_LIST) @ret=1; \ diff --git a/tools/testing/selftests/devices/probe/Makefile b/tools/testing/selftests/devices/probe/Makefile index 7a6eaa031cfe..f630108c3fdf 100644 --- a/tools/testing/selftests/devices/probe/Makefile +++ b/tools/testing/selftests/devices/probe/Makefile @@ -1,4 +1,4 @@ TEST_PROGS := test_discoverable_devices.py -TEST_FILES := boards ksft.py +TEST_FILES := boards include ../../lib.mk diff --git a/tools/testing/selftests/devices/probe/test_discoverable_devices.py b/tools/testing/selftests/devices/probe/test_discoverable_devices.py index 8f2200540a1f..d94a74b8a054 100755 --- a/tools/testing/selftests/devices/probe/test_discoverable_devices.py +++ b/tools/testing/selftests/devices/probe/test_discoverable_devices.py @@ -16,12 +16,17 @@ import argparse import glob -import ksft import os import re import sys import yaml +# Allow ksft module to be imported from different directory +this_dir = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(this_dir, "../../kselftest/")) + +import ksft + pci_controllers = [] usb_controllers = [] diff --git a/tools/testing/selftests/devices/probe/ksft.py b/tools/testing/selftests/kselftest/ksft.py similarity index 100% rename from tools/testing/selftests/devices/probe/ksft.py rename to tools/testing/selftests/kselftest/ksft.py From patchwork Fri Jul 5 23:29:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= X-Patchwork-Id: 13725586 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 F382516D9A4; Fri, 5 Jul 2024 23:30:13 +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=1720222215; cv=none; b=NEY0yxVxDy9IYpm/0UMIsfpjXu31kWt1UkTplNEPsoJMrcdSO1n2aYMRH2lbOsjBOYNtcRO2bSDCSyQVadEoTQSssvtewBjscXdDFtpWHSnHlaQLtw3PsLTlGAzJkoGd6E92dnx2CFscXfe9d3h5JBBNvW0O6CJkN1bqeXBatRA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720222215; c=relaxed/simple; bh=KXP1PLG22gD+T352YnjlF9j1bB/6aJs9Gs0doHGBIBs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pwpiavXhdH70n70zX/rzoKc6FD0cXjS3WBd1VIfU7wAU4LfEzSiJKfe0gLj2HplkpucvZb0d95hgNRpOox2vEAi92JPDN4OMvpScn8Z1Pk0T+7DHsjEQJbPzOkIP+Gc3JaWwwB3PC3bWcQoiztXcWNgHogbWe07S+vB0lYHBHC4= 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=vwFNqutu; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="vwFNqutu" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1720222212; bh=KXP1PLG22gD+T352YnjlF9j1bB/6aJs9Gs0doHGBIBs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=vwFNqutux5y24gRoxK0SDzXPLfO2NV0mnnzrQ08yf9jLPyduLHJq/B8pVras50ETx zmhs8pKPYY9wE+YUbeMVQNvt43aDNnzTKGBEn6HXmUvlV08zsK10HskltkI0SU6ifN bWBSs1CabS/wJDBfUfUNq2i8projBbAMJA5kgSLpjWkOeHfuyQnPziBkapPVuDJcWA zMRsjvNQkxXI3zhkRBTkQVyhLqJpS9pwoPxNIJ5f++lp/nlY7PPKDCIbso00mg+sns kvD8awMfqFsihSqSgaeSO+8XhQu+acww1MgdDQGtEg6zJo5TUQB2BZVwK6wKH5GNQr nULjpENvksHbA== Received: from [192.168.1.238] (tango.collaboradmins.com [167.235.144.72]) (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: nfraprado) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 42F3137821FE; Fri, 5 Jul 2024 23:30:11 +0000 (UTC) From: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= Date: Fri, 05 Jul 2024 19:29:56 -0400 Subject: [PATCH v2 3/3] kselftest: devices: Add test to detect device error logs Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240705-dev-err-log-selftest-v2-3-163b9cd7b3c1@collabora.com> References: <20240705-dev-err-log-selftest-v2-0-163b9cd7b3c1@collabora.com> In-Reply-To: <20240705-dev-err-log-selftest-v2-0-163b9cd7b3c1@collabora.com> To: Shuah Khan , Greg Kroah-Hartman Cc: kernel@collabora.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kernelci@lists.linux.dev, =?utf-8?b?TsOtY29s?= =?utf-8?b?YXMgRi4gUi4gQS4gUHJhZG8=?= X-Mailer: b4 0.14.0 Log errors are the most widely used mechanism for reporting issues in the kernel. When an error is logged using the device helpers, eg dev_err(), it gets metadata attached that identifies the subsystem and device where the message is coming from. Introduce a new test that makes use of that metadata to report which devices logged errors (or more critical messages). Signed-off-by: Nícolas F. R. A. Prado --- tools/testing/selftests/Makefile | 1 + .../testing/selftests/devices/error_logs/Makefile | 3 + .../devices/error_logs/test_device_error_logs.py | 85 ++++++++++++++++++++++ 3 files changed, 89 insertions(+) diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 7bd78b9f5cdd..c4937c87df22 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -13,6 +13,7 @@ TARGETS += core TARGETS += cpufreq TARGETS += cpu-hotplug TARGETS += damon +TARGETS += devices/error_logs TARGETS += devices/probe TARGETS += dmabuf-heaps TARGETS += drivers/dma-buf diff --git a/tools/testing/selftests/devices/error_logs/Makefile b/tools/testing/selftests/devices/error_logs/Makefile new file mode 100644 index 000000000000..d546c3fb0a7f --- /dev/null +++ b/tools/testing/selftests/devices/error_logs/Makefile @@ -0,0 +1,3 @@ +TEST_PROGS := test_device_error_logs.py + +include ../../lib.mk diff --git a/tools/testing/selftests/devices/error_logs/test_device_error_logs.py b/tools/testing/selftests/devices/error_logs/test_device_error_logs.py new file mode 100755 index 000000000000..3dd56c8ec92c --- /dev/null +++ b/tools/testing/selftests/devices/error_logs/test_device_error_logs.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2024 Collabora Ltd +# +# This test checks for the presence of error (or more critical) log messages +# coming from devices in the kernel log. +# +# One failed test case is reported for each device that has outputted error +# logs. Devices with no errors do not produce a passing test case to avoid +# polluting the results, therefore a successful run will list 0 tests run. +# + +import glob +import os +import re +import sys + +# Allow ksft module to be imported from different directory +this_dir = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(this_dir, "../../kselftest/")) + +import ksft + +kmsg = "/dev/kmsg" + +RE_log = re.compile( + r"(?P[0-9]+),(?P[0-9]+),(?P[0-9]+),(?P[^;]*)(,[^;]*)*;(?P.*)" +) +RE_tag = re.compile(r" (?P[^=]+)=(?P.*)") + +PREFIX_ERROR = 3 + +logs = [] +error_log_per_device = {} + + +def parse_kmsg(): + current_log = {} + + with open(kmsg) as f: + os.set_blocking(f.fileno(), False) + + for line in f: + tag_line = RE_tag.match(line) + log_line = RE_log.match(line) + + if log_line: + if current_log: + logs.append(current_log) # Save last log + + current_log = { + "prefix": int(log_line.group("prefix")), + "sequence": int(log_line.group("sequence")), + "timestamp": int(log_line.group("timestamp")), + "flag": log_line.group("flag"), + "message": log_line.group("message"), + } + elif tag_line: + current_log[tag_line.group("key")] = tag_line.group("value") + + +def generate_per_device_error_log(): + for log in logs: + if log.get("DEVICE") and log["prefix"] <= PREFIX_ERROR: + if not error_log_per_device.get(log["DEVICE"]): + error_log_per_device[log["DEVICE"]] = [] + error_log_per_device[log["DEVICE"]].append(log) + + +parse_kmsg() + +generate_per_device_error_log() +num_tests = len(error_log_per_device) + +ksft.print_header() +ksft.set_plan(num_tests) + +for device in error_log_per_device: + for log in error_log_per_device[device]: + ksft.print_msg(log["message"]) + ksft.test_result_fail(device) +if num_tests == 0: + ksft.print_msg("No device error logs found") +ksft.finished()