forked from niranjan-m-gowda/LLMLNCL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_win.cpp
More file actions
147 lines (137 loc) · 4.03 KB
/
test_win.cpp
File metadata and controls
147 lines (137 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
* Copyright 2022 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Written by: Evgeny Stupachenko
* e-mail: evgeny.v.stupachenko@intel.com
*/
#include "multilink.h"
#include <stdio.h>
#include <windows.h>
#include <tchar.h>
#include <strsafe.h>
#include <synchapi.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <sysinfoapi.h>
//#include <unistd.h>
MultiLink MlSend;
MultiLink MlReceive;
uint16_t LocalPort = 3000;
uint16_t RemotePort = 4000;
uint16_t LocalNum = 0;
uint16_t RemoteNum = 0;
uint16_t N = 0;
uint16_t K = 0;
uint16_t TestType = 0;
DWORD WINAPI runReceive(LPVOID Arg) {
//void *runReceive(void *arg) {
uint16_t Size = 0;
uint8_t Data[0xFFFF];
// For receive Local and Remote are swaped
MlReceive.setCommDeviceNumber(RemoteNum, LocalNum);
for (int32_t i = 0; i < RemoteNum; i++)
MlReceive.addLocalIfaceAndPort("lo", LocalPort + i);
for (int32_t i = 0; i < LocalNum; i++)
MlReceive.addRemoteAddrAndPort("127.0.0.1", RemotePort + i);
MlReceive.setRedundancy(N, K);
MlReceive.initiateLinks();
Sleep(1000);
if (TestType == 0) {
// Receiving increment
for (int32_t i = 0; i < 1024; i++) {
MlReceive.receive(&Size, Data);
if (Size != 4) {
printf("Wrong size on receive %u, expected 4\n", Size);
exit(-2); // wrong size on increment receive
}
if (*(int32_t *)Data != i) {
printf("Wrong data on receive %d, expected %d\n", *(int32_t *)Data, i);
exit(-3); // wrong increment received
}
Sleep(10);
}
} else if (TestType == 1) {
// Receiving big packet
Sleep(1000);
MlReceive.receive(&Size, Data);
printf("Size %d\n", Size);
if (Size != 32768) {
printf("Wrong size on receive %u, expected 4\n", Size);
exit(-2); // wrong size on increment receive
}
for (int32_t i = 0; i < 32768 / 4; i++)
if (((int32_t *)Data)[i] != i) {
printf("Wrong data on receive %d, expected %d\n", ((int32_t *)Data)[i], i);
exit(-3); // wrong increment received
}
} else {
// just handshake
}
printf("Finish receive\n");
return NULL;
}
int main(int argc, char *argv[]) {
uint16_t Cntr = 0, Size;
uint8_t Data[0xFFFF];
//pthread_t ReceiveThread;
HANDLE ReceiveThread;
if (argc < 6)
return 1;
TestType = atoi(argv[1]);
LocalNum = atoi(argv[2]);
RemoteNum = atoi(argv[3]);
N = atoi(argv[4]);
K = atoi(argv[5]);
MlSend.setCommDeviceNumber(LocalNum, RemoteNum);
for (int32_t i = 0; i < LocalNum; i++)
// MlSend.addLocalIfaceAndPort("ethernet_0", RemotePort + i);
MlSend.addLocalIfaceAndPort("lo", RemotePort + i);
MlSend.setRedundancy(N, K);
DWORD dwThreadIdArray;
ReceiveThread = CreateThread(NULL, 0, runReceive,
NULL, 0, &dwThreadIdArray);
//pthread_create(&ReceiveThread, NULL, runReceive, NULL);
Sleep(2000);
printf("Test type %d\n", TestType);
if (TestType == 0) {
// Sending increment
for (int32_t i = 0; i < 1024; i++) {
Size = 4;
*(int32_t *)Data = i;
MlSend.send(Size, Data);
Sleep(10);
}
} else if (TestType == 1) {
// sending big packet
for (int32_t i = 0; i < 32768 / 4; i++)
((int32_t *)Data)[i] = i;
Size = 32768;
MlSend.send(Size, Data);
} else {
// just handshake
}
Sleep(2000);
// if receive thread not finished return error
//if (pthread_cancel(ReceiveThread) == 0)
// return 1;
//if (TerminateThread(ReceiveThread, 0)) {
// printf("Test failed\n");
// return 1;
//}
printf("Test passed\n");
return 0;
}