-
Notifications
You must be signed in to change notification settings - Fork 596
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sk-tcp: Add test cases for TCP_CORK and TCP_NODELAY socket options
Currently there are no socket option test cases for TCP_CORK and TCP_NODELAY, this commit adds related test cases. The socket option test cases for TCP_KEEPCNT, TCP_KEEPIDLE, and TCP_KEEPINTVL already exist in socket-tcp_keepalive.c, so they are not included in this test case. Signed-off-by: Juntong Deng <[email protected]>
- Loading branch information
1 parent
277878b
commit 516b369
Showing
5 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include <sys/socket.h> | ||
#include <sys/types.h> | ||
#include <netinet/in.h> | ||
#include <netinet/tcp.h> | ||
|
||
#include "zdtmtst.h" | ||
|
||
const char *test_doc = "Check that different tcp socket options are restored"; | ||
const char *test_author = "Juntong Deng <[email protected]>"; | ||
|
||
#ifdef ZDTM_VAL_ZERO | ||
#define TCP_OPT_VAL 0 | ||
#else | ||
#define TCP_OPT_VAL 1 | ||
#endif | ||
|
||
#ifndef SOL_TCP | ||
#define SOL_TCP 6 | ||
#endif | ||
|
||
struct sk_opt { | ||
int level; | ||
int opt; | ||
int val; | ||
}; | ||
|
||
struct sk_opt tcp_sk_opts[] = { | ||
{ SOL_TCP, TCP_CORK, TCP_OPT_VAL }, | ||
{ SOL_TCP, TCP_NODELAY, TCP_OPT_VAL }, | ||
}; | ||
|
||
struct sk_conf { | ||
int domain; | ||
int type; | ||
int protocol; | ||
int sk; | ||
} sk_confs[] = { | ||
{ AF_INET, SOCK_STREAM, IPPROTO_TCP }, | ||
{ AF_INET6, SOCK_STREAM, IPPROTO_TCP }, | ||
}; | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
struct sk_opt *opts = tcp_sk_opts; | ||
int n_opts = ARRAY_SIZE(tcp_sk_opts); | ||
int exit_code = 1; | ||
int i, j, val; | ||
socklen_t len; | ||
|
||
test_init(argc, argv); | ||
|
||
for (i = 0; i < ARRAY_SIZE(sk_confs); i++) { | ||
sk_confs[i].sk = socket(sk_confs[i].domain, sk_confs[i].type, sk_confs[i].protocol); | ||
if (sk_confs[i].sk == -1) { | ||
pr_perror("socket(%d,%d,%d) failed", sk_confs[i].domain, sk_confs[i].type, | ||
sk_confs[i].protocol); | ||
goto close; | ||
} | ||
} | ||
|
||
for (i = 0; i < ARRAY_SIZE(sk_confs); i++) { | ||
for (j = 0; j < n_opts; j++) { | ||
val = opts[j].val; | ||
if (setsockopt(sk_confs[i].sk, opts[j].level, opts[j].opt, &val, sizeof(int)) == -1) { | ||
pr_perror("setsockopt(%d, %d) failed", opts[j].level, opts[j].opt); | ||
goto close; | ||
} | ||
} | ||
} | ||
|
||
test_daemon(); | ||
test_waitsig(); | ||
|
||
for (i = 0; i < ARRAY_SIZE(sk_confs); i++) { | ||
for (j = 0; j < n_opts; j++) { | ||
len = sizeof(int); | ||
if (getsockopt(sk_confs[i].sk, opts[j].level, opts[j].opt, &val, &len) == -1) { | ||
pr_perror("getsockopt(%d, %d) failed", opts[j].level, opts[j].opt); | ||
goto close; | ||
} | ||
|
||
if (val != opts[j].val) { | ||
fail("Unexpected value socket(%d,%d,%d) opts(%d,%d)", sk_confs[i].domain, | ||
sk_confs[i].type, sk_confs[i].protocol, opts[j].level, opts[j].opt); | ||
goto close; | ||
} | ||
} | ||
} | ||
|
||
pass(); | ||
exit_code = 0; | ||
close: | ||
for (i = 0; i < ARRAY_SIZE(sk_confs); i++) | ||
close(sk_confs[i].sk); | ||
return exit_code; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{'flags': 'suid'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
./sock_tcp_opts00.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
./sock_tcp_opts00.desc |