ReactOS 0.4.15-dev-7931-gfd331f1
TcpIp_user.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: User mode part of the TcpIp.sys test suite
5 * PROGRAMMER: Jérôme Gardou <jerome.gardou@reactos.org>
6 */
7
8#include <kmt_test.h>
9#include <winsock2.h>
10
11#include "tcpip.h"
12
13static
16{
18
19 /* Start the special-purpose driver */
22 if (Error)
23 return Error;
24
25 return ERROR_SUCCESS;
26}
27
28static
29void
31{
32 /* Stop the driver. */
35}
36
37START_TEST(TcpIpTdi)
38{
40
42 ok_eq_int(Error, 0);
43 if (Error)
44 return;
45
48
50}
51
52static
57{
58 WORD WinsockVersion;
59 WSADATA WsaData;
60 int Error;
61 SOCKET ListenSocket, AcceptSocket;
62 struct sockaddr_in ListenAddress, AcceptAddress;
63 int AcceptAddressLength;
64 HANDLE ReadyToConnectEvent = (HANDLE)Parameter;
65
66 /* Initialize winsock */
67 WinsockVersion = MAKEWORD(2, 0);
68 Error = WSAStartup(WinsockVersion, &WsaData);
69 ok_eq_int(Error, 0);
70
71 ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
72 ok(ListenSocket != INVALID_SOCKET, "socket failed\n");
73
74 ZeroMemory(&ListenAddress, sizeof(ListenAddress));
75 ListenAddress.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
77 ListenAddress.sin_family = AF_INET;
78
79 Error = bind(ListenSocket, (struct sockaddr*)&ListenAddress, sizeof(ListenAddress));
80 ok_eq_int(Error, 0);
81
82 Error = listen(ListenSocket, 1);
83 ok_eq_int(Error, 0);
84
85 SetEvent(ReadyToConnectEvent);
86
87 AcceptAddressLength = sizeof(AcceptAddress);
88 AcceptSocket = accept(ListenSocket, (struct sockaddr*)&AcceptAddress, &AcceptAddressLength);
89 ok(AcceptSocket != INVALID_SOCKET, "accept failed\n");
90 ok_eq_long(AcceptAddressLength, sizeof(AcceptAddress));
91 ok_eq_hex(AcceptAddress.sin_addr.S_un.S_addr, inet_addr("127.0.0.1"));
93
94 return 0;
95}
96
97START_TEST(TcpIpConnect)
98{
99 HANDLE AcceptThread;
100 HANDLE ReadyToConnectEvent;
101 DWORD Error;
102
103 ReadyToConnectEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
104 ok(ReadyToConnectEvent != NULL, "CreateEvent failed\n");
105
106 AcceptThread = CreateThread(NULL, 0, AcceptProc, (PVOID)ReadyToConnectEvent, 0, NULL);
107 ok(AcceptThread != NULL, "CreateThread failed\n");
108
109 WaitForSingleObject(ReadyToConnectEvent, INFINITE);
110
112
115
116 Error = WaitForSingleObject(AcceptThread, 10 * 1000);
117 ok(Error == WAIT_OBJECT_0, "AcceptThread timed out\n");
118
120
121 WSACleanup();
122}
static void UnloadTcpIpTestDriver(void)
Definition: TcpIp_user.c:30
static DWORD LoadTcpIpTestDriver(void)
Definition: TcpIp_user.c:15
static DWORD WINAPI AcceptProc(_In_ LPVOID Parameter)
Definition: TcpIp_user.c:55
#define ok_eq_hex(value, expected)
Definition: apitest.h:77
#define ok_eq_ulong(value, expected)
Definition: apitest.h:63
#define ok_eq_long(value, expected)
Definition: apitest.h:62
#define ok_eq_int(value, expected)
Definition: apitest.h:60
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
BOOL Error
Definition: chkdsk.c:66
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
#define IPPROTO_TCP
Definition: ip.h:196
#define SOCK_STREAM
Definition: tcpip.h:118
#define AF_INET
Definition: tcpip.h:117
#define INFINITE
Definition: serial.h:102
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
#define inet_addr(cp)
Definition: inet.h:98
#define htons(x)
Definition: module.h:215
#define IOCTL_TEST_CONNECT
Definition: tcpip.h:3
#define IOCTL_TEST_TDI
Definition: tcpip.h:2
#define TEST_CONNECT_SERVER_PORT
Definition: tcpip.h:6
#define TEST_CONNECT_CLIENT_PORT
Definition: tcpip.h:7
#define _In_
Definition: ms_sal.h:308
#define L(x)
Definition: ntvdm.h:50
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
Definition: sockctrl.c:123
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
Definition: socklife.c:23
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
struct in_addr sin_addr
Definition: winsock.h:512
short sin_family
Definition: winsock.h:510
u_short sin_port
Definition: winsock.h:511
DWORD KmtLoadAndOpenDriver(IN PCWSTR ServiceName, IN BOOLEAN RestartIfRunning)
Definition: support.c:213
VOID KmtCloseDriver(VOID)
Definition: support.c:236
DWORD KmtSendToDriver(IN DWORD ControlCode)
Definition: support.c:259
VOID KmtUnloadDriver(VOID)
Definition: support.c:167
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
#define MAKEWORD(a, b)
Definition: typedefs.h:248
PVOID HANDLE
Definition: typedefs.h:73
#define ZeroMemory
Definition: winbase.h:1712
#define CreateEvent
Definition: winbase.h:3748
#define WAIT_OBJECT_0
Definition: winbase.h:406
#define WINAPI
Definition: msvc.h:6
int PASCAL FAR WSACleanup(void)
Definition: startup.c:60
#define INVALID_SOCKET
Definition: winsock.h:332
UINT_PTR SOCKET
Definition: winsock.h:47
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _In_opt_ PWSK_SOCKET AcceptSocket
Definition: wsk.h:173
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:323