summaryrefslogtreecommitdiff
path: root/src/tools/stress
blob: f861753e64f64fc2ae206b869ffcbfec363bb7b7 (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
#!/usr/bin/python3.7

import argparse
import subprocess
import sys
import random

def hms_to_seconds(h):
    s = h.split(':')
    assert(1 <= len(s) and len(s) <= 3)
    if len(s) == 1:
        return int(h)
    elif len(s) == 2:
        return int(s[0]) * 60 + int(s[1])
    elif len(s) == 3:
        return ((int(s[0]) * 60 + int(s[1])) * 60) + int(s[2])

def seek(dcp_seconds):
    print("O %s" % args.dcp)
    print("P")
    test_seconds = hms_to_seconds(args.length)
    while test_seconds > 0:
        wait = random.randint(500, dcp_seconds * 1000)
        # Wait some milliseconds
        print("W %d" % wait)
        # Seek
        print("S %d" % random.randint(0, 4095))
        # Make sure we're stil playing
        print("P")
        test_seconds -= wait / 1000 

def repeat(dcp_seconds):
    print("O %s" % args.dcp)
    test_seconds = hms_to_seconds(args.length)
    while test_seconds > 0:
        print("P")
        print("W %d" % (dcp_seconds * 1000))
        test_seconds -= dcp_seconds

parser = argparse.ArgumentParser()
parser.add_argument('-d', '--dcp', help='DCP to make a script for', required=True)
parser.add_argument('-t', '--type', help='script type: seek - seek a lot, repeat - play back DCP over and over', required=True)
parser.add_argument('-l', '--length', help='approximate test length in H:M:S', required=True)
args = parser.parse_args()

for l in subprocess.run(['dcpinfo', args.dcp], capture_output=True).stdout.splitlines():
    if l.startswith(b'Total:'):
        b = l.split(b':')
        dcp_seconds = (int(b[1]) * 60 + int(b[2])) * 60 + int(b[3])
if args.type == 'seek':
    seek(dcp_seconds)
elif args.type == 'repeat':
    repeat(dcp_seconds)
else:
    print('Unknown type %s' % args.type, file=sys.stderr)
    sys.exit(1)