# Copyright 2015 Google Inc. All Rights Reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import subprocess


def RunTest(cmd, use_elf_loader=True):
  if use_elf_loader:
    cmd = ['./out/elf_loader'] + cmd
  print '* Running test: %s' % ' '.join(cmd)
  subprocess.check_call(['./out/ptracer'] + cmd)
  subprocess.check_call(['./out/restore'])


def Main():
  # This is a bare-bones test that does not need to be run through
  # elf_loader in order to be restored.
  RunTest(['./out/example_loader'], use_elf_loader=False)

  RunTest(['./out/example_prog'])
  RunTest(['./out/example_prog2'])

  # Get list of sub-test names.
  proc = subprocess.Popen(['./out/save_restore_tests'], stdout=subprocess.PIPE)
  stdout = proc.communicate()[0]
  test_names = stdout.strip().split('\n')

  for test_name in test_names:
    RunTest(['./out/save_restore_tests', test_name])

  RunTest(['/usr/bin/python', 'tests/python_example.py'])


if __name__ == '__main__':
  Main()

@@ -154,25 +154,278 @@
 import s
-ubprocess
+truct%0Aimport subprocess%0A%0A%0A__NR_getpid = 39%0A__NR_mknod = 133%0A%0A%0Adef AssertEquals(x, y):%0A  if x != y:%0A    raise AssertionError('%25r != %25r' %25 (x, y))%0A%0A%0Adef GetSnapshotSyscallNumber():%0A  fh = open('out_info', 'r')%0A  rax = struct.unpack('q', fh.read(8))%5B0%5D%0A  return rax
 %0A%0A%0Adef R
@@ -435,16 +435,24 @@
 est(cmd,
+ sysnum,
  use_elf
@@ -614,24 +614,290 @@
 er'%5D + cmd)%0A
+  # Check that the program was snapshotted at the expected syscall.%0A  # Otherwise, it could have been stopped earlier than we expected,%0A  # which would mean we wouldn't be testing the parts we expected to%0A  # test.%0A  AssertEquals(GetSnapshotSyscallNumber(), sysnum)%0A
   subprocess
@@ -1083,16 +1083,20 @@
 oader'%5D,
+ -1,
  use_elf
@@ -1143,16 +1143,29 @@
 e_prog'%5D
+, __NR_getpid
 )%0A  RunT
@@ -1191,16 +1191,20 @@
 _prog2'%5D
+, -1
 )%0A%0A  # G
@@ -1468,16 +1468,20 @@
 st_name%5D
+, -1
 )%0A%0A  Run
@@ -1531,16 +1531,28 @@
 ple.py'%5D
+, __NR_mknod
 )%0A%0A%0Aif _

Test that the program got snapshotted at the syscall we expected