Skip to contentSkip to conversation

selftests: rtc: Fixes rtctest error handling.

PATCH Superseded Atul Kumar Pant 3 participants 4 messages Jul 17, 2023 – Aug 17, 2023

Subsystems (2)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 selftests: rtc: Fixes rtctest error handling.

Adds a check to verify if the rtc device file is valid or not and prints a useful error message if the file is not accessible.

---

changes since v4:
Updated the commit message.

changes since v3:
Added Linux-kselftest and Linux-kernel mailing lists.

changes since v2:
Changed error message when rtc file does not exist.

changes since v1:
Removed check for uid=0
If rtc file is invalid, then exit the test.

 tools/testing/selftests/rtc/rtctest.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
tools/testing/selftests/rtc/rtctest.c +10 -1
index 63ce02d1d5cc..630fef735c7e 100644
@@ -17,6 +17,7 @@
 #include <unistd.h>
 
 #include "../kselftest_harness.h"
+#include "../kselftest.h"
 
 #define NUM_UIE 3
 #define ALARM_DELTA 3
@@ -419,6 +420,8 @@ __constructor_order_last(void)
 
 int main(int argc, char **argv)
 {
+	int ret = -1;
+
 	switch (argc) {
 	case 2:
 		rtc_file = argv[1];
@@ -430,5 +433,11 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
-	return test_harness_run(argc, argv);
+	// Run the test if rtc_file is valid
+	if (access(rtc_file, F_OK) == 0)
+		ret = test_harness_run(argc, argv);
+	else
+		ksft_exit_fail_msg("[ERROR]: Cannot access rtc file %s - Exiting\n", rtc_file);
+
+	return ret;
 }
Signature · 1 line
2.25.1
#1 lore raw
Quoted 4 lines · Atul Kumar Pant

Adds a check to verify if the rtc device file is valid or not and prints a useful error message if the file is not accessible.

Please collect and keep the tags you got on previous versions

Quoted 55 lines

---

changes since v4:
Updated the commit message.

changes since v3:
Added Linux-kselftest and Linux-kernel mailing lists.

changes since v2:
Changed error message when rtc file does not exist.

changes since v1:
Removed check for uid=0
If rtc file is invalid, then exit the test.

 tools/testing/selftests/rtc/rtctest.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
tools/testing/selftests/rtc/rtctest.c +10 -1
index 63ce02d1d5cc..630fef735c7e 100644
@@ -17,6 +17,7 @@
 #include <unistd.h>
 
 #include "../kselftest_harness.h"
+#include "../kselftest.h"
 
 #define NUM_UIE 3
 #define ALARM_DELTA 3
@@ -419,6 +420,8 @@ __constructor_order_last(void)
 
 int main(int argc, char **argv)
 {
+	int ret = -1;
+
 	switch (argc) {
 	case 2:
 		rtc_file = argv[1];
@@ -430,5 +433,11 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
-	return test_harness_run(argc, argv);
+	// Run the test if rtc_file is valid
+	if (access(rtc_file, F_OK) == 0)
+		ret = test_harness_run(argc, argv);
+	else
+		ksft_exit_fail_msg("[ERROR]: Cannot access rtc file %s - Exiting\n", rtc_file);
+
+	return ret;
 }
Signature · 1 line
2.25.1
Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
maintainer
#2 lore raw
Quoted 51 lines · Alexandre Belloni
Quoted 4 lines · Atul Kumar Pant

Adds a check to verify if the rtc device file is valid or not and prints a useful error message if the file is not accessible.

Please collect and keep the tags you got on previous versions

Quoted 43 lines

---

changes since v4:
Updated the commit message.

changes since v3:
Added Linux-kselftest and Linux-kernel mailing lists.

changes since v2:
Changed error message when rtc file does not exist.

changes since v1:
Removed check for uid=0
If rtc file is invalid, then exit the test.

  tools/testing/selftests/rtc/rtctest.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
tools/testing/selftests/rtc/rtctest.c +3 -0
index 63ce02d1d5cc..630fef735c7e 100644
@@ -17,6 +17,7 @@
  #include <unistd.h>
 
  #include "../kselftest_harness.h"
+#include "../kselftest.h"
 
  #define NUM_UIE 3
  #define ALARM_DELTA 3
@@ -419,6 +420,8 @@ __constructor_order_last(void)
 
  int main(int argc, char **argv)
  {
+	int ret = -1;
+
  	switch (argc) {
  	case 2:
  		rtc_file = argv[1];
@@ -430,5 +433,11 @@ int main(int argc, char **argv)
  		return 1;
  	}
 
Quoted 6 lines

tools/testing/selftests/rtc/rtctest.c int main(int argc, char **argv) · line 440

Quoted 6 lines
tools/testing/selftests/rtc/rtctest.c +5 -1
-	return test_harness_run(argc, argv);
+	// Run the test if rtc_file is valid
+	if (access(rtc_file, F_OK) == 0)
+		ret = test_harness_run(argc, argv);
+	else
+		ksft_exit_fail_msg("[ERROR]: Cannot access rtc file %s - Exiting\n", rtc_file);

This should be skip not a fail. access() could for a number of reasons. Since the test isn't run when access() returns error, this would be a skip. Also the new message could be improved to use strerror() to print message with details on why access() failed.

thanks,
-- Shuah
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#3 lore raw
Quoted 53 lines · Shuah Khan
Quoted 52 lines · Alexandre Belloni
Quoted 4 lines · Atul Kumar Pant

Adds a check to verify if the rtc device file is valid or not and prints a useful error message if the file is not accessible.

Please collect and keep the tags you got on previous versions

Quoted 44 lines

---

changes since v4:
Updated the commit message.

changes since v3:
Added Linux-kselftest and Linux-kernel mailing lists.

changes since v2:
Changed error message when rtc file does not exist.

changes since v1:
Removed check for uid=0
If rtc file is invalid, then exit the test.

  tools/testing/selftests/rtc/rtctest.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
tools/testing/selftests/rtc/rtctest.c +7 -1
index 63ce02d1d5cc..630fef735c7e 100644
@@ -17,6 +17,7 @@
  #include <unistd.h>
  #include "../kselftest_harness.h"
+#include "../kselftest.h"
  #define NUM_UIE 3
  #define ALARM_DELTA 3
@@ -419,6 +420,8 @@ __constructor_order_last(void)
  int main(int argc, char **argv)
  {
+	int ret = -1;
+
  	switch (argc) {
  	case 2:
  		rtc_file = argv[1];
@@ -430,5 +433,11 @@ int main(int argc, char **argv)
  		return 1;
  	}
-	return test_harness_run(argc, argv);
+	// Run the test if rtc_file is valid
+	if (access(rtc_file, F_OK) == 0)
+		ret = test_harness_run(argc, argv);
+	else
Quoted 8 lines
Quoted 1 line

tools/testing/selftests/rtc/rtctest.c int main(int argc, char **argv) · line 440

Quoted 1 line
tools/testing/selftests/rtc/rtctest.c +1 -0
+		ksft_exit_fail_msg("[ERROR]: Cannot access rtc file %s - Exiting\n", rtc_file);

This should be skip not a fail. access() could for a number of reasons. Since the test isn't run when access() returns error, this would be a skip. Also the new message could be improved to use strerror() to print message with details on why access() failed.
thanks,
-- Shuah

Thank for the feedback. I have made the changes based on above comments and updated the patch.
_______________________________________________
Linux-kernel-mentees mailing list [email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees