public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] [PATCH] cpuset_hotplug: fix cpuset_list_compute
@ 2018-11-14 15:00 Cristian Marussi
  2018-11-14 15:01 ` Cyril Hrubis
  0 siblings, 1 reply; 2+ messages in thread
From: Cristian Marussi @ 2018-11-14 15:00 UTC (permalink / raw)
  To: ltp

cpuset_hotplug failed with:

Usage : cpuset_list_compute [-a|s] list1 [list2]

        -a|s   list1 add/subtract list2.[default: -a]

        -h     Help.
cpuset_hotplug 1 TFAIL: root group's cpus isn't expected(Result: 0,2-5, Expect: ).

It turned out that the helper cpuset_list_compute was always failing
because it was improperly handling getopt retval using a char variable;
in such a case the while() loop used around getopt never gets false,
and as a consequence getopt() keeps on being invoked parsing also the
following unknown non-option input material: this in turn leads to
the loop termination through the default switch-label that finally
terminates the program without doing anything each time.

This condition can also be spotted during the compilation process:

cpuset_list_compute.c: In function 'checkopt':
cpuset_list_compute.c:35:41: warning: comparison is always true due to limited range of data type [-Wtype-limits]
  while ((c = getopt(argc, argv, "ahs")) != -1) {
                                         ^~

Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
 .../cpuset/cpuset_hotplug_test/cpuset_list_compute.c           | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/testcases/kernel/controllers/cpuset/cpuset_hotplug_test/cpuset_list_compute.c b/testcases/kernel/controllers/cpuset/cpuset_hotplug_test/cpuset_list_compute.c
index 17a332f8a..1c66b863a 100644
--- a/testcases/kernel/controllers/cpuset/cpuset_hotplug_test/cpuset_list_compute.c
+++ b/testcases/kernel/controllers/cpuset/cpuset_hotplug_test/cpuset_list_compute.c
@@ -29,8 +29,7 @@ static void usage(char *prog_name, int status)
 
 static void checkopt(int argc, char **argv)
 {
-	char c = '\0';
-	int optc = 0;
+	int c, optc = 0;
 
 	while ((c = getopt(argc, argv, "ahs")) != -1) {
 		switch (c) {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-11-14 15:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-14 15:00 [LTP] [PATCH] [PATCH] cpuset_hotplug: fix cpuset_list_compute Cristian Marussi
2018-11-14 15:01 ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox