Make examples that were in samples directory run
authorMitch Watrous <watrous@u.washington.edu>
Fri, 15 Apr 2011 13:03:02 -0700
changeset 7028 3963d3678649
parent 7026 b1e7e65c842c
child 7029 0df1e57ac40a
Make examples that were in samples directory run
src/core/examples/main-test-sync.cc
src/core/examples/wscript
src/core/test/examples-to-run.py
src/core/wscript
src/internet/test/examples-to-run.py
src/internet/wscript
src/mobility/test/examples-to-run.py
src/mobility/wscript
src/network/examples/main-test-sync.cc
src/network/examples/wscript
src/network/test/examples-to-run.py
src/network/wscript
src/propagation/test/examples-to-run.py
src/propagation/wscript
test.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/core/examples/main-test-sync.cc	Fri Apr 15 13:03:02 2011 -0700
@@ -0,0 +1,133 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+
+#include "ns3/simulator.h"
+#include "ns3/realtime-simulator-impl.h"
+#include "ns3/nstime.h"
+#include "ns3/log.h"
+#include "ns3/system-thread.h"
+#include "ns3/string.h"
+#include "ns3/config.h"
+#include "ns3/global-value.h"
+#include "ns3/ptr.h"
+
+#include <unistd.h>
+#include <sys/time.h>
+
+using namespace ns3;
+
+NS_LOG_COMPONENT_DEFINE ("TestSync");
+
+bool gFirstRun = false;
+
+void 
+inserted_function (void)
+{
+  NS_ASSERT (gFirstRun);
+  NS_LOG_UNCOND ("inserted_function() called at " << 
+    Simulator::Now ().GetSeconds () << " s");
+}
+
+void 
+background_function (void)
+{
+  NS_ASSERT (gFirstRun);
+  NS_LOG_UNCOND ("background_function() called at " << 
+    Simulator::Now ().GetSeconds () << " s");
+}
+
+void 
+first_function (void)
+{
+  NS_LOG_UNCOND ("first_function() called at " << 
+    Simulator::Now ().GetSeconds () << " s");
+  gFirstRun = true;
+}
+
+class FakeNetDevice
+{
+public:
+  FakeNetDevice ();
+  void Doit3 (void);
+  void Doit4 (void);
+};
+
+FakeNetDevice::FakeNetDevice ()
+{
+  NS_LOG_FUNCTION_NOARGS ();
+}
+
+void
+FakeNetDevice::Doit3 (void)
+{
+  NS_LOG_FUNCTION_NOARGS ();
+  sleep (1);
+  for (uint32_t i = 0; i < 10000; ++i)
+    {
+      //
+      // Exercise the realtime relative now path
+      //
+      DynamicCast<RealtimeSimulatorImpl> (Simulator::GetImplementation ())->ScheduleRealtimeNow (MakeEvent (&inserted_function));
+      usleep (1000);
+    }
+}
+
+void
+FakeNetDevice::Doit4 (void)
+{
+  NS_LOG_FUNCTION_NOARGS ();
+  sleep (1);
+  for (uint32_t i = 0; i < 10000; ++i)
+    {
+      //
+      // Exercise the realtime relative schedule path
+      //
+      DynamicCast<RealtimeSimulatorImpl> (Simulator::GetImplementation ())->ScheduleRealtime (Seconds (0), MakeEvent (&inserted_function));
+      usleep (1000);
+    }
+}
+
+void 
+test (void)
+{
+  GlobalValue::Bind ("SimulatorImplementationType", 
+    StringValue ("ns3::RealtimeSimulatorImpl"));
+
+  FakeNetDevice fnd;
+
+  // 
+  // Make sure ScheduleNow works when the system isn't running
+  //
+  DynamicCast<RealtimeSimulatorImpl> (Simulator::GetImplementation ())->ScheduleRealtimeNow(MakeEvent (&first_function));
+
+  // 
+  // drive the progression of m_currentTs at a ten millisecond rate from the main thread
+  //
+  for (double d = 0.; d < 14.999; d += 0.01)
+    {
+      Simulator::Schedule (Seconds (d), &background_function);
+    }
+
+  Ptr<SystemThread> st3 = Create<SystemThread> (
+    MakeCallback (&FakeNetDevice::Doit3, &fnd));
+  st3->Start ();
+
+  Ptr<SystemThread> st4 = Create<SystemThread> (
+    MakeCallback (&FakeNetDevice::Doit4, &fnd));
+  st4->Start ();
+
+  Simulator::Stop (Seconds (15.0));
+  Simulator::Run ();
+  st3->Join ();
+  st4->Join ();
+  Simulator::Destroy ();
+}
+
+int
+main (int argc, char *argv[])
+{
+  while (true)
+    {
+      test ();
+    }
+}
+
--- a/src/core/examples/wscript	Fri Apr 15 09:06:01 2011 -0700
+++ b/src/core/examples/wscript	Fri Apr 15 13:03:02 2011 -0700
@@ -4,7 +4,7 @@
     if not bld.env['ENABLE_EXAMPLES']:
         return;
 
-    obj = bld.create_ns3_program('main-attribute-value', ['core', 'node', 'devices/point-to-point'])
+    obj = bld.create_ns3_program('main-attribute-value', ['network', 'point-to-point'])
     obj.source = 'main-attribute-value.cc'
 
     obj = bld.create_ns3_program('main-callback', ['core'])
@@ -23,3 +23,7 @@
                                  ['core'])
     obj.source = 'sample-random-variable.cc'
 
+    if bld.env['ENABLE_THREADING'] and bld.env["ENABLE_REAL_TIME"]:
+        obj = bld.create_ns3_program('main-test-sync', ['network'])
+        obj.source = 'main-test-sync.cc'
+
--- a/src/core/test/examples-to-run.py	Fri Apr 15 09:06:01 2011 -0700
+++ b/src/core/test/examples-to-run.py	Fri Apr 15 13:03:02 2011 -0700
@@ -8,6 +8,12 @@
 #
 # See test.py for more information.
 cpp_examples = [
+    ("main-attribute-value", "True", "True"),
+    ("main-callback", "True", "True"),
+    ("sample-simulator", "True", "True"),
+    ("main-ptr", "True", "True"),
+    ("main-random-variable", "True", "True"),
+    ("sample-random-variable", "True", "True"),
 ]
 
 # A list of Python examples to run in order to ensure that they remain
@@ -16,4 +22,6 @@
 #     (example_name, do_run).
 #
 # See test.py for more information.
-python_examples = []
+python_examples = [
+    ("sample-simulator.py", "True"),
+]
--- a/src/core/wscript	Fri Apr 15 09:06:01 2011 -0700
+++ b/src/core/wscript	Fri Apr 15 13:03:02 2011 -0700
@@ -292,6 +292,9 @@
         core_test.uselib = core_test.uselib + ' GSL GSLCBLAS M'
         core_test.source.extend(['test/rng-test-suite.cc'])
 
+    if (bld.env['ENABLE_EXAMPLES']):
+        bld.add_subdirs('examples')
+
     pymod = bld.ns3_python_bindings()
     if pymod is not None:
         pymod.source += ['bindings/module_helpers.cc']
--- a/src/internet/test/examples-to-run.py	Fri Apr 15 09:06:01 2011 -0700
+++ b/src/internet/test/examples-to-run.py	Fri Apr 15 13:03:02 2011 -0700
@@ -8,6 +8,7 @@
 #
 # See test.py for more information.
 cpp_examples = [
+    ("main-simple", "True", "True"),
 ]
 
 # A list of Python examples to run in order to ensure that they remain
--- a/src/internet/wscript	Fri Apr 15 09:06:01 2011 -0700
+++ b/src/internet/wscript	Fri Apr 15 13:03:02 2011 -0700
@@ -283,5 +283,8 @@
         obj.uselib           = 'DL'
         internet_test.uselib = 'DL'
 
+    if (bld.env['ENABLE_EXAMPLES']):
+        bld.add_subdirs('examples')
+
     bld.ns3_python_bindings()
 
--- a/src/mobility/test/examples-to-run.py	Fri Apr 15 09:06:01 2011 -0700
+++ b/src/mobility/test/examples-to-run.py	Fri Apr 15 13:03:02 2011 -0700
@@ -8,6 +8,9 @@
 #
 # See test.py for more information.
 cpp_examples = [
+    ("main-grid-topology", "True", "True"),
+    ("main-random-topology", "True", "True"),
+    ("main-random-walk", "True", "True"),
 ]
 
 # A list of Python examples to run in order to ensure that they remain
--- a/src/mobility/wscript	Fri Apr 15 09:06:01 2011 -0700
+++ b/src/mobility/wscript	Fri Apr 15 13:03:02 2011 -0700
@@ -53,4 +53,7 @@
         'helper/ns2-mobility-helper.h',
         ]
 
+    if (bld.env['ENABLE_EXAMPLES']):
+        bld.add_subdirs('examples')
+
     bld.ns3_python_bindings()
--- a/src/network/examples/main-test-sync.cc	Fri Apr 15 09:06:01 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,133 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-
-#include "ns3/simulator.h"
-#include "ns3/realtime-simulator-impl.h"
-#include "ns3/nstime.h"
-#include "ns3/log.h"
-#include "ns3/system-thread.h"
-#include "ns3/string.h"
-#include "ns3/config.h"
-#include "ns3/global-value.h"
-#include "ns3/ptr.h"
-
-#include <unistd.h>
-#include <sys/time.h>
-
-using namespace ns3;
-
-NS_LOG_COMPONENT_DEFINE ("TestSync");
-
-bool gFirstRun = false;
-
-void 
-inserted_function (void)
-{
-  NS_ASSERT (gFirstRun);
-  NS_LOG_UNCOND ("inserted_function() called at " << 
-    Simulator::Now ().GetSeconds () << " s");
-}
-
-void 
-background_function (void)
-{
-  NS_ASSERT (gFirstRun);
-  NS_LOG_UNCOND ("background_function() called at " << 
-    Simulator::Now ().GetSeconds () << " s");
-}
-
-void 
-first_function (void)
-{
-  NS_LOG_UNCOND ("first_function() called at " << 
-    Simulator::Now ().GetSeconds () << " s");
-  gFirstRun = true;
-}
-
-class FakeNetDevice
-{
-public:
-  FakeNetDevice ();
-  void Doit3 (void);
-  void Doit4 (void);
-};
-
-FakeNetDevice::FakeNetDevice ()
-{
-  NS_LOG_FUNCTION_NOARGS ();
-}
-
-void
-FakeNetDevice::Doit3 (void)
-{
-  NS_LOG_FUNCTION_NOARGS ();
-  sleep (1);
-  for (uint32_t i = 0; i < 10000; ++i)
-    {
-      //
-      // Exercise the realtime relative now path
-      //
-      DynamicCast<RealtimeSimulatorImpl> (Simulator::GetImplementation ())->ScheduleRealtimeNow (MakeEvent (&inserted_function));
-      usleep (1000);
-    }
-}
-
-void
-FakeNetDevice::Doit4 (void)
-{
-  NS_LOG_FUNCTION_NOARGS ();
-  sleep (1);
-  for (uint32_t i = 0; i < 10000; ++i)
-    {
-      //
-      // Exercise the realtime relative schedule path
-      //
-      DynamicCast<RealtimeSimulatorImpl> (Simulator::GetImplementation ())->ScheduleRealtime (Seconds (0), MakeEvent (&inserted_function));
-      usleep (1000);
-    }
-}
-
-void 
-test (void)
-{
-  GlobalValue::Bind ("SimulatorImplementationType", 
-    StringValue ("ns3::RealtimeSimulatorImpl"));
-
-  FakeNetDevice fnd;
-
-  // 
-  // Make sure ScheduleNow works when the system isn't running
-  //
-  DynamicCast<RealtimeSimulatorImpl> (Simulator::GetImplementation ())->ScheduleRealtimeNow(MakeEvent (&first_function));
-
-  // 
-  // drive the progression of m_currentTs at a ten millisecond rate from the main thread
-  //
-  for (double d = 0.; d < 14.999; d += 0.01)
-    {
-      Simulator::Schedule (Seconds (d), &background_function);
-    }
-
-  Ptr<SystemThread> st3 = Create<SystemThread> (
-    MakeCallback (&FakeNetDevice::Doit3, &fnd));
-  st3->Start ();
-
-  Ptr<SystemThread> st4 = Create<SystemThread> (
-    MakeCallback (&FakeNetDevice::Doit4, &fnd));
-  st4->Start ();
-
-  Simulator::Stop (Seconds (15.0));
-  Simulator::Run ();
-  st3->Join ();
-  st4->Join ();
-  Simulator::Destroy ();
-}
-
-int
-main (int argc, char *argv[])
-{
-  while (true)
-    {
-      test ();
-    }
-}
-
--- a/src/network/examples/wscript	Fri Apr 15 09:06:01 2011 -0700
+++ b/src/network/examples/wscript	Fri Apr 15 13:03:02 2011 -0700
@@ -4,13 +4,9 @@
     if not bld.env['ENABLE_EXAMPLES']:
         return;
 
-    obj = bld.create_ns3_program('main-packet-header', ['common', 'core'])
+    obj = bld.create_ns3_program('main-packet-header', ['network'])
     obj.source = 'main-packet-header.cc'
 
-    obj = bld.create_ns3_program('main-packet-tag', ['common', 'core'])
+    obj = bld.create_ns3_program('main-packet-tag', ['network'])
     obj.source = 'main-packet-tag.cc'
 
-    if bld.env['ENABLE_THREADING'] and bld.env["ENABLE_REAL_TIME"]:
-        obj = bld.create_ns3_program('main-test-sync')
-        obj.source = 'main-test-sync.cc'
-
--- a/src/network/test/examples-to-run.py	Fri Apr 15 09:06:01 2011 -0700
+++ b/src/network/test/examples-to-run.py	Fri Apr 15 13:03:02 2011 -0700
@@ -8,6 +8,8 @@
 #
 # See test.py for more information.
 cpp_examples = [
+    ("main-packet-header", "True", "True"),
+    ("main-packet-tag", "True", "True"),
 ]
 
 # A list of Python examples to run in order to ensure that they remain
--- a/src/network/wscript	Fri Apr 15 09:06:01 2011 -0700
+++ b/src/network/wscript	Fri Apr 15 13:03:02 2011 -0700
@@ -126,4 +126,7 @@
         'helper/trace-helper.h',
         ]
 
+    if (bld.env['ENABLE_EXAMPLES']):
+        bld.add_subdirs('examples')
+
     bld.ns3_python_bindings()
--- a/src/propagation/test/examples-to-run.py	Fri Apr 15 09:06:01 2011 -0700
+++ b/src/propagation/test/examples-to-run.py	Fri Apr 15 13:03:02 2011 -0700
@@ -8,6 +8,7 @@
 #
 # See test.py for more information.
 cpp_examples = [
+    ("main-propagation-loss", "True", "True"),
 ]
 
 # A list of Python examples to run in order to ensure that they remain
--- a/src/propagation/wscript	Fri Apr 15 09:06:01 2011 -0700
+++ b/src/propagation/wscript	Fri Apr 15 13:03:02 2011 -0700
@@ -24,4 +24,7 @@
         'model/cost231-propagation-loss-model.h',
         ]
 
+    if (bld.env['ENABLE_EXAMPLES']):
+        bld.add_subdirs('examples')
+
     bld.ns3_python_bindings()
--- a/test.py	Fri Apr 15 09:06:01 2011 -0700
+++ b/test.py	Fri Apr 15 13:03:02 2011 -0700
@@ -47,6 +47,7 @@
     "NS3_MODULE_PATH",
     "NSC_ENABLED",
     "ENABLE_REAL_TIME",
+    "ENABLE_THREADING",
     "ENABLE_EXAMPLES",
     "EXAMPLE_DIRECTORIES",
     "ENABLE_PYTHON_BINDINGS",
@@ -56,6 +57,7 @@
 
 NSC_ENABLED = False
 ENABLE_REAL_TIME = False
+ENABLE_THREADING = False
 ENABLE_EXAMPLES = True
 ENABLE_CLICK = False
 ENABLE_OPENFLOW = False