From 5eff4f91b7668f11153c37f06e28f54b568f87f3 Mon Sep 17 00:00:00 2001
From: Nathan Yee <nyee32@schedmd.com>
Date: Thu, 4 Sep 2014 08:12:39 -0700
Subject: [PATCH] Modify test for more gereric node names

Previous test could fail for node names numeric suffix with more
than one digit. This captures all digits plus checks for names
without a numeric suffix.
---
 testsuite/expect/test15.21 | 63 ++++++++++++++++++++++++--------------
 1 file changed, 40 insertions(+), 23 deletions(-)

diff --git a/testsuite/expect/test15.21 b/testsuite/expect/test15.21
index 4fd1062a39a..a88eb4578de 100755
--- a/testsuite/expect/test15.21
+++ b/testsuite/expect/test15.21
@@ -43,6 +43,32 @@ set exit_code   0
 
 print_header $test_id
 
+proc get_host_num { host } {
+	global number bin_echo exit_code
+
+	log_user 0
+	set num -1
+	spawn $bin_echo $host
+	expect {
+		-re "($number)\r\n" {
+			set num $expect_out(1,string)
+			exp_continue
+		}
+		timeout {
+			send_user "\nFAILURE: echo is not responding\n"
+			set exit_code 1
+		}
+		eof {
+			wait
+		}
+	}
+	# Change host number to integer in case it looks like octal
+	scan $num %d num
+	log_user 1
+
+	return $num
+}
+
 if {[test_front_end] != 0} {
 	send_user "\nWARNING: This test is incompatible with front-end systems\n"
 	exit 0
@@ -88,32 +114,19 @@ expect {
 		send_user "\nWARNING: can't test salloc task distribution\n"
 		exit $exit_code
 	}
-	-re "($number): *($alpha_numeric_under)($number)" {
-		set task_id $expect_out(1,string)
-		if {$task_id == 0} {
-			set host_0_name $expect_out(2,string)
-			set host_0_num  $expect_out(3,string)
-		}
-		if {$task_id == 1} {
-			set host_1_name $expect_out(2,string)
-			set host_1_num  $expect_out(3,string)
-		}
-		if {$task_id == 2} {
-			set host_2_name $expect_out(2,string)
-			set host_2_num  $expect_out(3,string)
-		}
-		exp_continue
-	}
 	-re "($number): *($alpha_numeric_under)" {
 		set task_id $expect_out(1,string)
 		if {$task_id == 0} {
 			set host_0_name $expect_out(2,string)
+			set host_0_num [get_host_num $expect_out(2,string)]
 		}
 		if {$task_id == 1} {
 			set host_1_name $expect_out(2,string)
+			set host_1_num [get_host_num $expect_out(2,string)]
 		}
 		if {$task_id == 2} {
 			set host_2_name $expect_out(2,string)
+			set host_2_num [get_host_num $expect_out(2,string)]
 		}
 		exp_continue
 	}
@@ -154,13 +167,17 @@ if {[string compare $host_2_name ""] == 0} {
 #
 # Verify node sequence number
 #
-if {$host_1_num != [expr $host_0_num + 1]} {
-	send_user "\nFAILURE: node sequence number not contiguous\n"
-	set exit_code   1
-}
-if {$host_2_num != [expr $host_1_num + 1]} {
-	send_user "\nFAILURE: node sequence number not contiguous\n"
-	set exit_code   1
+if {$host_1_num == -1 || $host_1_num == -1 || $host_2_num == -1} {
+	send_user "\nWARNING: node names do not have trailing numbers as needed for this test\n"
+} else {
+	if {$host_1_num != [expr $host_0_num + 1]} {
+		send_user "\nFAILURE: node sequence number not contiguous\n"
+		set exit_code   1
+	}
+	if {$host_2_num != [expr $host_1_num + 1]} {
+		send_user "\nFAILURE: node sequence number not contiguous\n"
+		set exit_code   1
+	}
 }
 
 if {$exit_code == 0} {
-- 
GitLab