Skip to contentSkip to conversation

tst_cmd: Change tst_check_cmd() return type to int

PATCH In review Petr Vorel 2 participants 3 messages Oct 20, 2025 – Oct 22, 2025 Library code

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/1 tst_cmd: Change tst_check_cmd() return type to int

Function use just bool value, no need for int (readability).

---
 include/tst_private.h | 2 +-
 lib/tst_cmd.c         | 9 +++++----
 2 files changed, 6 insertions(+), 5 deletions(-)
include/tst_private.h +1 -1
index 292f7e9366..87ec8829a1 100644
@@ -45,7 +45,7 @@ char tst_kconfig_get(const char *confname);
  * function checks command version whether meets this requirement.
  * If not, case breaks if brk_nosupp is defined.
  */
-int tst_check_cmd(const char *cmd, const int brk_nosupp);
+bool tst_check_cmd(const char *cmd, const int brk_nosupp);
 
 /*
  * Returns NULL-terminated array of kernel-supported filesystems.
lib/tst_cmd.c +5 -4
index 82d60497a8..2faf7c7430 100644
@@ -27,6 +27,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <signal.h>
+#include <stdbool.h>
 #include "test.h"
 #include "tst_cmd.h"
 #include "tst_private.h"
@@ -249,7 +250,7 @@ static struct version_parser {
 	{},
 };
 
-int tst_check_cmd(const char *cmd, const int brk_nosupp)
+bool tst_check_cmd(const char *cmd, const int brk_nosupp)
 {
 	struct version_parser *p;
 	char *cmd_token, *op_token, *version_token, *next, *str;
@@ -268,7 +269,7 @@ int tst_check_cmd(const char *cmd, const int brk_nosupp)
 		tst_brkm(TCONF, NULL, "Couldn't find '%s' in $PATH", cmd_token);
 
 	if (!op_token)
-		return 0;
+		return true;
 
 	if (!version_token || str) {
 		tst_brkm(TCONF, NULL,
@@ -318,7 +319,7 @@ int tst_check_cmd(const char *cmd, const int brk_nosupp)
 		tst_brkm(TCONF, NULL, "Invalid op(%s)", op_token);
 	}
 
-	return 0;
+	return true;
 error:
 	if (brk_nosupp) {
 		tst_brkm(TCONF, NULL, "%s requires %s %d, but got %d",
@@ -328,5 +329,5 @@ error:
 			cmd, op_token, ver_get, ver_parser);
 	}
 
-	return 1;
+	return false;
 }
Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by Li Wang on v1 1/1
#1 lore raw
Quoted 4 lines · Petr Vorel

Function use just bool value, no need for int (readability).

---

Quoted 74 lines
 include/tst_private.h | 2 +-
 lib/tst_cmd.c         | 9 +++++----
 2 files changed, 6 insertions(+), 5 deletions(-)
include/tst_private.h +1 -1
index 292f7e9366..87ec8829a1 100644
@@ -45,7 +45,7 @@ char tst_kconfig_get(const char *confname);
  * function checks command version whether meets this requirement.
  * If not, case breaks if brk_nosupp is defined.
  */
-int tst_check_cmd(const char *cmd, const int brk_nosupp);
+bool tst_check_cmd(const char *cmd, const int brk_nosupp);
 
 /*
  * Returns NULL-terminated array of kernel-supported filesystems.
lib/tst_cmd.c +3 -2
index 82d60497a8..2faf7c7430 100644
@@ -27,6 +27,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <signal.h>
+#include <stdbool.h>
 #include "test.h"
 #include "tst_cmd.h"
 #include "tst_private.h"
@@ -249,7 +250,7 @@ static struct version_parser {
        {},
 };
 
-int tst_check_cmd(const char *cmd, const int brk_nosupp)
+bool tst_check_cmd(const char *cmd, const int brk_nosupp)
 {
        struct version_parser *p;
        char *cmd_token, *op_token, *version_token, *next, *str;
@@ -268,7 +269,7 @@ int tst_check_cmd(const char *cmd, const int
 brk_nosupp)
                tst_brkm(TCONF, NULL, "Couldn't find '%s' in $PATH",
 cmd_token);
 
        if (!op_token)
-               return 0;
+               return true;
 
        if (!version_token || str) {
                tst_brkm(TCONF, NULL,
lib/tst_cmd.c +1 -1
@@ -318,7 +319,7 @@ int tst_check_cmd(const char *cmd, const int
 brk_nosupp)
                tst_brkm(TCONF, NULL, "Invalid op(%s)", op_token);
        }
 
-       return 0;
+       return true;
 error:
        if (brk_nosupp) {

tst_brkm(TCONF, NULL, "%s requires %s %d, but got %d",

lib/tst_cmd.c +1 -2
@@ -328,5 +329,5 @@ error:
                        cmd, op_token, ver_get, ver_parser);
        }
 
-       return 1;
+       return false;
 }
--

2.51.0

--
Mailing list info: https://lists.linux.it/listinfo/ltp

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
author
#2 lore raw

Hi Li,

thanks for your review, merged.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp