From 1bae1aab037c94b86fd099182dce40dbd315df1b Mon Sep 17 00:00:00 2001
From: Bob Lantz <rlantz@cs.stanford.edu>
Date: Wed, 1 Oct 2014 14:20:59 -0700
Subject: [PATCH] Turn of ntpd and set date manually before tests

This should fix the problem where we see the first test
taking negative time, as well as possibly other issues
with performance tests which may be sensitive to changes
in wall clock time.

Fixes #398
---
 util/vm/build.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/util/vm/build.py b/util/vm/build.py
index 7d77238a..6d46c892 100755
--- a/util/vm/build.py
+++ b/util/vm/build.py
@@ -484,6 +484,15 @@ def login( vm, user='mininet', password='mininet' ):
     log( '* Waiting for login...' )
 
 
+def disableNtpd( vm, prompt=Prompt, ntpserver='pool.ntp.org' ):
+    "Turn off ntpd and set clock from pool.ntp.org"
+    log( '* Turning off ntpd' )
+    vm.sendline( 'sudo -n service ntp stop' )
+    vm.expect( prompt )
+    log( '* Setting clock from', ntpserver  )
+    vm.sendline( 'sudo -n ntpdate ' + ntpserver )
+
+
 def sanityTest( vm ):
     "Run Mininet sanity test (pingall) in vm"
     vm.sendline( 'sudo mn --test pingall' )
@@ -802,6 +811,10 @@ def build( flavor='raring32server', tests=None, pre='', post='', memory=1024 ):
 
 def runTests( vm, tests=None, pre='', post='', prompt=Prompt ):
     "Run tests (list) in vm (pexpect object)"
+    # We disable ntpd and set the time so that it won't be
+    # messing with the time during tests
+    disableNtpd( vm )
+    vm.expect( prompt )
     if Branch:
         checkOutBranch( vm, branch=Branch )
         vm.expect( prompt )
-- 
GitLab