bindings, build: fix bindings and visualizer build
Includes: - scan python scripts - run python scripts from ns3 - replace visualizer file copy with configure_file to prevent cmake refreshes - replace ns__init__.py file copy with configure_file to prevent cmake refreshes - fix bindings scanning with cmake - pass include directories to modulegen for castxml consumption - add missing parameters of Recv in python-unit-tests.py - change apiscan targets from apiscan-module to libmodule-apiscan - change bindings targets from module-bingings to libmodule-bindings - scanning and bindings build tests - scan scratch python scripts - replace FindPython3 with FindPython to be compatible with CMake 3.10 - do not export private visual-simulator-impl.h - do not export udp-socket-impl.h - use .so suffix for bindings on Mac instead of .dylib
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2008-2011 INESC Porto
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
@@ -25,6 +27,8 @@ import ns.mobility
|
||||
import ns.csma
|
||||
import ns.applications
|
||||
|
||||
UINT32_MAX = 0xFFFFFFFF
|
||||
|
||||
|
||||
## TestSimulator class
|
||||
class TestSimulator(unittest.TestCase):
|
||||
@@ -170,7 +174,7 @@ class TestSimulator(unittest.TestCase):
|
||||
@return none
|
||||
"""
|
||||
assert self._received_packet is None
|
||||
self._received_packet = socket.Recv()
|
||||
self._received_packet = socket.Recv(maxSize=UINT32_MAX, flags=0)
|
||||
|
||||
sink = ns.network.Socket.CreateSocket(node, ns.core.TypeId.LookupByName("ns3::UdpSocketFactory"))
|
||||
sink.Bind(ns.network.InetSocketAddress(ns.network.Ipv4Address.GetAny(), 80))
|
||||
|
||||
@@ -1138,8 +1138,8 @@ class NS3BuildBaseTestCase(NS3BaseTestCase):
|
||||
f.write("""
|
||||
#include <ns3/core-module.h>
|
||||
using namespace ns3;
|
||||
int main ()
|
||||
{
|
||||
int main ()
|
||||
{
|
||||
Simulator::Stop (Seconds (1.0));
|
||||
Simulator::Run ();
|
||||
Simulator::Destroy ();
|
||||
@@ -1246,6 +1246,92 @@ class NS3BuildBaseTestCase(NS3BaseTestCase):
|
||||
stdout = stdout.replace("scratch_%s" % target_cmake, "") # remove build lines
|
||||
self.assertIn(target_to_run.split("/")[-1], stdout)
|
||||
|
||||
NS3BuildBaseTestCase.cleaned_once = False
|
||||
|
||||
def test_10_PybindgenBindings(self):
|
||||
"""!
|
||||
Test if cmake is calling pybindgen through modulegen to generate
|
||||
the bindings source files correctly
|
||||
@return None
|
||||
"""
|
||||
|
||||
# First we enable python bindings
|
||||
return_code, stdout, stderr = run_ns3("configure --enable-examples --enable-tests --enable-python-bindings")
|
||||
self.assertEqual(return_code, 0)
|
||||
|
||||
# Then look for python bindings sources
|
||||
core_bindings_generated_sources_path = os.path.join(ns3_path, "build", "src", "core", "bindings")
|
||||
core_bindings_sources_path = os.path.join(ns3_path, "src", "core", "bindings")
|
||||
core_bindings_path = os.path.join(ns3_path, "build", "bindings", "python", "ns")
|
||||
core_bindings_header = os.path.join(core_bindings_generated_sources_path, "ns3module.h")
|
||||
core_bindings_source = os.path.join(core_bindings_generated_sources_path, "ns3module.cc")
|
||||
self.assertTrue(os.path.exists(core_bindings_header))
|
||||
self.assertTrue(os.path.exists(core_bindings_source))
|
||||
|
||||
# Then try to build the bindings for the core module
|
||||
return_code, stdout, stderr = run_ns3("build core-bindings")
|
||||
self.assertEqual(return_code, 0)
|
||||
|
||||
# Then check if it was built
|
||||
self.assertGreater(len(list(filter(lambda x: "_core" in x, os.listdir(core_bindings_path)))), 0)
|
||||
|
||||
# Now enable python bindings scanning
|
||||
return_code, stdout, stderr = run_ns3("configure -- -DNS3_SCAN_PYTHON_BINDINGS=ON")
|
||||
self.assertEqual(return_code, 0)
|
||||
|
||||
# Get the file status for the current scanned bindings
|
||||
bindings_sources = os.listdir(core_bindings_sources_path)
|
||||
bindings_sources = [os.path.join(core_bindings_sources_path, y) for y in bindings_sources]
|
||||
timestamps = {}
|
||||
[timestamps.update({x: os.stat(x)}) for x in bindings_sources]
|
||||
|
||||
# Try to scan the bindings for the core module
|
||||
return_code, stdout, stderr = run_ns3("build core-apiscan")
|
||||
self.assertEqual(return_code, 0)
|
||||
|
||||
# Check if they exist, are not empty and have a different timestamp
|
||||
generated_python_files = ["callbacks_list.py", "modulegen__gcc_LP64.py"]
|
||||
for binding_file in timestamps.keys():
|
||||
if os.path.basename(binding_file) in generated_python_files:
|
||||
self.assertTrue(os.path.exists(binding_file))
|
||||
self.assertGreater(os.stat(binding_file).st_size, 0)
|
||||
new_fstat = os.stat(binding_file)
|
||||
self.assertNotEqual(timestamps[binding_file].st_mtime, new_fstat.st_mtime)
|
||||
|
||||
# Then delete the old bindings sources
|
||||
for f in os.listdir(core_bindings_generated_sources_path):
|
||||
os.remove(os.path.join(core_bindings_generated_sources_path, f))
|
||||
|
||||
# Reconfigure to recreate the source files
|
||||
return_code, stdout, stderr = run_ns3("configure")
|
||||
self.assertEqual(return_code, 0)
|
||||
|
||||
# Check again if they exist
|
||||
self.assertTrue(os.path.exists(core_bindings_header))
|
||||
self.assertTrue(os.path.exists(core_bindings_source))
|
||||
|
||||
# Build the core bindings again
|
||||
return_code, stdout, stderr = run_ns3("build core-bindings")
|
||||
self.assertEqual(return_code, 0)
|
||||
|
||||
# Then check if it was built
|
||||
self.assertGreater(len(list(filter(lambda x: "_core" in x, os.listdir(core_bindings_path)))), 0)
|
||||
|
||||
# We are on python anyways, so we can just try to load it from here
|
||||
sys.path.insert(0, os.path.join(core_bindings_path, ".."))
|
||||
try:
|
||||
from ns import core
|
||||
except ImportError:
|
||||
self.assertTrue(True)
|
||||
|
||||
# Check if ns3 can find and run the python example
|
||||
return_code, stdout, stderr = run_ns3("run sample-simulator.py")
|
||||
self.assertEqual(return_code, 0)
|
||||
|
||||
# Check if test.py can find and run the python example
|
||||
return_code, stdout, stderr = run_program("./test.py", "-p src/core/examples/sample-simulator.py", python=True)
|
||||
self.assertEqual(return_code, 0)
|
||||
|
||||
|
||||
class NS3ExpectedUseTestCase(NS3BaseTestCase):
|
||||
"""!
|
||||
|
||||
Reference in New Issue
Block a user