Permalink
Browse files

Trying to fix bug on BSD/OSX which breaks root test

  • Loading branch information...
1 parent 30f83e9 commit 8bb4292f888ea1438d007ea475ac0cc46b5aabdc Caleb James DeLisle committed Dec 11, 2012
@@ -43,7 +43,7 @@ if (CMAKE_CROSSCOMPILING AND REMOTE_TEST_IP_PORT)
endfunction()
- function(remoteTest executable)
+ function(RemoteTest_addTest executable)
string(REPLACE "__TEST_FILE__" "${CMAKE_CURRENT_BINARY_DIR}/${executable}${CMAKE_EXECUTABLE_SUFFIX}" fileContent "${FILE_CONTENT}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${executable}_remote.sh "${fileContent}")
execute_process(COMMAND chmod
@@ -14,54 +14,11 @@
*/
#include "interface/Interface.h"
#include "interface/TUNInterface.h"
-#include "benc/String.h"
-#include "util/Endian.h"
-
-#include "util/platform/libc/string.h"
-#include <event2/event.h>
-
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#include <iphlpapi.h>
-#include <winbase.h>
-#include <io.h>
-
-// Windows maps interface names to NDIS names which are 256 bytes
-#define IFNAMSIZ 256
-
-#define EPERM WSAEPERM
-
-
-// Defined extra large so large MTU can be taken advantage of later.
-#define MAX_PACKET_SIZE 8192
-#define PADDING_SPACE (10240 - MAX_PACKET_SIZE)
-
-// The number of bytes at the beginning of the message which is used
-// to contain the type of packet.
-#define PACKET_INFO_SIZE 4
-
-
-static int openTunnel(const char* interfaceName, char assignedInterfaceName[IFNAMSIZ])
-{
- return 0;
-}
-
-static void closeInterface(void* vcontext)
-{
-}
-
-static void handleEvent(evutil_socket_t socket, short eventType, void* vcontext)
-{
-}
-
-static uint8_t sendMessage(struct Message* message, struct Interface* iface)
-{
- return 0;
-}
struct TUNInterface* TUNInterface_new(void* handle,
struct event_base* base,
- struct Allocator* allocator)
+ struct Allocator* allocator,
+ struct Log* logger)
{
return NULL;
}
@@ -18,9 +18,11 @@
#include "wire/Message.h"
#include <stdint.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
+#ifndef WIN32
+ #include <netinet/in.h>
+ #include <sys/socket.h>
+#endif
/**
* Simple and sane, the 4 bytes prior to the message contain flags and the
@@ -39,6 +41,7 @@ uint16_t TUNMessageType_pop_Linux(struct Message* message)
return ((uint16_t*) message->bytes)[-1];
}
+#ifndef WIN32
/**
* OSX and BSD is expect you to send the platform dependent
@@ -82,3 +85,5 @@ uint16_t TUNMessageType_pop_Illumos(struct Message* message)
{
return ethertypeForPacketType(message->bytes[0]);
}
+
+#endif
@@ -38,10 +38,12 @@
#include "wire/Ethernet.h"
#include "wire/Headers.h"
-#if defined(BSD) || defined(Illumos)
+#ifdef WIN32
+ #include <winsock2.h>
+#else
#include <sys/socket.h>
+ #include <netinet/in.h>
#endif
-#include <netinet/in.h>
// On loan from the DoD, thanks guys.
const uint8_t testAddrA[4] = {11, 0, 0, 1};
@@ -12,14 +12,18 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#define string_strcmp
-#define string_strlen
+#ifdef WIN32
+ // todo fix
+ int main() { return 1; }
+#else
+
#include "admin/testframework/AdminTestFramework.h"
#include "admin/Admin.h"
#include "admin/AdminClient.h"
#include "benc/Dict.h"
#include "benc/String.h"
#include "benc/Int.h"
+#include "exception/Jmp.h"
#include "interface/UDPInterface_pvt.h"
#include "interface/TUNInterface.h"
#include "interface/TUNMessageType.h"
@@ -102,6 +106,30 @@ static void fail(void* ignored)
Assert_true(!"timeout");
}
+// Mac OSX and BSD do not set up their TUN devices synchronously.
+// We'll just keep on trying until this works.
+static struct UDPInterface* setupUDP(struct EventBase* base,
+ const char* bindAddr,
+ struct Allocator* allocator,
+ struct Log* logger,
+ struct InterfaceController* ic)
+{
+ // try for 20 seconds.
+ for (int i = 0; i < 20; i++) {
+ struct Jmp jmp;
+ Jmp_try(jmp) {
+ return UDPInterface_new(base, bindAddr, allocator, &jmp.handler, logger, ic);
+ } Jmp_catch {
+ #ifdef BSD
+ usleep(1000);
+ #else
+ sleep(1);
+ #endif
+ }
+ }
+ Assert_true(!"Couldn't setup UDP");
+}
+
int main(int argc, char** argv)
{
struct Allocator* alloc = CanaryAllocator_new(MallocAllocator_new(1<<20), NULL);
@@ -119,13 +147,7 @@ int main(int argc, char** argv)
TUNConfigurator_addIp6Address(assignedInterfaceName, testAddrA, 126, logger, NULL);
struct TUNInterface* tun = TUNInterface_new(tunPtr, base, alloc, logger);
- #if defined(OSX) || defined(BSD)
- // Mac OSX and BSD do not set up their TUN devices synchronously.
- // There should be a proper way to do this but I'm too lazy to look for it atm.
- usleep(10 * 1000);
- #endif
-
- struct UDPInterface* udp = UDPInterface_new(base, "[fd00::1]", alloc, NULL, logger, &ic);
+ struct UDPInterface* udp = setupUDP(base, "[fd00::1]", alloc, logger, &ic);
struct sockaddr_in6 sin = { .sin6_family = AF_INET6 };
sin.sin6_port = udp->boundPort_be;
@@ -145,3 +167,5 @@ int main(int argc, char** argv)
EventBase_beginLoop(base);
}
+
+#endif
View
@@ -16,6 +16,8 @@
#define Socket_H
#ifdef WIN32
+ #include <stdint.h>
+
#define Socket intptr_t
#else
#define Socket int

0 comments on commit 8bb4292

Please sign in to comment.