Skip to content

Commit

Permalink
zdtm: sock_opts00: Improve error messages.
Browse files Browse the repository at this point in the history
Make it clear that the option numbers are indexes not the option
identifiers ("names"). Also show the value change that prompted test
failure.

Signed-off-by: Michał Mirosław <[email protected]>
  • Loading branch information
osctobe committed Jun 16, 2023
1 parent 2ae8bd8 commit 798274d
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions test/zdtm/static/sock_opts00.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,28 @@ const char *test_author = "Pavel Emelyanov <[email protected]>";
#define TEST_PORT 59687
#define TEST_ADDR INADDR_ANY

#define NOPTS 8

int main(int argc, char **argv)
{
int sock, ret = 0, vname[NOPTS], val[NOPTS], rval, i;
#define OPT(x) { x, #x }
static const struct {
int opt;
const char *name;
} vname[] = {
OPT(SO_PRIORITY),
OPT(SO_RCVLOWAT),
OPT(SO_MARK),
OPT(SO_PASSCRED),
OPT(SO_PASSSEC),
OPT(SO_DONTROUTE),
OPT(SO_NO_CHECK),
OPT(SO_OOBINLINE),
};
static const int NOPTS = sizeof(vname) / sizeof(*vname);
#undef OPT

int sock, ret = 0, val[NOPTS], rval, i;
socklen_t len = sizeof(int);

vname[0] = SO_PRIORITY;
vname[1] = SO_RCVLOWAT;
vname[2] = SO_MARK;
vname[3] = SO_PASSCRED;
vname[4] = SO_PASSSEC;
vname[5] = SO_DONTROUTE;
vname[6] = SO_NO_CHECK;
vname[7] = SO_OOBINLINE;

test_init(argc, argv);

sock = socket(PF_INET, SOCK_STREAM, 0);
Expand All @@ -37,29 +43,29 @@ int main(int argc, char **argv)
}

for (i = 0; i < NOPTS; i++) {
ret = getsockopt(sock, SOL_SOCKET, vname[i], &val[i], &len);
ret = getsockopt(sock, SOL_SOCKET, vname[i].opt, &val[i], &len);
if (ret) {
pr_perror("can't get option %d", i);
pr_perror("can't get %s", vname[i].name);
return 1;
}

val[i]++;

ret = setsockopt(sock, SOL_SOCKET, vname[i], &val[i], len);
ret = setsockopt(sock, SOL_SOCKET, vname[i].opt, &val[i], len);
if (ret) {
pr_perror("can't set option %d", i);
pr_perror("can't set %s = %d", vname[i].name, val[i]);
return 1;
}

ret = getsockopt(sock, SOL_SOCKET, vname[i], &rval, &len);
ret = getsockopt(sock, SOL_SOCKET, vname[i].opt, &rval, &len);
if (ret) {
pr_perror("can't get option %d 2", i);
pr_perror("can't re-get %s", vname[i].name);
return 1;
}

if (rval != val[i]) {
if (rval + 1 == val[i]) {
pr_perror("can't reset option %d want %d have %d", i, val[i], rval);
pr_perror("failed to set %s: want %d have %d", vname[i].name, val[i], rval);
return 1;
}

Expand All @@ -72,14 +78,15 @@ int main(int argc, char **argv)
test_waitsig();

for (i = 0; i < NOPTS; i++) {
ret = getsockopt(sock, SOL_SOCKET, vname[i], &rval, &len);
ret = getsockopt(sock, SOL_SOCKET, vname[i].opt, &rval, &len);
if (ret) {
pr_perror("can't get option %d again", i);
pr_perror("can't verify %s", vname[i].name);
return 1;
}

if (val[i] != rval) {
fail("option %d changed", i);
errno = 0;
fail("%s changed: %d -> %d", vname[i].name, val[i], rval);
return 1;
}
}
Expand Down

0 comments on commit 798274d

Please sign in to comment.