summaryrefslogtreecommitdiff
path: root/cpp/config/TestUtil.py
blob: 648ee7e026cf6ffa34f101ed4a3a5118b20140be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
# **********************************************************************
#
# Copyright (c) 2001
# MutableRealms, Inc.
# Huntsville, AL, USA
#
# All Rights Reserved
#
# **********************************************************************

import sys, os, string

serverPids = []

def killServers():

    global serverPids

    for pid in serverPids:
        if os.name == "nt":
            import win32api
            handle = win32api.OpenProcess(1, 0, pid)
            return (0 != win32api.TerminateProcess(handle, 0))
        else:
            os.kill(pid, 9)

    serverPids = []

def clientServerTest(toplevel, name):

    testdir = os.path.join(toplevel, "test", name)
    server = os.path.join(testdir, "server")
    client = os.path.join(testdir, "client")

    print "starting server...",
    serverPipe = os.popen(os.path.join(testdir, "server --pid"))
    output = serverPipe.readline().strip()
    if not output:
        print "failed!"
        sys.exit(0)
    serverPids.append(int(output))
    print "ok"
    
    print "starting client...",
    clientPipe = os.popen(os.path.join(testdir, "client"))
    output = clientPipe.read().strip()
    if not output:
        print "failed!"
        killServers()
        sys.exit(0)
    print "ok"
    print output

def collocatedTest(toplevel, name):

    testdir = os.path.join(toplevel, "test", name)
    collocated = os.path.join(testdir, "collocated")

    print "starting collocated...",
    collocatedPipe = os.popen(os.path.join(testdir, "collocated"))
    output = collocatedPipe.read().strip()
    if not output:
        print "failed!"
        sys.exit(0)
    print "ok"
    print output