Skip to contentSkip to conversation

selftests: net: socket: fix inverted failure diagnostic

PATCH New Omokefe Emmanuel Onanaroghene 1 participant 1 message Nov 20

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: net: socket: fix inverted failure diagnostic

When socket() succeeds but the test case expected failure, the error branch prints "expected success got err" with strerror(errno), both backwards (reality is "expected err, got success") and stale (errno is meaningless after a successful call). Mirror the sibling fd<0 branch:
name the expected errno via strerror(-s->expect).

---
 tools/testing/selftests/net/socket.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/testing/selftests/net/socket.c +3 -2
index 9e270548dad80..7f075acc0b19c 100644
@@ -71,10 +71,11 @@ static int run_tests(void)
 			close(fd);
 
 			if (s->expect < 0) {
-				msg1 = strerror_r(errno, err_string1, ERR_STRING_SZ);
+				msg1 = strerror_r(-s->expect, err_string1,
+						  ERR_STRING_SZ);
 
 				fprintf(stderr, "socket(%d, %d, %d) expected "
-					"success got err (%s)\n",
+					"err (%s) got success\n",
 					s->domain, s->type, s->protocol,
 					msg1);
 
Signature · 1 line
2.43.0