~ubuntu-branches/debian/sid/cde/sid

« back to all changes in this revision

Viewing changes to tests/cde_test_common.py

  • Committer: Package Import Robot
  • Author(s): Yaroslav Halchenko
  • Date: 2012-02-03 19:27:05 UTC
  • Revision ID: package-import@ubuntu.com-20120203192705-ll6f1nr45ead65ed
Tags: upstream-0.1
ImportĀ upstreamĀ versionĀ 0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# common utilities for all CDE tests
 
2
import os, time
 
3
from subprocess import *
 
4
 
 
5
CDE_BIN  = "/home/pgbovine/CDE/cde"
 
6
CDE_EXEC = "/home/pgbovine/CDE/cde-exec"
 
7
 
 
8
CDE_ROOT_DIR = 'cde-package/cde-root'
 
9
 
 
10
def generic_lib_checks():
 
11
  assert os.path.islink('cde-package/cde-root/lib/libc.so.6')
 
12
  assert os.readlink('cde-package/cde-root/lib/libc.so.6') == 'libc-2.8.so'
 
13
  assert os.path.isfile('cde-package/cde-root/lib/ld-linux.so.2')
 
14
 
 
15
def run_cde(argv, silent=False):
 
16
  (stdout, stderr) = Popen([CDE_BIN] + argv, stdout=PIPE, stderr=PIPE).communicate()
 
17
  if not silent:
 
18
    if stderr: 
 
19
      print "stderr:", stderr
 
20
  return (stdout, stderr)
 
21
 
 
22
def run_and_cmp_cde_exec(argv, prev_stdout, prev_stderr):
 
23
  # to make for a tougher test, move the entire cde-package directory to /tmp
 
24
  # and try to do a cde-exec run
 
25
  full_pwd = os.getcwd()
 
26
  full_pwd_renamed = full_pwd + '-renamed'
 
27
  cur_dirname = os.path.basename(full_pwd)
 
28
 
 
29
  tmp_test_rootdir = "/tmp/" + cur_dirname
 
30
  tmp_test_dir = tmp_test_rootdir + '/cde-package/cde-root/' + full_pwd
 
31
 
 
32
  # careful with these commands! use 'finally' to clean up even after
 
33
  # exceptions!
 
34
  try:
 
35
    (stdout, stderr) = Popen(["rm", "-rf", tmp_test_rootdir], stdout=PIPE, stderr=PIPE).communicate()
 
36
    assert not stdout and not stderr
 
37
    (stdout, stderr) = Popen(["cp", "-aR", full_pwd, "/tmp"], stdout=PIPE, stderr=PIPE).communicate()
 
38
    assert not stdout and not stderr
 
39
 
 
40
    # rename full_pwd to make it impossible for the new version in /tmp
 
41
    # to reference already-existing files in full_pwd (a harsher test!)
 
42
    try:
 
43
      os.rename(full_pwd, full_pwd_renamed)
 
44
 
 
45
      # run the cde-exec test in tmp_test_dir
 
46
      os.chdir(tmp_test_dir)
 
47
      (stdout, stderr) = Popen([CDE_EXEC] + argv, stdout=PIPE, stderr=PIPE).communicate()
 
48
      #print '=== prev_stdout:', prev_stdout
 
49
      #print '=== stdout:', stdout
 
50
      assert stdout == prev_stdout
 
51
      #print '=== prev_stderr:', prev_stderr
 
52
      #print '=== stderr:', stderr
 
53
      assert stderr == prev_stderr
 
54
 
 
55
    finally:
 
56
      # rename it back to be nice :)
 
57
      os.rename(full_pwd_renamed, full_pwd)
 
58
      os.chdir(full_pwd) # make sure to chdir back!!!
 
59
 
 
60
  finally:
 
61
    # remove the version in tmp
 
62
    (stdout, stderr) = Popen(["rm", "-rf", tmp_test_rootdir], stdout=PIPE, stderr=PIPE).communicate()
 
63
 
 
64
 
 
65
def generic_test_runner(argv, checker_func, skip_generic_lib_checks=False, clear_cde_options=True):
 
66
  # careful!!!
 
67
  os.system('rm -rf cde-package')
 
68
 
 
69
  if clear_cde_options:
 
70
    os.system('rm -f cde.options')
 
71
 
 
72
  time.sleep(0.3) # to give os.system some time to work :)
 
73
 
 
74
 
 
75
  (stdout, stderr) = run_cde(argv)
 
76
 
 
77
  checker_func()
 
78
 
 
79
  if not skip_generic_lib_checks:
 
80
    generic_lib_checks()
 
81
 
 
82
  run_and_cmp_cde_exec(argv, stdout, stderr)
 
83