Permalink
Browse files

Refactoring and added root tests to check TUN device functionality.

  • Loading branch information...
1 parent 53df63c commit be0561f9a15f1c548c62771ddecac83d1cdcedcd Caleb James DeLisle committed Dec 8, 2012
Showing with 1,477 additions and 577 deletions.
  1. +1 −1 admin/angel/Core.c
  2. +56 −0 cmake/modules/HasRoot.cmake
  3. +48 −9 cmake/modules/RemoteTest.cmake
  4. +12 −5 cmake/modules/Test.cmake
  5. +3 −1 interface/CMakeLists.txt
  6. +1 −1 interface/ETHInterface.h
  7. +50 −99 interface/ETHInterface_Linux.c
  8. +1 −1 interface/ETHInterface_admin.c
  9. +1 −1 interface/ETHInterface_admin.h
  10. +15 −29 {net → interface}/InterfaceController.h
  11. +199 −0 interface/MultiInterface.c
  12. +45 −0 interface/MultiInterface.h
  13. +28 −6 interface/TUNConfigurator.h
  14. +17 −8 interface/TUNConfigurator_FreeBSD.c
  15. +18 −9 interface/TUNConfigurator_Illumos.c
  16. +67 −9 interface/TUNConfigurator_Linux.c
  17. +17 −8 interface/TUNConfigurator_OSX.c
  18. +17 −8 interface/TUNConfigurator_OpenBSD.c
  19. +14 −5 interface/TUNConfigurator_W32.c
  20. +46 −79 interface/TUNInterface.c
  21. +17 −2 interface/TUNInterface.h
  22. +31 −87 interface/UDPInterface.c
  23. +3 −4 interface/UDPInterface.h
  24. +1 −1 interface/UDPInterface_admin.c
  25. +1 −1 interface/UDPInterface_admin.h
  26. +11 −6 interface/UDPInterface_pvt.h
  27. +5 −0 interface/test/CMakeLists.txt
  28. +117 −0 interface/test/MultiInterface_test.c
  29. +134 −0 interface/test/TUNInterface_ipv4_root_test.c
  30. +133 −0 interface/test/TUNInterface_ipv6_root_test.c
  31. +8 −4 interface/test/UDPInterface_communication_test.c
  32. +7 −20 interface/test/UDPInterface_test.c
  33. +38 −130 net/DefaultInterfaceController.c
  34. +2 −1 net/DefaultInterfaceController.h
  35. +17 −4 net/Ducttape.c
  36. +2 −9 net/test/DefaultInterfaceController_test.c
  37. +9 −11 test/TestFramework.c
  38. +2 −0 test/TestFramework.h
  39. +6 −1 test/threeNodes_test.c
  40. +6 −0 test/twoNodes_test.c
  41. +8 −0 tunnel/IpTunnel.c
  42. +3 −0 tunnel/test/IpTunnel_test.c
  43. +1 −0 util/CMakeLists.txt
  44. +38 −17 util/Map.h
  45. +39 −0 util/events/Event.h
  46. +1 −0 util/events/libevent/CMakeLists.txt
  47. +77 −0 util/events/libevent/Event.c
  48. +17 −0 util/platform/CMakeLists.txt
  49. +21 −0 util/platform/Socket.c
  50. +26 −0 util/platform/Socket.h
  51. +24 −0 wire/Ethernet.h
  52. +16 −0 wire/Message.h
View
@@ -169,7 +169,7 @@ void Core_initTunnel(String* desiredDeviceName,
//Ducttape_setUserInterface(dt, &icmp->internal);
Ducttape_setUserInterface(dt, &tun->iface);
- TUNConfigurator_setIpAddress(assignedTunName, ipAddr, addressPrefix, logger, eh);
+ TUNConfigurator_addIp6Address(assignedTunName, ipAddr, addressPrefix, logger, eh);
TUNConfigurator_setMTU(assignedTunName, DEFAULT_MTU, logger, eh);
}
@@ -0,0 +1,56 @@
+# You may redistribute this program and/or modify it under the terms of
+# the GNU General Public License as published by the Free Software Foundation,
+# either version 3 of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+if (NOT HasRoot_CMAKE)
+
+set(content "
+ #ifdef WIN32
+ #include <windows.h>
+ #include <string.h>
+ int main()
+ {
+ char buff[32] = {0};
+ DWORD length = 32;
+ GetUserNameA(buff, &length);
+ printf(\"%s\\n\", buff);
+ return strcmp(\"Administrator\", buff);
+ }
+ #else
+ #include <unistd.h>
+ int main()
+ {
+ return getuid();
+ }
+ #endif
+")
+
+file(WRITE ${CMAKE_BINARY_DIR}/HasRoot.c "${content}")
+RemoteTest_tryRun(runRes compRes ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}/HasRoot.c
+ COMPILE_OUTPUT_VARIABLE compileOut
+ RUN_OUTPUT_VARIABLE output
+)
+if (NOT compRes)
+ message("${compileOut}")
+ message(FATAL_ERROR "Compilation failed")
+endif()
+if ("${runRes}" STREQUAL "PLEASE_FILL_OUT-FAILED_TO_RUN")
+ message(FATAL_ERROR "RunFailed")
+endif()
+if (NOT runRes)
+ set(HasRoot TRUE CACHE INTERNAL "")
+ message("Testing with root access, root tests enabled")
+else()
+ set(HasRoot FALSE CACHE INTERNAL "")
+ message("Testing without root access, root tests disabled")
+endif()
+
+set(HasRoot_CMAKE TRUE CACHE INTERNAL "")
+endif()
@@ -9,15 +9,40 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-if (NOT REMOTE_TEST)
-set(REMOTE_TEST TRUE)
-file(READ ${CMAKE_SOURCE_DIR}/cmake/modules/RemoteTestTemplate.bash template)
-string(REPLACE "__REMOTE_TEST_IP_PORT__" "${REMOTE_TEST_IP_PORT}" FILE_CONTENT "${template}")
-set(template FALSE)
+if (CMAKE_CROSSCOMPILING AND REMOTE_TEST_IP_PORT)
+ file(READ ${CMAKE_SOURCE_DIR}/cmake/modules/RemoteTestTemplate.bash template)
+ string(REPLACE "__REMOTE_TEST_IP_PORT__" "${REMOTE_TEST_IP_PORT}" FILE_CONTENT "${template}")
+ # try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR
+ # bindir srcfile [CMAKE_FLAGS <Flags>]
+ # [COMPILE_DEFINITIONS <flags>]
+ # [COMPILE_OUTPUT_VARIABLE comp]
+ # [RUN_OUTPUT_VARIABLE run]
+ # [OUTPUT_VARIABLE var]
+ # [ARGS <arg1> <arg2>...])
+ function(RemoteTest_tryRun RUN_RESULT COMPILE_RESULT bindir srcfile)
+ set(params "")
+ foreach(i RANGE ${ARGC})
+ list(APPEND params ${ARGV${i}})
+ endforeach()
+ string(RANDOM rand)
+ set(execFile ${CMAKE_CURRENT_BINARY_DIR}/${rand}_remote_executable)
+ try_compile(${COMPILE_RESULT} ${bindir} ${srcfile} COPY_FILE ${execFile})
+
+ message("Running remote test: ${execFile}_remote.sh")
+ string(REPLACE "__TEST_FILE__" "${execFile}" fileContent "${FILE_CONTENT}")
+ file(WRITE "${execFile}_remote.sh" "${fileContent}")
+ execute_process(COMMAND chmod "a+x" ${execFile}_remote.sh)
+ execute_process(COMMAND ${execFile}_remote.sh
+ RESULT_VARIABLE runResult
+ OUTPUT_VARIABLE output
+ )
+ set(${RUN_RESULT} ${runResult} PARENT_SCOPE)
+ set(${RUN_OUTPUT_VARIABLE} ${output} PARENT_SCOPE)
+
+ endfunction()
-if (REMOTE_TEST_IP_PORT)
function(remoteTest 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}")
@@ -27,10 +52,24 @@ if (REMOTE_TEST_IP_PORT)
add_test(${executable} ${CMAKE_CURRENT_BINARY_DIR}/${executable}_remote.sh)
message(" Running test remotely")
endFunction()
-else()
- function(remoteTest executable)
+elseif(CMAKE_CROSSCOMPILING)
+ function(RemoteTest_addTest executable)
message(" REMOTE_TEST_IP_PORT unspecified, skipping test.")
endfunction()
-endif()
+ function(RemoteTest_tryRun)
+ message(FATAL_ERROR "REMOTE_TEST_IP_PORT unspecified.")
+ endfunction()
+else()
+ function(RemoteTest_addTest executable)
+ add_test(${executable} ${executable})
+ endfunction()
+
+ function(RemoteTest_tryRun)
+ set(params "")
+ foreach(i RANGE ${ARGC})
+ list(APPEND params ${ARGV${i}})
+ endforeach()
+ try_run(${params})
+ endfunction()
endif()
View
@@ -10,21 +10,28 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
include(${CMAKE_SOURCE_DIR}/cmake/modules/RemoteTest.cmake)
+include(${CMAKE_SOURCE_DIR}/cmake/modules/HasRoot.cmake)
string(REGEX REPLACE "^.*/" "" main_dir_name ${CMAKE_SOURCE_DIR})
string(REPLACE ${CMAKE_SOURCE_DIR} ${main_dir_name} this_dir ${CMAKE_CURRENT_SOURCE_DIR})
message("-- Tests to run for " ${this_dir})
add_definitions(-g -DTEST)
-foreach(test_source ${Test_FILES})
+function(Test_process test_source isRootTest)
string(REPLACE "test.c" "test" test_bin ${test_source})
message(" " ${test_source})
add_executable(${test_bin} ${test_source})
target_link_libraries(${test_bin} ${Test_LIBRARIES})
- if (CMAKE_CROSSCOMPILING)
- remoteTest(${test_bin})
- else()
- add_test(${test_bin} ${test_bin})
+ if (NOT isRootTest OR HasRoot)
+ RemoteTest_addTest(${test_bin})
endif()
+endfunction()
+
+foreach(test_source ${Test_FILES})
+ Test_process(${test_source} FALSE)
endforeach()
+foreach(test_source ${Test_ROOT_FILES})
+ Test_process(${test_source} TRUE)
+endforeach()
+
message("")
View
@@ -32,12 +32,14 @@ add_library(interface
InterfaceConnector.c
SessionManager.c
ICMP6Generator.c
+ MultiInterface.c
)
target_link_libraries(interface
util
cjdns-crypto-key
- ${LIBEVENT2_LIBRARIES}
+ cjdns-util-events-libevent
+ cjdns-util-platform-socket
)
add_library(cjdns-interface-pipeinterface
View
@@ -17,7 +17,7 @@
#include "util/events/EventBase.h"
#include "interface/Interface.h"
-#include "net/InterfaceController.h"
+#include "interface/InterfaceController.h"
#include "util/log/Log.h"
#include "memory/Allocator.h"
Oops, something went wrong.

0 comments on commit be0561f

Please sign in to comment.