diff options
author | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2013-05-15 10:26:50 -0400 |
---|---|---|
committer | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2013-05-15 10:26:50 -0400 |
commit | 12e04ffcd93b25dfd726d46338c2ee7d23de556e (patch) | |
tree | f91479a62805619168994fd3ee55e3ffa23fc24e /tools/testing/selftests/net/socket.c | |
parent | 9eff37a8713939f218ab8bf0dc93f1d67af7b8b4 (diff) | |
parent | f722406faae2d073cc1d01063d1123c35425939e (diff) |
Merge tag 'v3.10-rc1' into stable/for-linus-3.10
Linux 3.10-rc1
* tag 'v3.10-rc1': (12273 commits)
Linux 3.10-rc1
[SCSI] qla2xxx: Update firmware link in Kconfig file.
[SCSI] iscsi class, qla4xxx: fix sess/conn refcounting when find fns are used
[SCSI] sas: unify the pointlessly separated enums sas_dev_type and sas_device_type
[SCSI] pm80xx: thermal, sas controller config and error handling update
[SCSI] pm80xx: NCQ error handling changes
[SCSI] pm80xx: WWN Modification for PM8081/88/89 controllers
[SCSI] pm80xx: Changed module name and debug messages update
[SCSI] pm80xx: Firmware flash memory free fix, with addition of new memory region for it
[SCSI] pm80xx: SPC new firmware changes for device id 0x8081 alone
[SCSI] pm80xx: Added SPCv/ve specific hardware functionalities and relevant changes in common files
[SCSI] pm80xx: MSI-X implementation for using 64 interrupts
[SCSI] pm80xx: Updated common functions common for SPC and SPCv/ve
[SCSI] pm80xx: Multiple inbound/outbound queue configuration
[SCSI] pm80xx: Added SPCv/ve specific ids, variables and modify for SPC
[SCSI] lpfc: fix up Kconfig dependencies
[SCSI] Handle MLQUEUE busy response in scsi_send_eh_cmnd
dm cache: set config value
dm cache: move config fns
dm thin: generate event when metadata threshold passed
...
Diffstat (limited to 'tools/testing/selftests/net/socket.c')
-rw-r--r-- | tools/testing/selftests/net/socket.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/tools/testing/selftests/net/socket.c b/tools/testing/selftests/net/socket.c new file mode 100644 index 000000000000..0f227f2f9be9 --- /dev/null +++ b/tools/testing/selftests/net/socket.c | |||
@@ -0,0 +1,92 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <errno.h> | ||
3 | #include <unistd.h> | ||
4 | #include <string.h> | ||
5 | #include <sys/types.h> | ||
6 | #include <sys/socket.h> | ||
7 | #include <netinet/in.h> | ||
8 | |||
9 | struct socket_testcase { | ||
10 | int domain; | ||
11 | int type; | ||
12 | int protocol; | ||
13 | |||
14 | /* 0 = valid file descriptor | ||
15 | * -foo = error foo | ||
16 | */ | ||
17 | int expect; | ||
18 | |||
19 | /* If non-zero, accept EAFNOSUPPORT to handle the case | ||
20 | * of the protocol not being configured into the kernel. | ||
21 | */ | ||
22 | int nosupport_ok; | ||
23 | }; | ||
24 | |||
25 | static struct socket_testcase tests[] = { | ||
26 | { AF_MAX, 0, 0, -EAFNOSUPPORT, 0 }, | ||
27 | { AF_INET, SOCK_STREAM, IPPROTO_TCP, 0, 1 }, | ||
28 | { AF_INET, SOCK_DGRAM, IPPROTO_TCP, -EPROTONOSUPPORT, 1 }, | ||
29 | { AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0, 1 }, | ||
30 | { AF_INET, SOCK_STREAM, IPPROTO_UDP, -EPROTONOSUPPORT, 1 }, | ||
31 | }; | ||
32 | |||
33 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) | ||
34 | #define ERR_STRING_SZ 64 | ||
35 | |||
36 | static int run_tests(void) | ||
37 | { | ||
38 | char err_string1[ERR_STRING_SZ]; | ||
39 | char err_string2[ERR_STRING_SZ]; | ||
40 | int i, err; | ||
41 | |||
42 | err = 0; | ||
43 | for (i = 0; i < ARRAY_SIZE(tests); i++) { | ||
44 | struct socket_testcase *s = &tests[i]; | ||
45 | int fd; | ||
46 | |||
47 | fd = socket(s->domain, s->type, s->protocol); | ||
48 | if (fd < 0) { | ||
49 | if (s->nosupport_ok && | ||
50 | errno == EAFNOSUPPORT) | ||
51 | continue; | ||
52 | |||
53 | if (s->expect < 0 && | ||
54 | errno == -s->expect) | ||
55 | continue; | ||
56 | |||
57 | strerror_r(-s->expect, err_string1, ERR_STRING_SZ); | ||
58 | strerror_r(errno, err_string2, ERR_STRING_SZ); | ||
59 | |||
60 | fprintf(stderr, "socket(%d, %d, %d) expected " | ||
61 | "err (%s) got (%s)\n", | ||
62 | s->domain, s->type, s->protocol, | ||
63 | err_string1, err_string2); | ||
64 | |||
65 | err = -1; | ||
66 | break; | ||
67 | } else { | ||
68 | close(fd); | ||
69 | |||
70 | if (s->expect < 0) { | ||
71 | strerror_r(errno, err_string1, ERR_STRING_SZ); | ||
72 | |||
73 | fprintf(stderr, "socket(%d, %d, %d) expected " | ||
74 | "success got err (%s)\n", | ||
75 | s->domain, s->type, s->protocol, | ||
76 | err_string1); | ||
77 | |||
78 | err = -1; | ||
79 | break; | ||
80 | } | ||
81 | } | ||
82 | } | ||
83 | |||
84 | return err; | ||
85 | } | ||
86 | |||
87 | int main(void) | ||
88 | { | ||
89 | int err = run_tests(); | ||
90 | |||
91 | return err; | ||
92 | } | ||